Пример #1
0
 /**
  * Returns either a cached list of twitter accounts for a user, or
  * the accounts out of the database which will immediately be validated
  * against the twitter service (network access)
  *
  * @param array $options An associative array with the following
  * key value/pairs:
  *   - userId: the id of the user to fetch al twitter accounts for
  * @param Conjoon_BeanContext_Decoratable $model
  *
  * @return Array anr array with instances of
  * Conjoon_Modules_Service_Twitter_Account_Model_Account
  */
 protected function _build(array $options, Conjoon_BeanContext_Decoratable $model)
 {
     $userId = $options['userId'];
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     $decoratedModel = new Conjoon_BeanContext_Decorator($model);
     $accounts = $decoratedModel->getAccountsForUserAsDto($userId);
     /**
      * @see Conjoon_Service_Twitter
      */
     require_once 'Conjoon/Service/Twitter.php';
     /**
      * @see Conjoon_Modules_Default_Registry_Facade
      */
     require_once 'Conjoon/Modules/Default/Registry/Facade.php';
     $protocolContext = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/server/environment/protocol', $userId);
     for ($i = 0, $len = count($accounts); $i < $len; $i++) {
         $dto =& $accounts[$i];
         try {
             /**
              * @todo move to separate model
              */
             /**
              * @see Zend_Oauth_Token_Access
              */
             require_once 'Zend/Oauth/Token/Access.php';
             $accessToken = new Zend_Oauth_Token_Access();
             $accessToken->setParams(array('oauth_token' => $dto->oauthToken, 'oauth_token_secret' => $dto->oauthTokenSecret, 'user_id' => $dto->twitterId, 'screen_name' => $dto->name));
             $twitter = new Conjoon_Service_Twitter(array('username' => $dto->name, 'accessToken' => $accessToken));
             $response = $twitter->userShow($dto->name);
             $dto->twitterId = $response->id_str;
             $dto->twitterName = $response->name;
             $dto->twitterScreenName = $response->screen_name;
             $dto->twitterLocation = $response->location;
             $dto->twitterProfileImageUrl = $protocolContext === 'https' ? $response->profile_image_url_https : $response->profile_image_url;
             $dto->twitterUrl = $response->url;
             $dto->twitterProtected = $response->protected;
             $dto->twitterDescription = $response->description;
             $dto->twitterFollowersCount = $response->followers_count;
         } catch (Exception $e) {
             Conjoon_Log::log("Could not retrieve account information for twitter " . "account: \"" . $e->getMessage() . "\"", Zend_Log::INFO);
             // ignore
         }
         $dto->oauthTokenSecret = str_pad("", strlen($dto->oauthTokenSecret), '*');
     }
     return $accounts;
 }
Пример #2
0
 private function retrieve_token($provider_key)
 {
     $config = $this->get_configuration($provider_key);
     if (!empty($config['accessToken']) && !empty($config['accessTokenSecret'])) {
         $token = new Zend_Oauth_Token_Access();
         $token->setParams(array('oauth_token' => $config['accessToken'], 'oauth_token_secret' => $config['accessTokenSecret']));
         return $token;
     }
     $tikilib = TikiLib::lib('tiki');
     $token = $tikilib->get_preference('oauth_token_' . $provider_key);
     return $token ? unserialize($token) : null;
 }