[1] | 1 | <?php |
---|
| 2 | /** |
---|
[42] | 3 | * ImageThumb.inc.php |
---|
[136] | 4 | * code by strangecode :: www.strangecode.com :: this document contains copyrighted information |
---|
[1] | 5 | * |
---|
| 6 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
[119] | 7 | * @requires Netpbm <http://sourceforge.net/projects/netpbm/> and libjpeg or GD. |
---|
| 8 | * @version 2.0 |
---|
[1] | 9 | */ |
---|
| 10 | |
---|
[152] | 11 | // Image proprtion options. |
---|
[1] | 12 | define('IMAGETHUMB_FIT_WIDTH', 1); |
---|
| 13 | define('IMAGETHUMB_FIT_HEIGHT', 2); |
---|
| 14 | define('IMAGETHUMB_FIT_LARGER', 3); |
---|
| 15 | define('IMAGETHUMB_STRETCH', 4); |
---|
| 16 | define('IMAGETHUMB_NO_SCALE', 5); |
---|
[152] | 17 | |
---|
| 18 | // Image resize options. |
---|
[119] | 19 | define('IMAGETHUMB_METHOD_NETPBM', 6); |
---|
| 20 | define('IMAGETHUMB_METHOD_GD', 7); |
---|
[1] | 21 | |
---|
| 22 | class ImageThumb { |
---|
[119] | 23 | |
---|
| 24 | // General object parameters. |
---|
| 25 | var $_params = array( |
---|
| 26 | // The location for images to create thumbnails from. |
---|
| 27 | 'source_dir' => null, |
---|
[42] | 28 | |
---|
[119] | 29 | // Existing files will be overwritten when there is a name conflict? |
---|
| 30 | 'allow_overwriting' => false, |
---|
[42] | 31 | |
---|
[119] | 32 | // The file permissions of the uploaded files. Remember, files will be owned by the web server user. |
---|
| 33 | 'dest_file_perms' => 0600, |
---|
[42] | 34 | |
---|
[119] | 35 | // Permissions of autocreated directories. Must be at least 0700 with owner=apache. |
---|
[152] | 36 | 'dest_dir_perms' => 0700, |
---|
[42] | 37 | |
---|
[119] | 38 | // Require file to have one of the following file name extentions. |
---|
| 39 | 'valid_file_extensions' => array('jpg', 'jpeg', 'gif', 'png'), |
---|
| 40 | |
---|
| 41 | // Method to use for resizing. (IMAGETHUMB_METHOD_NETPBM or IMAGETHUMB_METHOD_GD) |
---|
| 42 | 'resize_method' => IMAGETHUMB_METHOD_NETPBM, |
---|
[1] | 43 | |
---|
[119] | 44 | // Netpbm and libjpeg binary locations. |
---|
| 45 | 'anytopnm_binary' => '/usr/bin/anytopnm', |
---|
| 46 | 'pnmscale_binary' => '/usr/bin/pnmscale', |
---|
| 47 | 'cjpeg_binary' => '/usr/bin/cjpeg', |
---|
[42] | 48 | |
---|
[119] | 49 | // Which messages do we pass to raiseMsg? Use one of the MSG_* constants or false to disable. |
---|
| 50 | 'display_messages' => MSG_ALL, |
---|
| 51 | ); |
---|
| 52 | |
---|
| 53 | // Default image size specs. |
---|
[152] | 54 | var $_default_image_specs = array( |
---|
| 55 | // The destination for an image thumbnail size. |
---|
| 56 | // Use initial / to specify absolute paths, leave off to specify a path relative to source_dir (eg: ../thumbs). |
---|
[119] | 57 | 'dest_dir' => null, |
---|
[120] | 58 | |
---|
| 59 | // Destination file types. (IMG_JPG, IMG_PNG, IMG_GIF, IMG_WBMP) |
---|
| 60 | 'dest_file_type' => IMG_JPG, |
---|
| 61 | |
---|
| 62 | // Destination file types. ('jpg', 'png', 'gif', 'wbmp') |
---|
| 63 | 'dest_file_extention' => 'jpg', |
---|
| 64 | |
---|
[119] | 65 | // Type of scaling to perform, and sizes used to calculate max dimentions. |
---|
| 66 | 'scaling_type' => IMAGETHUMB_FIT_LARGER, |
---|
| 67 | 'width' => null, |
---|
| 68 | 'height' => null, |
---|
[120] | 69 | |
---|
[119] | 70 | // Percentage quality of image compression output 0-100. |
---|
| 71 | 'quality' => 65, |
---|
[120] | 72 | |
---|
[119] | 73 | // Create progressive jpegs? |
---|
| 74 | 'progressive' => false, |
---|
[120] | 75 | |
---|
| 76 | // If using GD method, apply sharpen filter. Requires PHP > 5.1. |
---|
| 77 | 'sharpen' => true, |
---|
| 78 | |
---|
| 79 | // Integers between 1-100, useful values are 65-85. |
---|
| 80 | 'sharpen_value' => 75, |
---|
| 81 | |
---|
[119] | 82 | // If source image is smaller than thumbnail, allow upscaling? |
---|
| 83 | 'allow_upscaling' => false, |
---|
[120] | 84 | |
---|
[119] | 85 | // If thumb exists and filesize is smaller than this, do not overwrite the thumb. |
---|
| 86 | 'keep_filesize' => null, |
---|
| 87 | ); |
---|
[1] | 88 | |
---|
[119] | 89 | // Final specifications for image sizes, set with setSpec(). |
---|
[152] | 90 | var $_image_specs = array(); |
---|
[119] | 91 | |
---|
[1] | 92 | /** |
---|
[119] | 93 | * Set (or overwrite existing) parameters by passing an array of new parameters. |
---|
[1] | 94 | * |
---|
[119] | 95 | * @access public |
---|
| 96 | * @param array $params Array of parameters (key => val pairs). |
---|
[1] | 97 | */ |
---|
[119] | 98 | function setParam($params) |
---|
[1] | 99 | { |
---|
[136] | 100 | $app =& App::getInstance(); |
---|
| 101 | |
---|
[119] | 102 | if (isset($params) && is_array($params)) { |
---|
| 103 | |
---|
[152] | 104 | // Enforce valid source_dir parameter. |
---|
[119] | 105 | if (isset($params['source_dir'])) { |
---|
| 106 | $params['source_dir'] = realpath($params['source_dir']); |
---|
[152] | 107 | // Source must be directory. |
---|
[119] | 108 | if (!is_dir($params['source_dir'])) { |
---|
[152] | 109 | $app->logMsg(sprintf('Attempting to auto-create source directory: %s', $params['source_dir']), LOG_NOTICE, __FILE__, __LINE__); |
---|
| 110 | if (phpversion() > '5') { |
---|
| 111 | // Recursive. |
---|
| 112 | mkdir($params['source_dir'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'), true); |
---|
| 113 | } else { |
---|
| 114 | mkdir($params['source_dir'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms')); |
---|
| 115 | } |
---|
| 116 | if (!is_dir($params['source_dir'])) { |
---|
| 117 | $app->logMsg(sprintf('Source directory invalid: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__); |
---|
| 118 | trigger_error(sprintf('Source directory invalid: %s', $params['source_dir']), E_USER_ERROR); |
---|
| 119 | } |
---|
[119] | 120 | } |
---|
[152] | 121 | // Source must be readable. |
---|
[119] | 122 | if (!is_readable($params['source_dir'])) { |
---|
[136] | 123 | $app->logMsg(sprintf('Source directory not readable: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__); |
---|
[119] | 124 | trigger_error(sprintf('Source directory not readable: %s', $params['source_dir']), E_USER_ERROR); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | // Merge new parameters with old overriding only those passed. |
---|
| 129 | $this->_params = array_merge($this->_params, $params); |
---|
| 130 | } else { |
---|
[136] | 131 | $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /** |
---|
[119] | 136 | * Return the value of a parameter, if it exists. |
---|
[1] | 137 | * |
---|
[119] | 138 | * @access public |
---|
| 139 | * @param string $param Which parameter to return. |
---|
| 140 | * @return mixed Configured parameter value. |
---|
[1] | 141 | */ |
---|
[119] | 142 | function getParam($param) |
---|
[1] | 143 | { |
---|
[136] | 144 | $app =& App::getInstance(); |
---|
| 145 | |
---|
[119] | 146 | if (isset($this->_params[$param])) { |
---|
| 147 | return $this->_params[$param]; |
---|
| 148 | } else { |
---|
[146] | 149 | $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); |
---|
[119] | 150 | return null; |
---|
[1] | 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /** |
---|
| 155 | * Set the specification of thumbnails. |
---|
| 156 | * |
---|
| 157 | * @access public |
---|
[119] | 158 | * @param array $spec The specifications for a size of output image. |
---|
[1] | 159 | */ |
---|
[120] | 160 | function setSpec($spec, $index=null) |
---|
[1] | 161 | { |
---|
[136] | 162 | $app =& App::getInstance(); |
---|
| 163 | |
---|
[119] | 164 | // A little sanity checking. |
---|
[152] | 165 | if (!isset($spec['dest_dir']) || '' == trim($spec['dest_dir'])) { |
---|
[136] | 166 | $app->logMsg('setSpec error: dest_dir not specified.', LOG_ERR, __FILE__, __LINE__); |
---|
[152] | 167 | } else { |
---|
| 168 | $spec['dest_dir'] = trim($spec['dest_dir']); |
---|
[1] | 169 | } |
---|
[120] | 170 | if (isset($spec['dest_file_type'])) { |
---|
| 171 | switch ($spec['dest_file_type']) { |
---|
| 172 | case IMG_JPG : |
---|
| 173 | if (imagetypes() & IMG_JPG == 0) { |
---|
[136] | 174 | $app->logMsg(sprintf('IMG_JPG is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__); |
---|
[120] | 175 | } |
---|
| 176 | $spec['dest_file_extention'] = 'jpg'; |
---|
| 177 | break; |
---|
| 178 | case IMG_PNG : |
---|
| 179 | if (imagetypes() & IMG_PNG == 0) { |
---|
[136] | 180 | $app->logMsg(sprintf('IMG_PNG is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__); |
---|
[120] | 181 | } |
---|
| 182 | $spec['dest_file_extention'] = 'png'; |
---|
| 183 | break; |
---|
| 184 | case IMG_GIF : |
---|
| 185 | if (imagetypes() & IMG_GIF == 0) { |
---|
[136] | 186 | $app->logMsg(sprintf('IMG_GIF is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__); |
---|
[120] | 187 | } |
---|
| 188 | $spec['dest_file_extention'] = 'gif'; |
---|
| 189 | break; |
---|
| 190 | case IMG_WBMP : |
---|
| 191 | if (imagetypes() & IMG_WBMP == 0) { |
---|
[136] | 192 | $app->logMsg(sprintf('IMG_WBMP is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__); |
---|
[120] | 193 | } |
---|
| 194 | $spec['dest_file_extention'] = 'wbmp'; |
---|
| 195 | break; |
---|
| 196 | default : |
---|
[136] | 197 | $app->logMsg(sprintf('Invalid dest_file_type: %s', $spec['dest_file_type']), LOG_ERR, __FILE__, __LINE__); |
---|
[120] | 198 | break; |
---|
| 199 | } |
---|
| 200 | } |
---|
[119] | 201 | if (!isset($spec['width']) || !is_int($spec['width'])) { |
---|
[136] | 202 | $app->logMsg('setSpec error: width not specified.', LOG_ERR, __FILE__, __LINE__); |
---|
[119] | 203 | } |
---|
| 204 | if (!isset($spec['height']) || !is_int($spec['height'])) { |
---|
[136] | 205 | $app->logMsg('setSpec error: height not specified.', LOG_ERR, __FILE__, __LINE__); |
---|
[119] | 206 | } |
---|
[120] | 207 | if (isset($spec['quality']) && IMG_JPG != $spec['dest_file_type']) { |
---|
[136] | 208 | $app->logMsg('The "quality" specification is not used unless IMG_JPG is the dest_file_type.', LOG_INFO, __FILE__, __LINE__); |
---|
[119] | 209 | } |
---|
[120] | 210 | if (isset($spec['progressive']) && IMG_JPG != $spec['dest_file_type']) { |
---|
[136] | 211 | $app->logMsg('The "progressive" specification is not used unless IMG_JPG is the dest_file_type.', LOG_INFO, __FILE__, __LINE__); |
---|
[119] | 212 | } |
---|
[120] | 213 | |
---|
[152] | 214 | // Add to _image_specs array. |
---|
| 215 | if (isset($index) && isset($this->_image_specs[$index])) { |
---|
| 216 | // Merge with existing spec if index is provided. |
---|
| 217 | $final_spec = array_merge($this->_image_specs[$index], $spec); |
---|
| 218 | $this->_image_specs[$index] = $final_spec; |
---|
[120] | 219 | } else { |
---|
[152] | 220 | // Merge with spec defaults. |
---|
| 221 | $final_spec = array_merge($this->_default_image_specs, $spec); |
---|
| 222 | $this->_image_specs[] = $final_spec; |
---|
[120] | 223 | } |
---|
[121] | 224 | |
---|
| 225 | return $final_spec; |
---|
[1] | 226 | } |
---|
| 227 | |
---|
| 228 | /** |
---|
[119] | 229 | * Process an entire directory of images. |
---|
[1] | 230 | * |
---|
| 231 | * @access public |
---|
| 232 | * @return bool true on success, false on failure. |
---|
| 233 | */ |
---|
[121] | 234 | function processAll($runtime_specs=null) |
---|
[1] | 235 | { |
---|
[136] | 236 | $app =& App::getInstance(); |
---|
| 237 | |
---|
[1] | 238 | // Ensure we have a source. |
---|
[119] | 239 | if ('' == $this->getParam('source_dir')) { |
---|
[136] | 240 | $app->logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 241 | return false; |
---|
| 242 | } |
---|
[119] | 243 | |
---|
| 244 | // Get all files in source directory. |
---|
| 245 | $dir_handle = opendir($this->getParam('source_dir')); |
---|
| 246 | while ($dir_handle && ($file = readdir($dir_handle)) !== false) { |
---|
| 247 | // If the file name does not start with a dot (. or .. or .htaccess). |
---|
| 248 | if (!preg_match('/^\./', $file) && in_array(strtolower(substr($file, strrpos($file, '.') + 1)), $this->getParam('valid_file_extensions'))) { |
---|
| 249 | $files[] = $file; |
---|
[1] | 250 | } |
---|
| 251 | } |
---|
[42] | 252 | |
---|
[119] | 253 | // Process each found file. |
---|
| 254 | if (is_array($files) && !empty($files)) { |
---|
| 255 | $return_val = 0; |
---|
| 256 | foreach ($files as $file_name) { |
---|
[121] | 257 | $return_val += $this->processFile($file_name, $runtime_specs); |
---|
[119] | 258 | } |
---|
[120] | 259 | $this->_raiseMsg(sprintf(_("Resized %s images."), sizeof($files)), MSG_SUCCESS, __FILE__, __LINE__); |
---|
[119] | 260 | return 0 === $return_val; |
---|
| 261 | } else { |
---|
[152] | 262 | $app->logMsg(sprintf('No source images found in directory: %s', $this->getParam('source_dir')), LOG_NOTICE, __FILE__, __LINE__); |
---|
[119] | 263 | return false; |
---|
| 264 | } |
---|
[1] | 265 | } |
---|
| 266 | |
---|
| 267 | /** |
---|
| 268 | * Generate thumbnails for the specified file. |
---|
| 269 | * |
---|
| 270 | * @access public |
---|
| 271 | * @param string $file_name Name of file with extention. |
---|
[121] | 272 | * @param array $runtime_specs Array of specifications that will override all configured specifications. |
---|
[1] | 273 | * @return bool true on success, false on failure. |
---|
| 274 | */ |
---|
[121] | 275 | function processFile($file_name, $runtime_specs=null) |
---|
[1] | 276 | { |
---|
[136] | 277 | $app =& App::getInstance(); |
---|
| 278 | |
---|
[119] | 279 | // Source file determinted by provided file_name. |
---|
| 280 | $source_file = realpath(sprintf('%s/%s', $this->getParam('source_dir'), $file_name)); |
---|
| 281 | |
---|
| 282 | // Ensure we have a source. |
---|
[152] | 283 | if (sizeof($this->_image_specs) < 1) { |
---|
[121] | 284 | if (is_array($runtime_specs)) { |
---|
| 285 | $this->setSpec($runtime_specs, 0); |
---|
| 286 | } else { |
---|
[136] | 287 | $app->logMsg(sprintf('Image specifications not set before processing.'), LOG_ERR, __FILE__, __LINE__); |
---|
[121] | 288 | return false; |
---|
| 289 | } |
---|
[1] | 290 | } |
---|
[42] | 291 | |
---|
[1] | 292 | // Ensure we have a source. |
---|
[119] | 293 | if ('' == $this->getParam('source_dir')) { |
---|
[136] | 294 | $app->logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 295 | return false; |
---|
| 296 | } |
---|
[42] | 297 | |
---|
[1] | 298 | // Confirm source image exists. |
---|
[119] | 299 | if (!file_exists($source_file)) { |
---|
[120] | 300 | $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s was not found."), $file_name), MSG_ERR, __FILE__, __LINE__); |
---|
[152] | 301 | $app->logMsg(sprintf('Source image not found: %s', $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 302 | return false; |
---|
| 303 | } |
---|
[42] | 304 | |
---|
[1] | 305 | // Confirm source image is readable. |
---|
[119] | 306 | if (!is_readable($source_file)) { |
---|
[120] | 307 | $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s is not readable."), $file_name), MSG_ERR, __FILE__, __LINE__); |
---|
[152] | 308 | $app->logMsg(sprintf('Source image not readable: %s', $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 309 | return false; |
---|
| 310 | } |
---|
[42] | 311 | |
---|
[1] | 312 | // Confirm source image contains data. |
---|
[119] | 313 | if (filesize($source_file) <= 0) { |
---|
[120] | 314 | $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s is zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__); |
---|
[152] | 315 | $app->logMsg(sprintf('Source image is zero bytes: %s', $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 316 | return false; |
---|
| 317 | } |
---|
[42] | 318 | |
---|
[1] | 319 | // Confirm source image has a valid file extension. |
---|
[119] | 320 | if (!$this->_validFileExtension($file_name)) { |
---|
[120] | 321 | $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s not a valid type. It must have one of the following file name extensions: %s"), $file_name, join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__); |
---|
[154] | 322 | $app->logMsg(sprintf('Image resizing failed: source image not of valid type: %s', $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 323 | return false; |
---|
| 324 | } |
---|
[42] | 325 | |
---|
[119] | 326 | // Ensure destination directories are created. This will only be called once per page load. |
---|
[152] | 327 | if (!$this->_createDestDirs()) { |
---|
| 328 | return false; |
---|
| 329 | } |
---|
[119] | 330 | |
---|
| 331 | // To keep this script running even if user tries to stop browser. |
---|
| 332 | ignore_user_abort(true); |
---|
[121] | 333 | ini_set('max_execution_time', 300); |
---|
| 334 | ini_set('max_input_time', 300); |
---|
[1] | 335 | |
---|
| 336 | // This remains zero until something goes wrong. |
---|
[119] | 337 | $return_val = 0; |
---|
[42] | 338 | |
---|
[152] | 339 | foreach ($this->_image_specs as $index => $spec) { |
---|
[119] | 340 | |
---|
[121] | 341 | if (is_array($runtime_specs)) { |
---|
| 342 | // Override with runtime specs. |
---|
| 343 | $spec = $this->setSpec($runtime_specs, $index); |
---|
| 344 | } |
---|
| 345 | |
---|
[119] | 346 | // Destination filename uses the extention defined by dest_file_extention. |
---|
[152] | 347 | if ('/' == $spec['dest_dir']{0}) { |
---|
| 348 | // Absolute path. |
---|
| 349 | $dest_file = sprintf('%s/%s.%s', $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']); |
---|
| 350 | } else { |
---|
| 351 | // Relative path. |
---|
| 352 | $dest_file = sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']); |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | // Ensure destination directory exists and is writable. |
---|
| 356 | if (!is_dir(dirname($dest_file)) || !is_writable(dirname($dest_file))) { |
---|
| 357 | $this->_createDestDirs($dest_file); |
---|
| 358 | if (!is_dir(dirname($dest_file)) || !is_writable(dirname($dest_file))) { |
---|
| 359 | $app->logMsg(sprintf('Image resizing failed, dest_dir invalid: %s', dirname($dest_file)), LOG_ERR, __FILE__, __LINE__); |
---|
| 360 | $return_val++; |
---|
| 361 | continue; |
---|
| 362 | } |
---|
| 363 | } |
---|
[42] | 364 | |
---|
[119] | 365 | // Skip existing thumbnails with file size below $spec['keep_filesize']. |
---|
| 366 | if (isset($spec['keep_filesize']) && file_exists($dest_file)) { |
---|
| 367 | $file_size = filesize($dest_file); |
---|
| 368 | if (false !== $file_size && $file_size < $spec['keep_filesize']) { |
---|
[136] | 369 | $app->logMsg(sprintf('Skipping thumbnail %s. File already exists and file size is less than %s bytes.', $spec['dest_dir'] . '/' . $file_name, $spec['keep_filesize']), LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 370 | continue; |
---|
| 371 | } |
---|
| 372 | } |
---|
[42] | 373 | |
---|
[119] | 374 | // Determine if original file size is smaller than specified thumbnail size. Do not scale-up if $spec['allow_upscaling'] config is set to false. |
---|
| 375 | $image_size = getimagesize($source_file); |
---|
| 376 | if ($image_size['0'] <= $spec['width'] && $image_size['1'] <= $spec['height'] && !$spec['allow_upscaling']) { |
---|
| 377 | $spec['scaling_type'] = IMAGETHUMB_NO_SCALE; |
---|
[152] | 378 | $app->logMsg(sprintf('Image %s smaller than specified %s thumbnail size. Keeping original size.', $file_name, basename($spec['dest_dir'])), LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 379 | } |
---|
[42] | 380 | |
---|
[119] | 381 | // DO IT! Based on available method. |
---|
| 382 | if (IMAGETHUMB_METHOD_NETPBM === $this->getParam('resize_method') && file_exists($this->getParam('anytopnm_binary')) && file_exists($this->getParam('pnmscale_binary')) && file_exists($this->getParam('cjpeg_binary'))) { |
---|
| 383 | // Resize using Netpbm binaries. |
---|
[154] | 384 | // $app->logMsg(sprintf('Resizing with Netpbm: %s', $source_file), LOG_DEBUG, __FILE__, __LINE__); |
---|
[119] | 385 | $return_val += $this->_resizeWithNetpbm($source_file, $dest_file, $spec); |
---|
| 386 | } else if (IMAGETHUMB_METHOD_GD === $this->getParam('resize_method') && extension_loaded('gd')) { |
---|
| 387 | // Resize with GD. |
---|
[154] | 388 | // $app->logMsg(sprintf('Resizing with GD: %s', $source_file), LOG_DEBUG, __FILE__, __LINE__); |
---|
[119] | 389 | $return_val += $this->_resizeWithGD($source_file, $dest_file, $spec); |
---|
[1] | 390 | } else { |
---|
[152] | 391 | $app->logMsg(sprintf('Image thumbnailing canceled. Neither Netpbm or GD is available.', null), LOG_ERR, __FILE__, __LINE__); |
---|
[119] | 392 | return false; |
---|
[1] | 393 | } |
---|
[119] | 394 | } |
---|
[42] | 395 | |
---|
[152] | 396 | // If > 0, there was a problem thumbnailing. |
---|
[119] | 397 | return 0 === $return_val; |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | /* |
---|
| 401 | * Use the Netpbm and libjpg cjpeg tools to generate a rescaled compressed image. |
---|
| 402 | * This is the preferred method over GD which has (supposedly) less quality. |
---|
| 403 | * |
---|
| 404 | * @access private |
---|
| 405 | * @param string $source_file Full path to source image file. |
---|
| 406 | * @param string $dest_file Full path to destination image file. |
---|
| 407 | * @param array $spec Array of image size specifications. |
---|
[120] | 408 | * @return int 0 if no error, n > 0 if errors. |
---|
[119] | 409 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 410 | * @version 1.0 |
---|
| 411 | * @since 19 May 2006 13:55:46 |
---|
| 412 | */ |
---|
| 413 | function _resizeWithNetpbm($source_file, $dest_file, $spec) |
---|
| 414 | { |
---|
[136] | 415 | $app =& App::getInstance(); |
---|
| 416 | |
---|
[119] | 417 | // Define pnmscale arguments. |
---|
| 418 | switch ($spec['scaling_type']) { |
---|
| 419 | case IMAGETHUMB_FIT_WIDTH : |
---|
| 420 | $pnmscale_args = sprintf(' -width %s ', escapeshellarg($spec['width'])); |
---|
| 421 | break; |
---|
| 422 | case IMAGETHUMB_FIT_HEIGHT : |
---|
| 423 | $pnmscale_args = sprintf(' -height %s ', escapeshellarg($spec['height'])); |
---|
| 424 | break; |
---|
| 425 | case IMAGETHUMB_FIT_LARGER : |
---|
| 426 | $pnmscale_args = sprintf(' -xysize %s %s ', escapeshellarg($spec['width']), escapeshellarg($spec['height'])); |
---|
| 427 | break; |
---|
| 428 | case IMAGETHUMB_STRETCH : |
---|
| 429 | $pnmscale_args = sprintf(' -width %s -height %s ', escapeshellarg($spec['width']), escapeshellarg($spec['height'])); |
---|
| 430 | break; |
---|
| 431 | case IMAGETHUMB_NO_SCALE : |
---|
| 432 | default : |
---|
| 433 | $pnmscale_args = ' 1 '; |
---|
| 434 | break; |
---|
[1] | 435 | } |
---|
[42] | 436 | |
---|
[119] | 437 | // Define cjpeg arguments. |
---|
| 438 | $cjpeg_args = sprintf(' -optimize -quality %s ', escapeshellarg($spec['quality'])); |
---|
| 439 | $cjpeg_args .= (true === $spec['progressive']) ? ' -progressive ' : ''; |
---|
| 440 | |
---|
| 441 | // Format the command that creates the thumbnail. |
---|
| 442 | $command = sprintf('%s %s | %s %s | %s %s > %s/%s', |
---|
| 443 | escapeshellcmd($this->getParam('anytopnm_binary')), |
---|
| 444 | escapeshellcmd($source_file), |
---|
| 445 | escapeshellcmd($this->getParam('pnmscale_binary')), |
---|
| 446 | escapeshellcmd($pnmscale_args), |
---|
| 447 | escapeshellcmd($this->getParam('cjpeg_binary')), |
---|
| 448 | escapeshellcmd($cjpeg_args), |
---|
| 449 | escapeshellcmd($dest_file), |
---|
| 450 | escapeshellcmd($file_name) |
---|
| 451 | ); |
---|
[136] | 452 | $app->logMsg(sprintf('ImageThumb Netpbm command: %s', $command), LOG_DEBUG, __FILE__, __LINE__); |
---|
[119] | 453 | |
---|
| 454 | // Execute! |
---|
| 455 | exec($command, $output, $return_val); |
---|
| 456 | |
---|
| 457 | if (0 === $return_val) { |
---|
| 458 | // Success! |
---|
| 459 | // Make the thumbnail writable so the user can delete it over ftp without being 'apache'. |
---|
| 460 | chmod($dest_file, $this->getParam('dest_file_perms')); |
---|
[136] | 461 | $app->logMsg(sprintf('Successfully resized image %s', $spec['dest_dir'] . '/' . basename($dest_file), $return_val), LOG_DEBUG, __FILE__, __LINE__); |
---|
[119] | 462 | } else { |
---|
| 463 | // An error occurred. |
---|
[136] | 464 | $app->logMsg(sprintf('Image %s failed resizing with return value: %s%s', $spec['dest_dir'] . '/' . basename($dest_file), $return_val, empty($output) ? '' : ' (' . getDump($output) . ')'), LOG_ERR, __FILE__, __LINE__); |
---|
[119] | 465 | } |
---|
| 466 | |
---|
| 467 | // Return from the command will be > 0 if there was an error. |
---|
| 468 | return $return_val; |
---|
[1] | 469 | } |
---|
| 470 | |
---|
[119] | 471 | /* |
---|
| 472 | * Use PHP's built-in GD tools to generate a rescaled compressed image. |
---|
| 473 | * |
---|
| 474 | * @access private |
---|
| 475 | * @param string $source_file Full path to source image file. |
---|
| 476 | * @param string $dest_file Full path to destination image file. |
---|
| 477 | * @param array $spec Array of image size specifications. |
---|
[120] | 478 | * @return int 0 if no error, n > 0 if errors. |
---|
[119] | 479 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 480 | * @version 1.0 |
---|
| 481 | * @since 19 May 2006 15:46:02 |
---|
| 482 | */ |
---|
| 483 | function _resizeWithGD($source_file, $dest_file, $spec) |
---|
[1] | 484 | { |
---|
[136] | 485 | $app =& App::getInstance(); |
---|
| 486 | |
---|
[119] | 487 | // Get original file dimensions and type. |
---|
| 488 | list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_file); |
---|
| 489 | |
---|
| 490 | // Define destination image dimentions. |
---|
| 491 | switch ($spec['scaling_type']) { |
---|
| 492 | case IMAGETHUMB_FIT_WIDTH : |
---|
[120] | 493 | $dest_image_width = $spec['width']; |
---|
[119] | 494 | $dest_image_height = $source_image_height * ($spec['width'] / $source_image_width); |
---|
| 495 | break; |
---|
| 496 | case IMAGETHUMB_FIT_HEIGHT : |
---|
[120] | 497 | $dest_image_height = $spec['height']; |
---|
[119] | 498 | $dest_image_width = $source_image_width * ($spec['height'] / $source_image_height); |
---|
| 499 | break; |
---|
| 500 | case IMAGETHUMB_FIT_LARGER : |
---|
[120] | 501 | if (($source_image_width * ($spec['height'] / $source_image_height)) <= $spec['width']) { |
---|
| 502 | // Height is larger. |
---|
| 503 | $dest_image_height = $spec['height']; |
---|
| 504 | $dest_image_width = $source_image_width * ($spec['height'] / $source_image_height); |
---|
[119] | 505 | } else { |
---|
[120] | 506 | // Width is larger. |
---|
| 507 | $dest_image_width = $spec['width']; |
---|
| 508 | $dest_image_height = $source_image_height * ($spec['width'] / $source_image_width); |
---|
[119] | 509 | } |
---|
| 510 | break; |
---|
| 511 | case IMAGETHUMB_STRETCH : |
---|
| 512 | $dest_image_width = $spec['width']; |
---|
| 513 | $dest_image_height = $spec['height']; |
---|
| 514 | break; |
---|
| 515 | case IMAGETHUMB_NO_SCALE : |
---|
| 516 | default : |
---|
| 517 | $dest_image_width = $source_image_width; |
---|
| 518 | $dest_image_height = $source_image_height; |
---|
| 519 | break; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | // Create source image data in memory. |
---|
| 523 | switch ($source_image_type) { |
---|
| 524 | case IMAGETYPE_JPEG : |
---|
[120] | 525 | $source_image_resource = imagecreatefromjpeg($source_file); |
---|
[119] | 526 | break; |
---|
| 527 | case IMAGETYPE_PNG : |
---|
[120] | 528 | $source_image_resource = imagecreatefrompng($source_file); |
---|
[119] | 529 | break; |
---|
| 530 | case IMAGETYPE_GIF : |
---|
[120] | 531 | $source_image_resource = imagecreatefromgif($source_file); |
---|
[119] | 532 | break; |
---|
| 533 | case IMAGETYPE_WBMP : |
---|
[120] | 534 | $source_image_resource = imagecreatefromwbmp($source_file); |
---|
[119] | 535 | default : |
---|
[136] | 536 | $app->logMsg(sprintf('Source image type %s not supported.', $source_image_type), LOG_WARNING, __FILE__, __LINE__); |
---|
[120] | 537 | return 1; |
---|
[119] | 538 | break; |
---|
[1] | 539 | } |
---|
[120] | 540 | if (!$source_image_resource) { |
---|
[136] | 541 | $app->logMsg(sprintf('Error creating %s image in memory from %s', $source_image_type, $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[120] | 542 | return 1; |
---|
[119] | 543 | } |
---|
| 544 | |
---|
| 545 | // Create destination image data in memory. |
---|
[120] | 546 | $dest_image_resource = imagecreatetruecolor($dest_image_width, $dest_image_height); |
---|
[42] | 547 | |
---|
[119] | 548 | // Resample! |
---|
[120] | 549 | if (!imagecopyresampled($dest_image_resource, $source_image_resource, 0, 0, 0, 0, $dest_image_width, $dest_image_height, $source_image_width, $source_image_height)) { |
---|
[136] | 550 | $app->logMsg(sprintf('Error resampling image %s', $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[152] | 551 | // Always cleanup images from memory. |
---|
| 552 | imagedestroy($source_image_resource); |
---|
| 553 | imagedestroy($dest_image_resource); |
---|
[120] | 554 | return 1; |
---|
[1] | 555 | } |
---|
[120] | 556 | |
---|
| 557 | // Sharpen image using a custom filter matrix. |
---|
| 558 | if (phpversion() > '5.1' && true === $spec['sharpen'] && $spec['sharpen_value'] > 0) { |
---|
| 559 | $sharpen_value = round((((48 - 10) / (100 - 1)) * (100 - $spec['sharpen_value'])) + 10); |
---|
| 560 | imageconvolution($dest_image_resource, array(array(-1,-1,-1),array(-1,$sharpen_value,-1),array(-1,-1,-1)), ($sharpen_value - 8), 0); |
---|
| 561 | } |
---|
[42] | 562 | |
---|
[119] | 563 | // Save image. |
---|
| 564 | $return_val = true; |
---|
[120] | 565 | switch ($spec['dest_file_type']) { |
---|
[119] | 566 | case IMG_JPG : |
---|
[120] | 567 | imageinterlace($dest_image_resource, (true == $spec['progressive'] ? 1 : 0)); |
---|
| 568 | $return_val = imagejpeg($dest_image_resource, $dest_file, $spec['quality']); |
---|
[119] | 569 | break; |
---|
| 570 | case IMG_PNG : |
---|
[120] | 571 | $return_val = imagepng($dest_image_resource, $dest_file); |
---|
[119] | 572 | break; |
---|
| 573 | case IMG_GIF : |
---|
[120] | 574 | $return_val = imagegif($dest_image_resource, $dest_file); |
---|
[119] | 575 | break; |
---|
| 576 | case IMG_WBMP : |
---|
[120] | 577 | $return_val = imagewbmp($dest_image_resource, $dest_file); |
---|
[119] | 578 | break; |
---|
| 579 | default : |
---|
[136] | 580 | $app->logMsg(sprintf('Destination image type %s not supported for image %s.', $spec['dest_file_type'], $dest_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[152] | 581 | // Always cleanup images from memory. |
---|
| 582 | imagedestroy($source_image_resource); |
---|
| 583 | imagedestroy($dest_image_resource); |
---|
[120] | 584 | return 1; |
---|
[119] | 585 | break; |
---|
| 586 | } |
---|
| 587 | |
---|
[152] | 588 | // Always cleanup images from memory. |
---|
| 589 | imagedestroy($source_image_resource); |
---|
| 590 | imagedestroy($dest_image_resource); |
---|
| 591 | |
---|
[119] | 592 | if ($return_val) { |
---|
| 593 | // Success! |
---|
| 594 | // Make the thumbnail writable so the user can delete it over ftp without being 'apache'. |
---|
[152] | 595 | if (!chmod($dest_file, $this->getParam('dest_file_perms'))) { |
---|
| 596 | $app->logMsg(sprintf('chmod failed on file: %s', $dest_file), LOG_ERR, __FILE__, __LINE__); |
---|
| 597 | } |
---|
| 598 | $app->logMsg(sprintf('Successfully resized image: %s', $dest_file), LOG_DEBUG, __FILE__, __LINE__); |
---|
[120] | 599 | return 0; |
---|
[1] | 600 | } else { |
---|
[119] | 601 | // An error occurred. |
---|
[152] | 602 | $app->logMsg(sprintf('Failed resizing image: %s', $dest_file), LOG_ERR, __FILE__, __LINE__); |
---|
[120] | 603 | return 1; |
---|
[1] | 604 | } |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | /** |
---|
| 608 | * Delete the thumbnails for the specified file name. |
---|
| 609 | * |
---|
| 610 | * @access public |
---|
| 611 | * @param string $file_name The file name to delete, with extention. |
---|
| 612 | * @return bool true on success, false on failure. |
---|
| 613 | */ |
---|
| 614 | function deleteThumbs($file_name) |
---|
| 615 | { |
---|
[136] | 616 | $app =& App::getInstance(); |
---|
| 617 | |
---|
[1] | 618 | // Ensure we have a source. |
---|
[119] | 619 | if ('' == $this->getParam('source_dir')) { |
---|
[136] | 620 | $app->logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 621 | return false; |
---|
| 622 | } |
---|
[42] | 623 | |
---|
[119] | 624 | $return_val = 0; |
---|
[152] | 625 | foreach ($this->_image_specs as $spec) { |
---|
| 626 | if ('/' == $spec['dest_dir']{0}) { |
---|
| 627 | // Absolute path. |
---|
| 628 | $dest_file = realpath(sprintf('%s/%s.%s', $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention'])); |
---|
| 629 | } else { |
---|
| 630 | // Relative path. |
---|
| 631 | $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention'])); |
---|
| 632 | } |
---|
[119] | 633 | if (file_exists($dest_file)) { |
---|
| 634 | if (!unlink($dest_file)) { |
---|
| 635 | $return_val++; |
---|
[141] | 636 | $app->logMsg(sprintf('Delete thumbs failed: %s', $dest_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 637 | } |
---|
| 638 | } |
---|
| 639 | } |
---|
[121] | 640 | $this->_raiseMsg(sprintf(_("The thumbnails for file %s have been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__); |
---|
[119] | 641 | return 0 === $return_val; |
---|
[1] | 642 | } |
---|
| 643 | |
---|
| 644 | /** |
---|
| 645 | * Delete the source image with the specified file name. |
---|
| 646 | * |
---|
| 647 | * @access public |
---|
| 648 | * @param string $file_name The file name to delete, with extention. |
---|
| 649 | * @return bool true on success, false on failure. |
---|
| 650 | */ |
---|
| 651 | function deleteOriginal($file_name) |
---|
| 652 | { |
---|
[136] | 653 | $app =& App::getInstance(); |
---|
| 654 | |
---|
[1] | 655 | // Ensure we have a source. |
---|
[119] | 656 | if ('' == $this->getParam('source_dir')) { |
---|
[136] | 657 | $app->logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 658 | return false; |
---|
| 659 | } |
---|
[42] | 660 | |
---|
[119] | 661 | $source_file = realpath(sprintf('%s/%s', $this->getParam('source_dir'), $file_name)); |
---|
| 662 | if (!unlink($source_file)) { |
---|
[141] | 663 | $app->logMsg(sprintf('Delete original failed: %s', $source_file), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 664 | return false; |
---|
| 665 | } |
---|
[121] | 666 | $this->_raiseMsg(sprintf(_("The original file %s has been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__); |
---|
[1] | 667 | return true; |
---|
| 668 | } |
---|
[42] | 669 | |
---|
[1] | 670 | /** |
---|
| 671 | * Returns true if file exists. |
---|
| 672 | * |
---|
| 673 | * @access public |
---|
| 674 | * @param string $file_name The file name to test, with extention. |
---|
| 675 | * @return bool true on success, false on failure. |
---|
| 676 | */ |
---|
| 677 | function exists($file_name) |
---|
| 678 | { |
---|
[136] | 679 | $app =& App::getInstance(); |
---|
| 680 | |
---|
[1] | 681 | // Ensure we have a source. |
---|
[119] | 682 | if ('' == $this->getParam('source_dir')) { |
---|
[136] | 683 | $app->logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 684 | return false; |
---|
| 685 | } |
---|
[42] | 686 | |
---|
[119] | 687 | $source_file = realpath(sprintf('%s/%s', $this->getParam('source_dir'), $file_name)); |
---|
| 688 | return file_exists($source_file); |
---|
[1] | 689 | } |
---|
[42] | 690 | |
---|
[1] | 691 | /** |
---|
| 692 | * Tests if extention of $file_name is in the array valid_file_extensions. |
---|
| 693 | * |
---|
| 694 | * @access public |
---|
| 695 | * @param string $file_name A file name. |
---|
| 696 | * @return bool True on success, false on failure. |
---|
| 697 | */ |
---|
[119] | 698 | function _validFileExtension($file_name) |
---|
[1] | 699 | { |
---|
| 700 | preg_match('/.*?\.(\w+)$/i', $file_name, $ext); |
---|
[121] | 701 | return !empty($ext) && in_array(strtolower($ext[1]), $this->getParam('valid_file_extensions')); |
---|
[1] | 702 | } |
---|
[42] | 703 | |
---|
[1] | 704 | /** |
---|
[119] | 705 | * Make directory for each specified thumbnail size, if it doesn't exist. |
---|
[1] | 706 | * |
---|
[119] | 707 | * @access public |
---|
| 708 | * @return bool true on success, false on failure. |
---|
| 709 | */ |
---|
[152] | 710 | function _createDestDirs($filename=null) |
---|
[119] | 711 | { |
---|
[136] | 712 | $app =& App::getInstance(); |
---|
| 713 | |
---|
[152] | 714 | // Keep track of directories we've already created. |
---|
| 715 | $dd_hash = md5(isset($filename) ? dirname($filename) : 'none'); |
---|
| 716 | static $already_checked = array(); |
---|
[119] | 717 | |
---|
[152] | 718 | $return_val = 0; |
---|
| 719 | |
---|
| 720 | if (!isset($already_checked[$dd_hash])) { |
---|
[119] | 721 | // Ensure we have a source. |
---|
| 722 | if ('' == $this->getParam('source_dir')) { |
---|
[136] | 723 | $app->logMsg(sprintf('Source directory not set before creating destination directories.'), LOG_ERR, __FILE__, __LINE__); |
---|
[119] | 724 | return false; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | // Loop through specs and ensure all dirs are created. |
---|
[152] | 728 | foreach ($this->_image_specs as $spec) { |
---|
| 729 | if (isset($filename)) { |
---|
| 730 | $dest_dir = dirname($filename); |
---|
| 731 | } else { |
---|
| 732 | if ('/' == $spec['dest_dir']{0}) { |
---|
| 733 | // Absolute path. |
---|
| 734 | $dest_dir = $spec['dest_dir']; |
---|
| 735 | } else { |
---|
| 736 | // Relative path. |
---|
| 737 | $dest_dir = sprintf('%s/%s', $this->getParam('source_dir'), $spec['dest_dir']); |
---|
[119] | 738 | } |
---|
| 739 | } |
---|
[152] | 740 | if (!file_exists($dest_dir)) { |
---|
[154] | 741 | if (phpversion() > '5') { |
---|
[152] | 742 | // Recursive. |
---|
[154] | 743 | if (!file_exists($dest_dir) && !($ret = mkdir($dest_dir, $this->getParam('dest_dir_perms'), true))) { |
---|
[152] | 744 | $return_val++; |
---|
| 745 | $app->logMsg(sprintf('mkdir failure: %s', $dest_dir), LOG_ERR, __FILE__, __LINE__); |
---|
| 746 | } |
---|
| 747 | } else { |
---|
| 748 | // Recursive mkdir for php 4. |
---|
| 749 | $path = ''; |
---|
| 750 | foreach (array_diff(explode('/', $dest_dir), array('')) as $dir) { |
---|
| 751 | $path .= '/' . $dir; |
---|
| 752 | if (! ($ret = file_exists($path) ? true : mkdir($path, $this->getParam('dest_dir_perms')))) { |
---|
| 753 | $return_val++; |
---|
| 754 | $app->logMsg(sprintf('mkdir failure: %s', $path), LOG_ERR, __FILE__, __LINE__); |
---|
| 755 | break; |
---|
| 756 | } |
---|
| 757 | } |
---|
| 758 | } |
---|
| 759 | |
---|
| 760 | if ($ret) { |
---|
| 761 | $app->logMsg(sprintf('mkdir success: %s', $dest_dir), LOG_DEBUG, __FILE__, __LINE__); |
---|
| 762 | } |
---|
| 763 | } |
---|
[119] | 764 | } |
---|
| 765 | } |
---|
| 766 | |
---|
[152] | 767 | $already_checked[$dd_hash] = true; |
---|
| 768 | |
---|
| 769 | // If > 0, there was a problem creating dest dirs. |
---|
| 770 | return 0 === $return_val; |
---|
[119] | 771 | } |
---|
| 772 | |
---|
| 773 | /** |
---|
[136] | 774 | * An alias for $app->raiseMsg that only sends messages configured by display_messages. |
---|
[119] | 775 | * |
---|
[1] | 776 | * @access public |
---|
| 777 | * |
---|
| 778 | * @param string $message The text description of the message. |
---|
| 779 | * @param int $type The type of message: MSG_NOTICE, |
---|
| 780 | * MSG_SUCCESS, MSG_WARNING, or MSG_ERR. |
---|
| 781 | * @param string $file __FILE__. |
---|
| 782 | * @param string $line __LINE__. |
---|
| 783 | */ |
---|
[119] | 784 | function _raiseMsg($message, $type, $file, $line) |
---|
[1] | 785 | { |
---|
[136] | 786 | $app =& App::getInstance(); |
---|
| 787 | |
---|
[119] | 788 | if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') & $type > 0)) { |
---|
[136] | 789 | $app->raiseMsg($message, $type, $file, $line); |
---|
[1] | 790 | } |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | } // End of class. |
---|
| 794 | ?> |
---|