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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<?php
require_once('utils.php');
need_auth();
function is_valid_path($kind,$path) {
$fullpath=(($kind=='media')?'media/':'content/').$path.'/'.$name;
return is_dir($fullpath);
}
function add_fold($kind,$path,$name) {
$fullpath=(($kind=='media')?'media/':'content/').$path.'/'.$name;
return mkdir($fullpath)===1?0:E_SYSTEM_ERROR;
}
function add_media($path,$name) {
//TODO
}
function add_page($path,$name) {
if ( $res=add_fold('page',$path,$name) ) {
$props = array(
'page_template' => 'default', //TODO : not static
'page_layout' => 'article',
'page_title' => '(missing)',
'page_description' => '(missing)',
'page_keywords' => '(missing)'
);
$ini_path="content/$path/$name/props.ini";
$res=write_ini_file($props, $ini_path, false);
}
return $res;
}
// TODO : choose between unix convention (0 is fine, else is error) and PHP one (FALSE is error, else is okay)
function do_action($kind,$action,$path,$name) {
if ($action==='none') return 0;
if ($name==='') return E_INVALID_NAME;
if ( ! is_valid_path($kind,$path) ) return E_INVALID_PATH;
if ( is_valid_path($kind,$path . '/' . $name) ) return E_INVALID_NAME;
switch ($action) {
case 'add_fold':
return add_fold($kind,$path,$name);
break;
case 'add_item':
if ( $kind=='media' ) {
return add_media($path,$name);
} else {
return add_page($path,$name);
}
break;
default:
return E_INVALID_ACTION;
}
}
// Config loading
$site_conf = load_ini_site_conf("content/site_conf.ini");
if ( ! is_array($site_conf) ) trigger_error("Error parsing site_conf.ini", E_USER_ERROR);
// Localization Init
l10n_init($site_conf['site_admin_lang']);
$default_path = _('(choose a folder in the tree)');
// URL parameter parsing
$kind = sanitize($_GET, 'kind', RE_IDENTIFIER_CLEANER, 'page'); /* Could be : page, media */
$action=sanitize($_GET, 'action', RE_IDENTIFIER_CLEANER, 'none'); /* Could be : none, add_fold, add_item */
$path = sanitize($_GET, 'path', RE_RELPATH_CLEANER, $default_path);
$name = sanitize($_GET, 'name', RE_IDENTIFIER_CLEANER, '');
// Pre-computed because used twice
$page_title = _('Admin') . ' - ' . ( ($kind=='media')?_('Add or remove a media'):_('Add or remove a page') );
$res=do_action($kind,$action,$path,$name);
if ($res===E_INVALID_PATH) $path = $default_path;
//echo "<pre>\$res==$res</pre>\n";
//TODO : user feedback for success/failure
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="treeview.css">
<link rel="stylesheet" href="admin.css">
<script type="text/javascript" src="admin.js"></script>
<title><?=$page_title?></title>
</head>
<body>
<h1><?=$page_title?></h1>
<form>
<span class="inline_half">
<fieldset>
<legend><?=($kind=='media')?_('Media tree'):_('Page tree')?></legend>
<div class="css-treeview">
<?php
if ($kind=='media') {
$tree=find_all('../media', 'media');
} else {
$tree=find_all('./content', 'page');
}
php_array_to_tree($tree, 'select_fold');
?>
</div>
</fieldset>
</span><!-- No blanks here, important for CSS --><span class="inline_half">
<fieldset>
<legend><?=_('Selected folder')?></legend>
<label for="fold_path"><?=_('Folder path')?></label>
<input id="fold_path" name="fold_path" readonly="readonly" value="<?=$path?>"><br>
<label for="fold_add_name"><?=_('New item name')?></label>
<input id="fold_add_name" type="text" value=""><br>
<label for="fold_add_item"><?=_('Actions')?></label>
<input id="fold_add_item" type="button" value="<?=($kind=='media')?_('Add media'):_('Add page')?>" onclick="go_add('<?=$kind?>','item');">
<input id="fold_add_fold" type="button" value="<?=_('Add folder')?>" onclick="go_add('<?=$kind?>','fold');">
</fieldset>
</span><!-- No blanks here, important for CSS --><span class="inline_half">
<input id="fold_back_admin" type="button" value="<?=_('Back to admin')?>" onclick="go_admin_page();">
</span>
</form>
</body>
</html>
|