X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fhtml2plain.php;h=83aa05ed565691029e463b6d7160156849e4a1ef;hb=0fe832ef8aeafa1ddba793a8b084005cf070f1f4;hp=dfb577abe18018714b4518dd4319ec457addc18e;hpb=c308bb904236deeadd9f996f387bd3002d17b934;p=friendica.git diff --git a/include/html2plain.php b/include/html2plain.php index dfb577abe1..83aa05ed56 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -1,15 +1,14 @@ 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; + if ($level > 0) { + $newline = str_repeat(">", $level) . ' ' . $newline; + } - $newlines[] = $newline." "; - $line = substr($line, $pos+1); + $newlines[] = $newline . " "; + $line = substr($line, $pos + 1); } + } while ((strlen($line) > $wraplen) && !($oldline == $line)); - } while ((strlen($line) > $wraplen) and !($oldline == $line)); - - if ($level > 0) - $line = str_repeat(">", $level).' '.$line; + if ($level > 0) { + $line = str_repeat(">", $level) . ' ' . $line; + } $newlines[] = $line; - - return(implode($newlines, "\n")); + return implode($newlines, "\n"); } function quotelevel($message, $wraplength = 75) @@ -49,62 +49,72 @@ 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) { + while (strpos("*" . $line, '[quote]') > 0) { $level++; $pos = strpos($line, '[quote]'); - $line = substr($line, 0, $pos).substr($line, $pos+7); + $line = substr($line, 0, $pos) . substr($line, $pos + 7); $startquote = true; } $currlevel = $level; - while (strpos("*".$line, '[/quote]') > 0) { + while (strpos("*" . $line, '[/quote]') > 0) { $level--; - if ($level < 0) + if ($level < 0) { $level = 0; + } $pos = strpos($line, '[/quote]'); - $line = substr($line, 0, $pos).substr($line, $pos+8); + $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")); + + return implode($newlines, "\n"); } -function collecturls($message) { +function collecturls($message) +{ $pattern = '/(.*?)<\/a>/is'; preg_match_all($pattern, $message, $result, PREG_SET_ORDER); $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/", "//twitter.com/"); - foreach ($list as $listitem) - if (strpos($treffer[1], $listitem) !== false) + "//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], "//twitter.com/") !== false) && (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) && (strpos($treffer[1], "/posts") !== false)) { + $ignore = false; + } - if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/photos") !== false)) - $ignore = false; + if ((strpos($treffer[1], "//plus.google.com/") !== false) && (strpos($treffer[1], "/photos") !== false)) { + $ignore = false; + } - if (!$ignore) + if (!$ignore) { $urls[$treffer[1]] = $treffer[1]; + } } - return($urls); + + return $urls; } function html2plain($html, $wraplength = 75, $compact = false) @@ -113,12 +123,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; @@ -146,20 +150,21 @@ function html2plain($html, $wraplength = 75, $compact = false) // MyBB-Auszeichnungen /* - node2bbcode($doc, 'span', array('style'=>'text-decoration: underline;'), '_', '_'); - node2bbcode($doc, 'span', array('style'=>'font-style: italic;'), '/', '/'); - node2bbcode($doc, 'span', array('style'=>'font-weight: bold;'), '*', '*'); + node2bbcode($doc, 'span', array('style'=>'text-decoration: underline;'), '_', '_'); + node2bbcode($doc, 'span', array('style'=>'font-style: italic;'), '/', '/'); + node2bbcode($doc, 'span', array('style'=>'font-weight: bold;'), '*', '*'); - node2bbcode($doc, 'strong', array(), '*', '*'); - node2bbcode($doc, 'b', array(), '*', '*'); - node2bbcode($doc, 'i', array(), '/', '/'); - node2bbcode($doc, 'u', array(), '_', '_'); - */ + node2bbcode($doc, 'strong', array(), '*', '*'); + node2bbcode($doc, 'b', array(), '*', '*'); + node2bbcode($doc, 'i', array(), '/', '/'); + node2bbcode($doc, 'u', array(), '_', '_'); + */ - if ($compact) + if ($compact) { node2bbcode($doc, 'blockquote', array(), "»", "«"); - else + } else { node2bbcode($doc, 'blockquote', array(), '[quote]', "[/quote]\n"); + } node2bbcode($doc, 'br', array(), "\n", ''); @@ -172,7 +177,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(), "\n".str_repeat("-", 70)."\n", ""); + node2bbcode($doc, 'hr', array(), "\n" . str_repeat("-", 70) . "\n", ""); node2bbcode($doc, 'tr', array(), "\n", ""); node2bbcode($doc, 'td', array(), "\t", ""); @@ -185,17 +190,18 @@ 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]'); - else - node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '', ''); + if (!$compact) { + node2bbcode($doc, 'img', array('src' => '/(.+)/'), ' [img]$1', '[/img] '); + } else { + node2bbcode($doc, 'img', array('src' => '/(.+)/'), ' ', ' '); + } - node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), ' $1 ', '', true); + node2bbcode($doc, 'iframe', array('src' => '/(.+)/'), ' $1 ', ''); $message = $doc->saveHTML(); @@ -206,7 +212,7 @@ function html2plain($html, $wraplength = 75, $compact = false) // was ersetze ich da? // Irgendein stoerrisches UTF-Zeug - $message = str_replace(chr(194).chr(160), ' ', $message); + $message = str_replace(chr(194) . chr(160), ' ', $message); $message = str_replace(" ", " ", $message); @@ -218,12 +224,12 @@ function html2plain($html, $wraplength = 75, $compact = false) $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8'); - if (!$compact) { - $counter = 1; - foreach ($urls as $id=>$url) - if (strpos($message, $url) === false) - $message .= "\n".$url." "; - //$message .= "\n[".($counter++)."] ".$url; + if (!$compact && ($message != '')) { + foreach ($urls as $id => $url) { + if ($url != '' && strpos($message, $url) === false) { + $message .= "\n" . $url . ' '; + } + } } $message = str_replace("\n«", "«\n", $message); @@ -236,6 +242,5 @@ function html2plain($html, $wraplength = 75, $compact = false) $message = quotelevel(trim($message), $wraplength); - return(trim($message)); + return trim($message); } -