diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index c26b0c334..9acd1e066 100755
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -13,30 +13,45 @@ require_once('include/html2bbcode.php');
function diaspora2bb($s) {
+ // for testing purposes: Collect raw markdown articles
+ $file = tempnam("/tmp/", "markdown");
+ file_put_contents($file, $s);
+
$s = html_entity_decode($s,ENT_COMPAT,'UTF-8');
- $s = str_replace("\r","\n",$s);
+
+ // Too many new lines. So deactivated the following line
+ // $s = str_replace("\r","\n",$s);
+ // Simply remove cr.
+ $s = str_replace("\r","",$s);
$s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s);
- $s = preg_replace('/\#([^\s\#])/','\\#$1',$s);
+ // Escaping the hash tags - doesn't always seem to work
+ // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s);
+ // This seems to work
+ $s = preg_replace('/\#([^\s\#])/','#$1',$s);
$s = Markdown($s);
- $s = str_replace('#','#',$s);
- $s = str_replace("\n",'
',$s);
+ $s = str_replace('#','#',$s);
+
+ // Again: too many new lines
+ //$s = str_replace("\n",'
',$s);
$s = html2bbcode($s);
// $s = str_replace('*','*',$s);
- $s = preg_replace("/\[url\=?(.*?)\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/url\]/ism",'[youtube]$2[/youtube]',$s);
- $s = preg_replace("/\[url\=https?:\/\/www.youtube.com\/watch\?v\=(.*?)\].*?\[\/url\]/ism",'[youtube]$1[/youtube]',$s);
+ $s = preg_replace("/\[url\=?(.*?)\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/url\]/ism",'[youtube]$2[/youtube]',$s);
+ $s = preg_replace("/\[url\=https?:\/\/www.youtube.com\/watch\?v\=(.*?)\].*?\[\/url\]/ism",'[youtube]$1[/youtube]',$s);
$s = preg_replace("/\[url\=?(.*?)\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/url\]/ism",'[vimeo]$2[/vimeo]',$s);
$s = preg_replace("/\[url\=https?:\/\/vimeo.com\/([0-9]+)\](.*?)\[\/url\]/ism",'[vimeo]$1[/vimeo]',$s);
$s = preg_replace("/([^\]\=]|^)(https?\:\/\/)(vimeo|youtu|www\.youtube|soundcloud)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2$3$4[/url]',$s);
// remove duplicate adjacent code tags
$s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s);
- $s = scale_diaspora_images($s);
+
+ // Don't show link to full picture (until it is fixed)
+ $s = scale_diaspora_images($s, false);
return $s;
}
diff --git a/include/bbcode.php b/include/bbcode.php
index cae867eb8..528df33ec 100755
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -12,20 +12,20 @@ function stripcode_br_cb($s) {
function tryoembed($match){
$url = ((count($match)==2)?$match[1]:$match[2]);
// logger("tryoembed: $url");
-
+
$o = oembed_fetch_url($url);
//echo "
"; var_dump($match, $url, $o); killme(); if ($o->type=="error") return $match[0]; - + $html = oembed_format_object($o); return $html; //oembed_iframe($html,$o->width,$o->height); - + } -// [noparse][i]italic[/i][/noparse] turns into -// [noparse][ i ]italic[ /i ][/noparse], +// [noparse][i]italic[/i][/noparse] turns into +// [noparse][ i ]italic[ /i ][/noparse], // to hide them from parser. function bb_spacefy($st) { @@ -36,7 +36,7 @@ function bb_spacefy($st) { return $new_str; } -// The previously spacefied [noparse][ i ]italic[ /i ][/noparse], +// The previously spacefied [noparse][ i ]italic[ /i ][/noparse], // now turns back and the [noparse] tags are trimed // returning [i]italic[/i] @@ -59,8 +59,8 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); - // Extract a single private image which uses data url's since preg has issues with - // large data sizes. Stash it away while we do bbcode conversion, and then put it back + // Extract a single private image which uses data url's since preg has issues with + // large data sizes. Stash it away while we do bbcode conversion, and then put it back // in after we've done all the regex matching. We cannot use any preg functions to do this. $saved_image = ''; @@ -71,13 +71,13 @@ function bbcode($Text,$preserve_nl = false) { $start_fragment = substr($Text,0,$img_start); $img_start += strlen('[img]'); $saved_image = substr($Text,$img_start,$img_end - $img_start); - $end_fragment = substr($Text,$img_end + strlen('[/img]')); + $end_fragment = substr($Text,$img_end + strlen('[/img]')); // logger('saved_image: ' . $saved_image,LOGGER_DEBUG); $Text = $start_fragment . '[$#saved_image#$]' . $end_fragment; } // If we find any event code, turn it into an event. - // After we're finished processing the bbcode we'll + // After we're finished processing the bbcode we'll // replace all of the event code with a reformatted version. $ev = bbtoevent($Text); @@ -105,7 +105,7 @@ function bbcode($Text,$preserve_nl = false) { // Perform URL Search $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); - + $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text); $Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text); @@ -118,7 +118,7 @@ function bbcode($Text,$preserve_nl = false) { // Perform MAIL Search $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); - + // Check for bold text $Text = preg_replace("(\[b\](.*?)\[\/b\])ism",'$1',$Text); @@ -150,20 +150,14 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
$1'; + $QuoteLayout = '
$1'; // Check for [quote] text - $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism","$QuoteLayout", $Text); + // handle nested quotes + $endlessloop = 0; + while (strpos($Text, "[/quote]") and strpos($Text, "[quote]") and (++$endlessloop < 20)) + $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism","$QuoteLayout", $Text); // Check for [quote=Author] text $t_wrote = t('$1 wrote:'); - $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", - "
" . $t_wrote . " $2", - $Text); + // handle nested quotes + $endlessloop = 0; + while (strpos($Text, "[/quote]") and strpos($Text, "[quote=") and (++$endlessloop < 20)) + $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", + "
" . $t_wrote . " $2", + $Text); // [img=widthxheight]image source[/img] $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 8025c336b..1b4b5e99a 100755 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -1,127 +1,279 @@ (.*?)\<\/pre\>/is', - '/\
/is',
- '/\<\/p\>/is',
- '/\(.*?)\<\/b\>/is',
- '/\(.*?)\<\/i\>/is',
- '/\(.*?)\<\/u\>/is',
- '/\(.*?)\<\/ul\>/is',
- '/\
/is',
- '/\(.*?)\<\/strong\>/is',
- '/\(.*?)\<\/a\>/is',
- '/\(.*?)\<\/code\>/is',
- '/\(.*?)\<\/span\>/is',
- '/\(.*?)\<\/span\>/is',
- '/\
(.*?)\<\/blockquote\>/is',
- '/\