]> git.mxchange.org Git - friendica.git/blobdiff - include/html2plain.php
Merge pull request #2016 from fabrixxm/template_vars_hook
[friendica.git] / include / html2plain.php
index 21261327db82aefc2ce9dda46c8d930155fb390d..1d5910d83bea975a11a02b2aef1e8c3eba01e68b 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-require_once "html2bbcode.php";
+require_once("include/html2bbcode.php");
 
 function breaklines($line, $level, $wraplength = 75)
 {
@@ -82,16 +82,25 @@ function collecturls($message) {
 
        $urls = array();
        foreach ($result as $treffer) {
+
+               $ignore = false;
+
                // A list of some links that should be ignored
-               $list = array("/user/", "/tag/", "/group/", "/profile/", "/search?search=", "mailto:", "/u/", "/node/",
-                               "//facebook.com/profile.php?id=", "//plus.google.com/");
+               $list = array("/user/", "/tag/", "/group/", "/profile/", "/search?search=", "/search?tag=", "mailto:", "/u/", "/node/",
+                               "//facebook.com/profile.php?id=", "//plus.google.com/", "//twitter.com/");
                foreach ($list as $listitem)
                        if (strpos($treffer[1], $listitem) !== false)
                                $ignore = true;
 
+               if ((strpos($treffer[1], "//twitter.com/") !== false) and (strpos($treffer[1], "/status/") !== false))
+                               $ignore = false;
+
                if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/posts") !== false))
                                $ignore = false;
 
+               if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/photos") !== false))
+                               $ignore = false;
+
                if (!$ignore)
                        $urls[$treffer[1]] = $treffer[1];
        }
@@ -170,15 +179,15 @@ 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(), '', '');
        if (!$compact)
-               node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
+               node2bbcode($doc, 'img', array('src'=>'/(.+)/'), ' [img]$1', '[/img] ');
        else
-               node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '', '');
+               node2bbcode($doc, 'img', array('src'=>'/(.+)/'), ' ', ' ');
 
        node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), ' $1 ', '', true);
 
@@ -203,14 +212,18 @@ function html2plain($html, $wraplength = 75, $compact = false)
 
        $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
 
-       if (!$compact) {
+       if (!$compact AND ($message != "")) {
                $counter = 1;
                foreach ($urls as $id=>$url)
-                       if (strpos($message, $url) == false)
-                               $message .= "\n".$url." ";
-                               //$message .= "\n[".($counter++)."] ".$url;
+                       if ($url != "")
+                               if (strpos($message, $url) === false)
+                                       $message .= "\n".$url." ";
+                                       //$message .= "\n[".($counter++)."] ".$url;
        }
 
+       $message = str_replace("\n«", "«\n", $message);
+       $message = str_replace("»\n", "\n»", $message);
+
        do {
                $oldmessage = $message;
                $message = str_replace("\n\n\n", "\n\n", $message);