コード例 #1
0
 /**
  * Create different sizes of user photos.
  */
 public function processAvatars()
 {
     $UploadImage = new Gdn_UploadImage();
     $UserData = $this->SQL->select('u.Photo')->from('User u')->where('u.Photo is not null')->get();
     // Make sure the avatars folder exists.
     if (!file_exists(PATH_UPLOADS . '/userpics')) {
         mkdir(PATH_UPLOADS . '/userpics');
     }
     // Get sizes
     $ProfileHeight = c('Garden.Profile.MaxHeight', 1000);
     $ProfileWidth = c('Garden.Profile.MaxWidth', 250);
     $ThumbSize = c('Garden.Thumbnail.Size', 40);
     // Temporarily set maximum quality
     saveToConfig('Garden.UploadImage.Quality', 100, false);
     // Create profile and thumbnail sizes
     foreach ($UserData->result() as $User) {
         try {
             $Image = PATH_ROOT . DS . 'uploads' . DS . GetValue('Photo', $User);
             $ImageBaseName = pathinfo($Image, PATHINFO_BASENAME);
             // Save profile size
             $UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/p' . $ImageBaseName, $ProfileHeight, $ProfileWidth);
             // Save thumbnail size
             $UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, true);
         } catch (Exception $ex) {
         }
     }
 }
コード例 #2
0
 /**
  * Create different sizes of user photos.
  */
 public function ProcessAvatars()
 {
     $UploadImage = new Gdn_UploadImage();
     $UserData = $this->SQL->Select('u.Photo')->From('User u')->Where('u.Photo is not null')->Get();
     // Make sure the avatars folder exists.
     if (!file_exists(PATH_UPLOADS . '/userpics')) {
         mkdir(PATH_UPLOADS . '/userpics');
     }
     $ProfileHeight = C('Garden.Profile.MaxHeight', 1000);
     $ProfileWidth = C('Garden.Profile.MaxWidth', 250);
     $PreviewHeight = C('Garden.Preview.MaxHeight', 100);
     $PreviewWidth = C('Garden.Preview.MaxWidth', 75);
     $ThumbSize = C('Garden.Thumbnail.Size', 50);
     foreach ($UserData->Result() as $User) {
         try {
             $Image = PATH_ROOT . DS . 'uploads' . DS . $User->Photo;
             $ImageBaseName = pathinfo($Image, PATHINFO_BASENAME);
             // Save profile size
             $UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/p' . $ImageBaseName, $ProfileHeight, $ProfileWidth);
             // Save thumbnail size
             $UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
         }
     }
 }
コード例 #3
0
 /**
  * Create different sizes of user photos.
  */
 public function processAvatars()
 {
     $UploadImage = new Gdn_UploadImage();
     $UserData = $this->SQL->select('u.Photo')->from('User u')->get();
     foreach ($UserData->result() as $User) {
         try {
             $Image = PATH_ROOT . DS . 'uploads' . DS . str_replace('userpics', 'attachments', $User->Photo);
             // Check extension length
             $ImageExtension = strlen(pathinfo($Image, PATHINFO_EXTENSION));
             $ImageBaseName = pathinfo($Image, PATHINFO_BASENAME) + 1;
             if (!file_exists($Image)) {
                 rename(substr($Image, 0, -$ImageExtension), $Image);
             }
             // Make sure the avatars folder exists.
             if (!file_exists(PATH_ROOT . '/uploads/userpics')) {
                 mkdir(PATH_ROOT . '/uploads/userpics');
             }
             // Save the uploaded image in profile size
             if (!file_exists(PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName)) {
                 $UploadImage->SaveImageAs($Image, PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName, Gdn::config('Garden.Profile.MaxHeight', 1000), Gdn::config('Garden.Profile.MaxWidth', 250));
             }
             // Save the uploaded image in preview size
             /*if (!file_exists(PATH_ROOT.'/uploads/userpics/t'.$ImageBaseName))
               $UploadImage->SaveImageAs(
                  $Image,
                  PATH_ROOT.'/uploads/userpics/t'.$ImageBaseName,
                  Gdn::config('Garden.Preview.MaxHeight', 100),
                  Gdn::config('Garden.Preview.MaxWidth', 75)
               );*/
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::config('Garden.Thumbnail.Size', 40);
             if (!file_exists(PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName)) {
                 $UploadImage->SaveImageAs($Image, PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, true);
             }
         } catch (Exception $ex) {
         }
     }
 }
コード例 #4
0
ファイル: default.php プロジェクト: edward-tsai/vanilla4china
 public function PostController_Imageupload_create()
 {
     try {
         $UploadImage = new Gdn_UploadImage();
         $TmpImage = $UploadImage->ValidateUpload('image_file');
         // Generate the target image name.
         $TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS . '/imageupload', '', TRUE);
         $Props = $UploadImage->SaveImageAs($TmpImage, $TargetImage, C('Plugins.UploadImage.MaxHeight', ''), C('Plugins.UploadImage.MaxWidth', 650));
         echo json_encode(array('url' => $Props['Url'], 'name' => $UploadImage->GetUploadedFileName()));
     } catch (Exception $e) {
         header('HTTP/1.0 400', TRUE, 400);
         echo $e;
     }
 }
コード例 #5
0
 /**
  * Touch icon management screen.
  *
  * @since 1.0
  * @access public
  */
 public function SettingsController_TouchIcon_Create($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->AddSideMenu('settings/touchicon');
     $Sender->Title(T('Touch Icon'));
     if ($Sender->Form->AuthenticatedPostBack()) {
         $Upload = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $Upload->ValidateUpload('TouchIcon', FALSE);
             if ($TmpImage) {
                 // Save the uploaded image.
                 $TouchIconPath = 'banner/touchicon_' . substr(md5(microtime()), 16) . '.png';
                 $ImageInfo = $Upload->SaveImageAs($TmpImage, $TouchIconPath, 114, 114, array('OutputType' => 'png', 'ImageQuality' => '8'));
                 SaveToConfig('Garden.TouchIcon', $ImageInfo['SaveName']);
             }
         } catch (Exception $ex) {
             $Sender->Form->AddError($ex->getMessage());
         }
         $Sender->InformMessage(T("Your icon has been saved."));
     }
     $Sender->SetData('Path', $this->getIconUrl());
     $Sender->Render($this->GetView('touchicon.php'));
 }
コード例 #6
0
 public function Picture($UserReference = '', $Username = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $ImageManipOk = FALSE;
     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.")));
     }
     $this->GetUserInfo($UserReference, $Username);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Delete any previously uploaded images
             @unlink(PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'p%s'));
             // Don't delete this one because it hangs around in activity streams:
             // @unlink(PATH_ROOT.'/uploads/'.ChangeBasename($this->User->Photo, 't%s'));
             @unlink(PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'n%s'));
             // Make sure the avatars folder exists.
             if (!file_exists(PATH_ROOT . '/uploads/userpics')) {
                 mkdir(PATH_ROOT . '/uploads/userpics');
             }
             // Save the uploaded image in profile size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
             // Save the uploaded image in preview size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/t' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
             $this->Form->AddError($ex->getMessage());
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'Photo' => 'userpics/' . $ImageBaseName))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('dashboard/profile/' . $UserReference);
         }
     }
     if ($this->Form->ErrorCount() > 0) {
         $this->DeliveryType(DELIVERY_TYPE_ALL);
     }
     $this->Render();
 }
コード例 #7
0
   public function Thumbnail($UserReference = '', $Username = '') {
      $this->Permission('Garden.SignIn.Allow');
      $this->AddJsFile('jquery.jcrop.pack.js');
      $this->AddJsFile('profile.js');
            
      $Session = Gdn::Session();
      if (!$Session->IsValid())
         $this->Form->AddError('You must be authenticated in order to use this form.');
               
      $this->GetUserInfo($UserReference, $Username);
      
      if ($this->User->UserID != $Session->UserID && !$Session->CheckPermission('Garden.Users.Edit'))
         throw new Exception(T('You cannot edit the thumbnail of another member.'));
      
      $this->Form->SetModel($this->UserModel);
      $this->Form->AddHidden('UserID', $this->User->UserID);
      
      if (!$this->User->Photo)
         $this->Form->AddError('You must first upload a picture before you can create a thumbnail.');
      
      // Define the thumbnail size
      $this->ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 32);
      
      // Define the source (profile sized) picture & dimensions.
      $Basename = ChangeBasename($this->User->Photo, 'p%s');
      $Upload = new Gdn_UploadImage();
      $PhotoParsed = Gdn_Upload::Parse($Basename);
      $Source = $Upload->CopyLocal($Basename);

      if (!$Source) {
         $this->Form->AddError('You cannot edit the thumbnail of an externally linked profile picture.');
      } else {
         $this->SourceSize = getimagesize($Source);
      }
      
      // Add some more hidden form fields for jcrop
      $this->Form->AddHidden('x', '0');
      $this->Form->AddHidden('y', '0');
      $this->Form->AddHidden('w', $this->ThumbSize);
      $this->Form->AddHidden('h', $this->ThumbSize);
      $this->Form->AddHidden('HeightSource', $this->SourceSize[1]);
      $this->Form->AddHidden('WidthSource', $this->SourceSize[0]);
      $this->Form->AddHidden('ThumbSize', $this->ThumbSize);      
      if ($this->Form->AuthenticatedPostBack() === TRUE) {
         try {
            // Get the dimensions from the form.
            Gdn_UploadImage::SaveImageAs(
               $Source,
               'userpics/'.ChangeBasename(basename($this->User->Photo), 'n%s'),
               $this->ThumbSize, $this->ThumbSize,
               array('Crop' => TRUE, 'SourceX' => $this->Form->GetValue('x'), 'SourceY' => $this->Form->GetValue('y'), 'SourceWidth' => $this->Form->GetValue('w'), 'SourceHeight' => $this->Form->GetValue('h')));
         } catch (Exception $Ex) {
            $this->Form->AddError($Ex);
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
            Redirect('dashboard/profile/'.$this->ProfileUrl());
         }
      }
      // Delete the source image if it is externally hosted.
      if ($PhotoParsed['Type']) {
         @unlink($Source);
      }
      $this->Render();
   }
コード例 #8
0
 /**
  * Banner management screen.
  *
  * @since 2.0.0
  * @access public
  */
 public function Banner()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->AddSideMenu('dashboard/settings/banner');
     $this->Title(T('Banner'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.HomepageTitle' => C('Garden.Title'), 'Garden.Title', 'Garden.Description'));
     // Set the model on the form.
     $this->Form->SetModel($ConfigurationModel);
     // Get the current logo.
     $Logo = C('Garden.Logo');
     if ($Logo) {
         $Logo = ltrim($Logo, '/');
         // Fix the logo path.
         if (StringBeginsWith($Logo, 'uploads/')) {
             $Logo = substr($Logo, strlen('uploads/'));
         }
         $this->SetData('Logo', $Logo);
     }
     // Get the current favicon.
     $Favicon = C('Garden.FavIcon');
     $this->SetData('Favicon', $Favicon);
     $ShareImage = C('Garden.ShareImage');
     $this->SetData('ShareImage', $ShareImage);
     // If seeing the form for the first time...
     if (!$this->Form->AuthenticatedPostBack()) {
         // Apply the config settings to the form.
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $SaveData = array();
         if ($this->Form->Save() !== FALSE) {
             $Upload = new Gdn_Upload();
             try {
                 // Validate the upload
                 $TmpImage = $Upload->ValidateUpload('Logo', FALSE);
                 if ($TmpImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images.
                     if ($Logo) {
                         $Upload->Delete($Logo);
                     }
                     // Save the uploaded image
                     $Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
                     $ImageBaseName = $Parts['SaveName'];
                     $SaveData['Garden.Logo'] = $ImageBaseName;
                     $this->SetData('Logo', $ImageBaseName);
                 }
                 $ImgUpload = new Gdn_UploadImage();
                 $TmpFavicon = $ImgUpload->ValidateUpload('Favicon', FALSE);
                 if ($TmpFavicon) {
                     $ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
                     if ($Favicon) {
                         $Upload->Delete($Favicon);
                     }
                     // Resize the to a png.
                     $Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => TRUE));
                     $SaveData['Garden.FavIcon'] = $Parts['SaveName'];
                     $this->SetData('Favicon', $Parts['SaveName']);
                 }
                 $TmpShareImage = $Upload->ValidateUpload('ShareImage', FALSE);
                 if ($TmpShareImage) {
                     $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, FALSE);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     if ($ShareImage) {
                         $Upload->Delete($ShareImage);
                     }
                     $Parts = $Upload->SaveAs($TmpShareImage, $ImageBaseName);
                     $SaveData['Garden.ShareImage'] = $Parts['SaveName'];
                     $this->SetData('ShareImage', $Parts['SaveName']);
                 }
             } catch (Exception $ex) {
                 $this->Form->AddError($ex);
             }
             // If there were no errors, save the path to the logo in the config
             if ($this->Form->ErrorCount() == 0) {
                 SaveToConfig($SaveData);
             }
             $this->InformMessage(T("Your settings have been saved."));
         }
     }
     $this->Render();
 }
コード例 #9
0
ファイル: profile.php プロジェクト: kidmax/Garden
 public function Picture($UserReference = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $this->GetUserInfo($UserReference);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image in large size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'o' . $ImageBaseName, Gdn::Config('Garden.Picture.MaxHeight', 1000), Gdn::Config('Garden.Picture.MaxWidth', 1000));
             // Save the uploaded image in profile size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
             // Save the uploaded image in preview size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
             $this->Form->AddError($ex->getMessage());
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             $PhotoModel = new Model('Photo');
             $PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('garden/profile/' . $UserReference);
         }
     }
     $this->Render();
 }
コード例 #10
0
 /**
  * Set user's thumbnail (crop & center photo).
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possible username or ID.
  * @param string $Username.
  */
 public function Thumbnail($UserReference = '', $Username = '')
 {
     if (!C('Garden.Profile.EditPhotos', TRUE)) {
         throw ForbiddenException('@Editing user photos has been disabled.');
     }
     // Initial permission checks (valid user)
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     // Need some extra JS
     // jcrop update jan28, 2014 as jQuery upgrade to 1.10.2 no longer
     // supported browser()
     $this->AddJsFile('jquery.jcrop.min.js');
     $this->AddJsFile('profile.js');
     $this->GetUserInfo($UserReference, $Username, '', TRUE);
     // Permission check (correct user)
     if ($this->User->UserID != $Session->UserID && !CheckPermission('Garden.Users.Edit') && !CheckPermission('Moderation.Profiles.Edit')) {
         throw new Exception(T('You cannot edit the thumbnail of another member.'));
     }
     // Form prep
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     // Confirm we have a photo to manipulate
     if (!$this->User->Photo) {
         $this->Form->AddError('You must first upload a picture before you can create a thumbnail.');
     }
     // Define the thumbnail size
     $this->ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 40);
     // Define the source (profile sized) picture & dimensions.
     $Basename = ChangeBasename($this->User->Photo, 'p%s');
     $Upload = new Gdn_UploadImage();
     $PhotoParsed = Gdn_Upload::Parse($Basename);
     $Source = $Upload->CopyLocal($Basename);
     if (!$Source) {
         $this->Form->AddError('You cannot edit the thumbnail of an externally linked profile picture.');
     } else {
         $this->SourceSize = getimagesize($Source);
     }
     // We actually need to upload a new file to help with cdb ttls.
     $NewPhoto = $Upload->GenerateTargetName('userpics', trim(pathinfo($this->User->Photo, PATHINFO_EXTENSION), '.'), TRUE);
     // Add some more hidden form fields for jcrop
     $this->Form->AddHidden('x', '0');
     $this->Form->AddHidden('y', '0');
     $this->Form->AddHidden('w', $this->ThumbSize);
     $this->Form->AddHidden('h', $this->ThumbSize);
     $this->Form->AddHidden('HeightSource', $this->SourceSize[1]);
     $this->Form->AddHidden('WidthSource', $this->SourceSize[0]);
     $this->Form->AddHidden('ThumbSize', $this->ThumbSize);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         try {
             // Get the dimensions from the form.
             Gdn_UploadImage::SaveImageAs($Source, ChangeBasename($NewPhoto, 'n%s'), $this->ThumbSize, $this->ThumbSize, array('Crop' => TRUE, 'SourceX' => $this->Form->GetValue('x'), 'SourceY' => $this->Form->GetValue('y'), 'SourceWidth' => $this->Form->GetValue('w'), 'SourceHeight' => $this->Form->GetValue('h')));
             // Save new profile picture.
             $Parsed = $Upload->SaveAs($Source, ChangeBasename($NewPhoto, 'p%s'));
             $UserPhoto = sprintf($Parsed['SaveFormat'], $NewPhoto);
             // Save the new photo info.
             Gdn::UserModel()->SetField($this->User->UserID, 'Photo', $UserPhoto);
             // Remove the old profile picture.
             @$Upload->Delete($Basename);
         } catch (Exception $Ex) {
             $this->Form->AddError($Ex);
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect(UserUrl($this->User, '', 'picture'));
             $this->InformMessage(Sprite('Check', 'InformSprite') . T('Your changes have been saved.'), 'Dismissable AutoDismiss HasSprite');
         }
     }
     // Delete the source image if it is externally hosted.
     if ($PhotoParsed['Type']) {
         @unlink($Source);
     }
     $this->Title(T('Edit My Thumbnail'));
     $this->_SetBreadcrumbs(T('Edit My Thumbnail'), '/profile/thumbnail');
     $this->Render();
 }
コード例 #11
0
 function ThumbnailImage($Data, $Attributes = False)
 {
     if (function_exists('Debug') && Debug()) {
         Deprecated(__FUNCTION__, 'Thumbnail');
     }
     $Width = ArrayValue('width', $Attributes, '');
     $Height = ArrayValue('height', $Attributes, '');
     if (Is_Array($Data)) {
         // group, todo
         // <ul><li><a></a></li>
     }
     $Prefix = substr($Data, 0, 7);
     //if(In_Array($Prefix, array('http://', 'https:/'))) {}
     //$bLocalImage = False;
     if ($Prefix != 'http://') {
         //$bLocalImage = True;
         $IncomingImage = $Data;
         $ImageFindPaths[] = 'uploads' . DS . $Data;
         $ImageFindPaths[] = $Data;
         foreach ($ImageFindPaths as $File) {
             if (file_exists($File) && is_file($File)) {
                 $IncomingImage = $File;
                 break;
             }
         }
     } else {
         $IncomingImage = $Data;
     }
     $CacheDirectory = 'uploads/cached';
     if (!is_writable($CacheDirectory)) {
         mkdir($CacheDirectory, 0777, True);
         if (!is_writable($CacheDirectory)) {
             $ErrorMessage = ErrorMessage(sprintf(T('Directory (%s) is not writable.'), $CacheDirectory), 'PHP', __FUNCTION__);
             trigger_error($ErrorMessage, E_USER_ERROR);
             return '';
         }
     }
     $Name = CleanupString(pathinfo($IncomingImage, PATHINFO_FILENAME) . ' ' . $Width . ' ' . $Height);
     $Extension = FileExtension($IncomingImage);
     $Target = $CacheDirectory . DS . $Name . '.' . $Extension;
     if (!file_exists($Target)) {
         Gdn_UploadImage::SaveImageAs($IncomingImage, $Target, $Height, $Width);
     }
     $Target = str_replace(DS, '/', $Target);
     if (!array_key_exists('alt', $Attributes)) {
         $Attributes['alt'] = pathinfo($Name, PATHINFO_FILENAME);
     }
     list($Width, $Height, $Type) = GetImageSize($IncomingImage);
     $Attributes['alt'] .= sprintf(' (%d×%d)', $Width, $Height);
     $Image = Img($Target, $Attributes);
     return Anchor($Image, Url($IncomingImage), '', '', True);
 }
コード例 #12
0
 /**
  * Banner management screen.
  *
  * @since 2.0.0
  * @access public
  */
 public function banner()
 {
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     $this->setHighlightRoute('dashboard/settings/banner');
     $this->title(t('Banner'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->setField(array('Garden.HomepageTitle' => c('Garden.Title'), 'Garden.Title', 'Garden.Description'));
     // Set the model on the form.
     $this->Form->setModel($ConfigurationModel);
     // Get the current logo.
     $Logo = c('Garden.Logo');
     if ($Logo) {
         $Logo = ltrim($Logo, '/');
         // Fix the logo path.
         if (stringBeginsWith($Logo, 'uploads/')) {
             $Logo = substr($Logo, strlen('uploads/'));
         }
         $this->setData('Logo', $Logo);
     }
     // Get the current mobile logo.
     $MobileLogo = c('Garden.MobileLogo');
     if ($MobileLogo) {
         $MobileLogo = ltrim($MobileLogo, '/');
         // Fix the logo path.
         if (stringBeginsWith($MobileLogo, 'uploads/')) {
             $MobileLogo = substr($MobileLogo, strlen('uploads/'));
         }
         $this->setData('MobileLogo', $MobileLogo);
     }
     // Get the current favicon.
     $Favicon = c('Garden.FavIcon');
     $this->setData('Favicon', $Favicon);
     $ShareImage = c('Garden.ShareImage');
     $this->setData('ShareImage', $ShareImage);
     // If seeing the form for the first time...
     if (!$this->Form->authenticatedPostBack()) {
         // Apply the config settings to the form.
         $this->Form->setData($ConfigurationModel->Data);
     } else {
         $SaveData = array();
         if ($this->Form->save() !== false) {
             $Upload = new Gdn_Upload();
             try {
                 // Validate the upload
                 $TmpImage = $Upload->validateUpload('Logo', false);
                 if ($TmpImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images.
                     if ($Logo) {
                         $Upload->delete($Logo);
                     }
                     // Save the uploaded image
                     $Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
                     $ImageBaseName = $Parts['SaveName'];
                     $SaveData['Garden.Logo'] = $ImageBaseName;
                     $this->setData('Logo', $ImageBaseName);
                 }
                 $TmpMobileImage = $Upload->validateUpload('MobileLogo', false);
                 if ($TmpMobileImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images.
                     if ($MobileLogo) {
                         $Upload->delete($MobileLogo);
                     }
                     // Save the uploaded image
                     $Parts = $Upload->saveAs($TmpMobileImage, $ImageBaseName);
                     $ImageBaseName = $Parts['SaveName'];
                     $SaveData['Garden.MobileLogo'] = $ImageBaseName;
                     $this->setData('MobileLogo', $ImageBaseName);
                 }
                 $ImgUpload = new Gdn_UploadImage();
                 $TmpFavicon = $ImgUpload->validateUpload('Favicon', false);
                 if ($TmpFavicon) {
                     $ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
                     if ($Favicon) {
                         $Upload->delete($Favicon);
                     }
                     // Resize the to a png.
                     $Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => true));
                     $SaveData['Garden.FavIcon'] = $Parts['SaveName'];
                     $this->setData('Favicon', $Parts['SaveName']);
                 }
                 $TmpShareImage = $Upload->ValidateUpload('ShareImage', false);
                 if ($TmpShareImage) {
                     $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, false);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     if ($ShareImage) {
                         $Upload->delete($ShareImage);
                     }
                     $Parts = $Upload->SaveAs($TmpShareImage, $ImageBaseName);
                     $SaveData['Garden.ShareImage'] = $Parts['SaveName'];
                     $this->setData('ShareImage', $Parts['SaveName']);
                 }
             } catch (Exception $ex) {
                 $this->Form->addError($ex);
             }
             // If there were no errors, save the path to the logo in the config
             if ($this->Form->errorCount() == 0) {
                 saveToConfig($SaveData);
             }
             $this->informMessage(t("Your settings have been saved."));
         }
     }
     $this->render();
 }
コード例 #13
0
 function FancyZoomImage($Source, $Attributes = array())
 {
     // defaults
     if (!is_array($Attributes)) {
         $Attributes = array();
     }
     $NoHiding = GetValue('NoHiding', $Attributes, '', True);
     $bSaveImage = False;
     $Hash = Crc32Value($Source, $Attributes);
     $Filename = pathinfo($Source, PATHINFO_FILENAME);
     $Extension = pathinfo($Source, PATHINFO_EXTENSION);
     if (!array_key_exists('SmallImage', $Attributes)) {
         // make directory
         $TargetFolder = 'uploads/cached';
         // cache directory
         if (!is_dir($TargetFolder)) {
             mkdir($TargetFolder, 0777, True);
         }
         $SmallImage = GenerateCleanTargetName($TargetFolder, $Filename . '-' . $Hash, $Extension, False, True);
         $Attributes['SmallImage'] = $SmallImage;
         if (!file_exists($SmallImage)) {
             $bSaveImage = True;
         }
     }
     // get attributes
     $Width = ArrayValue('width', $Attributes, '');
     $Height = ArrayValue('height', $Attributes, '');
     $Crop = GetValue('Crop', $Attributes, False, True);
     $SmallImage = GetValue('SmallImage', $Attributes, '', True);
     $ZoomAttributes = array('id' => 'p' . $Hash);
     if (!$NoHiding) {
         $ZoomAttributes['style'] = 'display:none';
     }
     //if (!array_key_exists('alt', $Attributes)) $Attributes['alt'] = $Filename;
     TouchValue('alt', $Attributes, $Filename);
     if ($bSaveImage) {
         Gdn_UploadImage::SaveImageAs($Source, $SmallImage, $Height, $Width, $Crop);
     }
     $SmallImage = Img($SmallImage, $Attributes);
     $ZoomImage = Img($Source, array('alt' => ArrayValue('alt', $Attributes, '')));
     return "\n" . Wrap($SmallImage, 'a', array('href' => '#p' . $Hash)) . Wrap($ZoomImage, 'div', $ZoomAttributes);
 }
コード例 #14
0
ファイル: class.form.php プロジェクト: elpum/TgaForumBundle
 /**
  * Save an image from a field and delete any old image that's been uploaded.
  * 
  * @param string $Field The name of the field. The image will be uploaded with the _New extension while the current image will be just the field name.
  * @param array $Options
  */
 public function SaveImage($Field, $Options = array())
 {
     $Upload = new Gdn_UploadImage();
     $FileField = str_replace('.', '_', $Field);
     if (!GetValueR("{$FileField}_New.name", $_FILES)) {
         Trace("{$Field} not uploaded, returning.");
         return FALSE;
     }
     // First make sure the file is valid.
     try {
         $TmpName = $Upload->ValidateUpload($FileField . '_New', TRUE);
         if (!$TmpName) {
             return FALSE;
         }
         // no file uploaded.
     } catch (Exception $Ex) {
         $this->AddError($Ex);
         return FALSE;
     }
     // Get the file extension of the file.
     $Ext = GetValue('OutputType', $Options, trim($Upload->GetUploadedFileExtension(), '.'));
     if ($Ext == 'jpeg') {
         $Ext = 'jpg';
     }
     Trace($Ext, 'Ext');
     // The file is valid so let's come up with its new name.
     if (isset($Options['Name'])) {
         $Name = $Options['Name'];
     } elseif (isset($Options['Prefix'])) {
         $Name = $Options['Prefix'] . md5(microtime()) . '.' . $Ext;
     } else {
         $Name = md5(microtime()) . '.' . $Ext;
     }
     // We need to parse out the size.
     $Size = GetValue('Size', $Options);
     if ($Size) {
         if (is_numeric($Size)) {
             TouchValue('Width', $Options, $Size);
             TouchValue('Height', $Options, $Size);
         } elseif (preg_match('`(\\d+)x(\\d+)`i', $Size, $M)) {
             TouchValue('Width', $Options, $M[1]);
             TouchValue('Height', $Options, $M[2]);
         }
     }
     Trace($Options, "Saving image {$Name}.");
     try {
         $Parsed = $Upload->SaveImageAs($TmpName, $Name, GetValue('Height', $Options, ''), GetValue('Width', $Options, ''), $Options);
         Trace($Parsed, 'Saved Image');
         $Current = $this->GetFormValue($Field);
         if ($Current && GetValue('DeleteOriginal', $Options, TRUE)) {
             // Delete the current image.
             Trace("Deleting original image: {$Current}.");
             if ($Current) {
                 $Upload->Delete($Current);
             }
         }
         // Set the current value.
         $this->SetFormValue($Field, $Parsed['SaveName']);
     } catch (Exception $Ex) {
         $this->AddError($Ex);
     }
 }
コード例 #15
0
 public function UtilityController_Thumbnail_Create($Sender, $Args)
 {
     $SubPath = implode('/', $Args);
     $Path = MediaModel::PathUploads() . "/{$SubPath}";
     if (!file_exists($Path)) {
         throw NotFoundException('File');
     }
     // Figure out the dimensions of the upload.
     $ImageSize = getimagesize($Path);
     $SHeight = $ImageSize[1];
     $SWidth = $ImageSize[0];
     $Options = array();
     $ThumbHeight = MediaModel::ThumbnailHeight();
     $ThumbWidth = MediaModel::ThumbnailWidth();
     if (!$ThumbHeight || $SHeight < $ThumbHeight) {
         $Height = $SHeight;
         $Width = $SWidth;
     } else {
         $Height = $ThumbHeight;
         $Width = round($Height * $SWidth / $SHeight);
     }
     if ($ThumbWidth && $Width > $ThumbWidth) {
         $Width = $ThumbWidth;
         if (!$ThumbHeight) {
             $Height = round($Width * $SHeight / $SWidth);
         } else {
             $Options['Crop'] = TRUE;
         }
     }
     $TargetPath = MediaModel::PathUploads() . "/thumbnails/{$SubPath}";
     if (!file_exists(dirname($TargetPath))) {
         mkdir(dirname($TargetPath), 0777, TRUE);
     }
     Gdn_UploadImage::SaveImageAs($Path, $TargetPath, $Height, $Width, $Options);
     $Url = MediaModel::Url("/thumbnails/{$SubPath}");
     Redirect($Url, 302);
     //      Gdn_FileSystem::ServeFile($TargetPath, basename($Path), '', 'inline');
 }
コード例 #16
0
 /**
  * Allows plugin to handle ajax file uploads.
  *
  * @access public
  * @param object $Sender
  */
 public function PostController_Upload_Create($Sender)
 {
     if (!$this->IsEnabled()) {
         return;
     }
     list($FieldName) = $Sender->RequestArgs;
     $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
     $Sender->DeliveryType(DELIVERY_TYPE_VIEW);
     include_once $Sender->FetchViewLocation('fileupload_functions', '', 'plugins/FileUpload');
     $Sender->FieldName = $FieldName;
     $Sender->ApcKey = Gdn::Request()->GetValueFrom(Gdn_Request::INPUT_POST, 'APC_UPLOAD_PROGRESS');
     // this will hold the IDs and filenames of the items we were sent. booyahkashaa.
     $MediaResponse = array();
     $FileData = Gdn::Request()->GetValueFrom(Gdn_Request::INPUT_FILES, $FieldName, FALSE);
     try {
         if (!$this->CanUpload) {
             throw new FileUploadPluginUploadErrorException("You do not have permission to upload files", 11, '???');
         }
         if (!$Sender->Form->IsPostBack()) {
             $PostMaxSize = ini_get('post_max_size');
             throw new FileUploadPluginUploadErrorException("The post data was too big (max {$PostMaxSize})", 10, '???');
         }
         if (!$FileData) {
             //$PostMaxSize = ini_get('post_max_size');
             $MaxUploadSize = ini_get('upload_max_filesize');
             //throw new FileUploadPluginUploadErrorException("The uploaded file was too big (max {$MaxUploadSize})",10,'???');
             throw new FileUploadPluginUploadErrorException("No file data could be found in your post", 10, '???');
         }
         // Validate the file upload now.
         $FileErr = $FileData['error'];
         $FileType = $FileData['type'];
         $FileName = $FileData['name'];
         $FileTemp = $FileData['tmp_name'];
         $FileSize = $FileData['size'];
         $FileKey = $Sender->ApcKey ? $Sender->ApcKey : '';
         if ($FileErr != UPLOAD_ERR_OK) {
             $ErrorString = '';
             switch ($FileErr) {
                 case UPLOAD_ERR_INI_SIZE:
                     $MaxUploadSize = ini_get('upload_max_filesize');
                     $ErrorString = sprintf(T('The uploaded file was too big (max %s).'), $MaxUploadSize);
                     break;
                 case UPLOAD_ERR_FORM_SIZE:
                     $ErrorString = 'The uploaded file was too big';
                     break;
                 case UPLOAD_ERR_PARTIAL:
                     $ErrorString = 'The uploaded file was only partially uploaded';
                     break;
                 case UPLOAD_ERR_NO_FILE:
                     $ErrorString = 'No file was uploaded';
                     break;
                 case UPLOAD_ERR_NO_TMP_DIR:
                     $ErrorString = 'Missing a temporary folder';
                     break;
                 case UPLOAD_ERR_CANT_WRITE:
                     $ErrorString = 'Failed to write file to disk';
                     break;
                 case UPLOAD_ERR_EXTENSION:
                     $ErrorString = 'A PHP extension stopped the file upload';
                     break;
             }
             throw new FileUploadPluginUploadErrorException($ErrorString, $FileErr, $FileName, $FileKey);
         }
         // Analyze file extension
         $FileNameParts = pathinfo($FileName);
         $Extension = strtolower($FileNameParts['extension']);
         $AllowedExtensions = C('Garden.Upload.AllowedFileExtensions', array("*"));
         if (!in_array($Extension, $AllowedExtensions) && !in_array('*', $AllowedExtensions)) {
             throw new FileUploadPluginUploadErrorException("Uploaded file type is not allowed.", 11, $FileName, $FileKey);
         }
         // Check upload size
         $MaxUploadSize = Gdn_Upload::UnformatFileSize(C('Garden.Upload.MaxFileSize', '1G'));
         if ($FileSize > $MaxUploadSize) {
             $Message = sprintf(T('The uploaded file was too big (max %s).'), Gdn_Upload::FormatFileSize($MaxUploadSize));
             throw new FileUploadPluginUploadErrorException($Message, 11, $FileName, $FileKey);
         }
         // Build filename
         $SaveFilename = md5(microtime()) . '.' . strtolower($Extension);
         $SaveFilename = '/FileUpload/' . substr($SaveFilename, 0, 2) . '/' . substr($SaveFilename, 2);
         // Get the image size before doing anything.
         list($ImageWidth, $ImageHeight, $ImageType) = Gdn_UploadImage::ImageSize($FileTemp, $FileName);
         // Fire event for hooking save location
         $this->EventArguments['Path'] = $FileTemp;
         $Parsed = Gdn_Upload::Parse($SaveFilename);
         $this->EventArguments['Parsed'] =& $Parsed;
         $this->EventArguments['OriginalFilename'] = $FileName;
         $Handled = FALSE;
         $this->EventArguments['Handled'] =& $Handled;
         $this->EventArguments['ImageType'] = $ImageType;
         $this->FireAs('Gdn_Upload')->FireEvent('SaveAs');
         $SavePath = $Parsed['Name'];
         if (!$Handled) {
             // Build save location
             $SavePath = MediaModel::PathUploads() . $SaveFilename;
             if (!is_dir(dirname($SavePath))) {
                 @mkdir(dirname($SavePath), 0777, TRUE);
             }
             if (!is_dir(dirname($SavePath))) {
                 throw new FileUploadPluginUploadErrorException("Internal error, could not save the file.", 9, $FileName);
             }
             // Move to permanent location
             // Use SaveImageAs so that image is rotated if necessary
             if ($ImageType !== FALSE) {
                 try {
                     $ImgParsed = Gdn_UploadImage::SaveImageAs($FileTemp, $SavePath);
                     $MoveSuccess = TRUE;
                     // In case image got rotated
                     $ImageWidth = $ImgParsed['Width'];
                     $ImageHeight = $ImgParsed['Height'];
                 } catch (Exception $Ex) {
                     // In case it was an image, but not a supported type - still upload
                     $MoveSuccess = @move_uploaded_file($FileTemp, $SavePath);
                 }
             } else {
                 // If not an image, just upload it
                 $MoveSuccess = @move_uploaded_file($FileTemp, $SavePath);
             }
             if (!$MoveSuccess) {
                 throw new FileUploadPluginUploadErrorException("Internal error, could not move the file.", 9, $FileName);
             }
         } else {
             $SaveFilename = $Parsed['SaveName'];
         }
         // Save Media data
         $Media = array('Name' => $FileName, 'Type' => $FileType, 'Size' => $FileSize, 'ImageWidth' => $ImageWidth, 'ImageHeight' => $ImageHeight, 'InsertUserID' => Gdn::Session()->UserID, 'DateInserted' => date('Y-m-d H:i:s'), 'StorageMethod' => 'local', 'Path' => $SaveFilename);
         $MediaID = $this->MediaModel()->Save($Media);
         $Media['MediaID'] = $MediaID;
         $FinalImageLocation = '';
         $PreviewImageLocation = MediaModel::ThumbnailUrl($Media);
         //
         $MediaResponse = array('Status' => 'success', 'MediaID' => $MediaID, 'Filename' => $FileName, 'Filesize' => $FileSize, 'FormatFilesize' => Gdn_Format::Bytes($FileSize, 1), 'ProgressKey' => $Sender->ApcKey ? $Sender->ApcKey : '', 'Thumbnail' => base64_encode(MediaThumbnail($Media)), 'FinalImageLocation' => Url(MediaModel::Url($Media)), 'Parsed' => $Parsed);
     } catch (FileUploadPluginUploadErrorException $e) {
         $MediaResponse = array('Status' => 'failed', 'ErrorCode' => $e->getCode(), 'Filename' => $e->getFilename(), 'StrError' => $e->getMessage());
         if (!is_null($e->getApcKey())) {
             $MediaResponse['ProgressKey'] = $e->getApcKey();
         }
         if ($e->getFilename() != '???') {
             $MediaResponse['StrError'] = '(' . $e->getFilename() . ') ' . $MediaResponse['StrError'];
         }
     } catch (Exception $Ex) {
         $MediaResponse = array('Status' => 'failed', 'ErrorCode' => $Ex->getCode(), 'StrError' => $Ex->getMessage());
     }
     $Sender->SetJSON('MediaResponse', $MediaResponse);
     // Kludge: This needs to have a content type of text/* because it's in an iframe.
     ob_clean();
     header('Content-Type: text/html');
     echo json_encode($Sender->GetJson());
     die;
     $Sender->Render($this->GetView('blank.php'));
 }