aboutsummaryrefslogtreecommitdiffstats
path: root/include/bb2diaspora.php
diff options
context:
space:
mode:
authorZvi ben Yaakov (a.k.a rdc) <coderzvi@infosoc.net>2012-06-25 13:59:53 +0300
committerZvi ben Yaakov (a.k.a rdc) <coderzvi@infosoc.net>2012-06-25 13:59:53 +0300
commit94f895e98df73efe32a7c986a4b7844b0ab8fc01 (patch)
tree92324c19bb13025d8f2f0087212348a039acbec6 /include/bb2diaspora.php
parent00668aaa71336f48b141c443749a66c58a555503 (diff)
parent7ea5917bf794c431fe304fa25380f19a6927cf63 (diff)
downloadvolse-hubzilla-94f895e98df73efe32a7c986a4b7844b0ab8fc01.tar.gz
volse-hubzilla-94f895e98df73efe32a7c986a4b7844b0ab8fc01.tar.bz2
volse-hubzilla-94f895e98df73efe32a7c986a4b7844b0ab8fc01.zip
Merge git://github.com/friendica/friendica
Diffstat (limited to 'include/bb2diaspora.php')
-rw-r--r--include/bb2diaspora.php50
1 files changed, 47 insertions, 3 deletions
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index 96cc735bd..ac693127b 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -68,9 +68,14 @@ function stripdcode_br_cb($s) {
function diaspora_ul($s) {
- // Replace "[\\*]" followed by any number (including zero) of
+ // Replace "[*]" followed by any number (including zero) of
// spaces by "* " to match Diaspora's list format
- return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]);
+ if( strpos($s[0], "[list]") === 0 )
+ return '<ul class="listbullet" style="list-style-type: circle;">' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[ul]") === 0 )
+ return '<ul class="listbullet" style="list-style-type: circle;">' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '</ul>';
+ else
+ return $s[0];
}
@@ -80,12 +85,45 @@ function diaspora_ol($s) {
// 1. First element
// 1. Second element
// 1. Third element
- return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]);
+ if( strpos($s[0], "[list=1]") === 0 )
+ return '<ul class="listdecimal" style="list-style-type: decimal;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=i]") === 0 )
+ return '<ul class="listlowerroman" style="list-style-type: lower-roman;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=I]") === 0 )
+ return '<ul class="listupperroman" style="list-style-type: upper-roman;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=a]") === 0 )
+ return '<ul class="listloweralpha" style="list-style-type: lower-alpha;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=A]") === 0 )
+ return '<ul class="listupperalpha" style="list-style-type: upper-alpha;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[ol]") === 0 )
+ return '<ul class="listdecimal" style="list-style-type: decimal;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ else
+ return $s[0];
}
function bb2diaspora($Text,$preserve_nl = false) {
+ // bbcode() will convert "[*]" into "<li>" with no closing "</li>"
+ // Markdownify() is unable to handle these, as it makes each new
+ // "<li>" into a deeper nested element until it crashes. So pre-format
+ // the lists as Diaspora lists before sending the $Text to bbcode()
+ //
+ // Note that regular expressions are really not suitable for parsing
+ // text with opening and closing tags, so nested lists may make things
+ // wonky
+ $endlessloop = 0;
+ while ((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false) && (++$endlessloop < 20)) {
+ $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text);
+ $Text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/is", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=i\](.*?)\[\/list\]/s",'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=I\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=a\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=A\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ }
+ $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text);
+ $Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
+
// Convert it to HTML - don't try oembed
$Text = bbcode($Text, $preserve_nl, false);
@@ -93,6 +131,12 @@ function bb2diaspora($Text,$preserve_nl = false) {
$md = new Markdownify(false, false, false);
$Text = $md->parseString($Text);
+ // If the text going into bbcode() has a plain URL in it, i.e.
+ // with no [url] tags around it, it will come out of parseString()
+ // looking like: <http://url.com>, which gets removed by strip_tags().
+ // So take off the angle brackets of any such URL
+ $Text = preg_replace("/<http(.*?)>/is", "http$1", $Text);
+
// Remove all unconverted tags
$Text = strip_tags($Text);