aboutsummaryrefslogtreecommitdiffstats
path: root/include/bb2diaspora.php
diff options
context:
space:
mode:
authorMichael Vogel <icarus@dabo.de>2012-06-17 19:49:05 +0200
committerMichael Vogel <icarus@dabo.de>2012-06-17 19:49:05 +0200
commit3968e77f9e15c149d8cafa1dac37411777bd58bd (patch)
tree860447e502067a1204d87be4955b63f2eac69e39 /include/bb2diaspora.php
parent7c2d27e2750dc0b6cc7448f8e85b25a3c9b09687 (diff)
downloadvolse-hubzilla-3968e77f9e15c149d8cafa1dac37411777bd58bd.tar.gz
volse-hubzilla-3968e77f9e15c149d8cafa1dac37411777bd58bd.tar.bz2
volse-hubzilla-3968e77f9e15c149d8cafa1dac37411777bd58bd.zip
New function to convert bbcode to markdown.
Diffstat (limited to 'include/bb2diaspora.php')
-rw-r--r--include/bb2diaspora.php39
1 files changed, 25 insertions, 14 deletions
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index d86ba4543..0617ecc5f 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -1,10 +1,11 @@
<?php
require_once("include/oembed.php");
-require_once('include/event.php');
-
-require_once('library/markdown.php');
-require_once('include/html2bbcode.php');
+require_once("include/event.php");
+require_once("library/markdown.php");
+require_once("include/html2bbcode.php");
+require_once("include/bbcode.php");
+require_once("include/markdownify/markdownify.php");
// we don't want to support a bbcode specific markdown interpreter
// and the markdown library we have is pretty good, but provides HTML output.
@@ -78,13 +79,23 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = str_replace(">", "&gt;", $Text);
// If we find any event code, turn it into an event.
- // After we're finished processing the bbcode we'll
+ // After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
-
if($preserve_nl)
$Text = str_replace(array("\n","\r"), array('',''),$Text);
+ // Convert it to HTML
+ $Text = bbcode($Text);
+
+ // Now convert HTML to Markdown
+ $md = new Markdownify(false, false, false);
+ $Text = $md->parseString($Text);
+
+ // Remove all unconverted tags
+ $Text = strip_tags($Text);
+
+/*
// Set up the parameters for a URL search string
$URLSearchString = "^\[\]";
// Set up the parameters for a MAIL search string
@@ -98,7 +109,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// new javascript markdown processor to handle links with images as the link "text"
// It is not optimal and may be removed if this ability is restored in the future
- $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism",
+ $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism",
'![' . t('image/photo') . '](' . '$2' . ')' . "\n" . '[' . t('link') . '](' . '$1' . ')', $Text);
$Text = preg_replace("/\[bookmark\]([$URLSearchString]*)\[\/bookmark\]/ism", '[$1]($1)', $Text);
@@ -115,7 +126,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// Perform MAIL Search
$Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text);
$Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '[$2](mailto:$1)', $Text);
-
+
$Text = str_replace('*', '\\*', $Text);
$Text = str_replace('_', '\\_', $Text);
@@ -158,7 +169,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/s", '<table border="1" >$1</table>' ,$Text);
// $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/s", '<table border="0" >$1</table>' ,$Text);
-
+
// $Text = str_replace("[*]", "<li>", $Text);
// Check for font change text
@@ -174,10 +185,10 @@ function bb2diaspora($Text,$preserve_nl = false) {
// Declare the format for [quote] layout
- // $QuoteLayout = '<blockquote>$1</blockquote>';
+ // $QuoteLayout = '<blockquote>$1</blockquote>';
// Check for [quote] text
$Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is",">$1\n\n", $Text);
-
+
// Images
// html5 video and audio
@@ -187,7 +198,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text);
// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
-
+
// [img=widthxheight]image source[/img]
// $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/", '<img src="$3" style="height:{$2}px; width:{$1}px;" >', $Text);
@@ -211,7 +222,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
if(x($ev,'desc') && x($ev,'start')) {
$sub = format_event_diaspora($ev);
-
+
$Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/is",$sub,$Text);
$Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/is",'',$Text);
$Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/is",'',$Text);
@@ -222,7 +233,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text);
$Text = preg_replace_callback('/\[(.*?)\]\((.*?)\)/ism','unescape_underscores_in_links',$Text);
-
+*/
call_hooks('bb2diaspora',$Text);
return $Text;