X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbb2diaspora.php;h=20309b9d2000591fe3ee86196b39f0d8ca98df85;hb=e40c3a9d7c980c4287c273bc12d934ceb8b55fc0;hp=fc05e720f4f7b1c7a16896532d7e534d315cc7d1;hpb=2d75e1f4224e3ebe77cc5873fa26559b729f0c3d;p=friendica.git diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index fc05e720f4..20309b9d20 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -1,63 +1,86 @@ ", "
", '
'),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);
-
- $s = str_replace('#','#',$s);
+ $regexp = "/@\{(?:([^\}]+?); )?([^\} ]+)\}/";
+ $s = preg_replace_callback($regexp, 'diaspora_mention2bb', $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:\/\-?&;.=_~#%$!+,@]+(?".$tagline;
+ foreach ($tags[2] as $tag) {
+ $tag = html_entity_decode($tag, ENT_QUOTES, 'UTF-8');
+ if (!strpos(html_entity_decode($Text, ENT_QUOTES, 'UTF-8'), '#' . $tag)) {
+ $tagline .= '#' . $tag . ' ';
+ }
+ }
+ $Text = $Text." ".$tagline;
}
-
- } else
+ } else {
$Text = bbcode($Text, $preserve_nl, false, 4);
+ }
- // mask some special HTML chars from conversation to markdown
- $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text);
+ // mask some special HTML chars from conversation to markdown
+ $Text = str_replace(array('<', '>', '&'), array('&_lt_;', '&_gt_;', '&_amp_;'), $Text);
// If a link is followed by a quote then there should be a newline before it
// Maybe we should make this newline at every time before a quote.
@@ -114,10 +185,11 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
$stamp1 = microtime(true);
// Now convert HTML to Markdown
- $Text = new HTML_To_Markdown($Text);
+ $converter = new HtmlConverter();
+ $Text = $converter->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 +200,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 +242,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";
+ . '](' . System::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";
+ . '](' . System::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;