本文整理汇总了PHP中UserModel::getDefaultAvatarUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP UserModel::getDefaultAvatarUrl方法的具体用法?PHP UserModel::getDefaultAvatarUrl怎么用?PHP UserModel::getDefaultAvatarUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserModel
的用法示例。
在下文中一共展示了UserModel::getDefaultAvatarUrl方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: userPhotoUrl
/**
* Take a user object an return the URL to their photo.
*
* @param object|array $User
*/
function userPhotoUrl($User)
{
$FullUser = Gdn::userModel()->getID(val('UserID', $User), DATASET_TYPE_ARRAY);
$Photo = val('Photo', $User);
if ($FullUser && $FullUser['Banned']) {
$Photo = 'https://c3409409.ssl.cf0.rackcdn.com/images/banned_100.png';
}
if ($Photo) {
if (!isUrl($Photo)) {
$PhotoUrl = Gdn_Upload::url(changeBasename($Photo, 'n%s'));
} else {
$PhotoUrl = $Photo;
}
return $PhotoUrl;
}
return UserModel::getDefaultAvatarUrl($User);
}
示例2: defaultAvatar
/**
* Settings page for uploading, deleting and cropping the default avatar.
*
* @throws Exception
*/
public function defaultAvatar()
{
$this->permission('Garden.Community.Manage');
$this->addSideMenu('dashboard/settings/avatars');
$this->title(t('Default Avatar'));
$this->addJsFile('avatars.js');
$validation = new Gdn_Validation();
$configurationModel = new Gdn_ConfigurationModel($validation);
$this->Form->setModel($configurationModel);
if (($avatar = c('Garden.DefaultAvatar')) && $this->isUploadedDefaultAvatar($avatar)) {
//Get the image source so we can manipulate it in the crop module.
$upload = new Gdn_UploadImage();
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
$basename = changeBasename($avatar, "p%s");
$source = $upload->copyLocal($basename);
//Set up cropping.
$crop = new CropImageModule($this, $this->Form, $thumbnailSize, $thumbnailSize, $source);
$crop->setExistingCropUrl(Gdn_UploadImage::url(changeBasename($avatar, "n%s")));
$crop->setSourceImageUrl(Gdn_UploadImage::url(changeBasename($avatar, "p%s")));
$this->setData('crop', $crop);
} else {
$this->setData('avatar', UserModel::getDefaultAvatarUrl());
}
if (!$this->Form->authenticatedPostBack()) {
$this->Form->setData($configurationModel->Data);
} else {
if ($this->Form->save() !== false) {
$upload = new Gdn_UploadImage();
$newAvatar = false;
if ($tmpAvatar = $upload->validateUpload('DefaultAvatar', false)) {
// New upload
$thumbOptions = array('Crop' => true, 'SaveGif' => c('Garden.Thumbnail.SaveGif'));
$newAvatar = $this->saveDefaultAvatars($tmpAvatar, $thumbOptions);
} else {
if ($avatar && $crop && $crop->isCropped()) {
// New thumbnail
$tmpAvatar = $source;
$thumbOptions = array('Crop' => true, 'SourceX' => $crop->getCropXValue(), 'SourceY' => $crop->getCropYValue(), 'SourceWidth' => $crop->getCropWidth(), 'SourceHeight' => $crop->getCropHeight());
$newAvatar = $this->saveDefaultAvatars($tmpAvatar, $thumbOptions);
}
}
if ($this->Form->errorCount() == 0) {
if ($newAvatar) {
$this->deleteDefaultAvatars($avatar);
$avatar = c('Garden.DefaultAvatar');
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
// Update crop properties.
$basename = changeBasename($avatar, "p%s");
$source = $upload->copyLocal($basename);
$crop = new CropImageModule($this, $this->Form, $thumbnailSize, $thumbnailSize, $source);
$crop->setSize($thumbnailSize, $thumbnailSize);
$crop->setExistingCropUrl(Gdn_UploadImage::url(changeBasename($avatar, "n%s")));
$crop->setSourceImageUrl(Gdn_UploadImage::url(changeBasename($avatar, "p%s")));
$this->setData('crop', $crop);
}
}
$this->informMessage(t("Your settings have been saved."));
}
}
$this->render();
}
示例3: joinUsers
/**
* Add user data to a result set.
*
* @param array|Gdn_DataSet $Data Results we need to associate user data with.
* @param array $Columns Database columns containing UserIDs to get data for.
* @param array $Options Optionally pass list of user data to collect with key 'Join'.
*/
public function joinUsers(&$Data, $Columns, $Options = [])
{
if ($Data instanceof Gdn_DataSet) {
$Data2 = $Data->result();
} else {
$Data2 =& $Data;
}
// Grab all of the user fields that need to be joined.
$UserIDs = [];
foreach ($Data as $Row) {
foreach ($Columns as $ColumnName) {
$ID = val($ColumnName, $Row);
if (is_numeric($ID)) {
$UserIDs[$ID] = 1;
}
}
}
// Get the users.
$Users = $this->getIDs(array_keys($UserIDs));
// Get column name prefix (ex: 'Insert' from 'InsertUserID')
$Prefixes = [];
foreach ($Columns as $ColumnName) {
$Prefixes[] = StringEndsWith($ColumnName, 'UserID', true, true);
}
// Join the user data using prefixes (ex: 'Name' for 'InsertUserID' becomes 'InsertName')
$Join = val('Join', $Options, ['Name', 'Email', 'Photo']);
foreach ($Data2 as &$Row) {
foreach ($Prefixes as $Px) {
$ID = val($Px . 'UserID', $Row);
if (is_numeric($ID)) {
$User = val($ID, $Users, false);
foreach ($Join as $Column) {
$Value = $User[$Column];
if ($Column == 'Photo') {
if ($Value && !isUrl($Value)) {
$Value = Gdn_Upload::url(changeBasename($Value, 'n%s'));
} elseif (!$Value) {
$Value = UserModel::getDefaultAvatarUrl($User);
}
}
setValue($Px . $Column, $Row, $Value);
}
} else {
foreach ($Join as $Column) {
setValue($Px . $Column, $Row, null);
}
}
}
}
}
示例4: val
exit;
}
$User = val('User', Gdn::controller());
if (!$User && Gdn::session()->isValid()) {
$User = Gdn::session()->User;
}
if (!$User) {
return;
}
$Photo = $User->Photo;
if ($Photo) {
if (!IsUrl($Photo)) {
$Photo = Gdn_Upload::url(changeBasename($Photo, 'p%s'));
}
} else {
$Photo = UserModel::getDefaultAvatarUrl($User, 'profile');
}
if ($User->Banned) {
$BannedPhoto = c('Garden.BannedPhoto', 'https://c3409409.ssl.cf0.rackcdn.com/images/banned_large.png');
if ($BannedPhoto) {
$Photo = Gdn_Upload::url($BannedPhoto);
}
}
if ($Photo) {
?>
<div class="Photo PhotoWrap PhotoWrapLarge <?php
echo val('_CssClass', $User);
?>
">
<?php
$Img = img($Photo, array('class' => 'ProfilePhotoLarge'));
示例5: init
/**
*
*
* @param string $Path
* @param Gdn_Controller $Controller
*/
public function init($Path, $Controller)
{
$Smarty = $this->smarty();
// Get a friendly name for the controller.
$ControllerName = get_class($Controller);
if (StringEndsWith($ControllerName, 'Controller', true)) {
$ControllerName = substr($ControllerName, 0, -10);
}
// Get an ID for the body.
$BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod)));
$Smarty->assign('BodyID', htmlspecialchars($BodyIdentifier));
//$Smarty->assign('Config', Gdn::Config());
// Assign some information about the user.
$Session = Gdn::session();
if ($Session->isValid()) {
$User = array('Name' => htmlspecialchars($Session->User->Name), 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
$Photo = $Session->User->Photo;
if ($Photo) {
if (!isUrl($Photo)) {
$Photo = Gdn_Upload::url(changeBasename($Photo, 'n%s'));
}
} else {
$Photo = UserModel::getDefaultAvatarUrl($Session->User);
}
$User['Photo'] = $Photo;
} else {
$User = false;
/*array(
'Name' => '',
'CountNotifications' => 0,
'SignedIn' => FALSE);*/
}
$Smarty->assign('User', $User);
// Make sure that any datasets use arrays instead of objects.
foreach ($Controller->Data as $Key => $Value) {
if ($Value instanceof Gdn_DataSet) {
$Controller->Data[$Key] = $Value->resultArray();
} elseif ($Value instanceof stdClass) {
$Controller->Data[$Key] = (array) $Value;
}
}
$BodyClass = val('CssClass', $Controller->Data, '', true);
$Sections = Gdn_Theme::section(null, 'get');
if (is_array($Sections)) {
foreach ($Sections as $Section) {
$BodyClass .= ' Section-' . $Section;
}
}
$Controller->Data['BodyClass'] = $BodyClass;
// Set the current locale for themes to take advantage of.
$Locale = Gdn::locale()->Locale;
$CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', Gdn::locale()->language(true)));
if (class_exists('Locale')) {
$CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
$CurrentLocale['Region'] = Locale::getRegion($Locale);
$CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
$CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
$CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
}
$Smarty->assign('CurrentLocale', $CurrentLocale);
$Smarty->assign('Assets', (array) $Controller->Assets);
// 2016-07-07 Linc: Request used to return blank for homepage.
// Now it returns defaultcontroller. This restores BC behavior.
$isHomepage = val('isHomepage', $Controller->Data);
$Path = $isHomepage ? "" : Gdn::request()->path();
$Smarty->assign('Path', $Path);
$Smarty->assign('Homepage', $isHomepage);
// true/false
// Assign the controller data last so the controllers override any default data.
$Smarty->assign($Controller->Data);
$security = new SmartySecurityVanilla($Smarty);
$security->php_handling = Smarty::PHP_REMOVE;
$security->allow_constants = false;
$security->allow_super_globals = false;
$security->streams = null;
$security->setPhpFunctions(array_merge($security->php_functions, ['array', 'category', 'checkPermission', 'inSection', 'inCategory', 'ismobile', 'multiCheckPermission', 'getValue', 'setValue', 'url', 'useragenttype']));
$security->php_modifiers = array_merge($security->php_functions, array('sprintf'));
$Smarty->enableSecurity($security);
}
示例6: init
/**
*
*
* @param $Path
* @param $Controller
*/
public function init($Path, $Controller)
{
$Smarty = $this->smarty();
// Get a friendly name for the controller.
$ControllerName = get_class($Controller);
if (StringEndsWith($ControllerName, 'Controller', true)) {
$ControllerName = substr($ControllerName, 0, -10);
}
// Get an ID for the body.
$BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod)));
$Smarty->assign('BodyID', htmlspecialchars($BodyIdentifier));
//$Smarty->assign('Config', Gdn::Config());
// Assign some information about the user.
$Session = Gdn::session();
if ($Session->isValid()) {
$User = array('Name' => htmlspecialchars($Session->User->Name), 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
$Photo = $Session->User->Photo;
if ($Photo) {
if (!isUrl($Photo)) {
$Photo = Gdn_Upload::url(changeBasename($Photo, 'n%s'));
}
} else {
$Photo = UserModel::getDefaultAvatarUrl($Session->User);
}
$User['Photo'] = $Photo;
} else {
$User = false;
/*array(
'Name' => '',
'CountNotifications' => 0,
'SignedIn' => FALSE);*/
}
$Smarty->assign('User', $User);
// Make sure that any datasets use arrays instead of objects.
foreach ($Controller->Data as $Key => $Value) {
if ($Value instanceof Gdn_DataSet) {
$Controller->Data[$Key] = $Value->resultArray();
} elseif ($Value instanceof stdClass) {
$Controller->Data[$Key] = (array) $Value;
}
}
$BodyClass = val('CssClass', $Controller->Data, '', true);
$Sections = Gdn_Theme::section(null, 'get');
if (is_array($Sections)) {
foreach ($Sections as $Section) {
$BodyClass .= ' Section-' . $Section;
}
}
$Controller->Data['BodyClass'] = $BodyClass;
// Set the current locale for themes to take advantage of.
$Locale = Gdn::locale()->Locale;
$CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', $Locale));
if (class_exists('Locale')) {
$CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
$CurrentLocale['Region'] = Locale::getRegion($Locale);
$CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
$CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
$CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
}
$Smarty->assign('CurrentLocale', $CurrentLocale);
$Smarty->assign('Assets', (array) $Controller->Assets);
$Smarty->assign('Path', Gdn::request()->path());
// Assign the controller data last so the controllers override any default data.
$Smarty->assign($Controller->Data);
$Smarty->Controller = $Controller;
// for smarty plugins
$Smarty->security = true;
$Smarty->security_settings['IF_FUNCS'] = array_merge($Smarty->security_settings['IF_FUNCS'], array('Category', 'CheckPermission', 'InSection', 'InCategory', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url'));
$Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf'));
$Smarty->secure_dir = array($Path);
}
示例7: IsUrl
$RemotePhoto = IsUrl($this->User->Photo, 0, 7);
// Define the current profile picture
$Picture = '';
if ($this->User->Photo != '') {
if (IsUrl($this->User->Photo)) {
$Picture = img($this->User->Photo, array('class' => 'ProfilePhotoLarge'));
} else {
$Picture = img(Gdn_Upload::url(changeBasename($this->User->Photo, 'p%s')), array('class' => 'ProfilePhotoLarge'));
}
}
// Define the current thumbnail icon
$Thumbnail = $this->User->Photo;
if ($Thumbnail && !isUrl($Thumbnail)) {
$Thumbnail = Gdn_Upload::url(changeBasename($Thumbnail, 'n%s'));
} else {
$Thumbnail = UserModel::getDefaultAvatarUrl($this->User);
}
$Thumbnail = img($Thumbnail, array('alt' => t('Thumbnail')));
?>
<h4 class="H discussions-label"><?php
echo $this->data('Title');
?>
</h4>
<div class="SmallPopup FormTitleWrapper">
<?php
echo $this->Form->open(array('enctype' => 'multipart/form-data'));
echo $this->Form->errors();
?>
<ul>
<?php
if ($Picture != '') {
示例8: picture
/**
* Set user's photo (avatar).
*
* @since 2.0.0
* @access public
*
* @param mixed $userReference Unique identifier, possible username or ID.
* @param string $username The username.
* @param string $userID The user's ID.
*
* @throws Exception
* @throws Gdn_UserException
*/
public function picture($userReference = '', $username = '', $userID = '')
{
$this->addJsFile('profile.js');
if (!$this->CanEditPhotos) {
throw forbiddenException('@Editing user photos has been disabled.');
}
// Permission checks
$this->permission(array('Garden.Profiles.Edit', 'Moderation.Profiles.Edit', 'Garden.ProfilePicture.Edit'), false);
$session = Gdn::session();
if (!$session->isValid()) {
$this->Form->addError('You must be authenticated in order to use this form.');
}
// Check ability to manipulate image
if (function_exists('gd_info')) {
$gdInfo = gd_info();
$gdVersion = preg_replace('/[a-z ()]+/i', '', $gdInfo['GD Version']);
if ($gdVersion < 2) {
throw new Exception(sprintf(t("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $gdVersion));
}
} else {
throw new Exception(sprintf(t("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better.")));
}
// Get user data & prep form.
if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('UserID')) {
$userID = $this->Form->getFormValue('UserID');
}
$this->getUserInfo($userReference, $username, $userID, true);
$validation = new Gdn_Validation();
$configurationModel = new Gdn_ConfigurationModel($validation);
$this->Form->setModel($configurationModel);
$avatar = $this->User->Photo;
if ($avatar === null) {
$avatar = UserModel::getDefaultAvatarUrl();
}
$source = '';
$crop = null;
if ($this->isUploadedAvatar($avatar)) {
// Get the image source so we can manipulate it in the crop module.
$upload = new Gdn_UploadImage();
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
$basename = changeBasename($avatar, "p%s");
$source = $upload->copyLocal($basename);
// Set up cropping.
$crop = new CropImageModule($this, $this->Form, $thumbnailSize, $thumbnailSize, $source);
$crop->setExistingCropUrl(Gdn_UploadImage::url(changeBasename($avatar, "n%s")));
$crop->setSourceImageUrl(Gdn_UploadImage::url(changeBasename($avatar, "p%s")));
$this->setData('crop', $crop);
} else {
$this->setData('avatar', $avatar);
}
if (!$this->Form->authenticatedPostBack()) {
$this->Form->setData($configurationModel->Data);
} else {
if ($this->Form->save() !== false) {
$upload = new Gdn_UploadImage();
$newAvatar = false;
if ($tmpAvatar = $upload->validateUpload('Avatar', false)) {
// New upload
$thumbOptions = array('Crop' => true, 'SaveGif' => c('Garden.Thumbnail.SaveGif'));
$newAvatar = $this->saveAvatars($tmpAvatar, $thumbOptions, $upload);
} else {
if ($avatar && $crop && $crop->isCropped()) {
// New thumbnail
$tmpAvatar = $source;
$thumbOptions = array('Crop' => true, 'SourceX' => $crop->getCropXValue(), 'SourceY' => $crop->getCropYValue(), 'SourceWidth' => $crop->getCropWidth(), 'SourceHeight' => $crop->getCropHeight());
$newAvatar = $this->saveAvatars($tmpAvatar, $thumbOptions);
}
}
if ($this->Form->errorCount() == 0) {
if ($newAvatar !== false) {
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
// Update crop properties.
$basename = changeBasename($newAvatar, "p%s");
$source = $upload->copyLocal($basename);
$crop = new CropImageModule($this, $this->Form, $thumbnailSize, $thumbnailSize, $source);
$crop->setSize($thumbnailSize, $thumbnailSize);
$crop->setExistingCropUrl(Gdn_UploadImage::url(changeBasename($newAvatar, "n%s")));
$crop->setSourceImageUrl(Gdn_UploadImage::url(changeBasename($newAvatar, "p%s")));
$this->setData('crop', $crop);
}
}
if ($this->deliveryType() === DELIVERY_TYPE_VIEW) {
$this->jsonTarget('', '', 'Refresh');
$this->RedirectUrl = userUrl($this->User);
}
$this->informMessage(t("Your settings have been saved."));
}
//.........这里部分代码省略.........