X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fhtml2plain.php;h=f09087e0b0179fab68fb4e42328ba5037dbabf61;hb=cd7d29d13ec6341198131d2d00231c8e828b22a7;hp=7aa20500a57a1ad2594fa4f489743035dc343ebb;hpb=7d23149a61f75923b2c71a288a722ee219f5e6ba;p=friendica.git diff --git a/include/html2plain.php b/include/html2plain.php index 7aa20500a5..f09087e0b0 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -1,5 +1,5 @@ (.*?)<\/a>/is'; + $message = preg_replace($pattern, '#$2', $message); + } +*/ $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; @@ -157,7 +172,7 @@ function html2plain($html, $wraplength = 75, $compact = false) //node2bbcode($doc, 'ol', array(), "\n[list=1]", "[/list]\n"); node2bbcode($doc, 'li', array(), "\n* ", "\n"); - node2bbcode($doc, 'hr', array(), str_repeat("-", 70), ""); + node2bbcode($doc, 'hr', array(), "\n".str_repeat("-", 70)."\n", ""); node2bbcode($doc, 'tr', array(), "\n", ""); node2bbcode($doc, 'td', array(), "\t", ""); @@ -170,15 +185,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 +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);