$s = str_replace("\r","",$s);
// <br/> is invalid. Replace it with the valid expression
- $s = str_replace("<br/>","<br />",$s);
+ logger("diaspora2bb: 1: ".$s);
+ $s = str_replace(array("<br/>", "</p>", "<p>"),array("<br />", "<br />", "<br />"),$s);
+ logger("diaspora2bb: 2: ".$s);
$s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s);
function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
+ // Since Diaspora is creating a summary for links, this function removes them before posting
+ if ($fordiaspora)
+ $Text = bb_remove_share_information($Text);
+
// Re-enabling the converter again.
// The bbcode parser now handles youtube-links (and the other stuff) correctly.
// Additionally the html code is now fixed so that lists are now working.
// $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism",
// "[url]$1[/url]\n[img]$2[/img]", $Text);
+ // Remove the avatar picture since that isn't looking good on the other side
+ //$Text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","\n[share$1$2]$3[/share]",$Text);
+
// Convert it to HTML - don't try oembed
- $Text = bbcode($Text, $preserve_nl, false);
+ if ($fordiaspora)
+ $Text = bbcode($Text, $preserve_nl, false, 3);
+ else
+ $Text = bbcode($Text, $preserve_nl, false, 4);
// Now convert HTML to Markdown
$md = new Markdownify(false, false, false);
$Text = $md->parseString($Text);
+ // The Markdownify converter converts underscores '_' in URLs to '\_', which
+ // messes up the URL. Manually fix these
+ $count = 1;
+ $pos = bb_find_open_close($Text, '[', ']', $count);
+ while($pos !== false) {
+ $start = substr($Text, 0, $pos['start']);
+ $subject = substr($Text, $pos['start'], $pos['end'] - $pos['start'] + 1);
+ $end = substr($Text, $pos['end'] + 1);
+
+ $subject = str_replace('\_', '_', $subject);
+ $Text = $start . $subject . $end;
+
+ $count++;
+ $pos = bb_find_open_close($Text, '[', ']', $count);
+ }
+
// 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().