/**
  * @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');
 }
 /**
  * Add a method to the ModerationController to handle merging discussions.
  * @param Gdn_Controller $Sender
  */
 public function ModerationController_MergeDiscussions_Create($Sender)
 {
     $Session = Gdn::Session();
     $Sender->Form = new Gdn_Form();
     $Sender->Title(T('Merge Discussions'));
     $DiscussionModel = new DiscussionModel();
     $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
     if (!is_array($CheckedDiscussions)) {
         $CheckedDiscussions = array();
     }
     $DiscussionIDs = $CheckedDiscussions;
     $Sender->SetData('DiscussionIDs', $DiscussionIDs);
     $CountCheckedDiscussions = count($DiscussionIDs);
     $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
     $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
     $Sender->SetData('Discussions', $Discussions);
     // Perform the merge
     if ($Sender->Form->AuthenticatedPostBack()) {
         // Create a new discussion record
         $MergeDiscussion = FALSE;
         $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
         foreach ($Discussions as $Discussion) {
             if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
                 $MergeDiscussion = $Discussion;
                 break;
             }
         }
         if ($MergeDiscussion) {
             $ErrorCount = 0;
             // Verify that the user has permission to perform the merge.
             $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
             if ($Category && !$Category['PermsDiscussionsEdit']) {
                 throw PermissionException('Vanilla.Discussions.Edit');
             }
             // Assign the comments to the new discussion record
             $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put();
             $CommentModel = new CommentModel();
             foreach ($Discussions as $Discussion) {
                 if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
                     continue;
                 }
                 // Create a comment out of the discussion.
                 $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
                 $Comment['DiscussionID'] = $MergeDiscussionID;
                 $CommentModel->Validation->Results(TRUE);
                 $CommentID = $CommentModel->Save($Comment);
                 if ($CommentID) {
                     // Move any attachments (FileUpload plugin awareness)
                     if (class_exists('MediaModel')) {
                         $MediaModel = new MediaModel();
                         $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
                     }
                     // Delete discussion that was merged
                     $DiscussionModel->Delete($Discussion['DiscussionID']);
                 } else {
                     $Sender->InformMessage($CommentModel->Validation->ResultsText());
                     $ErrorCount++;
                 }
             }
             // Update counts on all affected discussions.
             $CommentModel->UpdateCommentCount($MergeDiscussionID);
             $CommentModel->RemovePageCache($MergeDiscussionID);
             // Clear selections
             Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
             ModerationController::InformCheckedDiscussions($Sender);
             if ($ErrorCount == 0) {
                 $Sender->RedirectUrl = Url("/discussion/{$MergeDiscussionID}/" . Gdn_Format::Url($MergeDiscussion['Name']));
             }
         }
     }
     $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
 }
 /**
  * Add a method to the ModerationController to handle merging discussions.
  * @param Gdn_Controller $Sender
  */
 public function ModerationController_MergeDiscussions_Create($Sender)
 {
     $Session = Gdn::Session();
     $Sender->Form = new Gdn_Form();
     $Sender->Title(T('Merge Discussions'));
     $DiscussionModel = new DiscussionModel();
     $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
     if (!is_array($CheckedDiscussions)) {
         $CheckedDiscussions = array();
     }
     $DiscussionIDs = $CheckedDiscussions;
     $Sender->SetData('DiscussionIDs', $DiscussionIDs);
     $CountCheckedDiscussions = count($DiscussionIDs);
     $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
     $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
     $Sender->SetData('Discussions', $Discussions);
     // Perform the merge
     if ($Sender->Form->AuthenticatedPostBack()) {
         // Create a new discussion record
         $MergeDiscussion = FALSE;
         $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
         foreach ($Discussions as $Discussion) {
             if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
                 $MergeDiscussion = $Discussion;
                 break;
             }
         }
         $RedirectLink = $Sender->Form->GetFormValue('RedirectLink');
         if ($MergeDiscussion) {
             $ErrorCount = 0;
             // Verify that the user has permission to perform the merge.
             $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
             if ($Category && !$Category['PermsDiscussionsEdit']) {
                 throw PermissionException('Vanilla.Discussions.Edit');
             }
             $DiscussionModel->DefineSchema();
             $MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name'));
             // Assign the comments to the new discussion record
             $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put();
             $CommentModel = new CommentModel();
             foreach ($Discussions as $Discussion) {
                 if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
                     continue;
                 }
                 // Create a comment out of the discussion.
                 $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
                 $Comment['DiscussionID'] = $MergeDiscussionID;
                 $CommentModel->Validation->Results(TRUE);
                 $CommentID = $CommentModel->Save($Comment);
                 if ($CommentID) {
                     // Move any attachments (FileUpload plugin awareness)
                     if (class_exists('MediaModel')) {
                         $MediaModel = new MediaModel();
                         $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
                     }
                     if ($RedirectLink) {
                         // The discussion needs to be changed to a moved link.
                         $RedirectDiscussion = array('Name' => SliceString(sprintf(T('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => FormatString(T('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html');
                         $DiscussionModel->SetField($Discussion['DiscussionID'], $RedirectDiscussion);
                         $CommentModel->UpdateCommentCount($Discussion['DiscussionID']);
                         $CommentModel->RemovePageCache($Discussion['DiscussionID']);
                     } else {
                         // Delete discussion that was merged.
                         $DiscussionModel->Delete($Discussion['DiscussionID']);
                     }
                 } else {
                     $Sender->InformMessage($CommentModel->Validation->ResultsText());
                     $ErrorCount++;
                 }
             }
             // Update counts on all affected discussions.
             $CommentModel->UpdateCommentCount($MergeDiscussionID);
             $CommentModel->RemovePageCache($MergeDiscussionID);
             // Clear selections
             Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
             ModerationController::InformCheckedDiscussions($Sender);
             if ($ErrorCount == 0) {
                 $Sender->JsonTarget('', '', 'Refresh');
             }
         }
     }
     $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
 }
 /**
  *
  * @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);
 }
 /**
  * Handling the event fired at the end of the BuildProfile method of the Profile controller
  * If a valid Steam ID is found, load the profile and add it to the profile sidebar.
  * If no valid Steam ID is found, do nothing.
  *
  * @param Gdn_Controller $Sender
  */
 public function ProfileController_AddProfileTabs_Handler(&$Sender)
 {
     // Instantiating our SteamProfile model and attempting to retrieve the profile data
     $this->SteamProfileModel = new SteamProfileModel();
     // Rustling up the SteamID64 data associated with the user, if available
     $UserMetaSteamID64 = $this->GetUserMeta($Sender->User->UserID, 'SteamID64');
     $SteamID64 = GetValue('Plugin.steamprofile.SteamID64', $UserMetaSteamID64, '');
     // Attempting to retrieve the profile data associated with the SteamID64 field
     $Sender->SetData('SteamProfile', $this->SteamProfileModel->GetByID($SteamID64));
     // Did we get back a valid profile?
     if ($Sender->Data('SteamProfile', FALSE)) {
         // Is there a record(s) for this user's "Most Played Games"?
         if (isset($Sender->Data('SteamProfile')->mostPlayedGames->mostPlayedGame)) {
             // If there are several results, there will be an array of elements.  Is there an array of elements?
             if (is_array($Sender->Data('SteamProfile')->mostPlayedGames->mostPlayedGame)) {
                 //  ...if so, grab the first one.
                 $Sender->SetData('MostPlayedGame', $Sender->Data('SteamProfile')->mostPlayedGames->mostPlayedGame[0]);
             } else {
                 // ...if not, grab the single element.
                 $Sender->SetData('MostPlayedGame', $Sender->Data('SteamProfile')->mostPlayedGames->mostPlayedGame);
             }
         }
         // Attach the style sheet, load up the view, attach it all to the panel
         $Sender->AddCssFile('style.css', 'plugins/steamprofile');
         $Sender->AddAsset('Panel', $Sender->FetchView($this->GetView('panel.php')), 'Steam');
     }
 }
Esempio n. 6
0
 /**
  * Delete a Tag
  *
  * @param Gdn_Controller $Sender
  */
 public function Controller_Delete($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $TagID = GetValue(1, $Sender->RequestArgs);
     $TagModel = new TagModel();
     $Tag = $TagModel->GetID($TagID, DATASET_TYPE_ARRAY);
     if ($Sender->Form->AuthenticatedPostBack()) {
         // Delete tag & tag relations.
         $SQL = Gdn::SQL();
         $SQL->Delete('TagDiscussion', array('TagID' => $TagID));
         $SQL->Delete('Tag', array('TagID' => $TagID));
         $Sender->InformMessage(FormatString(T('<b>{Name}</b> deleted.'), $Tag));
         $Sender->JsonTarget("#Tag_{$Tag['TagID']}", NULL, 'Remove');
     }
     $Sender->SetData('Title', T('Delete Tag'));
     $Sender->Render('delete', '', 'plugins/Tagging');
 }
 /**
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 protected function Settings_AddEdit($Sender, $Args)
 {
     $client_id = $Sender->Request->Get('client_id');
     Gdn::Locale()->SetTranslation('AuthenticationKey', 'Client ID');
     Gdn::Locale()->SetTranslation('AssociationSecret', 'Secret');
     Gdn::Locale()->SetTranslation('AuthenticateUrl', 'Authentication Url');
     $Form = new Gdn_Form();
     $Sender->Form = $Form;
     if ($Form->AuthenticatedPostBack()) {
         if ($Form->GetFormValue('Generate') || $Sender->Request->Post('Generate')) {
             $Form->SetFormValue('AuthenticationKey', mt_rand());
             $Form->SetFormValue('AssociationSecret', md5(mt_rand()));
             $Sender->SetFormSaved(FALSE);
         } else {
             $Form->ValidateRule('AuthenticationKey', 'ValidateRequired');
             //          $Form->ValidateRule('AuthenticationKey', 'regex:`^[a-z0-9_-]+$`i', T('The client id must contain only letters, numbers and dashes.'));
             $Form->ValidateRule('AssociationSecret', 'ValidateRequired');
             $Form->ValidateRule('AuthenticateUrl', 'ValidateRequired');
             $Values = $Form->FormValues();
             //        $Values = ArrayTranslate($Values, array('Name', 'AuthenticationKey', 'URL', 'AssociationSecret', 'AuthenticateUrl', 'SignInUrl', 'RegisterUrl', 'SignOutUrl', 'IsDefault'));
             $Values['AuthenticationSchemeAlias'] = 'jsconnect';
             $Values['AssociationHashMethod'] = 'md5';
             $Values['Attributes'] = serialize(array('HashType' => $Form->GetFormValue('HashType'), 'TestMode' => $Form->GetFormValue('TestMode'), 'Trusted' => $Form->GetFormValue('Trusted', 0)));
             if ($Form->ErrorCount() == 0) {
                 if ($client_id) {
                     Gdn::SQL()->Put('UserAuthenticationProvider', $Values, array('AuthenticationKey' => $client_id));
                 } else {
                     Gdn::SQL()->Options('Ignore', TRUE)->Insert('UserAuthenticationProvider', $Values);
                 }
                 $Sender->RedirectUrl = Url('/settings/jsconnect');
             }
         }
     } else {
         if ($client_id) {
             $Provider = self::GetProvider($client_id);
             TouchValue('Trusted', $Provider, 1);
         } else {
             $Provider = array();
         }
         $Form->SetData($Provider);
     }
     $Sender->SetData('Title', sprintf(T($client_id ? 'Edit %s' : 'Add %s'), T('Connection')));
     $Sender->Render('Settings_AddEdit', '', 'plugins/jsconnect');
 }
Esempio n. 8
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. 9
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. 10
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);
 }
 /**
  * Add the customize text page to the dashboard.
  * 
  * @param Gdn_Controller $Sender
  */
 public function SettingsController_CustomizeText_Create($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->AddSideMenu('settings/customizetext');
     $Sender->AddJsFile('jquery.autogrow.js');
     $Sender->Title('Customize Text');
     $Directive = GetValue(0, $Sender->RequestArgs, '');
     $View = 'customizetext';
     if ($Directive == 'rebuild') {
         $View = 'rebuild';
     } elseif ($Directive == 'rebuildcomplete') {
         $View = 'rebuildcomplete';
     }
     $Method = 'none';
     if ($Sender->Form->IsPostback()) {
         $Method = 'search';
         if ($Sender->Form->GetValue('Save_All')) {
             $Method = 'save';
         }
     }
     $Matches = array();
     $Keywords = NULL;
     switch ($Method) {
         case 'none':
             break;
         case 'search':
         case 'save':
             $Keywords = strtolower($Sender->Form->GetValue('Keywords'));
             if ($Method == 'search') {
                 $Sender->Form->ClearInputs();
                 $Sender->Form->SetFormValue('Keywords', $Keywords);
             }
             $Definitions = Gdn::Locale()->GetDeveloperDefinitions();
             $CountDefinitions = sizeof($Definitions);
             $Sender->SetData('CountDefinitions', $CountDefinitions);
             $Changed = FALSE;
             foreach ($Definitions as $Key => $BaseDefinition) {
                 $KeyHash = md5($Key);
                 $ElementName = "def_{$KeyHash}";
                 // Look for matches
                 $k = strtolower($Key);
                 $d = strtolower($BaseDefinition);
                 // If this key doesn't match, skip it
                 if ($Keywords != '*' && !(strlen($Keywords) > 0 && (strpos($k, $Keywords) !== FALSE || strpos($d, $Keywords) !== FALSE))) {
                     continue;
                 }
                 $Modified = FALSE;
                 // Found a definition, look it up in the real locale first, to see if it has been overridden
                 $CurrentDefinition = Gdn::Locale()->Translate($Key, FALSE);
                 if ($CurrentDefinition !== FALSE && $CurrentDefinition != $BaseDefinition) {
                     $Modified = TRUE;
                 } else {
                     $CurrentDefinition = $BaseDefinition;
                 }
                 $Matches[$Key] = array('def' => $CurrentDefinition, 'mod' => $Modified);
                 if ($CurrentDefinition[0] == "\r\n") {
                     $CurrentDefinition = "\r\n{$CurrentDefinition}";
                 } else {
                     if ($CurrentDefinition[0] == "\r") {
                         $CurrentDefinition = "\r{$CurrentDefinition}";
                     } else {
                         if ($CurrentDefinition[0] == "\n") {
                             $CurrentDefinition = "\n{$CurrentDefinition}";
                         }
                     }
                 }
                 if ($Method == 'save') {
                     $SuppliedDefinition = $Sender->Form->GetValue($ElementName);
                     // Has this field been changed?
                     if ($SuppliedDefinition != FALSE && $SuppliedDefinition != $CurrentDefinition) {
                         // Changed from what it was, but is it a change from the *base* value?
                         $SaveDefinition = $SuppliedDefinition != $BaseDefinition ? $SuppliedDefinition : NULL;
                         if (!is_null($SaveDefinition)) {
                             $CurrentDefinition = $SaveDefinition;
                             $SaveDefinition = str_replace("\r\n", "\n", $SaveDefinition);
                         }
                         Gdn::Locale()->SetTranslation($Key, $SaveDefinition, array('Save' => TRUE, 'RemoveEmpty' => TRUE));
                         $Matches[$Key] = array('def' => $SuppliedDefinition, 'mod' => !is_null($SaveDefinition));
                         $Changed = TRUE;
                     }
                 }
                 $Sender->Form->SetFormValue($ElementName, $CurrentDefinition);
             }
             if ($Changed) {
                 $Sender->InformMessage("Locale changes have been saved!");
             }
             break;
     }
     $Sender->SetData('Matches', $Matches);
     $CountMatches = sizeof($Matches);
     $Sender->SetData('CountMatches', $CountMatches);
     $Sender->Render($View, '', 'plugins/CustomizeText');
 }
   /**
    * Tag management (let admins rename tags, remove tags, etc).
    * TODO: manage the Plugins.Tagging.Required boolean setting that makes tagging required or not.
    * @param Gdn_Controller $Sender
    */
   public function SettingsController_Tagging_Create($Sender, $Args) {
      $Sender->Permission('Garden.Settings.Manage');
      $Sender->Title('Tagging');
      $Sender->AddSideMenu('settings/tagging');
      $Sender->AddCSSFile('plugins/Tagging/design/tagadmin.css');
      $Sender->AddJSFile('plugins/Tagging/admin.js');
      $SQL = Gdn::SQL();

      list($Offset, $Limit) = OffsetLimit($Sender->Request->Get('Page'), 100);
      $Sender->SetData('_Limit', $Limit);

      $Sender->SetData('Tags', $SQL
         ->Select('t.*')
         ->From('Tag t')
         ->OrderBy('t.Name', 'asc')
         ->OrderBy('t.CountDiscussions', 'desc')
         ->Limit($Limit, $Offset)
         ->Get()->ResultArray());

      $Sender->SetData('RecordCount', $SQL->GetCount('Tag'));
         
      $Sender->Render('Tagging', '', 'plugins/Tagging');
   }
Esempio n. 13
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);
 }