Exemplo n.º 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();
     }
 }
Exemplo n.º 2
0
 /** Call Twitter service
  *
  * @return array
  */
 private function _callTwitter()
 {
     if (!$this->getCache()->test(md5($this->getKey()))) {
         $tokens = new OauthTokens();
         $token = $tokens->fetchRow($tokens->select()->where('service = ?', 'twitterAccess'));
         $twitter = new Zend_Service_Twitter(array('username' => 'findsorguk', 'accessToken' => unserialize($token->accessToken), 'oauthOptions' => array('consumerKey' => $this->getConfig()->webservice->twitter->consumerKey, 'consumerSecret' => $this->getConfig()->webservice->twitter->consumerSecret)));
         $tweets = $twitter->statusesUserTimeline(array('count' => $this->getCount()))->toValue();
         $this->getCache()->save($tweets);
     } else {
         $tweets = $this->getCache()->load(md5($this->getKey()));
     }
     return $this->buildHtml($tweets);
 }