class.modules.php
6.85 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
<?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
*/
include_once(MAIN_SOURCE_PATH.'/modules/admin/lang/'.MAIN_LANG.'/lang.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.objects.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.query.php');
class filedsSetModules
{
static function m_name($v){
if ( empty($v) ){
throw new Exception('Ошибка: название модуля не указано');
}
return $v;
}
static function m_path($v){
if ( empty($v) ){
throw new Exception('Ошибка: адрес модуля не указан');
$this -> make_error(ERROR_MESSAGE,'');
}
return $v;
}
}
class filedsGetModules
{
static $__var = array(); // для хранения временных переменных
}
class modulesQuery extends query{
var $fields_get = 'filedsGetModules';
public function __construct($alias){
$this -> set_table(MAIN_MODULES_TBL);
$this -> set_alias($alias);
}
public function include_pages($alias,$cols=''){
$this -> include_table(MAIN_PAGES_TBL,$alias,'m_id',$cols );
return true;
}
public function where_id($id){
$id = intval($id);
if ( empty($id) ){
return false;
}
return $this -> set_where( $this -> alias.'.m_id',$id);
}
public function where_active($id){
$id = intval($id);
if ( empty($id) ){
return false;
}
return $this -> set_where( $this -> alias.'.m_status',$id);
}
public function where_path($path){
if ( !modules::is_path($path) ){
return false;
}
return $this -> set_where( $this -> alias.'.m_path',$path);
}
public function orderby_pos($v){
return $this -> set_orderby($this -> alias.'.m_pos',$v);
}
} // end modulesQuery
class modules extends objects{
public $table = "system_modules";
public $key = "m_id";
public $fields = 'filedsSetModules';
// загрузка модуля по его id
static function load_id($id){
$m = modules::query('m');
if ( false===$m -> where_id($id) ){
return FALSE;
}
$m -> get('*');
if ( $m -> get_count_rows()==0 ){
return FALSE;
}
return new modules($id,$m -> row());
}
static function load_path($id){
$m = modules::query('m');
if ( !$m -> where_path($id) ){
return false;
}
$m -> get('*');
if ( $m -> get_count_rows()==0 ){
return FALSE;
}
$row = $m -> row();
return new modules($row['m_id'],$row);
}
static function create(){
return new modules(0, array('f_id'=>0) );
}
static function query($alias){
return new modulesQuery( $alias );
}
public function insert(){
// так как запись новая, нужно проверить уникальные ключи на повторение
if ( self::exists_module($this -> set_info['m_path']) ){
throw new Exception(ERROR_MESSAGE, sprintf(A_EXISTS_MODULE,$this -> set_info['m_path']));
}
return parent::insert();
}
public function delete(){
$id = $this -> id();
if ( empty($id) ){
throw new Exception(A_EMPTY_ID);
}
if ( !file_exists(MAIN_SOURCE_PATH.'/modules/'.$this -> get('m_path').'/info.php') ){
throw new Exception( 'Ошибка: модуль "'.$this -> get('m_path').'" не содержит системного файла info.php!' );
}
include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/class.pages.php');
$p = new pagesQuery('f');
$p -> where_mid($id);
$p -> get('f.f_id');
while( list($f_id) = $p -> row() ){
$page = pages::load_id($f_id);
if ( false===$page ){
die('continue');
}
$page -> delete();
}
return parent::delete();
}
public function id(){
return $this -> info['m_id'];
}
public function path(){
return $this -> info['m_path'];
}
public function name(){
return $this -> info['m_name'];
}
static function is_path($p){
if ( empty($p) ){
return false;
}
if ( preg_match('#[^a-z_0-9]#i',$p) ){
return false;
}
return true;
}
static function exists_module($v){
$u = modules::query('m');
//$u -> set_debug(1);
if ( false===$u -> where_path($v) )
{
throw new Exception('Это не путь к модулю!');
}
$u -> get('COUNT(*)');
list($count) = $u -> row();
if ( $count>0 ){
return true;
}
return false;
}
/**
* получаем список модулей
*
*/
static function list_active(){
$modules = array();
$m = modules::query('m');
$m -> where_active(1);
$m -> get('m_path');
while( list($m_path) = $m -> row() ){
$modules[]=$m_path;
}
return $modules;
}
public function installPages($pages){
foreach( $pages as $k=>$v ){
$p = pages::load_pname($k);
if ( false!==$p){
throw new Exception( 'Страница "'.$k.'" уже существует');
}
$p = pages::create();
$p -> set('f_active',1);
$p -> set('f_name',$v);
$p -> set('p_name',$k);
$p -> set('m_dirname', $this -> get('m_path') );
$p -> set('m_id', $this -> key_value );
$p -> set('f_func',$k);
$p -> set('lang',MAIN_LANG);
$p_id = $p -> insert();
if ( false===$p_id ){
throw new Exception( $p -> error() );
}
$p -> set('link_id',$p_id);
$p -> update();
pages::add_langs($p_id);
}
return true;
}
public function installBlocks($blocks){
//$setup_blocks = array();
foreach( $blocks as $block ){
$b = blocks::query('b');
// $b -> set_debug(1);
if ( false===$b -> where_parser_name($block['parser_name']) ){
throw new Exception( 'Ошибка: неверно указан parser_name блока "'.$block['parser_name'].'"');
}
if ( false===$b -> where_path( $this -> get('m_path') ) ){
throw new Exception( 'Ошибка: неверно указан путь к блоку "'.$this -> get('m_path').'"');
}
$b -> get('COUNT(*)',false);
list($count) = $b -> row();
if ( $count>0 ){
$setup_blocks[]=$block['parser_name'];
continue;
}
$p = blocks::create();
//$p -> set_debug(1);
$p -> set('b_name',$block['name']);
$p -> set('m_path',$this -> get('m_path') );
$p -> set('b_func',$block['file']);
$p -> set('b_parser_name',$block['parser_name']);
if ( false===$p -> insert() ){
throw new Exception( $p -> error() );
}
// $setup_blocks[]=$block['parser_name'];
}//foreach
return true;//$setup_blocks;
}
/**
* Выпадающий список модулей
*
*/
static function listSelect($v){
$s = new select_box();
$s -> empty_record(true,0);
$s -> selected_id($v);
$m = self::query('m');
$m -> where_active(1);
$m -> get('m_path,m_name');
while( $row = $m -> row() ){
$s -> set($row['m_path'],$row['m_name']);
}
return $s -> get();
}
}