当前位置: 首页>>代码示例>>PHP>>正文


PHP Format::ToDateTime方法代码示例

本文整理汇总了PHP中Format::ToDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Format::ToDateTime方法的具体用法?PHP Format::ToDateTime怎么用?PHP Format::ToDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Format的用法示例。


在下文中一共展示了Format::ToDateTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Save

 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;
 }
开发者ID:kidmax,项目名称:Garden,代码行数:32,代码来源:class.conversationmessagemodel.php

示例2: CheckForSpam

 /**
  * 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;
 }
开发者ID:nbudin,项目名称:Garden,代码行数:60,代码来源:class.vanillamodel.php

示例3: SetWatch

 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()));
         }
     }
 }
开发者ID:jhampha,项目名称:Garden,代码行数:18,代码来源:class.commentmodel.php

示例4: Save

 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;
 }
开发者ID:Aetasiric,项目名称:Garden,代码行数:42,代码来源:class.conversationmessagemodel.php

示例5: SettingsController_DashboardData_Handler

 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')))));
 }
开发者ID:Beyzie,项目名称:Garden,代码行数:21,代码来源:hooks.php

示例6: SettingsController_DashboardData_Handler

 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')))));
 }
开发者ID:Aetasiric,项目名称:Garden,代码行数:21,代码来源:hooks.php

示例7: DiscussionController_Score_Create

 /**
  * 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;
 }
开发者ID:kidmax,项目名称:Garden,代码行数:44,代码来源:class.commentscore.plugin.php

示例8: MarkRead

 /**
  * 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();
 }
开发者ID:Beyzie,项目名称:Garden,代码行数:10,代码来源:class.conversationmodel.php

示例9: BookmarkDiscussion

 /**
  * 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;
 }
开发者ID:Valooo,项目名称:Garden,代码行数:16,代码来源:class.discussionmodel.php

示例10: UpdateLastVisit

 /**
  * 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();
 }
开发者ID:robi-bobi,项目名称:Garden,代码行数:28,代码来源:class.usermodel.php

示例11: Index

 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();
 }
开发者ID:jeastwood,项目名称:Garden,代码行数:76,代码来源:settings.php

示例12: Save

 /**
  * 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;
 }
开发者ID:Aetasiric,项目名称:Garden,代码行数:66,代码来源:class.configuration.php

示例13: Start

 /**
  * 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));
     }
 }
开发者ID:robi-bobi,项目名称:Garden,代码行数:41,代码来源:class.session.php

示例14: xIndex

 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();
 }
开发者ID:robi-bobi,项目名称:Garden,代码行数:38,代码来源:settings.php

示例15: Index

 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);
 }
开发者ID:Beyzie,项目名称:Garden,代码行数:81,代码来源:class.searchmodel.php


注:本文中的Format::ToDateTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。