added spaces + some curly braces + some usage of dbm::is_result()

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Haeder 2017-04-04 19:46:56 +02:00
parent bebff8ebbb
commit 03571f6e74
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
11 changed files with 309 additions and 268 deletions

View file

@ -206,30 +206,33 @@ function bb_spacefy($st) {
// returning [i]italic[/i]
function bb_unspacefy_and_trim($st) {
$whole_match = $st[0];
$captured = $st[1];
$unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
return $unspacefied;
$whole_match = $st[0];
$captured = $st[1];
$unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
return $unspacefied;
}
function bb_find_open_close($s, $open, $close, $occurance = 1) {
if($occurance < 1)
if ($occurance < 1)
$occurance = 1;
$start_pos = -1;
for($i = 1; $i <= $occurance; $i++) {
if( $start_pos !== false)
for ($i = 1; $i <= $occurance; $i++) {
if ( $start_pos !== false) {
$start_pos = strpos($s, $open, $start_pos + 1);
}
}
if( $start_pos === false)
if ( $start_pos === false) {
return false;
}
$end_pos = strpos($s, $close, $start_pos);
if( $end_pos === false)
if ( $end_pos === false) {
return false;
}
$res = array( 'start' => $start_pos, 'end' => $end_pos );
@ -238,35 +241,48 @@ function bb_find_open_close($s, $open, $close, $occurance = 1) {
function get_bb_tag_pos($s, $name, $occurance = 1) {
if($occurance < 1)
if ($occurance < 1)
$occurance = 1;
$start_open = -1;
for($i = 1; $i <= $occurance; $i++) {
if( $start_open !== false)
for ($i = 1; $i <= $occurance; $i++) {
if ( $start_open !== false) {
$start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags
}
}
if( $start_open === false)
if ( $start_open === false) {
return false;
}
$start_equal = strpos($s, '=', $start_open);
$start_close = strpos($s, ']', $start_open);
if( $start_close === false)
if ( $start_close === false) {
return false;
}
$start_close++;
$end_open = strpos($s, '[/' . $name . ']', $start_close);
if( $end_open === false)
if ( $end_open === false) {
return false;
}
$res = array( 'start' => array('open' => $start_open, 'close' => $start_close),
'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) );
if( $start_equal !== false)
$res = array(
'start' => array(
'open' => $start_open,
'close' => $start_close
),
'end' => array(
'open' => $end_open,
'close' => $end_open + strlen('[/' . $name . ']')
),
);
if ( $start_equal !== false) {
$res['start']['equal'] = $start_equal + 1;
}
return $res;
}
@ -277,12 +293,12 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {
$occurance = 1;
$pos = get_bb_tag_pos($string, $name, $occurance);
while($pos !== false && $occurance < 1000) {
while ($pos !== false && $occurance < 1000) {
$start = substr($string, 0, $pos['start']['open']);
$subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
$end = substr($string, $pos['end']['close']);
if($end === false)
if ($end === false)
$end = '';
$subject = preg_replace($pattern, $replace, $subject);
@ -295,7 +311,7 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {
return $string;
}
if(! function_exists('bb_extract_images')) {
if (! function_exists('bb_extract_images')) {
function bb_extract_images($body) {
$saved_image = array();
@ -306,12 +322,12 @@ function bb_extract_images($body) {
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
while(($img_st_close !== false) && ($img_end !== false)) {
while (($img_st_close !== false) && ($img_end !== false)) {
$img_st_close++; // make it point to AFTER the closing bracket
$img_end += $img_start;
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
@ -324,7 +340,7 @@ function bb_extract_images($body) {
$orig_body = substr($orig_body, $img_end + strlen('[/img]'));
if($orig_body === false) // in case the body ends on a closing image tag
if ($orig_body === false) // in case the body ends on a closing image tag
$orig_body = '';
$img_start = strpos($orig_body, '[img');
@ -337,7 +353,7 @@ function bb_extract_images($body) {
return array('body' => $new_body, 'images' => $saved_image);
}}
if(! function_exists('bb_replace_images')) {
if (! function_exists('bb_replace_images')) {
function bb_replace_images($body, $images) {
$newbody = $body;
@ -619,7 +635,7 @@ function bb_DiasporaLinks($match) {
function bb_RemovePictureLinks($match) {
$text = Cache::get($match[1]);
if(is_null($text)){
if (is_null($text)){
$a = get_app();
$stamp1 = microtime(true);
@ -673,7 +689,7 @@ function bb_expand_links($match) {
function bb_CleanPictureLinksSub($match) {
$text = Cache::get($match[1]);
if(is_null($text)){
if (is_null($text)){
$a = get_app();
$stamp1 = microtime(true);
@ -724,7 +740,7 @@ function bb_CleanPictureLinks($text) {
}
function bb_highlight($match) {
if(in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby',
if (in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby',
'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','sh']))
return text_highlight($match[2],strtolower($match[1]));
return $match[0];
@ -814,7 +830,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);
if($preserve_nl)
if ($preserve_nl)
$Text = str_replace(array("\n","\r"), array('',''),$Text);
// Set up the parameters for a URL search string
@ -1132,7 +1148,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Summary (e.g. title) is required, earlier revisions only required description (in addition to
// start which is always required). Allow desc with a missing summary for compatibility.
if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
if ((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
$sub = format_event_html($ev, $simplehtml);
$Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text);
@ -1178,7 +1194,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism';
$Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text);
if($saved_image) {
if ($saved_image) {
$Text = bb_replace_images($Text, $saved_image);
}