]> git.mxchange.org Git - friendica.git/blobdiff - include/html2plain.php
Avoiding some PHP warnings
[friendica.git] / include / html2plain.php
index 572f9714a32162f2ffc1504aab4708df4b6600f0..54cc44794dc9e3a1ca96a622df0008bb78cd2b7b 100644 (file)
@@ -82,13 +82,19 @@ 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=", "/search?tag=", "mailto:", "/u/", "/node/",
-                               "//facebook.com/profile.php?id=", "//plus.google.com/");
+                               "//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;
 
@@ -107,6 +113,12 @@ function html2plain($html, $wraplength = 75, $compact = false)
 
        $message = str_replace("\r", "", $html);
 
+       // replace all hashtag addresses
+       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;
 
@@ -179,9 +191,9 @@ function html2plain($html, $wraplength = 75, $compact = false)
        //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);
 
@@ -206,14 +218,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);
@@ -223,4 +239,4 @@ function html2plain($html, $wraplength = 75, $compact = false)
 
        return(trim($message));
 }
-?>
+