X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fhtml2bbcode.php;h=189ba91f19c847e673844367c10c9a02054da19b;hb=d49325d177cf03b97df250ca3cb081421c541049;hp=1021bcdf165639e19f856a9669fd711b475ca9af;hpb=3b9a8daeeb2994cbf8f88dd07aa8334ca6527fde;p=friendica.git
diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index 1021bcdf16..189ba91f19 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -1,11 +1,14 @@
query("//".$node);
- foreach ($list as $child)
- $child->parentNode->removeChild($child);
-}}
+function _replace_code_cb($m){
+ return "".str_replace("\n","
\n",$m[1]). "
";
+}
function html2bbcode($message)
{
- //$file = tempnam("/tmp/", "html");
- //file_put_contents($file, $message);
-
$message = str_replace("\r", "", $message);
+ $message = preg_replace_callback("|
([^<]*)
|ism", "_replace_code_cb", $message);
+
$message = str_replace(array(
"",
- "
"),
+ "",
+ ),
array(
"",
- ""),
+ "",
+ ),
$message);
// remove namespaces
@@ -112,12 +111,12 @@ function html2bbcode($message)
@$doc->loadHTML($message);
- deletenode($doc, 'style');
- deletenode($doc, 'head');
- deletenode($doc, 'title');
- deletenode($doc, 'meta');
- deletenode($doc, 'xml');
- deletenode($doc, 'removeme');
+ xml::deleteNode($doc, 'style');
+ xml::deleteNode($doc, 'head');
+ xml::deleteNode($doc, 'title');
+ xml::deleteNode($doc, 'meta');
+ xml::deleteNode($doc, 'xml');
+ xml::deleteNode($doc, 'removeme');
$xpath = new DomXPath($doc);
$list = $xpath->query("//pre");
@@ -190,6 +189,7 @@ function html2bbcode($message)
node2bbcode($doc, 'span', array(), "", "");
node2bbcode($doc, 'pre', array(), "", "");
+
node2bbcode($doc, 'div', array(), "\r", "\r");
node2bbcode($doc, 'p', array(), "\n", "\n");
@@ -233,6 +233,7 @@ function html2bbcode($message)
node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
node2bbcode($doc, 'code', array(), '[code]', '[/code]');
+ node2bbcode($doc, 'key', array(), '[code]', '[/code]');
$message = $doc->saveHTML();