Changeset 320 for trunk/lib/ImageThumb.inc.php
- Timestamp:
- Mar 21, 2008 10:20:11 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/ImageThumb.inc.php
r315 r320 638 638 * 639 639 * @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) 641 642 * @return bool true on success, false on failure. 642 643 */ 643 function deleteThumbs($file_name )644 function deleteThumbs($file_name, $use_glob=false) 644 645 { 645 646 $app =& App::getInstance(); … … 653 654 $return_val = 0; 654 655 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))); 658 660 } 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 662 664 if (file_exists($dest_file)) { 663 665 if (!unlink($dest_file)) { … … 667 669 } 668 670 } 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__); 670 672 return 0 === $return_val; 671 673 } … … 766 768 $dest_dir = dirname($filename); 767 769 } 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']); 775 772 } 776 773 if (!file_exists($dest_dir)) { … … 835 832 } 836 833 } 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 } 837 855 838 856 } // End of class.
Note: See TracChangeset
for help on using the changeset viewer.