From 35fbe3be14ace42ce7ef61665ac2300d01d1ef46 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 18 May 2014 18:56:07 +0200 Subject: [PATCH 1/3] Diaspora: Better handling of "red"-links --- include/bb2diaspora.php | 3 ++- include/bbcode.php | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 0ffbf0a1..eeed19d8 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -63,7 +63,8 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { /** * Transform #tags, strip off the [url] and replace spaces with underscore */ - $Text = preg_replace_callback('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', create_function('$match', + $URLSearchString = "^\[\]"; + $Text = preg_replace_callback("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/i", create_function('$match', 'return \'#\'. str_replace(\' \', \'_\', $match[2]);' ), $Text); diff --git a/include/bbcode.php b/include/bbcode.php index 686bd41b..b036a5dc 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -40,11 +40,11 @@ function bb_remove_share_information($Text, $plaintext = false) { } function bb_cleanup_share($shared) { - if ($shared[2] != "type-link") - return($shared[3]); + if (!in_array($shared[2], array("type-link", "type-video"))) + return($shared[0]); if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark)) - return($shared[3]); + return($shared[0]); $title = ""; $link = ""; @@ -747,9 +747,20 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // Set up the parameters for a MAIL search string $MAILSearchString = $URLSearchString; + // Remove all hashtag addresses + if (!$tryoembed OR $simplehtml) + $Text = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text); + // Bookmarks in red - will be converted to bookmarks in friendica $Text = preg_replace("/#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '[bookmark=$1]$1[/bookmark]', $Text); $Text = preg_replace("/#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $Text); + $Text = preg_replace("/#\[url\=[$URLSearchString]*\]\^\[\/url\]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/i", + "[bookmark=$1]$2[/bookmark]", $Text); + + if ($simplehtml == 2) { + $Text = preg_replace("/[^#@]\[url\=([^\]]*)\](.*?)\[\/url\]/ism",' $2 [url]$1[/url]',$Text); + $Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",' $2 [url]$1[/url]',$Text); + } if ($simplehtml == 5) $Text = preg_replace("/[^#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url]$1[/url]', $Text); @@ -1063,11 +1074,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // $Text = str_replace('
save_timestamp($stamp1, "parser"); From 7cc2723e2d4a1326ed4492cf1cade608fa6b94b0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 18 May 2014 18:57:31 +0200 Subject: [PATCH 2/3] Improvement for shortening of the new plaintext option. --- include/html2plain.php | 8 ++++---- include/plaintext.php | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/html2plain.php b/include/html2plain.php index 0398ea79..f09087e0 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -114,11 +114,11 @@ function html2plain($html, $wraplength = 75, $compact = false) $message = str_replace("\r", "", $html); // replace all hashtag addresses - if (get_config("system", "remove_hashtags_on_export")) { +/* if (get_config("system", "remove_hashtags_on_export")) { $pattern = '/#(.*?)<\/a>/is'; $message = preg_replace($pattern, '#$2', $message); } - +*/ $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; @@ -185,8 +185,8 @@ function html2plain($html, $wraplength = 75, $compact = false) node2bbcode($doc, 'h6', array(), "\n\n*", "*\n"); // Problem: there is no reliable way to detect if it is a link to a tag or profile - //node2bbcode($doc, 'a', array('href'=>'/(.+)/'), ' $1 ', '', true); - node2bbcode($doc, 'a', array('href'=>'/(.+)/', 'rel'=>'oembed'), ' $1 ', '', true); + //node2bbcode($doc, 'a', array('href'=>'/(.+)/'), ' $1 ', ' ', true); + //node2bbcode($doc, 'a', array('href'=>'/(.+)/', 'rel'=>'oembed'), ' $1 ', '', true); //node2bbcode($doc, 'img', array('alt'=>'/(.+)/'), '$1', ''); //node2bbcode($doc, 'img', array('title'=>'/(.+)/'), '$1', ''); //node2bbcode($doc, 'img', array(), '', ''); diff --git a/include/plaintext.php b/include/plaintext.php index 0c985e05..76bcaa1f 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -168,6 +168,8 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false) { // Is the new message empty by now or is it a reshared message? elseif (($msg == "") OR (($row == 1) AND (substr($msg, 0, 4) == $recycle))) $msg = substr(substr(trim($msg."\n".$line), 0, $limit), 0, -3)."..."; + else + break; } } } From 31886ecd4f55f63f2b0c3d8ab93bad50cbfbae6a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 18 May 2014 18:59:10 +0200 Subject: [PATCH 3/3] Content got lost sometimes due to a needless security function (HTML content is handled in the bbcode function) --- include/items.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/items.php b/include/items.php index 27be613d..94285e61 100755 --- a/include/items.php +++ b/include/items.php @@ -990,9 +990,9 @@ function item_store($arr,$force_parent = false) { $arr['type'] = 'remote'; // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. - - if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) - $arr['body'] = strip_tags($arr['body']); + // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<" + //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) + // $arr['body'] = strip_tags($arr['body']); if (version_compare(PHP_VERSION, '5.3.0', '>=')) {