public function getAccessToken($feedSID = null, $action = null, &$errors)
 {
     SJB_Session::setValue('twitterFeed', serialize($_REQUEST));
     if ($feedSID != null) {
         $feedInfo = SJB_SocialMedia::getFeedInfoByNetworkIdAndSID(self::NETWORK_ID, $feedSID);
     }
     if ($action != 'grant') {
         $feedInfo['consumerKey'] = SJB_Request::getVar('consumerKey');
         $feedInfo['consumerSecret'] = SJB_Request::getVar('consumerSecret');
         $feedInfo['account_id'] = SJB_Request::getVar('account_id');
     }
     $config = array('callbackUrl' => self::getCallBackUrl($feedSID, $action, SJB_Request::getVar('submit')), 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $feedInfo['consumerKey'], 'consumerSecret' => $feedInfo['consumerSecret'], 'requestTokenUrl' => 'https://api.twitter.com/oauth/request_token', 'userAuthorizationUrl' => 'https://api.twitter.com/oauth/authorize', 'accessTokenUrl' => 'https://api.twitter.com/oauth/access_token');
     $consumer = new Zend_Oauth_Consumer($config);
     $client = new Zend_Http_Client();
     $client->setConfig(array('sslcert' => 'cacert.pem'));
     $consumer->setHttpClient($client);
     $sessionTwitterRequestToken = SJB_Session::getValue('TWITTER_REQUEST_TOKEN');
     if (SJB_Request::getVar('process_token', false) && !is_null($sessionTwitterRequestToken)) {
         $accessToken = $consumer->getAccessToken($_GET, unserialize($sessionTwitterRequestToken));
         $feedInfo['access_token'] = $accessToken;
         $twitter = self::getZendServiceTwitter($feedInfo, $accessToken);
         $response = $twitter->account->accountVerifyCredentials()->toValue();
         if (!empty($response->screen_name) && strtolower($response->screen_name) == strtolower($feedInfo['account_id'])) {
             return $accessToken;
         } else {
             $errors[] = 'Twitter account verification failed';
             return false;
         }
     } else {
         if ($requestToken = $consumer->getRequestToken()) {
             SJB_Session::setValue('TWITTER_REQUEST_TOKEN', serialize($requestToken));
             $consumer->redirect();
         } else {
             $errors[] = 'Could not retrieve a valid Token. Please check "Consumer Key" and "Consumer secret"';
             return false;
         }
     }
 }
 /**
  * @param int $feedSID
  */
 public function run_manually_check($feedSID)
 {
     $feed = SJB_SocialMedia::getFeedInfoByNetworkIdAndSID($this->networkID, $feedSID);
     $feedManager = SJB_SocialMediaPostingsPublisher::getPublisher($feed, $this->networkID);
     $listingSIDs = $feedManager->getListingsSIDsToPostByFeed();
     $postedToday = $feedManager->getPostedTodayByFeed();
     $this->tp->assign('foundListingsToPost', count($listingSIDs));
     $this->tp->assign('postedToday', $postedToday);
     $this->displayResult($feedManager);
 }
Exemple #3
0
 /**
  * @param SJB_TemplateProcessor $tp
  * @param $networkSocialMedia
  * @param array $errors
  * @param array $feedInfo
  * @param string $network
  * @param int $sid
  */
 private function checkToken(SJB_TemplateProcessor $tp, $networkSocialMedia, array &$errors, array $feedInfo, $network, $sid)
 {
     if ($networkSocialMedia->approveAccount()) {
         if (empty($feedInfo)) {
             $feedInfo = SJB_SocialMedia::getFeedInfoByNetworkIdAndSID($network, $sid);
         }
         if (!empty($feedInfo)) {
             if (SJB_SocialMedia::isFeedExpired($feedInfo)) {
                 $errors[] = 'TOKEN_EXPIRED';
                 $tp->assign('expired', true);
             } else {
                 $errors[] = 'APPROVE_ACCOUNT';
                 $tp->assign('approveAccount', true);
             }
         }
     }
 }