Пример #1
0
 public static function getGroups($accessToken)
 {
     try {
         $client = XenForo_Helper_Http::getClient('https://graph.facebook.com/v2.0/me/groups');
         $client->setParameterGet('access_token', $accessToken);
         $response = $client->request('GET');
         $jsonDecoded = json_decode($response->getBody(), true);
         if (!empty($jsonDecoded['data'])) {
             $groups = array();
             foreach ($jsonDecoded['data'] as $entry) {
                 $groups[$entry['id']] = array('name' => $entry['name'], 'target_id' => bdSocialShare_Helper_Common::encryptTargetId($entry['name'], array('targetId' => $entry['id'], 'accessToken' => $accessToken, 'type' => 'group')));
             }
             return $groups;
         }
     } catch (Zend_Http_Client_Exception $e) {
         if (XenForo_Application::debugMode()) {
             XenForo_Error::logException($e, false);
         }
     }
     return false;
 }
Пример #2
0
 public function actionSocialShareAddMoreTwitter()
 {
     $this->assertAdminPermission('option');
     if (!bdSocialShare_Option::hasPermissionTwitter()) {
         return $this->responseError(new XenForo_Phrase('bdsocialshare_twitter_must_be_configured'));
     }
     $inputToken = $this->_input->filterSingle('token', XenForo_Input::STRING);
     /* @var $twitterModel bdSocialShare_Model_Twitter */
     $twitterModel = $this->getModelFromCache('bdSocialShare_Model_Twitter');
     $existingAccounts = $twitterModel->getAccounts();
     if (empty($inputToken)) {
         $inputOauthToken = $this->_input->filterSingle('oauth_token', XenForo_Input::STRING);
         $oauthVerifier = $this->_input->filterSingle('oauth_verifier', XenForo_Input::STRING);
         $session = XenForo_Application::getSession();
         if (empty($inputOauthToken) or empty($oauthVerifier)) {
             $redirectUri = XenForo_Link::buildAdminLink('full:tools/social-share/add-more/twitter');
             list($authorizeUri, $oauthToken, $oauthTokenSecret) = bdSocialShare_Helper_Twitter::getAuthorizeUri($redirectUri);
             $session->set(self::SESSION_KEY_TWITTER_OAUTH_TOKEN_PREFIX . $oauthToken, $oauthTokenSecret);
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, $authorizeUri);
         }
         if (!$session->isRegistered(self::SESSION_KEY_TWITTER_OAUTH_TOKEN_PREFIX . $inputOauthToken)) {
             return $this->responseNoPermission();
         }
         $sessionOauthTokenSecret = $session->get(self::SESSION_KEY_TWITTER_OAUTH_TOKEN_PREFIX . $inputOauthToken);
         $session->delete(self::SESSION_KEY_TWITTER_OAUTH_TOKEN_PREFIX . $inputOauthToken);
         $token = bdSocialShare_Helper_Twitter::getToken($inputOauthToken, $sessionOauthTokenSecret, $oauthVerifier);
         if (empty($token)) {
             return $this->responseNoPermission();
         }
     } else {
         $token = unserialize($inputToken);
     }
     if ($this->isConfirmedPost()) {
         $accounts = $this->_input->filterSingle('accounts', XenForo_Input::ARRAY_SIMPLE);
         $newAccounts = $existingAccounts;
         foreach ($accounts as $accountId => $account) {
             if (!empty($account['add'])) {
                 $newAccounts[$accountId] = $account;
             } elseif (isset($newAccounts[$accountId])) {
                 unset($newAccounts[$accountId]);
             }
         }
         $twitterModel->setAccounts($newAccounts);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, XenForo_Link::buildAdminLink('tools/social-share/twitter-targets'));
     }
     $accounts = array();
     $accounts[$token['user_id']] = array('target_id' => bdSocialShare_Helper_Common::encryptTargetId($token['screen_name'], $token), 'name' => $token['screen_name'], 'selected' => isset($existingAccounts[$token['user_id']]));
     $viewParams = array('type' => 'twitter', 'token' => serialize($token), 'accounts' => $accounts);
     return $this->responseView('bdSocialShare_ViewAdmin_Tools_AddMore', 'bdsocialshare_tools_add_more', $viewParams);
 }