]> git.mxchange.org Git - friendica-addons.git/commitdiff
Twitter: avooid sending broken words at the end of a Tweet
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Sat, 7 Apr 2012 05:07:55 +0000 (07:07 +0200)
committerTobias Diekershoff <tobias.diekershoff@gmx.net>
Sat, 7 Apr 2012 05:07:55 +0000 (07:07 +0200)
twitter/twitter.php

index 8a072fa28bfdf2ed3b7c13ef8bd9f613de52a193..1dfc7391961a1316a26c7ce2ec7b2eccdc427ccf 100755 (executable)
@@ -345,7 +345,13 @@ function twitter_post_hook(&$a,&$b) {
                        $shortlink = short_link( $b['plink'] );
                        // the new message will be shortened such that "... $shortlink"
                        // will fit into the character limit
-                       $msg = substr($msg, 0, $max_char-strlen($shortlink)-4);
+                       $msg = nl2br(substr($msg, 0, $max_char-strlen($shortlink)-4));
+                        $msg = str_replace(array('<br>','<br />'),' ',$msg);
+                        $e = explode(' ', $msg);
+                        //  remove the last word from the cut down message to 
+                        //  avoid sending cut words to the MicroBlog
+                        array_pop($e);
+                        $msg = implode(' ', $e);
                        $msg .= '... ' . $shortlink;
                }
                // and now tweet it :-)