X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbb2diaspora.php;h=a07a583538e4ac5e88b1613ff765c50837c83846;hb=45d73b106bbebdea17c56c00235c0dcebc471536;hp=a8b39f741ac84a2d066066e129176cf0dff82b9a;hpb=9ab5bfb5074ddba22777c3b043bb539a473288a5;p=friendica.git diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index a8b39f741a..a07a583538 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -1,63 +1,82 @@ ", "

", '

'),array("
", "
", "
"),$s); + $s = str_replace(array('

', '

', '

'), array('
', '
', '
'), $s); // Escaping the hash tags - $s = preg_replace('/\#([^\s\#])/','#$1',$s); + $s = preg_replace('/\#([^\s\#])/', '#$1', $s); $s = Markdown($s); - $s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s); + $regexp = "/@\{(?:([^\}]+?); )?([^\} ]+)\}/"; + $s = preg_replace_callback($regexp, 'diaspora_mention2bb', $s); - $s = str_replace('#','#',$s); - - $search = array(" \n", "\n "); - $replace = array("\n", "\n"); - do { - $oldtext = $s; - $s = str_replace($search, $replace, $s); - } while ($oldtext != $s); - - $s = str_replace("\n\n", "
", $s); + $s = str_replace('#', '#', $s); $s = html2bbcode($s); // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands - $s = str_replace('♲',html_entity_decode('♲',ENT_QUOTES,'UTF-8'),$s); + $s = str_replace('♲', html_entity_decode('♲', ENT_QUOTES, 'UTF-8'), $s); // Convert everything that looks like a link to a link - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); + $s = preg_replace('/([^\]=]|^)(https?\:\/\/)([a-zA-Z0-9:\/\-?&;.=_~#%$!+,@]+(?convert($Text); - // unmask the special chars back to HTML - $Text = str_replace(array('&_lt_;','&_gt_;','&_amp_;'),array('<','>','&'),$Text); + // unmask the special chars back to HTML + $Text = str_replace(array('&_lt_;', '&_gt_;', '&_amp_;'), array('<', '>', '&'), $Text); $a->save_timestamp($stamp1, "parser"); @@ -128,22 +196,36 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { // the Diaspora signature verification and cause the item to disappear $Text = trim($Text); + if ($fordiaspora) { + $URLSearchString = "^\[\]"; + $Text = preg_replace_callback("/([@]\[(.*?)\])\(([$URLSearchString]*?)\)/ism", 'diaspora_mentions', $Text); + } + + // Restore code blocks + $Text = preg_replace_callback('/#codeblock-([0-9]+)#/iU', + function ($matches) use ($codeblocks) { + $return = ''; + if (isset($codeblocks[intval($matches[1])])) { + $return = $codeblocks[$matches[1]]; + } + return $return; + } + , $Text); + call_hooks('bb2diaspora',$Text); return $Text; } function unescape_underscores_in_links($m) { - $y = str_replace('\\_','_', $m[2]); + $y = str_replace('\\_', '_', $m[2]); return('[' . $m[1] . '](' . $y . ')'); } function format_event_diaspora($ev) { - - $a = get_app(); - - if(! ((is_array($ev)) && count($ev))) + if (! ((is_array($ev)) && count($ev))) { return ''; + } $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM @@ -156,19 +238,21 @@ function format_event_diaspora($ev) { $ev['start'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $ev['start'] , $bd_format))) - . '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; + . '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; - if(! $ev['nofinish']) + if (! $ev['nofinish']) { $o .= t('Finishes:') . ' ' . '[' . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', $ev['finish'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $ev['finish'] , $bd_format ))) - . '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; + . '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; + } - if(strlen($ev['location'])) + if (strlen($ev['location'])) { $o .= t('Location:') . bb2diaspora($ev['location']) . "\n"; + } $o .= "\n"; return $o;