ImageAction.class.php (1878B)
1 <?php 2 3 namespace cms\action; 4 5 use cms\model\Image; 6 use util\Html; 7 8 9 /** 10 * Action-Klasse zum Bearbeiten eines Bildes. 11 * @author Jan Dankert 12 * @version $Revision$ 13 * @package openrat.actions 14 */ 15 class ImageAction extends FileAction 16 { 17 /** 18 * @var Image 19 */ 20 protected $image; 21 22 /** 23 * Konstruktor 24 */ 25 public function __construct() 26 { 27 parent::__construct(); 28 29 } 30 31 32 public function init() 33 { 34 $image = new Image( $this->request->getId() ); 35 $image->load(); 36 37 $this->setBaseObject( $image ); 38 39 } 40 41 42 protected function setBaseObject( $image ) { 43 $this->image = $image; 44 45 parent::setBaseObject($image); 46 } 47 48 49 50 protected function imageFormat() 51 { 52 if ( ! function_exists( 'imagetypes' ) ) 53 return 0; 54 55 $ext = strtolower($this->image->getRealExtension()); 56 $types = imagetypes(); 57 $formats = array( 'gif' =>IMG_GIF, 58 'jpg' =>IMG_JPG, 59 'jpeg'=>IMG_JPG, 60 'png' =>IMG_PNG ); 61 62 if ( !isset($formats[$ext]) ) 63 return 0; 64 65 if ( $types & $formats[$ext] ) 66 return $formats[$ext]; 67 68 return 0; 69 } 70 71 72 73 protected function imageExt() 74 { 75 switch( $this->imageFormat() ) 76 { 77 case IMG_GIF: 78 return 'GIF'; 79 case IMG_JPG: 80 return 'JPEG'; 81 case IMG_PNG: 82 return 'PNG'; 83 } 84 } 85 86 87 88 protected function imageFormats() 89 { 90 if ( ! function_exists( 'imagetypes' ) ) 91 return array(); 92 93 $types = imagetypes(); 94 $formats = array( IMG_GIF => 'gif', 95 IMG_JPG => 'jpeg', 96 IMG_PNG => 'png' ); 97 $formats2 = $formats; 98 99 foreach( $formats as $b=>$f ) 100 if ( !($types & $b) ) 101 unset( $formats2[$b] ); 102 103 return $formats2; 104 } 105 106 107 108 }