Commits

Eric Nishio committed 3d3a977

Fixed the rewrite regex and corrected the documentation.

  • Participants
  • Parent commits d80c4f3

Comments (0)

Files changed (6)

components/ImgInstaller.php

 class ImgInstaller extends CComponent
 {
 	/**
-	 * @property ImgModule the image module.
+	 * @var ImgModule the image module.
 	 */
 	private $_module;
 	/**
-	 * @property string the image path.
+	 * @var string the image path.
 	 */
 	private $_imagePath;
 	/**
-	 * @property string the base path.
+	 * @var string the base path.
 	 */
 	private $_basePath;
 	/**
 		// Replace the placeholders in the template file.
 		$htaccess=strtr($htaccess,array(
 			'{baseUrl}'=>Yii::app()->getRequest()->getBaseUrl().'/',
-			'{sourceUrl}'=>'^versions/([^/]+)/.*\-*(\d+)\.(gif|jpg|png)$',
+			'{sourceUrl}'=>'^versions/([^/]+)/[^\-]*\-?(\d+)\.(gif|jpg|png)$',
 			'{targetUrl}'=>$targetUrl,
 		));
 

components/ImgManager.php

-<?php
+<?php
 /**
  * Image manager class file.
  * @author Christoffer Niska <ChristofferNiska@gmail.com>
  * @see http://phpthumb.gxdlabs.com/
  */
 
-require_once(dirname(__FILE__).'/../vendors/phpthumb/ThumbLib.inc.php'); // Yii::import() will not work in this case.
+require_once(dirname(__FILE__) . '/../vendors/phpthumb/ThumbLib.inc.php'); // Yii::import() will not work in this case.
 
 class ImgManager extends CApplicationComponent
 {
 	 * );
 	 * </code>
 	 *
-	 * @property array
+	 * @var array
 	 */
 	public $thumbOptions=array();
 	/**
-	 * @property string the relative path where to store images.
+	 * @var string the base url.
+	 */
+	public $baseUrl;
+	/**
+	 * @var string the relative path where to store images.
 	 */
 	public $imagePath='files/images/';
 	/**
-	 * @property array the image versions.
+	 * @var array the image versions.
 	 */
 	public $versions=array();
 	/**
-	 * @property string the base path.
+	 * @var string the base path.
 	 */
 	protected $_basePath;
 	/**
-	 * @property string the image version path.
+	 * @var string the path to the original images.
+	 */
+	protected $_originalBasePath;
+	/**
+	 * @var string the path to the versioned images.
 	 */
 	protected $_versionBasePath;
 
 		self::$_thumbOptions=$this->thumbOptions;
 		self::$_imagePath=$this->getImagePath(true);
 
+		if ($this->baseUrl === null)
+			$this->baseUrl = Yii::app()->request->baseUrl;
+
 		parent::init();
 	}
 
 		{
 			$image=$this->loadModel($id);
 			$path=$this->getVersionPath($version).$image->getPath().$this->resolveFileName($image);
-			return Yii::app()->request->getBaseUrl($absolute).'/'.$path;
+			return '/'.$this->baseUrl.'/'.$path;
 		}
 		else
 			throw new ImgException(Img::t('error','Failed to get image URL! Version is unknown.'));
 
 		if($image instanceof Image)
 		{
+			$deleted = true;
+
 			$path=$this->resolveImagePath($image).$this->resolveFileName($image);
 
 			if($image->delete()===false)
 				throw new ImgException(Img::t('error', 'Failed to delete image! File could not be deleted.'));
 
 			foreach($this->versions as $version=>$config)
-				$this->deleteVersion($image,$version);
+				$deleted = $this->deleteVersion($image,$version);
+
+			return $deleted;
 		}
 		else
 			throw new ImgException(Img::t('error', 'Failed to delete image! Record could not be found.'));
 			
 			if(file_exists($path)!==false && unlink($path)===false)
 				throw new ImgException(Img::t('error', 'Failed to delete the image version! File could not be deleted.'));
+
+			return true;
 		}
 		else
 			throw new ImgException(Img::t('error', 'Failed to delete image version! Version is unknown.'));
 	 */
 	protected function resolveImagePath($image)
 	{
-		return $this->getImagePath(true).$image->getPath();
+		return $this->getOriginalPath(true).$image->getPath();
 	}
 
 	/**
 		$path=$this->getVersionBasePath($absolute).$version.'/';
 
 		// Might be a new version so we need to create the path if it doesn't exist.
-		if(!file_exists($path))
-			mkdir($path);
+		if($absolute && !file_exists($path))
+			$this->createDirectory($path);
 
 		return $path;
 	}
 
 	/**
-	 * Returns the image version path.
+	 * Returns the path to the original images.
+	 * @param boolean $absolute whether or not the path should be absolute.
+	 * @return string the path.
+	 */
+	protected function getOriginalPath($absolute=false)
+	{
+		$path='';
+
+		if($absolute===true)
+			$path.=$this->getBasePath();
+
+		if($this->_originalBasePath!==null)
+			$path.=$this->_originalBasePath;
+		else
+			$path.=$this->_originalBasePath = $this->getImagePath().'original/';
+
+		return $path;
+	}
+
+	/**
+	 * Returns the path to the versioned images.
 	 * @param boolean $absolute whether or not the path should be absolute.
 	 * @return string the path.
 	 */
 	}
 
 	/**
-	 * Normalizes the given string by replacing special characters. �=>a, �=>e, �=>o, etc.
+	 * Normalizes the given string by replacing special characters. �=>a, �=>e, �=>o, etc.
 	 * @param string $string the text to normalize.
 	 * @return string the normalized string.
 	 * @since 1.2.0
 	 */
 	protected function normalizeString($string)
 	{
-		$string=str_replace(str_split('/\?%*:|"<>. '),'',$string);
-		$string=preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i','$1',htmlentities($string,ENT_QUOTES,'UTF-8'));
+		$string=str_replace(str_split('-/\?%*:|"<>. '),'',$string);
+		$string=preg_replace('/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);/i','$1',htmlentities($string,ENT_QUOTES,'UTF-8'));
+		$string=preg_replace('/&.+;/','',$string);
 		return $string;
 	}
 

components/ImgRecordBehavior.php

 class ImgRecordBehavior extends CBehavior
 {
 	/**
-	 * @property string the image id attribute. Defaults to "imageId".
+	 * @var string the image id attribute. Defaults to "imageId".
 	 * @since 1.2.0
 	 */
 	public $attribute='imageId';
 	}
 
 	/**
+	 * Deletes the image for the owner of this behavior.
+	 * @return boolean whether the image was deleted.
+	 */
+	public function deleteImage()
+	{
+		if ($this->owner->hasAttribute($this->attribute))
+			return Yii::app()->image->delete($this->owner->{$this->attribute});
+		else
+			return false;
+	}
+
+	/**
 	 * Renders the image for the owner of this behavior.
 	 * @param string $version the name of the image version.
 	 * @param string $alt the image alternative text.
 		{
 			$image=Yii::app()->image->loadModel($this->owner->{$this->attribute});
 
-			if ($image!==null)
+			if($image!==null)
 				$image->render($version,$alt,$htmlOptions);
 		}
 	}

controllers/DefaultController.php

  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  * @since 0.5
  */
-class DefaultController extends Controller
+class DefaultController extends CController
 {
 	/**
 	 * Default auction, redirects to the home URL.

controllers/InstallController.php

  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  * @since 0.5
  */
-class InstallController extends Controller
+class InstallController extends CController
 {
 	/**
 	 * Creates and renders a new version of a specific image.
 	 */
 	public function tableName()
 	{
-		return 'Image';
+		return 'image';
 	}
 
 	/**