diff --git a/api/api_system.php b/api/api_system.php index ed45ef4..736e2e0 100644 --- a/api/api_system.php +++ b/api/api_system.php @@ -31,8 +31,8 @@ class api_system extends api_login{ public static function call_locale($request,$lang){ return \SYSTEM\LOG\JsonResult::toString(\SYSTEM\locale::getStrings($request, $lang));} - public static function call_img($cat,$id = null){ - return \SYSTEM\IMG\img::get($cat, $id, true);} + public static function call_files($cat,$id = null){ + return \SYSTEM\FILES\files::get($cat, $id, true);} public static function static__lang($lang){ \SYSTEM\locale::set($lang);} diff --git a/autoload.inc.php b/autoload.inc.php index 0db345c..c718e94 100644 --- a/autoload.inc.php +++ b/autoload.inc.php @@ -33,7 +33,7 @@ require_once dirname(__FILE__).'/system/autoload.php'; \SYSTEM\autoload::registerFolder(dirname(__FILE__).'/sai','SYSTEM\SAI'); \SYSTEM\autoload::registerFolder(dirname(__FILE__).'/docu','SYSTEM\DOCU'); -\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/img','SYSTEM\IMG'); +\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/files','SYSTEM\FILES'); require_once dirname(__FILE__).'/lib/autoload.inc.php'; require_once dirname(__FILE__).'/docu/register_sys_docu.php'; diff --git a/files/files.php b/files/files.php new file mode 100644 index 0000000..40d913d --- /dev/null +++ b/files/files.php @@ -0,0 +1,59 @@ + path) + + public static function registerFolder($path, $cat) { + self::$folders[$cat] = $path;} + + public static function get($cat = null, $id = null, $returnasjson = false) { + if (!$cat) { + return $returnasjson ? \SYSTEM\LOG\JsonResult::toString(self::$folders) : self::$folders;} + + if (!array_key_exists($cat, self::$folders)) { + throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} + + $folder = self::getFolder(self::$folders[$cat]); + if ($id == null) { + return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder;} + + if (!in_array($id, $folder)) { + throw new \SYSTEM\LOG\ERROR("No matching ID '" . $id . "' found.");} + + \SYSTEM\HEADER::PNG(); + return file_get_contents(self::$folders[$cat].$id); + } + + public static function put($cat, $id, $contents) { + if (!array_key_exists($cat, self::$folders)) { + throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} + return move_uploaded_file($contents, self::$folders[$cat].$id); + } + + public static function delete($cat, $id) { + if (!array_key_exists($cat, self::$folders)) { + throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} + if(!file_exists(self::$folders[$cat].$id)){ + return false;} + return unlink(self::$folders[$cat].$id); + } + + public static function rename($cat, $id, $newid) { + if (!array_key_exists($cat, self::$folders)) { + throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} + if(!file_exists(self::$folders[$cat].$id)){ + return false;} + return rename(self::$folders[$cat].$id, self::$folders[$cat].$newid); + } + + private static function getFolder($folder) { + $files = array(); + foreach (glob($folder.'*') as $file) { + $files[] = basename($file);} + return $files; + } + + public static function getURL($cat, $id = null) { + return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL) . 'api.php?call=files&cat=' . $cat . '&id=' . $id;} +} \ No newline at end of file diff --git a/img/img.php b/img/img.php deleted file mode 100644 index f55a8bd..0000000 --- a/img/img.php +++ /dev/null @@ -1,69 +0,0 @@ - array(2.path 3.mask))* - - public static function registerFolder($path, $cat, $mask) { - self::$imgfolders[$cat] = array($path, $mask); - } - - public static function get($cat = null, $id = null, $returnasjson = false) { - if (!$cat) { - return $returnasjson ? \SYSTEM\LOG\JsonResult::toString(self::$imgfolders) : 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]); - if ($id == null) { - return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder; - } - - 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) { - if (!array_key_exists($cat, self::$imgfolders)) { - throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} - return move_uploaded_file($contents, self::$imgfolders[$cat][0].$id); - } - - public static function delete($cat, $id) { - if (!array_key_exists($cat, self::$imgfolders)) { - throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} - if(!file_exists(self::$imgfolders[$cat][0].$id)){ - return false;} - return unlink(self::$imgfolders[$cat][0].$id); - } - - public static function rename($cat, $id, $newid) { - if (!array_key_exists($cat, self::$imgfolders)) { - throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");} - if(!file_exists(self::$imgfolders[$cat][0].$id)){ - return false;} - return rename(self::$imgfolders[$cat][0].$id, self::$imgfolders[$cat][0].$newid.substr(self::$imgfolders[$cat][1],1)); - } - - private static function getFolder($folder, $mask) { - $files = array(); - foreach (glob($folder . $mask,GLOB_BRACE) as $file) { - $files[] = basename($file); - } - return $files; - } - - public static function getURL($cat, $id = null) { - return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL) . 'api.php?call=img&cat=' . $cat . '&id=' . $id; - } - -} diff --git a/sai/modules/autoload_modules.php b/sai/modules/autoload_modules.php index e82a55a..b06e339 100644 --- a/sai/modules/autoload_modules.php +++ b/sai/modules/autoload_modules.php @@ -11,4 +11,4 @@ SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_locale','SYSTEM\S SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_cache','SYSTEM\SAI'); SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_docu','SYSTEM\SAI'); SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_todo','SYSTEM\SAI'); -SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_img','SYSTEM\SAI'); \ No newline at end of file +SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_files','SYSTEM\SAI'); \ No newline at end of file diff --git a/sai/modules/register_modules.php b/sai/modules/register_modules.php index 7f869ce..5c4c50b 100644 --- a/sai/modules/register_modules.php +++ b/sai/modules/register_modules.php @@ -5,7 +5,7 @@ \SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_config'); \SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_api'); \SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_locale'); -\SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_img'); +\SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_files'); \SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_cache'); \SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_todo'); \SYSTEM\SAI\sai::register_sys('\SYSTEM\SAI\saimod_sys_docu'); diff --git a/sai/modules/saimod_sys_img/sai_sys_img.js b/sai/modules/saimod_sys_files/sai_sys_files.js similarity index 100% rename from sai/modules/saimod_sys_img/sai_sys_img.js rename to sai/modules/saimod_sys_files/sai_sys_files.js diff --git a/sai/modules/saimod_sys_img/saimod_sys_img.php b/sai/modules/saimod_sys_files/saimod_sys_files.php similarity index 59% rename from sai/modules/saimod_sys_img/saimod_sys_img.php rename to sai/modules/saimod_sys_files/saimod_sys_files.php index f34925e..8487859 100644 --- a/sai/modules/saimod_sys_img/saimod_sys_img.php +++ b/sai/modules/saimod_sys_files/saimod_sys_files.php @@ -1,36 +1,36 @@ $folder){ - $cat = \SYSTEM\IMG\img::get($name); + foreach($file_folders as $name=>$folder){ + $cat = \SYSTEM\FILES\files::get($name); $result .= "