diff options
Diffstat (limited to 'code/admin/ajax.php')
-rw-r--r-- | code/admin/ajax.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/code/admin/ajax.php b/code/admin/ajax.php new file mode 100644 index 0000000..0893843 --- /dev/null +++ b/code/admin/ajax.php @@ -0,0 +1,63 @@ +<?php + require_once('utils.php'); + need_auth(); + + function load_page_props($path) { + return load_ini_page_props($path); + } + + function load_media_props($path) { + return array( + 'media_title' => 'test title', + 'media_description' => 'test descr', + 'media_keywords' => 'test, keyword', + ); + } + + function save_page_props($path) { + //TODO : Should validate props here also... + $props=load_page_props($path); + + foreach ( array('page_title', 'page_description', 'page_keywords') as $k ) { + if ( array_key_exists($k,$_GET) ) $props[$k]=$_GET[$k]; + } + + $ini_path="content/$path/props.ini"; + return write_ini_file($props, $ini_path, false); + } + + function save_media_props($path) { + return FALSE; + } + + // URL params clean-up + $action=sanitize($_GET, 'action', '/[^a-z_]+/', 'none'); /* Could be : load_page_props, load_media_props... */ + $path=sanitize($_GET, 'path', '/[^a-z0-9\/]+/', ''); // Never put \. in this regex + + switch($action) { + case 'load_page_props': + $res = load_page_props($path); + break; + case 'load_media_props': + $res = load_media_props($path); + break; + case 'save_page_props': + if ( save_page_props($path) ) { + $res=array('result' => 'OK'); + } else { + $res=array('result' => 'FAILED'); + } + break; + case 'save_media_props': + if ( save_media_props($path) ) { + $res=array('result' => 'OK'); + } else { + $res=array('result' => 'FAILED'); + } + break; + default: + $res = array('result' => 'ERROR', 'error'=>'invalid action'); + break; + } + echo json_encode($res); +?> |