admin_stat_pages2.php
7.66 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* @author: Bunzia Alexander <nifus@mail.ru> <http://www.weblancer.net/users/nifus/>
* @copyright: Copyright (c) 2010, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @package HiLo CMS
*/
/*
* управление статичными страничками на сайте
*
*/
class admin_stat_pages{
private $error = false;
private $act = 'index';
private $JsHttpRequest = false;
public function __construct(){
global $MAIN_PAGE;
define('M_PATH',MAIN_SOURCE_PATH.'/modules/'.$MAIN_PAGE -> dirname() );
define('M_URL',MAIN_SOURCE_URL.'/modules/'.$MAIN_PAGE -> dirname() );
define('A_CHARSET', $MAIN_PAGE -> charset() );
include_once(M_PATH.'/inc/url.php');
include_once(M_PATH.'/inc/class.stat_pages.php');
//include_once(M_PATH.'/inc/class.modules.php');
include_once(MAIN_SOURCE_PATH.'/modules/admin/lang/'.MAIN_LANG.'/lang.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.html.php');
include(MAIN_SOURCE_PATH.'/ext/ajax/JsHttpRequest.php');
$this -> JsHttpRequest = new JsHttpRequest( A_CHARSET );
$this -> act = !empty($_REQUEST['act']) ? $_REQUEST['act'] : $this -> act;
$GLOBALS['_RESULT']['id_request'] = !empty($_REQUEST['id_request']) ? $_REQUEST['id_request'] : 0;
}
public function get(){
//sleep(2);
$func = $this -> act;
if ( !method_exists($this ,$func) ){
sys_error(ERROR_404);
}
return $this -> $func();
}
// выводим заданную страницу
private function ajax_view(){
sys_block_disable();
$p = new stat_pages_q('f');
$p -> include_tmpl('t','t.t_path');
$url = preg_replace('#^/#','',$_REQUEST['url']);
if (! $p -> where_url($url) ){
sys_error(ERROR_404);
}
//$p -> set_debug(1);
$p -> get('f.*,f.p_id as check_access',false);
$row = $p -> row();
if ( !is_array($row)){
exit();
}
if ( !$row['check_access'] ){
exit();
}
// меняем вывод блоков
//$MAIN_PAGE -> set_tmpl_id($row['t_id']);
// меняем вывод шаблона
//$MAIN_PAGE -> set_tmpl($row['t_path']);
$GLOBALS['_RESULT']['content'] = $row['p_content'];
$GLOBALS['_RESULT']['title'] =$row['p_meta_title'];
exit();
}
// выводим заданную страницу
private function view(){
global $MAIN_PAGE;
$p = new stat_pages_q('f');
$p -> include_tmpl('t','t.t_path');
$url = preg_replace('#^/#','',$_REQUEST['url']);
if (! $p -> where_url($url) ){
sys_error(ERROR_404);
}
//$p -> set_debug(1);
$p -> get('f.*,f.p_id as check_access',false);
$row = $p -> row();
if ( !is_array($row)){
sys_error(ERROR_404);
}
if ( !$row['check_access'] ){
sys_error(ERROR_403);
}
// меняем вывод блоков
$MAIN_PAGE -> set_tmpl_id($row['t_id']);
// меняем вывод шаблона
$MAIN_PAGE -> set_tmpl($row['t_path']);
$MAIN_PAGE -> set_meta_title($row['p_meta_title']);
$MAIN_PAGE -> set_meta_keywords($row['p_meta_desc']);
$MAIN_PAGE -> set_meta_description($row['p_meta_keywords']);
// выдаём контент
if( $row['p_type_content']=='HTML' ){
return $row['p_content'];
}elseif( $row['p_type_content']=='PHP' ){
return eval($row['p_type_content']);
}elseif( $row['p_type_content']=='TMPL'){
// блоки генерим заранее, чтобы на них можно было ссылаться в шаблоне
sys_blocks_enable();
$t = new PHPTAL();
$t -> setSource($row['p_content']);
return $t -> execute();
}
}
// главная, формирует список шаблонов
private function index(){
global $MAIN_USER;
if ( !$MAIN_USER -> is_admin() ){
sys_error(ERROR_403);
}
$t = new PHPTAL( M_PATH.'/tmpl/control_stat_pages/main.html' );
$t -> URL_ADMIN_STAT_PAGES = sys_url(URL_ADMIN_STAT_PAGES);
$t -> URL_ADMIN = sys_url(URL_ADMIN);
$p = new stat_pages_q('f');
$p -> include_tmpl('t','t.t_name as tmpl_name');
$p -> orderby_id('DESC');
$p -> get('f.*',false);
$rows= array();
while( $row = $p -> row() ){
$rows[] = arr_to_obj($row);
}
// редактор
$e = html_control::editor('ck');
$e -> set_name('p_content');
$e -> set_value('');
$e -> set_attr('cols',10);
$t -> editor = $e -> show();
// вывод
$t -> rows = $rows;
return $t -> execute();
}
/* AJAX */
private function ajax_reload(){
global $MAIN_USER;
if ( !$MAIN_USER -> is_admin() ){
sys_error(ERROR_403);
}
sys_block_disable();
$t = new PHPTAL( M_PATH.'/tmpl/control_stat_pages/inc/tmpl_row.html' );
$t -> execute = true;
// выбираем страницы
$p = new stat_pages_q('f');
$p -> include_tmpl('t','t.t_name as tmpl_name');
$p -> orderby_id('DESC');
$p -> get('f.*',false);
$rows= array();
while( $row = $p -> row() ){
$rows[]=$row;
}
$t -> rows = $rows;
$GLOBALS['_RESULT']['content'] = $t -> execute();
exit();
}
// удаляем
private function ajax_delete(){
global $MAIN_USER;
if ( !$MAIN_USER -> is_admin() ){
sys_error(ERROR_403);
}
sys_block_disable();
$m = stat_pages::load_id($_REQUEST['id']);
if ( false===$m ){
die( A_EMPTY_ID );
}
$m -> delete();
exit();
}
// форма редактирвоания $_REQUEST['id']
private function ajax_edit(){
global $MAIN_USER;
if ( !$MAIN_USER -> is_admin() ){
sys_error(ERROR_403);
}
sys_block_disable();
// получаем из базы страницу $_REQUEST['id']
$p = new stat_pages_q('p');
if ( !$p -> where_id($_REQUEST['id']) ){
$row = array();
}else{
$p -> get('*,
p_type_content AS type_content_tmpl,
p_type_content AS type_content_php,
p_type_content AS type_content_html,
p_id as groups');
$row = $p -> row();
}
// подключаем редактор
$row['editor'] = 'p_content';
// список шаблонов
include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/class.tmpl.php');
$p = new tmpl_q('f');
$p -> orderby_tid('DESC');
$p -> get('f.t_id, f.t_name');
$s = new select_box();
$s -> selected_id($row['t_id']);
$s -> empty_record(false);
while( list($t_id,$t_name) = $p -> row() ){
$s -> set($t_id,$t_name );
}
$row['tmpl_list']=$s -> get();
// группы
$g = new group_select_box();
$row['group_list']=$g -> group_list($row['groups']);
// формируем страницу
$t = new PHPTAL( M_PATH.'/tmpl/control_stat_pages/edit.html' );
$t -> row = $row ;
$GLOBALS['_RESULT']['content'] = $t -> execute();
$GLOBALS['_RESULT']['title'] = M_ADMIN_SP_ADD_EDIT_PAGE;
exit();
}
// сохранение формы редактирования
private function ajax_save(){
global $MAIN_USER;
if ( !$MAIN_USER -> is_admin() ){
sys_error(ERROR_403);
}
sys_block_disable();
// загружаем из базы
$p = stat_pages::load_id($_REQUEST['id']);
if ( false===$p ){
define('create',1);
$p = stat_pages::create();
}
// обновляем её
$p -> set('p_url',$_REQUEST['p_url']);
$p -> set('t_id',$_REQUEST['t_id']);
$p -> set('p_content',$_REQUEST['p_content']);
$p -> set('p_meta_title',$_REQUEST['p_meta_title']);
$p -> set('p_meta_keywords',$_REQUEST['p_meta_keywords']);
$p -> set('p_meta_desc',$_REQUEST['p_meta_desc']);
$p -> set('p_type_content',$_REQUEST['p_type_content']);
//$p -> set_debug(1);
if ( create==1 ){
$id = $p -> insert();
}else{
$id = $p -> update();
}
if ( false===$id ){
die( $p -> error() );
}
// обновляем права доступа к страничке
stat_pages::set_groups($id,$_REQUEST['access']);
// обновляем морду
$GLOBALS['_RESULT']['msg'] = M_ADMIN_SP_SAVE;
exit();
}
}
?>