workin proto img

This commit is contained in:
Ulf Gebhardt 2013-11-12 16:40:03 +01:00
parent 6ccee2307e
commit ceba006772

View File

@ -4,19 +4,22 @@ namespace SYSTEM\IMG;
class img { class img {
private static $imgfolders = array(); //only strings! (catname => array(2.path 3.mask))* 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);} self::$imgfolders[$cat] = array($path,$mask);}
public static function get($cat,$id = null,$returnasjson=false){ public static function get($cat,$id = null,$returnasjson = false){
$result = null; if(!array_key_exists($cat, self::$imgfolders)){
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]);
$result = ($id == null) ? $folder : (array_key_exists($id, $folder)) ? file_get_contents($folder[$id]) : null;}
if($returnasjson && $result == null){ $folder = self::getFolder(self::$imgfolders[$cat][0],self::$imgfolders[$cat][1]);
throw new \SYSTEM\LOG\ERROR("No matching Cat '".$cat."' or Key '".$id."' found or Folder is empty.");} if($id == null){
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder;}
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($result) : $result; if(!in_array($id, $folder)){
throw new \SYSTEM\LOG\ERROR("No matching ID '".$id."' found.");}
\SYSTEM\HEADER::PNG();
return file_get_contents(self::$imgfolders[$cat][0].$id);
} }
public static function put($cat,$id,$contents){ public static function put($cat,$id,$contents){
@ -25,7 +28,7 @@ class img {
private static function getFolder($folder,$mask){ private static function getFolder($folder,$mask){
$files = array(); $files = array();
foreach (glob($folder.$mask) as $file) { foreach (glob($folder.$mask) as $file) {
$files[] = $file;} $files[] = basename($file);}
return $files; return $files;
} }