Ignore:
Timestamp:
May 22, 2006 5:29:19 AM (18 years ago)
Author:
scdev
Message:

Q - Added "sc-" to all css class selectors; Finished reworking Upload and ImageThumb? (now with GD support!); More PHP 5 upgrades.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/ImageThumb.inc.php

    r120 r121  
    194194        if (isset($index) && isset($this->image_specs[$index])) {
    195195            // Merge with previous.
    196             $this->image_specs[$index] = array_merge($this->image_specs[$index], $spec);
     196            $final_spec = array_merge($this->image_specs[$index], $spec);
     197            $this->image_specs[$index] = $final_spec;
    197198        } else {
    198199            // Merge with defaults.
    199             $this->image_specs[] = array_merge($this->default_image_specs, $spec);           
    200         }
     200            $final_spec = array_merge($this->default_image_specs, $spec);           
     201            $this->image_specs[] = $final_spec;
     202        }
     203       
     204        return $final_spec;
    201205    }
    202206
     
    207211     * @return  bool true on success, false on failure.
    208212     */
    209     function processAll()
     213    function processAll($runtime_specs=null)
    210214    {
    211215        // Ensure we have a source.
     
    228232            $return_val = 0;
    229233            foreach ($files as $file_name) {
    230                 $return_val += $this->processFile($file_name);
     234                $return_val += $this->processFile($file_name, $runtime_specs);
    231235            }
    232236            $this->_raiseMsg(sprintf(_("Resized %s images."), sizeof($files)), MSG_SUCCESS, __FILE__, __LINE__);
     
    243247     * @access  public
    244248     * @param   string $file_name Name of file with extention.
     249     * @param   array $runtime_specs Array of specifications that will override all configured specifications.
    245250     * @return  bool true on success, false on failure.
    246251     */
    247     function processFile($file_name)
     252    function processFile($file_name, $runtime_specs=null)
    248253    {
    249254        // Source file determinted by provided file_name.
     
    252257        // Ensure we have a source.
    253258        if (sizeof($this->image_specs) < 1) {
    254             App::logMsg(sprintf('Image specifications not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    255             return false;
     259            if (is_array($runtime_specs)) {
     260                $this->setSpec($runtime_specs, 0);
     261            } else {
     262                App::logMsg(sprintf('Image specifications not set before processing.'), LOG_ERR, __FILE__, __LINE__);
     263                return false;               
     264            }
    256265        }
    257266
     
    265274        if (!file_exists($source_file)) {
    266275            $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s was not found."), $file_name), MSG_ERR, __FILE__, __LINE__);
    267             App::logMsg(sprintf('Source image not found: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
     276            App::logMsg(sprintf('Source image not found: %s', $source_file), LOG_ALERT, __FILE__, __LINE__);
    268277            return false;
    269278        }
     
    272281        if (!is_readable($source_file)) {
    273282            $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s is not readable."), $file_name), MSG_ERR, __FILE__, __LINE__);
    274             App::logMsg(sprintf('Source image not readable: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
     283            App::logMsg(sprintf('Source image not readable: %s', $source_file), LOG_ALERT, __FILE__, __LINE__);
    275284            return false;
    276285        }
     
    279288        if (filesize($source_file) <= 0) {
    280289            $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s is zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
    281             App::logMsg(sprintf('Source image is zero bytes: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
     290            App::logMsg(sprintf('Source image is zero bytes: %s', $source_file), LOG_ALERT, __FILE__, __LINE__);
    282291            return false;
    283292        }
     
    286295        if (!$this->_validFileExtension($file_name)) {
    287296            $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__);
    288             App::logMsg(sprintf('Image resizing failed: source image not of valid type: %s', $file_name), LOG_ERR, __FILE__, __LINE__);
     297            App::logMsg(sprintf('Image resizing failed: source image not of valid type: %s', $source_file), LOG_ERR, __FILE__, __LINE__);
    289298            return false;
    290299        }
     
    295304        // To keep this script running even if user tries to stop browser.
    296305        ignore_user_abort(true);
    297         if (!ini_get('safe_mode')) {
    298             set_time_limit(300);
    299         }
     306        ini_set('max_execution_time', 300);
     307        ini_set('max_input_time', 300);
    300308
    301309        // This remains zero until something goes wrong.
    302310        $return_val = 0;
    303311
    304         foreach ($this->image_specs as $spec) {
     312        foreach ($this->image_specs as $index => $spec) {
     313           
     314            if (is_array($runtime_specs)) {
     315                // Override with runtime specs.
     316                $spec = $this->setSpec($runtime_specs, $index);
     317            }
    305318           
    306319            // Destination filename uses the extention defined by dest_file_extention.
     
    558571            }
    559572        }
    560         $this->_raiseMsg(sprintf(_("The thumbnails for file <strong>%s</strong> have been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
     573        $this->_raiseMsg(sprintf(_("The thumbnails for file %s have been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
    561574        return 0 === $return_val;
    562575    }
     
    582595            return false;
    583596        }
    584         $this->_raiseMsg(sprintf(_("The original file <strong>%s</strong> has been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
     597        $this->_raiseMsg(sprintf(_("The original file %s has been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
    585598        return true;
    586599    }
     
    615628    {
    616629        preg_match('/.*?\.(\w+)$/i', $file_name, $ext);
    617         return in_array(strtolower($ext[1]), $this->getParam('valid_file_extensions'));
     630        return !empty($ext) && in_array(strtolower($ext[1]), $this->getParam('valid_file_extensions'));       
    618631    }
    619632
Note: See TracChangeset for help on using the changeset viewer.