本文整理汇总了PHP中Gdn_Format::toDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Format::toDateTime方法的具体用法?PHP Gdn_Format::toDateTime怎么用?PHP Gdn_Format::toDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Format
的用法示例。
在下文中一共展示了Gdn_Format::toDateTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: informNotifications
/**
* Grabs all new notifications and adds them to the sender's inform queue.
*
* This method gets called by dashboard's hooks file to display new
* notifications on every pageload.
*
* @since 2.0.18
* @access public
*
* @param Gdn_Controller $Sender The object calling this method.
*/
public static function informNotifications($Sender)
{
$Session = Gdn::session();
if (!$Session->isValid()) {
return;
}
$ActivityModel = new ActivityModel();
// Get five pending notifications.
$Where = array('NotifyUserID' => Gdn::session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
// If we're in the middle of a visit only get very recent notifications.
$Where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes'));
$Activities = $ActivityModel->getWhere($Where, 0, 5)->resultArray();
$ActivityIDs = array_column($Activities, 'ActivityID');
$ActivityModel->setNotified($ActivityIDs);
$Sender->EventArguments['Activities'] =& $Activities;
$Sender->fireEvent('InformNotifications');
foreach ($Activities as $Activity) {
if ($Activity['Photo']) {
$UserPhoto = anchor(img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
} else {
$UserPhoto = '';
}
$Excerpt = Gdn_Format::plainText($Activity['Story']);
$ActivityClass = ' Activity-' . $Activity['ActivityType'];
$Sender->informMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
}
}
示例2: resolve
/**
* Resolves a discussion
*
* @param object $discussion
* @param int $resolve
* @return void
*/
public function resolve(&$discussion, $resolve)
{
$resolution = array('Resolved' => $resolve, 'DateResolved' => $resolve ? Gdn_Format::toDateTime() : null, 'ResolvedUserID' => $resolve ? Gdn::session()->UserID : null);
$discussionID = val('DiscussionID', $discussion);
self::discussionModel()->setField($discussionID, $resolution);
svalr('Resolved', $discussion, $resolve);
}
示例3: structure
/**
* Create the target category that is needed for this plugin to work.
*/
public function structure()
{
$category = (array) CategoryModel::instance()->getByCode('welcome');
$cachedCategoryID = val('CategoryID', $category, false);
if (!$cachedCategoryID) {
$categoryModel = CategoryModel::instance();
$categoryModel->save(['ParentCategoryID' => -1, 'Depth' => 1, 'InsertUserID' => 1, 'UpdateUserID' => 1, 'DateInserted' => Gdn_Format::toDateTime(), 'DateUpdated' => Gdn_Format::toDateTime(), 'Name' => 'Welcome', 'UrlCode' => 'welcome', 'Description' => 'Introduce yourself to the community!', 'PermissionCategoryID' => -1]);
}
}
示例4: structure
public function structure()
{
// Get a user for operations.
$UserID = Gdn::sql()->GetWhere('User', array('Name' => 'Akismet', 'Admin' => 2))->Value('UserID');
if (!$UserID) {
$UserID = Gdn::sql()->Insert('User', array('Name' => 'Akismet', 'Password' => RandomString('20'), 'HashMethod' => 'Random', 'Email' => 'akismet@domain.com', 'DateInserted' => Gdn_Format::toDateTime(), 'Admin' => '2'));
}
saveToConfig('Plugins.Akismet.UserID', $UserID);
}
示例5: markRead
public function markRead($CategoryID, $TKey)
{
if (Gdn::session()->validateTransientKey($TKey)) {
$this->CategoryModel->SaveUserTree($CategoryID, array('DateMarkedRead' => Gdn_Format::toDateTime()));
}
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
redirect('/categories');
}
$this->render();
}
示例6: index
/**
* Show the contributor agreement form & workflow for signing.
*/
public function index()
{
if (!Gdn::session()->isValid()) {
$this->View = 'signin';
} else {
if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('Agree', '') == '1') {
Gdn::sql()->update('User')->set('DateContributorAgreement', Gdn_Format::toDateTime(), true, false)->where('UserID', Gdn::session()->UserID)->put();
$this->View = 'done';
}
}
$this->render();
}
示例7: index
/**
*
*
* @param string $ID
* @param string $ServeFile
*/
public function index($ID = '', $ServeFile = '0')
{
$this->addJsFile('jquery.js');
// Define the item being downloaded
if (strtolower($ID) == 'vanilla') {
$ID = 'vanilla-core';
}
$UrlFilename = Gdn::request()->filename();
$PathInfo = pathinfo($UrlFilename);
$Ext = val('extension', $PathInfo);
if ($Ext == 'zip') {
$ServeFile = '1';
$ID = $Ext = val('filename', $PathInfo);
}
// Find the requested addon
$this->Addon = $this->AddonModel->getSlug($ID, true);
$this->setData('Addon', $this->Addon);
if (!is_array($this->Addon) || !val('File', $this->Addon)) {
$this->Addon = array('Name' => 'Not Found', 'Version' => 'undefined', 'File' => '');
} else {
$AddonID = $this->Addon['AddonID'];
if ($ServeFile != '1') {
$this->addJsFile('get.js');
}
if ($ServeFile == '1') {
// Record this download
$this->Database->sql()->insert('Download', array('AddonID' => $AddonID, 'DateInserted' => Gdn_Format::toDateTime(), 'RemoteIp' => @$_SERVER['REMOTE_ADDR']));
$this->AddonModel->setProperty($AddonID, 'CountDownloads', $this->Addon['CountDownloads'] + 1);
if (val('Slug', $this->Addon)) {
$Filename = $this->Addon['Slug'];
} else {
$Filename = "{$this->Addon['Name']}-{$this->Addon['Version']}";
}
$Filename = Gdn_Format::url($Filename) . '.zip';
$File = $this->Addon['File'];
$Url = Gdn_Upload::url($File);
Gdn_FileSystem::serveFile($Url, $Filename);
}
}
$this->addModule('AddonHelpModule');
$this->render();
}
示例8: entryController_registerValidation_handler
/**
* Enforces AgeGate verification at registration submission.
*
* @param EntryController $sender Sending Controller.
* @param array $args Arguments.
*/
public function entryController_registerValidation_handler($sender, $args)
{
$day = (int) $sender->Form->getFormValue('DateOfBirth_Day', 0);
$month = (int) $sender->Form->getFormValue('DateOfBirth_Month', 0);
$year = (int) $sender->Form->getFormValue('DateOfBirth_Year', 0);
if ($day == 0 || $year == 0 || $month == 0) {
$sender->UserModel->Validation->addValidationResult('', "Please select a valid Date of Birth.");
return;
}
$dob = Gdn_Format::toDateTime(mktime(0, 0, 0, $month, $day, $year));
$datetime1 = new DateTime($year . '-' . $month . '-' . $day);
$datetime2 = new DateTime();
$interval = $datetime1->diff($datetime2);
$age = $interval->format('%y');
$minimumAge = C('Plugins.AgeGate.MinimumAge', 0);
$minimumAgeWithConsent = C('Plugins.AgeGate.MinimumAgeWithConsent', false);
$addConfirmation = C('Plugins.AgeGate.AddConfirmation', false);
if ($minimumAgeWithConsent) {
if ($addConfirmation && $age < $minimumAgeWithConsent && $age >= $minimumAge) {
$sender->UserModel->Validation->applyRule('AgeGateConfirmation', 'Required', 'You must confirm you have received consent to register.');
return;
}
if ($age < $minimumAge) {
$sender->UserModel->Validation->addValidationResult('', sprintf("You must be at least %d years old to register.", $minimumAge));
return;
}
} elseif ($age < $minimumAge) {
if ($addConfirmation) {
$sender->UserModel->Validation->applyRule('AgeGateConfirmation', 'Required', 'You must confirm you have received consent to register.');
} else {
$sender->UserModel->Validation->addValidationResult('', sprintf("You must be at least %d years old to register.", $minimumAge));
}
return;
}
// Set the value on the form so that it will be saved to user model
if ($sender->Form->errorCount() == 0 && !$sender->UserModel->Validation->results()) {
$sender->Form->_FormValues['DateOfBirth'] = $dob;
}
}
示例9: getFileHeader
protected function getFileHeader()
{
$Now = Gdn_Format::toDateTime();
$Result = "<?php if (!defined('APPLICATION')) exit();\n/** This file was generated by the LocaleModel on {$Now} **/\n\n";
return $Result;
}
示例10: save
/**
* Save message from form submission.
*
* @since 2.0.0
* @access public
*
* @param array $FormPostValues Values submitted via form.
* @return int Unique ID of message created or updated.
*/
public function save($FormPostValues, $Conversation = null, $Options = array())
{
$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);
$this->EventArguments['FormPostValues'] = $FormPostValues;
$this->fireEvent('BeforeSaveValidation');
// Determine if spam check should be skipped.
$SkipSpamCheck = !empty($Options['NewConversation']);
// Validate the form posted values
$MessageID = false;
if ($this->validate($FormPostValues) && !$this->checkForSpam('ConversationMessage', $SkipSpamCheck)) {
$Fields = $this->Validation->schemaValidationFields();
// All fields on the form that relate to the schema
touchValue('Format', $Fields, c('Garden.InputFormatter', 'Html'));
$this->EventArguments['Fields'] = $Fields;
$this->fireEvent('BeforeSave');
$MessageID = $this->SQL->insert($this->Name, $Fields);
$this->LastMessageID = $MessageID;
$ConversationID = val('ConversationID', $Fields, 0);
if (!$Conversation) {
$Conversation = $this->SQL->getWhere('Conversation', array('ConversationID' => $ConversationID))->firstRow(DATASET_TYPE_ARRAY);
}
$Message = $this->getID($MessageID);
$this->EventArguments['Conversation'] = $Conversation;
$this->EventArguments['Message'] = $Message;
$this->fireEvent('AfterSave');
// Get the new message count for the conversation.
$SQLR = $this->SQL->select('MessageID', 'count', 'CountMessages')->select('MessageID', 'max', 'LastMessageID')->from('ConversationMessage')->where('ConversationID', $ConversationID)->get()->firstRow(DATASET_TYPE_ARRAY);
if (sizeof($SQLR)) {
list($CountMessages, $LastMessageID) = array_values($SQLR);
} else {
return;
}
// Update the conversation's DateUpdated field.
$DateUpdated = Gdn_Format::toDateTime();
$this->SQL->update('Conversation c')->set('CountMessages', $CountMessages)->set('LastMessageID', $LastMessageID)->set('UpdateUserID', Gdn::session()->UserID)->set('DateUpdated', $DateUpdated)->where('ConversationID', $ConversationID)->put();
// Update the last message of the users that were previously up-to-date on their read messages.
$this->SQL->update('UserConversation uc')->set('uc.LastMessageID', $MessageID)->set('uc.DateConversationUpdated', $DateUpdated)->where('uc.ConversationID', $ConversationID)->where('uc.Deleted', '0')->where('uc.CountReadMessages', $CountMessages - 1)->where('uc.UserID <>', $Session->UserID)->put();
// Update the date updated of the users that were not up-to-date.
$this->SQL->update('UserConversation uc')->set('uc.DateConversationUpdated', $DateUpdated)->where('uc.ConversationID', $ConversationID)->where('uc.Deleted', '0')->where('uc.CountReadMessages <>', $CountMessages - 1)->where('uc.UserID <>', $Session->UserID)->put();
// Update the sending user.
$this->SQL->update('UserConversation uc')->set('uc.CountReadMessages', $CountMessages)->set('Deleted', 0)->set('uc.DateConversationUpdated', $DateUpdated)->where('ConversationID', $ConversationID)->where('UserID', $Session->UserID)->put();
// Find users involved in this conversation
$UserData = $this->SQL->select('UserID')->select('LastMessageID')->select('Deleted')->from('UserConversation')->where('ConversationID', $ConversationID)->get()->result(DATASET_TYPE_ARRAY);
$UpdateCountUserIDs = array();
$NotifyUserIDs = array();
// Collapse for call to UpdateUserCache and ActivityModel.
$InsertUserFound = false;
foreach ($UserData as $UpdateUser) {
$LastMessageID = val('LastMessageID', $UpdateUser);
$UserID = val('UserID', $UpdateUser);
$Deleted = val('Deleted', $UpdateUser);
if ($UserID == val('InsertUserID', $Fields)) {
$InsertUserFound = true;
if ($Deleted) {
$this->SQL->put('UserConversation', array('Deleted' => 0, 'DateConversationUpdated' => $DateUpdated), array('ConversationID' => $ConversationID, 'UserID' => $UserID));
}
}
// Update unread for users that were up to date
if ($LastMessageID == $MessageID) {
$UpdateCountUserIDs[] = $UserID;
}
// Send activities to users that have not deleted the conversation
if (!$Deleted) {
$NotifyUserIDs[] = $UserID;
}
}
if (!$InsertUserFound) {
$UserConversation = array('UserID' => val('InsertUserID', $Fields), 'ConversationID' => $ConversationID, 'LastMessageID' => $LastMessageID, 'CountReadMessages' => $CountMessages, 'DateConversationUpdated' => $DateUpdated);
$this->SQL->insert('UserConversation', $UserConversation);
}
if (sizeof($UpdateCountUserIDs)) {
$ConversationModel = new ConversationModel();
$ConversationModel->updateUserUnreadCount($UpdateCountUserIDs, true);
}
$this->fireEvent('AfterAdd');
$activityModel = new ActivityModel();
foreach ($NotifyUserIDs as $notifyUserID) {
if ($Session->UserID == $notifyUserID) {
continue;
// don't notify self.
}
// Notify the users of the new message.
$activity = array('ActivityType' => 'ConversationMessage', 'ActivityUserID' => val('InsertUserID', $Fields), 'NotifyUserID' => $notifyUserID, 'HeadlineFormat' => t('HeadlineFormat.ConversationMessage', '{ActivityUserID,user} sent you a <a href="{Url,html}">message</a>'), 'RecordType' => 'Conversation', 'RecordID' => $ConversationID, 'Story' => val('Body', $Fields, ''), 'Format' => val('Format', $Fields, c('Garden.InputFormatter')), 'Route' => "/messages/{$ConversationID}#{$MessageID}");
if (c('Conversations.Subjects.Visible') && val('Subject', $Conversation, '')) {
$activity['HeadlineFormat'] = val('Subject', $Conversation, '');
}
//.........这里部分代码省略.........
示例11: saveDiscussion
/**
*
*
* @param $discussion_id
* @param $tags
* @param array $types
* @param int $category_id
* @param string $new_type
* @throws Exception
*/
public function saveDiscussion($discussion_id, $tags, $types = array(''), $category_id = 0, $new_type = '')
{
// First grab all of the current tags.
$all_tags = $current_tags = $this->getDiscussionTags($discussion_id, TagModel::IX_TAGID);
// Put all the default tag types in the types if necessary.
if (in_array('', $types)) {
$types = array_merge($types, array_keys($this->defaultTypes()));
$types = array_unique($types);
}
// Remove the types from the current tags that we don't need anymore.
$current_tags = array_filter($current_tags, function ($row) use($types) {
if (in_array($row['Type'], $types)) {
return true;
}
return false;
});
// Turn the tags into a nice array.
if (is_string($tags)) {
$tags = TagModel::SplitTags($tags);
}
$new_tags = array();
$tag_ids = array();
// See which tags are new and which ones aren't.
foreach ($tags as $tag_id) {
if (is_id($tag_id)) {
$tag_ids[$tag_id] = true;
} else {
$new_tags[TagModel::tagSlug($tag_id)] = $tag_id;
}
}
// See if any of the new tags actually exist by searching by name.
if (!empty($new_tags)) {
$found_tags = $this->getWhere(array('Name' => array_keys($new_tags)))->resultArray();
foreach ($found_tags as $found_tag_row) {
$tag_ids[$found_tag_row['TagID']] = $found_tag_row;
unset($new_tags[TagModel::TagSlug($found_tag_row['Name'])]);
}
}
// Add any remaining tags that need to be added.
if (Gdn::session()->checkPermission('Plugins.Tagging.Add')) {
foreach ($new_tags as $name => $full_name) {
$new_tag = array('Name' => trim(str_replace(' ', '-', strtolower($name)), '-'), 'FullName' => $full_name, 'Type' => $new_type, 'CategoryID' => $category_id, 'InsertUserID' => Gdn::session()->UserID, 'DateInserted' => Gdn_Format::toDateTime(), 'CountDiscussions' => 0);
$tag_id = $this->SQL->options('Ignore', true)->insert('Tag', $new_tag);
$tag_ids[$tag_id] = true;
}
}
// Grab the tags so we can see more information about them.
$save_tags = $this->getWhere(array('TagID' => array_keys($tag_ids)))->resultArray();
// Add any parent tags that may need to be added.
foreach ($save_tags as $save_tag) {
$parent_tag_id = val('ParentTagID', $save_tag);
if ($parent_tag_id) {
$tag_ids[$parent_tag_id] = true;
}
$all_tags[$save_tag['TagID']] = $save_tag;
}
// Remove tags that are already associated with the discussion.
// $same_tag_ids = array_intersect_key($tag_ids, $current_tags);
// $current_tags = array_diff_key($current_tags, $same_tag_ids);
// $tag_ids = array_diff_key($tag_ids, $same_tag_ids);
// Figure out the tags we need to add.
$insert_tag_ids = array_diff_key($tag_ids, $current_tags);
// Figure out the tags we need to remove.
$delete_tag_ids = array_diff_key($current_tags, $tag_ids);
$now = Gdn_Format::toDateTime();
// Insert the new tag mappings.
foreach ($insert_tag_ids as $tag_id => $bool) {
if (isset($all_tags[$tag_id])) {
$insert_category_id = $all_tags[$tag_id]['CategoryID'];
} else {
$insert_category_id = $category_id;
}
$this->SQL->options('Ignore', true)->insert('TagDiscussion', array('DiscussionID' => $discussion_id, 'TagID' => $tag_id, 'DateInserted' => $now, 'CategoryID' => $insert_category_id));
}
// Delete the old tag mappings.
if (!empty($delete_tag_ids)) {
$this->SQL->delete('TagDiscussion', array('DiscussionID' => $discussion_id, 'TagID' => array_keys($delete_tag_ids)));
}
// Increment the tag counts.
if (!empty($insert_tag_ids)) {
$this->SQL->update('Tag')->set('CountDiscussions', 'CountDiscussions + 1', false)->whereIn('TagID', array_keys($insert_tag_ids))->put();
}
// Decrement the tag counts.
if (!empty($delete_tag_ids)) {
$this->SQL->update('Tag')->set('CountDiscussions', 'CountDiscussions - 1', false)->whereIn('TagID', array_keys($delete_tag_ids))->put();
}
}
示例12: save
/**
*
*
* @param array $FormPostValues
* @param array|bool $UserModel
* @param array $Options
* @return bool
* @throws Exception
*/
public function save($FormPostValues, $UserModel, $Options = array())
{
$Session = Gdn::session();
$UserID = $Session->UserID;
$SendEmail = val('SendEmail', $Options, true);
$Resend = val('Resend', $Options, false);
// Define the primary key in this model's table.
$this->defineSchema();
// Add & apply any extra validation rules:
$this->Validation->applyRule('Email', 'Email');
// Make sure required db fields are present.
$this->AddInsertFields($FormPostValues);
if (!isset($FormPostValues['DateExpires'])) {
$Expires = strtotime(c('Garden.Registration.InviteExpiration'));
if ($Expires > time()) {
$FormPostValues['DateExpires'] = Gdn_Format::toDateTime($Expires);
}
}
$FormPostValues['Code'] = $this->GetInvitationCode();
// Validate the form posted values
if ($this->validate($FormPostValues, true) === true) {
$Fields = $this->Validation->ValidationFields();
// All fields on the form that need to be validated
$Email = arrayValue('Email', $Fields, '');
// Make sure this user has a spare invitation to send.
$InviteCount = $UserModel->GetInvitationCount($UserID);
if ($InviteCount == 0) {
$this->Validation->addValidationResult('Email', 'You do not have enough invitations left.');
return false;
}
// Make sure that the email does not already belong to an account in the application.
$TestData = $UserModel->getWhere(array('Email' => $Email));
if ($TestData->numRows() > 0) {
$this->Validation->addValidationResult('Email', 'The email you have entered is already related to an existing account.');
return false;
}
// Make sure that the email does not already belong to an invitation in the application.
$TestData = $this->getWhere(array('Email' => $Email));
$DeleteID = false;
if ($TestData->numRows() > 0) {
if (!$Resend) {
$this->Validation->addValidationResult('Email', 'An invitation has already been sent to the email you entered.');
return false;
} else {
// Mark the old invitation for deletion.
$DeleteID = val('InvitationID', $TestData->firstRow(DATASET_TYPE_ARRAY));
}
}
// Define the fields to be inserted
$Fields = $this->Validation->SchemaValidationFields();
// Call the base model for saving
$InvitationID = $this->insert($Fields);
// Delete an old invitation.
if ($InvitationID && $DeleteID) {
$this->delete($DeleteID);
}
// Now that saving has succeeded, update the user's invitation settings
if ($InviteCount > 0) {
$UserModel->ReduceInviteCount($UserID);
}
// And send the invitation email
if ($SendEmail) {
try {
$this->send($InvitationID);
} catch (Exception $ex) {
$this->Validation->addValidationResult('Email', sprintf(t('Although the invitation was created successfully, the email failed to send. The server reported the following error: %s'), strip_tags($ex->getMessage())));
return false;
}
}
return true;
}
return false;
}
示例13: deleteID
/**
* Delete a single user.
*
* @param int $userID The user to delete.
* @param array $options See {@link UserModel::deleteContent()}, and {@link UserModel::getDelete()}.
*/
public function deleteID($userID, $options = [])
{
if ($userID == $this->getSystemUserID()) {
$this->Validation->addValidationResult('', 'You cannot delete the system user.');
return false;
}
$Content = [];
// Remove shared authentications.
$this->getDelete('UserAuthentication', ['UserID' => $userID], $Content);
// Remove role associations.
$this->getDelete('UserRole', ['UserID' => $userID], $Content);
$this->deleteContent($userID, $options, $Content);
// Remove the user's information
$this->SQL->update('User')->set(['Name' => t('[Deleted User]'), 'Photo' => null, 'Password' => randomString('10'), 'About' => '', 'Email' => 'user_' . $userID . '@deleted.email', 'ShowEmail' => '0', 'Gender' => 'u', 'CountVisits' => 0, 'CountInvitations' => 0, 'CountNotifications' => 0, 'InviteUserID' => null, 'DiscoveryText' => '', 'Preferences' => null, 'Permissions' => null, 'Attributes' => dbencode(['State' => 'Deleted']), 'DateSetInvitations' => null, 'DateOfBirth' => null, 'DateUpdated' => Gdn_Format::toDateTime(), 'HourOffset' => '0', 'Score' => null, 'Admin' => 0, 'Deleted' => 1])->where('UserID', $userID)->put();
// Remove user's cache rows
$this->clearCache($userID);
return true;
}
示例14: comment
/**
* Create or update a comment.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique ID to add the comment to. If blank, this method will throw an error.
*/
public function comment($DiscussionID = '')
{
// Get $DiscussionID from RequestArgs if valid
if ($DiscussionID == '' && count($this->RequestArgs)) {
if (is_numeric($this->RequestArgs[0])) {
$DiscussionID = $this->RequestArgs[0];
}
}
// If invalid $DiscussionID, get from form.
$this->Form->setModel($this->CommentModel);
$DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->getFormValue('DiscussionID', 0);
// Set discussion data
$this->DiscussionID = $DiscussionID;
$this->Discussion = $Discussion = $this->DiscussionModel->getID($DiscussionID);
// Is this an embedded comment being posted to a discussion that doesn't exist yet?
$vanilla_type = $this->Form->getFormValue('vanilla_type', '');
$vanilla_url = $this->Form->getFormValue('vanilla_url', '');
$vanilla_category_id = $this->Form->getFormValue('vanilla_category_id', '');
$Attributes = array('ForeignUrl' => $vanilla_url);
$vanilla_identifier = $this->Form->getFormValue('vanilla_identifier', '');
$isEmbeddedComments = $vanilla_url != '' && $vanilla_identifier != '';
// Only allow vanilla identifiers of 32 chars or less - md5 if larger
if (strlen($vanilla_identifier) > 32) {
$Attributes['vanilla_identifier'] = $vanilla_identifier;
$vanilla_identifier = md5($vanilla_identifier);
}
if (!$Discussion && $isEmbeddedComments) {
$Discussion = $Discussion = $this->DiscussionModel->getForeignID($vanilla_identifier, $vanilla_type);
if ($Discussion) {
$this->DiscussionID = $DiscussionID = $Discussion->DiscussionID;
$this->Form->setValue('DiscussionID', $DiscussionID);
}
}
// If so, create it!
if (!$Discussion && $isEmbeddedComments) {
// Add these values back to the form if they exist!
$this->Form->addHidden('vanilla_identifier', $vanilla_identifier);
$this->Form->addHidden('vanilla_type', $vanilla_type);
$this->Form->addHidden('vanilla_url', $vanilla_url);
$this->Form->addHidden('vanilla_category_id', $vanilla_category_id);
$PageInfo = fetchPageInfo($vanilla_url);
if (!($Title = $this->Form->getFormValue('Name'))) {
$Title = val('Title', $PageInfo, '');
if ($Title == '') {
$Title = t('Undefined discussion subject.');
if (!empty($PageInfo['Exception']) && $PageInfo['Exception'] === "Couldn't connect to host.") {
$Title .= ' ' . t('Page timed out.');
}
}
}
$Description = val('Description', $PageInfo, '');
$Images = val('Images', $PageInfo, array());
$LinkText = t('EmbededDiscussionLinkText', 'Read the full story here');
if (!$Description && count($Images) == 0) {
$Body = formatString('<p><a href="{Url}">{LinkText}</a></p>', array('Url' => $vanilla_url, 'LinkText' => $LinkText));
} else {
$Body = formatString('
<div class="EmbeddedContent">{Image}<strong>{Title}</strong>
<p>{Excerpt}</p>
<p><a href="{Url}">{LinkText}</a></p>
<div class="ClearFix"></div>
</div>', array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? img(val(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $vanilla_url, 'LinkText' => $LinkText));
}
if ($Body == '') {
$Body = $vanilla_url;
}
if ($Body == '') {
$Body = t('Undefined discussion body.');
}
// Validate the CategoryID for inserting.
$Category = CategoryModel::categories($vanilla_category_id);
if (!$Category) {
$vanilla_category_id = c('Vanilla.Embed.DefaultCategoryID', 0);
if ($vanilla_category_id <= 0) {
// No default category defined, so grab the first non-root category and use that.
$vanilla_category_id = $this->DiscussionModel->SQL->select('CategoryID')->from('Category')->where('CategoryID >', 0)->get()->firstRow()->CategoryID;
// No categories in the db? default to 0
if (!$vanilla_category_id) {
$vanilla_category_id = 0;
}
}
} else {
$vanilla_category_id = $Category['CategoryID'];
}
$EmbedUserID = c('Garden.Embed.UserID');
if ($EmbedUserID) {
$EmbedUser = Gdn::userModel()->getID($EmbedUserID);
}
if (!$EmbedUserID || !$EmbedUser) {
$EmbedUserID = Gdn::userModel()->getSystemUserID();
}
$EmbeddedDiscussionData = array('InsertUserID' => $EmbedUserID, 'DateInserted' => Gdn_Format::toDateTime(), 'DateUpdated' => Gdn_Format::toDateTime(), 'CategoryID' => $vanilla_category_id, 'ForeignID' => $vanilla_identifier, 'Type' => $vanilla_type, 'Name' => $Title, 'Body' => $Body, 'Format' => 'Html', 'Attributes' => dbencode($Attributes));
//.........这里部分代码省略.........
示例15: markRead
/**
* Update a conversation as read for a specific user id.
*
* @since 2.0.0
* @access public
*
* @param int $ConversationID Unique ID of conversation effected.
* @param int $ReadingUserID Unique ID of current user.
*/
public function markRead($ConversationID, $ReadingUserID)
{
// Update the the read conversation count for the user.
$this->SQL->update('UserConversation uc')->join('Conversation c', 'c.ConversationID = uc.ConversationID')->set('uc.CountReadMessages', 'c.CountMessages', false)->set('uc.DateLastViewed', Gdn_Format::toDateTime())->set('uc.LastMessageID', 'c.LastMessageID', false)->where('c.ConversationID', $ConversationID)->where('uc.ConversationID', $ConversationID)->where('uc.UserID', $ReadingUserID)->put();
// Also update the unread conversation count for this user
$CountUnread = $this->countUnread($ReadingUserID);
// Also write through to the current session user.
if ($ReadingUserID > 0 && $ReadingUserID == Gdn::session()->UserID) {
Gdn::session()->User->CountUnreadConversations = $CountUnread;
}
}