From ceba006772ce80dbd426d2bb945eb9fbc0c948c1 Mon Sep 17 00:00:00 2001 From: rylon Date: Tue, 12 Nov 2013 16:40:03 +0100 Subject: [PATCH] workin proto img --- img/img.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/img/img.php b/img/img.php index 75d1955..595e022 100644 --- a/img/img.php +++ b/img/img.php @@ -4,19 +4,22 @@ namespace SYSTEM\IMG; class img { private static $imgfolders = array(); //only strings! (catname => array(2.path 3.mask))* - public static function registerFolder($cat,$path,$mask){ + public static function registerFolder($path,$cat,$mask){ self::$imgfolders[$cat] = array($path,$mask);} - public static function get($cat,$id = null,$returnasjson=false){ - $result = null; - if(array_key_exists($cat, self::$imgfolders)){ - $folder = self::getFolder(self::$imgfolders[$cat][0],self::$imgfolders[$cat][1]); - $result = ($id == null) ? $folder : (array_key_exists($id, $folder)) ? file_get_contents($folder[$id]) : null;} + public static function get($cat,$id = null,$returnasjson = false){ + if(!array_key_exists($cat, self::$imgfolders)){ + throw new \SYSTEM\LOG\ERROR("No matching Cat '".$cat."' found.");} + + $folder = self::getFolder(self::$imgfolders[$cat][0],self::$imgfolders[$cat][1]); + if($id == null){ + return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder;} - if($returnasjson && $result == null){ - throw new \SYSTEM\LOG\ERROR("No matching Cat '".$cat."' or Key '".$id."' found or Folder is empty.");} + if(!in_array($id, $folder)){ + throw new \SYSTEM\LOG\ERROR("No matching ID '".$id."' found.");} - return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($result) : $result; + \SYSTEM\HEADER::PNG(); + return file_get_contents(self::$imgfolders[$cat][0].$id); } public static function put($cat,$id,$contents){ @@ -25,7 +28,7 @@ class img { private static function getFolder($folder,$mask){ $files = array(); foreach (glob($folder.$mask) as $file) { - $files[] = $file;} + $files[] = basename($file);} return $files; }