getDefaultAvatarUrl() public static method

Returns the url to the default avatar for a user.
public static getDefaultAvatarUrl ( array $user = [], string $size = 'thumbnail' ) : string
$user array The user to get the default avatar for.
$size string The size of avatar to return (only respected for dashboard-uploaded default avatars).
return string The url to the default avatar image.
 /**
  * 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);
 }
 /**
  * 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();
 }
Beispiel #3
0
 /**
  * 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);
                 }
             }
         }
     }
 }
Beispiel #4
0
    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'));
Beispiel #5
0
 /**
  *
  *
  * @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);
 }
Beispiel #6
0
 /**
  *
  *
  * @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);
 }
Beispiel #7
0
$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 != '') {
 /**
  * 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."));
         }
     }
     if (val('SideMenuModule', val('Panel', val('Assets', $this)))) {
         /** @var SideMenuModule $sidemenu */
         $sidemenu = $this->Assets['Panel']['SideMenuModule'];
         $sidemenu->highlightRoute('/profile/picture');
     }
     $this->title(t('Change Picture'));
     $this->_setBreadcrumbs(t('Change My Picture'), userUrl($this->User, '', 'picture'));
     $this->render('picture', 'profile', 'dashboard');
 }