Changeset 320 for trunk/lib


Ignore:
Timestamp:
Mar 21, 2008 10:20:11 AM (16 years ago)
Author:
quinn
Message:

Added a glob function to the ImageThumb? deleteThumbs method. Fixed some HTML errors. Minor admin2 CSS tweaks.

Location:
trunk/lib
Files:
2 edited

Legend:

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

    r315 r320  
    638638     *
    639639     * @access  public
    640      * @param   string $file_name The file name to delete, with extension.
     640     * @param   string  $file_name  The file name to delete, with extension.
     641     * @param   bool    $use_glob   Set true to use glob to find the filename (using $file_name as a pattern)
    641642     * @return  bool true on success, false on failure.
    642643     */
    643     function deleteThumbs($file_name)
     644    function deleteThumbs($file_name, $use_glob=false)
    644645    {
    645646        $app =& App::getInstance();
     
    653654        $return_val = 0;
    654655        foreach ($this->_image_specs as $spec) {
    655             if ('/' == $spec['dest_dir']{0}) {
    656                 // Absolute path.
    657                 $dest_file = realpath(sprintf('%s/%s.%s', $spec['dest_dir'], mb_substr($file_name, 0, mb_strrpos($file_name, '.')), $spec['dest_file_extension']));               
     656            // Get base directory depending on if the spec's dest_dir is an absolute path or not.
     657            $dest_dir = '/' == $spec['dest_dir']{0} ? $spec['dest_dir'] : sprintf('%s/%s', $this->getParam('source_dir'), $spec['dest_dir']);
     658            if ($use_glob) {
     659                $dest_file = realpath(sprintf('%s/%s', $dest_dir, $this->_glob($file_name, $dest_dir)));               
    658660            } else {
    659                 // Relative path.
    660                 $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], mb_substr($file_name, 0, mb_strrpos($file_name, '.')), $spec['dest_file_extension']));
    661             }
     661                $dest_file = realpath(sprintf('%s/%s.%s', $dest_dir, mb_substr($file_name, 0, mb_strrpos($file_name, '.')), $spec['dest_file_extension']));
     662            }           
     663           
    662664            if (file_exists($dest_file)) {
    663665                if (!unlink($dest_file)) {
     
    667669            }
    668670        }
    669         $app->logMsg(sprintf('Thumbnails deleted for file: %s', $file_name), LOG_INFO, __FILE__, __LINE__);
     671        $app->logMsg(sprintf('Thumbnails deleted for file: %s', $dest_file), LOG_DEBUG, __FILE__, __LINE__);
    670672        return 0 === $return_val;
    671673    }
     
    766768                    $dest_dir = dirname($filename);
    767769                } else {
    768                     if ('/' == $spec['dest_dir']{0}) {
    769                         // Absolute path.
    770                         $dest_dir = $spec['dest_dir'];
    771                     } else {
    772                         // Relative path.
    773                         $dest_dir = sprintf('%s/%s', $this->getParam('source_dir'), $spec['dest_dir']);
    774                     }
     770                    // Get base directory depending on if the spec's dest_dir is an absolute path or not.
     771                    $dest_dir = '/' == $spec['dest_dir']{0} ? $spec['dest_dir'] : sprintf('%s/%s', $this->getParam('source_dir'), $spec['dest_dir']);
    775772                }
    776773                if (!file_exists($dest_dir)) {
     
    835832        }
    836833    }
     834   
     835    /**
     836     * Get filename by glob pattern. Searches a directory for an image that matches the
     837     * specified glob pattern and returns the filename of the first file found.
     838     *
     839     * @access  public
     840     * @param   string  $pattern    Pattern to match filename.
     841     * @param   string  $directory  Pattern to match containing directory.
     842     * @return  string filename on success, empty string on failure.
     843     * @author  Quinn Comendant <quinn@strangecode.com>
     844     * @since   15 Nov 2005 20:55:22
     845     */
     846    function _glob($pattern, $directory)
     847    {
     848        $file_list = glob(sprintf('%s/%s', $directory, $pattern));
     849        if (isset($file_list[0])) {
     850            return basename($file_list[0]);
     851        } else {
     852            return '';
     853        }
     854    }
    837855
    838856} // End of class.
  • trunk/lib/Utilities.inc.php

    r294 r320  
    108108/**
    109109 * Returns text with stylistic modifications. Warning: this will break some HTML attibutes!
    110  * TODO: Allow a string such as this to be passted: <a href="javascript:openPopup('/foo/bar.php')">Click here</a>
     110 * TODO: Allow a string such as this to be passed: <a href="javascript:openPopup('/foo/bar.php')">Click here</a>
    111111 *
    112112 * @param  string   $text Text to clean.
Note: See TracChangeset for help on using the changeset viewer.