Esempio n. 1
0
 public function __construct()
 {
     if (!class_exists('TwitterOAuth')) {
         if (isset(\Kiki\Config::$twitterOAuthPath)) {
             Log::error("could not instantiate TwitterOAuth class from " . \Kiki\Config::$twitterOAuthPath . "/autoload.php");
         }
         return;
     }
     $this->enabled = true;
 }
Esempio n. 2
0
 public static function getInstance($service, $id = 0, $kikiUserId = 0)
 {
     // TODO: remove migration from namespaces
     $service = str_replace("User_", "", $service);
     $class = ucfirst($service);
     if (!strstr($class, __NAMESPACE__)) {
         $class = __NAMESPACE__ . "\\" . $class;
     }
     if (!class_exists($class)) {
         \Kiki\Log::error("Non-existant class {$class} requested");
         return null;
     }
     return new $class($id, $kikiUserId);
 }
Esempio n. 3
0
    }
}
$tweets = array();
$storePublicationsAsComment = false;
foreach ($connectionIds as $connectionId) {
    $q = $db->buildQuery("SELECT external_id, object_id FROM publications WHERE connection_id=%d AND external_id!=0", $connectionId);
    $rs = $db->query($q);
    while ($o = $db->fetchObject($rs)) {
        $objectIds[$o->external_id] = $o->object_id;
    }
    $apiUser = User\Factory::getInstance('Twitter', $connectionId);
    try {
        $rs = $apiUser->api()->get('application/rate_limit_status');
    } catch (User\Exception $e) {
        echo "API call failed for user " . print_r($apiUser, true);
        Log::error("API call failed for user " . print_r($apiUser, true));
        continue;
    }
    if (!isset($rs)) {
        echo "No valid result from Twitter (connection {$connectionId})." . PHP_EOL;
        continue;
    }
    $remainingHits = $rs->resources->application->{'/application/rate_limit_status'}->remaining;
    if ($remainingHits < 5) {
        $resetTime = $rs->resources->application->{'/application/rate_limit_status'}->reset;
        $wait = $resetTime - time();
        echo "Less than 10 query hits remaining ({$remainingHits}), replenishes in {$wait}s." . PHP_EOL;
        continue;
    }
    $getMore = true;
    $maxId = 0;
Esempio n. 4
0
 public function revokePerm($perm, $deleteStoredValue = false)
 {
     // Tell Facebook to revoke permission
     try {
         $fbRs = $this->api()->api("/me/permissions/{$perm}", $method = 'DELETE');
     } catch (Exception $e) {
         Log::error("Exception: {$e}");
     }
     // Remove permission from database
     self::storePerm($perm, false, $deleteStoredValue);
     // Remove user access_token and cookie to force retrieval of a new access token with correct permissions
     $q = $this->db->buildQuery("UPDATE connections set token=null where service='%s' and external_id='%s'", get_class($this), $this->externalId);
     $this->db->query($q);
     $cookieId = "fbs_" . \Kiki\Config::$facebookApp;
     setcookie($cookieId, "", time() - 3600, "/", $_SERVER['SERVER_NAME']);
 }
Esempio n. 5
0
 public function post($objectId, $msg, $link = '', $name = '', $caption = '', $description = '', $picture = '')
 {
     $result = new \stdClass();
     $result->id = null;
     $result->url = null;
     $result->error = null;
     /*
         if ( !$this->authenticated || !$this->api )
         {
           $result->error = "Twitter user not authenticated.";
           return $result;
         }
     */
     \Kiki\Log::debug("msg: {$msg}");
     try {
         $twRs = $this->api()->post('statuses/update', array('status' => $msg));
     } catch (Exception $e) {
         \Kiki\Log::error("Exception: {$e}");
     }
     $publication = new \Kiki\Publication();
     $publication->setObjectId($objectId);
     $publication->setConnectionId($this->externalId);
     $publication->setBody($msg);
     $publication->setResponse(serialize($twRs));
     $publication->setExternalId(isset($twRs->id) ? $twRs->id : 0);
     $publication->save();
     if (!$twRs) {
         $result->error = "Twitter status update failed.";
         return $result;
     }
     if (isset($twRs->errors)) {
         $result->error = $twRs->errors->message;
         \Kiki\Log::debug("twPost error: {$result->errors}->message");
     } else {
         $result->id = $twRs->id;
         $result->url = "//www.twitter.com/" . $twRs->user->screen_name . "/status/" . $result->id;
     }
     return $result;
 }