changed img -> files

This commit is contained in:
Ulf Gebhardt 2014-05-19 04:02:09 +02:00
parent 029d90c0bc
commit 41655484f4
9 changed files with 80 additions and 90 deletions

View File

@ -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);}

View File

@ -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';

59
files/files.php Normal file
View File

@ -0,0 +1,59 @@
<?php
namespace SYSTEM\FILES;
class files {
private static $folders = array(); //only strings! array(catname => 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;}
}

View File

@ -1,69 +0,0 @@
<?php
namespace SYSTEM\IMG;
class img {
private static $imgfolders = array(); //only strings! (catname => 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;
}
}

View File

@ -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');
SYSTEM\autoload::registerFolder(dirname(__FILE__).'/saimod_sys_files','SYSTEM\SAI');

View File

@ -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');

View File

@ -1,36 +1,36 @@
<?php
namespace SYSTEM\SAI;
class saimod_sys_img extends \SYSTEM\SAI\SaiModule {
public static function sai_mod__SYSTEM_SAI_saimod_sys_img_action_del($cat,$id){
class saimod_sys_files extends \SYSTEM\SAI\SaiModule {
public static function sai_mod__SYSTEM_SAI_saimod_sys_files_action_del($cat,$id){
if(!\SYSTEM\IMG\img::delete($cat, $id)){
throw new \SYSTEM\LOG\ERROR("delete problem");}
return \SYSTEM\LOG\JsonResult::ok();
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_img_action_rn($cat,$id,$newid){
public static function sai_mod__SYSTEM_SAI_saimod_sys_files_action_rn($cat,$id,$newid){
if(!\SYSTEM\IMG\img::rename($cat, $id, $newid)){
throw new \SYSTEM\LOG\ERROR("rename problem");}
return \SYSTEM\LOG\JsonResult::ok();
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_img_action_upload($cat){
public static function sai_mod__SYSTEM_SAI_saimod_sys_files_action_upload($cat){
if(!\SYSTEM\IMG\img::put($cat, basename($_FILES['datei']['name']) , $_FILES['datei']['tmp_name'])){
throw new \SYSTEM\LOG\ERROR("upload problem");}
return \SYSTEM\LOG\JsonResult::ok();
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_img(){
public static function sai_mod__SYSTEM_SAI_saimod_sys_files(){
//tt
$result = '';
$img_folders = \SYSTEM\IMG\img::get();
$file_folders = \SYSTEM\FILES\files::get();
$i = 0;
foreach($img_folders as $name=>$folder){
$cat = \SYSTEM\IMG\img::get($name);
foreach($file_folders as $name=>$folder){
$cat = \SYSTEM\FILES\files::get($name);
$result .= "<h3>".$name."</h3>";
$result .= '<form action="'.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_BASEURL).'sai_mod=.SYSTEM.SAI.saimod_sys_img&action=upload&cat='.$name.'" method="post" enctype="multipart/form-data">';
$result .= '<form action="'.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_BASEURL).'sai_mod=.SYSTEM.SAI.saimod_sys_files&action=upload&cat='.$name.'" method="post" enctype="multipart/form-data">';
$result .= //'<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
'<input type="file" name="datei"><br>
<input type="submit" class="btn" value="Add">';
@ -38,7 +38,7 @@ class saimod_sys_img extends \SYSTEM\SAI\SaiModule {
$result .= "<table><tr><th>Delete</th><th>Name</th><th>new name</th><th>Rename</th></tr>";
foreach($cat as $img){
//$result .= '<img src="api.php?call=img&cat='.$name.'&id='.$img.'" alt="" />';
$result .= '<tr><td><input type="button" class="btn-danger imgdelbtn" style="margin: 1px; margin-right: 3px" value="Delete" cat="'.$name.'" id="'.$img.'"></td><td><a href="api.php?call=img&cat='.$name.'&id='.$img.'">'.$img.'</a></td><td><input type="text" id="renametext_'.$i.'" class="form-control" style="width: 100px; margin:0;" placeholder="new name..."></td><td><input type="submit" class="btn-warning imgrnbtn" style="margin: 1px;;" value="Rename" cat="'.$name.'" id="'.$img.'" textfield="'.$i.'"></td></tr>';
$result .= '<tr><td><input type="button" class="btn-danger imgdelbtn" style="margin: 1px; margin-right: 3px" value="Delete" cat="'.$name.'" id="'.$img.'"></td><td><a href="api.php?call=files&cat='.$name.'&id='.$img.'">'.$img.'</a></td><td><input type="text" id="renametext_'.$i.'" class="form-control" style="width: 100px; margin:0;" placeholder="new name..."></td><td><input type="submit" class="btn-warning imgrnbtn" style="margin: 1px;;" value="Rename" cat="'.$name.'" id="'.$img.'" textfield="'.$i.'"></td></tr>';
$i++;
}
$result .= "</table>";
@ -46,11 +46,11 @@ class saimod_sys_img extends \SYSTEM\SAI\SaiModule {
return $result;
}
public static function html_li_menu(){return '<li><a href="#" saimenu=".SYSTEM.SAI.saimod_sys_img">Img</a></li>';}
public static function html_li_menu(){return '<li><a href="#" saimenu=".SYSTEM.SAI.saimod_sys_files">Files</a></li>';}
public static function right_public(){return false;}
public static function right_right(){return \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI) && \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI_IMG);}
public static function right_right(){return \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI) && \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI_FILES);}
public static function sai_mod__SYSTEM_SAI_saimod_sys_img_flag_css(){}
public static function sai_mod__SYSTEM_SAI_saimod_sys_img_flag_js(){return \SYSTEM\LOG\JsonResult::toString(
array( \SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_img/sai_sys_img.js')));}
public static function sai_mod__SYSTEM_SAI_saimod_sys_files_flag_css(){}
public static function sai_mod__SYSTEM_SAI_saimod_sys_files_flag_js(){return \SYSTEM\LOG\JsonResult::toString(
array( \SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_img/sai_sys_files.js')));}
}

View File

@ -13,7 +13,7 @@ class RIGHTS {
//Database Text Module
const SYS_SAI_LOCALE = 10;
//Image Module
const SYS_SAI_IMG = 15;
const SYS_SAI_FILES = 15;
//Reserve first 1000 ids.
const RESERVED_SYS_0_999 = 999;