]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
bbcode: New element "share" for shared content
[friendica.git] / include / bbcode.php
index d83fe6c12f15efcb40e067d8953b46c7082169b4..b3f6aa826b6938390b4b94c62ecf0cd773ed1cfe 100644 (file)
@@ -206,7 +206,59 @@ function bb_replace_images($body, $images) {
        return $newbody;
 }}
 
+function bb_ShareAttributes($match) {
 
+        $attributes = $match[1];
+
+        $author = "";
+        preg_match("/author='(.*?)'/ism", $attributes, $matches);
+        if ($matches[1] != "")
+                $author = $matches[1];
+
+        preg_match('/author="(.*?)"/ism', $attributes, $matches);
+        if ($matches[1] != "")
+                $author = $matches[1];
+
+        $link = "";
+        preg_match("/link='(.*?)'/ism", $attributes, $matches);
+        if ($matches[1] != "")
+                $link = $matches[1];
+
+        preg_match('/link="(.*?)"/ism', $attributes, $matches);
+        if ($matches[1] != "")
+                $link = $matches[1];
+
+        $avatar = "";
+        preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
+        if ($matches[1] != "")
+                $avatar = $matches[1];
+
+        preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
+        if ($matches[1] != "")
+                $avatar = $matches[1];
+
+        $profile = "";
+        preg_match("/profile='(.*?)'/ism", $attributes, $matches);
+        if ($matches[1] != "")
+                $profile = $matches[1];
+
+        preg_match('/profile="(.*?)"/ism', $attributes, $matches);
+        if ($matches[1] != "")
+                $profile = $matches[1];
+
+        $headline = '<div class="shared_header">';
+
+       if ($avatar != "")
+               $headline .= '<img src="'.$avatar.'" height="32" width="32" >';
+
+       $headline .= sprintf(t('<span><a href="%s">%s</a> wrote the following <a href="%s">post</a>:</span>'), $profile, $author, $link);
+
+        $headline .= "</div>";
+
+        $text = "<br />".$headline.'<blockquote class="shared_content">'.trim($match[2])."</blockquote>";
+
+        return($text);
+}
 
        // BBcode 2 HTML was written by WAY2WEB.net
        // extended to work with Mistpark/Friendica - Mike Macgirvin
@@ -248,6 +300,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
        $Text = str_replace("<", "&lt;", $Text);
        $Text = str_replace(">", "&gt;", $Text);
 
+       // remove some newlines before the general conversion
+       $Text = preg_replace("/\s?\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","[share$1]$2[/share]",$Text);
+
+       // when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
+       if (!$tryoembed)
+               $Text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","\n[share$1$2]$3[/share]",$Text);
+
        // Convert new line chars to html <br /> tags
 
        // nlbr seems to be hopelessly messed up
@@ -271,7 +330,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 
        // Perform URL Search
 
-       $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
+       $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
 
        if ($tryoembed)
                $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
@@ -422,7 +481,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
        // [img]pathtoimage[/img]
        $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
 
-
+       // Shared content
+       $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text);
 
        $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
        $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);