]> git.mxchange.org Git - friendica-addons.git/commitdiff
Update Twitter addon documentation, file comment
authorHypolite Petovan <mrpetovan@gmail.com>
Sun, 28 Jan 2018 04:20:09 +0000 (23:20 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Sun, 28 Jan 2018 04:20:09 +0000 (23:20 -0500)
- Fix formatting

twitter/LICENSE
twitter/README.md
twitter/twitter.php
twitter/twitter_sync.php

index 062cc88805d0f08c09c3660433c8d02f42eb1711..496cce20dbe65087330a248d3a9f80c718de0220 100644 (file)
@@ -1,4 +1,4 @@
-Copyright (c) 2011-2013 Tobias Diekershoff, Michael Vogel
+Copyright (c) 2011-2018 Tobias Diekershoff, Michael Vogel, Hypolite Petovan
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
index 7936f894ef23278c2b4e397280c271d19b96607f..5a48869007148fa3610e5fae4b8c9fcf4ab47185 100644 (file)
@@ -1,39 +1,23 @@
 Twitter Addon
 ==============
 
 Twitter Addon
 ==============
 
-Main authors Tobias Diekershoff and Michael Vogel.
+Main authors Tobias Diekershoff, Michael Vogel and Hypolite Petovan.
 
 
-With this addon to friendica you can give your users the possibility to post their *public* messages to Twitter and 
-to import their timeline. The messages will be strapped their rich context and shortened to 280 characters length if 
-necessary.
+This bi-directional connector addon allows each user to crosspost their Friendica public posts to Twitter, import their
+Twitter timeline, interact with tweets from Friendica, and crosspost to Friendica their public tweets.
 
 
-The addon can also mirror a users Tweets into the ~friendica wall.
+## Installation
 
 
-Installation
-------------
-
-To use this addon you have to register an [application](https://apps.twitter.com/) for your friendica instance on Twitter. Please leave the field "Callback URL" empty.
+To use this addon you have to register an [application](https://apps.twitter.com/) for your Friendica instance on Twitter.
+Please leave the field "Callback URL" empty.
 
 After the registration please enter the values for "Consumer Key" and "Consumer Secret" in the [administration](admin/addons/twitter).
 
 
 After the registration please enter the values for "Consumer Key" and "Consumer Secret" in the [administration](admin/addons/twitter).
 
-Where to find
--------------
-
-In the friendica addon git repository /twitter/, this directory contains
-all required PHP files (including the [Twitter OAuth library][1] by Abraham
-Williams, MIT licensed and the [Slinky library][2] by Beau Lebens, BSD license),
-a CSS file for styling of the user configuration and an image to _Sign in with
-Twitter_.
-
-[1]: https://github.com/abraham/twitteroauth
-[2]: http://dentedreality.com.au/projects/slinky/
-
-License
-=======
-
-The _StatusNet Connector_ is licensed under the [3-clause BSD license][3] see the
-LICENSE file in the addons directory.
+## License
 
 
-[3]: http://opensource.org/licenses/BSD-3-Clause
+The _Twitter Connector_ is licensed under the [3-clause BSD license][2] see the LICENSE file in the addons directory.
 
 
+The _Twitter Connector_ uses the [Twitter OAuth library][2] by Abraham Williams, MIT licensed
 
 
+[1]: http://opensource.org/licenses/BSD-3-Clause
+[2]: https://github.com/abraham/twitteroauth
index fabdc6bd0c88a8e36b21c445ec882b4a69be0756..38b4728a1e9d7ebb2e71ac8afd187e5d51405bc3 100644 (file)
@@ -2,11 +2,12 @@
 /**
  * Name: Twitter Connector
  * Description: Bidirectional (posting, relaying and reading) connector for Twitter.
 /**
  * Name: Twitter Connector
  * Description: Bidirectional (posting, relaying and reading) connector for Twitter.
- * Version: 1.0.4
+ * Version: 1.1.0
  * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
  * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
+ * Maintainer: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
  *
  *
- * Copyright (c) 2011-2013 Tobias Diekershoff, Michael Vogel
+ * Copyright (c) 2011-2013 Tobias Diekershoff, Michael Vogel, Hypolite Petovan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -56,7 +57,7 @@
  *     setting. After this, your user can configure their Twitter account settings
  *     from "Settings -> Addon Settings".
  *
  *     setting. After this, your user can configure their Twitter account settings
  *     from "Settings -> Addon Settings".
  *
- *     Requirements: PHP5, curl [Slinky library]
+ *     Requirements: PHP5, curl
  */
 
 use Abraham\TwitterOAuth\TwitterOAuth;
  */
 
 use Abraham\TwitterOAuth\TwitterOAuth;
@@ -151,9 +152,9 @@ function twitter_follow(App $a, &$contact)
 
        $uid = $a->user["uid"];
 
 
        $uid = $a->user["uid"];
 
-       $ckey    = Config::get('twitter', 'consumerkey');
+       $ckey = Config::get('twitter', 'consumerkey');
        $csecret = Config::get('twitter', 'consumersecret');
        $csecret = Config::get('twitter', 'consumersecret');
-       $otoken  = PConfig::get($uid, 'twitter', 'oauthtoken');
+       $otoken = PConfig::get($uid, 'twitter', 'oauthtoken');
        $osecret = PConfig::get($uid, 'twitter', 'oauthsecret');
 
        $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
        $osecret = PConfig::get($uid, 'twitter', 'oauthsecret');
 
        $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
@@ -257,10 +258,10 @@ function twitter_settings(App $a, &$s)
         * 2) If no OAuthtoken & stuff is present, generate button to get some
         * 3) Checkbox for "Send public notices (280 chars only)
         */
         * 2) If no OAuthtoken & stuff is present, generate button to get some
         * 3) Checkbox for "Send public notices (280 chars only)
         */
-       $ckey    = Config::get('twitter', 'consumerkey' );
-       $csecret = Config::get('twitter', 'consumersecret' );
-       $otoken  = PConfig::get(local_user(), 'twitter', 'oauthtoken'  );
-       $osecret = PConfig::get(local_user(), 'twitter', 'oauthsecret' );
+       $ckey    = Config::get('twitter', 'consumerkey');
+       $csecret = Config::get('twitter', 'consumersecret');
+       $otoken  = PConfig::get(local_user(), 'twitter', 'oauthtoken');
+       $osecret = PConfig::get(local_user(), 'twitter', 'oauthsecret');
 
        $enabled            = intval(PConfig::get(local_user(), 'twitter', 'post'));
        $defenabled         = intval(PConfig::get(local_user(), 'twitter', 'post_by_default'));
 
        $enabled            = intval(PConfig::get(local_user(), 'twitter', 'post'));
        $defenabled         = intval(PConfig::get(local_user(), 'twitter', 'post_by_default'));
@@ -425,7 +426,10 @@ function twitter_post_hook(App $a, &$b)
                logger("twitter_post_hook: parameter " . print_r($b, true), LOGGER_DATA);
 
                // Looking if its a reply to a twitter post
                logger("twitter_post_hook: parameter " . print_r($b, true), LOGGER_DATA);
 
                // Looking if its a reply to a twitter post
-               if ((substr($b["parent-uri"], 0, 9) != "twitter::") && (substr($b["extid"], 0, 9) != "twitter::") && (substr($b["thr-parent"], 0, 9) != "twitter::")) {
+               if ((substr($b["parent-uri"], 0, 9) != "twitter::")
+                       && (substr($b["extid"], 0, 9) != "twitter::")
+                       && (substr($b["thr-parent"], 0, 9) != "twitter::"))
+               {
                        logger("twitter_post_hook: no twitter post " . $b["parent"]);
                        return;
                }
                        logger("twitter_post_hook: no twitter post " . $b["parent"]);
                        return;
                }
@@ -474,10 +478,12 @@ function twitter_post_hook(App $a, &$b)
 
        if ($b['verb'] == ACTIVITY_LIKE) {
                logger("twitter_post_hook: parameter 2 " . substr($b["thr-parent"], 9), LOGGER_DEBUG);
 
        if ($b['verb'] == ACTIVITY_LIKE) {
                logger("twitter_post_hook: parameter 2 " . substr($b["thr-parent"], 9), LOGGER_DEBUG);
-               if ($b['deleted'])
+               if ($b['deleted']) {
                        twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "unlike");
                        twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "unlike");
-               else
+               } else {
                        twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "like");
                        twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "like");
+               }
+
                return;
        }
 
                return;
        }
 
@@ -619,8 +625,8 @@ function twitter_post_hook(App $a, &$b)
 
 function twitter_addon_admin_post(App $a)
 {
 
 function twitter_addon_admin_post(App $a)
 {
-       $consumerkey     = x($_POST, 'consumerkey')     ? notags(trim($_POST['consumerkey']))     : '';
-       $consumersecret  = x($_POST, 'consumersecret')  ? notags(trim($_POST['consumersecret']))  : '';
+       $consumerkey    = x($_POST, 'consumerkey')    ? notags(trim($_POST['consumerkey']))    : '';
+       $consumersecret = x($_POST, 'consumersecret') ? notags(trim($_POST['consumersecret'])) : '';
        Config::set('twitter', 'consumerkey', $consumerkey);
        Config::set('twitter', 'consumersecret', $consumersecret);
        info(L10n::t('Settings updated.') . EOL);
        Config::set('twitter', 'consumerkey', $consumerkey);
        Config::set('twitter', 'consumersecret', $consumersecret);
        info(L10n::t('Settings updated.') . EOL);
@@ -665,8 +671,9 @@ function twitter_cron(App $a, $b)
        }
 
        $abandon_days = intval(Config::get('system', 'account_abandon_days'));
        }
 
        $abandon_days = intval(Config::get('system', 'account_abandon_days'));
-       if ($abandon_days < 1)
+       if ($abandon_days < 1) {
                $abandon_days = 0;
                $abandon_days = 0;
+       }
 
        $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400);
 
 
        $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400);
 
@@ -803,7 +810,14 @@ function twitter_do_mirrorpost(App $a, $uid, $post)
                // We don't support nested shares, so we mustn't show quotes as shares on retweets
                $item = twitter_createpost($a, $uid, $post->retweeted_status, ['id' => 0], false, false, true);
 
                // We don't support nested shares, so we mustn't show quotes as shares on retweets
                $item = twitter_createpost($a, $uid, $post->retweeted_status, ['id' => 0], false, false, true);
 
-               $datarray['body'] = "\n" . share_header($item['author-name'], $item['author-link'], $item['author-avatar'], "", $item['created'], $item['plink']);
+               $datarray['body'] = "\n" . share_header(
+                       $item['author-name'],
+                       $item['author-link'],
+                       $item['author-avatar'],
+                       "",
+                       $item['created'],
+                       $item['plink']
+               );
 
                $datarray['body'] .= $item['body'] . '[/share]';
        } else {
 
                $datarray['body'] .= $item['body'] . '[/share]';
        } else {
@@ -977,7 +991,8 @@ function twitter_fetch_contact($uid, $contact, $create_user)
                "addr" => $contact->screen_name . "@twitter.com", "generation" => 2]);
 
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
                "addr" => $contact->screen_name . "@twitter.com", "generation" => 2]);
 
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
-               intval($uid), dbesc("twitter::" . $contact->id_str));
+               intval($uid),
+               dbesc("twitter::" . $contact->id_str));
 
        if (!count($r) && !$create_user) {
                return 0;
 
        if (!count($r) && !$create_user) {
                return 0;
@@ -1095,9 +1110,9 @@ function twitter_fetch_contact($uid, $contact, $create_user)
 
 function twitter_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
 {
 
 function twitter_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
 {
-       $ckey    = Config::get('twitter', 'consumerkey');
+       $ckey = Config::get('twitter', 'consumerkey');
        $csecret = Config::get('twitter', 'consumersecret');
        $csecret = Config::get('twitter', 'consumersecret');
-       $otoken  = PConfig::get($uid, 'twitter', 'oauthtoken');
+       $otoken = PConfig::get($uid, 'twitter', 'oauthtoken');
        $osecret = PConfig::get($uid, 'twitter', 'oauthsecret');
 
        $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
        $osecret = PConfig::get($uid, 'twitter', 'oauthsecret');
 
        $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
@@ -1357,8 +1372,8 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis
 
        // Don't import our own comments
        $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
 
        // Don't import our own comments
        $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
-                       dbesc($postarray['uri']),
-                       intval($uid)
+               dbesc($postarray['uri']),
+               intval($uid)
        );
 
        if (count($r)) {
        );
 
        if (count($r)) {
@@ -1372,8 +1387,8 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis
                $parent = "twitter::" . $post->in_reply_to_status_id_str;
 
                $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                $parent = "twitter::" . $post->in_reply_to_status_id_str;
 
                $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc($parent),
-                               intval($uid)
+                       dbesc($parent),
+                       intval($uid)
                );
                if (count($r)) {
                        $postarray['thr-parent'] = $r[0]["uri"];
                );
                if (count($r)) {
                        $postarray['thr-parent'] = $r[0]["uri"];
@@ -1382,8 +1397,8 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis
                        $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
                } else {
                        $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
                        $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
                } else {
                        $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
-                                       dbesc($parent),
-                                       intval($uid)
+                               dbesc($parent),
+                               intval($uid)
                        );
                        if (count($r)) {
                                $postarray['thr-parent'] = $r[0]['uri'];
                        );
                        if (count($r)) {
                                $postarray['thr-parent'] = $r[0]['uri'];
@@ -1504,7 +1519,14 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis
 
                $postarray['body'] = $statustext;
 
 
                $postarray['body'] = $statustext;
 
-               $postarray['body'] .= "\n" . share_header($quoted['author-name'], $quoted['author-link'], $quoted['author-avatar'], "", $quoted['created'], $quoted['plink']);
+               $postarray['body'] .= "\n" . share_header(
+                       $quoted['author-name'],
+                       $quoted['author-link'],
+                       $quoted['author-avatar'],
+                       "",
+                       $quoted['created'],
+                       $quoted['plink']
+               );
 
                $postarray['body'] .= $quoted['body'] . '[/share]';
        }
 
                $postarray['body'] .= $quoted['body'] . '[/share]';
        }
@@ -1516,7 +1538,7 @@ function twitter_checknotification(App $a, $uid, $own_id, $top_item, $postarray)
 {
        /// TODO: this whole function doesn't seem to work. Needs complete check
        $user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
 {
        /// TODO: this whole function doesn't seem to work. Needs complete check
        $user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
-                       intval($uid)
+               intval($uid)
        );
 
        if (!count($user)) {
        );
 
        if (!count($user)) {
@@ -1529,8 +1551,8 @@ function twitter_checknotification(App $a, $uid, $own_id, $top_item, $postarray)
        }
 
        $own_user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
        }
 
        $own_user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
-                       intval($uid),
-                       dbesc("twitter::".$own_id)
+               intval($uid),
+               dbesc("twitter::".$own_id)
        );
 
        if (!count($own_user)) {
        );
 
        if (!count($own_user)) {
@@ -1543,8 +1565,8 @@ function twitter_checknotification(App $a, $uid, $own_id, $top_item, $postarray)
        }
 
        $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
        }
 
        $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
-                       dbesc($postarray['parent-uri']),
-                       intval($uid)
+               dbesc($postarray['parent-uri']),
+               intval($uid)
        );
 
        if (count($myconv)) {
        );
 
        if (count($myconv)) {
@@ -1598,8 +1620,8 @@ function twitter_fetchparentposts(App $a, $uid, $post, $connection, $self, $own_
                }
 
                $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                }
 
                $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc("twitter::".$post->id_str),
-                               intval($uid)
+                       dbesc("twitter::".$post->id_str),
+                       intval($uid)
                );
 
                if (count($r)) {
                );
 
                if (count($r)) {
@@ -1617,8 +1639,9 @@ function twitter_fetchparentposts(App $a, $uid, $post, $connection, $self, $own_
                foreach ($posts as $post) {
                        $postarray = twitter_createpost($a, $uid, $post, $self, false, false, false);
 
                foreach ($posts as $post) {
                        $postarray = twitter_createpost($a, $uid, $post, $self, false, false, false);
 
-                       if (trim($postarray['body']) == "")
+                       if (trim($postarray['body']) == "") {
                                continue;
                                continue;
+                       }
 
                        $item = item_store($postarray);
                        $postarray["id"] = $item;
 
                        $item = item_store($postarray);
                        $postarray["id"] = $item;
@@ -1810,8 +1833,9 @@ function twitter_fetchhometimeline(App $a, $uid)
                                        $item = $r[0]['id'];
                                        $parent_id = $r[0]['parent'];
                                }
                                        $item = $r[0]['id'];
                                        $parent_id = $r[0]['parent'];
                                }
-                       } else
+                       } else {
                                $parent_id = $postarray['parent'];
                                $parent_id = $postarray['parent'];
+                       }
 
                        if (($item != 0) && !function_exists("check_item_notification")) {
                                require_once 'include/enotify.php';
 
                        if (($item != 0) && !function_exists("check_item_notification")) {
                                require_once 'include/enotify.php';
@@ -1917,7 +1941,6 @@ function twitter_is_retweet(App $a, $uid, $body)
        $osecret = PConfig::get($uid, 'twitter', 'oauthsecret');
 
        $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
        $osecret = PConfig::get($uid, 'twitter', 'oauthsecret');
 
        $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
-
        $result = $connection->post('statuses/retweet/' . $id);
 
        logger('twitter_is_retweet: result ' . print_r($result, true), LOGGER_DEBUG);
        $result = $connection->post('statuses/retweet/' . $id);
 
        logger('twitter_is_retweet: result ' . print_r($result, true), LOGGER_DEBUG);
index 5d6e8b2ffb28d30be9e5f19cda4b0490d587468d..7ff3dbb3781d7042af99fc5714690bf71b244e43 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 <?php
+
 use Friendica\Core\Config;
 
 use Friendica\Core\Config;
 
-function twitter_sync_run($argv, $argc) {
+function twitter_sync_run($argv, $argc)
+{
        global $a;
 
        global $a;
 
-       require_once("addon/twitter/twitter.php");
+       require_once 'addon/twitter/twitter.php';
 
        if (function_exists('sys_getloadavg')) {
                $load = sys_getloadavg();
 
        if (function_exists('sys_getloadavg')) {
                $load = sys_getloadavg();
@@ -27,4 +29,3 @@ function twitter_sync_run($argv, $argc) {
                twitter_fetchhometimeline($a, $uid);
        }
 }
                twitter_fetchhometimeline($a, $uid);
        }
 }
-?>