コード例 #1
0
 public function getAccessToken($url, $code)
 {
     try {
         $client = XenForo_Helper_Http::getClient(sprintf('%s://%s/oauth/token', $this->schema, $this->api));
         $client->setParameterPost(array('client_id' => $this->clientId, 'redirect_uri' => $url, 'client_secret' => $this->clientSecret, 'code' => $code, 'grant_type' => 'authorization_code'));
         $response = $client->request('POST');
         $body = $response->getBody();
         if (preg_match('#^[{\\[]#', $body)) {
             $parts = json_decode($body, true);
         } else {
             $parts = XenForo_Application::parseQueryString($body);
         }
         return $parts;
     } catch (Zend_Http_Client_Exception $e) {
         return false;
     }
 }
コード例 #2
0
ファイル: Facebook.php プロジェクト: darkearl/projectT122015
 /**
  * Takes a code (with a redirect URL) and gets an access token.
  *
  * @param string $url
  * @param string $code
  *
  * @return array|false Array of info (may be error); false if Facebook integration not active
  */
 public static function getAccessToken($url, $code)
 {
     $options = XenForo_Application::get('options');
     if (!$options->facebookAppId) {
         return false;
     }
     try {
         $client = XenForo_Helper_Http::getClient('https://graph.facebook.com/v2.4/oauth/access_token');
         $client->setParameterGet(array('client_id' => $options->facebookAppId, 'redirect_uri' => $url, 'client_secret' => $options->facebookAppSecret, 'code' => $code));
         $response = $client->request('GET');
         $body = $response->getBody();
         if (preg_match('#^[{\\[]#', $body)) {
             $parts = json_decode($body, true);
         } else {
             $parts = XenForo_Application::parseQueryString($body);
         }
         return $parts;
     } catch (Zend_Http_Client_Exception $e) {
         return false;
     }
 }
コード例 #3
0
ファイル: Core.php プロジェクト: hahuunguyen/DTUI_201105
 /**
  * Converts a URL that may have a route/action and named params to a form
  * action (script name, things before query string) and named params. A route
  * in the query string is converted to a named param "_".
  *
  * @param string $url
  *
  * @return array Format: [action] => form action, [params] => key-value param pairs
  */
 public static function convertUrlToActionAndNamedParams($url)
 {
     $params = array();
     if (($questPos = strpos($url, '?')) !== false) {
         $queryString = htmlspecialchars_decode(substr($url, $questPos + 1));
         $url = substr($url, 0, $questPos);
         if (preg_match('/^([^=&]*)(&|$)/', $queryString, $queryStringUrl)) {
             $route = $queryStringUrl[1];
             $queryString = substr($queryString, strlen($queryStringUrl[0]));
         } else {
             $route = '';
         }
         if ($route !== '') {
             $params['_'] = $route;
         }
         if ($queryString) {
             $params = array_merge($params, XenForo_Application::parseQueryString($queryString));
         }
     }
     return array('action' => htmlspecialchars($url), 'params' => $params);
 }
コード例 #4
0
ファイル: Controller.php プロジェクト: Sywooch/forums
 /**
  * Turns a serialized (by jQuery) query string from input into a XenForo_Input object.
  *
  * @param string Name of index to fetch from $this->_input
  * @param boolean On error, throw an exception or return false
  * @param string
  *
  * @return XenForo_Input|false
  */
 protected function _getInputFromSerialized($varname, $throw = true, &$errorPhraseKey = null)
 {
     if ($inputString = $this->_input->filterSingle($varname, XenForo_Input::STRING)) {
         try {
             return new XenForo_Input(XenForo_Application::parseQueryString($inputString));
         } catch (Exception $e) {
             $errorPhraseKey = 'string_could_not_be_converted_to_input';
             if ($throw) {
                 throw $this->responseException($this->responseError(new XenForo_Phrase($errorPhraseKey)));
             }
         }
     }
     return false;
 }
コード例 #5
0
ファイル: Session.php プロジェクト: darkearl/projectT122015
 /**
  * Adds details about session activity to a list of session activity records.
  *
  * @param array $activities
  *
  * @return array Activity records (in same order), with details in activityDescription/activityItemTitle/activityItemUrl keys.
  */
 public function addSessionActivityDetailsToList(array $activities)
 {
     // TODO: in the future, probably remove dependence on the visitor object (via called controllers)
     $controllerGroups = array();
     foreach ($activities as $key => $activity) {
         $activity['params'] = XenForo_Application::parseQueryString($activity['params']);
         $controllerGroups[$activity['controller_name']][$key] = $activity;
     }
     foreach ($controllerGroups as $controller => $controllerGroup) {
         try {
             $controller = XenForo_Application::resolveDynamicClass($controller, 'controller');
             $canLoad = $controller && XenForo_Application::autoload($controller);
         } catch (XenForo_Exception $e) {
             // likely an XFCP autoload error - skip this
             $canLoad = false;
         }
         if ($canLoad) {
             $result = call_user_func(array($controller, 'getSessionActivityDetailsForList'), $controllerGroup);
         } else {
             $result = false;
         }
         if (is_array($result)) {
             foreach ($result as $resultKey => $resultInfo) {
                 if (!isset($controllerGroup[$resultKey])) {
                     continue;
                 }
                 if (is_array($resultInfo)) {
                     $activities[$resultKey]['activityDescription'] = $resultInfo[0];
                     $activities[$resultKey]['activityItemTitle'] = $resultInfo[1];
                     $activities[$resultKey]['activityItemUrl'] = $resultInfo[2];
                     $activities[$resultKey]['activityItemPreviewUrl'] = $resultInfo[3];
                 } else {
                     $activities[$resultKey]['activityDescription'] = $resultInfo;
                     $activities[$resultKey]['activityItemTitle'] = false;
                     $activities[$resultKey]['activityItemUrl'] = false;
                     $activities[$resultKey]['activityItemPreviewUrl'] = false;
                 }
             }
         } else {
             foreach ($controllerGroup as $key => $activity) {
                 $activities[$key]['activityDescription'] = $result;
                 $activities[$key]['activityItemTitle'] = false;
                 $activities[$key]['activityItemUrl'] = false;
                 $activities[$key]['activityItemPreviewUrl'] = false;
             }
         }
     }
     return $activities;
 }