From e49c5760a83283889c2803dcf857ae731ec4d915 Mon Sep 17 00:00:00 2001 From: Shoaib Nawaz Date: Thu, 1 Sep 2016 23:01:51 +0500 Subject: [PATCH] Priority file source location for configured templates are introduced --- .../Image/ImageCacheController.php | 16 +++++++++++-- src/config/config.php | 24 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index 7fca05d..1bc812d 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -41,8 +41,8 @@ public function getResponse($template, $filename) */ public function getImage($template, $filename) { + $path = $this->getImagePath($filename, $template); $template = $this->getTemplate($template); - $path = $this->getImagePath($filename); // image manipulation based on callback $manager = new ImageManager(Config::get('image')); @@ -122,8 +122,20 @@ private function getTemplate($template) * @param string $filename * @return string */ - private function getImagePath($filename) + private function getImagePath($filename, $template=null) { + // find file in priority locations + if(!is_null($template) && array_key_exists($template, config('imagecache.priority_paths'))) { + foreach(config("imagecache.priority_paths.$template") as $path) { + // don't allow '..' in filenames + $image_path = $path.'/'.str_replace('..', '', $filename); + if (file_exists($image_path) && is_file($image_path)) { + // file found + return $image_path; + } + } + } + // find file foreach (config('imagecache.paths') as $path) { // don't allow '..' in filenames diff --git a/src/config/config.php b/src/config/config.php index 84f656b..778e763 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -35,6 +35,30 @@ public_path('images') ), + /* + |-------------------------------------------------------------------------- + | Priority Storage Paths + |-------------------------------------------------------------------------- + | + | Here you can associte some image source paths + | specific to a particular tempalate. + | + | Example: + | + | 'blog' => array( + | public_path('images/blog'), + | public_path('upload/blog'), + | ), + | 'profile' => array( + | public_path('upload/profile'), + | ), + | + */ + + 'priority_paths' => array( + + ), + /* |-------------------------------------------------------------------------- | Manipulation templates