]> git.mxchange.org Git - friendica-addons.git/commitdiff
SN: avoide to send broken last words to SN when shorten a message
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Sat, 7 Apr 2012 05:02:55 +0000 (07:02 +0200)
committerTobias Diekershoff <tobias.diekershoff@gmx.net>
Sat, 7 Apr 2012 05:02:55 +0000 (07:02 +0200)
statusnet/statusnet.php

index 13f3f7e2c1819af1eb0bba8f6cea89d0eb3dbd24..62ee8e8bbb8932ebf4760122a795fa1a0135ac26 100755 (executable)
@@ -480,7 +480,13 @@ function statusnet_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 :-)