예제 #1
0
 public function sendUpdates()
 {
     $tw_service = new TwitterService();
     $updates = $tw_service->getUpdates();
     $subscribers = $tw_service->getFollowers();
     $tw_service->tweet($updates, $subscribers);
 }
 public function execute(&$value, &$error)
 {
     $password_field = $this->getParameterHolder()->get('password_field');
     $password = $this->getContext()->getRequest()->getParameter($password_field);
     $update = false;
     $update_field = $this->getParameterHolder()->get('update_field');
     $update = $this->getContext()->getRequest()->getParameter($update_field);
     $username = $value;
     // It's a valid account if the password is set to the standard null
     if ($password == sfConfig::get('app_profile_null_password')) {
         return true;
     }
     $twitter = new TwitterService($username, $password);
     if ($twitter->simpleVerifyCredentials() == true) {
         return true;
     }
     $error = $this->getParameterHolder()->get('twitter_error');
     return false;
 }
 public function searchTweets($query, $count)
 {
     // Init caching
     $cacheKey = "searchTweets_" . str_replace("-", "_", Convert::raw2url($query)) . "_{$count}";
     $cache = SS_Cache::factory('CachedTwitterService');
     // Return cached value, if available
     if ($rawResult = $cache->load($cacheKey)) {
         return unserialize($rawResult);
     }
     // Save and return
     $result = $this->cachedService->searchTweets($query, $count);
     $cache->save(serialize($result), $cacheKey, array(), Config::inst()->get('CachedTwitterService', 'lifetime'));
     // Refresh the 'TimeAgo' field, as the cached value would now be outdated, or the locale could have changed.
     if ($result) {
         foreach ($result as $index => $item) {
             $result[$index]['TimeAgo'] = TwitterService::determine_time_ago($item['Date']);
         }
     }
     return $result;
 }
예제 #4
0
 public function executeUpdateExternalServices()
 {
     $this->profile = $this->getUser()->getProfile();
     $this->logMessage('Profile set: [' . $this->profile . ']');
     $twitter_username = $this->getRequestParameter('twitter_username');
     $twitter_password = $this->getRequestParameter('twitter_password');
     if ($twitter_username != null && $twitter_password != null) {
         $ext_services = $this->getUser()->getProfile()->getExternalServices();
         $ext_services->setTwitterUsername($twitter_username);
         if ($twitter_password != sfConfig::get('app_profile_null_password')) {
             $ext_services->setTwitterPassword($twitter_password);
         }
         $ext_services->setTwitterConfirmed(true);
         $ext_services->setTwitterUpdate($this->getRequestParameter('twitter_update'));
         $ext_services->setTwitterStatusUpdate($this->getRequestParameter('twitter_status_update'));
         $ext_services->save();
         $es = $ext_services;
         $twitter = new TwitterService($es->getTwitterUsername(), $es->getTwitterPassword());
         $response = $twitter->follow('cothink');
         $response = $twitter->createFriendship('cothink');
         $twitter2 = new TwitterService(sfConfig::get('app_external_twitter_username'), sfConfig::get('app_external_twitter_password'));
         $response = $twitter2->follow($es->getTwitterUsername());
         $response = $twitter2->createFriendship($es->getTwitterUsername());
         $message = ' Hey, we\'re following each other now - how exciting!';
         if ($es->getTwitterUpdate()) {
             $message .= ' We\'ll include twitter updates for you from now on.';
         } else {
             $message .= 'We\'ll only send you critical updates, unless you choose to use our TwitterUpdate.';
         }
         if ($es->getTwitterStatusUpdate()) {
             $message .= 'Also, your CoThink status will be set to your latest tweet.';
         }
         $response = $this->getUser()->getProfile()->notify($message);
     }
     //$this->redirect('user/editProfile');
 }
예제 #5
0
 public function tweets()
 {
     return TwitterService::get_tweets_for_username($this->username);
 }
예제 #6
0
 public function sendTwitterMessage($message, $options = array())
 {
     if (!isset($options["full"]) || $options["full"] == false) {
         if (strlen($message) > 100) {
             $message = substr($message, 0, 100) . '...';
         }
     }
     $twitter = new TwitterService(sfConfig::get('app_external_twitter_username'), sfConfig::get('app_external_twitter_password'));
     $response = $twitter->sendMessage($this->getTwitterUsername(), $message);
     return $response->isError();
 }