X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fhtml2bbcode.php;h=10a2fd13e5e24eb6be995d5fb7fbc92965e234da;hb=545a7a80e4c56fe58f8c810be7d5711d2fe5272d;hp=985c36eaa4499e5f03acbe72dbd52bb1159947ea;hpb=2bdbdc8d8ef229946e225791801e753a7fd5c695;p=friendica.git diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 985c36eaa4..10a2fd13e5 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -16,7 +16,7 @@ function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb) function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) { - $savestart = str_replace('$', '%', $startbb); + $savestart = str_replace('$', '\x01', $startbb); $replace = false; $xpath = new DomXPath($doc); @@ -37,7 +37,7 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) foreach ($attributes as $attribute => $value) { - $startbb = str_replace('%'.++$i, '$1', $startbb); + $startbb = str_replace('\x01'.++$i, '$1', $startbb); if (strpos('*'.$startbb, '$1') > 0) { @@ -76,28 +76,32 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) return($replace); } +if(!function_exists('deletenode')) { function deletenode(&$doc, $node) { $xpath = new DomXPath($doc); $list = $xpath->query("//".$node); foreach ($list as $child) $child->parentNode->removeChild($child); -} +}} function html2bbcode($message) { - //$file = tempnam("/tmp/", "html"); - //file_put_contents($file, $message); - $message = str_replace("\r", "", $message); + $message = preg_replace_callback("|
([^<]*)
|ism", function($m) { + return "".str_replace("\n","
\n",$m[1]). "
"; + }, $message); + $message = str_replace(array( "
  • ", - "

  • "), + "

    ", + ), array( "
  • ", - "
  • "), + "", + ), $message); // remove namespaces @@ -156,12 +160,19 @@ function html2bbcode($message) //node2bbcode($doc, 'span', array('style'=>'/.*font-size:\s*(.+?)[,;].*/'), '[size=$1]', '[/size]'); node2bbcode($doc, 'span', array('style'=>'/.*color:\s*(.+?)[,;].*/'), '[color="$1"]', '[/color]'); + //node2bbcode($doc, 'span', array('style'=>'/.*font-family:\s*(.+?)[,;].*/'), '[font=$1]', '[/font]'); //node2bbcode($doc, 'div', array('style'=>'/.*font-family:\s*(.+?)[,;].*font-size:\s*(\d+?)pt.*/'), '[font=$1][size=$2]', '[/size][/font]'); //node2bbcode($doc, 'div', array('style'=>'/.*font-family:\s*(.+?)[,;].*font-size:\s*(\d+?)px.*/'), '[font=$1][size=$2]', '[/size][/font]'); //node2bbcode($doc, 'div', array('style'=>'/.*font-family:\s*(.+?)[,;].*/'), '[font=$1]', '[/font]'); + // Importing the classes - interesting for importing of posts from third party networks that were exported from friendica + // Test + //node2bbcode($doc, 'span', array('class'=>'/([\w ]+)/'), '[class=$1]', '[/class]'); + node2bbcode($doc, 'span', array('class'=>'type-link'), '[class=type-link]', '[/class]'); + node2bbcode($doc, 'span', array('class'=>'type-video'), '[class=type-video]', '[/class]'); + node2bbcode($doc, 'strong', array(), '[b]', '[/b]'); node2bbcode($doc, 'em', array(), '[i]', '[/i]'); node2bbcode($doc, 'b', array(), '[b]', '[/b]'); @@ -182,6 +193,7 @@ function html2bbcode($message) node2bbcode($doc, 'span', array(), "", ""); node2bbcode($doc, 'pre', array(), "", ""); + node2bbcode($doc, 'div', array(), "\r", "\r"); node2bbcode($doc, 'p', array(), "\n", "\n"); @@ -199,13 +211,21 @@ function html2bbcode($message) //node2bbcode($doc, 'tr', array(), "[tr]", "[/tr]"); //node2bbcode($doc, 'td', array(), "[td]", "[/td]"); - node2bbcode($doc, 'h1', array(), "\n\n[size=xx-large][b]", "[/b][/size]\n"); - node2bbcode($doc, 'h2', array(), "\n\n[size=x-large][b]", "[/b][/size]\n"); - node2bbcode($doc, 'h3', array(), "\n\n[size=large][b]", "[/b][/size]\n"); - node2bbcode($doc, 'h4', array(), "\n\n[size=medium][b]", "[/b][/size]\n"); - node2bbcode($doc, 'h5', array(), "\n\n[size=small][b]", "[/b][/size]\n"); - node2bbcode($doc, 'h6', array(), "\n\n[size=x-small][b]", "[/b][/size]\n"); - + //node2bbcode($doc, 'h1', array(), "\n\n[size=xx-large][b]", "[/b][/size]\n"); + //node2bbcode($doc, 'h2', array(), "\n\n[size=x-large][b]", "[/b][/size]\n"); + //node2bbcode($doc, 'h3', array(), "\n\n[size=large][b]", "[/b][/size]\n"); + //node2bbcode($doc, 'h4', array(), "\n\n[size=medium][b]", "[/b][/size]\n"); + //node2bbcode($doc, 'h5', array(), "\n\n[size=small][b]", "[/b][/size]\n"); + //node2bbcode($doc, 'h6', array(), "\n\n[size=x-small][b]", "[/b][/size]\n"); + + node2bbcode($doc, 'h1', array(), "\n\n[h1]", "[/h1]\n"); + node2bbcode($doc, 'h2', array(), "\n\n[h2]", "[/h2]\n"); + node2bbcode($doc, 'h3', array(), "\n\n[h3]", "[/h3]\n"); + node2bbcode($doc, 'h4', array(), "\n\n[h4]", "[/h4]\n"); + node2bbcode($doc, 'h5', array(), "\n\n[h5]", "[/h5]\n"); + node2bbcode($doc, 'h6', array(), "\n\n[h6]", "[/h6]\n"); + + node2bbcode($doc, 'a', array('href'=>'/mailto:(.+)/'), '[mail=$1]', '[/mail]'); node2bbcode($doc, 'a', array('href'=>'/(.+)/'), '[url=$1]', '[/url]'); node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'width'=>'/(\d+)/', 'height'=>'/(\d+)/'), '[img=$2x$3]$1', '[/img]'); @@ -217,6 +237,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();