X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=include%2Fhtml2plain.php;h=1d5910d83bea975a11a02b2aef1e8c3eba01e68b;hb=75be187216255c7c45421cb5f9596118a954f878;hp=2a4cf663913720caeac1bd041c3b6b99f993c3ab;hpb=437e18d7a7433ea5a9e3388c39ba32c7fe25eb18;p=friendica.git
diff --git a/include/html2plain.php b/include/html2plain.php
index 2a4cf66391..1d5910d83b 100644
--- a/include/html2plain.php
+++ b/include/html2plain.php
@@ -1,9 +1,15 @@
(.*?)<\/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)
+ $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];
+ }
+ return($urls);
+}
+
+function html2plain($html, $wraplength = 75, $compact = false)
{
global $lang;
@@ -93,22 +130,16 @@ function html2plain($html)
$message = str_replace(array("\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"), array("<", ">", "
", " ", ""), $message);
$message = preg_replace('= [\s]*=i', " ", $message);
- // nach ... suchen, die ... miteinander vergleichen und bei Gleichheit durch ein einzelnes ... ersetzen.
- $pattern = '/(.*?)<\/a>/is';
- preg_match_all($pattern, $message, $result, PREG_SET_ORDER);
+ // Collecting all links
+ $urls = collecturls($message);
- foreach ($result as $treffer) {
- if ($treffer[1] == $treffer[2]) {
- $search = ''.$treffer[1].'';
- $message = str_replace($search, $treffer[1], $message);
- }
- }
@$doc->loadHTML($message);
node2bbcode($doc, 'html', array(), '', '');
node2bbcode($doc, 'body', array(), '', '');
// 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;'), '*', '*');
@@ -117,8 +148,12 @@ function html2plain($html)
node2bbcode($doc, 'b', array(), '*', '*');
node2bbcode($doc, 'i', array(), '/', '/');
node2bbcode($doc, 'u', array(), '_', '_');
+ */
- node2bbcode($doc, 'blockquote', array(), '[quote]', "[/quote]\n");
+ if ($compact)
+ node2bbcode($doc, 'blockquote', array(), "»", "«");
+ else
+ node2bbcode($doc, 'blockquote', array(), '[quote]', "[/quote]\n");
node2bbcode($doc, 'br', array(), "\n", '');
@@ -131,7 +166,7 @@ function html2plain($html)
//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", "");
@@ -143,16 +178,25 @@ function html2plain($html)
node2bbcode($doc, 'h5', array(), "\n\n*", "*\n");
node2bbcode($doc, 'h6', array(), "\n\n*", "*\n");
- node2bbcode($doc, 'a', array('href'=>'/(.+)/'), ' $1', '', true);
- node2bbcode($doc, 'img', array('alt'=>'/(.+)/'), '$1', '');
- node2bbcode($doc, 'img', array('title'=>'/(.+)/'), '$1', '');
- node2bbcode($doc, 'img', array(), '', '');
- node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
+ // 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, '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'=>'/(.+)/'), ' ', ' ');
+
+ node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), ' $1 ', '', true);
$message = $doc->saveHTML();
- $message = str_replace("[img]", "", $message);
- $message = str_replace("[/img]", "", $message);
+ if (!$compact) {
+ $message = str_replace("[img]", "", $message);
+ $message = str_replace("[/img]", "", $message);
+ }
// was ersetze ich da?
// Irgendein stoerrisches UTF-Zeug
@@ -168,12 +212,24 @@ function html2plain($html)
$message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
+ if (!$compact AND ($message != "")) {
+ $counter = 1;
+ foreach ($urls as $id=>$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);
} while ($oldmessage != $message);
- $message = quotelevel(trim($message));
+ $message = quotelevel(trim($message), $wraplength);
return(trim($message));
}