summaryrefslogtreecommitdiff
path: root/code/admin/ajax.php
blob: fd6dab5149655da02e7c8f991dc0db9ee306bbdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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) {
		$props=load_page_props($path);

		foreach ( array('page_title', 'page_description', 'page_keywords') as $k ) {
			if ( array_key_exists($k,$_GET) ) {
				$props[$k]= sanitize($_GET, $k, RE_TEXT_LINE_CLEANER, '');
			}
		}

		$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', RE_IDENTIFIER_CLEANER, 'none'); /* Could be : load_page_props, load_media_props... */
	$path = sanitize($_GET, 'path', RE_RELPATH_CLEANER, ''); 

	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);
?>