public function Save($FormPostValues) { $Session = Gdn::Session(); // Define the primary key in this model's table. $this->DefineSchema(); // Add & apply any extra validation rules: $this->Validation->ApplyRule('Body', 'Required'); $this->AddInsertFields($FormPostValues); // Validate the form posted values $MessageID = FALSE; if ($this->Validate($FormPostValues)) { $Fields = $this->Validation->SchemaValidationFields(); // All fields on the form that relate to the schema $MessageID = $this->SQL->Insert($this->Name, $Fields); $ConversationID = ArrayValue('ConversationID', $Fields, 0); // Update the conversation's DateUpdated field $this->SQL->Update('Conversation')->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $Session->UserID)->Where('ConversationID', $ConversationID)->Put(); // NOTE: INCREMENTING COUNTS INSTEAD OF GETTING ACTUAL COUNTS COULD // BECOME A PROBLEM. WATCH FOR IT. // Update the message counts for all users in the conversation $this->SQL->Update('UserConversation')->Set('CountMessages', 'CountMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Put(); $this->SQL->Update('UserConversation')->Set('CountNewMessages', 'CountNewMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put(); // Update the CountUnreadConversations count on each user related to the discussion. $this->UpdateCountUnreadConversations($ConversationID, $Session->UserID); // Update the userconversation records to reflect the most recently // added message for all users other than the one that added the // message (otherwise they would see their name/message on the // conversation list instead of the person they are conversing with). $this->SQL->Update('UserConversation')->Set('LastMessageID', $MessageID)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put(); } return $MessageID; }
/** * 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; }
public function SetWatch($Discussion, $Limit, $Offset, $TotalComments) { // Record the user's watch data $Session = Gdn::Session(); if ($Session->UserID > 0) { $CountWatch = $Limit + $Offset; if ($CountWatch > $TotalComments) { $CountWatch = $TotalComments; } if (is_numeric($Discussion->CountCommentWatch)) { // Update the watch data $this->SQL->Put('UserDiscussion', array('CountComments' => $CountWatch, 'DateLastViewed' => Format::ToDateTime()), array('UserID' => $Session->UserID, 'DiscussionID' => $Discussion->DiscussionID, 'CountComments <' => $CountWatch)); } else { // Insert watch data $this->SQL->Insert('UserDiscussion', array('UserID' => $Session->UserID, 'DiscussionID' => $Discussion->DiscussionID, 'CountComments' => $CountWatch, 'DateLastViewed' => Format::ToDateTime())); } } }
public function Save($FormPostValues) { $Session = Gdn::Session(); // Define the primary key in this model's table. $this->DefineSchema(); // Add & apply any extra validation rules: $this->Validation->ApplyRule('Body', 'Required'); $this->AddInsertFields($FormPostValues); // Validate the form posted values $MessageID = FALSE; if ($this->Validate($FormPostValues)) { $Fields = $this->Validation->SchemaValidationFields(); // All fields on the form that relate to the schema $MessageID = $this->SQL->Insert($this->Name, $Fields); $ConversationID = ArrayValue('ConversationID', $Fields, 0); // Update the conversation's DateUpdated field $this->SQL->Update('Conversation')->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $Session->UserID)->Where('ConversationID', $ConversationID)->Put(); // NOTE: INCREMENTING COUNTS INSTEAD OF GETTING ACTUAL COUNTS COULD // BECOME A PROBLEM. WATCH FOR IT. // Update the message counts for all users in the conversation $this->SQL->Update('UserConversation')->Set('CountMessages', 'CountMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Put(); $this->SQL->Update('UserConversation')->Set('CountNewMessages', 'CountNewMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put(); // Update the userconversation records to reflect the most recently // added message for all users other than the one that added the // message (otherwise they would see their name/message on the // conversation list instead of the person they are conversing with). $this->SQL->Update('UserConversation')->Set('LastMessageID', $MessageID)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put(); // Update the CountUnreadConversations count on each user related to the discussion. // And notify the users of the new message $UnreadData = $this->SQL->Select('c.UserID')->Select('c2.CountNewMessages', 'count', 'CountUnreadConversations')->From('UserConversation c')->Join('UserConversation c2', 'c.UserID = c2.UserID')->Where('c2.CountNewMessages >', 0)->Where('c.ConversationID', $ConversationID)->Where('c.UserID <>', $Session->UserID)->GroupBy('c.UserID')->Get(); $ActivityModel = new Gdn_ActivityModel(); foreach ($UnreadData->Result() as $User) { // Update the CountUnreadConversations count on each user related to the discussion. $this->SQL->Update('User')->Set('CountUnreadConversations', $User->CountUnreadConversations)->Where('UserID', $User->UserID)->Put(); // And notify the users of the new message $ActivityID = $ActivityModel->Add($Session->UserID, 'ConversationMessage', '', $User->UserID, '', '/messages/' . $ConversationID . '#' . $MessageID, FALSE); $Story = ArrayValue('Body', $Fields, ''); $ActivityModel->SendNotification($ActivityID, $Story); } } return $MessageID; }
public function SettingsController_DashboardData_Handler(&$Sender) { $DiscussionModel = new Gdn_DiscussionModel(); // Number of Discussions $CountDiscussions = $DiscussionModel->GetCount(); $Sender->AddDefinition('CountDiscussions', $CountDiscussions); $Sender->BuzzData[Gdn::Translate('Discussions')] = number_format($CountDiscussions); // Number of New Discussions in the last day $Sender->BuzzData[Translate('New discussions in the last day')] = number_format($DiscussionModel->GetCount(array('d.DateInserted >=' => Format::ToDateTime(strtotime('-1 day'))))); // Number of New Discussions in the last week $Sender->BuzzData[Translate('New discussions in the last week')] = number_format($DiscussionModel->GetCount(array('d.DateInserted >=' => Format::ToDateTime(strtotime('-1 week'))))); $CommentModel = new Gdn_CommentModel(); // Number of Comments $CountComments = $CommentModel->GetCountWhere(); $Sender->AddDefinition('CountComments', $CountComments); $Sender->BuzzData[Gdn::Translate('Comments')] = number_format($CountComments); // Number of New Comments in the last day $Sender->BuzzData[Translate('New comments in the last day')] = number_format($CommentModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 day'))))); // Number of New Comments in the last week $Sender->BuzzData[Translate('New comments in the last week')] = number_format($CommentModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 week'))))); }
public function SettingsController_DashboardData_Handler(&$Sender) { $ConversationModel = new Gdn_ConversationModel(); // Number of Conversations $CountConversations = $ConversationModel->GetCountWhere(); $Sender->AddDefinition('CountConversations', $CountConversations); $Sender->BuzzData[Translate('Conversations')] = number_format($CountConversations); // Number of New Conversations in the last day $Sender->BuzzData[Translate('New conversations in the last day')] = number_format($ConversationModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 day'))))); // Number of New Conversations in the last week $Sender->BuzzData[Translate('New conversations in the last week')] = number_format($ConversationModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 week'))))); $ConversationMessageModel = new Gdn_ConversationMessageModel(); // Number of Messages $CountMessages = $ConversationMessageModel->GetCountWhere(); $Sender->AddDefinition('CountConversationMessages', $CountMessages); $Sender->BuzzData[Translate('Conversation Messages')] = number_format($CountMessages); // Number of New Messages in the last day $Sender->BuzzData[Translate('New messages in the last day')] = number_format($ConversationMessageModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 day'))))); // Number of New Messages in the last week $Sender->BuzzData[Translate('New messages in the last week')] = number_format($ConversationMessageModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 week'))))); }
/** * Add or subtract a value from a comment's score. * @param DiscussionController $Sender The controller that is implementing this method. * @param array $Args The arguments for the operation. */ public function DiscussionController_Score_Create($Sender, $Args) { $CommentID = $Args[0]; $ScoreKey = substr($Args[1], 0, 3) == 'Neg' ? -1 : 1; //$TransientKey = $Args[2]; $SQL = Gdn::SQL(); $Session = Gdn::Session(); // Get the current score for this user. $Data = $SQL->Select('uc.Score')->From('UserComment uc')->Where('uc.CommentID', $CommentID)->Where('uc.UserID', $Session->UserID)->Get()->FirstRow(); $UserScore = $Data ? $Data->Score : 0; // Get the score increments. $Inc = $this->GetScoreIncrements($CommentID, $UserScore); $Score = $Inc[$ScoreKey]; $UserScore += $Score; if ($Score != 0) { if ($Data) { // Update the score on an existing comment. $SQL->Update('UserComment')->Set('Score', $UserScore)->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $Session->UserID)->Where('UserID', $Session->UserID)->Where('CommentID', $CommentID)->Put(); } else { // Insert a new score. $SQL->Insert('UserComment', array('CommentID' => $CommentID, 'UserID' => $Session->UserID, 'Score' => $UserScore, 'DateInserted' => Format::ToDateTime(), 'InsertUserID' => $Session->UserID, 'DateUpdated' => Format::ToDateTime(), 'UpdateUserID' => $Session->UserID)); } // Update the comment table with the sum of the scores. $Data = $SQL->Select('uc.Score', 'sum', 'SumScore')->From('UserComment uc')->Where('uc.CommentID', $CommentID)->Get()->FirstRow(); $SumScore = $Data ? $Data->SumScore : 0; $SQL->Update('Comment')->Set('SumScore', $SumScore)->Where('CommentID', $CommentID)->Put(); $Inc = $this->GetScoreIncrements($CommentID, $UserScore); } // Redirect back where the user came from if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_BOOL) { $Target = GetIncomingValue('Target', '/vanilla/discussions/scored'); Redirect($Target); } // Send the current information back to be dealt with on the client side. $Sender->SetJson('SumScore', isset($SumScore) ? sprintf(Plural($SumScore, '%s point', '%s points'), $SumScore) : NULL); $Sender->SetJson('Inc', $Inc); $Sender->Render(); break; }
/** * Update a conversation as read for a specific user id. */ public function MarkRead($ConversationID, $ReadingUserID) { $this->SQL->Update('UserConversation')->Set('CountNewMessages', 0)->Set('DateLastViewed', Format::ToDateTime())->Where('ConversationID', $ConversationID)->Where('UserID', $ReadingUserID)->Put(); // Also update the unread conversation count for this user $UnreadData = $this->SQL->Select('CountNewMessages', 'count', 'CountUnreadConversations')->From('UserConversation c')->Where('CountNewMessages >', 0)->Where('UserID', $ReadingUserID)->GroupBy('UserID')->Get(); $this->SQL->Update('User')->Set('CountUnreadConversations', $UnreadData->NumRows() > 0 ? $UnreadData->FirstRow()->CountUnreadConversations : 0)->Where('UserID', $ReadingUserID)->Put(); }
/** * Bookmarks (or unbookmarks) a discussion. Returns the current state of the * bookmark (ie. TRUE for bookmarked, FALSE for unbookmarked) */ public function BookmarkDiscussion($DiscussionID, $UserID, &$Discussion = NULL) { $State = '1'; $Discussion = $this->GetID($DiscussionID); if ($Discussion->CountCommentWatch == '') { $this->SQL->Insert('UserDiscussion', array('UserID' => $UserID, 'DiscussionID' => $DiscussionID, 'CountComments' => 0, 'DateLastViewed' => Format::ToDateTime(), 'Bookmarked' => '1')); } else { $State = $Discussion->Bookmarked == '1' ? '0' : '1'; $this->SQL->Update('UserDiscussion')->Set('Bookmarked', $State)->Where('UserID', $UserID)->Where('DiscussionID', $DiscussionID)->Put(); } return $State == '1' ? TRUE : FALSE; }
/** * Update last visit. * * Regenerates other related user properties. * * @param int $UserID * @param array $Attributes * @param string|int|float $ClientHour */ function UpdateLastVisit($UserID, $Attributes, $ClientHour = '') { $UserID = (int) $UserID; if (!$UserID) { throw new Exception('A valid UserId is required.'); } $this->SQL->Update('User')->Set('DateLastActive', Format::ToDateTime())->Set('CountVisits', 'CountVisits + 1', FALSE); if (isset($Attributes) && is_array($Attributes)) { // Generate a new transient key for the user (used to authenticate postbacks). $Attributes['TransientKey'] = RandomString(12); $this->SQL->Set('Attributes', Format::Serialize($Attributes)); } // Set the hour offset based on the client's clock. if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) { $HourOffset = $ClientHour - date('G', time()); $this->SQL->Set('HourOffset', $HourOffset); } $this->SQL->Where('UserID', $UserID)->Put(); }
public function Index() { $this->AddJsFile('settings.js'); $this->Title(Translate('Dashboard')); $this->RequiredAdminPermissions[] = 'Garden.Settings.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Routes.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Applications.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Plugins.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Themes.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Registration.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Applicants.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Roles.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Users.Add'; $this->RequiredAdminPermissions[] = 'Garden.Users.Edit'; $this->RequiredAdminPermissions[] = 'Garden.Users.Delete'; $this->RequiredAdminPermissions[] = 'Garden.Users.Approve'; $this->FireEvent('DefineAdminPermissions'); $this->Permission($this->RequiredAdminPermissions, '', FALSE); $this->AddSideMenu('garden/settings'); $UserModel = Gdn::UserModel(); // Load some data to display on the dashboard $this->BuzzData = array(); // Get the number of users in the database $CountUsers = $UserModel->GetCountLike(); $this->AddDefinition('CountUsers', $CountUsers); $this->BuzzData[Translate('Users')] = number_format($CountUsers); // Get the number of new users in the last day $this->BuzzData[Translate('New users in the last day')] = number_format($UserModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 day'))))); // Get the number of new users in the last week $this->BuzzData[Translate('New users in the last week')] = number_format($UserModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 week'))))); // Get recently active users $this->ActiveUserData = $UserModel->GetActiveUsers(5); // Check to see if the application needs to phone-home for updates. Doing // this here because this method is always called when admin pages are // loaded regardless of the application loading them. $UpdateCheckDate = Gdn::Config('Garden.UpdateCheckDate', ''); if ($UpdateCheckDate == '' || !IsTimestamp($UpdateCheckDate) || $UpdateCheckDate < strtotime("-1 day")) { $UpdateData = array(); // Grab all of the plugins & versions $PluginManager = Gdn::Factory('PluginManager'); $Plugins = $PluginManager->AvailablePlugins(); foreach ($Plugins as $Plugin => $Info) { $Name = ArrayValue('Name', $Info, $Plugin); $Version = ArrayValue('Version', $Info, ''); if ($Version != '') { $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Plugin'); } } // Grab all of the applications & versions $ApplicationManager = Gdn::Factory('ApplicationManager'); $Applications = $ApplicationManager->AvailableApplications(); foreach ($Applications as $Application => $Info) { $Name = ArrayValue('Name', $Info, $Application); $Version = ArrayValue('Version', $Info, ''); if ($Version != '') { $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Application'); } } // Grab all of the themes & versions $ThemeManager = new Gdn_ThemeManager(); $Themes = $ThemeManager->AvailableThemes(); foreach ($Themes as $Theme => $Info) { $Name = ArrayValue('Name', $Info, $Theme); $Version = ArrayValue('Version', $Info, ''); if ($Version != '') { $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Theme'); } } // Dump the entire set of information into the definition list (jQuery // will pick it up and ping the VanillaForums.org server with this info). $this->AddDefinition('UpdateChecks', Format::Serialize($UpdateData)); } // Fire an event so other applications can add some data to be displayed $this->FireEvent('DashboardData'); $this->Render(); }
/** * Saves all settings in $Group to $File. * * @param string $File The full path to the file where the Settings should be saved. * @param string $Group The name of the settings group to be saved to the $File. * @param boolean $RequireSourceFile Should $File be required to exist in order to save? If true, then values * from this file will be merged into the settings array before it is saved. * If false, the values in the settings array will overwrite any values * existing in the file (if it exists). * @return boolean */ public function Save($File = '', $Group = '', $RequireSourceFile = TRUE) { if ($File == '') { $File = $this->_File; } if ($File == '') { trigger_error(ErrorMessage('You must specify a file path to be saved.', 'Configuration', 'Save'), E_USER_ERROR); } if ($Group == '') { $Group = $this->CurrentGroup; } if ($Group == '') { $Group = 'Configuration'; } $Data =& $this->_SaveData; $this->_Sort($Data); // Check for the case when the configuration is the group. if (is_array($Data) && count($Data) == 1 && array_key_exists($Group, $Data)) { $Data = $Data[$Group]; } $NewLines = array(); $NewLines[] = "<?php if (!defined('APPLICATION')) exit();"; $LastName = ''; foreach ($Data as $Name => $Value) { // Write a newline to seperate sections. if ($LastName != $Name && is_array($Value)) { $NewLines[] = ''; $NewLines[] = '// ' . $Name; } $Line = "\$" . $Group . "['" . $Name . "']"; $this->_FormatArrayAssignment($NewLines, $Line, $Value); } // Record who made the change and when if (is_array($NewLines)) { $Session = Gdn::Session(); $User = $Session->UserID > 0 && is_object($Session->User) ? $Session->User->Name : 'Unknown'; $NewLines[] = ''; $NewLines[] = '// Last edited by ' . $User . ' ' . Format::ToDateTime(); } $FileContents = FALSE; if ($NewLines !== FALSE) { $FileContents = implode("\n", $NewLines); } if ($FileContents === FALSE) { trigger_error(ErrorMessage('Failed to define configuration file contents.', 'Configuration', 'Save'), E_USER_ERROR); } // echo 'saving '.$File; //Gdn_FileSystem::SaveFile($File, $FileContents); // Call the built in method to remove the dependancy to an external object. file_put_contents($File, $FileContents); // Clear out the save data array $this->_SaveData = array(); $this->_File = ''; return TRUE; }
/** * Authenticates the user with the provided Authenticator class. * * @param Gdn_IAuthenticator $Authenticator The authenticator used to identify the user making the request. */ function Start($Authenticator) { // Retrieve the authenticated UserID from the Authenticator module. $UserModel = Gdn::UserModel(); $this->UserID = $Authenticator->GetIdentity(); $this->User = FALSE; // Now retrieve user information if ($this->UserID > 0) { // Instantiate a UserModel to get session info $this->User = $UserModel->GetSession($this->UserID); $UserModel->EventArguments['User'] =& $this->User; $UserModel->FireEvent('AfterGetSession'); if ($this->User) { $this->_Permissions = Format::Unserialize($this->User->Permissions); $this->_Preferences = Format::Unserialize($this->User->Preferences); $this->_Attributes = Format::Unserialize($this->User->Attributes); $this->_TransientKey = is_array($this->_Attributes) ? ArrayValue('TransientKey', $this->_Attributes) : FALSE; if ($this->_TransientKey === FALSE) { $this->_TransientKey = $UserModel->SetTransientKey($this->UserID); } // If the user hasn't been active in the session-time, update their date last active $SessionLength = Gdn::Config('Garden.Session.Length', '15 minutes'); if (Format::ToTimestamp($this->User->DateLastActive) < strtotime($SessionLength . ' ago')) { $UserModel->Save(array('UserID' => $this->UserID, 'DateLastActive' => Format::ToDateTime())); } } else { $this->UserID = 0; $this->User = FALSE; $Authenticator->DeAuthenticate(); } } // Load guest permissions if necessary if ($this->UserID == 0) { $this->_Permissions = Format::Unserialize($UserModel->DefinePermissions(0)); } }
public function xIndex() { $this->AddJsFile('settings.js'); $this->Title(Translate('Dashboard')); $this->RequiredAdminPermissions[] = 'Garden.Settings.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Routes.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Applications.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Plugins.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Themes.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Registration.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Applicants.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Roles.Manage'; $this->RequiredAdminPermissions[] = 'Garden.Users.Add'; $this->RequiredAdminPermissions[] = 'Garden.Users.Edit'; $this->RequiredAdminPermissions[] = 'Garden.Users.Delete'; $this->RequiredAdminPermissions[] = 'Garden.Users.Approve'; $this->FireEvent('DefineAdminPermissions'); $this->Permission($this->RequiredAdminPermissions, '', FALSE); $this->AddSideMenu('garden/settings'); $UserModel = Gdn::UserModel(); // Load some data to display on the dashboard $this->BuzzData = array(); // Get the number of users in the database $CountUsers = $UserModel->GetCountLike(); $this->AddDefinition('CountUsers', $CountUsers); $this->BuzzData[Translate('Users')] = number_format($CountUsers); // Get the number of new users in the last day $this->BuzzData[Translate('New users in the last day')] = number_format($UserModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 day'))))); // Get the number of new users in the last week $this->BuzzData[Translate('New users in the last week')] = number_format($UserModel->GetCountWhere(array('DateInserted >=' => Format::ToDateTime(strtotime('-1 week'))))); // Get recently active users $this->ActiveUserData = $UserModel->GetActiveUsers(5); // Check for updates $this->AddUpdateCheck(); // Fire an event so other applications can add some data to be displayed $this->FireEvent('DashboardData'); $this->Render(); }
public function Index($Document, $Keywords = NULL) { $DocumentID = NULL; // Get the keywords ready for inserting. if (is_null($Keywords)) { $Keywords = ArrayValue('Summary', $Document, ''); } $this->FilterKeywords($Keywords); if (!is_array($Keywords) || count($Keywords) == 0) { return; } $Keywords = array_fill_keys($Keywords, NULL); $KeywordsToDelete = array(); self::_TrimString('Title', $Document, 50); self::_TrimString('Summary', $Document, 200); // Get the document id. if (!array_key_exists('DocumentID', $Document)) { // See if there is already a document. $Data = $this->SQL->GetWhere('SearchDocument', array('TableName' => $Document['TableName'], 'PrimaryID' => $Document['PrimaryID']))->FirstRow(); if ($Data) { // The document was found, but must be updated. $DocumentID = $Data->DocumentID; } else { $DocumentID = NULL; } } else { $DocumentID = $Document['DocumentID']; } // Insert or update the document. $Set = array_intersect_key($Document, array('TableName' => '', 'PrimaryID' => '', 'PermissionJunctionID' => '', 'Title' => '', 'Summary' => '', 'Url' => '', 'InsertUserID' => '', 'DateInserted' => '')); if (is_null($DocumentID)) { // There was no document so insert it. if (!array_key_exists('DateInserted', $Set)) { $Set['DateInserted'] = Format::ToDateTime(); } $DocumentID = $this->SQL->Insert('SearchDocument', $Set); } else { $this->SQL->Update('SearchDocument', $Set, array('DocumentID' => $DocumentID))->Put(); // Get the list of current keywords. $Data = $this->SQL->Select('k.KeywordID, k.Keyword')->From('SearchKeyword k')->Join('SearchKeywordDocument d', 'k.KeywordID = d.KeywordID')->Where('d.DocumentID', $DocumentID)->Get(); while ($Row = $Data->NextRow()) { $Keyword = $Row->Keyword; $this->_KeywordCache[$Keyword] = $Row->KeywordID; if (array_key_exists($Keyword, $Keywords)) { // The keyword doesn't have to be inserted. unset($Keywords[$Keyword]); } else { // The keyword has to be deleted. $KeywordsToDelete[] = $Row->KeywordID; } } } // Insert the keywords. $Set = array(); foreach ($Keywords as $Keyword => $KeywordID) { if (!is_null($KeywordID)) { continue; } $Keyword = substr($Keyword, 0, 50); // Make sure the keyword is inserted. if (array_key_exists($Keyword, $this->_KeywordCache)) { $KeywordID = $this->_KeywordCache[$Keyword]; } else { $Data = $this->SQL->GetWhere('SearchKeyword', array('Keyword' => $Keyword))->FirstRow(); if ($Data === FALSE) { $KeywordID = $this->SQL->Insert('SearchKeyword', array('Keyword' => $Keyword)); } else { $KeywordID = $Data->KeywordID; } $this->_KeywordCache[$Keyword] = $KeywordID; } // Build up the set statement. $Set[] = array('KeywordID' => $KeywordID, 'DocumentID' => $DocumentID); } // Delete the keyword links. if (count($KeywordsToDelete) > 0) { $this->SQL->WhereIn('KeywordID', $KeywordsToDelete)->Delete('SearchKeywordDocument', array('DocumentID' => $DocumentID)); } // Insert the link to this document. $this->SQL->Insert('SearchKeywordDocument', $Set); }
<?php if (!defined('APPLICATION')) { exit; } if (!isset($Drop)) { $Drop = FALSE; } if (!isset($Explicit)) { $Explicit = TRUE; } $SQL = $Database->SQL(); $Construct = $Database->Structure(); $Construct->Table('Category')->Column('CategoryID', 'int', 4, FALSE, NULL, 'primary', TRUE)->Column('ParentCategoryID', 'int', 4, TRUE)->Column('CountDiscussions', 'int', 4, FALSE, '0')->Column('AllowDiscussions', array('1', '0'), '', FALSE, '1')->Column('Name', 'varchar', 30)->Column('Description', 'varchar', 250, TRUE)->Column('Sort', 'int', 4, TRUE)->Column('InsertUserID', 'int', 10, FALSE, NULL, 'key')->Column('UpdateUserID', 'int', 10, TRUE)->Column('DateInserted', 'datetime')->Column('DateUpdated', 'datetime')->Set($Explicit, $Drop); if ($Drop) { $SQL->Insert('Category', array('InsertUserID' => 1, 'UpdateUserID' => 1, 'DateInserted' => Format::ToDateTime(), 'DateUpdated' => Format::ToDateTime(), 'Name' => 'General', 'Description' => 'General discussions', 'Sort' => '1')); } // Construct the discussion table. $Construct->Table('Discussion')->Column('DiscussionID', 'int', 11, FALSE, NULL, 'primary', TRUE)->Column('CategoryID', 'int', 4, FALSE, NULL, 'key')->Column('InsertUserID', 'int', 10, FALSE, NULL, 'key')->Column('UpdateUserID', 'int', 10, FALSE, NULL)->Column('FirstCommentID', 'int', 11, TRUE, NULL, 'key')->Column('LastCommentID', 'int', 11, TRUE, NULL, 'key')->Column('Name', 'varchar', 100)->Column('CountComments', 'int', 4, FALSE, '1')->Column('Closed', array('1', '0'), '', FALSE, '0')->Column('Announce', array('1', '0'), '', FALSE, '0')->Column('Sink', array('1', '0'), '', FALSE, '0')->Column('DateInserted', 'datetime')->Column('DateUpdated', 'datetime')->Column('DateLastComment', 'datetime')->Column('Attributes', 'text', '', TRUE)->Set($Explicit, $Drop); // Allows the tracking of relationships between discussions and users (bookmarks, dismissed announcements, # of read comments in a discussion, etc) // Column($Name, $Type, $Length = '', $Null = FALSE, $Default = NULL, $KeyType = FALSE, $AutoIncrement = FALSE) $Construct->Table('UserDiscussion')->Column('UserID', 'int', 11, FALSE, NULL, 'primary')->Column('DiscussionID', 'int', 11, FALSE, NULL, 'primary')->Column('CountComments', 'int', 4, FALSE, '0')->Column('DateLastViewed', 'datetime')->Column('Dismissed', 'varchar', 1, TRUE)->Column('Bookmarked', 'varchar', 1, TRUE)->Set($Explicit, $Drop); $Construct->Table('Comment')->Column('CommentID', 'int', 11, FALSE, NULL, 'primary', TRUE)->Column('DiscussionID', 'int', 11, FALSE, NULL, 'key')->Column('InsertUserID', 'int', 10, TRUE, NULL, 'key')->Column('UpdateUserID', 'int', 10, TRUE)->Column('DeleteUserID', 'int', 10, TRUE)->Column('Body', 'text')->Column('Format', 'varchar', 20, TRUE)->Column('DateInserted', 'datetime')->Column('DateDeleted', 'datetime', '', TRUE)->Column('DateUpdated', 'datetime', '', TRUE)->Column('Flag', 'int', 2, TRUE, 0)->Set($Explicit, $Drop); // Allows the tracking of already-read comments on a per-user basis. $Construct->Table('CommentWatch')->Column('UserID', 'int', 11, FALSE, NULL, 'primary')->Column('CommentID', 'int', 11, FALSE, NULL, 'primary')->Column('DateLastViewed', 'datetime')->Set($Explicit, $Drop); // Add extra columns to user table for tracking discussions & comments $Construct->Table('User')->Column('CountDiscussions', 'int', 11, FALSE, '0')->Column('CountUnreadDiscussions', 'int', 11, FALSE, '0')->Column('CountComments', 'int', 11, FALSE, '0')->Column('CountDrafts', 'int', 11, FALSE, '0')->Column('CountBookmarks', 'int', 11, FALSE, '0')->Set(); $Construct->Table('Draft')->Column('DraftID', 'int', 11, FALSE, NULL, 'primary', TRUE)->Column('DiscussionID', 'int', 11, TRUE, NULL, 'key')->Column('CategoryID', 'int', 4, TRUE, NULL, 'key')->Column('InsertUserID', 'int', 10, FALSE, NULL, 'key')->Column('UpdateUserID', 'int', 10, FALSE, NULL)->Column('Name', 'varchar', 100, TRUE)->Column('Closed', array('1', '0'), '', FALSE, '0')->Column('Announce', array('1', '0'), '', FALSE, '0')->Column('Sink', array('1', '0'), '', FALSE, '0')->Column('Body', 'text')->Column('Format', 'varchar', 20, TRUE)->Column('DateInserted', 'datetime')->Column('DateUpdated', 'datetime', '', TRUE)->Set($Explicit, $Drop); // Insert some activity types /// %1 = ActivityName /// %2 = ActivityName Possessive
public function History($UpdateFields = TRUE, $InsertFields = FALSE) { $UserID = Gdn::Session()->UserID; if ($InsertFields) { $this->Set('DateInserted', Format::ToDateTime())->Set('InsertUserID', $UserID); } if ($UpdateFields) { $this->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $UserID); } return $this; }
public function Delete($ActivityID) { // Get the activity first $Activity = $this->GetID($ActivityID); if (is_object($Activity)) { $Users = array(); $Users[] = $Activity->ActivityUserID; if (is_numeric($Activity->RegardingUserID) && $Activity->RegardingUserID > 0) { $Users[] = $Activity->RegardingUserID; } // Update the user's dateupdated field so that profile pages will not // be cached and will reflect this deletion. $this->SQL->Update('User')->Set('DateUpdated', Format::ToDateTime())->WhereIn('UserID', $Users)->Put(); // Delete comments on the activity item parent::Delete(array('CommentActivityID' => $ActivityID), FALSE, TRUE); // Delete the activity item parent::Delete(array('ActivityID' => $ActivityID)); } }
/** * Adds $this->UpdateUserID and $this->DateUpdated fields to an associative * array of fieldname/values if those fields exist on the table being * updated. * * @param array $Fields The array of fields to add the values to. */ protected function AddUpdateFields(&$Fields) { $this->DefineSchema(); if ($this->Schema->FieldExists($this->Name, $this->DateUpdated)) { $Fields[$this->DateUpdated] = Format::ToDateTime(); } $Session = Gdn::Session(); if ($Session->UserID > 0 && $this->Schema->FieldExists($this->Name, $this->UpdateUserID)) { $Fields[$this->UpdateUserID] = $Session->UserID; } }