File modules/cms/action/image/ImageSizeAction.class.php
Last commit: Wed Mar 9 13:28:52 2022 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()'
1 <?php 2 namespace cms\action\image; 3 use cms\action\Action; 4 use cms\action\ImageAction; 5 use cms\action\Method; 6 use cms\model\Image; 7 use cms\model\Name; 8 use cms\model\Permission; 9 use language\Messages; 10 use util\exception\ValidationException; 11 12 class ImageSizeAction extends ImageAction implements Method { 13 public function getRequiredPermission() { 14 return Permission::ACL_WRITE; 15 } 16 17 public function view() { 18 $this->setTemplateVars( $this->image->getProperties() ); 19 20 $format = $this->imageFormat(); 21 22 if ( $format == 0 ) 23 { 24 $this->addWarningFor( $this->image,Messages::IMAGE_RESIZING_UNKNOWN_TYPE); 25 } 26 27 $formats = $this->imageFormats(); 28 29 if ( empty($formats) ) 30 $this->addWarningFor($this->image,Messages::IMAGE_RESIZING_NOT_AVAILABLE); 31 32 $sizes = array(); 33 foreach( array(10,25,50,75,100,125,150,175,200,250,300,350,400,500,600,800) as $s ) 34 $sizes[strval($s/100)] = $s.'%'; 35 36 $jpeglist = array(); 37 for ($i=10; $i<=95; $i+=5) 38 $jpeglist[$i]=$i.'%'; 39 40 $this->setTemplateVar('factors' ,$sizes ); 41 $this->setTemplateVar('jpeglist' ,$jpeglist ); 42 $this->setTemplateVar('formats' ,$formats ); 43 $this->setTemplateVar('format' ,$format ); 44 $this->setTemplateVar('factor' ,1 ); 45 46 $this->image->getImageSize(); 47 $this->setTemplateVar('width' ,$this->image->width ); 48 $this->setTemplateVar('height',$this->image->height ); 49 $this->setTemplateVar('type' ,'input' ); 50 } 51 52 53 public function post() { 54 $width = $this->request->getNumber('width' ); 55 $height = $this->request->getNumber('height' ); 56 $jpegcompression = $this->request->getText('jpeg_compression'); 57 $format = $this->request->getText('format' ); 58 $factor = $this->request->getText('factor' ); 59 60 if ( $this->request->getText('type') == 'input' && 61 ! $width && 62 ! $height ) 63 { 64 $this->addWarningFor(null,Messages::INPUT_NEW_IMAGE_SIZE); 65 throw new ValidationException('width' ); 66 } 67 68 if ( $this->request->isTrue('copy') ) 69 { 70 // Datei neu anlegen. 71 $imageFile = new Image(); 72 73 $imageFile->filename = $imageFile->filename.'_resized_'.time(); 74 $imageFile->persist(); 75 $imageFile->copyNamesFrom( $this->image->objectid ); 76 $imageFile->copyValueFromFile( $this->image->objectid ); 77 } 78 else 79 { 80 $imageFile = $this->image; 81 } 82 83 if ( $this->request->getText('type') == 'factor') 84 { 85 $width = 0; 86 $height = 0; 87 } 88 else 89 { 90 $factor = 1; 91 } 92 93 $imageFile->write(); 94 95 $imageFile->imageResize( intval($width),intval($height),$factor,$this->imageFormat(),$format,$jpegcompression ); 96 $imageFile->setTimestamp(); 97 $imageFile->save(); // Um z.B. Groesse abzuspeichern 98 $imageFile->saveValue(); 99 100 $this->addNoticeFor($imageFile,Messages::IMAGE_RESIZED); 101 } 102 }
Downloadmodules/cms/action/image/ImageSizeAction.class.php
History Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Sun, 14 Mar 2021 23:51:49 +0100 Jan Dankert Refactoring: Using the ValidationException where possible. Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Thu, 19 Nov 2020 14:49:58 +0100 Jan Dankert Fix: Action::addNotice() is replaced by Action::addNoticeFor() Thu, 19 Nov 2020 12:36:44 +0100 Jan Dankert Fix: nextSubAction() is depracated and should not be used. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.