本文整理汇总了PHP中Gdn::userModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn::userModel方法的具体用法?PHP Gdn::userModel怎么用?PHP Gdn::userModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn
的用法示例。
在下文中一共展示了Gdn::userModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pluginController_quoteMention_create
public function pluginController_quoteMention_create($sender, $discussionID, $commentID, $username)
{
$sender->deliveryMethod(DELIVERY_METHOD_JSON);
$user = Gdn::userModel()->getByUsername($username);
$discussionModel = new DiscussionModel();
$discussion = $discussionModel->getID($discussionID);
if (!$user || !$discussion) {
throw notFoundException();
}
// Make sure this endpoint can't be used to snoop around.
$sender->permission('Vanilla.Discussions.View', true, 'Category', $discussion->PermissionCategoryID);
// Find the previous comment of the mentioned user in this discussion.
$item = Gdn::sql()->getWhere('Comment', ['DiscussionID' => $discussion->DiscussionID, 'InsertUserID' => $user->UserID, 'CommentID <' => $commentID], 'CommentID', 'desc', 1)->firstRow();
// The items ID in the DOM used for highlighting.
if ($item) {
$target = '#Comment_' . $item->CommentID;
// The mentioned user might be the discussion creator.
} elseif ($discussion->InsertUserID == $user->UserID) {
$item = $discussion;
$target = '#Discussion_' . $item->DiscussionID;
}
if (!$item) {
// A success response code always means that a comment was found.
$sender->statusCode(404);
}
$sender->renderData($item ? ['html' => nl2br(sliceString(Gdn_Format::plainText($item->Body, $item->Format), c('QuoteMention.MaxLength', 400))), 'target' => $target] : []);
}
示例2: afterImport
/**
* Custom finalization.
*
* @throws Exception
*/
public function afterImport()
{
// Set up the routes to redirect from their older counterparts.
$Router = Gdn::router();
// Categories
$Router->SetRoute('forumdisplay\\.php\\?f=(\\d+)', 'categories/$1', 'Permanent');
$Router->SetRoute('archive\\.php/f-(\\d+)\\.html', 'categories/$1', 'Permanent');
// Discussions & Comments
$Router->SetRoute('showthread\\.php\\?t=(\\d+)', 'discussion/$1', 'Permanent');
//$Router->SetRoute('showthread\.php\?p=(\d+)', 'discussion/comment/$1#Comment_$1', 'Permanent');
//$Router->SetRoute('showpost\.php\?p=(\d+)', 'discussion/comment/$1#Comment_$1', 'Permanent');
$Router->SetRoute('archive\\.php/t-(\\d+)\\.html', 'discussion/$1', 'Permanent');
// Profiles
$Router->SetRoute('member\\.php\\?u=(\\d+)', 'profile/$1/x', 'Permanent');
$Router->SetRoute('usercp\\.php', 'profile', 'Permanent');
$Router->SetRoute('profile\\.php', 'profile', 'Permanent');
// Other
$Router->SetRoute('attachment\\.php\\?attachmentid=(\\d+)', 'discussion/download/$1', 'Permanent');
$Router->SetRoute('search\\.php', 'discussions', 'Permanent');
$Router->SetRoute('private\\.php', 'messages/all', 'Permanent');
$Router->SetRoute('subscription\\.php', 'discussions/bookmarked', 'Permanent');
// Make different sizes of avatars
$this->ProcessAvatars();
// Prep config for ProfileExtender plugin based on imported fields
$this->ProfileExtenderPrep();
// Set guests to System user to prevent security issues
$SystemUserID = Gdn::userModel()->GetSystemUserID();
$this->SQL->update('Discussion')->set('InsertUserID', $SystemUserID)->where('InsertUserID', 0)->put();
$this->SQL->update('Comment')->set('InsertUserID', $SystemUserID)->where('InsertUserID', 0)->put();
}
示例3: adminUser
/**
* Create the default admin user.
*
* @return void
*/
protected function adminUser()
{
$UserModel = Gdn::userModel();
$UserModel->defineSchema();
$user = ['Name' => getenv('VANILLA_ADMIN_NAME'), 'Email' => getenv('VANILLA_ADMIN_EMAIL'), 'Password' => getenv('VANILLA_ADMIN_PASSWORD')];
$AdminUserID = $UserModel->SaveAdminUser($user);
}
示例4: loadData
public function loadData()
{
$UserID = Gdn::controller()->data('Profile.UserID', Gdn::session()->UserID);
$this->User = Gdn::userModel()->getID($UserID);
$this->Roles = Gdn::userModel()->GetRoles($UserID)->resultArray();
// Hide personal info roles
if (!checkPermission('Garden.PersonalInfo.View')) {
$this->Roles = array_filter($this->Roles, 'RoleModel::FilterPersonalInfo');
}
}
示例5: isSpam
/**
* Check whether or not the record is spam.
* @param string $RecordType By default, this should be one of the following:
* - Comment: A comment.
* - Discussion: A discussion.
* - User: A user registration.
* @param array $Data The record data.
* @param array $Options Options for fine-tuning this method call.
* - Log: Log the record if it is found to be spam.
*/
public static function isSpam($RecordType, $Data, $Options = array())
{
if (self::$Disabled) {
return false;
}
// Set some information about the user in the data.
if ($RecordType == 'Registration') {
touchValue('Username', $Data, $Data['Name']);
} else {
touchValue('InsertUserID', $Data, Gdn::session()->UserID);
$User = Gdn::userModel()->getID(val('InsertUserID', $Data), DATASET_TYPE_ARRAY);
if ($User) {
if (val('Verified', $User)) {
// The user has been verified and isn't a spammer.
return false;
}
touchValue('Username', $Data, $User['Name']);
touchValue('Email', $Data, $User['Email']);
touchValue('IPAddress', $Data, $User['LastIPAddress']);
}
}
if (!isset($Data['Body']) && isset($Data['Story'])) {
$Data['Body'] = $Data['Story'];
}
touchValue('IPAddress', $Data, Gdn::request()->ipAddress());
$Sp = self::_Instance();
$Sp->EventArguments['RecordType'] = $RecordType;
$Sp->EventArguments['Data'] =& $Data;
$Sp->EventArguments['Options'] =& $Options;
$Sp->EventArguments['IsSpam'] = false;
$Sp->fireEvent('CheckSpam');
$Spam = $Sp->EventArguments['IsSpam'];
// Log the spam entry.
if ($Spam && val('Log', $Options, true)) {
$LogOptions = array();
switch ($RecordType) {
case 'Registration':
$LogOptions['GroupBy'] = array('RecordIPAddress');
break;
case 'Comment':
case 'Discussion':
case 'Activity':
case 'ActivityComment':
$LogOptions['GroupBy'] = array('RecordID');
break;
}
LogModel::insert('Spam', $RecordType, $Data, $LogOptions);
}
return $Spam;
}
示例6: discussionModel_afterSaveDiscussion_handler
/**
* Post every new discussion to HipChat.
*
* @param PostController $sender
* @param array $args
*/
public function discussionModel_afterSaveDiscussion_handler($sender, $args)
{
// Make sure we have a valid discussion.
if (!$args['Discussion'] || !val('DiscussionID', $args['Discussion'])) {
return;
}
// Only trigger for new discussions.
if (!$args['Insert']) {
return;
}
// Prep HipChat message.
$author = Gdn::userModel()->getID(val('InsertUserID', $args['Discussion']));
$message = sprintf('%1$s: %2$s', userAnchor($author), anchor(val('Name', $args['Discussion']), discussionUrl($args['Discussion'])));
// Say it.
self::sayInHipChat($message);
}
示例7: deleteUserData
/**
* Delete all of the Vanilla related information for a specific user.
*
* @since 2.1
*
* @param int $userID The ID of the user to delete.
* @param array $options An array of options:
* - DeleteMethod: One of delete, wipe, or NULL
*/
public function deleteUserData($userID, $options = array(), &$data = null)
{
$sql = Gdn::sql();
// Remove discussion watch records and drafts.
$sql->delete('UserDiscussion', array('UserID' => $userID));
Gdn::userModel()->getDelete('Draft', array('InsertUserID' => $userID), $data);
// Comment deletion depends on method selected
$deleteMethod = val('DeleteMethod', $options, 'delete');
if ($deleteMethod == 'delete') {
// Get a list of category IDs that has this user as the most recent poster.
$discussionCats = $sql->select('cat.CategoryID')->from('Category cat')->join('Discussion d', 'd.DiscussionID = cat.LastDiscussionID')->where('d.InsertUserID', $userID)->get()->resultArray();
$commentCats = $sql->select('cat.CategoryID')->from('Category cat')->join('Comment c', 'c.CommentID = cat.LastCommentID')->where('c.InsertUserID', $userID)->get()->resultArray();
$categoryIDs = array_unique(array_merge(array_column($discussionCats, 'CategoryID'), array_column($commentCats, 'CategoryID')));
// Grab all of the discussions that the user has engaged in.
$discussionIDs = $sql->select('DiscussionID')->from('Comment')->where('InsertUserID', $userID)->groupBy('DiscussionID')->get()->resultArray();
$discussionIDs = array_column($discussionIDs, 'DiscussionID');
Gdn::userModel()->getDelete('Comment', array('InsertUserID' => $userID), $data);
// Update the comment counts.
$commentCounts = $sql->select('DiscussionID')->select('CommentID', 'count', 'CountComments')->select('CommentID', 'max', 'LastCommentID')->whereIn('DiscussionID', $discussionIDs)->groupBy('DiscussionID')->get('Comment')->resultArray();
foreach ($commentCounts as $row) {
$sql->put('Discussion', array('CountComments' => $row['CountComments'] + 1, 'LastCommentID' => $row['LastCommentID']), array('DiscussionID' => $row['DiscussionID']));
}
// Update the last user IDs.
$sql->update('Discussion d')->join('Comment c', 'd.LastCommentID = c.CommentID', 'left')->set('d.LastCommentUserID', 'c.InsertUserID', false, false)->set('d.DateLastComment', 'coalesce(c.DateInserted, d.DateInserted)', false, false)->whereIn('d.DiscussionID', $discussionIDs)->put();
// Update the last posts.
$discussions = $sql->whereIn('DiscussionID', $discussionIDs)->where('LastCommentUserID', $userID)->get('Discussion');
// Delete the user's discussions.
Gdn::userModel()->getDelete('Discussion', array('InsertUserID' => $userID), $data);
// Update the appropriate recent posts in the categories.
$categoryModel = new CategoryModel();
foreach ($categoryIDs as $categoryID) {
$categoryModel->setRecentPost($categoryID);
}
} elseif ($deleteMethod == 'wipe') {
// Erase the user's discussions.
$sql->update('Discussion')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $userID)->put();
$sql->update('Comment')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $userID)->put();
} else {
// Leave comments
}
// Remove the user's profile information related to this application
$sql->update('User')->set(array('CountDiscussions' => 0, 'CountUnreadDiscussions' => 0, 'CountComments' => 0, 'CountDrafts' => 0, 'CountBookmarks' => 0))->where('UserID', $userID)->put();
}
示例8: deleteUserData
/**
* Delete all of the Vanilla related information for a specific user.
*
* @since 2.1
*
* @param int $UserID The ID of the user to delete.
* @param array $Options An array of options:
* - DeleteMethod: One of delete, wipe, or NULL
*/
public function deleteUserData($UserID, $Options = array(), &$Data = null)
{
$SQL = Gdn::sql();
// Remove discussion watch records and drafts.
$SQL->delete('UserDiscussion', array('UserID' => $UserID));
Gdn::userModel()->GetDelete('Draft', array('InsertUserID' => $UserID), $Data);
// Comment deletion depends on method selected
$DeleteMethod = val('DeleteMethod', $Options, 'delete');
if ($DeleteMethod == 'delete') {
// Clear out the last posts to the categories.
$SQL->update('Category c')->join('Discussion d', 'd.DiscussionID = c.LastDiscussionID')->where('d.InsertUserID', $UserID)->set('c.LastDiscussionID', null)->set('c.LastCommentID', null)->put();
$SQL->update('Category c')->join('Comment d', 'd.CommentID = c.LastCommentID')->where('d.InsertUserID', $UserID)->set('c.LastDiscussionID', null)->set('c.LastCommentID', null)->put();
// Grab all of the discussions that the user has engaged in.
$DiscussionIDs = $SQL->select('DiscussionID')->from('Comment')->where('InsertUserID', $UserID)->groupBy('DiscussionID')->get()->resultArray();
$DiscussionIDs = consolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID');
Gdn::userModel()->GetDelete('Comment', array('InsertUserID' => $UserID), $Data);
// Update the comment counts.
$CommentCounts = $SQL->select('DiscussionID')->select('CommentID', 'count', 'CountComments')->select('CommentID', 'max', 'LastCommentID')->whereIn('DiscussionID', $DiscussionIDs)->groupBy('DiscussionID')->get('Comment')->resultArray();
foreach ($CommentCounts as $Row) {
$SQL->put('Discussion', array('CountComments' => $Row['CountComments'] + 1, 'LastCommentID' => $Row['LastCommentID']), array('DiscussionID' => $Row['DiscussionID']));
}
// Update the last user IDs.
$SQL->update('Discussion d')->join('Comment c', 'd.LastCommentID = c.CommentID', 'left')->set('d.LastCommentUserID', 'c.InsertUserID', false, false)->set('d.DateLastComment', 'c.DateInserted', false, false)->whereIn('d.DiscussionID', $DiscussionIDs)->put();
// Update the last posts.
$Discussions = $SQL->whereIn('DiscussionID', $DiscussionIDs)->where('LastCommentUserID', $UserID)->get('Discussion');
// Delete the user's dicussions
Gdn::userModel()->GetDelete('Discussion', array('InsertUserID' => $UserID), $Data);
// Update the appropriat recent posts in the categories.
$CategoryModel = new CategoryModel();
$Categories = $CategoryModel->getWhere(array('LastDiscussionID' => null))->resultArray();
foreach ($Categories as $Category) {
$CategoryModel->SetRecentPost($Category['CategoryID']);
}
} elseif ($DeleteMethod == 'wipe') {
// Erase the user's dicussions
$SQL->update('Discussion')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $UserID)->put();
$SQL->update('Comment')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $UserID)->put();
} else {
// Leave comments
}
// Remove the user's profile information related to this application
$SQL->update('User')->set(array('CountDiscussions' => 0, 'CountUnreadDiscussions' => 0, 'CountComments' => 0, 'CountDrafts' => 0, 'CountBookmarks' => 0))->where('UserID', $UserID)->put();
}
示例9: drawEdited
/**
* Output 'edited' notice.
*
* @param $Sender
*/
protected function drawEdited($Sender)
{
$Record = $Sender->data('Discussion');
if (!$Record) {
$Record = $Sender->data('Record');
}
if (!$Record) {
return;
}
$PermissionCategoryID = val('PermissionCategoryID', $Record);
$Data = $Record;
$RecordType = 'discussion';
$RecordID = val('DiscussionID', $Data);
// But override if comment
if (isset($Sender->EventArguments['Comment']) || val('RecordType', $Record) == 'comment') {
$Data = $Sender->EventArguments['Comment'];
$RecordType = 'comment';
$RecordID = val('CommentID', $Data);
}
$UserCanEdit = Gdn::session()->checkPermission('Vanilla.' . ucfirst($RecordType) . 's.Edit', true, 'Category', $PermissionCategoryID);
if (is_null($Data->DateUpdated)) {
return;
}
// Do not show log link if no log would have been generated.
$elapsed = Gdn_Format::toTimestamp(val('DateUpdated', $Data)) - Gdn_Format::toTimestamp(val('DateInserted', $Data));
$grace = c('Garden.Log.FloodControl', 20) * 60;
if ($elapsed < $grace) {
return;
}
$UpdatedUserID = $Data->UpdateUserID;
$UserData = Gdn::userModel()->getID($UpdatedUserID);
$Edited = array('EditUser' => val('Name', $UserData, t('Unknown User')), 'EditDate' => Gdn_Format::date($Data->DateUpdated, 'html'), 'EditLogUrl' => url("/log/record/{$RecordType}/{$RecordID}"), 'EditWord' => 'at');
$DateUpdateTime = Gdn_Format::toTimestamp($Data->DateUpdated);
if (date('ymd', $DateUpdateTime) != date('ymd')) {
$Edited['EditWord'] = 'on';
}
$Format = t('PostEdited.Plain', 'Post edited by {EditUser} {EditWord} {EditDate}');
if ($UserCanEdit) {
$Format = t('PostEdited.Log', 'Post edited by {EditUser} {EditWord} {EditDate} (<a href="{EditLogUrl}">log</a>)');
}
echo '<div class="PostEdited">' . formatString($Format, $Edited) . '</div>';
}
示例10: getData
/**
*
*
* @throws Exception
*/
protected function getData()
{
$userID = $this->UserID ?: Gdn::session()->UserID;
$user = Gdn::userModel()->getID($userID);
$banned = val('Banned', $user);
$bits = BanModel::explodeBans($banned);
$reasons = array();
foreach ($bits as $bit) {
if (($bit & $this->ExcludeBans) === 0) {
$reasons[$bit] = t("BanReason.{$bit}");
}
}
$this->setData('Reasons', $reasons);
if (!$this->Summary) {
if ($this->ExcludeBans) {
$summary = "Also banned for the following:";
} else {
$summary = "Banned for the following:";
}
}
$this->setData('Summary', $this->Summary ?: $summary);
$this->EventArguments['User'] = $user;
$this->fireEvent('GetData');
}
示例11: configure
/**
* Allows the configuration of basic setup information in Garden. This
* should not be functional after the application has been set up.
*
* @since 2.0.0
* @access public
* @param string $RedirectUrl Where to send user afterward.
*/
private function configure($RedirectUrl = '')
{
// Create a model to save configuration settings
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->setField(array('Garden.Locale', 'Garden.Title', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password', 'Garden.Registration.ConfirmEmail', 'Garden.Email.SupportName'));
// Set the models on the forms.
$this->Form->setModel($ConfigurationModel);
// If seeing the form for the first time...
if (!$this->Form->isPostback()) {
// Force the webroot using our best guesstimates
$ConfigurationModel->Data['Database.Host'] = 'localhost';
$this->Form->setData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->applyRule('Database.Name', 'Required', 'You must specify the name of the database in which you want to set up Vanilla.');
// Let's make some user-friendly custom errors for database problems
$DatabaseHost = $this->Form->getFormValue('Database.Host', '~~Invalid~~');
$DatabaseName = $this->Form->getFormValue('Database.Name', '~~Invalid~~');
$DatabaseUser = $this->Form->getFormValue('Database.User', '~~Invalid~~');
$DatabasePassword = $this->Form->getFormValue('Database.Password', '~~Invalid~~');
$ConnectionString = GetConnectionString($DatabaseName, $DatabaseHost);
try {
$Connection = new PDO($ConnectionString, $DatabaseUser, $DatabasePassword);
} catch (PDOException $Exception) {
switch ($Exception->getCode()) {
case 1044:
$this->Form->addError(t('The database user you specified does not have permission to access the database. Have you created the database yet? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 1045:
$this->Form->addError(t('Failed to connect to the database with the username and password you entered. Did you mistype them? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 1049:
$this->Form->addError(t('It appears as though the database you specified does not exist yet. Have you created it yet? Did you mistype the name? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 2005:
$this->Form->addError(t("Are you sure you've entered the correct database host name? Maybe you mistyped it? The database reported: <code>%s</code>"), strip_tags($Exception->getMessage()));
break;
default:
$this->Form->addError(sprintf(t('ValidateConnection'), strip_tags($Exception->getMessage())));
break;
}
}
$ConfigurationModel->Validation->applyRule('Garden.Title', 'Required');
$ConfigurationFormValues = $this->Form->formValues();
if ($ConfigurationModel->validate($ConfigurationFormValues) !== true || $this->Form->errorCount() > 0) {
// Apply the validation results to the form(s)
$this->Form->setValidationResults($ConfigurationModel->validationResults());
} else {
$Host = array_shift(explode(':', Gdn::request()->requestHost()));
$Domain = Gdn::request()->domain();
// Set up cookies now so that the user can be signed in.
$ExistingSalt = c('Garden.Cookie.Salt', false);
$ConfigurationFormValues['Garden.Cookie.Salt'] = $ExistingSalt ? $ExistingSalt : betterRandomString(16, 'Aa0');
$ConfigurationFormValues['Garden.Cookie.Domain'] = '';
// Don't set this to anything by default. # Tim - 2010-06-23
// Additional default setup values.
$ConfigurationFormValues['Garden.Registration.ConfirmEmail'] = true;
$ConfigurationFormValues['Garden.Email.SupportName'] = $ConfigurationFormValues['Garden.Title'];
$ConfigurationModel->save($ConfigurationFormValues, true);
// If changing locale, redefine locale sources:
$NewLocale = 'en-CA';
// $this->Form->getFormValue('Garden.Locale', false);
if ($NewLocale !== false && Gdn::config('Garden.Locale') != $NewLocale) {
$Locale = Gdn::locale();
$Locale->set($NewLocale);
}
// Install db structure & basic data.
$Database = Gdn::database();
$Database->init();
$Drop = false;
$Explicit = false;
try {
include PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'structure.php';
} catch (Exception $ex) {
$this->Form->addError($ex);
}
if ($this->Form->errorCount() > 0) {
return false;
}
// Create the administrative user
$UserModel = Gdn::userModel();
$UserModel->defineSchema();
$UsernameError = t('UsernameError', 'Username can only contain letters, numbers, underscores, and must be between 3 and 20 characters long.');
$UserModel->Validation->applyRule('Name', 'Username', $UsernameError);
$UserModel->Validation->applyRule('Name', 'Required', t('You must specify an admin username.'));
$UserModel->Validation->applyRule('Password', 'Required', t('You must specify an admin password.'));
$UserModel->Validation->applyRule('Password', 'Match');
$UserModel->Validation->applyRule('Email', 'Email');
if (!($AdminUserID = $UserModel->SaveAdminUser($ConfigurationFormValues))) {
$this->Form->setValidationResults($UserModel->validationResults());
} else {
//.........这里部分代码省略.........
示例12: _formatStringCallback
//.........这里部分代码省略.........
}
break;
case 'rawurlencode':
$Result = rawurlencode($Value);
break;
case 'text':
$Result = Gdn_Format::text($Value, false);
break;
case 'time':
$Result = Gdn_Format::date($Value, '%l:%M%p');
break;
case 'url':
if (strpos($Field, '/') !== false) {
$Value = $Field;
}
$Result = Url($Value, $SubFormat == 'domain');
break;
case 'exurl':
if (strpos($Field, '/') !== false) {
$Value = $Field;
}
$Result = externalUrl($Value);
break;
case 'urlencode':
$Result = urlencode($Value);
break;
case 'gender':
// Format in the form of FieldName,gender,male,female,unknown[,plural]
if (is_array($Value) && count($Value) == 1) {
$Value = array_shift($Value);
}
$Gender = 'u';
if (!is_array($Value)) {
$User = Gdn::userModel()->getID($Value);
if ($User) {
$Gender = $User->Gender;
}
} else {
$Gender = 'p';
}
switch ($Gender) {
case 'm':
$Result = $SubFormat;
break;
case 'f':
$Result = $FormatArgs;
break;
case 'p':
$Result = val(5, $Parts, val(4, $Parts));
break;
case 'u':
default:
$Result = val(4, $Parts);
}
break;
case 'user':
case 'you':
case 'his':
case 'her':
case 'your':
// $Result = print_r($Value, true);
$ArgsBak = $Args;
if (is_array($Value) && count($Value) == 1) {
$Value = array_shift($Value);
}
if (is_array($Value)) {
示例13: registerInvitation
/**
* Invitation-only registration. Requires code.
*
* @param int $InvitationCode
* @since 2.0.0
*/
public function registerInvitation($InvitationCode = 0)
{
$this->Form->setModel($this->UserModel);
// Define gender dropdown options
$this->GenderOptions = array('u' => t('Unspecified'), 'm' => t('Male'), 'f' => t('Female'));
if (!$this->Form->isPostBack()) {
$this->Form->setValue('InvitationCode', $InvitationCode);
}
$InvitationModel = new InvitationModel();
// Look for the invitation.
$Invitation = $InvitationModel->getWhere(array('Code' => $this->Form->getValue('InvitationCode')))->firstRow(DATASET_TYPE_ARRAY);
if (!$Invitation) {
$this->Form->addError('Invitation not found.', 'Code');
} else {
if ($Expires = val('DateExpires', $Invitation)) {
$Expires = Gdn_Format::toTimestamp($Expires);
if ($Expires <= time()) {
}
}
}
$this->Form->addHidden('ClientHour', date('Y-m-d H:00'));
// Use the server's current hour as a default
$this->Form->addHidden('Target', $this->target());
Gdn::userModel()->addPasswordStrength($this);
if ($this->Form->isPostBack() === true) {
$this->InvitationCode = $this->Form->getValue('InvitationCode');
// Add validation rules that are not enforced by the model
$this->UserModel->defineSchema();
$this->UserModel->Validation->applyRule('Name', 'Username', $this->UsernameError);
$this->UserModel->Validation->applyRule('TermsOfService', 'Required', t('You must agree to the terms of service.'));
$this->UserModel->Validation->applyRule('Password', 'Required');
$this->UserModel->Validation->applyRule('Password', 'Strength');
$this->UserModel->Validation->applyRule('Password', 'Match');
// $this->UserModel->Validation->applyRule('DateOfBirth', 'MinimumAge');
$this->fireEvent('RegisterValidation');
try {
$Values = $this->Form->formValues();
$Values = $this->UserModel->filterForm($Values, true);
unset($Values['Roles']);
$AuthUserID = $this->UserModel->register($Values, array('Method' => 'Invitation'));
$this->setData('UserID', $AuthUserID);
if (!$AuthUserID) {
$this->Form->setValidationResults($this->UserModel->validationResults());
} else {
// The user has been created successfully, so sign in now.
Gdn::session()->start($AuthUserID);
if ($this->Form->getFormValue('RememberMe')) {
Gdn::authenticator()->setIdentity($AuthUserID, true);
}
$this->fireEvent('RegistrationSuccessful');
// ... and redirect them appropriately
$Route = $this->redirectTo();
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->RedirectUrl = url($Route);
} else {
if ($Route !== false) {
redirect($Route);
}
}
}
} catch (Exception $Ex) {
$this->Form->addError($Ex);
}
} else {
// Set some form defaults.
if ($Name = val('Name', $Invitation)) {
$this->Form->setValue('Name', $Name);
}
$this->InvitationCode = $InvitationCode;
}
// Make sure that the hour offset for new users gets defined when their account is created
$this->addJsFile('entry.js');
$this->render();
}
示例14: updateUser
/**
* Update user's total comment count.
*
* @since 2.0.0
* @access public
*
* @param int $UserID Unique ID of the user to be updated.
*/
public function updateUser($UserID, $Inc = false)
{
if ($Inc) {
// Just increment the comment count.
$this->SQL->update('User')->set('CountComments', 'CountComments + 1', false)->where('UserID', $UserID)->put();
} else {
// Retrieve a comment count
$CountComments = $this->SQL->select('c.CommentID', 'count', 'CountComments')->from('Comment c')->where('c.InsertUserID', $UserID)->get()->firstRow()->CountComments;
// Save to the attributes column of the user table for this user.
Gdn::userModel()->setField($UserID, 'CountComments', $CountComments);
}
}
示例15: profileController_quotes_create
/**
*
*
* @param $Sender
*/
public function profileController_quotes_create($Sender)
{
$Sender->permission('Garden.SignIn.Allow');
$Sender->title(t("Quotes Settings"));
$Args = $Sender->RequestArgs;
if (sizeof($Args) < 2) {
$Args = array_merge($Args, array(0, 0));
} elseif (sizeof($Args) > 2) {
$Args = array_slice($Args, 0, 2);
}
list($UserReference, $Username) = $Args;
$Sender->getUserInfo($UserReference, $Username);
$UserPrefs = Gdn_Format::unserialize($Sender->User->Preferences);
if (!is_array($UserPrefs)) {
$UserPrefs = array();
}
$UserID = Gdn::session()->UserID;
$ViewingUserID = $UserID;
if ($Sender->User->UserID != $ViewingUserID) {
$Sender->permission('Garden.Users.Edit');
$UserID = $Sender->User->UserID;
$Sender->setData('ForceEditing', $Sender->User->Name);
} else {
$Sender->setData('ForceEditing', false);
}
$QuoteFolding = val('Quotes.Folding', $UserPrefs, '1');
$Sender->Form->setValue('QuoteFolding', $QuoteFolding);
$Sender->setData('QuoteFoldingOptions', array('None' => t("Don't fold quotes"), '1' => plural(1, '%s level deep', '%s levels deep'), '2' => plural(2, '%s level deep', '%s levels deep'), '3' => plural(3, '%s level deep', '%s levels deep'), '4' => plural(4, '%s level deep', '%s levels deep'), '5' => plural(5, '%s level deep', '%s levels deep')));
// Form submission handling.
if ($Sender->Form->authenticatedPostBack()) {
$NewFoldingLevel = $Sender->Form->getValue('QuoteFolding', '1');
if ($NewFoldingLevel != $QuoteFolding) {
Gdn::userModel()->savePreference($UserID, 'Quotes.Folding', $NewFoldingLevel);
$Sender->informMessage(t("Your changes have been saved."));
}
}
$Sender->render('quotes', '', 'plugins/Quotes');
}