Exemple #1
0
 /**
  * Get Timeline off Twitter
  * @param  string	$user		Tiki username to get timeline for
  * @param  string	$timelineType	Timeline to get: public/friends/search - Default: public
  * @param  string	$search		Search string
  * @return string|int			-1 if the user did not authorize the site with twitter, a negative number corresponding to the HTTP response codes from twitter (https://dev.twitter.com/docs/streaming-api/response-codes) or the requested timeline (json encoded object)
  */
 function getTwitterTimeline($user, $timelineType = 'public', $search = 'tikiwiki')
 {
     global $prefs;
     $token = $this->get_user_preference($user, 'twitter_token', '');
     if ($token == '') {
         $this->add_log('tweet', 'user not registered with twitter');
         return -1;
     }
     $token = unserialize($token);
     $twitter = new Zend_Service_Twitter(array('oauthOptions' => array('consumerKey' => $prefs['socialnetworks_twitter_consumer_key'], 'consumerSecret' => $prefs['socialnetworks_twitter_consumer_secret']), 'accessToken' => $token));
     if ($timelineType == 'friends') {
         $response = $twitter->statusesHomeTimeline();
     } elseif ($timelineType == 'search') {
         $response = $twitter->search->tweets($search, array('include_entities' => true));
     } else {
         $response = $twitter->statusesUserTimeline();
     }
     if (!$response->isSuccess()) {
         $errors = $response->getErrors();
         $this->add_log('tweet', 'twitter response: ' . $errors[0]->message . ' - Code: ' . $errors[0]->code);
         return -$errors['code'];
     } else {
         return $response->toValue();
     }
 }