/**
  * @return UserModel
  */
 public function GetUserModel()
 {
     if ($this->_UserModel === null) {
         $this->_UserModel = Gdn::UserModel();
     }
     return $this->_UserModel;
 }
 public function AfterImport()
 {
     // Set up the routes to redirect from their older counterparts.
     $Router = Gdn::Router();
     // Categories
     $Router->SetRoute('forumdisplay\\.php\\?f=(\\d+)', 'categories/$1', 'Permanent');
     $Router->SetRoute('archive\\.php/f-(\\d+)\\.html', 'categories/$1', 'Permanent');
     // Discussions & Comments
     $Router->SetRoute('showthread\\.php\\?t=(\\d+)', 'discussion/$1', 'Permanent');
     //$Router->SetRoute('showthread\.php\?p=(\d+)', 'discussion/comment/$1#Comment_$1', 'Permanent');
     //$Router->SetRoute('showpost\.php\?p=(\d+)', 'discussion/comment/$1#Comment_$1', 'Permanent');
     $Router->SetRoute('archive\\.php/t-(\\d+)\\.html', 'discussion/$1', 'Permanent');
     // Profiles
     $Router->SetRoute('member\\.php\\?u=(\\d+)', 'profile/$1/x', 'Permanent');
     $Router->SetRoute('usercp\\.php', 'profile', 'Permanent');
     $Router->SetRoute('profile\\.php', 'profile', 'Permanent');
     // Other
     $Router->SetRoute('attachment\\.php\\?attachmentid=(\\d+)', 'discussion/download/$1', 'Permanent');
     $Router->SetRoute('search\\.php', 'discussions', 'Permanent');
     $Router->SetRoute('private\\.php', 'messages/all', 'Permanent');
     $Router->SetRoute('subscription\\.php', 'discussions/bookmarked', 'Permanent');
     // Make different sizes of avatars
     $this->ProcessAvatars();
     // Prep config for ProfileExtender plugin based on imported fields
     $this->ProfileExtenderPrep();
     // Set guests to System user to prevent security issues
     $SystemUserID = Gdn::UserModel()->GetSystemUserID();
     $this->SQL->Update('Discussion')->Set('InsertUserID', $SystemUserID)->Where('InsertUserID', 0)->Put();
     $this->SQL->Update('Comment')->Set('InsertUserID', $SystemUserID)->Where('InsertUserID', 0)->Put();
 }
Example #3
0
 protected function GetUserInfo($UserReference = '', $Username = '', $UserID = '')
 {
     // If a UserID was provided as a querystring parameter, use it over anything else:
     if ($UserID) {
         $UserReference = $UserID;
         $Username = '******';
         // Fill this with a value so the $UserReference is assumed to be an integer/userid.
     }
     if ($UserReference == '') {
         $User = Gdn::UserModel()->Get(Gdn::Session()->UserID);
     } else {
         if (is_numeric($UserReference) && $Username != '') {
             $User = Gdn::UserModel()->Get($UserReference);
         } else {
             $User = Gdn::UserModel()->GetByUsername($UserReference);
         }
     }
     if ($User === FALSE) {
         throw NotFoundException();
     } else {
         if ($this->User->Deleted == 1) {
             throw NotFoundException();
         } else {
             if (GetValue('UserID', $User) == Gdn::Session()->UserID) {
                 throw NotFoundException();
             } else {
                 return $User;
             }
         }
     }
 }
 public function ProfileController_Quotes_Create($Sender)
 {
     $Sender->Permission('Garden.SignIn.Allow');
     $Sender->Title("Quotes Settings");
     $Args = $Sender->RequestArgs;
     if (sizeof($Args) < 2) {
         $Args = array_merge($Args, array(0, 0));
     } elseif (sizeof($Args) > 2) {
         $Args = array_slice($Args, 0, 2);
     }
     list($UserReference, $Username) = $Args;
     $Sender->GetUserInfo($UserReference, $Username);
     $UserPrefs = Gdn_Format::Unserialize($Sender->User->Preferences);
     if (!is_array($UserPrefs)) {
         $UserPrefs = array();
     }
     $UserID = $ViewingUserID = Gdn::Session()->UserID;
     if ($Sender->User->UserID != $ViewingUserID) {
         $Sender->Permission('Garden.Users.Edit');
         $UserID = $Sender->User->UserID;
     }
     $Sender->SetData('ForceEditing', $UserID == Gdn::Session()->UserID ? FALSE : $Sender->User->Name);
     $QuoteFolding = GetValue('Quotes.Folding', $UserPrefs, '1');
     $Sender->Form->SetValue('QuoteFolding', $QuoteFolding);
     $Sender->SetData('QuoteFoldingOptions', array('None' => "Don't ever fold quotes", '1' => 'One level deep', '2' => 'Two levels deep', '3' => 'Three levels deep', '4' => 'Four levels deep', '5' => 'Five levels deep'));
     // If seeing the form for the first time...
     if ($Sender->Form->IsPostBack()) {
         $NewFoldingLevel = $Sender->Form->GetValue('QuoteFolding', '1');
         if ($NewFoldingLevel != $QuoteFolding) {
             Gdn::UserModel()->SavePreference($UserID, 'Quotes.Folding', $NewFoldingLevel);
             $Sender->InformMessage(T("Your changes have been saved."));
         }
     }
     $Sender->Render('quotes', '', 'plugins/Quotes');
 }
 protected function _AttachPostCount($Sender)
 {
     $User = Gdn::UserModel()->GetID($Sender->EventArguments['Author']->UserID);
     if ($User) {
         $Posts = GetValue('CountComments', $User, 0) + GetValue('CountDiscussions', $User, 0);
         echo '<span class="MItem PostCount">' . Plural(number_format($Posts), '@' . T('Posts.Singular: %s', 'Posts: <b>%s</b>'), '@' . T('Posts.Plural: %s', 'Posts: <b>%s</b>')) . '</span>';
     }
 }
Example #6
0
 /**
  * Checks to see if the user is spamming. Returns TRUE if the user is spamming.
  */
 public function CheckForSpam($Type)
 {
     $Spam = FALSE;
     if (!in_array($Type, array('Comment', 'Discussion'))) {
         trigger_error(ErrorMessage(sprintf('Spam check type unknown: %s', $Type), 'VanillaModel', 'CheckForSpam'), E_USER_ERROR);
     }
     $Session = Gdn::Session();
     $CountSpamCheck = $Session->GetAttribute('Count' . $Type . 'SpamCheck', 0);
     $DateSpamCheck = $Session->GetAttribute('Date' . $Type . 'SpamCheck', 0);
     $SecondsSinceSpamCheck = time() - Format::ToTimestamp($DateSpamCheck);
     $SpamCount = Gdn::Config('Vanilla.' . $Type . '.SpamCount');
     if (!is_numeric($SpamCount) || $SpamCount < 2) {
         $SpamCount = 2;
     }
     // 2 spam minimum
     $SpamTime = Gdn::Config('Vanilla.' . $Type . '.SpamTime');
     if (!is_numeric($SpamTime) || $SpamTime < 0) {
         $SpamTime = 30;
     }
     // 30 second minimum spam span
     $SpamLock = Gdn::Config('Vanilla.' . $Type . '.SpamLock');
     if (!is_numeric($SpamLock) || $SpamLock < 30) {
         $SpamLock = 30;
     }
     // 30 second minimum lockout
     // Definition:
     // Users cannot post more than $SpamCount comments within $SpamTime
     // seconds or their account will be locked for $SpamLock seconds.
     // Apply a spam lock if necessary
     $Attributes = array();
     if ($SecondsSinceSpamCheck < $SpamLock && $CountSpamCheck >= $SpamCount && $DateSpamCheck !== FALSE) {
         // TODO: REMOVE DEBUGGING INFO AFTER THIS IS WORKING PROPERLY
         /*
         echo '<div>SecondsSinceSpamCheck: '.$SecondsSinceSpamCheck.'</div>';
         echo '<div>SpamLock: '.$SpamLock.'</div>';
         echo '<div>CountSpamCheck: '.$CountSpamCheck.'</div>';
         echo '<div>SpamCount: '.$SpamCount.'</div>';
         echo '<div>DateSpamCheck: '.$DateSpamCheck.'</div>';
         echo '<div>SpamTime: '.$SpamTime.'</div>';
         */
         $Spam = TRUE;
         $this->Validation->AddValidationResult('Body', sprintf(T('You have posted %1$s times within %2$s seconds. A spam block is now in effect on your account. You must wait at least %3$s seconds before attempting to post again.'), $SpamCount, $SpamTime, $SpamLock));
         // Update the 'waiting period' every time they try to post again
         $Attributes['Date' . $Type . 'SpamCheck'] = Format::ToDateTime();
     } else {
         if ($SecondsSinceSpamCheck > $SpamTime) {
             $Attributes['Count' . $Type . 'SpamCheck'] = 1;
             $Attributes['Date' . $Type . 'SpamCheck'] = Format::ToDateTime();
         } else {
             $Attributes['Count' . $Type . 'SpamCheck'] = $CountSpamCheck + 1;
         }
     }
     // Update the user profile after every comment
     $UserModel = Gdn::UserModel();
     $UserModel->SaveAttribute($Session->UserID, $Attributes);
     return $Spam;
 }
Example #7
0
 public function ClearPermissions()
 {
     static $PermissionsCleared = FALSE;
     if (!$PermissionsCleared) {
         // Remove the cached permissions for all users.
         Gdn::UserModel()->ClearPermissions();
         $PermissionsCleared = TRUE;
     }
 }
 public function LoadData()
 {
     $UserID = Gdn::Controller()->Data('Profile.UserID', Gdn::Session()->UserID);
     $this->User = Gdn::UserModel()->GetID($UserID);
     $this->Roles = Gdn::UserModel()->GetRoles($UserID)->ResultArray();
     // Hide personal info roles
     if (!CheckPermission('Garden.PersonalInfo.View')) {
         $this->Roles = array_filter($this->Roles, 'RoleModel::FilterPersonalInfo');
     }
 }
Example #9
0
 public function EntryController_RegisterBasic_Create($Sender)
 {
     // print_r($Values);
     // die('ok');
     Gdn::UserModel()->AddPasswordStrength($Sender);
     if ($Sender->Form->IsPostBack() === TRUE) {
         // Add validation rules that are not enforced by the model
         $Sender->UserModel->DefineSchema();
         $Sender->UserModel->Validation->ApplyRule('Name', 'Username', $Sender->UsernameError);
         $Sender->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.'));
         $Sender->UserModel->Validation->ApplyRule('Password', 'Required');
         $Sender->UserModel->Validation->ApplyRule('Password', 'Strength');
         $Sender->UserModel->Validation->ApplyRule('Password', 'Match');
         // $Sender->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge');
         $Sender->FireEvent('RegisterValidation');
         try {
             $Values = $Sender->Form->FormValues();
             unset($Values['Roles']);
             $AuthUserID = $Sender->UserModel->Register($Values);
             if ($AuthUserID == UserModel::REDIRECT_APPROVE) {
                 $Sender->Form->SetFormValue('Target', '/entry/registerthanks');
                 $Sender->_SetRedirect();
                 return;
             } elseif (!$AuthUserID) {
                 $Sender->Form->SetValidationResults($Sender->UserModel->ValidationResults());
             } else {
                 // The user has been created successfully, so sign in now.
                 Gdn::Session()->Start($AuthUserID);
                 if ($Sender->Form->GetFormValue('RememberMe')) {
                     Gdn::Authenticator()->SetIdentity($AuthUserID, TRUE);
                 }
                 try {
                     $Sender->UserModel->SendWelcomeEmail($AuthUserID, '', 'Register');
                 } catch (Exception $Ex) {
                 }
                 $Sender->FireEvent('RegistrationSuccessful');
                 // ... and redirect them appropriately
                 $Route = $Sender->RedirectTo();
                 if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
                     $Sender->RedirectUrl = Url($Route);
                 } else {
                     if ($Route !== FALSE) {
                         Redirect($Route);
                     }
                 }
             }
         } catch (Exception $Ex) {
             $Sender->Form->AddError($Ex);
         }
     }
     $Sender->Render();
 }
 public function toString()
 {
     $users = Gdn::UserModel()->GetIDs($this->getBirthdays());
     if (!$users) {
         return;
     }
     $return = '<div class="Box BirthdayModule"><h4>' . plural(count($users), T("Today's Birthday"), T("Today's Birthdays")) . '</h4><p>';
     foreach ($users as $user) {
         $return .= userPhoto($user, 'Medium') . ' ';
     }
     $return .= '</p></div>';
     return $return;
 }
 /**
  * Check whether or not the record is spam.
  * @param string $RecordType By default, this should be one of the following:
  *  - Comment: A comment.
  *  - Discussion: A discussion.
  *  - User: A user registration.
  * @param array $Data The record data.
  * @param array $Options Options for fine-tuning this method call.
  *  - Log: Log the record if it is found to be spam.
  */
 public static function IsSpam($RecordType, $Data, $Options = array())
 {
     if (self::$Disabled) {
         return FALSE;
     }
     // Set some information about the user in the data.
     if ($RecordType == 'Registration') {
         TouchValue('Username', $Data, $Data['Name']);
     } else {
         TouchValue('InsertUserID', $Data, Gdn::Session()->UserID);
         $User = Gdn::UserModel()->GetID(GetValue('InsertUserID', $Data), DATASET_TYPE_ARRAY);
         if ($User) {
             if (GetValue('Verified', $User)) {
                 // The user has been verified and isn't a spammer.
                 return FALSE;
             }
             TouchValue('Username', $Data, $User['Name']);
             TouchValue('Email', $Data, $User['Email']);
             TouchValue('IPAddress', $Data, $User['LastIPAddress']);
         }
     }
     if (!isset($Data['Body']) && isset($Data['Story'])) {
         $Data['Body'] = $Data['Story'];
     }
     TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress());
     $Sp = self::_Instance();
     $Sp->EventArguments['RecordType'] = $RecordType;
     $Sp->EventArguments['Data'] =& $Data;
     $Sp->EventArguments['Options'] =& $Options;
     $Sp->EventArguments['IsSpam'] = FALSE;
     $Sp->FireEvent('CheckSpam');
     $Spam = $Sp->EventArguments['IsSpam'];
     // Log the spam entry.
     if ($Spam && GetValue('Log', $Options, TRUE)) {
         $LogOptions = array();
         switch ($RecordType) {
             case 'Registration':
                 $LogOptions['GroupBy'] = array('RecordIPAddress');
                 break;
             case 'Comment':
             case 'Discussion':
             case 'Activity':
             case 'ActivityComment':
                 $LogOptions['GroupBy'] = array('RecordID');
                 break;
         }
         LogModel::Insert('Spam', $RecordType, $Data, $LogOptions);
     }
     return $Spam;
 }
Example #12
0
 public function Dismiss($MessageID = '', $TransientKey = FALSE)
 {
     $Session = Gdn::Session();
     if ($TransientKey !== FALSE && $Session->ValidateTransientKey($TransientKey)) {
         $Prefs = $Session->GetPreference('DismissedMessages', array());
         $Prefs[] = $MessageID;
         $UserModel = Gdn::UserModel();
         $UserModel->SavePreference($Session->UserID, 'DismissedMessages', $Prefs);
     }
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         Redirect(GetIncomingValue('Target', '/vanilla/discussions'));
     }
     $this->Render();
 }
Example #13
0
 /**
  * Delete all of the Vanilla related information for a specific user.
  * @param int $UserID The ID of the user to delete.
  * @param array $Options An array of options:
  *  - DeleteMethod: One of delete, wipe, or NULL
  * @since 2.1
  */
 public function DeleteUserData($UserID, $Options = array(), &$Data = NULL)
 {
     $SQL = Gdn::SQL();
     // Remove discussion watch records and drafts.
     $SQL->Delete('UserDiscussion', array('UserID' => $UserID));
     Gdn::UserModel()->GetDelete('Draft', array('InsertUserID' => $UserID), $Data);
     // Comment deletion depends on method selected
     $DeleteMethod = GetValue('DeleteMethod', $Options, 'delete');
     if ($DeleteMethod == 'delete') {
         // Clear out the last posts to the categories.
         $SQL->Update('Category c')->Join('Discussion d', 'd.DiscussionID = c.LastDiscussionID')->Where('d.InsertUserID', $UserID)->Set('c.LastDiscussionID', NULL)->Set('c.LastCommentID', NULL)->Put();
         $SQL->Update('Category c')->Join('Comment d', 'd.CommentID = c.LastCommentID')->Where('d.InsertUserID', $UserID)->Set('c.LastDiscussionID', NULL)->Set('c.LastCommentID', NULL)->Put();
         // Grab all of the discussions that the user has engaged in.
         $DiscussionIDs = $SQL->Select('DiscussionID')->From('Comment')->Where('InsertUserID', $UserID)->GroupBy('DiscussionID')->Get()->ResultArray();
         $DiscussionIDs = ConsolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID');
         Gdn::UserModel()->GetDelete('Comment', array('InsertUserID' => $UserID), $Data);
         // Update the comment counts.
         $CommentCounts = $SQL->Select('DiscussionID')->Select('CommentID', 'count', 'CountComments')->Select('CommentID', 'max', 'LastCommentID')->WhereIn('DiscussionID', $DiscussionIDs)->GroupBy('DiscussionID')->Get('Comment')->ResultArray();
         foreach ($CommentCounts as $Row) {
             $SQL->Put('Discussion', array('CountComments' => $Row['CountComments'] + 1, 'LastCommentID' => $Row['LastCommentID']), array('DiscussionID' => $Row['DiscussionID']));
         }
         // Update the last user IDs.
         $SQL->Update('Discussion d')->Join('Comment c', 'd.LastCommentID = c.CommentID', 'left')->Set('d.LastCommentUserID', 'c.InsertUserID', FALSE, FALSE)->Set('d.DateLastComment', 'c.DateInserted', FALSE, FALSE)->WhereIn('d.DiscussionID', $DiscussionIDs)->Put();
         // Update the last posts.
         $Discussions = $SQL->WhereIn('DiscussionID', $DiscussionIDs)->Where('LastCommentUserID', $UserID)->Get('Discussion');
         // Delete the user's dicussions
         Gdn::UserModel()->GetDelete('Discussion', array('InsertUserID' => $UserID), $Data);
         // Update the appropriat recent posts in the categories.
         $CategoryModel = new CategoryModel();
         $Categories = $CategoryModel->GetWhere(array('LastDiscussionID' => NULL))->ResultArray();
         foreach ($Categories as $Category) {
             $CategoryModel->SetRecentPost($Category['CategoryID']);
         }
     } else {
         if ($DeleteMethod == 'wipe') {
             // Erase the user's dicussions
             $SQL->Update('Discussion')->Set('Body', T('The user and all related content has been deleted.'))->Set('Format', 'Deleted')->Where('InsertUserID', $UserID)->Put();
             // Erase the user's comments
             $SQL->From('Comment')->Join('Discussion d', 'c.DiscussionID = d.DiscussionID')->Delete('Comment c', array('d.InsertUserID' => $UserID));
             $SQL->Update('Comment')->Set('Body', T('The user and all related content has been deleted.'))->Set('Format', 'Deleted')->Where('InsertUserID', $UserID)->Put();
         } else {
             // Leave comments
         }
     }
     // Remove the user's profile information related to this application
     $SQL->Update('User')->Set(array('CountDiscussions' => 0, 'CountUnreadDiscussions' => 0, 'CountComments' => 0, 'CountDrafts' => 0, 'CountBookmarks' => 0))->Where('UserID', $UserID)->Put();
 }
Example #14
0
 public function DiscussionController_BeforeDiscussionRender_Handler($Sender, $Args)
 {
     if (!isset($_GET['noiseless'])) {
         return;
     }
     $Discussion = $Sender->Data('Discussion');
     $Sql = Gdn::SQL();
     $Sql->Select('*')->From('Comment c')->Where('c.DiscussionID', $Discussion->DiscussionID, TRUE, FALSE)->Where('c.InsertUserID', $Discussion->InsertUserID, TRUE, FALSE)->OrderBy('c.DateInserted', 'asc');
     $Result = $Sql->Get();
     Gdn::UserModel()->JoinUsers($Result, array('InsertUserID', 'UpdateUserID'));
     if (self::checkVersion('2.0')) {
         $Sender->SetData('CommentData', $Result, TRUE);
     }
     $Sender->SetData('Comments', $Result);
     $Sender->Pager->Configure(0, 0, 0, '', TRUE);
     $Sender->Offset = 0;
 }
 protected function GetUserEmails($FormValues)
 {
     $SQL = Gdn::SQL();
     $UserModel = Gdn::UserModel();
     if (ArrayValue('SendMeOnly', $FormValues)) {
         $Session = Gdn::Session();
         $UserID = GetValueR('User.UserID', $Session);
         $User = $UserModel->Get($UserID);
         $Result[$User->Email] = $User->Name;
         return $Result;
     }
     $Roles = ArrayValue('Roles', $FormValues);
     if (is_array($Roles) && count($Roles) > 0) {
         $DataSet = $SQL->Select('u.Name, u.Email')->From('UserRole r')->Join('User u', 'u.UserID = r.UserID')->WhereIn('r.RoleID', $Roles)->Get();
     } else {
         $DataSet = $SQL->Select('u.Name, u.Email')->From('User u')->Get();
     }
     $Result = ConsolidateArrayValuesByKey($DataSet->ResultArray(), 'Email', 'Name');
     return $Result;
 }
 protected function DrawEdited($Sender)
 {
     $Record = $Sender->Data('Discussion');
     if (!$Record) {
         $Record = $Sender->Data('Record');
     }
     if (!$Record) {
         return;
     }
     $PermissionCategoryID = GetValue('PermissionCategoryID', $Record);
     $Data = $Record;
     $RecordType = 'discussion';
     $RecordID = GetValue('DiscussionID', $Data);
     // But override if comment
     if (isset($Sender->EventArguments['Comment']) || GetValue('RecordType', $Record) == 'comment') {
         $Data = $Sender->EventArguments['Comment'];
         $RecordType = 'comment';
         $RecordID = GetValue('CommentID', $Data);
     }
     $UserCanEdit = Gdn::Session()->CheckPermission('Vanilla.' . ucfirst($RecordType) . 's.Edit', TRUE, 'Category', $PermissionCategoryID);
     if (is_null($Data->DateUpdated)) {
         return;
     }
     if (Gdn_Format::ToTimestamp($Data->DateUpdated) <= Gdn_Format::ToTimestamp($Data->DateInserted)) {
         return;
     }
     $SourceUserID = $Data->InsertUserID;
     $UpdatedUserID = $Data->UpdateUserID;
     $UserData = Gdn::UserModel()->GetID($UpdatedUserID);
     $Edited = array('EditUser' => GetValue('Name', $UserData, T('Unknown User')), 'EditDate' => Gdn_Format::Date($Data->DateUpdated, 'html'), 'EditLogUrl' => Url("/log/record/{$RecordType}/{$RecordID}"), 'EditWord' => 'at');
     $DateUpdateTime = Gdn_Format::ToTimestamp($Data->DateUpdated);
     if (date('ymd', $DateUpdateTime) != date('ymd')) {
         $Edited['EditWord'] = 'on';
     }
     $Format = T('PostEdited.Plain', 'Post edited by {EditUser} {EditWord} {EditDate}');
     if ($UserCanEdit) {
         $Format = T('PostEdited.Log', 'Post edited by {EditUser} {EditWord} {EditDate} (<a href="{EditLogUrl}">log</a>)');
     }
     $Display = '<div class="PostEdited">' . FormatString($Format, $Edited) . '</div>';
     echo $Display;
 }
Example #17
0
 public function Base_Render_Before(&$Sender)
 {
     $Session = Gdn::Session();
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
         // echo 'test'.$PreviewThemeFolder;
         if ($PreviewThemeFolder != '') {
             $Sender->Theme = $PreviewThemeFolder;
             $Sender->AddAsset('Content', $Sender->FetchView('previewtheme', 'settingscontroller', 'dashboard'));
             $Sender->AddCssFile('previewtheme.css');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     if ($Sender->MasterView == 'admin') {
         $Exceptions[] = '[Admin]';
     } else {
         if (in_array($Sender->MasterView, array('', 'default'))) {
             $Exceptions[] = '[NonAdmin]';
         }
     }
     if ($Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache)) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions);
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             $Sender->AddModule($MessageModule);
         }
     }
     // If there are applicants, alert admins by showing in the main menu
     if (in_array($Sender->MasterView, array('', 'default')) && $Sender->Menu && C('Garden.Registration.Method') == 'Approval') {
         $CountApplicants = Gdn::UserModel()->GetApplicants()->NumRows();
         if ($CountApplicants > 0) {
             $Sender->Menu->AddLink('Applicants', T('Applicants') . ' <span>' . $CountApplicants . '</span>', '/dashboard/user/applicants', array('Garden.Registration.Manage'));
         }
     }
 }
 /**
  * Renders the reaction record for a specific item
  * 
  * @param int $ID
  * @param string $Type 'discussion', 'activity', or 'comment'
  */
 function RenderReactionRecord($ID, $Type)
 {
     $Reactions = Yaga::ReactionModel()->GetRecord($ID, $Type);
     $Limit = C('Yaga.Reactions.RecordLimit');
     $ReactionCount = count($Reactions);
     $i = 0;
     foreach ($Reactions as $Reaction) {
         $i++;
         // Limit the record if there are a lot of reactions
         if ($i <= $Limit || $Limit <= 0) {
             $User = Gdn::UserModel()->GetID($Reaction->UserID);
             $DateTitle = sprintf(T('Yaga.Reactions.RecordFormat'), $User->Name, $Reaction->Name, Gdn_Format::Date($Reaction->DateInserted, '%B %e, %Y'));
             $String = UserPhoto($User, array('Size' => 'Small', 'title' => $DateTitle));
             $String .= '<span class="ReactSprite Reaction-' . $Reaction->ActionID . ' ' . $Reaction->CssClass . '"></span>';
             $Wrapttributes = array('class' => 'UserReactionWrap', 'data-userid' => $User->UserID, 'title' => $DateTitle);
             echo Wrap($String, 'span', $Wrapttributes);
         }
         if ($Limit > 0 && $i >= $ReactionCount && $ReactionCount > $Limit) {
             echo Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural');
         }
     }
 }
 /**
  * @param DiscussionController $Sender
  */
 public function DiscussionController_Render_Before($Sender, $Args)
 {
     $ConversationID = $Sender->Data('Discussion.Attributes.WhisperConversationID');
     if (!$ConversationID) {
         return;
     }
     if ($ConversationID === TRUE) {
         $UserIDs = $Sender->Data('Discussion.Attributes.WhisperUserIDs');
         // Grab the users that are in the conversaton.
         $WhisperUsers = array();
         foreach ($UserIDs as $UserID) {
             $WhisperUsers[] = array('UserID' => $UserID);
         }
     } else {
         // There is already a conversation so grab its users.
         $WhisperUsers = Gdn::SQL()->Select('UserID')->From('UserConversation')->Where('ConversationID', $ConversationID)->Where('Deleted', 0)->Get()->ResultArray();
         $UserIDs = ConsolidateArrayValuesByKey($WhisperUsers, 'UserID');
     }
     if (!Gdn::Session()->CheckPermission('Conversations.Moderation.Manage') && !in_array(Gdn::Session()->UserID, $UserIDs)) {
         $Sender->Data['Discussion']->Closed = TRUE;
         return;
     }
     Gdn::UserModel()->JoinUsers($WhisperUsers, array('UserID'));
     $Sender->SetData('WhisperUsers', $WhisperUsers);
 }
 public function RemovePicture($UserReference = '', $Username = '', $TransientKey = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $this->GetUserInfo($UserReference, $Username);
     $RedirectUrl = 'dashboard/profile/' . $UserReference . '/' . Gdn_Format::Url($Username);
     if ($Session->ValidateTransientKey($TransientKey) && is_object($this->User) && ($this->User->UserID == $Session->UserID || $Session->CheckPermission('Garden.Users.Edit'))) {
         Gdn::UserModel()->RemovePicture($this->User->UserID);
         $this->StatusMessage = T('Your picture has been removed.');
         $RedirectUrl = 'dashboard/profile/' . Gdn_Format::Url($this->User->Name);
     }
     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         Redirect($RedirectUrl);
     } else {
         $this->ControllerName = 'Home';
         $this->View = 'FileNotFound';
         $this->RedirectUrl = Url($RedirectUrl);
         $this->Render();
     }
 }
Example #21
0
 public function Save2($CommentID, $Insert, $CheckExisting = TRUE)
 {
     $Fields = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
     $Session = Gdn::Session();
     // Make a quick check so that only the user making the comment can make the notification.
     // This check may be used in the future so should not be depended on later in the method.
     if ($Fields['InsertUserID'] != $Session->UserID) {
         return;
     }
     $DiscussionModel = new DiscussionModel();
     $DiscussionID = ArrayValue('DiscussionID', $Fields);
     $Discussion = $DiscussionModel->GetID($DiscussionID);
     if ($Insert) {
         // Notify any users who were mentioned in the comment
         $Usernames = GetMentions($Fields['Body']);
         $UserModel = Gdn::UserModel();
         $Story = ArrayValue('Body', $Fields, '');
         $NotifiedUsers = array();
         foreach ($Usernames as $Username) {
             $User = $UserModel->GetByUsername($Username);
             if ($User && $User->UserID != $Session->UserID) {
                 $NotifiedUsers[] = $User->UserID;
                 $ActivityModel = new ActivityModel();
                 $ActivityID = $ActivityModel->Add($Session->UserID, 'CommentMention', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $User->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
                 $ActivityModel->SendNotification($ActivityID, $Story);
             }
         }
         // Notify users who have bookmarked the discussion
         $BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
         foreach ($BookmarkData->Result() as $Bookmark) {
             if (!in_array($Bookmark->UserID, $NotifiedUsers) && $Bookmark->UserID != $Session->UserID) {
                 $NotifiedUsers[] = $Bookmark->UserID;
                 $ActivityModel = new ActivityModel();
                 $ActivityID = $ActivityModel->Add($Session->UserID, 'BookmarkComment', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $Bookmark->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
                 $ActivityModel->SendNotification($ActivityID, $Story);
             }
         }
         // Record user-comment activity
         if ($Discussion !== FALSE && !in_array($Session->UserID, $NotifiedUsers)) {
             $this->RecordActivity($Discussion, $Session->UserID, $CommentID, 'Only');
         }
     }
     $this->UpdateCommentCount($DiscussionID);
     // Mark the comment read (note: add 1 to $Discussion->CountComments because this comment has been added since $Discussion was loaded)
     $this->SetWatch($Discussion, $Discussion->CountComments, $Discussion->CountComments + 1, $Discussion->CountComments + 1);
     // Update the discussion author's CountUnreadDiscussions (ie.
     // the number of discussions created by the user that s/he has
     // unread messages in) if this comment was not added by the
     // discussion author.
     $Data = $this->SQL->Select('d.InsertUserID')->Select('d.DiscussionID', 'count', 'CountDiscussions')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = d.InsertUserID')->Where('w.CountComments >', 0)->Where('c.InsertUserID', $Session->UserID)->Where('c.InsertUserID <>', 'd.InsertUserID', TRUE, FALSE)->GroupBy('d.InsertUserID')->Get();
     if ($Data->NumRows() > 0) {
         $UserData = $Data->FirstRow();
         $this->SQL->Update('User')->Set('CountUnreadDiscussions', $UserData->CountDiscussions)->Where('UserID', $UserData->InsertUserID)->Put();
     }
     $this->UpdateUser($Session->UserID);
 }
 /**
  * Allows user to mark all discussions as viewed.
  *
  * @since 1.0
  * @access public
  */
 public function DiscussionsController_MarkAllViewed_Create($Sender)
 {
     $UserModel = Gdn::UserModel();
     $UserModel->UpdateAllViewed();
     Redirect('discussions');
 }
Example #23
0
 public function Applicants()
 {
     $this->Permission('Garden.Users.Approve');
     $this->AddSideMenu('garden/user/applicants');
     $this->AddJsFile('/js/library/jquery.gardencheckcolumn.js');
     $this->Title(T('Applicants'));
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $Action = $this->Form->GetValue('Submit');
         $Applicants = $this->Form->GetValue('Applicants');
         $ApplicantCount = is_array($Applicants) ? count($Applicants) : 0;
         if ($ApplicantCount > 0 && in_array($Action, array('Approve', 'Decline'))) {
             $Session = Gdn::Session();
             for ($i = 0; $i < $ApplicantCount; ++$i) {
                 $this->HandleApplicant($Action, $Applicants[$i]);
             }
         }
     }
     $UserModel = Gdn::UserModel();
     $this->UserData = $UserModel->GetApplicants();
     $this->View = 'applicants';
     $this->Render();
 }
Example #24
0
 /**
  * Sets a value in the $this->_Preferences array. This setting will persist
  * changes to user prefs.
  *
  * @param string|array $Name
  * @param mixed $Value
  * @todo check argument type
  */
 public function SetPreference($Name, $Value = '', $SaveToDatabase = TRUE)
 {
     if (!is_array($Name)) {
         $Name = array($Name => $Value);
     }
     foreach ($Name as $Key => $Val) {
         $this->_Preferences[$Key] = $Val;
     }
     if ($SaveToDatabase && $this->UserID > 0) {
         $UserModel = Gdn::UserModel();
         $UserModel->SavePreference($this->UserID, $Name);
     }
 }
Example #25
0
function _FormatStringCallback($Match, $SetArgs = FALSE)
{
    static $Args = array();
    if ($SetArgs) {
        $Args = $Match;
        return;
    }
    $Match = $Match[1];
    if ($Match == '{') {
        return $Match;
    }
    // Parse out the field and format.
    $Parts = explode(',', $Match);
    $Field = trim($Parts[0]);
    $Format = trim(GetValue(1, $Parts, ''));
    $SubFormat = strtolower(trim(GetValue(2, $Parts, '')));
    $FormatArgs = GetValue(3, $Parts, '');
    if (in_array($Format, array('currency', 'integer', 'percent'))) {
        $FormatArgs = $SubFormat;
        $SubFormat = $Format;
        $Format = 'number';
    } elseif (is_numeric($SubFormat)) {
        $FormatArgs = $SubFormat;
        $SubFormat = '';
    }
    $Value = GetValueR($Field, $Args, '');
    if ($Value == '' && !in_array($Format, array('url', 'exurl'))) {
        $Result = '';
    } else {
        switch (strtolower($Format)) {
            case 'date':
                switch ($SubFormat) {
                    case 'short':
                        $Result = Gdn_Format::Date($Value, '%d/%m/%Y');
                        break;
                    case 'medium':
                        $Result = Gdn_Format::Date($Value, '%e %b %Y');
                        break;
                    case 'long':
                        $Result = Gdn_Format::Date($Value, '%e %B %Y');
                        break;
                    default:
                        $Result = Gdn_Format::Date($Value);
                        break;
                }
                break;
            case 'html':
            case 'htmlspecialchars':
                $Result = htmlspecialchars($Value);
                break;
            case 'number':
                if (!is_numeric($Value)) {
                    $Result = $Value;
                } else {
                    switch ($SubFormat) {
                        case 'currency':
                            $Result = '$' . number_format($Value, is_numeric($FormatArgs) ? $FormatArgs : 2);
                        case 'integer':
                            $Result = (string) round($Value);
                            if (is_numeric($FormatArgs) && strlen($Result) < $FormatArgs) {
                                $Result = str_repeat('0', $FormatArgs - strlen($Result)) . $Result;
                            }
                            break;
                        case 'percent':
                            $Result = round($Value * 100, is_numeric($FormatArgs) ? $FormatArgs : 0);
                            break;
                        default:
                            $Result = number_format($Value, is_numeric($FormatArgs) ? $FormatArgs : 0);
                            break;
                    }
                }
                break;
            case 'plural':
                if (is_array($Value)) {
                    $Value = count($Value);
                } elseif (StringEndsWith($Field, 'UserID', TRUE)) {
                    $Value = 1;
                }
                if (!is_numeric($Value)) {
                    $Result = $Value;
                } else {
                    if (!$SubFormat) {
                        $SubFormat = rtrim("%s {$Field}", 's');
                    }
                    if (!$FormatArgs) {
                        $FormatArgs = $SubFormat . 's';
                    }
                    $Result = Plural($Value, $SubFormat, $FormatArgs);
                }
                break;
            case 'rawurlencode':
                $Result = rawurlencode($Value);
                break;
            case 'text':
                $Result = Gdn_Format::Text($Value, FALSE);
                break;
            case 'time':
                $Result = Gdn_Format::Date($Value, '%l:%M%p');
                break;
            case 'url':
                if (strpos($Field, '/') !== FALSE) {
                    $Value = $Field;
                }
                $Result = Url($Value, $SubFormat == 'domain');
                break;
            case 'exurl':
                if (strpos($Field, '/') !== FALSE) {
                    $Value = $Field;
                }
                $Result = ExternalUrl($Value);
                break;
            case 'urlencode':
                $Result = urlencode($Value);
                break;
            case 'gender':
                // Format in the form of FieldName,gender,male,female,unknown
                if (is_array($Value) && count($Value) == 1) {
                    $Value = array_shift($Value);
                }
                $Gender = 'u';
                if (!is_array($Value)) {
                    $User = Gdn::UserModel()->GetID($Value);
                    if ($User) {
                        $Gender = $User->Gender;
                    }
                }
                switch ($Gender) {
                    case 'm':
                        $Result = $SubFormat;
                        break;
                    case 'f':
                        $Result = $FormatArgs;
                        break;
                    default:
                        $Result = GetValue(4, $Parts);
                }
                break;
            case 'user':
            case 'you':
            case 'his':
            case 'her':
            case 'your':
                $Result = print_r($Value, TRUE);
                $ArgsBak = $Args;
                if (is_array($Value) && count($Value) == 1) {
                    $Value = array_shift($Value);
                }
                if (is_array($Value)) {
                    $Max = C('Garden.FormatUsername.Max', 5);
                    $Count = count($Value);
                    $Result = '';
                    for ($i = 0; $i < $Count; $i++) {
                        if ($i >= $Max && $Count > $Max + 1) {
                            $Others = $Count - $i;
                            $Result .= ' ' . T('sep and', 'and') . ' ' . Plural($Others, '%s other', '%s others');
                            break;
                        }
                        $ID = $Value[$i];
                        if (is_array($ID)) {
                            continue;
                        }
                        if ($i == $Count - 1) {
                            $Result .= ' ' . T('sep and', 'and') . ' ';
                        } elseif ($i > 0) {
                            $Result .= ', ';
                        }
                        $Special = array(-1 => T('everyone'), -2 => T('moderators'), -3 => T('administrators'));
                        if (isset($Special[$ID])) {
                            $Result .= $Special[$ID];
                        } else {
                            $User = Gdn::UserModel()->GetID($ID);
                            $User->Name = FormatUsername($User, $Format, Gdn::Session()->UserID);
                            $Result .= UserAnchor($User);
                        }
                    }
                } else {
                    $User = Gdn::UserModel()->GetID($Value);
                    $User->Name = FormatUsername($User, $Format, Gdn::Session()->UserID);
                    $Result = UserAnchor($User);
                }
                $Args = $ArgsBak;
                break;
            default:
                $Result = $Value;
                break;
        }
    }
    return $Result;
}
 public function Post($Notify = FALSE, $UserID = FALSE)
 {
     if (is_numeric($Notify)) {
         $UserID = $Notify;
         $Notify = FALSE;
     }
     if (!$UserID) {
         $UserID = Gdn::Session()->UserID;
     }
     switch ($Notify) {
         case 'mods':
             $this->Permission('Garden.Moderation.Manage');
             $NotifyUserID = ActivityModel::NOTIFY_MODS;
             break;
         case 'admins':
             $this->Permission('Garden.Settings.Manage');
             $NotifyUserID = ActivityModel::NOTIFY_ADMINS;
             break;
         default:
             $this->Permission('Garden.Profiles.Edit');
             $NotifyUserID = ActivityModel::NOTIFY_PUBLIC;
             break;
     }
     $Activities = array();
     if ($this->Form->IsPostBack()) {
         $Data = $this->Form->FormValues();
         $Data = $this->ActivityModel->FilterForm($Data);
         if (!isset($Data['Format']) || strcasecmp($Data['Format'], 'Raw') == 0) {
             $Data['Format'] = C('Garden.InputFormatter');
         }
         if ($UserID != Gdn::Session()->UserID) {
             // This is a wall post.
             $Activity = array('ActivityType' => 'WallPost', 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::Session()->UserID, 'HeadlineFormat' => T('HeadlineFormat.WallPost', '{RegardingUserID,you} &rarr; {ActivityUserID,you}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format']);
         } else {
             // This is a status update.
             $Activity = array('ActivityType' => 'Status', 'HeadlineFormat' => T('HeadlineFormat.Status', '{ActivityUserID,user}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format'], 'NotifyUserID' => $NotifyUserID);
             $this->SetJson('StatusMessage', Gdn_Format::PlainText($Activity['Story'], $Activity['Format']));
         }
         $Activity = $this->ActivityModel->Save($Activity, FALSE, array('CheckSpam' => TRUE));
         if ($Activity == SPAM || $Activity == UNAPPROVED) {
             $this->StatusMessage = T('ActivityRequiresApproval', 'Your post will appear after it is approved.');
             $this->Render('Blank', 'Utility');
             return;
         }
         if ($Activity) {
             if ($UserID == Gdn::Session()->UserID && $NotifyUserID == ActivityModel::NOTIFY_PUBLIC) {
                 Gdn::UserModel()->SetField(Gdn::Session()->UserID, 'About', Gdn_Format::PlainText($Activity['Story'], $Activity['Format']));
             }
             $Activities = array($Activity);
             ActivityModel::JoinUsers($Activities);
             $this->ActivityModel->CalculateData($Activities);
         } else {
             $this->Form->SetValidationResults($this->ActivityModel->ValidationResults());
             $this->StatusMessage = $this->ActivityModel->Validation->ResultsText();
             //            $this->Render('Blank', 'Utility');
         }
     }
     if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
         Redirect($this->Request->Get('Target', '/activity'));
     }
     $this->SetData('Activities', $Activities);
     $this->Render('Activities');
 }
Example #27
0
 /**
  * Saves the category.
  * 
  * @since 2.0.0
  * @access public
  *
  * @param array $FormPostValue The values being posted back from the form.
  * @return int ID of the saved category.
  */
 public function Save($FormPostValues)
 {
     // Define the primary key in this model's table.
     $this->DefineSchema();
     // Get data from form
     $CategoryID = ArrayValue('CategoryID', $FormPostValues);
     $NewName = ArrayValue('Name', $FormPostValues, '');
     $UrlCode = ArrayValue('UrlCode', $FormPostValues, '');
     $AllowDiscussions = ArrayValue('AllowDiscussions', $FormPostValues, '');
     $CustomPermissions = (bool) GetValue('CustomPermissions', $FormPostValues);
     // Is this a new category?
     $Insert = $CategoryID > 0 ? FALSE : TRUE;
     if ($Insert) {
         $this->AddInsertFields($FormPostValues);
     }
     $this->AddUpdateFields($FormPostValues);
     $this->Validation->ApplyRule('UrlCode', 'Required');
     $this->Validation->ApplyRule('UrlCode', 'UrlStringRelaxed');
     // Make sure that the UrlCode is unique among categories.
     $this->SQL->Select('CategoryID')->From('Category')->Where('UrlCode', $UrlCode);
     if ($CategoryID) {
         $this->SQL->Where('CategoryID <>', $CategoryID);
     }
     if ($this->SQL->Get()->NumRows()) {
         $this->Validation->AddValidationResult('UrlCode', 'The specified url code is already in use by another category.');
     }
     //	Prep and fire event.
     $this->EventArguments['FormPostValues'] =& $FormPostValues;
     $this->EventArguments['CategoryID'] = $CategoryID;
     $this->FireEvent('BeforeSaveCategory');
     // Validate the form posted values
     if ($this->Validate($FormPostValues, $Insert)) {
         $Fields = $this->Validation->SchemaValidationFields();
         $Fields = RemoveKeyFromArray($Fields, 'CategoryID');
         $AllowDiscussions = ArrayValue('AllowDiscussions', $Fields) == '1' ? TRUE : FALSE;
         $Fields['AllowDiscussions'] = $AllowDiscussions ? '1' : '0';
         if ($Insert === FALSE) {
             $OldCategory = $this->GetID($CategoryID, DATASET_TYPE_ARRAY);
             $AllowDiscussions = $OldCategory['AllowDiscussions'];
             // Force the allowdiscussions property
             $Fields['AllowDiscussions'] = $AllowDiscussions ? '1' : '0';
             $this->Update($Fields, array('CategoryID' => $CategoryID));
             // Check for a change in the parent category.
             if (isset($Fields['ParentCategoryID']) && $OldCategory['ParentCategoryID'] != $Fields['ParentCategoryID']) {
                 $this->RebuildTree();
             } else {
                 $this->SetCache($CategoryID, $Fields);
             }
         } else {
             $CategoryID = $this->Insert($Fields);
             if ($CustomPermissions && $CategoryID) {
                 $this->SQL->Put('Category', array('PermissionCategoryID' => $CategoryID), array('CategoryID' => $CategoryID));
             }
             $this->RebuildTree();
             // Safeguard to make sure that treeleft and treeright cols are added
         }
         // Save the permissions
         if ($AllowDiscussions && $CategoryID) {
             // Check to see if this category uses custom permissions.
             if ($CustomPermissions) {
                 $PermissionModel = Gdn::PermissionModel();
                 $Permissions = $PermissionModel->PivotPermissions(GetValue('Permission', $FormPostValues, array()), array('JunctionID' => $CategoryID));
                 $PermissionModel->SaveAll($Permissions, array('JunctionID' => $CategoryID, 'JunctionTable' => 'Category'));
                 if (!$Insert) {
                     // Figure out my last permission and tree info.
                     $Data = $this->SQL->Select('PermissionCategoryID, TreeLeft, TreeRight')->From('Category')->Where('CategoryID', $CategoryID)->Get()->FirstRow(DATASET_TYPE_ARRAY);
                     // Update this category's permission.
                     $this->SQL->Put('Category', array('PermissionCategoryID' => $CategoryID), array('CategoryID' => $CategoryID));
                     // Update all of my children that shared my last category permission.
                     $this->SQL->Put('Category', array('PermissionCategoryID' => $CategoryID), array('TreeLeft >' => $Data['TreeLeft'], 'TreeRight <' => $Data['TreeRight'], 'PermissionCategoryID' => $Data['PermissionCategoryID']));
                     self::ClearCache();
                 }
             } elseif (!$Insert) {
                 // Figure out my parent's permission.
                 $NewPermissionID = $this->SQL->Select('p.PermissionCategoryID')->From('Category c')->Join('Category p', 'c.ParentCategoryID = p.CategoryID')->Where('c.CategoryID', $CategoryID)->Get()->Value('PermissionCategoryID', 0);
                 if ($NewPermissionID != $CategoryID) {
                     // Update all of my children that shared my last permission.
                     $this->SQL->Put('Category', array('PermissionCategoryID' => $NewPermissionID), array('PermissionCategoryID' => $CategoryID));
                     self::ClearCache();
                 }
                 // Delete my custom permissions.
                 $this->SQL->Delete('Permission', array('JunctionTable' => 'Category', 'JunctionColumn' => 'PermissionCategoryID', 'JunctionID' => $CategoryID));
             }
         }
         // Force the user permissions to refresh.
         Gdn::UserModel()->ClearPermissions();
         // $this->RebuildTree();
     } else {
         $CategoryID = FALSE;
     }
     return $CategoryID;
 }
Example #28
0
 public function NotSpam($LogIDs)
 {
     $this->Permission('Garden.Moderation.Manage');
     if (!$this->Request->IsPostBack()) {
         throw PermissionException('Javascript');
     }
     $Logs = array();
     // Verify the appropriate users.
     $UserIDs = $this->Form->GetFormValue('UserID', array());
     if (!is_array($UserIDs)) {
         $UserIDs = array();
     }
     foreach ($UserIDs as $UserID) {
         Gdn::UserModel()->SetField($UserID, 'Verified', TRUE);
         $Logs = array_merge($Logs, $this->LogModel->GetWhere(array('Operation' => 'Spam', 'RecordUserID' => $UserID)));
     }
     // Grab the logs.
     $Logs = array_merge($Logs, $this->LogModel->GetIDs($LogIDs));
     //      try {
     foreach ($Logs as $Log) {
         $this->LogModel->Restore($Log);
     }
     //      } catch (Exception $Ex) {
     //         $this->Form->AddError($Ex->getMessage());
     //      }
     $this->LogModel->Recalculate();
     $this->SetData('Complete');
     $this->SetData('Count', count($Logs));
     $this->Render('Blank', 'Utility');
 }
 public function RecalculateUserQnA($UserID)
 {
     $CountAcceptedAnswers = Gdn::SQL()->GetCount('Comment', array('InsertUserID' => $UserID, 'QnA' => 'Accepted'));
     Gdn::UserModel()->SetField($UserID, 'CountAcceptedAnswers', $CountAcceptedAnswers);
 }
   public function SetClientHour($ClientHour = '', $TransientKey = '') {
      $this->_DeliveryType = DELIVERY_TYPE_BOOL;
      $Session = Gdn::Session();
      $Success = FALSE;
      if (
			is_numeric($ClientHour)
			&& $Session->UserID > 0
         && $Session->ValidateTransientKey($TransientKey)
      ) {
         $UserModel = Gdn::UserModel();
			$HourOffset = $ClientHour - date('G', time());
			$UserModel->Update(array('HourOffset' => $HourOffset), array('UserID' => $Session->UserID));
			$Success = TRUE;
      }
         
      $this->Render();
   }