1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) XEHub <https://www.xehub.io> */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @class ModuleObject |
6
|
|
|
* @author XEHub ([email protected]) |
7
|
|
|
* base class of ModuleHandler |
8
|
|
|
* */ |
9
|
|
|
class ModuleObject extends BaseObject |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
var $mid = NULL; ///< string to represent run-time instance of Module (XE Module) |
13
|
|
|
var $module = NULL; ///< Class name of Xe Module that is identified by mid |
14
|
|
|
var $module_srl = NULL; ///< integer value to represent a run-time instance of Module (XE Module) |
15
|
|
|
var $module_info = NULL; ///< an object containing the module information |
16
|
|
|
var $origin_module_info = NULL; |
17
|
|
|
var $xml_info = NULL; ///< an object containing the module description extracted from XML file |
18
|
|
|
var $module_path = NULL; ///< a path to directory where module source code resides |
19
|
|
|
var $act = NULL; ///< a string value to contain the action name |
20
|
|
|
var $template_path = NULL; ///< a path of directory where template files reside |
21
|
|
|
var $template_file = NULL; ///< name of template file |
22
|
|
|
var $layout_path = ''; ///< a path of directory where layout files reside |
23
|
|
|
var $layout_file = ''; ///< name of layout file |
24
|
|
|
var $edited_layout_file = ''; ///< name of temporary layout files that is modified in an admin mode |
25
|
|
|
var $stop_proc = FALSE; ///< a flag to indicating whether to stop the execution of code. |
26
|
|
|
var $module_config = NULL; |
27
|
|
|
var $ajaxRequestMethod = array('XMLRPC', 'JSON'); |
28
|
|
|
var $gzhandler_enable = TRUE; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* setter to set the name of module |
32
|
|
|
* @param string $module name of module |
33
|
|
|
* @return void |
34
|
|
|
* */ |
35
|
|
|
function setModule($module) |
36
|
|
|
{ |
37
|
|
|
$this->module = $module; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* setter to set the name of module path |
42
|
|
|
* @param string $path the directory path to a module directory |
43
|
|
|
* @return void |
44
|
|
|
* */ |
45
|
|
|
function setModulePath($path) |
46
|
|
|
{ |
47
|
|
|
if(substr_compare($path, '/', -1) !== 0) |
48
|
|
|
{ |
49
|
|
|
$path.='/'; |
50
|
|
|
} |
51
|
|
|
$this->module_path = $path; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* setter to set an url for redirection |
56
|
|
|
* @param string $url url for redirection |
57
|
|
|
* @remark redirect_url is used only for ajax requests |
58
|
|
|
* @return void |
59
|
|
|
* */ |
60
|
|
|
function setRedirectUrl($url = './', $output = NULL) |
61
|
|
|
{ |
62
|
|
|
$ajaxRequestMethod = array_flip($this->ajaxRequestMethod); |
63
|
|
|
if(!isset($ajaxRequestMethod[Context::getRequestMethod()])) |
64
|
|
|
{ |
65
|
|
|
$this->add('redirect_url', $url); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if($output !== NULL && is_object($output)) |
69
|
|
|
{ |
70
|
|
|
return $output; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* get url for redirection |
76
|
|
|
* @return string redirect_url |
77
|
|
|
* */ |
78
|
|
|
function getRedirectUrl() |
79
|
|
|
{ |
80
|
|
|
return $this->get('redirect_url'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* set message |
85
|
|
|
* @param string $message a message string |
86
|
|
|
* @param string $type type of message (error, info, update) |
87
|
|
|
* @return void |
88
|
|
|
* */ |
89
|
|
|
function setMessage($message = 'success', $type = NULL) |
90
|
|
|
{ |
91
|
|
|
parent::setMessage($message); |
92
|
|
|
$this->setMessageType($type); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* set type of message |
97
|
|
|
* @param string $type type of message (error, info, update) |
98
|
|
|
* @return void |
99
|
|
|
* */ |
100
|
|
|
function setMessageType($type) |
101
|
|
|
{ |
102
|
|
|
$this->add('message_type', $type); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* get type of message |
107
|
|
|
* @return string $type |
108
|
|
|
* */ |
109
|
|
|
function getMessageType() |
110
|
|
|
{ |
111
|
|
|
$type = $this->get('message_type'); |
112
|
|
|
$typeList = array('error' => 1, 'info' => 1, 'update' => 1); |
113
|
|
|
if(!isset($typeList[$type])) |
114
|
|
|
{ |
115
|
|
|
$type = $this->getError() ? 'error' : 'info'; |
116
|
|
|
} |
117
|
|
|
return $type; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* sett to set the template path for refresh.html |
122
|
|
|
* refresh.html is executed as a result of method execution |
123
|
|
|
* Tpl as the common run of the refresh.html .. |
124
|
|
|
* @return void |
125
|
|
|
* */ |
126
|
|
|
function setRefreshPage() |
127
|
|
|
{ |
128
|
|
|
$this->setTemplatePath('./common/tpl'); |
129
|
|
|
$this->setTemplateFile('refresh'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* sett to set the action name |
134
|
|
|
* @param string $act |
135
|
|
|
* @return void |
136
|
|
|
* */ |
137
|
|
|
function setAct($act) |
138
|
|
|
{ |
139
|
|
|
$this->act = $act; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* sett to set module information |
144
|
|
|
* @param object $module_info object containing module information |
145
|
|
|
* @param object $xml_info object containing module description |
146
|
|
|
* @return void |
147
|
|
|
* */ |
148
|
|
|
function setModuleInfo($module_info, $xml_info) |
149
|
|
|
{ |
150
|
|
|
// The default variable settings |
151
|
|
|
$this->mid = $module_info->mid; |
152
|
|
|
$this->module_srl = $module_info->module_srl; |
153
|
|
|
$this->module_info = $module_info; |
154
|
|
|
$this->origin_module_info = $module_info; |
155
|
|
|
$this->xml_info = $xml_info; |
156
|
|
|
$this->skin_vars = $module_info->skin_vars; |
|
|
|
|
157
|
|
|
// validate certificate info and permission settings necessary in Web-services |
158
|
|
|
$is_logged = Context::get('is_logged'); |
159
|
|
|
$logged_info = Context::get('logged_info'); |
160
|
|
|
// module model create an object |
161
|
|
|
$oModuleModel = getModel('module'); |
162
|
|
|
// permission settings. access, manager(== is_admin) are fixed and privilege name in XE |
163
|
|
|
$module_srl = Context::get('module_srl'); |
164
|
|
|
if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl)) |
165
|
|
|
{ |
166
|
|
|
$request_module = $oModuleModel->getModuleInfoByModuleSrl($module_srl); |
167
|
|
|
if($request_module->module_srl == $module_srl) |
168
|
|
|
{ |
169
|
|
|
$grant = $oModuleModel->getGrant($request_module, $logged_info); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
else |
173
|
|
|
{ |
174
|
|
|
$grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info); |
175
|
|
|
// have at least access grant |
176
|
|
|
if(substr_count($this->act, 'Member') || substr_count($this->act, 'Communication')) |
177
|
|
|
{ |
178
|
|
|
$grant->access = 1; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
// display no permission if the current module doesn't have an access privilege |
182
|
|
|
//if(!$grant->access) return $this->stop("msg_not_permitted"); |
183
|
|
|
// checks permission and action if you don't have an admin privilege |
184
|
|
|
if(!$grant->manager) |
|
|
|
|
185
|
|
|
{ |
186
|
|
|
// get permission types(guest, member, manager, root) of the currently requested action |
187
|
|
|
$permission_target = $xml_info->permission->{$this->act}; |
188
|
|
|
// check manager if a permission in module.xml otherwise action if no permission |
189
|
|
|
if(!$permission_target && substr_count($this->act, 'Admin')) |
190
|
|
|
{ |
191
|
|
|
$permission_target = 'manager'; |
192
|
|
|
} |
193
|
|
|
// Check permissions |
194
|
|
|
switch($permission_target) |
195
|
|
|
{ |
196
|
|
|
case 'root' : |
197
|
|
|
case 'manager' : |
198
|
|
|
$this->stop('msg_is_not_administrator'); |
199
|
|
|
return; |
200
|
|
|
case 'member' : |
201
|
|
|
if(!$is_logged) |
202
|
|
|
{ |
203
|
|
|
$this->stop('msg_not_permitted_act'); |
204
|
|
|
return; |
205
|
|
|
} |
206
|
|
|
break; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
// permission variable settings |
210
|
|
|
$this->grant = $grant; |
|
|
|
|
211
|
|
|
|
212
|
|
|
Context::set('grant', $grant); |
213
|
|
|
|
214
|
|
|
$this->module_config = $oModuleModel->getModuleConfig($this->module, $module_info->site_srl); |
215
|
|
|
|
216
|
|
|
if(method_exists($this, 'init')) |
217
|
|
|
{ |
218
|
|
|
$this->init(); |
|
|
|
|
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* set the stop_proc and approprate message for msg_code |
224
|
|
|
* @param string $msg_code an error code |
225
|
|
|
* @return ModuleObject $this |
226
|
|
|
* */ |
227
|
|
|
function stop($msg_code) |
228
|
|
|
{ |
229
|
|
|
// flag setting to stop the proc processing |
230
|
|
|
$this->stop_proc = TRUE; |
231
|
|
|
// Error handling |
232
|
|
|
$this->setError(-1); |
233
|
|
|
$this->setMessage($msg_code); |
234
|
|
|
// Error message display by message module |
235
|
|
|
$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
236
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $type); |
237
|
|
|
$oMessageObject->setError(-1); |
238
|
|
|
$oMessageObject->setMessage($msg_code); |
239
|
|
|
$oMessageObject->dispMessage(); |
240
|
|
|
|
241
|
|
|
$this->setTemplatePath($oMessageObject->getTemplatePath()); |
242
|
|
|
$this->setTemplateFile($oMessageObject->getTemplateFile()); |
243
|
|
|
|
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* set the file name of the template file |
249
|
|
|
* @param string name of file |
250
|
|
|
* @return void |
251
|
|
|
* */ |
252
|
|
|
function setTemplateFile($filename) |
253
|
|
|
{ |
254
|
|
|
if(isset($filename) && substr_compare($filename, '.html', -5) !== 0) |
255
|
|
|
{ |
256
|
|
|
$filename .= '.html'; |
257
|
|
|
} |
258
|
|
|
$this->template_file = $filename; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* retrieve the directory path of the template directory |
263
|
|
|
* @return string |
264
|
|
|
* */ |
265
|
|
|
function getTemplateFile() |
266
|
|
|
{ |
267
|
|
|
return $this->template_file; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* set the directory path of the template directory |
272
|
|
|
* @param string path of template directory. |
273
|
|
|
* @return void |
274
|
|
|
* */ |
275
|
|
View Code Duplication |
function setTemplatePath($path) |
|
|
|
|
276
|
|
|
{ |
277
|
|
|
if(!$path) return; |
278
|
|
|
|
279
|
|
|
if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
280
|
|
|
{ |
281
|
|
|
$path = './' . $path; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
if(substr_compare($path, '/', -1) !== 0) |
285
|
|
|
{ |
286
|
|
|
$path .= '/'; |
287
|
|
|
} |
288
|
|
|
$this->template_path = $path; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* retrieve the directory path of the template directory |
293
|
|
|
* @return string |
294
|
|
|
* */ |
295
|
|
|
function getTemplatePath() |
296
|
|
|
{ |
297
|
|
|
return $this->template_path; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* set the file name of the temporarily modified by admin |
302
|
|
|
* @param string name of file |
303
|
|
|
* @return void |
304
|
|
|
* */ |
305
|
|
|
function setEditedLayoutFile($filename) |
306
|
|
|
{ |
307
|
|
|
if(!$filename) return; |
308
|
|
|
|
309
|
|
|
if(substr_compare($filename, '.html', -5) !== 0) |
310
|
|
|
{ |
311
|
|
|
$filename .= '.html'; |
312
|
|
|
} |
313
|
|
|
$this->edited_layout_file = $filename; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* retreived the file name of edited_layout_file |
318
|
|
|
* @return string |
319
|
|
|
* */ |
320
|
|
|
function getEditedLayoutFile() |
321
|
|
|
{ |
322
|
|
|
return $this->edited_layout_file; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* set the file name of the layout file |
327
|
|
|
* @param string name of file |
328
|
|
|
* @return void |
329
|
|
|
* */ |
330
|
|
|
function setLayoutFile($filename) |
331
|
|
|
{ |
332
|
|
|
if(!$filename) return; |
333
|
|
|
|
334
|
|
|
if(substr_compare($filename, '.html', -5) !== 0) |
335
|
|
|
{ |
336
|
|
|
$filename .= '.html'; |
337
|
|
|
} |
338
|
|
|
$this->layout_file = $filename; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* get the file name of the layout file |
343
|
|
|
* @return string |
344
|
|
|
* */ |
345
|
|
|
function getLayoutFile() |
346
|
|
|
{ |
347
|
|
|
return $this->layout_file; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* set the directory path of the layout directory |
352
|
|
|
* @param string path of layout directory. |
353
|
|
|
* */ |
354
|
|
View Code Duplication |
function setLayoutPath($path) |
|
|
|
|
355
|
|
|
{ |
356
|
|
|
if(!$path) return; |
357
|
|
|
|
358
|
|
|
if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
359
|
|
|
{ |
360
|
|
|
$path = './' . $path; |
361
|
|
|
} |
362
|
|
|
if(substr_compare($path, '/', -1) !== 0) |
363
|
|
|
{ |
364
|
|
|
$path .= '/'; |
365
|
|
|
} |
366
|
|
|
$this->layout_path = $path; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* set the directory path of the layout directory |
371
|
|
|
* @return string |
372
|
|
|
* */ |
373
|
|
|
function getLayoutPath($layout_name = "", $layout_type = "P") |
374
|
|
|
{ |
375
|
|
|
return $this->layout_path; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* excute the member method specified by $act variable |
380
|
|
|
* @return boolean true : success false : fail |
381
|
|
|
* */ |
382
|
|
|
function proc() |
383
|
|
|
{ |
384
|
|
|
// pass if stop_proc is true |
385
|
|
|
if($this->stop_proc) |
386
|
|
|
{ |
387
|
|
|
debugPrint($this->message, 'ERROR'); |
|
|
|
|
388
|
|
|
return FALSE; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
// trigger call |
392
|
|
|
$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'before', $this); |
393
|
|
|
if(!$triggerOutput->toBool()) |
394
|
|
|
{ |
395
|
|
|
$this->setError($triggerOutput->getError()); |
396
|
|
|
$this->setMessage($triggerOutput->getMessage()); |
397
|
|
|
return FALSE; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
// execute an addon(call called_position as before_module_proc) |
401
|
|
|
$called_position = 'before_module_proc'; |
402
|
|
|
$oAddonController = getController('addon'); |
403
|
|
|
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc"); |
404
|
|
|
if(FileHandler::exists($addon_file)) include($addon_file); |
|
|
|
|
405
|
|
|
|
406
|
|
|
if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act)) |
407
|
|
|
{ |
408
|
|
|
// Check permissions |
409
|
|
|
if($this->module_srl && !$this->grant->access) |
410
|
|
|
{ |
411
|
|
|
$this->stop("msg_not_permitted_act"); |
412
|
|
|
return FALSE; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
// integrate skin information of the module(change to sync skin info with the target module only by seperating its table) |
416
|
|
|
$is_default_skin = ((!Mobile::isFromMobilePhone() && $this->module_info->is_skin_fix == 'N') || (Mobile::isFromMobilePhone() && $this->module_info->is_mskin_fix == 'N')); |
417
|
|
|
$usedSkinModule = !($this->module == 'page' && ($this->module_info->page_type == 'OUTSIDE' || $this->module_info->page_type == 'WIDGET')); |
418
|
|
|
if($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module) |
419
|
|
|
{ |
420
|
|
|
$dir = (Mobile::isFromMobilePhone()) ? 'm.skins' : 'skins'; |
421
|
|
|
$valueName = (Mobile::isFromMobilePhone()) ? 'mskin' : 'skin'; |
422
|
|
|
$oModuleModel = getModel('module'); |
423
|
|
|
$skinType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
424
|
|
|
$skinName = $oModuleModel->getModuleDefaultSkin($this->module, $skinType); |
425
|
|
|
if($this->module == 'page') |
426
|
|
|
{ |
427
|
|
|
$this->module_info->{$valueName} = $skinName; |
428
|
|
|
} |
429
|
|
|
else |
430
|
|
|
{ |
431
|
|
|
$isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE); |
432
|
|
|
if(!$isTemplatPath) |
433
|
|
|
{ |
434
|
|
|
$this->setTemplatePath(sprintf('%s%s/%s/', $this->module_path, $dir, $skinName)); |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
$oModuleModel = getModel('module'); |
440
|
|
|
$oModuleModel->syncSkinInfoToModuleInfo($this->module_info); |
441
|
|
|
Context::set('module_info', $this->module_info); |
442
|
|
|
// Run |
443
|
|
|
$output = $this->{$this->act}(); |
444
|
|
|
} |
445
|
|
|
else |
446
|
|
|
{ |
447
|
|
|
return FALSE; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
// trigger call |
451
|
|
|
$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'after', $this); |
452
|
|
|
if(!$triggerOutput->toBool()) |
453
|
|
|
{ |
454
|
|
|
$this->setError($triggerOutput->getError()); |
455
|
|
|
$this->setMessage($triggerOutput->getMessage()); |
456
|
|
|
return FALSE; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
// execute an addon(call called_position as after_module_proc) |
460
|
|
|
$called_position = 'after_module_proc'; |
461
|
|
|
$oAddonController = getController('addon'); |
462
|
|
|
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc"); |
463
|
|
|
if(FileHandler::exists($addon_file)) include($addon_file); |
|
|
|
|
464
|
|
|
|
465
|
|
|
if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject')) |
466
|
|
|
{ |
467
|
|
|
$this->setError($output->getError()); |
468
|
|
|
$this->setMessage($output->getMessage()); |
469
|
|
|
|
470
|
|
|
if(!$output->toBool()) |
471
|
|
|
{ |
472
|
|
|
return FALSE; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
// execute api methods of the module if view action is and result is XMLRPC or JSON |
476
|
|
|
if($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile') |
477
|
|
|
{ |
478
|
|
|
if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON') |
479
|
|
|
{ |
480
|
|
|
$oAPI = getAPI($this->module_info->module, 'api'); |
|
|
|
|
481
|
|
|
if(method_exists($oAPI, $this->act)) |
482
|
|
|
{ |
483
|
|
|
$oAPI->{$this->act}($this); |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
return TRUE; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
} |
491
|
|
|
/* End of file ModuleObject.class.php */ |
492
|
|
|
/* Location: ./classes/module/ModuleObject.class.php */ |
493
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: