]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
dynamic delete icons for saved-search on network page
[friendica.git] / include / bbcode.php
index 8c565add6ccceff9a86da833822b9485e5716589..15b2ebb0a55c185e698476b2a07845cd8a91e634 100644 (file)
@@ -30,6 +30,24 @@ function tryoembed($match){
 
 function bbcode($Text,$preserve_nl = false) {
 
+
+       // Extract a single private image which uses data url's since preg has issues with 
+       // large data sizes. Stash it away while we do bbcode conversion, and then put it back 
+       // in after we've done all the regex matching. We cannot use any preg functions to do this.
+
+       $saved_image = '';
+       $img_start = strpos($Text,'[img]data:');
+       $img_end = strpos($Text,'[/img]');
+
+       if($img_start !== false && $img_end !== false && $img_end > $img_start) {
+               $start_fragment = substr($Text,0,$img_start);
+               $img_start += strlen('[img]');
+               $saved_image = substr($Text,$img_start,$img_end - $img_start);
+               $end_fragment = substr($Text,$img_end + strlen('[/img]'));              
+//             logger('saved_image: ' . $saved_image,LOGGER_DEBUG);
+               $Text = $start_fragment . '[$#saved_image#$]' . $end_fragment;
+       }
+
        // If we find any event code, turn it into an event.
        // After we're finished processing the bbcode we'll 
        // replace all of the event code with a reformatted version.
@@ -99,12 +117,16 @@ function bbcode($Text,$preserve_nl = false) {
        if(stristr($Text,'[/list]'))
                $Text = str_replace("[*]", "<li>", $Text);
 
-       $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet">$1</ul>' ,$Text);
-       $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal">$1</ul>' ,$Text);
-       $Text = preg_replace("/\[list=i\](.*?)\[\/list\]/sm",'<ul class="listlowerroman">$1</ul>' ,$Text);
-       $Text = preg_replace("/\[list=I\](.*?)\[\/list\]/sm", '<ul class="listupperroman">$1</ul>' ,$Text);
-       $Text = preg_replace("/\[list=a\](.*?)\[\/list\]/sm", '<ul class="listloweralpha">$1</ul>' ,$Text);
-       $Text = preg_replace("/\[list=A\](.*?)\[\/list\]/sm", '<ul class="listupperalpha">$1</ul>' ,$Text);
+       if(stristr($Text,'[/list]'))
+               $Text = str_replace("[*]", "<li>", $Text);
+
+       $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
+       $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>' ,$Text);
+       $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
+       $Text = preg_replace("/\[list=i\](.*?)\[\/list\]/sm",'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>' ,$Text);
+       $Text = preg_replace("/\[list=I\](.*?)\[\/list\]/sm", '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>' ,$Text);
+       $Text = preg_replace("/\[list=a\](.*?)\[\/list\]/sm", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>' ,$Text);
+       $Text = preg_replace("/\[list=A\](.*?)\[\/list\]/sm", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>' ,$Text);
        $Text = preg_replace("/\[li\](.*?)\[\/li\]/sm", '<li>$1</li>' ,$Text);
 
        $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>' ,$Text);
@@ -202,7 +224,9 @@ function bbcode($Text,$preserve_nl = false) {
 
        // fix any escaped ampersands that may have been converted into links
        $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text);
-       
+       if(strlen($saved_image))
+               $Text = str_replace('[$#saved_image#$]','<img src="' . $saved_image .'" alt="' . t('Image/photo') . '" />',$Text);
+
        call_hooks('bbcode',$Text);
 
        return $Text;