class.staticPages.php
8.3 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?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
*/
include_once(MAIN_SOURCE_PATH.'/inc/class.query.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.objects.php');
include_once(MAIN_SOURCE_PATH.'/modules/admin/lang/'.MAIN_LANG.'/lang.php');
class filedsSetStaticPages
{
//static $id = false; // адрес новости
static function p_type_content($v){
if ( empty($v) ){
return true;
}
$values = array('HTML','PHP','TMPL');
if ( !in_array($v,$values) ){
throw new Exception( M_ADMIN_BLOCKS_FALSE_TYPE_CONTENT );
}
return $v;
}
static function p_title($v){
$v = trim($v);
if ( empty($v) ){
throw new Exception( 'Ошибка: нужно заполнить поле "Название страницы"!' );
}
return $v;
}
static function p_url($v,$obj){
if ( empty($v) ){
throw new Exception( M_ADMIN_SP_EMPTY_URL );
}
if ( false!==staticPages::isExistsUrl($v,$obj-> id() ) ){
throw new Exception( 'Ошибка: адрес "'.$v.'" уже используется!' );
}
return $v;
}
static function t_id($v){
$v = intval($v);
if ( empty($v) ){
throw new Exception( M_ADMIN_SP_EMPTY_TMPL );
}
return $v;
}
static function free_access($v){
return !empty($v) ? '1' : '0';
}
}
class filedsGetStaticPages
{
static $__var = array(); // для хранения временных переменных
static function free_access($v){
return !empty($v) ? 'checked' : '';
}
static function tmpl_list($v){
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($v);
$s -> empty_record(false);
while( list($t_id,$t_name) = $p -> row() ){
$s -> set($t_id,$t_name );
}
return $s -> get();
}
static function type_content_php($v){
if ( $v=='PHP'){
return true;
}else{
return false;
}
}
static function type_content_html($v){
if ( $v=='HTML'){
return true;
}else{
return false;
}
}
static function type_content_tmpl($v){
if ( $v=='TMPL'){
return true;
}else{
return false;
}
}
// возвращаем список групп допущенных к просмотру страницы
static function groups($v){
global $MAIN_DB;
// группы
$sql = "SELECT g_id,g_name FROM ".$MAIN_DB -> prefix("system_groups")." WHERE hidden='0'";
$res = $MAIN_DB -> query($sql);
$groups = array();
while( $row = $MAIN_DB -> fetch_array($res) )
{
$groups[$row['g_id']]=$row;
}
if ( empty($v) ){
return $groups;
}
// допущенные
$sql = "SELECT g_id FROM ".$MAIN_DB -> prefix("system_stat_pages_groups_link")." WHERE p_id='$v'";
$res = $MAIN_DB -> query($sql);
while(list($g_id) = $MAIN_DB -> fetch_array($res) ){
$groups[$g_id]['checked']=true;
}
return $groups;
}
// проверяем доступ группы к странице v
static function check_access($v,$row){
global $MAIN_DB,$MAIN_USER;
if ( ($row['free_access']==1) )
{
return true;
}
// если перед нами языковая копия, то пользуемся правами оригинала
if ( $row['p_id']!=$row['link_id'] ){
$v = $row['link_id'];
}
$g_id = $MAIN_USER -> group();
$sql = "
SELECT count(*)
FROM ".$MAIN_DB -> prefix("system_stat_pages_groups_link")."
WHERE p_id='$v' AND g_id='$g_id'";
list($count) = $MAIN_DB -> fetch_array( $MAIN_DB -> query($sql) );
if ( $count>0 ){
return true;
}else{
return false;
}
}
static function lang_list($v){
if ( !defined('MAIN_LANGS') ){
return false;
}
$langs = explode(',',MAIN_LANGS);
$s = new select_box();
$s -> selected_id($v);
$s -> empty_record(false);
foreach( $langs as $lng )
{
$s -> set($lng,$lng);
}
return $s -> get();
}
static function lang_links($v){
if ( !defined('MAIN_LANGS') ){
return false;
}
$langs = explode(',',MAIN_LANGS);
$result = array();
foreach( $langs as $l ){
$q = new staticPagesQuery('q');
$q -> where_link($v);
$q -> where_lang($l);
$q -> get('COUNT(*)');
list($count) = $q -> row();
$result[] = array('lang'=>$l,'exists'=> (( $count ) ? 1 : 0) );
}
return $result;
}
}
class staticPagesQuery extends query{
var $fields_get = 'filedsGetStaticPages';
public function __construct($alias){
global $MAIN_DB;
$this -> set_table( $MAIN_DB -> prefix('system_stat_pages') );
$this -> set_alias($alias);
}
public function include_tmpl($alias,$cols=''){
$this -> include_table(MAIN_TMPL_TBL,$alias,'t_id',$cols );
return true;
}
public function where_id($v){
$v = intval($v);
if ( empty($v) ){
return false;
}
return $this -> set_where( $this -> alias.'.p_id',$v);
}
public function where_link($v){
if ( false===MAIN_MULTILANG ){
return $this -> where_id($v);
}
$v = intval($v);
if ( empty($v) ){
return false;
}
return $this -> set_where( $this -> alias.'.link_id',$v);
}
public function where_main_rows(){
if ( false===MAIN_MULTILANG ){
return false;
}
return $this -> set_anothe_where( $this -> alias.'.p_id='.$this -> alias.'.link_id');
}
public function where_url($v){
if ( empty($v) ){
return false;
}
if ( preg_match('#[^a-z0-9./\-_\#&%]#i',$v) ){
return false;
}
return $this -> set_where( $this -> alias.'.p_url',$v);
}
public function where_not_id($v){
$v = intval($v);
if ( empty($v) ){
return false;
}
return $this -> set_anothe_where( $this -> alias.'.p_id!="'.$v.'"');
}
public function where_lang($v){
if ( false===MAIN_MULTILANG ){
return false;
}
$langs = explode(',',MAIN_LANGS);
if ( !in_array($v,$langs) ){
return false;
}
return $this -> set_where( $this -> alias.'.lang',$v);
}
public function orderby_id($v){
return $this -> set_orderby( $this -> alias.'.p_id',$v);
}
}
// класс для управления записями таблицы system_staticPages
class staticPages extends objects{
public $table = "system_stat_pages";
public $key = "p_id";
public $fields = 'filedsSetStaticPages';
public function id(){
return $this -> info['p_id'];
}
public function meta_title(){
return $this -> info['p_meta_title'];
}
public function content(){
return $this -> info['p_content'];
}
// загрузка модуля по его id
static function load_id($id){
$m = new staticPagesQuery('m');
if ( !$m -> where_id($id) ){
return false;
}
$m -> get('*');
if ( $m -> get_count_rows()==0 ){
return FALSE;
}
return new staticPages($id,$m -> row());
}
static function load_url($v){
$m = new staticPagesQuery('m');
if ( !$m -> where_url($v) ){
return false;
}
$m -> get('*');
if ( $m -> get_count_rows()==0 ){
return FALSE;
}
$row = $m -> row();
return new staticPages($row['p_id'],$row);
}
static function create(){
return new staticPages( array('p_id'=>0));
}
/**
* генерируем список действующих страниц
*
*/
static function list_pages(){
$s = new staticPagesQuery('s');
$s -> orderby_id('DESC');
$s -> get('*');
$rows = array();
while( $row = $s -> row() ){
$rows[]=$row;
}
return $rows;
}
static function groups($id,$groups){
global $MAIN_DB;
if ( empty($id) ){
throw new Exception('Ошибка: не указан id');
}
$sql = "DELETE FROM ".$MAIN_DB -> prefix("system_stat_pages_groups_link")." WHERE p_id='$id'";
$MAIN_DB -> query($sql);
if ( !is_array($groups) ){
return false;
}
foreach( $groups as $g_id ){
$sql = "
INSERT INTO ".$MAIN_DB -> prefix("system_stat_pages_groups_link")."
SET p_id='$id', g_id='$g_id'";
$MAIN_DB -> query($sql);
}
return true;
}
static function isExistsUrl($url,$id){
$u = new staticPagesQuery('u');
//$u -> set_debug(1);
$u -> where_url($url);
$u -> where_not_id($id);
$u -> get('COUNT(*)');
list($count) = $u -> row();
if ( $count>0 ){
return true;
}
return false;
}
}
?>