]> git.mxchange.org Git - friendica-addons.git/blobdiff - twitter/twitter.php
Removed deprecated addons
[friendica-addons.git] / twitter / twitter.php
index 76b92ac811f82733ead1fe7a9efc23ea7d30ccf2..1fdcb89ca773d59cede3b2f70978ff3a9442abee 100644 (file)
@@ -334,27 +334,33 @@ function twitter_settings(&$a,&$s) {
 }
 
 
-function twitter_post_local(&$a,&$b) {
+function twitter_post_local(&$a, &$b) {
 
-       if($b['edit'])
+       if ($b['edit']) {
                return;
+       }
 
-       if((local_user()) && (local_user() == $b['uid']) && (! $b['private']) && (! $b['parent']) ) {
+       if (!local_user() || (local_user() != $b['uid'])) {
+               return;
+       }
 
-               $twitter_post = intval(get_pconfig(local_user(),'twitter','post'));
-               $twitter_enable = (($twitter_post && x($_REQUEST,'twitter_enable')) ? intval($_REQUEST['twitter_enable']) : 0);
+       $twitter_post = intval(get_pconfig(local_user(), 'twitter', 'post'));
+       $twitter_enable = (($twitter_post && x($_REQUEST, 'twitter_enable')) ? intval($_REQUEST['twitter_enable']) : 0);
 
-               // if API is used, default to the chosen settings
-               if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'twitter','post_by_default')))
-                       $twitter_enable = 1;
+       // if API is used, default to the chosen settings
+       if ($b['api_source'] && intval(get_pconfig(local_user(), 'twitter', 'post_by_default'))) {
+               $twitter_enable = 1;
+       }
 
-       if(! $twitter_enable)
+       if (!$twitter_enable) {
                return;
+       }
 
-       if(strlen($b['postopts']))
+       if (strlen($b['postopts'])) {
                $b['postopts'] .= ',';
-               $b['postopts'] .= 'twitter';
        }
+
+       $b['postopts'] .= 'twitter';
 }
 
 function twitter_action($a, $uid, $pid, $action) {
@@ -545,8 +551,20 @@ function twitter_post_hook(&$a,&$b) {
                }
 
                if(strlen($msg) && ($image == "")) {
+// -----------------
+                       $max_char = 280;
+                       require_once("include/plaintext.php");
+                       $msgarr = plaintext($a, $b, $max_char, true, 8);
+                       $msg = $msgarr["text"];
+
+                       if (($msg == "") && isset($msgarr["title"]))
+                               $msg = shortenmsg($msgarr["title"], $max_char - 50);
+
+                       if (isset($msgarr["url"]))
+                               $msg .= "\n".$msgarr["url"];
+// -----------------
                        $url = 'statuses/update';
-                       $post = array('status' => $msg);
+                       $post = array('status' => $msg, 'weighted_character_count' => 'true');
 
                        if ($iscomment)
                                $post["in_reply_to_status_id"] = substr($orig_post["uri"], 9);