]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #983 from annando/master
authortobiasd <tobias.diekershoff@gmx.net>
Sun, 18 May 2014 18:01:29 +0000 (20:01 +0200)
committertobiasd <tobias.diekershoff@gmx.net>
Sun, 18 May 2014 18:01:29 +0000 (20:01 +0200)
"red"-bookmarks and better plaintext export

include/bb2diaspora.php
include/bbcode.php
include/html2plain.php
include/items.php
include/plaintext.php

index 0ffbf0a14464fd8d4dc2bf9f2ab63953c4147bcf..eeed19d81686a150b9be58609243f2d5a684f74a 100644 (file)
@@ -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);
 
index 33c0721b08e9cda041b7b151d72d8226368791ea..4ccab8db5d9ffb276a17874a1ff3bd9edd680296 100644 (file)
@@ -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 = "";
@@ -746,9 +746,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);
@@ -1062,11 +1073,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
        //      $Text = str_replace('<br /><ul','<ul ', $Text);
 
        // Remove all hashtag addresses
-       if (!$tryoembed AND get_config("system", "remove_hashtags_on_export")) {
+/*     if (!$tryoembed AND get_config("system", "remove_hashtags_on_export")) {
                $pattern = '/#<a.*?href="(.*?)".*?>(.*?)<\/a>/is';
                $Text = preg_replace($pattern, '#$2', $Text);
        }
-
+*/
        call_hooks('bbcode',$Text);
 
        $a->save_timestamp($stamp1, "parser");
index 0398ea79b074159ff9fa2efa4e8b3ea7761eb492..f09087e0b0179fab68fb4e42328ba5037dbabf61 100644 (file)
@@ -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.*?href="(.*?)".*?>(.*?)<\/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(), '', '');
index 2f03818a76bae0e2099df620a75016a04ec6f1b5..76bcbc7b24120d39216ce49a42140427a7e19436 100755 (executable)
@@ -1007,9 +1007,9 @@ function item_store($arr,$force_parent = false) {
        }
 
        // 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', '>=')) {
index 0c985e05c05a6a489006260449081abcbc1be796..76bcaa1f9a769f9e6995c764c961d68f5f1037f8 100644 (file)
@@ -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;
                        }
                }
        }