]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/synctwitterfriends.php
Merge branch '0.8.x' into testing
[quix0rs-gnu-social.git] / scripts / synctwitterfriends.php
index 1bd75bac111170e4db3b3f6e72cb1d187f0f3b4c..b30e700a1c4a298a0633701932ebe824d511649e 100755 (executable)
@@ -1,8 +1,8 @@
 #!/usr/bin/env php
 <?php
 /*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, Control Yourself, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -37,11 +37,11 @@ require_once INSTALLDIR . '/lib/parallelizingdaemon.php';
  * Daemon to sync local friends with Twitter friends
  *
  * @category Twitter
- * @package  Laconica
- * @author   Zach Copley <zach@controlyourself.ca>
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Zach Copley <zach@status.net>
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  */
 
 $helptext = <<<END_OF_TWITTER_HELP
@@ -54,6 +54,18 @@ require_once INSTALLDIR . '/lib/parallelizingdaemon.php';
 
 class SyncTwitterFriendsDaemon extends ParallelizingDaemon
 {
+    /**
+     *  Constructor
+     *
+     * @param string  $id           the name/id of this daemon
+     * @param int     $interval     sleep this long before doing everything again
+     * @param int     $max_children maximum number of child processes at a time
+     * @param boolean $debug        debug output flag
+     *
+     * @return void
+     *
+     **/
+
     function __construct($id = null, $interval = 60,
                          $max_children = 2, $debug = null)
     {
@@ -68,9 +80,15 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
 
     function name()
     {
-        return ('synctwitterfriendsdaemon.' . $this->_id);
+        return ('synctwitterfriends.' . $this->_id);
     }
 
+    /**
+     * Find all the Twitter foreign links for users who have requested
+     * automatically subscribing to their Twitter friends locally.
+     *
+     * @return array flinks an array of Foreign_link objects
+     */
     function getObjects()
     {
         $flinks = array();
@@ -124,11 +142,20 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
     {
         $friends = array();
 
-        $client = new TwitterOAuthClient($flink->token, $flink->credentials);
+        $client = null;
+
+        if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
+            $token = TwitterOAuthClient::unpackToken($flink->credentials);
+            $client = new TwitterOAuthClient($token->key, $token->secret);
+            common_debug($this->name() . '- Grabbing friends IDs with OAuth.');
+        } else {
+            $client = new TwitterBasicAuthClient($flink);
+            common_debug($this->name() . '- Grabbing friends IDs with basic auth.');
+        }
 
         try {
-            $friends_ids = $client->friends_ids();
-        } catch (OAuthCurlException $e) {
+            $friends_ids = $client->friendsIds();
+        } catch (Exception $e) {
             common_log(LOG_WARNING, $this->name() .
                        ' - cURL error getting friend ids ' .
                        $e->getCode() . ' - ' . $e->getMessage());
@@ -156,8 +183,8 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
         for ($i = 1; $i <= $pages; $i++) {
 
         try {
-            $more_friends = $client->statuses_friends(null, null, null, $i);
-        } catch (OAuthCurlException $e) {
+            $more_friends = $client->statusesFriends(null, null, null, $i);
+        } catch (Exception $e) {
             common_log(LOG_WARNING, $this->name() .
                        ' - cURL error getting Twitter statuses/friends ' .
                        "page $i - " . $e->getCode() . ' - ' .
@@ -237,8 +264,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
 
 }
 
-declare(ticks = 1);
-
 $id    = null;
 $debug = null;