/**
  * @param Gdn_Controller $Sender
  * @param type $Args 
  */
 public function UtilityController_SiteMapIndex_Create($Sender)
 {
     // Clear the session to mimic a crawler.
     Gdn::Session()->Start(0, FALSE, FALSE);
     $Sender->DeliveryMethod(DELIVERY_METHOD_XHTML);
     $Sender->DeliveryType(DELIVERY_TYPE_VIEW);
     $Sender->SetHeader('Content-Type', 'text/xml');
     $SiteMaps = array();
     if (class_exists('CategoryModel')) {
         $Categories = CategoryModel::Categories();
         foreach ($Categories as $Category) {
             if (!$Category['PermsDiscussionsView'] || $Category['CategoryID'] < 0 || $Category['CountDiscussions'] == 0) {
                 continue;
             }
             $SiteMap = array('Loc' => Url('/sitemap-category-' . rawurlencode($Category['UrlCode'] ? $Category['UrlCode'] : $Category['CategoryID']) . '.xml', TRUE), 'LastMod' => $Category['DateLastComment'], 'ChangeFreq' => '', 'Priority' => '');
             $SiteMaps[] = $SiteMap;
         }
     }
     $Sender->SetData('SiteMaps', $SiteMaps);
     $Sender->Render('SiteMapIndex', '', 'plugins/Sitemaps');
 }
 /**
  *
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function Base_ConnectData_Handler($Sender, $Args)
 {
     if (GetValue(0, $Args) != 'sinaconnect') {
         return;
     }
     $RequestToken = GetValue('oauth_token', $_GET);
     // Get the access token.
     if ($RequestToken || !($AccessToken = $this->AccessToken())) {
         // Get the request secret.
         $RequestToken = $this->GetOAuthToken($RequestToken);
         $Consumer = new OAuthConsumer(C('Plugins.SinaConnect.ConsumerKey'), C('Plugins.SinaConnect.Secret'));
         $Url = 'http://api.t.sina.com.cn/oauth/access_token';
         $Params = array('oauth_verifier' => GetValue('oauth_verifier', $_GET));
         $Request = OAuthRequest::from_consumer_and_token($Consumer, $RequestToken, 'POST', $Url, $Params);
         $SignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
         $Request->sign_request($SignatureMethod, $Consumer, $RequestToken);
         $Post = $Request->to_postdata();
         $Curl = $this->_Curl($Request);
         $Response = curl_exec($Curl);
         if ($Response === FALSE) {
             $Response = curl_error($Curl);
         }
         $HttpCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
         curl_close($Curl);
         if ($HttpCode == '200') {
             $Data = OAuthUtil::parse_parameters($Response);
             $AccessToken = $this->AccessToken(GetValue('oauth_token', $Data), GetValue('oauth_token_secret', $Data));
             // Save the access token to the database.
             $this->SetOAuthToken($AccessToken);
             // Delete the request token.
             $this->DeleteOAuthToken($RequestToken);
         } else {
             // There was some sort of error.
         }
         $NewToken = TRUE;
     }
     // Get the profile.
     try {
         $Profile = $this->GetProfile($AccessToken);
     } catch (Exception $Ex) {
         if (!isset($NewToken)) {
             // There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
             if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 Redirect($this->_AuthorizeHref());
             } else {
                 $Sender->SetHeader('Content-type', 'application/json');
                 $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
                 $Sender->RedirectUrl = $this->_AuthorizeHref();
             }
         } else {
             $Sender->Form->AddError($Ex);
         }
     }
     //print_r($Profile);
     $Form = $Sender->Form;
     //new Gdn_Form();
     $ID = GetValue('id', $Profile);
     $Form->SetFormValue('UniqueID', $ID);
     $Form->SetFormValue('Provider', self::$ProviderKey);
     $Form->SetFormValue('ProviderName', 'Sina');
     $Form->SetFormValue('Name', GetValue('screen_name', $Profile));
     $Form->SetFormValue('FullName', GetValue('name', $Profile));
     $Form->SetFormValue('Email', GetValue('id', $Profile) . '@weibo.com');
     $Form->SetFormValue('Photo', GetValue('profile_image_url', $Profile));
     $Sender->SetData('Verified', TRUE);
 }
Esempio n. 3
0
 /**
  *
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function Base_ConnectData_Handler($Sender, $Args)
 {
     if (GetValue(0, $Args) != 'twitter') {
         return;
     }
     $Form = $Sender->Form;
     //new Gdn_Form();
     $RequestToken = GetValue('oauth_token', $_GET);
     $AccessToken = $Form->GetFormValue('AccessToken');
     if ($AccessToken) {
         $AccessToken = $this->GetOAuthToken($AccessToken);
         $this->AccessToken($AccessToken);
     }
     // Get the access token.
     if ($RequestToken && !$AccessToken) {
         // Get the request secret.
         $RequestToken = $this->GetOAuthToken($RequestToken);
         $Consumer = new OAuthConsumer(C('Plugins.Twitter.ConsumerKey'), C('Plugins.Twitter.Secret'));
         $Url = 'https://api.twitter.com/oauth/access_token';
         $Params = array('oauth_verifier' => GetValue('oauth_verifier', $_GET));
         $Request = OAuthRequest::from_consumer_and_token($Consumer, $RequestToken, 'POST', $Url, $Params);
         $SignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
         $Request->sign_request($SignatureMethod, $Consumer, $RequestToken);
         $Post = $Request->to_postdata();
         $Curl = $this->_Curl($Request);
         $Response = curl_exec($Curl);
         if ($Response === FALSE) {
             $Response = curl_error($Curl);
         }
         $HttpCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
         curl_close($Curl);
         if ($HttpCode == '200') {
             $Data = OAuthUtil::parse_parameters($Response);
             $AccessToken = new OAuthToken(GetValue('oauth_token', $Data), GetValue('oauth_token_secret', $Data));
             // Save the access token to the database.
             $this->SetOAuthToken($AccessToken->key, $AccessToken->secret, 'access');
             $this->AccessToken($AccessToken->key, $AccessToken->secret);
             // Delete the request token.
             $this->DeleteOAuthToken($RequestToken);
         } else {
             // There was some sort of error.
             throw new Exception('There was an error authenticating with twitter.', 400);
         }
         $NewToken = TRUE;
     }
     // Get the profile.
     try {
         $Profile = $this->GetProfile($AccessToken);
     } catch (Exception $Ex) {
         if (!isset($NewToken)) {
             // There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
             if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 Redirect($this->_AuthorizeHref());
             } else {
                 $Sender->SetHeader('Content-type', 'application/json');
                 $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
                 $Sender->RedirectUrl = $this->_AuthorizeHref();
             }
         } else {
             throw $Ex;
         }
     }
     $ID = GetValue('id', $Profile);
     $Form->SetFormValue('UniqueID', $ID);
     $Form->SetFormValue('Provider', self::ProviderKey);
     $Form->SetFormValue('ProviderName', 'Twitter');
     $Form->SetValue('ConnectName', GetValue('screen_name', $Profile));
     $Form->SetFormValue('Name', GetValue('screen_name', $Profile));
     $Form->SetFormValue('FullName', GetValue('name', $Profile));
     $Form->SetFormValue('Photo', GetValue('profile_image_url', $Profile));
     $Form->AddHidden('AccessToken', $AccessToken->key);
     // Save some original data in the attributes of the connection for later API calls.
     $Attributes = array(self::ProviderKey => array('AccessToken' => array($AccessToken->key, $AccessToken->secret), 'Profile' => $Profile));
     $Form->SetFormValue('Attributes', $Attributes);
     $Sender->SetData('Verified', TRUE);
 }
Esempio n. 4
0
 /**
  *
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function Base_ConnectData_Handler($Sender, $Args)
 {
     if (GetValue(0, $Args) != 'facebook') {
         return;
     }
     if (isset($_GET['error'])) {
         throw new Gdn_UserException(GetValue('error_description', $_GET, T('There was an error connecting to Facebook')));
     }
     $AppID = C('Plugins.Facebook.ApplicationID');
     $Secret = C('Plugins.Facebook.Secret');
     $Code = GetValue('code', $_GET);
     $Query = '';
     if ($Sender->Request->Get('display')) {
         $Query = 'display=' . urlencode($Sender->Request->Get('display'));
     }
     $RedirectUri = ConcatSep('&', $this->RedirectUri(), $Query);
     $RedirectUri = urlencode($RedirectUri);
     // Get the access token.
     if ($Code || !($AccessToken = $this->AccessToken())) {
         // Exchange the token for an access token.
         $Code = urlencode($Code);
         $Url = "https://graph.facebook.com/oauth/access_token?client_id={$AppID}&client_secret={$Secret}&code={$Code}&redirect_uri={$RedirectUri}";
         // Get the redirect URI.
         $C = curl_init();
         curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($C, CURLOPT_URL, $Url);
         $Contents = curl_exec($C);
         //         $Contents = ProxyRequest($Url);
         $Info = curl_getinfo($C);
         if (strpos(GetValue('content_type', $Info, ''), '/javascript') !== FALSE) {
             $Tokens = json_decode($Contents, TRUE);
         } else {
             parse_str($Contents, $Tokens);
         }
         if (GetValue('error', $Tokens)) {
             throw new Gdn_UserException('Facebook returned the following error: ' . GetValueR('error.message', $Tokens, 'Unknown error.'), 400);
         }
         $AccessToken = GetValue('access_token', $Tokens);
         $Expires = GetValue('expires', $Tokens, NULL);
         setcookie('fb_access_token', $AccessToken, time() + $Expires, C('Garden.Cookie.Path', '/'), C('Garden.Cookie.Domain', ''), NULL, TRUE);
         $NewToken = TRUE;
     }
     // Get the profile.
     try {
         $Profile = $this->GetProfile($AccessToken);
     } catch (Exception $Ex) {
         if (!isset($NewToken)) {
             // There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
             if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 Redirect($this->AuthorizeUri());
             } else {
                 $Sender->SetHeader('Content-type', 'application/json');
                 $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
                 $Sender->RedirectUrl = $this->AuthorizeUri();
             }
         } else {
             $Sender->Form->AddError('There was an error with the Facebook connection.');
         }
     }
     $Form = $Sender->Form;
     //new Gdn_Form();
     $ID = GetValue('id', $Profile);
     $Form->SetFormValue('UniqueID', $ID);
     $Form->SetFormValue('Provider', 'facebook');
     $Form->SetFormValue('ProviderName', 'Facebook');
     $Form->SetFormValue('FullName', GetValue('name', $Profile));
     $Form->SetFormValue('Email', GetValue('email', $Profile));
     $Form->SetFormValue('Photo', "http://graph.facebook.com/{$ID}/picture");
     if (C('Plugins.Facebook.UseFacebookNames')) {
         $Form->SetFormValue('Name', GetValue('name', $Profile));
         SaveToConfig(array('Garden.User.ValidationRegex' => UserModel::USERNAME_REGEX_MIN, 'Garden.User.ValidationLength' => '{3,50}', 'Garden.Registration.NameUnique' => FALSE), '', FALSE);
     }
     // Save some original data in the attributes of the connection for later API calls.
     $Attributes = array('Facebook.Profile' => $Profile);
     $Form->SetFormValue('Attributes', $Attributes);
     $Sender->SetData('Verified', TRUE);
 }
Esempio n. 5
0
 /**
  *
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function Base_ConnectData_Handler($Sender, $Args)
 {
     if (GetValue(0, $Args) != 'facebook') {
         return;
     }
     if (isset($_GET['error'])) {
         throw new Gdn_UserException(GetValue('error_description', $_GET, T('There was an error connecting to Facebook')));
     }
     $AppID = C('Plugins.Facebook.ApplicationID');
     $Secret = C('Plugins.Facebook.Secret');
     $Code = GetValue('code', $_GET);
     $Query = '';
     if ($Sender->Request->Get('display')) {
         $Query = 'display=' . urlencode($Sender->Request->Get('display'));
     }
     $RedirectUri = ConcatSep('&', $this->RedirectUri(), $Query);
     //      $RedirectUri = urlencode($RedirectUri);
     // Get the access token.
     if ($Code) {
         // Exchange the token for an access token.
         $Code = urlencode($Code);
         $AccessToken = $this->GetAccessToken($Code, $RedirectUri);
         $NewToken = TRUE;
     }
     // Get the profile.
     try {
         $Profile = $this->GetProfile($AccessToken);
     } catch (Exception $Ex) {
         if (!isset($NewToken)) {
             // There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
             if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 Redirect($this->AuthorizeUri());
             } else {
                 $Sender->SetHeader('Content-type', 'application/json');
                 $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
                 $Sender->RedirectUrl = $this->AuthorizeUri();
             }
         } else {
             $Sender->Form->AddError('There was an error with the Facebook connection.');
         }
     }
     $Form = $Sender->Form;
     //new Gdn_Form();
     $ID = GetValue('id', $Profile);
     $Form->SetFormValue('UniqueID', $ID);
     $Form->SetFormValue('Provider', self::ProviderKey);
     $Form->SetFormValue('ProviderName', 'Facebook');
     $Form->SetFormValue('FullName', GetValue('name', $Profile));
     $Form->SetFormValue('Email', GetValue('email', $Profile));
     $Form->SetFormValue('Photo', "http://graph.facebook.com/{$ID}/picture");
     if (C('Plugins.Facebook.UseFacebookNames')) {
         $Form->SetFormValue('Name', GetValue('name', $Profile));
         SaveToConfig(array('Garden.User.ValidationRegex' => UserModel::USERNAME_REGEX_MIN, 'Garden.User.ValidationLength' => '{3,50}', 'Garden.Registration.NameUnique' => FALSE), '', FALSE);
     }
     // Save some original data in the attributes of the connection for later API calls.
     $Attributes = array();
     $Attributes[self::ProviderKey] = array('AccessToken' => $AccessToken, 'Profile' => $Profile);
     $Form->SetFormValue('Attributes', $Attributes);
     $Sender->SetData('Verified', TRUE);
 }
Esempio n. 6
0
 /**
  *
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function Base_ConnectData_Handler($Sender, $Args)
 {
     if (GetValue(0, $Args) != 'accounts9') {
         return;
     }
     if (isset($_GET['error'])) {
         throw new Gdn_UserException(GetValue('error_description', $_GET, T('There was an error connecting to Accounts9')));
     }
     $AppID = C('Plugins.Accounts9.ApplicationID');
     $Secret = C('Plugins.Accounts9.Secret');
     if (!$Code) {
         if (!isset($_GET['code'])) {
             throw new Gdn_UserException('could not retrieve code out of callback request and no code given');
         }
         $Code = $_GET['code'];
     }
     $Code = GetValue('code', $_GET);
     /*     $Query = '';
           if ($Sender->Request->Get('display'))
              $Query = 'display='.urlencode($Sender->Request->Get('display'));
       */
     $RedirectUri = ConcatSep('&', $this->RedirectUri(), $Query);
     $RedirectUri = urlencode($RedirectUri);
     // Get the access token.
     if ($Code || !($AccessToken = $this->AccessToken())) {
         // Exchange the token for an access token.
         $Code = urlencode($Code);
         $Url = "https://accounts.net9.org/api/access_token?client_id={$AppID}&client_secret={$Secret}&code={$Code}&redirect_uri={$RedirectUri}";
         // Get the redirect URI.
         $C = curl_init();
         curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($C, CURLOPT_URL, $Url);
         $Contents = curl_exec($C);
         //         $Contents = ProxyRequest($Url);
         $Info = curl_getinfo($C);
         //        if (strpos(GetValue('content_type', $Info, ''), '/javascript') !== FALSE) {
         $Tokens = json_decode($Contents, TRUE);
         /* } else {
                     parse_str($Contents, $Tokens);
         	 }*/
         if (GetValue('error', $Tokens)) {
             throw new Gdn_UserException('Accounts9 returned the following error: ' . GetValueR('error.message', $Tokens, 'Unknown error.'), 400);
         }
         $AccessToken = GetValue('access_token', $Tokens);
         $Expires = GetValue('expires_in', $Tokens, NULL);
         setcookie('accounts9_access_token', $AccessToken, time() + $Expires, C('Garden.Cookie.Path', '/'), C('Garden.Cookie.Domain', ''));
         $NewToken = TRUE;
     }
     // Get the profile.
     try {
         $Profile = $this->GetProfile($AccessToken);
     } catch (Exception $Ex) {
         if (!isset($NewToken)) {
             // There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
             if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 Redirect($this->AuthorizeUri());
             } else {
                 $Sender->SetHeader('Content-type', 'application/json');
                 $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
                 $Sender->RedirectUrl = $this->AuthorizeUri();
             }
         } else {
             $Sender->Form->AddError('There was an error with the Accounts9 connection.');
         }
     }
     //throw new Gdn_UserException($Profile);
     $User = GetValue("user", $Profile);
     //      throw new Gdn_UserException($User['uid']);
     //      $User = json_decode($UContents,TRUE);
     $Form = $Sender->Form;
     //new Gdn_Form();
     $ID = GetValue('uid', $User);
     $Form->SetFormValue('UniqueID', $ID);
     $Form->SetFormValue('Provider', 'accounts9');
     $Form->SetFormValue('ProviderName', 'Accounts9');
     $Form->SetFormValue('Name', GetValue('name', $User));
     $Form->SetFormValue('NickName', GetValue('nickname', $User));
     $Form->SetFormValue('FullName', GetValue('username', $User));
     $Form->SetFormValue('Email', GetValue('email', $User));
     //      $Form->SetFormValue('Photo', "http://graph.facebook.com/$ID/picture");
     $Sender->SetData('Verified', TRUE);
 }