X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fhtml2plain.php;h=72185de3b5c9bea9eaf1c53f8371c23ba87f0aba;hb=27646cc4ad8d715317a2ca055b6c3318ddf555a9;hp=07de829656b9e4a6d2a8630b589dcae35093f3e5;hpb=7770317f1ede7a0d429262b1fa288e861bd8c879;p=friendica.git diff --git a/include/html2plain.php b/include/html2plain.php index 07de829656..72185de3b5 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -23,7 +23,7 @@ function breaklines($line, $level, $wraplength = 75) if ($pos == 0) $pos = strpos($line, ' '); - if (($pos > 0) and strlen($line) > $wraplen) { + if (($pos > 0) && strlen($line) > $wraplen) { $newline = trim(substr($line, 0, $pos)); if ($level > 0) $newline = str_repeat(">", $level).' '.$newline; @@ -32,7 +32,7 @@ function breaklines($line, $level, $wraplength = 75) $line = substr($line, $pos+1); } - } while ((strlen($line) > $wraplen) and !($oldline == $line)); + } while ((strlen($line) > $wraplen) && !($oldline == $line)); if ($level > 0) $line = str_repeat(">", $level).' '.$line; @@ -49,7 +49,7 @@ function quotelevel($message, $wraplength = 75) $newlines = array(); $level = 0; - foreach($lines as $line) {; + foreach ($lines as $line) {; $line = trim($line); $startquote = false; while (strpos("*".$line, '[quote]') > 0) { @@ -70,7 +70,7 @@ function quotelevel($message, $wraplength = 75) $line = substr($line, 0, $pos).substr($line, $pos+8); } - if (!$startquote or ($line != '')) + if (!$startquote || ($line != '')) $newlines[] = breaklines($line, $currlevel, $wraplength); } return(implode($newlines, "\n")); @@ -82,17 +82,23 @@ 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], "//plus.google.com/") !== false) and (strpos($treffer[1], "/posts") !== false)) + if ((strpos($treffer[1], "//twitter.com/") !== false) && (strpos($treffer[1], "/status/") !== false)) + $ignore = false; + + if ((strpos($treffer[1], "//plus.google.com/") !== false) && (strpos($treffer[1], "/posts") !== false)) $ignore = false; - if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/photos") !== false)) + if ((strpos($treffer[1], "//plus.google.com/") !== false) && (strpos($treffer[1], "/photos") !== false)) $ignore = false; if (!$ignore) @@ -107,12 +113,6 @@ 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>/is'; - $message = preg_replace($pattern, '#$2', $message); - } - $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; @@ -179,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); @@ -212,12 +212,13 @@ function html2plain($html, $wraplength = 75, $compact = false) $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8'); - if (!$compact) { + if (!$compact && ($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); @@ -232,4 +233,3 @@ function html2plain($html, $wraplength = 75, $compact = false) return(trim($message)); } -