1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) XEHub <https://www.xehub.io> */ |
3
|
|
|
/** |
4
|
|
|
* @class moduleController |
5
|
|
|
* @author XEHub ([email protected]) |
6
|
|
|
* @brief controller class of the module module |
7
|
|
|
*/ |
8
|
|
|
class moduleController extends module |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @brief Initialization |
12
|
|
|
*/ |
13
|
|
|
function init() |
14
|
|
|
{ |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @brief Add action forward |
19
|
|
|
* Action forward finds and forwards if an action is not in the requested module |
20
|
|
|
* This is used when installing a module |
21
|
|
|
*/ |
22
|
|
|
function insertActionForward($module, $type, $act) |
23
|
|
|
{ |
24
|
|
|
$args = new stdClass(); |
25
|
|
|
$args->module = $module; |
26
|
|
|
$args->type = $type; |
27
|
|
|
$args->act = $act; |
28
|
|
|
|
29
|
|
|
$output = executeQuery('module.insertActionForward', $args); |
30
|
|
|
|
31
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
32
|
|
|
if($oCacheHandler->isSupport()) |
33
|
|
|
{ |
34
|
|
|
$cache_key = 'action_forward'; |
35
|
|
|
$oCacheHandler->delete($cache_key); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $output; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @brief Delete action forward |
43
|
|
|
*/ |
44
|
|
|
function deleteActionForward($module, $type, $act) |
45
|
|
|
{ |
46
|
|
|
$args = new stdClass(); |
47
|
|
|
$args->module = $module; |
48
|
|
|
$args->type = $type; |
49
|
|
|
$args->act = $act; |
50
|
|
|
|
51
|
|
|
$output = executeQuery('module.deleteActionForward', $args); |
52
|
|
|
|
53
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
54
|
|
|
if($oCacheHandler->isSupport()) |
55
|
|
|
{ |
56
|
|
|
$cache_key = 'action_forward'; |
57
|
|
|
$oCacheHandler->delete($cache_key); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $output; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @brief Add module trigger |
65
|
|
|
* module trigger is to call a trigger to a target module |
66
|
|
|
* |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
function insertTrigger($trigger_name, $module, $type, $called_method, $called_position) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$args = new stdClass(); |
71
|
|
|
$args->trigger_name = $trigger_name; |
72
|
|
|
$args->module = $module; |
73
|
|
|
$args->type = $type; |
74
|
|
|
$args->called_method = $called_method; |
75
|
|
|
$args->called_position = $called_position; |
76
|
|
|
|
77
|
|
|
$output = executeQuery('module.insertTrigger', $args); |
78
|
|
|
if($output->toBool()) |
79
|
|
|
{ |
80
|
|
|
//remove from cache |
81
|
|
|
$GLOBALS['__triggers__'] = NULL; |
82
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
83
|
|
|
if($oCacheHandler->isSupport()) |
84
|
|
|
{ |
85
|
|
|
$cache_key = 'triggers'; |
86
|
|
|
$oCacheHandler->delete($cache_key); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $output; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @brief Delete module trigger |
95
|
|
|
* |
96
|
|
|
*/ |
97
|
|
View Code Duplication |
function deleteTrigger($trigger_name, $module, $type, $called_method, $called_position) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$args = new stdClass(); |
100
|
|
|
$args->trigger_name = $trigger_name; |
101
|
|
|
$args->module = $module; |
102
|
|
|
$args->type = $type; |
103
|
|
|
$args->called_method = $called_method; |
104
|
|
|
$args->called_position = $called_position; |
105
|
|
|
|
106
|
|
|
$output = executeQuery('module.deleteTrigger', $args); |
107
|
|
|
if($output->toBool()) |
108
|
|
|
{ |
109
|
|
|
//remove from cache |
110
|
|
|
$GLOBALS['__triggers__'] = NULL; |
111
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
112
|
|
|
if($oCacheHandler->isSupport()) |
113
|
|
|
{ |
114
|
|
|
$cache_key = 'triggers'; |
115
|
|
|
$oCacheHandler->delete($cache_key); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $output; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @brief Delete module trigger |
124
|
|
|
* |
125
|
|
|
*/ |
126
|
|
View Code Duplication |
function deleteModuleTriggers($module) |
|
|
|
|
127
|
|
|
{ |
128
|
|
|
$args = new stdClass(); |
129
|
|
|
$args->module = $module; |
130
|
|
|
|
131
|
|
|
$output = executeQuery('module.deleteModuleTriggers', $args); |
132
|
|
|
if($output->toBool()) |
133
|
|
|
{ |
134
|
|
|
//remove from cache |
135
|
|
|
$GLOBALS['__triggers__'] = NULL; |
136
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
137
|
|
|
if($oCacheHandler->isSupport()) |
138
|
|
|
{ |
139
|
|
|
$cache_key = 'triggers'; |
140
|
|
|
$oCacheHandler->delete($cache_key); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $output; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @brief Add module extend |
149
|
|
|
* |
150
|
|
|
*/ |
151
|
|
|
function insertModuleExtend($parent_module, $extend_module, $type, $kind='') |
152
|
|
|
{ |
153
|
|
|
if($kind != 'admin') $kind = ''; |
154
|
|
|
if(!in_array($type,array('model','controller','view','api','mobile'))) return false; |
155
|
|
|
if(in_array($parent_module, array('module','addon','widget','layout'))) return false; |
156
|
|
|
|
157
|
|
|
$cache_file = './files/config/module_extend.php'; |
158
|
|
|
FileHandler::removeFile($cache_file); |
159
|
|
|
|
160
|
|
|
$args = new stdClass; |
161
|
|
|
$args->parent_module = $parent_module; |
162
|
|
|
$args->extend_module = $extend_module; |
163
|
|
|
$args->type = $type; |
164
|
|
|
$args->kind = $kind; |
165
|
|
|
|
166
|
|
|
$output = executeQuery('module.getModuleExtendCount', $args); |
167
|
|
|
if($output->data->count>0) return false; |
168
|
|
|
|
169
|
|
|
$output = executeQuery('module.insertModuleExtend', $args); |
170
|
|
|
return $output; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @brief Delete module extend |
175
|
|
|
* |
176
|
|
|
*/ |
177
|
|
|
function deleteModuleExtend($parent_module, $extend_module, $type, $kind='') |
178
|
|
|
{ |
179
|
|
|
$cache_file = './files/config/module_extend.php'; |
180
|
|
|
FileHandler::removeFile($cache_file); |
181
|
|
|
|
182
|
|
|
$args = new stdClass; |
183
|
|
|
$args->parent_module = $parent_module; |
184
|
|
|
$args->extend_module = $extend_module; |
185
|
|
|
$args->type = $type; |
186
|
|
|
$args->kind = $kind; |
187
|
|
|
|
188
|
|
|
$output = executeQuery('module.deleteModuleExtend', $args); |
189
|
|
|
|
190
|
|
|
return $output; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
function updateModuleConfig($module, $config, $site_srl = 0) |
194
|
|
|
{ |
195
|
|
|
$args = new stdClass(); |
196
|
|
|
$args->module = $module; |
197
|
|
|
$args->site_srl = $site_srl; |
198
|
|
|
|
199
|
|
|
$oModuleModel = getModel('module'); |
200
|
|
|
$origin_config = $oModuleModel->getModuleConfig($module, $site_srl); |
201
|
|
|
|
202
|
|
|
if(!$origin_config) $origin_config = new stdClass; |
203
|
|
|
|
204
|
|
|
foreach($config as $key => $val) |
205
|
|
|
{ |
206
|
|
|
$origin_config->{$key} = $val; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
return $this->insertModuleConfig($module, $origin_config, $site_srl); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @brief Enter a specific set of modules |
214
|
|
|
* In order to manage global configurations of modules such as board, member and so on |
215
|
|
|
*/ |
216
|
|
View Code Duplication |
function insertModuleConfig($module, $config, $site_srl = 0) |
|
|
|
|
217
|
|
|
{ |
218
|
|
|
$args =new stdClass(); |
219
|
|
|
$args->module = $module; |
220
|
|
|
$args->config = serialize($config); |
221
|
|
|
$args->site_srl = $site_srl; |
222
|
|
|
|
223
|
|
|
$output = executeQuery('module.deleteModuleConfig', $args); |
224
|
|
|
if(!$output->toBool()) return $output; |
225
|
|
|
|
226
|
|
|
$output = executeQuery('module.insertModuleConfig', $args); |
227
|
|
|
|
228
|
|
|
//remove from cache |
229
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
230
|
|
|
if($oCacheHandler->isSupport()) |
231
|
|
|
{ |
232
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
233
|
|
|
} |
234
|
|
|
return $output; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @brief Save module configurations of the mid |
239
|
|
|
* Manage mid configurations depending on module |
240
|
|
|
*/ |
241
|
|
View Code Duplication |
function insertModulePartConfig($module, $module_srl, $config) |
|
|
|
|
242
|
|
|
{ |
243
|
|
|
$args = new stdClass(); |
244
|
|
|
$args->module = $module; |
245
|
|
|
$args->module_srl = $module_srl; |
246
|
|
|
$args->config = serialize($config); |
247
|
|
|
|
248
|
|
|
$output = executeQuery('module.deleteModulePartConfig', $args); |
249
|
|
|
if(!$output->toBool()) return $output; |
250
|
|
|
|
251
|
|
|
$output = executeQuery('module.insertModulePartConfig', $args); |
252
|
|
|
|
253
|
|
|
//remove from cache |
254
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
255
|
|
|
if($oCacheHandler->isSupport()) |
256
|
|
|
{ |
257
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
return $output; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @brief create virtual site |
265
|
|
|
*/ |
266
|
|
|
function insertSite($domain, $index_module_srl) |
267
|
|
|
{ |
268
|
|
|
if(isSiteID($domain)) |
269
|
|
|
{ |
270
|
|
|
$oModuleModel = getModel('module'); |
271
|
|
|
if($oModuleModel->isIDExists($domain, 0)) return new BaseObject(-1,'msg_already_registed_vid'); |
272
|
|
|
} |
273
|
|
|
else |
274
|
|
|
{ |
275
|
|
|
$domain = strtolower($domain); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
$args = new stdClass; |
279
|
|
|
$args->site_srl = getNextSequence(); |
280
|
|
|
$args->domain = (substr_compare($domain, '/', -1) === 0) ? substr($domain, 0, -1) : $domain; |
281
|
|
|
$args->index_module_srl = $index_module_srl; |
282
|
|
|
$args->default_language = Context::getLangType(); |
283
|
|
|
|
284
|
|
|
$columnList = array('modules.site_srl'); |
285
|
|
|
$oModuleModel = getModel('module'); |
286
|
|
|
$output = $oModuleModel->getSiteInfoByDomain($args->domain, $columnList); |
287
|
|
|
if($output) return new BaseObject(-1,'msg_already_registed_vid'); |
288
|
|
|
|
289
|
|
|
$output = executeQuery('module.insertSite', $args); |
290
|
|
|
if(!$output->toBool()) return $output; |
291
|
|
|
|
292
|
|
|
$output->add('site_srl', $args->site_srl); |
293
|
|
|
return $output; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @brief modify virtual site |
298
|
|
|
*/ |
299
|
|
|
function updateSite($args) |
300
|
|
|
{ |
301
|
|
|
$oModuleModel = getModel('module'); |
302
|
|
|
$columnList = array('sites.site_srl', 'sites.domain'); |
303
|
|
|
$site_info = $oModuleModel->getSiteInfo($args->site_srl, $columnList); |
304
|
|
|
|
305
|
|
|
if(!$args->domain && $site_info->site_srl == $args->site_srl) |
306
|
|
|
{ |
307
|
|
|
$args->domain = $site_info->domain; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
if($site_info->domain != $args->domain) |
311
|
|
|
{ |
312
|
|
|
$info = $oModuleModel->getSiteInfoByDomain($args->domain, $columnList); |
313
|
|
|
if($info->site_srl && $info->site_srl != $args->site_srl) return new BaseObject(-1,'msg_already_registed_domain'); |
314
|
|
|
if(isSiteID($args->domain) && $oModuleModel->isIDExists($args->domain)) return new BaseObject(-1,'msg_already_registed_vid'); |
315
|
|
|
|
316
|
|
|
if($args->domain && !isSiteID($args->domain)) |
317
|
|
|
{ |
318
|
|
|
$args->domain = (strlen($args->domain) >= 1 && substr_compare($args->domain, '/', -1) === 0) ? substr($args->domain, 0, -1) : $args->domain; |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
$output = executeQuery('module.updateSite', $args); |
322
|
|
|
//clear cache for default mid |
323
|
|
|
if($args->site_srl == 0) $vid=''; |
|
|
|
|
324
|
|
|
else $vid=$args->domain; |
|
|
|
|
325
|
|
|
|
326
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->index_module_srl); |
327
|
|
|
$mid = $module_info->mid; |
|
|
|
|
328
|
|
|
|
329
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
330
|
|
|
if($oCacheHandler->isSupport()) |
331
|
|
|
{ |
332
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
return $output; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @brief Arrange module information |
340
|
|
|
*/ |
341
|
|
|
function arrangeModuleInfo(&$args, &$extra_vars) |
342
|
|
|
{ |
343
|
|
|
// Remove unnecessary information |
344
|
|
|
unset($args->body); |
345
|
|
|
unset($args->act); |
346
|
|
|
unset($args->page); |
347
|
|
|
// Test mid value |
348
|
|
|
if(!preg_match("/^[a-z][a-z0-9_]+$/i", $args->mid)) return new BaseObject(-1, 'msg_limit_mid'); |
349
|
|
|
// Test variables (separate basic vars and other vars in modules) |
350
|
|
|
$extra_vars = clone($args); |
351
|
|
|
unset($extra_vars->module_srl); |
352
|
|
|
unset($extra_vars->module); |
353
|
|
|
unset($extra_vars->module_category_srl); |
354
|
|
|
unset($extra_vars->layout_srl); |
355
|
|
|
unset($extra_vars->mlayout_srl); |
356
|
|
|
unset($extra_vars->use_mobile); |
357
|
|
|
unset($extra_vars->menu_srl); |
358
|
|
|
unset($extra_vars->site_srl); |
359
|
|
|
unset($extra_vars->mid); |
360
|
|
|
unset($extra_vars->is_skin_fix); |
361
|
|
|
unset($extra_vars->skin); |
362
|
|
|
unset($extra_vars->is_mskin_fix); |
363
|
|
|
unset($extra_vars->mskin); |
364
|
|
|
unset($extra_vars->browser_title); |
365
|
|
|
unset($extra_vars->description); |
366
|
|
|
unset($extra_vars->is_default); |
367
|
|
|
unset($extra_vars->content); |
368
|
|
|
unset($extra_vars->mcontent); |
369
|
|
|
unset($extra_vars->open_rss); |
370
|
|
|
unset($extra_vars->header_text); |
371
|
|
|
unset($extra_vars->footer_text); |
372
|
|
|
$args = delObjectVars($args, $extra_vars); |
373
|
|
|
|
374
|
|
|
return new BaseObject(); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @brief Insert module |
379
|
|
|
*/ |
380
|
|
|
function insertModule($args) |
381
|
|
|
{ |
382
|
|
|
if(isset($args->isMenuCreate)) |
383
|
|
|
{ |
384
|
|
|
$isMenuCreate = $args->isMenuCreate; |
385
|
|
|
} |
386
|
|
|
else |
387
|
|
|
{ |
388
|
|
|
$isMenuCreate = TRUE; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
$output = $this->arrangeModuleInfo($args, $extra_vars); |
392
|
|
|
if(!$output->toBool()) return $output; |
393
|
|
|
// Check whether the module name already exists |
394
|
|
|
if(!$args->site_srl) $args->site_srl = 0; |
395
|
|
|
$oModuleModel = getModel('module'); |
396
|
|
|
if($oModuleModel->isIDExists($args->mid, $args->site_srl)) return new BaseObject(-1, 'msg_module_name_exists'); |
397
|
|
|
|
398
|
|
|
// begin transaction |
399
|
|
|
$oDB = &DB::getInstance(); |
400
|
|
|
$oDB->begin(); |
401
|
|
|
// Get colorset from the skin information |
402
|
|
|
$module_path = ModuleHandler::getModulePath($args->module); |
403
|
|
|
$skin_info = $oModuleModel->loadSkinInfo($module_path, $args->skin); |
404
|
|
|
$skin_vars = new stdClass(); |
405
|
|
|
$skin_vars->colorset = $skin_info->colorset[0]->name; |
406
|
|
|
// Arrange variables and then execute a query |
407
|
|
|
if(!$args->module_srl) $args->module_srl = getNextSequence(); |
408
|
|
|
|
409
|
|
|
// default value |
410
|
|
View Code Duplication |
if($args->skin == '/USE_DEFAULT/') |
411
|
|
|
{ |
412
|
|
|
$args->is_skin_fix = 'N'; |
413
|
|
|
} |
414
|
|
|
else |
415
|
|
|
{ |
416
|
|
|
if(isset($args->is_skin_fix)) |
417
|
|
|
{ |
418
|
|
|
$args->is_skin_fix = ($args->is_skin_fix != 'Y') ? 'N' : 'Y'; |
419
|
|
|
} |
420
|
|
|
else |
421
|
|
|
{ |
422
|
|
|
$args->is_skin_fix = 'Y'; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
View Code Duplication |
if($args->mskin == '/USE_DEFAULT/') |
427
|
|
|
{ |
428
|
|
|
$args->is_mskin_fix = 'N'; |
429
|
|
|
} |
430
|
|
|
else |
431
|
|
|
{ |
432
|
|
|
if(isset($args->is_mskin_fix)) |
433
|
|
|
{ |
434
|
|
|
$args->is_mskin_fix = ($args->is_mskin_fix != 'Y') ? 'N' : 'Y'; |
435
|
|
|
} |
436
|
|
|
else |
437
|
|
|
{ |
438
|
|
|
$args->is_mskin_fix = 'Y'; |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
unset($output); |
443
|
|
|
|
444
|
|
|
$args->browser_title = strip_tags($args->browser_title); |
445
|
|
|
|
446
|
|
|
if($isMenuCreate === TRUE) |
447
|
|
|
{ |
448
|
|
|
$menuArgs = new stdClass; |
449
|
|
|
$menuArgs->menu_srl = $args->menu_srl; |
450
|
|
|
$menuOutput = executeQuery('menu.getMenu', $menuArgs); |
451
|
|
|
|
452
|
|
|
// if menu is not created, create menu also. and does not supported that in virtual site. |
453
|
|
|
if(!$menuOutput->data && !$args->site_srl) |
454
|
|
|
{ |
455
|
|
|
$oMenuAdminModel = getAdminModel('menu'); |
|
|
|
|
456
|
|
|
|
457
|
|
|
$oMenuAdminController = getAdminController('menu'); |
458
|
|
|
$menuSrl = $oMenuAdminController->getUnlinkedMenu(); |
459
|
|
|
|
460
|
|
|
$menuArgs->menu_srl = $menuSrl; |
461
|
|
|
$menuArgs->menu_item_srl = getNextSequence(); |
462
|
|
|
$menuArgs->parent_srl = 0; |
463
|
|
|
$menuArgs->open_window = 'N'; |
464
|
|
|
$menuArgs->url = $args->mid; |
465
|
|
|
$menuArgs->expand = 'N'; |
466
|
|
|
$menuArgs->is_shortcut = 'N'; |
467
|
|
|
$menuArgs->name = $args->browser_title; |
468
|
|
|
$menuArgs->listorder = $args->menu_item_srl * -1; |
469
|
|
|
|
470
|
|
|
$menuItemOutput = executeQuery('menu.insertMenuItem', $menuArgs); |
471
|
|
|
if(!$menuItemOutput->toBool()) |
472
|
|
|
{ |
473
|
|
|
$oDB->rollback(); |
474
|
|
|
return $menuItemOutput; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
$oMenuAdminController->makeXmlFile($menuSrl); |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
// Insert a module |
482
|
|
|
$args->menu_srl = $menuArgs->menu_srl; |
|
|
|
|
483
|
|
|
$output = executeQuery('module.insertModule', $args); |
484
|
|
|
if(!$output->toBool()) |
485
|
|
|
{ |
486
|
|
|
$oDB->rollback(); |
487
|
|
|
return $output; |
488
|
|
|
} |
489
|
|
|
// Insert module extra vars |
490
|
|
|
$this->insertModuleExtraVars($args->module_srl, $extra_vars); |
491
|
|
|
|
492
|
|
|
// commit |
493
|
|
|
$oDB->commit(); |
494
|
|
|
|
495
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
496
|
|
|
if($oCacheHandler->isSupport()) |
497
|
|
|
{ |
498
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
$output->add('module_srl',$args->module_srl); |
502
|
|
|
return $output; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* @brief Modify module information |
507
|
|
|
*/ |
508
|
|
|
function updateModule($args) |
509
|
|
|
{ |
510
|
|
|
if(isset($args->isMenuCreate)) |
511
|
|
|
{ |
512
|
|
|
$isMenuCreate = $args->isMenuCreate; |
513
|
|
|
} |
514
|
|
|
else |
515
|
|
|
{ |
516
|
|
|
$isMenuCreate = TRUE; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
$output = $this->arrangeModuleInfo($args, $extra_vars); |
520
|
|
|
if(!$output->toBool()) return $output; |
521
|
|
|
// begin transaction |
522
|
|
|
$oDB = &DB::getInstance(); |
523
|
|
|
$oDB->begin(); |
524
|
|
|
|
525
|
|
|
$oModuleModel = getModel('module'); |
526
|
|
|
$columnList = array('module_srl', 'site_srl', 'browser_title', 'mid'); |
|
|
|
|
527
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl); |
528
|
|
|
|
529
|
|
|
if(!$args->site_srl || !$args->browser_title) |
530
|
|
|
{ |
531
|
|
|
if(!$args->site_srl) $args->site_srl = (int)$module_info->site_srl; |
532
|
|
|
if(!$args->browser_title) $args->browser_title = $module_info->browser_title; |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
$args->browser_title = strip_tags($args->browser_title); |
536
|
|
|
|
537
|
|
|
$output = executeQuery('module.isExistsModuleName', $args); |
538
|
|
|
if(!$output->toBool() || $output->data->count) |
539
|
|
|
{ |
540
|
|
|
$oDB->rollback(); |
541
|
|
|
return new BaseObject(-1, 'msg_module_name_exists'); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
// default value |
545
|
|
View Code Duplication |
if($args->skin == '/USE_DEFAULT/') |
546
|
|
|
{ |
547
|
|
|
$args->is_skin_fix = 'N'; |
548
|
|
|
} |
549
|
|
|
else |
550
|
|
|
{ |
551
|
|
|
if(isset($args->is_skin_fix)) |
552
|
|
|
{ |
553
|
|
|
$args->is_skin_fix = ($args->is_skin_fix != 'Y') ? 'N' : 'Y'; |
554
|
|
|
} |
555
|
|
|
else |
556
|
|
|
{ |
557
|
|
|
$args->is_skin_fix = 'Y'; |
558
|
|
|
} |
559
|
|
|
} |
560
|
|
|
|
561
|
|
View Code Duplication |
if($args->mskin == '/USE_DEFAULT/') |
562
|
|
|
{ |
563
|
|
|
$args->is_mskin_fix = 'N'; |
564
|
|
|
} |
565
|
|
|
else |
566
|
|
|
{ |
567
|
|
|
if(isset($args->is_mskin_fix)) |
568
|
|
|
{ |
569
|
|
|
$args->is_mskin_fix = ($args->is_mskin_fix != 'Y') ? 'N' : 'Y'; |
570
|
|
|
} |
571
|
|
|
else |
572
|
|
|
{ |
573
|
|
|
$args->is_mskin_fix = 'Y'; |
574
|
|
|
} |
575
|
|
|
} |
576
|
|
|
$output = executeQuery('module.updateModule', $args); |
577
|
|
|
if(!$output->toBool()) |
578
|
|
|
{ |
579
|
|
|
$oDB->rollback(); |
580
|
|
|
return $output; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
if($isMenuCreate === TRUE) |
584
|
|
|
{ |
585
|
|
|
$menuArgs = new stdClass; |
586
|
|
|
$menuArgs->url = $module_info->mid; |
587
|
|
|
$menuArgs->site_srl = $module_info->site_srl; |
588
|
|
|
$menuOutput = executeQueryArray('menu.getMenuItemByUrl', $menuArgs); |
589
|
|
|
if($menuOutput->data && count($menuOutput->data)) |
590
|
|
|
{ |
591
|
|
|
$oMenuAdminController = getAdminController('menu'); |
592
|
|
|
foreach($menuOutput->data as $itemInfo) |
593
|
|
|
{ |
594
|
|
|
$itemInfo->url = $args->mid; |
595
|
|
|
|
596
|
|
|
$updateMenuItemOutput = $oMenuAdminController->updateMenuItem($itemInfo); |
597
|
|
|
if(!$updateMenuItemOutput->toBool()) |
598
|
|
|
{ |
599
|
|
|
$oDB->rollback(); |
600
|
|
|
return $updateMenuItemOutput; |
601
|
|
|
} |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
// if mid changed, change mid of success_return_url to new mid |
607
|
|
|
if($module_info->mid != $args->mid && Context::get('success_return_url')) |
608
|
|
|
{ |
609
|
|
|
changeValueInUrl('mid', $args->mid, $module_info->mid); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
// Insert module extra vars |
613
|
|
|
$this->insertModuleExtraVars($args->module_srl, $extra_vars); |
614
|
|
|
|
615
|
|
|
$oDB->commit(); |
616
|
|
|
|
617
|
|
|
$output->add('module_srl',$args->module_srl); |
618
|
|
|
|
619
|
|
|
//remove from cache |
620
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
621
|
|
|
if($oCacheHandler->isSupport()) |
622
|
|
|
{ |
623
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
return $output; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* @brief 업데이트 기록 저장 |
631
|
|
|
* @param string $update_id |
632
|
|
|
* @return Boolean |
633
|
|
|
*/ |
634
|
|
|
public function insertUpdatedLog($update_id) |
635
|
|
|
{ |
636
|
|
|
$args = new stdClass(); |
637
|
|
|
$args->update_id = $update_id; |
638
|
|
|
$output = executeQuery('module.insertModuleUpdateLog', $args); |
639
|
|
|
|
640
|
|
|
if(!!$output->error) return false; |
641
|
|
|
|
642
|
|
|
return true; |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* @brief Change the module's virtual site |
647
|
|
|
*/ |
648
|
|
|
function updateModuleSite($module_srl, $site_srl, $layout_srl = 0) |
649
|
|
|
{ |
650
|
|
|
$args = new stdClass; |
651
|
|
|
$args->module_srl = $module_srl; |
652
|
|
|
$args->site_srl = $site_srl; |
653
|
|
|
$args->layout_srl = $layout_srl; |
654
|
|
|
$output = executeQuery('module.updateModuleSite', $args); |
655
|
|
|
if(!$output->toBool()) return $output; |
656
|
|
|
|
657
|
|
|
//remove from cache |
658
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
659
|
|
|
if($oCacheHandler->isSupport()) |
660
|
|
|
{ |
661
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
return $output; |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
/** |
668
|
|
|
* Delete module |
669
|
|
|
* Attempt to delete all related information when deleting a module. |
670
|
|
|
* Origin method is changed. because menu validation check is needed |
671
|
|
|
*/ |
672
|
|
|
function deleteModule($module_srl, $site_srl = 0) |
673
|
|
|
{ |
674
|
|
|
if(!$module_srl) return new BaseObject(-1,'msg_invalid_request'); |
675
|
|
|
|
676
|
|
|
$site_module_info = Context::get('site_module_info'); |
677
|
|
|
|
678
|
|
|
$oModuleModel = getModel('module'); |
679
|
|
|
$output = $oModuleModel->getModuleInfoByModuleSrl($module_srl); |
680
|
|
|
|
681
|
|
|
$args = new stdClass(); |
682
|
|
|
$args->url = $output->mid; |
683
|
|
|
$args->is_shortcut = 'N'; |
684
|
|
|
if(!$site_srl) $args->site_srl = $site_module_info->site_srl; |
685
|
|
|
else $args->site_srl = $site_srl; |
686
|
|
|
|
687
|
|
|
unset($output); |
688
|
|
|
|
689
|
|
|
$oMenuAdminModel = getAdminModel('menu'); |
690
|
|
|
$menuOutput = $oMenuAdminModel->getMenuList($args); |
691
|
|
|
|
692
|
|
|
// get menu_srl by site_srl |
693
|
|
|
if(is_array($menuOutput->data)) |
694
|
|
|
{ |
695
|
|
|
foreach($menuOutput->data AS $key=>$value) |
696
|
|
|
{ |
697
|
|
|
$args->menu_srl = $value->menu_srl; |
698
|
|
|
break; |
699
|
|
|
} |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
$output = executeQuery('menu.getMenuItemByUrl', $args); |
703
|
|
|
// menu delete |
704
|
|
|
if($output->data) |
705
|
|
|
{ |
706
|
|
|
unset($args); |
707
|
|
|
$args = new stdClass; |
708
|
|
|
$args->menu_srl = $output->data->menu_srl; |
709
|
|
|
$args->menu_item_srl = $output->data->menu_item_srl; |
710
|
|
|
$args->is_force = 'N'; |
711
|
|
|
|
712
|
|
|
$oMenuAdminController = getAdminController('menu'); |
713
|
|
|
$output = $oMenuAdminController->deleteItem($args); |
714
|
|
|
|
715
|
|
|
if($output->isSuccess) |
716
|
|
|
{ |
717
|
|
|
return new BaseObject(0, 'success_deleted'); |
718
|
|
|
} |
719
|
|
|
else |
720
|
|
|
{ |
721
|
|
|
return new BaseObject($output->error, $output->message); |
722
|
|
|
} |
723
|
|
|
} |
724
|
|
|
// only delete module |
725
|
|
|
else |
726
|
|
|
{ |
727
|
|
|
return $this->onlyDeleteModule($module_srl); |
728
|
|
|
} |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* Delete module |
733
|
|
|
* Attempt to delete all related information when deleting a module. |
734
|
|
|
*/ |
735
|
|
|
public function onlyDeleteModule($module_srl) |
736
|
|
|
{ |
737
|
|
|
if(!$module_srl) return new BaseObject(-1,'msg_invalid_request'); |
738
|
|
|
|
739
|
|
|
// check start module |
740
|
|
|
$oModuleModel = getModel('module'); |
741
|
|
|
$columnList = array('sites.index_module_srl'); |
742
|
|
|
$start_module = $oModuleModel->getSiteInfo(0, $columnList); |
743
|
|
|
if($module_srl == $start_module->index_module_srl) return new BaseObject(-1, 'msg_cannot_delete_startmodule'); |
744
|
|
|
|
745
|
|
|
// Call a trigger (before) |
746
|
|
|
$trigger_obj = new stdClass(); |
747
|
|
|
$trigger_obj->module_srl = $module_srl; |
748
|
|
|
$output = ModuleHandler::triggerCall('module.deleteModule', 'before', $trigger_obj); |
749
|
|
|
if(!$output->toBool()) return $output; |
750
|
|
|
|
751
|
|
|
// begin transaction |
752
|
|
|
$oDB = &DB::getInstance(); |
753
|
|
|
$oDB->begin(); |
754
|
|
|
|
755
|
|
|
$args = new stdClass(); |
756
|
|
|
$args->module_srl = $module_srl; |
757
|
|
|
// Delete module information from the DB |
758
|
|
|
$output = executeQuery('module.deleteModule', $args); |
759
|
|
|
if(!$output->toBool()) |
760
|
|
|
{ |
761
|
|
|
$oDB->rollback(); |
762
|
|
|
return $output; |
763
|
|
|
} |
764
|
|
|
// Delete permission information |
765
|
|
|
$this->deleteModuleGrants($module_srl); |
766
|
|
|
// Remove skin information |
767
|
|
|
$this->deleteModuleSkinVars($module_srl); |
768
|
|
|
// Delete module extra vars |
769
|
|
|
$this->deleteModuleExtraVars($module_srl); |
770
|
|
|
// Remove the module manager |
771
|
|
|
$this->deleteAdminId($module_srl); |
772
|
|
|
// Call a trigger (after) |
773
|
|
View Code Duplication |
if($output->toBool()) |
774
|
|
|
{ |
775
|
|
|
$trigger_output = ModuleHandler::triggerCall('module.deleteModule', 'after', $trigger_obj); |
776
|
|
|
if(!$trigger_output->toBool()) |
777
|
|
|
{ |
778
|
|
|
$oDB->rollback(); |
779
|
|
|
return $trigger_output; |
780
|
|
|
} |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
// commit |
784
|
|
|
$oDB->commit(); |
785
|
|
|
|
786
|
|
|
//remove from cache |
787
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
788
|
|
|
if($oCacheHandler->isSupport()) |
789
|
|
|
{ |
790
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
791
|
|
|
} |
792
|
|
|
return $output; |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
/** |
796
|
|
|
* @brief Change other information of the module |
797
|
|
|
* @deprecated |
798
|
|
|
*/ |
799
|
|
|
function updateModuleSkinVars($module_srl, $skin_vars) |
|
|
|
|
800
|
|
|
{ |
801
|
|
|
return new BaseObject(); |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
/** |
805
|
|
|
* @brief Set is_default as N in all modules(the default module is disabled) |
806
|
|
|
*/ |
807
|
|
View Code Duplication |
function clearDefaultModule() |
|
|
|
|
808
|
|
|
{ |
809
|
|
|
$output = executeQuery('module.clearDefaultModule'); |
810
|
|
|
if(!$output->toBool()) return $output; |
811
|
|
|
|
812
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
813
|
|
|
if($oCacheHandler->isSupport()) |
814
|
|
|
{ |
815
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
return $output; |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
/** |
822
|
|
|
* @brief Update menu_srl of mid which belongs to menu_srl |
823
|
|
|
*/ |
824
|
|
View Code Duplication |
function updateModuleMenu($args) |
|
|
|
|
825
|
|
|
{ |
826
|
|
|
$output = executeQuery('module.updateModuleMenu', $args); |
827
|
|
|
|
828
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
829
|
|
|
if($oCacheHandler->isSupport()) |
830
|
|
|
{ |
831
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
return $output; |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
/** |
838
|
|
|
* @brief Update layout_srl of mid which belongs to menu_srl |
839
|
|
|
*/ |
840
|
|
|
function updateModuleLayout($layout_srl, $menu_srl_list) |
841
|
|
|
{ |
842
|
|
|
if(!count($menu_srl_list)) return; |
843
|
|
|
|
844
|
|
|
$args = new stdClass; |
845
|
|
|
$args->layout_srl = $layout_srl; |
846
|
|
|
$args->menu_srls = implode(',',$menu_srl_list); |
847
|
|
|
$output = executeQuery('module.updateModuleLayout', $args); |
848
|
|
|
|
849
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
850
|
|
|
if($oCacheHandler->isSupport()) |
851
|
|
|
{ |
852
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
return $output; |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
/** |
859
|
|
|
* @brief Change the site administrator |
860
|
|
|
*/ |
861
|
|
|
function insertSiteAdmin($site_srl, $arr_admins) |
862
|
|
|
{ |
863
|
|
|
// Remove the site administrator |
864
|
|
|
$args = new stdClass; |
865
|
|
|
$args->site_srl = $site_srl; |
866
|
|
|
|
867
|
|
|
$output = executeQuery('module.deleteSiteAdmin', $args); |
868
|
|
|
|
869
|
|
|
if(!$output->toBool()) return $output; |
870
|
|
|
// Get user id of an administrator |
871
|
|
|
if(!is_array($arr_admins) || !count($arr_admins)) return new BaseObject(); |
872
|
|
|
foreach($arr_admins as $key => $user_id) |
873
|
|
|
{ |
874
|
|
|
if(!trim($user_id)) continue; |
875
|
|
|
$admins[] = trim($user_id); |
|
|
|
|
876
|
|
|
} |
877
|
|
|
if(!count($admins)) return new BaseObject(); |
|
|
|
|
878
|
|
|
|
879
|
|
|
$oMemberModel = getModel('member'); |
880
|
|
|
$member_config = $oMemberModel->getMemberConfig(); |
881
|
|
|
if($member_config->identifier == 'email_address') |
882
|
|
|
{ |
883
|
|
|
$args->email_address = '\''.implode('\',\'',$admins).'\''; |
884
|
|
|
} |
885
|
|
|
else |
886
|
|
|
{ |
887
|
|
|
$args->user_ids = '\''.implode('\',\'',$admins).'\''; |
888
|
|
|
} |
889
|
|
|
$output = executeQueryArray('module.getAdminSrls', $args); |
890
|
|
|
if(!$output->toBool()||!$output->data) return $output; |
891
|
|
|
|
892
|
|
|
foreach($output->data as $key => $val) |
893
|
|
|
{ |
894
|
|
|
unset($args); |
895
|
|
|
$args = new stdClass; |
896
|
|
|
$args->site_srl = $site_srl; |
897
|
|
|
$args->member_srl = $val->member_srl; |
898
|
|
|
$output = executeQueryArray('module.insertSiteAdmin', $args); |
899
|
|
|
if(!$output->toBool()) return $output; |
900
|
|
|
} |
901
|
|
|
return new BaseObject(); |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
/** |
905
|
|
|
* @brief Specify the admin ID to a module |
906
|
|
|
*/ |
907
|
|
|
function insertAdminId($module_srl, $admin_id) |
908
|
|
|
{ |
909
|
|
|
$oMemberModel = getModel('member'); |
910
|
|
|
$member_config = $oMemberModel->getMemberConfig(); |
911
|
|
|
|
912
|
|
|
if($member_config->identifier == 'email_address') |
913
|
|
|
$member_info = $oMemberModel->getMemberInfoByEmailAddress($admin_id); |
914
|
|
|
else |
915
|
|
|
$member_info = $oMemberModel->getMemberInfoByUserID($admin_id); |
916
|
|
|
|
917
|
|
|
if(!$member_info->member_srl) return; |
918
|
|
|
$args = new stdClass(); |
919
|
|
|
$args->module_srl = $module_srl; |
920
|
|
|
$args->member_srl = $member_info->member_srl; |
921
|
|
|
return executeQuery('module.insertAdminId', $args); |
922
|
|
|
} |
923
|
|
|
|
924
|
|
|
/** |
925
|
|
|
* @brief Remove the admin ID from a module |
926
|
|
|
*/ |
927
|
|
|
function deleteAdminId($module_srl, $admin_id = '') |
928
|
|
|
{ |
929
|
|
|
$args = new stdClass(); |
930
|
|
|
$args->module_srl = $module_srl; |
931
|
|
|
|
932
|
|
|
if($admin_id) |
933
|
|
|
{ |
934
|
|
|
$oMemberModel = getModel('member'); |
935
|
|
|
$member_info = $oMemberModel->getMemberInfoByUserID($admin_id); |
936
|
|
|
if($member_info->member_srl) $args->member_srl = $member_info->member_srl; |
937
|
|
|
} |
938
|
|
|
return executeQuery('module.deleteAdminId', $args); |
939
|
|
|
} |
940
|
|
|
|
941
|
|
|
/** |
942
|
|
|
* Insert skin vars to a module |
943
|
|
|
* @param $module_srl Sequence of module |
944
|
|
|
* @param $obj Skin variables |
945
|
|
|
*/ |
946
|
|
|
function insertModuleSkinVars($module_srl, $obj) |
947
|
|
|
{ |
948
|
|
|
return $this->_insertModuleSkinVars($module_srl, $obj, 'P'); |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
/** |
952
|
|
|
* Insert mobile skin vars to a module |
953
|
|
|
* @param $module_srl Sequence of module |
954
|
|
|
* @param $obj Skin variables |
955
|
|
|
*/ |
956
|
|
|
function insertModuleMobileSkinVars($module_srl, $obj) |
957
|
|
|
{ |
958
|
|
|
return $this->_insertModuleSkinVars($module_srl, $obj, 'M'); |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* @brief Insert skin vars to a module |
964
|
|
|
*/ |
965
|
|
|
function _insertModuleSkinVars($module_srl, $obj, $mode) |
966
|
|
|
{ |
967
|
|
|
$mode = $mode === 'P' ? 'P' : 'M'; |
968
|
|
|
|
969
|
|
|
$oDB = DB::getInstance(); |
970
|
|
|
$oDB->begin(); |
971
|
|
|
|
972
|
|
|
$output = $this->_deleteModuleSkinVars($module_srl, $mode); |
973
|
|
|
if(!$output->toBool()) |
974
|
|
|
{ |
975
|
|
|
$oDB->rollback(); |
976
|
|
|
return $output; |
977
|
|
|
} |
978
|
|
|
|
979
|
|
|
getDestroyXeVars($obj); |
980
|
|
|
if(!$obj || !count($obj)) return new BaseObject(); |
981
|
|
|
|
982
|
|
|
$args = new stdClass; |
983
|
|
|
$args->module_srl = $module_srl; |
984
|
|
|
foreach($obj as $key => $val) |
985
|
|
|
{ |
986
|
|
|
// #17927989 For an old board which used the old blog module |
987
|
|
|
// it often saved menu item(stdClass) on the skin info column |
988
|
|
|
// When updating the module on XE core 1.2.0 later versions, it occurs an error |
989
|
|
|
// fixed the error |
990
|
|
|
if (is_object($val)) continue; |
991
|
|
|
if (is_array($val)) $val = serialize($val); |
992
|
|
|
|
993
|
|
|
$args->name = trim($key); |
994
|
|
|
$args->value = trim($val); |
995
|
|
|
if(!$args->name || !$args->value) continue; |
996
|
|
|
|
997
|
|
|
if($mode === 'P') |
998
|
|
|
{ |
999
|
|
|
$output = executeQuery('module.insertModuleSkinVars', $args); |
1000
|
|
|
} |
1001
|
|
|
else |
1002
|
|
|
{ |
1003
|
|
|
$output = executeQuery('module.insertModuleMobileSkinVars', $args); |
1004
|
|
|
} |
1005
|
|
|
if(!$output->toBool()) |
1006
|
|
|
{ |
1007
|
|
|
return $output; |
1008
|
|
|
$oDB->rollback(); |
|
|
|
|
1009
|
|
|
} |
1010
|
|
|
} |
1011
|
|
|
|
1012
|
|
|
$oDB->commit(); |
1013
|
|
|
|
1014
|
|
|
return new BaseObject(); |
1015
|
|
|
} |
1016
|
|
|
|
1017
|
|
|
/** |
1018
|
|
|
* Remove skin vars ofa module |
1019
|
|
|
* @param $module_srl seqence of module |
1020
|
|
|
*/ |
1021
|
|
|
function deleteModuleSkinVars($module_srl) |
1022
|
|
|
{ |
1023
|
|
|
return $this->_deleteModuleSkinVars($module_srl, 'P'); |
1024
|
|
|
} |
1025
|
|
|
|
1026
|
|
|
/** |
1027
|
|
|
* Remove mobile skin vars ofa module |
1028
|
|
|
* @param $module_srl seqence of module |
1029
|
|
|
*/ |
1030
|
|
|
function deleteModuleMobileSkinVars($module_srl) |
1031
|
|
|
{ |
1032
|
|
|
return $this->_deleteModuleSkinVars($module_srl, 'M'); |
1033
|
|
|
} |
1034
|
|
|
|
1035
|
|
|
/** |
1036
|
|
|
* @brief Remove skin vars of a module |
1037
|
|
|
*/ |
1038
|
|
|
function _deleteModuleSkinVars($module_srl, $mode) |
1039
|
|
|
{ |
1040
|
|
|
$args = new stdClass(); |
1041
|
|
|
$args->module_srl = $module_srl; |
1042
|
|
|
$mode = $mode === 'P' ? 'P' : 'M'; |
1043
|
|
|
|
1044
|
|
|
if($mode === 'P') |
1045
|
|
|
{ |
1046
|
|
|
$object_key = 'module_skin_vars:'.$module_srl; |
1047
|
|
|
$query = 'module.deleteModuleSkinVars'; |
1048
|
|
|
} |
1049
|
|
|
else |
1050
|
|
|
{ |
1051
|
|
|
$object_key = 'module_mobile_skin_vars:'.$module_srl; |
1052
|
|
|
$query = 'module.deleteModuleMobileSkinVars'; |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
|
//remove from cache |
1056
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
1057
|
|
|
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); |
1058
|
|
|
if($oCacheHandler->isSupport()) |
1059
|
|
|
{ |
1060
|
|
|
$oCacheHandler->delete($cache_key); |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
return executeQuery($query, $args); |
1064
|
|
|
} |
1065
|
|
|
|
1066
|
|
|
/** |
1067
|
|
|
* @brief Register extra vars to the module |
1068
|
|
|
*/ |
1069
|
|
|
function insertModuleExtraVars($module_srl, $obj) |
1070
|
|
|
{ |
1071
|
|
|
$this->deleteModuleExtraVars($module_srl); |
1072
|
|
|
getDestroyXeVars($obj); |
1073
|
|
|
if(!$obj || !count($obj)) return; |
1074
|
|
|
|
1075
|
|
|
foreach($obj as $key => $val) |
1076
|
|
|
{ |
1077
|
|
|
if(is_object($val) || is_array($val)) continue; |
1078
|
|
|
|
1079
|
|
|
$args = new stdClass(); |
1080
|
|
|
$args->module_srl = $module_srl; |
1081
|
|
|
$args->name = trim($key); |
1082
|
|
|
$args->value = trim($val); |
1083
|
|
|
if(!$args->name || !$args->value) continue; |
1084
|
|
|
$output = executeQuery('module.insertModuleExtraVars', $args); |
|
|
|
|
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
1088
|
|
|
if($oCacheHandler->isSupport()) |
1089
|
|
|
{ |
1090
|
|
|
$object_key = 'module_extra_vars:'.$module_srl; |
1091
|
|
|
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); |
1092
|
|
|
$oCacheHandler->delete($cache_key); |
1093
|
|
|
} |
1094
|
|
|
} |
1095
|
|
|
|
1096
|
|
|
/** |
1097
|
|
|
* @brief Remove extra vars from the module |
1098
|
|
|
*/ |
1099
|
|
View Code Duplication |
function deleteModuleExtraVars($module_srl) |
|
|
|
|
1100
|
|
|
{ |
1101
|
|
|
$args = new stdClass(); |
1102
|
|
|
$args->module_srl = $module_srl; |
1103
|
|
|
$output = executeQuery('module.deleteModuleExtraVars', $args); |
1104
|
|
|
|
1105
|
|
|
//remove from cache |
1106
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
1107
|
|
|
if($oCacheHandler->isSupport()) |
1108
|
|
|
{ |
1109
|
|
|
$object_key = 'module_extra_vars:'.$module_srl; |
1110
|
|
|
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); |
1111
|
|
|
$oCacheHandler->delete($cache_key); |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
return $output; |
1115
|
|
|
} |
1116
|
|
|
|
1117
|
|
|
/** |
1118
|
|
|
* @brief Grant permission to the module |
1119
|
|
|
*/ |
1120
|
|
|
function insertModuleGrants($module_srl, $obj) |
1121
|
|
|
{ |
1122
|
|
|
$this->deleteModuleGrants($module_srl); |
1123
|
|
|
if(!$obj || !count($obj)) return; |
1124
|
|
|
|
1125
|
|
|
foreach($obj as $name => $val) |
1126
|
|
|
{ |
1127
|
|
|
if(!$val || !count($val)) continue; |
1128
|
|
|
|
1129
|
|
|
foreach($val as $group_srl) |
1130
|
|
|
{ |
1131
|
|
|
$args = new stdClass(); |
1132
|
|
|
$args->module_srl = $module_srl; |
1133
|
|
|
$args->name = $name; |
1134
|
|
|
$args->group_srl = trim($group_srl); |
1135
|
|
|
if(!$args->name || !$args->group_srl) continue; |
1136
|
|
|
executeQuery('module.insertModuleGrant', $args); |
1137
|
|
|
} |
1138
|
|
|
} |
1139
|
|
|
} |
1140
|
|
|
|
1141
|
|
|
/** |
1142
|
|
|
* @brief Remove permission from the module |
1143
|
|
|
*/ |
1144
|
|
|
function deleteModuleGrants($module_srl) |
1145
|
|
|
{ |
1146
|
|
|
$args = new stdClass(); |
1147
|
|
|
$args->module_srl = $module_srl; |
1148
|
|
|
return executeQuery('module.deleteModuleGrants', $args); |
1149
|
|
|
} |
1150
|
|
|
|
1151
|
|
|
/** |
1152
|
|
|
* @brief Change user-defined language |
1153
|
|
|
*/ |
1154
|
|
|
function replaceDefinedLangCode(&$output, $isReplaceLangCode = true) |
1155
|
|
|
{ |
1156
|
|
|
if($isReplaceLangCode) |
1157
|
|
|
{ |
1158
|
|
|
$output = preg_replace_callback('!\$user_lang->([a-z0-9\_]+)!is', array($this,'_replaceLangCode'), $output); |
1159
|
|
|
} |
1160
|
|
|
} |
1161
|
|
|
|
1162
|
|
|
function _replaceLangCode($matches) |
1163
|
|
|
{ |
1164
|
|
|
static $lang = false; |
1165
|
|
|
|
1166
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
1167
|
|
|
if($lang === false && $oCacheHandler->isSupport()) |
1168
|
|
|
{ |
1169
|
|
|
$site_module_info = Context::get('site_module_info'); |
1170
|
|
|
if(!$site_module_info) |
1171
|
|
|
{ |
1172
|
|
|
$oModuleModel = getModel('module'); |
1173
|
|
|
$site_module_info = $oModuleModel->getDefaultMid(); |
1174
|
|
|
Context::set('site_module_info', $site_module_info); |
1175
|
|
|
} |
1176
|
|
|
|
1177
|
|
|
$object_key = 'user_defined_langs:' . $site_module_info->site_srl . ':' . Context::getLangType(); |
1178
|
|
|
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); |
1179
|
|
|
$lang = $oCacheHandler->get($cache_key); |
1180
|
|
|
|
1181
|
|
|
if($lang === false) { |
1182
|
|
|
$oModuleAdminController = getAdminController('module'); |
1183
|
|
|
$lang = $oModuleAdminController->makeCacheDefinedLangCode($site_module_info->site_srl); |
1184
|
|
|
} |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
if(!Context::get($matches[1]) && $lang[$matches[1]]) return $lang[$matches[1]]; |
1188
|
|
|
|
1189
|
|
|
return str_replace('$user_lang->','',$matches[0]); |
1190
|
|
|
} |
1191
|
|
|
|
1192
|
|
|
|
1193
|
|
|
/** |
1194
|
|
|
* @brief Add and update a file into the file box |
1195
|
|
|
*/ |
1196
|
|
|
function procModuleFileBoxAdd() |
1197
|
|
|
{ |
1198
|
|
|
$ajax = Context::get('ajax'); |
1199
|
|
|
if ($ajax) Context::setRequestMethod('JSON'); |
1200
|
|
|
|
1201
|
|
|
$logged_info = Context::get('logged_info'); |
1202
|
|
|
if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new BaseObject(-1, 'msg_not_permitted'); |
1203
|
|
|
|
1204
|
|
|
$vars = Context::gets('addfile','filter'); |
1205
|
|
|
$attributeNames = Context::get('attribute_name'); |
1206
|
|
|
$attributeValues = Context::get('attribute_value'); |
1207
|
|
|
if(is_array($attributeNames) && is_array($attributeValues) && count($attributeNames) == count($attributeValues)) |
1208
|
|
|
{ |
1209
|
|
|
$attributes = array(); |
1210
|
|
|
foreach($attributeNames as $no => $name) |
1211
|
|
|
{ |
1212
|
|
|
if(empty($name)) |
1213
|
|
|
{ |
1214
|
|
|
continue; |
1215
|
|
|
} |
1216
|
|
|
$attributes[] = sprintf('%s:%s', $name, $attributeValues[$no]); |
1217
|
|
|
} |
1218
|
|
|
$attributes = implode(';', $attributes); |
1219
|
|
|
} |
1220
|
|
|
|
1221
|
|
|
$vars->comment = $attributes; |
|
|
|
|
1222
|
|
|
$module_filebox_srl = Context::get('module_filebox_srl'); |
1223
|
|
|
|
1224
|
|
|
$ext = strtolower(substr(strrchr($vars->addfile['name'],'.'),1)); |
1225
|
|
|
$vars->ext = $ext; |
1226
|
|
|
if($vars->filter) $filter = explode(',',$vars->filter); |
1227
|
|
|
else $filter = array('jpg','jpeg','gif','png'); |
1228
|
|
|
if(!in_array($ext,$filter)) return new BaseObject(-1, 'msg_error_occured'); |
1229
|
|
|
|
1230
|
|
|
$vars->member_srl = $logged_info->member_srl; |
1231
|
|
|
|
1232
|
|
|
// update |
1233
|
|
|
if($module_filebox_srl > 0) |
1234
|
|
|
{ |
1235
|
|
|
$vars->module_filebox_srl = $module_filebox_srl; |
1236
|
|
|
$output = $this->updateModuleFileBox($vars); |
1237
|
|
|
} |
1238
|
|
|
// insert |
1239
|
|
|
else |
1240
|
|
|
{ |
1241
|
|
|
if(!Context::isUploaded()) return new BaseObject(-1, 'msg_error_occured'); |
1242
|
|
|
$addfile = Context::get('addfile'); |
1243
|
|
|
if(!is_uploaded_file($addfile['tmp_name'])) return new BaseObject(-1, 'msg_error_occured'); |
1244
|
|
|
if($vars->addfile['error'] != 0) return new BaseObject(-1, 'msg_error_occured'); |
1245
|
|
|
$output = $this->insertModuleFileBox($vars); |
1246
|
|
|
} |
1247
|
|
|
|
1248
|
|
|
$this->setTemplatePath($this->module_path.'tpl'); |
1249
|
|
|
|
1250
|
|
|
if (!$ajax) |
1251
|
|
|
{ |
1252
|
|
|
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispModuleAdminFileBox'); |
1253
|
|
|
$this->setRedirectUrl($returnUrl); |
1254
|
|
|
return; |
1255
|
|
|
} |
1256
|
|
|
else |
1257
|
|
|
{ |
1258
|
|
|
if($output) $this->add('save_filename', $output->get('save_filename')); |
1259
|
|
|
else $this->add('save_filename', ''); |
1260
|
|
|
} |
1261
|
|
|
} |
1262
|
|
|
|
1263
|
|
|
/** |
1264
|
|
|
* @brief Update a file into the file box |
1265
|
|
|
*/ |
1266
|
|
|
function updateModuleFileBox($vars) |
1267
|
|
|
{ |
1268
|
|
|
$args = new stdClass; |
1269
|
|
|
// have file |
1270
|
|
|
if($vars->addfile['tmp_name'] && is_uploaded_file($vars->addfile['tmp_name'])) |
1271
|
|
|
{ |
1272
|
|
|
$oModuleModel = getModel('module'); |
1273
|
|
|
$output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl); |
1274
|
|
|
FileHandler::removeFile($output->data->filename); |
1275
|
|
|
|
1276
|
|
|
$path = $oModuleModel->getModuleFileBoxPath($vars->module_filebox_srl); |
1277
|
|
|
FileHandler::makeDir($path); |
1278
|
|
|
|
1279
|
|
|
$random = new Password(); |
1280
|
|
|
$ext = explode($vars->addfile['name'], '.'); |
1281
|
|
|
$ext = strtolower(array_pop($ext)); |
1282
|
|
|
|
1283
|
|
|
$save_filename = sprintf('%s%s.%s', $path, $random->createSecureSalt(32, 'hex'), $ext); |
1284
|
|
|
$tmp = $vars->addfile['tmp_name']; |
1285
|
|
|
|
1286
|
|
|
// Check uploaded file |
1287
|
|
|
if(!checkUploadedFile($tmp)) return false; |
1288
|
|
|
|
1289
|
|
|
if(!@move_uploaded_file($tmp, $save_filename)) |
1290
|
|
|
{ |
1291
|
|
|
return false; |
1292
|
|
|
} |
1293
|
|
|
|
1294
|
|
|
$args->fileextension = $ext; |
1295
|
|
|
$args->filename = $save_filename; |
1296
|
|
|
$args->filesize = $vars->addfile['size']; |
1297
|
|
|
} |
1298
|
|
|
|
1299
|
|
|
$args->module_filebox_srl = $vars->module_filebox_srl; |
1300
|
|
|
$args->comment = $vars->comment; |
1301
|
|
|
|
1302
|
|
|
// FIXME $args ?? |
1303
|
|
|
|
1304
|
|
|
return executeQuery('module.updateModuleFileBox', $vars); |
1305
|
|
|
} |
1306
|
|
|
|
1307
|
|
|
|
1308
|
|
|
/** |
1309
|
|
|
* @brief Add a file into the file box |
1310
|
|
|
*/ |
1311
|
|
|
function insertModuleFileBox($vars) |
1312
|
|
|
{ |
1313
|
|
|
// set module_filebox_srl |
1314
|
|
|
$vars->module_filebox_srl = getNextSequence(); |
1315
|
|
|
|
1316
|
|
|
// get file path |
1317
|
|
|
$oModuleModel = getModel('module'); |
1318
|
|
|
$path = $oModuleModel->getModuleFileBoxPath($vars->module_filebox_srl); |
1319
|
|
|
FileHandler::makeDir($path); |
1320
|
|
|
$random = new Password(); |
1321
|
|
|
$ext = explode($vars->addfile['name'], '.'); |
1322
|
|
|
$ext = strtolower(array_pop($ext)); |
|
|
|
|
1323
|
|
|
|
1324
|
|
|
$save_filename = sprintf('%s%s.%s',$path, $random->createSecureSalt(32, 'hex'), $vars->ext); |
1325
|
|
|
$tmp = $vars->addfile['tmp_name']; |
1326
|
|
|
|
1327
|
|
|
// Check uploaded file |
1328
|
|
|
if(!checkUploadedFile($tmp)) return false; |
1329
|
|
|
|
1330
|
|
|
// upload |
1331
|
|
|
if(!@move_uploaded_file($tmp, $save_filename)) |
1332
|
|
|
{ |
1333
|
|
|
return false; |
1334
|
|
|
} |
1335
|
|
|
|
1336
|
|
|
// insert |
1337
|
|
|
$args = new stdClass; |
1338
|
|
|
$args->module_filebox_srl = $vars->module_filebox_srl; |
1339
|
|
|
$args->member_srl = $vars->member_srl; |
1340
|
|
|
$args->comment = $vars->comment; |
1341
|
|
|
$args->filename = $save_filename; |
1342
|
|
|
$args->fileextension = strtolower(substr(strrchr($vars->addfile['name'],'.'),1)); |
1343
|
|
|
$args->filesize = $vars->addfile['size']; |
1344
|
|
|
|
1345
|
|
|
$output = executeQuery('module.insertModuleFileBox', $args); |
1346
|
|
|
$output->add('save_filename', $save_filename); |
1347
|
|
|
return $output; |
1348
|
|
|
} |
1349
|
|
|
|
1350
|
|
|
|
1351
|
|
|
/** |
1352
|
|
|
* @brief Delete a file from the file box |
1353
|
|
|
*/ |
1354
|
|
|
function procModuleFileBoxDelete() |
1355
|
|
|
{ |
1356
|
|
|
$logged_info = Context::get('logged_info'); |
1357
|
|
|
if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new BaseObject(-1, 'msg_not_permitted'); |
1358
|
|
|
|
1359
|
|
|
$module_filebox_srl = Context::get('module_filebox_srl'); |
1360
|
|
|
if(!$module_filebox_srl) return new BaseObject(-1, 'msg_invalid_request'); |
1361
|
|
|
$vars = new stdClass(); |
1362
|
|
|
$vars->module_filebox_srl = $module_filebox_srl; |
1363
|
|
|
$output = $this->deleteModuleFileBox($vars); |
1364
|
|
|
if(!$output->toBool()) return $output; |
1365
|
|
|
} |
1366
|
|
|
|
1367
|
|
|
function deleteModuleFileBox($vars) |
1368
|
|
|
{ |
1369
|
|
|
// delete real file |
1370
|
|
|
$oModuleModel = getModel('module'); |
1371
|
|
|
$output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl); |
1372
|
|
|
FileHandler::removeFile($output->data->filename); |
1373
|
|
|
|
1374
|
|
|
$args = new stdClass(); |
1375
|
|
|
$args->module_filebox_srl = $vars->module_filebox_srl; |
1376
|
|
|
return executeQuery('module.deleteModuleFileBox', $args); |
1377
|
|
|
} |
1378
|
|
|
|
1379
|
|
|
/** |
1380
|
|
|
* @brief function of locking (timeout is in seconds) |
1381
|
|
|
*/ |
1382
|
|
|
function lock($lock_name, $timeout, $member_srl = null) |
1383
|
|
|
{ |
1384
|
|
|
$this->unlockTimeoutPassed(); |
1385
|
|
|
$args = new stdClass; |
1386
|
|
|
$args->lock_name = $lock_name; |
1387
|
|
|
if(!$timeout) $timeout = 60; |
1388
|
|
|
$args->deadline = date("YmdHis", $_SERVER['REQUEST_TIME'] + $timeout); |
1389
|
|
|
if($member_srl) $args->member_srl = $member_srl; |
1390
|
|
|
$output = executeQuery('module.insertLock', $args); |
1391
|
|
|
if($output->toBool()) |
1392
|
|
|
{ |
1393
|
|
|
$output->add('lock_name', $lock_name); |
1394
|
|
|
$output->add('deadline', $args->deadline); |
1395
|
|
|
} |
1396
|
|
|
return $output; |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
function unlockTimeoutPassed() |
1400
|
|
|
{ |
1401
|
|
|
executeQuery('module.deleteLocksTimeoutPassed'); |
1402
|
|
|
} |
1403
|
|
|
|
1404
|
|
|
function unlock($lock_name, $deadline) |
1405
|
|
|
{ |
1406
|
|
|
$args = new stdClass; |
1407
|
|
|
$args->lock_name = $lock_name; |
1408
|
|
|
$args->deadline = $deadline; |
1409
|
|
|
$output = executeQuery('module.deleteLock', $args); |
1410
|
|
|
return $output; |
1411
|
|
|
} |
1412
|
|
|
|
1413
|
|
|
function updateModuleInSites($site_srls, $args) |
|
|
|
|
1414
|
|
|
{ |
1415
|
|
|
$args = new stdClass; |
1416
|
|
|
$args->site_srls = $site_srls; |
1417
|
|
|
$output = executeQuery('module.updateModuleInSites', $args); |
1418
|
|
|
|
1419
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
1420
|
|
|
if($oCacheHandler->isSupport()) |
1421
|
|
|
{ |
1422
|
|
|
$oCacheHandler->invalidateGroupKey('site_and_module'); |
1423
|
|
|
} |
1424
|
|
|
|
1425
|
|
|
return $output; |
1426
|
|
|
} |
1427
|
|
|
} |
1428
|
|
|
/* End of file module.controller.php */ |
1429
|
|
|
/* Location: ./modules/module/module.controller.php */ |
1430
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.