]> git.mxchange.org Git - friendica-addons.git/blobdiff - twitter/twitter.php
Preparations for shared posts
[friendica-addons.git] / twitter / twitter.php
index 4b7fcf57d234f3caa74c424d59ece463735009a4..ee3bd0fbda5467dcc85897f8e327a5bc9ff905c1 100755 (executable)
@@ -282,10 +282,9 @@ function twitter_shortenmsg($b) {
        // That means that we have to decode all image-urls
        $image = htmlspecialchars_decode($image);
 
-       if ($b["title"] == "")
-               $body = $b["body"];
-       else
-               $body = $b["title"];
+       $body = $b["body"];
+       if ($b["title"] != "")
+               $body = $b["title"]."\n\n".$body;
 
        // remove the recycle signs and the names since they aren't helpful on twitter
        // recycle 1
@@ -295,6 +294,9 @@ function twitter_shortenmsg($b) {
        $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
        $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
 
+       // remove the share element
+       $body = preg_replace("/\[share(.*?)\](.*?)\[\/share\]/ism","\n\n$2\n\n",$body);
+
        // At first convert the text to html
        $html = bbcode($body, false, false);
 
@@ -311,6 +313,9 @@ function twitter_shortenmsg($b) {
        while (strpos($msg, "  ") !== false)
                $msg = str_replace("  ", " ", $msg);
 
+       // Removing URLs
+       $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
+
        $msg = trim($msg);
 
        $link = '';
@@ -352,7 +357,7 @@ function twitter_shortenmsg($b) {
                $msg = substr($msg, 0, -1);
                $pos = strrpos($msg, "\n");
                if ($pos > 0)
-                       $msg = substr($msg, 0, $pos-1);
+                       $msg = substr($msg, 0, $pos);
                else if ($lastchar != "\n")
                        $msg = substr($msg, 0, -3)."...";
        }