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


PHP Gdn_UploadImage::url方法代码示例

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


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

示例1: getDefaultAvatarUrl

 /**
  * Returns the url to the default avatar for a user.
  *
  * @param array $user The user to get the default avatar for.
  * @param string $size The size of avatar to return (only respected for dashboard-uploaded default avatars).
  * @return string The url to the default avatar image.
  */
 public static function getDefaultAvatarUrl($user = [], $size = 'thumbnail')
 {
     if (!empty($user) && function_exists('UserPhotoDefaultUrl')) {
         return userPhotoDefaultUrl($user);
     }
     if ($avatar = c('Garden.DefaultAvatar', false)) {
         if (strpos($avatar, 'defaultavatar/') !== false) {
             if ($size == 'thumbnail') {
                 return Gdn_UploadImage::url(changeBasename($avatar, 'n%s'));
             } elseif ($size == 'profile') {
                 return Gdn_UploadImage::url(changeBasename($avatar, 'p%s'));
             }
         }
         return $avatar;
     }
     return asset('applications/dashboard/design/images/defaulticon.png', true);
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:24,代码来源:class.usermodel.php

示例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();
 }
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:66,代码来源:class.settingscontroller.php

示例3: emailImage

 /**
  * Form for adding an email image.
  * Exposes the Garden.EmailTemplate.Image setting.
  * Garden.EmailTemplate.Image must be an upload.
  *
  * Saves the image based on 2 config settings:
  * Garden.EmailTemplate.ImageMaxWidth (default 400px) and
  * Garden.EmailTemplate.ImageMaxHeight (default 300px)
  *
  * @throws Gdn_UserException
  */
 public function emailImage()
 {
     if (!Gdn::session()->checkPermission('Garden.Community.Manage')) {
         throw permissionException();
     }
     $this->addJsFile('email.js');
     $this->addSideMenu('dashboard/settings/email');
     $image = c('Garden.EmailTemplate.Image');
     $this->Form = new Gdn_Form();
     $validation = new Gdn_Validation();
     $configurationModel = new Gdn_ConfigurationModel($validation);
     // Set the model on the form.
     $this->Form->setModel($configurationModel);
     if ($this->Form->authenticatedPostBack() !== false) {
         try {
             $upload = new Gdn_UploadImage();
             // Validate the upload
             $tmpImage = $upload->validateUpload('EmailImage', false);
             if ($tmpImage) {
                 // Generate the target image name
                 $targetImage = $upload->generateTargetName(PATH_UPLOADS);
                 $imageBaseName = pathinfo($targetImage, PATHINFO_BASENAME);
                 // Delete any previously uploaded images.
                 if ($image) {
                     $upload->delete($image);
                 }
                 // Save the uploaded image
                 $parts = $upload->saveImageAs($tmpImage, $imageBaseName, c('Garden.EmailTemplate.ImageMaxWidth', 400), c('Garden.EmailTemplate.ImageMaxHeight', 300));
                 $imageBaseName = $parts['SaveName'];
                 saveToConfig('Garden.EmailTemplate.Image', $imageBaseName);
                 $this->setData('EmailImage', Gdn_UploadImage::url($imageBaseName));
             } else {
                 $this->Form->addError(t('There\'s been an error uploading the image. Your email logo can uploaded in one of the following filetypes: gif, jpg, png'));
             }
         } catch (Exception $ex) {
             $this->Form->addError($ex);
         }
     }
     $this->render();
 }
开发者ID:R-J,项目名称:vanilla,代码行数:51,代码来源:class.settingscontroller.php

示例4: getDefaultEmailImage

 /**
  * Retrieves default values for the email image.
  *
  * @return array An array representing an image.
  */
 public function getDefaultEmailImage()
 {
     $image = array();
     if (c('Garden.EmailTemplate.Image', '')) {
         $image['source'] = Gdn_UploadImage::url(c('Garden.EmailTemplate.Image'));
     }
     $image['link'] = url('/', true);
     $image['alt'] = c('Garden.LogoTitle', c('Garden.Title', ''));
     return $image;
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:15,代码来源:class.emailtemplate.php

示例5: emailImageUrl

 /**
  * Endpoint for retrieving current email image url.
  */
 public function emailImageUrl()
 {
     $this->deliveryMethod(DELIVERY_METHOD_JSON);
     $this->deliveryType(DELIVERY_TYPE_DATA);
     $image = c('Garden.EmailTemplate.Image');
     if ($image) {
         $image = Gdn_UploadImage::url($image);
     }
     $this->setData('EmailImage', $image);
     $this->render();
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:14,代码来源:class.settingscontroller.php

示例6: 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."));
         }
//.........这里部分代码省略.........
开发者ID:vanilla,项目名称:vanilla,代码行数:101,代码来源:class.profilecontroller.php


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