]> git.mxchange.org Git - friendica-addons.git/commitdiff
Statusnet/Twitter: When a message is less than 140 digits the post isn't modified...
authorMichael Vogel <icarus@dabo.de>
Fri, 29 Mar 2013 10:19:57 +0000 (11:19 +0100)
committerMichael Vogel <icarus@dabo.de>
Fri, 29 Mar 2013 10:19:57 +0000 (11:19 +0100)
statusnet/statusnet.php
twitter/twitter.php

index 77bff7a44fe199d7494a43008f490aa7f7639e47..0a9f0d8d439f2bd0379847703f9979d9f1680fc6 100755 (executable)
@@ -498,6 +498,8 @@ function statusnet_shortenmsg($b, $max_char) {
        while (strpos($msg, "  ") !== false)
                $msg = str_replace("  ", " ", $msg);
 
+       $origmsg = $msg;
+
        // Removing URLs
        $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
 
@@ -533,6 +535,10 @@ function statusnet_shortenmsg($b, $max_char) {
        if (($msglink == "") and strlen($msg) > $max_char)
                $msglink = $b["plink"];
 
+       // If the message is short enough then don't modify it. (if the link exists in the original message)
+       if ((strlen(trim($origmsg)) <= $max_char) AND (strpos($origmsg, $msglink) OR ($msglink == "")))
+               return(array("msg"=>trim($origmsg), "image"=>""));
+
        if (strlen($msglink) > 20)
                $msglink = short_link($msglink);
 
index e4848f9db8122cb63f0878477c55246c340da945..8941508eb903a95d791a7d6c59e394c4ae549f96 100755 (executable)
@@ -351,6 +351,8 @@ function twitter_shortenmsg($b) {
        while (strpos($msg, "  ") !== false)
                $msg = str_replace("  ", " ", $msg);
 
+       $origmsg = $msg;
+
        // Removing URLs
        $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
 
@@ -386,6 +388,10 @@ function twitter_shortenmsg($b) {
        if (($msglink == "") and strlen($msg) > $max_char)
                $msglink = $b["plink"];
 
+       // If the message is short enough then don't modify it. (if the link exists in the original message)
+       if ((strlen(trim($origmsg)) <= $max_char) AND (strpos($origmsg, $msglink) OR ($msglink == "")))
+               return(trim($origmsg));
+
        if (strlen($msglink) > 20)
                $msglink = short_link($msglink);