Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tablePrefix support and image error fix

  • Loading branch information...
commit 70a0ba17b637c45b852f0f487a4756f65c3ce1d9 1 parent d4d0be0
sandra1n authored
Showing with 43 additions and 17 deletions.
  1. +3 −0  README.md
  2. +39 −16 iwi/Iwi.php
  3. +1 −1  iwi/models/Storage.php
View
3  README.md
@@ -59,6 +59,9 @@ Use `adaptive()` method now.
Changelog
=====================
+### November 03, 2012
+* Added support of tablePrefix. Requested by the user: kernel32ddl
+* Fix error if image doesn't exist
#### July 25, 2012
* Recreating cache if cache is missing
View
55 iwi/Iwi.php
@@ -5,8 +5,12 @@
class Iwi extends Image
{
-
-
+ /**
+ * @param $width
+ * @param $height
+ * @param bool $upscale
+ * @return Iwi|object
+ */
public function adaptive($width, $height, $upscale = false)
{
@@ -29,9 +33,7 @@ public function adaptive($width, $height, $upscale = false)
if ($widthProportion > $heightProportion) {
$newWidth = $width;
$newHeight = round($newWidth / $this->image["width"] * $this->image["height"]);
- }
- else
- {
+ } else {
$newHeight = $height;
$newWidth = round($newHeight / $this->image["height"] * $this->image["width"]);
}
@@ -41,12 +43,15 @@ public function adaptive($width, $height, $upscale = false)
return $this->crop($width, $height, "center");
}
- return false;
+ return $this;
}
+ /**
+ * @return mixed
+ */
public function cache()
{
- $path = $this->buildPath() ? : "";
+ $path = $this->buildPath();
if ($path) {
if ($this->createOrNone() || !file_exists($path)) {
$this->save($path);
@@ -55,6 +60,9 @@ public function cache()
return Yii::app()->createUrl($path);
}
+ /**
+ * @return bool|string
+ */
public function buildPath()
{
if (!isset($this->image["file"])) {
@@ -67,6 +75,9 @@ public function buildPath()
return implode("/", $path);
}
+ /**
+ * @return string
+ */
public function buildDir()
{
$folder[] = YiiBase::getPathOfAlias('webroot.images.site.cache');
@@ -87,22 +98,29 @@ public function buildDir()
return $path;
}
+ /**
+ * @return string
+ */
public function hash()
{
return md5($this->generateBrief());
}
-
+ /**
+ * @return string
+ */
protected function generateBrief()
{
$needle = $this->actions;
array_unshift($needle, $this->image["file"]);
- if(is_file($this->image["file"]))
+ if (is_file($this->image["file"]))
array_unshift($needle, filemtime($this->image["file"]));
return json_encode($needle);
}
-
+ /**
+ * @return bool
+ */
public function createOrNone()
{
$this->verifyTable();
@@ -116,17 +134,23 @@ public function createOrNone()
return false;
}
+ /**
+ * Verify table
+ */
public function verifyTable()
{
- if (!Yii::app()->getDb()->schema->getTable('storage')) {
- Yii::app()->getDb()->createCommand()->createTable("storage", array(
+ if (!Yii::app()->getDb()->schema->getTable('{{storage}}')) {
+ Yii::app()->getDb()->createCommand()->createTable("{{storage}}", array(
'key' => 'string',
'value' => 'text',
));
}
}
-
+ /**
+ * @param $image
+ * @param null $config
+ */
// changed exception
public function __construct($image, $config = NULL)
{
@@ -140,7 +164,7 @@ public function __construct($image, $config = NULL)
// Check to make sure the image exists
if (!is_file($image))
- return false;
+ return $this;
// Disable error reporting, to prevent PHP warnings
$ER = error_reporting(0);
@@ -176,8 +200,7 @@ public function __construct($image, $config = NULL)
'driver' => 'GD',
'params' => array(),
);
- }
- else {
+ } else {
$this->config = $config;
}
View
2  iwi/models/Storage.php
@@ -24,7 +24,7 @@ public static function model($className=__CLASS__)
*/
public function tableName()
{
- return 'storage';
+ return '{{storage}}';
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.