diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index e509999236..03eff5a6b7 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -59,15 +59,6 @@ function diaspora2bb($s) { $s = str_replace('#', '#', $s); - $search = array(" \n", "\n "); - $replace = array("\n", "\n"); - do { - $oldtext = $s; - $s = str_replace($search, $replace, $s); - } while ($oldtext != $s); - - $s = str_replace("\n\n", '
', $s); - $s = html2bbcode($s); // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 189ba91f19..c14629b895 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -2,7 +2,7 @@ /** * @file include/html2bbcode.php * @brief Converter for HTML to BBCode - * + * * Made by: ike@piratenpartei.de * Originally made for the syncom project: http://wiki.piratenpartei.de/Syncom * https://github.com/annando/Syncom @@ -79,16 +79,25 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) return($replace); } -function _replace_code_cb($m){ - return "".str_replace("\n","
\n",$m[1]). "
"; -} - function html2bbcode($message) { $message = str_replace("\r", "", $message); - $message = preg_replace_callback("|
([^<]*)
|ism", "_replace_code_cb", $message); + // Removing code blocks before the whitespace removal processing below + $codeblocks = []; + $message = preg_replace_callback('#
(.*)
#iUs', + function ($matches) use (&$codeblocks) { + $return = '[codeblock-' . count($codeblocks) . ']'; + + $prefix = '[code]'; + if ($matches[1] != '') { + $prefix = '[code=' . $matches[1] . ']'; + } + $codeblocks[] = $prefix . $matches[2] . '[/code]'; + return $return; + } + , $message); $message = str_replace(array( "
  • ", @@ -232,7 +241,6 @@ function html2bbcode($message) node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]'); node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]'); - node2bbcode($doc, 'code', array(), '[code]', '[/code]'); node2bbcode($doc, 'key', array(), '[code]', '[/code]'); $message = $doc->saveHTML(); @@ -302,6 +310,19 @@ function html2bbcode($message) // Handling Yahoo style of mails $message = str_replace('[hr][b]From:[/b]', '[quote][b]From:[/b]', $message); - return(trim($message)); + // Restore code blocks + $message = preg_replace_callback('#\[codeblock-([0-9]+)\]#iU', + function ($matches) use ($codeblocks) { + $return = ''; + if (isset($codeblocks[intval($matches[1])])) { + $return = $codeblocks[$matches[1]]; + } + return $return; + } + , $message); + + $message = trim($message); + + return $message; } ?> diff --git a/include/ostatus.php b/include/ostatus.php index 931ea870fc..e6087de087 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -799,6 +799,9 @@ class ostatus { /// @todo This function is totally ugly and has to be rewritten totally + // Import all threads or only threads that were started by our followers? + $all_threads = !get_config('system','ostatus_full_threads'); + $item_stored = -1; $conversation_url = self::fetch_conversation($self, $conversation_url); @@ -807,8 +810,8 @@ class ostatus { // Don't do a completion on liked content if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR ($item["verb"] == ACTIVITY_LIKE) OR ($conversation_url == "")) { - $item_stored = item_store($item, true); - return($item_stored); + $item_stored = item_store($item, $all_threads); + return $item_stored; } // Get the parent @@ -888,7 +891,7 @@ class ostatus { if (!sizeof($items)) { if (count($item) > 0) { - $item_stored = item_store($item, true); + $item_stored = item_store($item, $all_threads); if ($item_stored) { logger("Conversation ".$conversation_url." couldn't be fetched. Item uri ".$item["uri"]." stored: ".$item_stored, LOGGER_DEBUG); @@ -1186,7 +1189,7 @@ class ostatus { } } - $item_stored = item_store($item, true); + $item_stored = item_store($item, $all_threads); if ($item_stored) { logger("Uri ".$item["uri"]." wasn't found in conversation ".$conversation_url, LOGGER_DEBUG); self::store_conversation($item_stored, $conversation_url); diff --git a/mod/babel.php b/mod/babel.php index e8ea11c94e..f71863bded 100644 --- a/mod/babel.php +++ b/mod/babel.php @@ -1,78 +1,73 @@ ', $s); + return str_replace("\n", '
    ', $s); } function babel_content(App $a) { - $o .= '

    Babel Diagnostic

    '; $o .= '
    '; - $o .= t('Source (bbcode) text:') . EOL . '' . EOL; + $o .= t('Source (bbcode) text:') . EOL; + $o .= '' . EOL; $o .= '
    '; $o .= '

    '; $o .= '
    '; - $o .= t('Source (Diaspora) text to convert to BBcode:') . EOL . '' . EOL; + $o .= t('Source (Diaspora) text to convert to BBcode:') . EOL; + $o .= '' . EOL; $o .= '
    '; $o .= '

    '; - if(x($_REQUEST,'text')) { - + if (x($_REQUEST, 'text')) { $text = trim($_REQUEST['text']); - $o .= "

    " . t("Source input: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('Source input: ') . '

    ' . EOL. EOL; $o .= visible_lf($text) . EOL. EOL; $html = bbcode($text); - $o .= "

    " . t("bb2html (raw HTML): ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2html (raw HTML): ') . '

    ' . EOL. EOL; $o .= htmlspecialchars($html). EOL. EOL; //$html = bbcode($text); - $o .= "

    " . t("bb2html: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2html: ') . '

    ' . EOL. EOL; $o .= $html. EOL. EOL; $bbcode = html2bbcode($html); - $o .= "

    " . t("bb2html2bb: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2html2bb: ') . '

    ' . EOL. EOL; $o .= visible_lf($bbcode) . EOL. EOL; $diaspora = bb2diaspora($text); - $o .= "

    " . t("bb2md: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2md: ') . '

    ' . EOL. EOL; $o .= visible_lf($diaspora) . EOL. EOL; $html = Markdown($diaspora); - $o .= "

    " . t("bb2md2html: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2md2html: ') . '

    ' . EOL. EOL; $o .= $html. EOL. EOL; $bbcode = diaspora2bb($diaspora); - $o .= "

    " . t("bb2dia2bb: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2dia2bb: ') . '

    ' . EOL. EOL; $o .= visible_lf($bbcode) . EOL. EOL; $bbcode = html2bbcode($html); - $o .= "

    " . t("bb2md2html2bb: ") . "

    " . EOL. EOL; + $o .= '

    ' . t('bb2md2html2bb: ') . '

    ' . EOL. EOL; $o .= visible_lf($bbcode) . EOL. EOL; - - - } - if(x($_REQUEST,'d2bbtext')) { - + if (x($_REQUEST, 'd2bbtext')) { $d2bbtext = trim($_REQUEST['d2bbtext']); - $o .= "

    " . t("Source input (Diaspora format): ") . "

    " . EOL. EOL; - $o .= visible_lf($d2bbtext) . EOL. EOL; - + $o .= '

    ' . t('Source input (Diaspora format): ') . '

    ' . EOL. EOL; + $o .= '
    ' . $d2bbtext . '
    ' . EOL. EOL; $bb = diaspora2bb($d2bbtext); - $o .= "

    " . t("diaspora2bb: ") . "

    " . EOL. EOL; - $o .= visible_lf($bb) . EOL. EOL; + $o .= '

    ' . t('diaspora2bb: ') . '

    ' . EOL. EOL; + $o .= '
    ' . $bb . '
    ' . EOL. EOL; } return $o;