Subversion Repositories cmsmadesimple

Rev

Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7476 Rev 8400
Line 4... Line 4...
 * @author $Author: Wei Zhuo $
 * @author $Author: Wei Zhuo $
 * @version $Id: ImageManager.php 4488 2008-05-14 22:53:57Z calguy1000 $
 * @version $Id: ImageManager.php 8400 2012-10-22 16:49:30Z calguy1000 $
 * @package ImageManager
 * @package ImageManager
 */
 */
 
 
require_once(dirname(__FILE__).'/Files.php');
require_once(dirname(__FILE__).'/Files.php');
 
 
/**
/**
 * ImageManager Class.
 * ImageManager Class.
 * @author $Author: Wei Zhuo $
 * @author $Author: Wei Zhuo $
 * @version $Id: ImageManager.php 4488 2008-05-14 22:53:57Z calguy1000 $
 * @version $Id: ImageManager.php 8400 2012-10-22 16:49:30Z calguy1000 $
 */
 */
class ImageManager
class ImageManager
{
{
	/**
	/**
	 * Configuration array.
	 * Configuration array.
Line 139... Line 139...
		$files = array();
		$files = array();
		$dirs = array();
		$dirs = array();
 
 
		if($this->isValidBase() == false)
		if($this->isValidBase() == false)
			return array($files,$dirs);
			return array($files,$dirs);
 
 
 
 
		$path = Files::fixPath($path);
		$path = Files::fixPath($path);
		$base = Files::fixPath($this->getBaseDir());
		$base = Files::fixPath($this->getBaseDir());
		$fullpath = Files::makePath($base,$path);
		$fullpath = Files::makePath($base,$path);
 
 
 
 
 
 
		$d = @dir($fullpath);
		$d = @dir($fullpath);
 
		if( $d ) {
		while (false !== ($entry = $d->read()))
		  while (false !== ($entry = $d->read())) {
		{
		    //not a dot file or directory
 
		    if(substr($entry,0,1) != '.') {
 
		      if(is_dir($fullpath.$entry)
 
			 && $this->isThumbDir($entry) == false) {
 
			$relative = Files::fixPath($path.$entry);
 
			$full = Files::fixPath($fullpath.$entry);
 
			$count = $this->countFiles($full);
 
			$dirs[$relative] = array('fullpath'=>$full,'entry'=>$entry,'count'=>$count);
 
		      }
 
		      else if(is_file($fullpath.$entry) &&
 
			      $this->isThumb($entry)==false && $this->isTmpFile($entry) == false) {
 
			$img = $this->getImageInfo($fullpath.$entry);
 
 
 
			if(!(!is_array($img)&&$this->config['validate_images'])) {
			//not a dot file or directory
			  $file['url'] = Files::makePath($this->config['base_url'],$path).$entry;
			if(substr($entry,0,1) != '.')
			  $file['relative'] = $path.$entry;
			{
			  $file['fullpath'] = $fullpath.$entry;
				if(is_dir($fullpath.$entry)
			  $file['image'] = $img;
					&& $this->isThumbDir($entry) == false)
			  $file['stat'] = stat($fullpath.$entry);
				{
			  $files[$entry] = $file;
					$relative = Files::fixPath($path.$entry);
 
					$full = Files::fixPath($fullpath.$entry);
 
					$count = $this->countFiles($full);
 
					$dirs[$relative] = array('fullpath'=>$full,'entry'=>$entry,'count'=>$count);
 
				}
 
				else if(is_file($fullpath.$entry) && $this->isThumb($entry)==false && $this->isTmpFile($entry) == false)
 
				{
 
					$img = $this->getImageInfo($fullpath.$entry);
 
 
 
					if(!(!is_array($img)&&$this->config['validate_images']))
 
					{
 
						$file['url'] = Files::makePath($this->config['base_url'],$path).$entry;
 
						$file['relative'] = $path.$entry;
 
						$file['fullpath'] = $fullpath.$entry;
 
						$file['image'] = $img;
 
						$file['stat'] = stat($fullpath.$entry);
 
						$files[$entry] = $file;
 
					}
 
				}
 
			}
			}
 
		      }
 
		    }
 
		  }
 
		  $d->close();
		}
		}
		$d->close();
 
 
 
			//Add a back directory
			//Add a back directory
 
 
			$backpath = $fullpath.'/..';
			$backpath = $fullpath.'/..';
			$backpath = realpath($backpath);
			$backpath = realpath($backpath);
Line 425... Line 417...
	 * @return boolean true if the file was processed successfully,
	 * @return boolean true if the file was processed successfully,
	 * false otherwise
	 * false otherwise
	 */
	 */
	function _processFiles($relative, $file)
	function _processFiles($relative, $file)
	{
	{
 
	  if( !$this->validRelativePath($relative) ) return false;
 
 
		if($file['error']!=0)
		if($file['error']!=0)
		{
		{
			Return false;
			Return false;
		}
		}
Line 558... Line 551...
	 * Delete and specified files.
	 * Delete and specified files.
	 * @return boolean true if delete, false otherwise
	 * @return boolean true if delete, false otherwise
	 */
	 */
	function deleteFiles()
	function deleteFiles()
	{
	{
		if(isset($_GET['delf']))
	  if(isset($_GET['delf']))
			$this->_delFile(rawurldecode($_GET['delf']));
	    $this->_delFile(rawurldecode($_GET['delf']));
	}
	}
 
 
	/**
	/**
	 * Delete and specified directories.
	 * Delete and specified directories.
	 * @return boolean true if delete, false otherwise
	 * @return boolean true if delete, false otherwise
	 */
	 */
	function deleteDirs()
	function deleteDirs()
	{
	{
		 if(isset($_GET['deld']))
	  if(isset($_GET['deld']) ) {
			return $this->_delDir(rawurldecode($_GET['deld']));
	    return $this->_delDir(rawurldecode($_GET['deld']));
		 else
	  }
			 Return false;
	  return false;
	}
	}
 
 
	/**
	/**
	 * Delete the relative file, and any thumbnails.
	 * Delete the relative file, and any thumbnails.
	 * @param string $relative the relative file.
	 * @param string $relative the relative file.
	 * @return boolean true if deleted, false otherwise.
	 * @return boolean true if deleted, false otherwise.
	 */
	 */
	function _delFile($relative)
	function _delFile($relative)
	{
	{
 
          $r2 = dirname($relative);
 
	  if( !$this->validRelativePath($r2) ) return false;
		$fullpath = Files::makeFile($this->getBaseDir(),$relative);
		$fullpath = Files::makeFile($this->getBaseDir(),$relative);
 
 
		//check that the file is an image
		//check that the file is an image
		if($this->config['validate_images'] == true)
		if($this->config['validate_images'] == true)
		{
		{
Line 605... Line 600...
	 * @param string $relative the relative path to be deleted.
	 * @param string $relative the relative path to be deleted.
	 * @return boolean true if deleted, false otherwise.
	 * @return boolean true if deleted, false otherwise.
	 */
	 */
	function _delDir($relative)
	function _delDir($relative)
	{
	{
 
	  if( !$this->validRelativePath($relative) ) return false;
		$fullpath = Files::makePath($this->getBaseDir(),$relative);
		$fullpath = Files::makePath($this->getBaseDir(),$relative);
		if($this->countFiles($fullpath) <= 0)
		if($this->countFiles($fullpath) <= 0)
			return Files::delFolder($fullpath,true); //delete recursively.
			return Files::delFolder($fullpath,true); //delete recursively.
		else
		else
			Return false;
			Return false;