Merge remote-tracking branch 'refs/remotes/friendica/develop' into develop
This commit is contained in:
commit
ce4eb1deb0
4 changed files with 59 additions and 49 deletions
|
@ -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", '<br>', $s);
|
||||
|
||||
$s = html2bbcode($s);
|
||||
|
||||
// protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands
|
||||
|
|
|
@ -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 "<code>".str_replace("\n","<br>\n",$m[1]). "</code>";
|
||||
}
|
||||
|
||||
function html2bbcode($message)
|
||||
{
|
||||
|
||||
$message = str_replace("\r", "", $message);
|
||||
|
||||
$message = preg_replace_callback("|<pre><code>([^<]*)</code></pre>|ism", "_replace_code_cb", $message);
|
||||
// Removing code blocks before the whitespace removal processing below
|
||||
$codeblocks = [];
|
||||
$message = preg_replace_callback('#<pre><code(?: class="([^"]*)")?>(.*)</code></pre>#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(
|
||||
"<li><p>",
|
||||
|
@ -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;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,78 +1,73 @@
|
|||
<?php
|
||||
|
||||
require_once('include/bbcode.php');
|
||||
require_once('library/markdown.php');
|
||||
require_once('include/bb2diaspora.php');
|
||||
require_once('include/html2bbcode.php');
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'library/markdown.php';
|
||||
require_once 'include/bb2diaspora.php';
|
||||
require_once 'include/html2bbcode.php';
|
||||
|
||||
function visible_lf($s) {
|
||||
return str_replace("\n",'<br />', $s);
|
||||
return str_replace("\n", '<br />', $s);
|
||||
}
|
||||
|
||||
function babel_content(App $a) {
|
||||
|
||||
$o .= '<h1>Babel Diagnostic</h1>';
|
||||
|
||||
$o .= '<form action="babel" method="post">';
|
||||
$o .= t('Source (bbcode) text:') . EOL . '<textarea name="text" >' . htmlspecialchars($_REQUEST['text']) .'</textarea>' . EOL;
|
||||
$o .= t('Source (bbcode) text:') . EOL;
|
||||
$o .= '<textarea name="text" cols="80" rows="10">' . htmlspecialchars($_REQUEST['text']) .'</textarea>' . EOL;
|
||||
$o .= '<input type="submit" name="submit" value="Submit" /></form>';
|
||||
|
||||
$o .= '<br /><br />';
|
||||
|
||||
$o .= '<form action="babel" method="post">';
|
||||
$o .= t('Source (Diaspora) text to convert to BBcode:') . EOL . '<textarea name="d2bbtext" >' . htmlspecialchars($_REQUEST['d2bbtext']) .'</textarea>' . EOL;
|
||||
$o .= t('Source (Diaspora) text to convert to BBcode:') . EOL;
|
||||
$o .= '<textarea name="d2bbtext" cols="80" rows="10">' . htmlspecialchars($_REQUEST['d2bbtext']) .'</textarea>' . EOL;
|
||||
$o .= '<input type="submit" name="submit" value="Submit" /></form>';
|
||||
|
||||
$o .= '<br /><br />';
|
||||
|
||||
if(x($_REQUEST,'text')) {
|
||||
|
||||
if (x($_REQUEST, 'text')) {
|
||||
$text = trim($_REQUEST['text']);
|
||||
$o .= "<h2>" . t("Source input: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('Source input: ') . '</h2>' . EOL. EOL;
|
||||
$o .= visible_lf($text) . EOL. EOL;
|
||||
|
||||
$html = bbcode($text);
|
||||
$o .= "<h2>" . t("bb2html (raw HTML): ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2html (raw HTML): ') . '</h2>' . EOL. EOL;
|
||||
$o .= htmlspecialchars($html). EOL. EOL;
|
||||
|
||||
//$html = bbcode($text);
|
||||
$o .= "<h2>" . t("bb2html: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2html: ') . '</h2>' . EOL. EOL;
|
||||
$o .= $html. EOL. EOL;
|
||||
|
||||
$bbcode = html2bbcode($html);
|
||||
$o .= "<h2>" . t("bb2html2bb: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2html2bb: ') . '</h2>' . EOL. EOL;
|
||||
$o .= visible_lf($bbcode) . EOL. EOL;
|
||||
|
||||
$diaspora = bb2diaspora($text);
|
||||
$o .= "<h2>" . t("bb2md: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2md: ') . '</h2>' . EOL. EOL;
|
||||
$o .= visible_lf($diaspora) . EOL. EOL;
|
||||
|
||||
$html = Markdown($diaspora);
|
||||
$o .= "<h2>" . t("bb2md2html: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2md2html: ') . '</h2>' . EOL. EOL;
|
||||
$o .= $html. EOL. EOL;
|
||||
|
||||
$bbcode = diaspora2bb($diaspora);
|
||||
$o .= "<h2>" . t("bb2dia2bb: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2dia2bb: ') . '</h2>' . EOL. EOL;
|
||||
$o .= visible_lf($bbcode) . EOL. EOL;
|
||||
|
||||
$bbcode = html2bbcode($html);
|
||||
$o .= "<h2>" . t("bb2md2html2bb: ") . "</h2>" . EOL. EOL;
|
||||
$o .= '<h2>' . t('bb2md2html2bb: ') . '</h2>' . EOL. EOL;
|
||||
$o .= visible_lf($bbcode) . EOL. EOL;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(x($_REQUEST,'d2bbtext')) {
|
||||
|
||||
if (x($_REQUEST, 'd2bbtext')) {
|
||||
$d2bbtext = trim($_REQUEST['d2bbtext']);
|
||||
$o .= "<h2>" . t("Source input (Diaspora format): ") . "</h2>" . EOL. EOL;
|
||||
$o .= visible_lf($d2bbtext) . EOL. EOL;
|
||||
|
||||
$o .= '<h2>' . t('Source input (Diaspora format): ') . '</h2>' . EOL. EOL;
|
||||
$o .= '<pre>' . $d2bbtext . '</pre>' . EOL. EOL;
|
||||
|
||||
$bb = diaspora2bb($d2bbtext);
|
||||
$o .= "<h2>" . t("diaspora2bb: ") . "</h2>" . EOL. EOL;
|
||||
$o .= visible_lf($bb) . EOL. EOL;
|
||||
$o .= '<h2>' . t('diaspora2bb: ') . '</h2>' . EOL. EOL;
|
||||
$o .= '<pre>' . $bb . '</pre>' . EOL. EOL;
|
||||
}
|
||||
|
||||
return $o;
|
||||
|
|
Loading…
Reference in a new issue