diff --git a/modules/Image.php b/modules/Image.php index ff3f27c..e09bbbd 100644 --- a/modules/Image.php +++ b/modules/Image.php @@ -40,19 +40,20 @@ class Image extends \LivingMarkup\Module public function onLoad(){ // load source file info - $this->fetchSourceInfo(); + $src = $this->getArgByName('src'); + $this->fetchSourceInfo($src); // set dimensions - $width = array_key_exists('width', $this->args) ? $this->args['width'] : NULL; - $height = array_key_exists('height', $this->args) ? $this->args['height'] : NULL; + $width = $this->getArgByName('width'); + $height = $this->getArgByName('height'); $this->setDimensions($width, $height); // set offset - $offset = array_key_exists('offset', $this->args) ? $this->args['offset'] : NULL; + $offset = $this->getArgByName('offset'); $this->setOffset($offset); // set alt - $alt = array_key_exists('alt', $this->args) ? $this->args['alt'] : NULL; + $alt = $this->getArgByName('alt'); $this->setCacheURL($alt); } @@ -69,15 +70,11 @@ public function onRender() HTML; } - public function fetchSourceInfo() + public function fetchSourceInfo($source) { - // image missing - if(!isset($this->args['src'])){ - return false; - } // TODO: add traversing prevention - $filepath = __DIR__ . '/..' . self::IMAGE_SOURCE_DIR . $this->args['src']; + $filepath = __DIR__ . '/..' . self::IMAGE_SOURCE_DIR . $source; // get dimensions from original image file [$this->source_width, $this->source_height, $this->source_type, $this->source_attr] = getimagesize($filepath); @@ -133,6 +130,7 @@ public function setOffset($offset){ list($this->offset['x'], $this->offset['y']) = explode(',', $offset); } } + /** * Set dimension (width x height) of output * diff --git a/src/Module.php b/src/Module.php index b7b0fae..58853f5 100644 --- a/src/Module.php +++ b/src/Module.php @@ -91,6 +91,16 @@ public function getId() return $this->module_id; } + /** + * Get Arg by Name + * + * @param $name + * @return mixed|null + */ + public function getArgByName($name){ + return array_key_exists($name, $this->args) ? $this->args[$name] : NULL; + } + /** * Abstract output method called by magic method *