Changeset 12775 for extensions/derivatives/include/derivative.inc.php
- Timestamp:
- Dec 21, 2011, 2:51:44 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/derivatives/include/derivative.inc.php
r12770 r12775 4 4 { 5 5 public $rel_path; 6 6 7 public $coi=null; 7 8 private $size=null; 8 9 9 10 function __construct($infos) 10 11 { … … 27 28 $this->rel_path = get_themeconf('mime_icon_dir').strtolower($ext).'.png'; 28 29 } 29 30 30 31 $this->coi = @$infos['coi']; 31 32 if (isset($infos['width']) && isset($infos['height'])) … … 34 35 } 35 36 } 36 37 38 function has_size() 39 { 40 return $this->size != null; 41 } 42 37 43 function get_size() 38 44 { … … 43 49 } 44 50 51 52 45 53 final class DerivativeImage 46 54 { 55 const SAME_AS_SRC = 0x10; 56 47 57 public $src_image; 58 59 private $requested_type; 60 61 private $flags = 0; 48 62 private $params; 49 63 private $rel_path, $rel_url; 50 51 function __construct($type, $infos) 52 { 53 $this->src_image = new SrcImage($infos); 54 self::build($type, $src_image, $this->rel_path, $this->rel_url, $this->params); 55 } 56 64 65 function __construct($type, $src_image) 66 { 67 $this->src_image = $src_image; 68 if (is_string($type)) 69 { 70 $this->requested_type = $type; 71 $this->params = ImageStdParams::get_by_type($type); 72 } 73 else 74 { 75 $this->requested_type = IMG_CUSTOM; 76 $this->params = $type; 77 } 78 79 self::build($src_image, $this->params, $this->rel_path, $this->rel_url, $this->flags); 80 } 81 57 82 static function thumb_url($infos) 58 83 { 59 84 $src_image = new SrcImage($infos); 60 self::build(IMG_THUMB, $src_image, $rel_path, $rel_url); 61 //die($rel_url); 85 self::build($src_image, ImageStdParams::get_by_type(IMG_THUMB), $rel_path, $rel_url); 62 86 return get_root_url().$rel_url; 63 87 } … … 66 90 { 67 91 $src_image = new SrcImage($infos); 68 self::build($type, $src_image, $rel_path, $rel_url); 92 $params = is_string($type) ? ImageStdParams::get_by_type($type) : $type; 93 self::build($src_image, $params, $rel_path, $rel_url); 69 94 return get_root_url().$rel_url; 70 95 } 71 72 private static function build($type, $src, &$rel_path, &$rel_url, &$params = null) 73 { 74 if (is_string($type)) 75 { 76 $params = ImageStdParams::get_by_type($type); 77 } 78 else 79 { 80 $type = IMG_CUSTOM; 96 97 static function get_all($infos) 98 { 99 $src_image = new SrcImage($infos); 100 $ret = array(); 101 foreach (ImageStdParams::get_defined_type_map() as $type => $params) 102 { 103 $derivative = new DerivativeImage($params, $src_image); 104 $ret[$type] = $derivative; 105 } 106 foreach (ImageStdParams::get_undefined_type_map() as $type => $type2) 107 { 108 $ret[$type] = $ret[$type2]; 81 109 } 82 110 83 // todo check if we should not downgrade to a different type because 84 // original file is too small ... 85 // we are using a mime type icon ... 86 // etc... 87 111 return $ret; 112 } 113 114 private static function build($src, &$params, &$rel_path, &$rel_url, &$flags = null) 115 { 116 if ( $src->has_size() && $params->is_identity( $src->get_size() ) ) 117 { 118 // todo - what if we have a watermark maybe return a smaller size? 119 $flags |= self::SAME_AS_SRC; 120 $params = null; 121 $rel_path = $rel_url = $src->rel_path; 122 return; 123 } 124 88 125 $tokens=array(); 89 $tokens[] = substr($ type,0,2);90 126 $tokens[] = substr($params->type,0,2); 127 91 128 if (!empty($src->coi)) 92 129 { 93 130 $tokens[] = 'ci'.$src->coi; 94 131 } 95 96 if ($ type==IMG_CUSTOM)132 133 if ($params->type==IMG_CUSTOM) 97 134 { 98 135 $params->add_url_tokens($tokens); 99 136 } 100 137 101 138 $loc = $src->rel_path; 102 139 if (substr_compare($loc, '../', 0, 3)==0) … … 107 144 108 145 $rel_path = PWG_DERIVATIVE_DIR.$loc; 109 146 110 147 global $conf; 111 148 $url_style=$conf['derivative_url_style']; … … 122 159 } 123 160 } 124 161 125 162 if ($url_style == 2) 126 163 { … … 136 173 } 137 174 175 function get_url() 176 { 177 return get_root_url().$this->rel_url; 178 } 179 180 function same_as_source() 181 { 182 return $this->flags & self::SAME_AS_SRC; 183 } 184 185 138 186 /* returns the size of the derivative image*/ 139 187 function get_size() 140 188 { 189 if ($this->flags & self::SAME_AS_SRC) 190 { 191 return $this->src_image->get_size(); 192 } 141 193 return $this->params->compute_final_size($this->src_image->get_size(), $this->src_image->coi); 142 194 } 195 196 function get_size_htm() 197 { 198 $size = $this->get_size(); 199 if ($size) 200 { 201 return 'width="'.$size[0].'" height="'.$size[1].'"'; 202 } 203 } 204 205 function get_size_hr() 206 { 207 $size = $this->get_size(); 208 if ($size) 209 { 210 return $size[0].' x '.$size[1]; 211 } 212 } 213 143 214 } 144 215
Note: See TracChangeset
for help on using the changeset viewer.