]> git.mxchange.org Git - friendica-addons.git/blobdiff - twitter/twitter.php
Preparations for shared posts
[friendica-addons.git] / twitter / twitter.php
index 82d059ee2d28954e240130489784a1c38a8bbd80..ee3bd0fbda5467dcc85897f8e327a5bc9ff905c1 100755 (executable)
@@ -294,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);
 
@@ -310,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 = '';
@@ -351,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)."...";
        }