* Description: Relay public postings to a connected Twitter account
* Version: 1.0.4
* Author: Tobias Diekershoff <http://diekershoff.homeunix.net/friendika/profile/tobias>
+ * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
*/
while (strpos($msg, " ") !== false)
$msg = str_replace(" ", " ", $msg);
+ $origmsg = $msg;
+
// Removing URLs
$msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
if (($msglink == "") and strlen($msg) > $max_char)
$msglink = $b["plink"];
+ // If the message is short enough then don't modify it.
+ if ((strlen(trim($origmsg)) <= $max_char) AND ($msglink == ""))
+ return(trim($origmsg));
+
+ // If the message is short enough and the link exists in the original message don't modify it as well
+ // -3 because of the bad shortener of twitter
+ if ((strlen(trim($origmsg)) <= ($max_char - 3)) AND strpos($origmsg, $msglink))
+ return(trim($origmsg));
+
if (strlen($msglink) > 20)
$msglink = short_link($msglink);
- if (strlen(trim($msg." ".$msglink)) > $max_char) {
- $msg = substr($msg, 0, $max_char - (strlen($msglink)));
+ if (strlen(trim($msg." ".$msglink)) > ($max_char - 3)) {
+ $msg = substr($msg, 0, ($max_char - 3) - (strlen($msglink)));
$lastchar = substr($msg, -1);
$msg = substr($msg, 0, -1);
$pos = strrpos($msg, "\n");
// ok, all the links we want to send out are save, now strip
// away the remaining bbcode
//$msg = strip_tags(bbcode($tmp, false, false));
- $msg = bbcode($tmp, false, false);
+ $msg = bbcode($tmp, false, false, true);
$msg = str_replace(array('<br>','<br />'),"\n",$msg);
$msg = strip_tags($msg);
$parameters["since_id"] = $lastid;
$items = $connection->get('statuses/user_timeline', $parameters);
+
+ if (!is_array($items))
+ return;
+
$posts = array_reverse($items);
if (count($posts)) {