|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @class ModuleHandler |
|
6
|
|
|
* @author NAVER ([email protected]) |
|
7
|
|
|
* Handling modules |
|
8
|
|
|
* |
|
9
|
|
|
* @remarks This class is to excute actions of modules. |
|
10
|
|
|
* Constructing an instance without any parameterconstructor, it finds the target module based on Context. |
|
11
|
|
|
* If there is no act on the found module, excute an action referencing action_forward. |
|
12
|
|
|
* */ |
|
13
|
|
|
class ModuleHandler extends Handler |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
var $module = NULL; ///< Module |
|
17
|
|
|
var $act = NULL; ///< action |
|
18
|
|
|
var $mid = NULL; ///< Module ID |
|
19
|
|
|
var $document_srl = NULL; ///< Document Number |
|
20
|
|
|
var $module_srl = NULL; ///< Module Number |
|
21
|
|
|
var $module_info = NULL; ///< Module Info. Object |
|
22
|
|
|
var $error = NULL; ///< an error code. |
|
23
|
|
|
var $httpStatusCode = NULL; ///< http status code. |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* prepares variables to use in moduleHandler |
|
27
|
|
|
* @param string $module name of module |
|
28
|
|
|
* @param string $act name of action |
|
29
|
|
|
* @param int $mid |
|
30
|
|
|
* @param int $document_srl |
|
31
|
|
|
* @param int $module_srl |
|
32
|
|
|
* @return void |
|
33
|
|
|
* */ |
|
34
|
|
|
|
|
35
|
|
|
function ModuleHandler($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '') |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
// If XE has not installed yet, set module as install |
|
38
|
|
|
if(!Context::isInstalled()) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->module = 'install'; |
|
41
|
|
|
$this->act = Context::get('act'); |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$oContext = Context::getInstance(); |
|
46
|
|
|
if($oContext->isSuccessInit == FALSE) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$logged_info = Context::get('logged_info'); |
|
49
|
|
|
if($logged_info->is_admin != "Y") |
|
50
|
|
|
{ |
|
51
|
|
|
$this->error = 'msg_invalid_request'; |
|
52
|
|
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// Set variables from request arguments |
|
57
|
|
|
$this->module = $module ? $module : Context::get('module'); |
|
58
|
|
|
$this->act = $act ? $act : Context::get('act'); |
|
59
|
|
|
$this->mid = $mid ? $mid : Context::get('mid'); |
|
60
|
|
|
$this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl'); |
|
61
|
|
|
$this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl'); |
|
62
|
|
|
if($entry = Context::get('entry')) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->entry = Context::convertEncodingStr($entry); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// Validate variables to prevent XSS |
|
68
|
|
|
$isInvalid = NULL; |
|
69
|
|
|
if($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module)) |
|
70
|
|
|
{ |
|
71
|
|
|
$isInvalid = TRUE; |
|
72
|
|
|
} |
|
73
|
|
|
if($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid)) |
|
74
|
|
|
{ |
|
75
|
|
|
$isInvalid = TRUE; |
|
76
|
|
|
} |
|
77
|
|
|
if($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act)) |
|
78
|
|
|
{ |
|
79
|
|
|
$isInvalid = TRUE; |
|
80
|
|
|
} |
|
81
|
|
|
if($isInvalid) |
|
82
|
|
|
{ |
|
83
|
|
|
htmlHeader(); |
|
84
|
|
|
echo Context::getLang("msg_invalid_request"); |
|
85
|
|
|
htmlFooter(); |
|
86
|
|
|
Context::close(); |
|
87
|
|
|
exit; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if(isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0)) |
|
91
|
|
|
{ |
|
92
|
|
|
if(Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on') |
|
93
|
|
|
{ |
|
94
|
|
|
if(Context::get('_https_port')!=null) { |
|
95
|
|
|
header('location:https://' . $_SERVER['HTTP_HOST'] . ':' . Context::get('_https_port') . $_SERVER['REQUEST_URI']); |
|
96
|
|
|
} else { |
|
97
|
|
|
header('location:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
|
98
|
|
|
} |
|
99
|
|
|
return; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// call a trigger before moduleHandler init |
|
104
|
|
|
ModuleHandler::triggerCall('moduleHandler.init', 'before', $this); |
|
105
|
|
|
if(__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0) |
|
106
|
|
|
{ |
|
107
|
|
|
if(__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR']) |
|
108
|
|
|
{ |
|
109
|
|
|
set_error_handler(array($this, 'xeErrorLog'), 3); |
|
110
|
|
|
if(3 & E_ERROR) |
|
111
|
|
|
{ |
|
112
|
|
|
register_shutdown_function(array($this, 'shutdownHandler')); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
else if(__DEBUG_PROTECT__ === 0) |
|
116
|
|
|
{ |
|
117
|
|
|
set_error_handler(array($this, 'xeErrorLog'), 3); |
|
118
|
|
|
if(3 & E_ERROR) |
|
119
|
|
|
{ |
|
120
|
|
|
register_shutdown_function(array($this, 'shutdownHandler')); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
// execute addon (before module initialization) |
|
126
|
|
|
$called_position = 'before_module_init'; |
|
127
|
|
|
$oAddonController = getController('addon'); |
|
128
|
|
|
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc'); |
|
129
|
|
|
if(file_exists($addon_file)) include($addon_file); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext) |
|
|
|
|
|
|
133
|
|
|
{ |
|
134
|
|
|
|
|
135
|
|
|
if(($errnumber & 3) == 0 || error_reporting() == 0) |
|
136
|
|
|
{ |
|
137
|
|
|
return false; |
|
138
|
|
|
} |
|
139
|
|
|
$errorname = self::getErrorType($errnumber);; |
|
140
|
|
|
|
|
141
|
|
|
set_error_handler(array($this, 'dummyHandler'), ~0); |
|
142
|
|
|
$buff = "\n" . $errorname . " : "; |
|
143
|
|
|
$buff .= $errormassage . "\n"; |
|
144
|
|
|
$buff .= "file : " . $errorfile . " line : "; |
|
145
|
|
|
$buff .= $errorline . "\n"; |
|
146
|
|
|
debugPrint($buff); |
|
147
|
|
|
restore_error_handler(); |
|
148
|
|
|
|
|
149
|
|
|
return true; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
function shutdownHandler() |
|
153
|
|
|
{ |
|
154
|
|
|
$errinfo = error_get_last(); |
|
155
|
|
|
if ($errinfo === null || ($errinfo['type'] != 1 && $errinfo['type'] != 4)) |
|
156
|
|
|
{ |
|
157
|
|
|
return false; |
|
158
|
|
|
} |
|
159
|
|
|
$errorname = self::getErrorType($errinfo['type']);; |
|
160
|
|
|
|
|
161
|
|
|
set_error_handler(array($this, 'dummyHandler'), ~0); |
|
162
|
|
|
$buff = "\n" . $errorname . " : "; |
|
163
|
|
|
$buff .= $errinfo['message'] . "\n"; |
|
164
|
|
|
$buff .= "file : " . $errinfo['file'] . " line : "; |
|
165
|
|
|
$buff .= $errinfo['line'] . "\n"; |
|
166
|
|
|
debugPrint($buff); |
|
167
|
|
|
set_error_handler(array($this, 'dummyHandler'), ~0); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* 더미 에러 핸들러. |
|
174
|
|
|
*/ |
|
175
|
|
|
public function dummyHandler($errnumber, $errormassage, $errorfile, $errorline, $errorcontext) |
|
|
|
|
|
|
176
|
|
|
{ |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public static function getErrorType($errno) |
|
180
|
|
|
{ |
|
181
|
|
|
switch ($errno) |
|
182
|
|
|
{ |
|
183
|
|
|
case E_ERROR: return 'Fatal Error'; |
|
184
|
|
|
case E_WARNING: return 'Warning'; |
|
185
|
|
|
case E_NOTICE: return 'Notice'; |
|
186
|
|
|
case E_CORE_ERROR: return 'Core Error'; |
|
187
|
|
|
case E_CORE_WARNING: return 'Core Warning'; |
|
188
|
|
|
case E_COMPILE_ERROR: return 'Compile Error'; |
|
189
|
|
|
case E_COMPILE_WARNING: return 'Compile Warning'; |
|
190
|
|
|
case E_USER_ERROR: return 'User Error'; |
|
191
|
|
|
case E_USER_WARNING: return 'User Warning'; |
|
192
|
|
|
case E_USER_NOTICE: return 'User Notice'; |
|
193
|
|
|
case E_STRICT: return 'Strict Standards'; |
|
194
|
|
|
case E_PARSE: return 'Parse Error'; |
|
195
|
|
|
case E_DEPRECATED: return 'Deprecated'; |
|
196
|
|
|
case E_USER_DEPRECATED: return 'User Deprecated'; |
|
197
|
|
|
case E_RECOVERABLE_ERROR: return 'Catchable Fatal Error'; |
|
198
|
|
|
default: return 'Error'; |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action |
|
204
|
|
|
* @return boolean true: OK, false: redirected |
|
205
|
|
|
* */ |
|
206
|
|
|
function init() |
|
207
|
|
|
{ |
|
208
|
|
|
$oModuleModel = getModel('module'); |
|
209
|
|
|
$site_module_info = Context::get('site_module_info'); |
|
210
|
|
|
|
|
211
|
|
|
// if success_return_url and error_return_url is incorrect |
|
212
|
|
|
$urls = array(Context::get('success_return_url'), Context::get('error_return_url')); |
|
213
|
|
|
foreach($urls as $url) |
|
214
|
|
|
{ |
|
215
|
|
|
if(empty($url)) |
|
216
|
|
|
{ |
|
217
|
|
|
continue; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
$urlInfo = parse_url($url); |
|
221
|
|
|
$host = $urlInfo['host']; |
|
222
|
|
|
|
|
223
|
|
|
$dbInfo = Context::getDBInfo(); |
|
224
|
|
|
$defaultUrlInfo = parse_url($dbInfo->default_url); |
|
225
|
|
|
$defaultHost = $defaultUrlInfo['host']; |
|
226
|
|
|
|
|
227
|
|
|
if($host && ($host != $defaultHost && $host != $site_module_info->domain)) |
|
228
|
|
|
{ |
|
229
|
|
|
throw new Exception('msg_default_url_is_null'); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
if(!$this->document_srl && $this->mid && $this->entry) |
|
234
|
|
|
{ |
|
235
|
|
|
$oDocumentModel = getModel('document'); |
|
236
|
|
|
$this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry); |
|
237
|
|
|
if($this->document_srl) |
|
238
|
|
|
{ |
|
239
|
|
|
Context::set('document_srl', $this->document_srl); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
// Get module's information based on document_srl, if it's specified |
|
244
|
|
|
if($this->document_srl) |
|
245
|
|
|
{ |
|
246
|
|
|
|
|
247
|
|
|
$module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl); |
|
248
|
|
|
// If the document does not exist, remove document_srl |
|
249
|
|
|
if(!$module_info) |
|
250
|
|
|
{ |
|
251
|
|
|
unset($this->document_srl); |
|
252
|
|
|
} |
|
253
|
|
|
else |
|
254
|
|
|
{ |
|
255
|
|
|
// If it exists, compare mid based on the module information |
|
256
|
|
|
// if mids are not matching, set it as the document's mid |
|
257
|
|
|
if(!$this->mid || ($this->mid != $module_info->mid)) |
|
258
|
|
|
{ |
|
259
|
|
|
|
|
260
|
|
|
if(Context::getRequestMethod() == 'GET') |
|
261
|
|
|
{ |
|
262
|
|
|
$this->mid = $module_info->mid; |
|
263
|
|
|
header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
|
264
|
|
|
return FALSE; |
|
265
|
|
|
} |
|
266
|
|
|
else |
|
267
|
|
|
{ |
|
268
|
|
|
$this->mid = $module_info->mid; |
|
269
|
|
|
Context::set('mid', $this->mid); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
} |
|
273
|
|
|
// if requested module is different from one of the document, remove the module information retrieved based on the document number |
|
274
|
|
|
if($this->module && $module_info->module != $this->module) |
|
275
|
|
|
{ |
|
276
|
|
|
unset($module_info); |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
// If module_info is not set yet, and there exists mid information, get module information based on the mid |
|
283
|
|
|
if(!$module_info && $this->mid) |
|
|
|
|
|
|
284
|
|
|
{ |
|
285
|
|
|
$module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl); |
|
286
|
|
|
//if($this->module && $module_info->module != $this->module) unset($module_info); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
// redirect, if module_site_srl and site_srl are different |
|
290
|
|
|
if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0) |
|
291
|
|
|
{ |
|
292
|
|
|
$site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl); |
|
293
|
|
|
header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid)); |
|
294
|
|
|
return FALSE; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
// If module_info is not set still, and $module does not exist, find the default module |
|
298
|
|
|
if(!$module_info && !$this->module && !$this->mid) |
|
299
|
|
|
{ |
|
300
|
|
|
$module_info = $site_module_info; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
if(!$module_info && !$this->module && $site_module_info->module_site_srl) |
|
304
|
|
|
{ |
|
305
|
|
|
$module_info = $site_module_info; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
// redirect, if site_srl of module_info is different from one of site's module_info |
|
309
|
|
|
if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) |
|
310
|
|
|
{ |
|
311
|
|
|
// If the module is of virtual site |
|
312
|
|
|
if($module_info->site_srl) |
|
313
|
|
|
{ |
|
314
|
|
|
$site_info = $oModuleModel->getSiteInfo($module_info->site_srl); |
|
315
|
|
|
$redirect_url = getNotEncodedSiteUrl($site_info->domain, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry')); |
|
316
|
|
|
// If it's called from a virtual site, though it's not a module of the virtual site |
|
317
|
|
|
} |
|
318
|
|
|
else |
|
319
|
|
|
{ |
|
320
|
|
|
$db_info = Context::getDBInfo(); |
|
321
|
|
|
if(!$db_info->default_url) |
|
322
|
|
|
{ |
|
323
|
|
|
return Context::getLang('msg_default_url_is_not_defined'); |
|
324
|
|
|
} |
|
325
|
|
|
else |
|
326
|
|
|
{ |
|
327
|
|
|
$redirect_url = getNotEncodedSiteUrl($db_info->default_url, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry')); |
|
328
|
|
|
} |
|
329
|
|
|
} |
|
330
|
|
|
header("location:" . $redirect_url); |
|
331
|
|
|
return FALSE; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
// If module info was set, retrieve variables from the module information |
|
335
|
|
|
if($module_info) |
|
336
|
|
|
{ |
|
337
|
|
|
$this->module = $module_info->module; |
|
338
|
|
|
$this->mid = $module_info->mid; |
|
339
|
|
|
$this->module_info = $module_info; |
|
340
|
|
|
Context::setBrowserTitle($module_info->browser_title); |
|
341
|
|
|
|
|
342
|
|
|
$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
|
343
|
|
|
$targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl'; |
|
344
|
|
|
|
|
345
|
|
|
// use the site default layout. |
|
346
|
|
|
if($module_info->{$targetSrl} == -1) |
|
347
|
|
|
{ |
|
348
|
|
|
$oLayoutAdminModel = getAdminModel('layout'); |
|
349
|
|
|
$layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl); |
|
350
|
|
|
} |
|
351
|
|
|
else |
|
352
|
|
|
{ |
|
353
|
|
|
$layoutSrl = $module_info->{$targetSrl}; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
// reset a layout_srl in module_info. |
|
357
|
|
|
$module_info->{$targetSrl} = $layoutSrl; |
|
358
|
|
|
|
|
359
|
|
|
$part_config = $oModuleModel->getModulePartConfig('layout', $layoutSrl); |
|
360
|
|
|
Context::addHtmlHeader($part_config->header_script); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
// Set module and mid into module_info |
|
364
|
|
|
if(!isset($this->module_info)) |
|
365
|
|
|
{ |
|
366
|
|
|
$this->module_info = new stdClass(); |
|
367
|
|
|
} |
|
368
|
|
|
$this->module_info->module = $this->module; |
|
369
|
|
|
$this->module_info->mid = $this->mid; |
|
370
|
|
|
|
|
371
|
|
|
// Set site_srl add 2011 08 09 |
|
372
|
|
|
$this->module_info->site_srl = $site_module_info->site_srl; |
|
373
|
|
|
|
|
374
|
|
|
// Still no module? it's an error |
|
375
|
|
|
if(!$this->module) |
|
376
|
|
|
{ |
|
377
|
|
|
$this->error = 'msg_module_is_not_exists'; |
|
378
|
|
|
$this->httpStatusCode = '404'; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
// If mid exists, set mid into context |
|
382
|
|
|
if($this->mid) |
|
383
|
|
|
{ |
|
384
|
|
|
Context::set('mid', $this->mid, TRUE); |
|
|
|
|
|
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
// Call a trigger after moduleHandler init |
|
388
|
|
|
$output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info); |
|
389
|
|
|
if(!$output->toBool()) |
|
390
|
|
|
{ |
|
391
|
|
|
$this->error = $output->getMessage(); |
|
392
|
|
|
return TRUE; |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
// Set current module info into context |
|
396
|
|
|
Context::set('current_module_info', $this->module_info); |
|
|
|
|
|
|
397
|
|
|
|
|
398
|
|
|
return TRUE; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* get a module instance and execute an action |
|
403
|
|
|
* @return ModuleObject executed module instance |
|
404
|
|
|
* */ |
|
405
|
|
|
function procModule() |
|
406
|
|
|
{ |
|
407
|
|
|
$oModuleModel = getModel('module'); |
|
408
|
|
|
$display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
|
409
|
|
|
|
|
410
|
|
|
// If error occurred while preparation, return a message instance |
|
411
|
|
|
if($this->error) |
|
412
|
|
|
{ |
|
413
|
|
|
$this->_setInputErrorToContext(); |
|
414
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
415
|
|
|
$oMessageObject->setError(-1); |
|
416
|
|
|
$oMessageObject->setMessage($this->error); |
|
417
|
|
|
$oMessageObject->dispMessage(); |
|
418
|
|
|
if($this->httpStatusCode) |
|
419
|
|
|
{ |
|
420
|
|
|
$oMessageObject->setHttpStatusCode($this->httpStatusCode); |
|
421
|
|
|
} |
|
422
|
|
|
return $oMessageObject; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
// Get action information with conf/module.xml |
|
426
|
|
|
$xml_info = $oModuleModel->getModuleActionXml($this->module); |
|
427
|
|
|
|
|
428
|
|
|
// If not installed yet, modify act |
|
429
|
|
|
if($this->module == "install") |
|
430
|
|
|
{ |
|
431
|
|
|
if(!$this->act || !$xml_info->action->{$this->act}) |
|
432
|
|
|
{ |
|
433
|
|
|
$this->act = $xml_info->default_index_act; |
|
434
|
|
|
} |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
// if act exists, find type of the action, if not use default index act |
|
438
|
|
|
if(!$this->act) |
|
439
|
|
|
{ |
|
440
|
|
|
$this->act = $xml_info->default_index_act; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
// still no act means error |
|
444
|
|
|
if(!$this->act) |
|
445
|
|
|
{ |
|
446
|
|
|
$this->error = 'msg_module_is_not_exists'; |
|
447
|
|
|
$this->httpStatusCode = '404'; |
|
448
|
|
|
|
|
449
|
|
|
$this->_setInputErrorToContext(); |
|
450
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
451
|
|
|
$oMessageObject->setError(-1); |
|
452
|
|
|
$oMessageObject->setMessage($this->error); |
|
453
|
|
|
$oMessageObject->dispMessage(); |
|
454
|
|
|
if($this->httpStatusCode) |
|
455
|
|
|
{ |
|
456
|
|
|
$oMessageObject->setHttpStatusCode($this->httpStatusCode); |
|
457
|
|
|
} |
|
458
|
|
|
return $oMessageObject; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
// get type, kind |
|
462
|
|
|
$type = $xml_info->action->{$this->act}->type; |
|
463
|
|
|
$ruleset = $xml_info->action->{$this->act}->ruleset; |
|
464
|
|
|
$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
|
465
|
|
|
if(!$kind && $this->module == 'admin') |
|
466
|
|
|
{ |
|
467
|
|
|
$kind = 'admin'; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
// check REQUEST_METHOD in controller |
|
471
|
|
View Code Duplication |
if($type == 'controller') |
|
472
|
|
|
{ |
|
473
|
|
|
$allowedMethod = $xml_info->action->{$this->act}->method; |
|
474
|
|
|
|
|
475
|
|
|
if(!$allowedMethod) |
|
476
|
|
|
{ |
|
477
|
|
|
$allowedMethodList[0] = 'POST'; |
|
|
|
|
|
|
478
|
|
|
} |
|
479
|
|
|
else |
|
480
|
|
|
{ |
|
481
|
|
|
$allowedMethodList = explode('|', strtoupper($allowedMethod)); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
485
|
|
|
{ |
|
486
|
|
|
$this->error = "msg_invalid_request"; |
|
487
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
488
|
|
|
$oMessageObject->setError(-1); |
|
489
|
|
|
$oMessageObject->setMessage($this->error); |
|
490
|
|
|
$oMessageObject->dispMessage(); |
|
491
|
|
|
return $oMessageObject; |
|
492
|
|
|
} |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
if($this->module_info->use_mobile != "Y") |
|
496
|
|
|
{ |
|
497
|
|
|
Mobile::setMobile(FALSE); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
$logged_info = Context::get('logged_info'); |
|
501
|
|
|
|
|
502
|
|
|
// check CSRF for POST actions |
|
503
|
|
|
if($_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && $this->act !== 'procFileUpload' && !checkCSRF()) { |
|
504
|
|
|
$this->error = 'msg_invalid_request'; |
|
505
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
506
|
|
|
$oMessageObject->setError(-1); |
|
507
|
|
|
$oMessageObject->setMessage($this->error); |
|
508
|
|
|
$oMessageObject->dispMessage(); |
|
509
|
|
|
return $oMessageObject; |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
// Admin ip |
|
513
|
|
|
if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
|
514
|
|
|
{ |
|
515
|
|
|
$this->_setInputErrorToContext(); |
|
516
|
|
|
$this->error = "msg_not_permitted_act"; |
|
517
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
518
|
|
|
$oMessageObject->setError(-1); |
|
519
|
|
|
$oMessageObject->setMessage($this->error); |
|
520
|
|
|
$oMessageObject->dispMessage(); |
|
521
|
|
|
return $oMessageObject; |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
// if(type == view, and case for using mobilephone) |
|
525
|
|
|
if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
|
526
|
|
|
{ |
|
527
|
|
|
$orig_type = "view"; |
|
528
|
|
|
$type = "mobile"; |
|
529
|
|
|
// create a module instance |
|
530
|
|
|
$oModule = $this->getModuleInstance($this->module, $type, $kind); |
|
531
|
|
View Code Duplication |
if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
532
|
|
|
{ |
|
533
|
|
|
$type = $orig_type; |
|
534
|
|
|
Mobile::setMobile(FALSE); |
|
535
|
|
|
$oModule = $this->getModuleInstance($this->module, $type, $kind); |
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
else |
|
539
|
|
|
{ |
|
540
|
|
|
// create a module instance |
|
541
|
|
|
$oModule = $this->getModuleInstance($this->module, $type, $kind); |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
View Code Duplication |
if(!is_object($oModule)) |
|
545
|
|
|
{ |
|
546
|
|
|
$this->_setInputErrorToContext(); |
|
547
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
548
|
|
|
$oMessageObject->setError(-1); |
|
549
|
|
|
$oMessageObject->setMessage($this->error); |
|
550
|
|
|
$oMessageObject->dispMessage(); |
|
551
|
|
|
if($this->httpStatusCode) |
|
552
|
|
|
{ |
|
553
|
|
|
$oMessageObject->setHttpStatusCode($this->httpStatusCode); |
|
554
|
|
|
} |
|
555
|
|
|
return $oMessageObject; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
// If there is no such action in the module object |
|
559
|
|
|
if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
|
560
|
|
|
{ |
|
561
|
|
|
|
|
562
|
|
View Code Duplication |
if(!Context::isInstalled()) |
|
563
|
|
|
{ |
|
564
|
|
|
$this->_setInputErrorToContext(); |
|
565
|
|
|
$this->error = 'msg_invalid_request'; |
|
566
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
567
|
|
|
$oMessageObject->setError(-1); |
|
568
|
|
|
$oMessageObject->setMessage($this->error); |
|
569
|
|
|
$oMessageObject->dispMessage(); |
|
570
|
|
|
if($this->httpStatusCode) |
|
571
|
|
|
{ |
|
572
|
|
|
$oMessageObject->setHttpStatusCode($this->httpStatusCode); |
|
573
|
|
|
} |
|
574
|
|
|
return $oMessageObject; |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
$forward = NULL; |
|
578
|
|
|
// 1. Look for the module with action name |
|
579
|
|
|
if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
|
580
|
|
|
{ |
|
581
|
|
|
$module = strtolower($matches[2] . $matches[3]); |
|
582
|
|
|
$xml_info = $oModuleModel->getModuleActionXml($module); |
|
583
|
|
|
|
|
584
|
|
|
if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
|
585
|
|
|
{ |
|
586
|
|
|
$forward = new stdClass(); |
|
587
|
|
|
$forward->module = $module; |
|
588
|
|
|
$forward->type = $xml_info->action->{$this->act}->type; |
|
589
|
|
|
$forward->ruleset = $xml_info->action->{$this->act}->ruleset; |
|
590
|
|
|
$forward->act = $this->act; |
|
591
|
|
|
} |
|
592
|
|
View Code Duplication |
else |
|
593
|
|
|
{ |
|
594
|
|
|
$this->error = 'msg_invalid_request'; |
|
595
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
596
|
|
|
$oMessageObject->setError(-1); |
|
597
|
|
|
$oMessageObject->setMessage($this->error); |
|
598
|
|
|
$oMessageObject->dispMessage(); |
|
599
|
|
|
|
|
600
|
|
|
return $oMessageObject; |
|
601
|
|
|
} |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
if(!$forward) |
|
605
|
|
|
{ |
|
606
|
|
|
$forward = $oModuleModel->getActionForward($this->act); |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
if($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
|
610
|
|
|
{ |
|
611
|
|
|
$kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : ''; |
|
612
|
|
|
$type = $forward->type; |
|
613
|
|
|
$ruleset = $forward->ruleset; |
|
614
|
|
|
$tpl_path = $oModule->getTemplatePath(); |
|
|
|
|
|
|
615
|
|
|
$orig_module = $oModule; |
|
|
|
|
|
|
616
|
|
|
|
|
617
|
|
|
$xml_info = $oModuleModel->getModuleActionXml($forward->module); |
|
618
|
|
|
|
|
619
|
|
|
// SECISSUE also check foward act method |
|
620
|
|
|
// check REQUEST_METHOD in controller |
|
621
|
|
View Code Duplication |
if($type == 'controller') |
|
622
|
|
|
{ |
|
623
|
|
|
$allowedMethod = $xml_info->action->{$forward->act}->method; |
|
624
|
|
|
|
|
625
|
|
|
if(!$allowedMethod) |
|
626
|
|
|
{ |
|
627
|
|
|
$allowedMethodList[0] = 'POST'; |
|
|
|
|
|
|
628
|
|
|
} |
|
629
|
|
|
else |
|
630
|
|
|
{ |
|
631
|
|
|
$allowedMethodList = explode('|', strtoupper($allowedMethod)); |
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
635
|
|
|
{ |
|
636
|
|
|
$this->error = "msg_invalid_request"; |
|
637
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
638
|
|
|
$oMessageObject->setError(-1); |
|
639
|
|
|
$oMessageObject->setMessage($this->error); |
|
640
|
|
|
$oMessageObject->dispMessage(); |
|
641
|
|
|
return $oMessageObject; |
|
642
|
|
|
} |
|
643
|
|
|
} |
|
644
|
|
|
|
|
645
|
|
|
if($type == "view" && Mobile::isFromMobilePhone()) |
|
646
|
|
|
{ |
|
647
|
|
|
$orig_type = "view"; |
|
648
|
|
|
$type = "mobile"; |
|
649
|
|
|
// create a module instance |
|
650
|
|
|
$oModule = $this->getModuleInstance($forward->module, $type, $kind); |
|
651
|
|
View Code Duplication |
if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
652
|
|
|
{ |
|
653
|
|
|
$type = $orig_type; |
|
654
|
|
|
Mobile::setMobile(FALSE); |
|
655
|
|
|
$oModule = $this->getModuleInstance($forward->module, $type, $kind); |
|
656
|
|
|
} |
|
657
|
|
|
} |
|
658
|
|
|
else |
|
659
|
|
|
{ |
|
660
|
|
|
$oModule = $this->getModuleInstance($forward->module, $type, $kind); |
|
661
|
|
|
} |
|
662
|
|
|
|
|
663
|
|
View Code Duplication |
if(!is_object($oModule)) |
|
664
|
|
|
{ |
|
665
|
|
|
$this->_setInputErrorToContext(); |
|
666
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
667
|
|
|
$oMessageObject->setError(-1); |
|
668
|
|
|
$oMessageObject->setMessage('msg_module_is_not_exists'); |
|
669
|
|
|
$oMessageObject->dispMessage(); |
|
670
|
|
|
if($this->httpStatusCode) |
|
671
|
|
|
{ |
|
672
|
|
|
$oMessageObject->setHttpStatusCode($this->httpStatusCode); |
|
673
|
|
|
} |
|
674
|
|
|
return $oMessageObject; |
|
675
|
|
|
} |
|
676
|
|
|
|
|
677
|
|
|
if($this->module == "admin" && $type == "view") |
|
678
|
|
|
{ |
|
679
|
|
|
if($logged_info->is_admin == 'Y') |
|
680
|
|
|
{ |
|
681
|
|
|
if($this->act != 'dispLayoutAdminLayoutModify') |
|
682
|
|
|
{ |
|
683
|
|
|
$oAdminView = getAdminView('admin'); |
|
684
|
|
|
$oAdminView->makeGnbUrl($forward->module); |
|
685
|
|
|
$oModule->setLayoutPath("./modules/admin/tpl"); |
|
686
|
|
|
$oModule->setLayoutFile("layout.html"); |
|
687
|
|
|
} |
|
688
|
|
|
} |
|
689
|
|
View Code Duplication |
else |
|
690
|
|
|
{ |
|
691
|
|
|
$this->_setInputErrorToContext(); |
|
692
|
|
|
|
|
693
|
|
|
$this->error = 'msg_is_not_administrator'; |
|
694
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
695
|
|
|
$oMessageObject->setError(-1); |
|
696
|
|
|
$oMessageObject->setMessage($this->error); |
|
697
|
|
|
$oMessageObject->dispMessage(); |
|
698
|
|
|
return $oMessageObject; |
|
699
|
|
|
} |
|
700
|
|
|
} |
|
701
|
|
|
if($kind == 'admin') |
|
702
|
|
|
{ |
|
703
|
|
|
$grant = $oModuleModel->getGrant($this->module_info, $logged_info); |
|
704
|
|
|
if(!$grant->manager) |
|
705
|
|
|
{ |
|
706
|
|
|
$this->_setInputErrorToContext(); |
|
707
|
|
|
$this->error = 'msg_is_not_manager'; |
|
708
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
709
|
|
|
$oMessageObject->setError(-1); |
|
710
|
|
|
$oMessageObject->setMessage($this->error); |
|
711
|
|
|
$oMessageObject->dispMessage(); |
|
712
|
|
|
return $oMessageObject; |
|
713
|
|
|
} |
|
714
|
|
|
else |
|
715
|
|
|
{ |
|
716
|
|
|
if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
|
|
|
|
|
|
717
|
|
|
{ |
|
718
|
|
|
$this->_setInputErrorToContext(); |
|
719
|
|
|
$this->error = 'msg_is_not_administrator'; |
|
720
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
|
721
|
|
|
$oMessageObject->setError(-1); |
|
722
|
|
|
$oMessageObject->setMessage($this->error); |
|
723
|
|
|
$oMessageObject->dispMessage(); |
|
724
|
|
|
return $oMessageObject; |
|
725
|
|
|
} |
|
726
|
|
|
} |
|
727
|
|
|
} |
|
728
|
|
|
} |
|
729
|
|
|
else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
730
|
|
|
{ |
|
731
|
|
|
$this->act = $xml_info->default_index_act; |
|
732
|
|
|
} |
|
733
|
|
|
else |
|
734
|
|
|
{ |
|
735
|
|
|
$this->error = 'msg_invalid_request'; |
|
736
|
|
|
$oModule->setError(-1); |
|
737
|
|
|
$oModule->setMessage($this->error); |
|
738
|
|
|
return $oModule; |
|
739
|
|
|
} |
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
// ruleset check... |
|
743
|
|
|
if(!empty($ruleset)) |
|
744
|
|
|
{ |
|
745
|
|
|
$rulesetModule = $forward->module ? $forward->module : $this->module; |
|
|
|
|
|
|
746
|
|
|
$rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid); |
|
747
|
|
|
if(!empty($rulesetFile)) |
|
748
|
|
|
{ |
|
749
|
|
|
if($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
|
750
|
|
|
{ |
|
751
|
|
|
$errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG']; |
|
752
|
|
|
foreach($errorLang as $key => $val) |
|
753
|
|
|
{ |
|
754
|
|
|
Context::setLang($key, $val); |
|
755
|
|
|
} |
|
756
|
|
|
unset($_SESSION['XE_VALIDATOR_ERROR_LANG']); |
|
757
|
|
|
} |
|
758
|
|
|
|
|
759
|
|
|
$Validator = new Validator($rulesetFile); |
|
760
|
|
|
$result = $Validator->validate(); |
|
761
|
|
|
if(!$result) |
|
762
|
|
|
{ |
|
763
|
|
|
$lastError = $Validator->getLastError(); |
|
764
|
|
|
$returnUrl = Context::get('error_return_url'); |
|
765
|
|
|
$errorMsg = $lastError['msg'] ? $lastError['msg'] : 'validation error'; |
|
766
|
|
|
|
|
767
|
|
|
//for xml response |
|
768
|
|
|
$oModule->setError(-1); |
|
769
|
|
|
$oModule->setMessage($errorMsg); |
|
770
|
|
|
//for html redirect |
|
771
|
|
|
$this->error = $errorMsg; |
|
772
|
|
|
$_SESSION['XE_VALIDATOR_ERROR'] = -1; |
|
773
|
|
|
$_SESSION['XE_VALIDATOR_MESSAGE'] = $this->error; |
|
774
|
|
|
$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = 'error'; |
|
775
|
|
|
$_SESSION['XE_VALIDATOR_RETURN_URL'] = $returnUrl; |
|
776
|
|
|
$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
|
777
|
|
|
$this->_setInputValueToSession(); |
|
778
|
|
|
return $oModule; |
|
779
|
|
|
} |
|
780
|
|
|
} |
|
781
|
|
|
} |
|
782
|
|
|
|
|
783
|
|
|
$oModule->setAct($this->act); |
|
784
|
|
|
|
|
785
|
|
|
$this->module_info->module_type = $type; |
|
786
|
|
|
$oModule->setModuleInfo($this->module_info, $xml_info); |
|
787
|
|
|
|
|
788
|
|
|
$skipAct = array( |
|
789
|
|
|
'dispEditorConfigPreview' => 1, |
|
790
|
|
|
'dispLayoutPreviewWithModule' => 1 |
|
791
|
|
|
); |
|
792
|
|
|
$db_use_mobile = Mobile::isMobileEnabled(); |
|
793
|
|
|
if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
|
794
|
|
|
{ |
|
795
|
|
|
global $lang; |
|
796
|
|
|
$header = '<style>div.xe_mobile{opacity:0.7;margin:1em 0;padding:.5em;background:#333;border:1px solid #666;border-left:0;border-right:0}p.xe_mobile{text-align:center;margin:1em 0}a.xe_mobile{color:#ff0;font-weight:bold;font-size:24px}@media only screen and (min-width:500px){a.xe_mobile{font-size:15px}}</style>'; |
|
797
|
|
|
$footer = '<div class="xe_mobile"><p class="xe_mobile"><a class="xe_mobile" href="' . getUrl('m', '1') . '">' . $lang->msg_pc_to_mobile . '</a></p></div>'; |
|
798
|
|
|
Context::addHtmlHeader($header); |
|
799
|
|
|
Context::addHtmlFooter($footer); |
|
800
|
|
|
} |
|
801
|
|
|
|
|
802
|
|
|
if($type == "view" && $kind != 'admin') |
|
803
|
|
|
{ |
|
804
|
|
|
$module_config = $oModuleModel->getModuleConfig('module'); |
|
805
|
|
|
if($module_config->htmlFooter) |
|
806
|
|
|
{ |
|
807
|
|
|
Context::addHtmlFooter($module_config->htmlFooter); |
|
808
|
|
|
} |
|
809
|
|
|
if($module_config->siteTitle) |
|
810
|
|
|
{ |
|
811
|
|
|
$siteTitle = Context::getBrowserTitle(); |
|
812
|
|
|
if(!$siteTitle) |
|
813
|
|
|
{ |
|
814
|
|
|
Context::setBrowserTitle($module_config->siteTitle); |
|
815
|
|
|
} |
|
816
|
|
|
} |
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
// if failed message exists in session, set context |
|
820
|
|
|
$this->_setInputErrorToContext(); |
|
821
|
|
|
|
|
822
|
|
|
$procResult = $oModule->proc(); |
|
823
|
|
|
|
|
824
|
|
|
$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
|
825
|
|
|
if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
|
826
|
|
|
{ |
|
827
|
|
|
$error = $oModule->getError(); |
|
828
|
|
|
$message = $oModule->getMessage(); |
|
829
|
|
|
$messageType = $oModule->getMessageType(); |
|
830
|
|
|
$redirectUrl = $oModule->getRedirectUrl(); |
|
831
|
|
|
if($messageType == 'error') debugPrint($message, 'ERROR'); |
|
|
|
|
|
|
832
|
|
|
|
|
833
|
|
|
if(!$procResult) |
|
834
|
|
|
{ |
|
835
|
|
|
$this->error = $message; |
|
836
|
|
|
if(!$redirectUrl && Context::get('error_return_url')) |
|
837
|
|
|
{ |
|
838
|
|
|
$redirectUrl = Context::get('error_return_url'); |
|
839
|
|
|
} |
|
840
|
|
|
$this->_setInputValueToSession(); |
|
841
|
|
|
} |
|
842
|
|
|
else |
|
|
|
|
|
|
843
|
|
|
{ |
|
844
|
|
|
|
|
845
|
|
|
} |
|
846
|
|
|
|
|
847
|
|
|
$_SESSION['XE_VALIDATOR_ERROR'] = $error; |
|
848
|
|
|
$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
|
849
|
|
|
if($message != 'success') |
|
850
|
|
|
{ |
|
851
|
|
|
$_SESSION['XE_VALIDATOR_MESSAGE'] = $message; |
|
852
|
|
|
} |
|
853
|
|
|
$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType; |
|
854
|
|
|
|
|
855
|
|
|
if(Context::get('xeVirtualRequestMethod') != 'xml') |
|
856
|
|
|
{ |
|
857
|
|
|
$_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl; |
|
858
|
|
|
} |
|
859
|
|
|
} |
|
860
|
|
|
|
|
861
|
|
|
unset($logged_info); |
|
862
|
|
|
return $oModule; |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
/** |
|
866
|
|
|
* set error message to Session. |
|
867
|
|
|
* @return void |
|
868
|
|
|
* */ |
|
869
|
|
|
function _setInputErrorToContext() |
|
870
|
|
|
{ |
|
871
|
|
|
if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) |
|
872
|
|
|
{ |
|
873
|
|
|
Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']); |
|
874
|
|
|
} |
|
875
|
|
|
if($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE')) |
|
876
|
|
|
{ |
|
877
|
|
|
Context::set('XE_VALIDATOR_MESSAGE', $_SESSION['XE_VALIDATOR_MESSAGE']); |
|
878
|
|
|
} |
|
879
|
|
|
if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE')) |
|
880
|
|
|
{ |
|
881
|
|
|
Context::set('XE_VALIDATOR_MESSAGE_TYPE', $_SESSION['XE_VALIDATOR_MESSAGE_TYPE']); |
|
882
|
|
|
} |
|
883
|
|
|
if($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL')) |
|
884
|
|
|
{ |
|
885
|
|
|
Context::set('XE_VALIDATOR_RETURN_URL', $_SESSION['XE_VALIDATOR_RETURN_URL']); |
|
886
|
|
|
} |
|
887
|
|
|
if($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID')) |
|
888
|
|
|
{ |
|
889
|
|
|
Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']); |
|
890
|
|
|
} |
|
891
|
|
|
if(count($_SESSION['INPUT_ERROR'])) |
|
892
|
|
|
{ |
|
893
|
|
|
Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']); |
|
894
|
|
|
} |
|
895
|
|
|
|
|
896
|
|
|
$this->_clearErrorSession(); |
|
897
|
|
|
} |
|
898
|
|
|
|
|
899
|
|
|
/** |
|
900
|
|
|
* clear error message to Session. |
|
901
|
|
|
* @return void |
|
902
|
|
|
* */ |
|
903
|
|
|
function _clearErrorSession() |
|
904
|
|
|
{ |
|
905
|
|
|
$_SESSION['XE_VALIDATOR_ERROR'] = ''; |
|
906
|
|
|
$_SESSION['XE_VALIDATOR_MESSAGE'] = ''; |
|
907
|
|
|
$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = ''; |
|
908
|
|
|
$_SESSION['XE_VALIDATOR_RETURN_URL'] = ''; |
|
909
|
|
|
$_SESSION['XE_VALIDATOR_ID'] = ''; |
|
910
|
|
|
$_SESSION['INPUT_ERROR'] = ''; |
|
911
|
|
|
} |
|
912
|
|
|
|
|
913
|
|
|
/** |
|
914
|
|
|
* occured error when, set input values to session. |
|
915
|
|
|
* @return void |
|
916
|
|
|
* */ |
|
917
|
|
|
function _setInputValueToSession() |
|
918
|
|
|
{ |
|
919
|
|
|
$requestVars = Context::getRequestVars(); |
|
920
|
|
|
unset($requestVars->act, $requestVars->mid, $requestVars->vid, $requestVars->success_return_url, $requestVars->error_return_url); |
|
921
|
|
|
foreach($requestVars AS $key => $value) |
|
922
|
|
|
{ |
|
923
|
|
|
$_SESSION['INPUT_ERROR'][$key] = $value; |
|
924
|
|
|
} |
|
925
|
|
|
} |
|
926
|
|
|
|
|
927
|
|
|
/** |
|
928
|
|
|
* display contents from executed module |
|
929
|
|
|
* @param ModuleObject $oModule module instance |
|
930
|
|
|
* @return void |
|
931
|
|
|
* */ |
|
932
|
|
|
function displayContent($oModule = NULL) |
|
933
|
|
|
{ |
|
934
|
|
|
// If the module is not set or not an object, set error |
|
935
|
|
|
if(!$oModule || !is_object($oModule)) |
|
936
|
|
|
{ |
|
937
|
|
|
$this->error = 'msg_module_is_not_exists'; |
|
938
|
|
|
$this->httpStatusCode = '404'; |
|
939
|
|
|
} |
|
940
|
|
|
|
|
941
|
|
|
// If connection to DB has a problem even though it's not install module, set error |
|
942
|
|
|
if($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE) |
|
943
|
|
|
{ |
|
944
|
|
|
$this->error = 'msg_dbconnect_failed'; |
|
945
|
|
|
} |
|
946
|
|
|
|
|
947
|
|
|
// Call trigger after moduleHandler proc |
|
948
|
|
|
$output = ModuleHandler::triggerCall('moduleHandler.proc', 'after', $oModule); |
|
|
|
|
|
|
949
|
|
|
if(!$output->toBool()) |
|
950
|
|
|
{ |
|
951
|
|
|
$this->error = $output->getMessage(); |
|
952
|
|
|
} |
|
953
|
|
|
|
|
954
|
|
|
// Use message view object, if HTML call |
|
955
|
|
|
$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
|
956
|
|
|
if(!isset($methodList[Context::getRequestMethod()])) |
|
957
|
|
|
{ |
|
958
|
|
|
|
|
959
|
|
|
if($_SESSION['XE_VALIDATOR_RETURN_URL']) |
|
960
|
|
|
{ |
|
961
|
|
|
$display_handler = new DisplayHandler(); |
|
962
|
|
|
$display_handler->_debugOutput(); |
|
963
|
|
|
|
|
964
|
|
|
header('location:' . $_SESSION['XE_VALIDATOR_RETURN_URL']); |
|
965
|
|
|
return; |
|
966
|
|
|
} |
|
967
|
|
|
|
|
968
|
|
|
// If error occurred, handle it |
|
969
|
|
|
if($this->error) |
|
970
|
|
|
{ |
|
971
|
|
|
// display content with message module instance |
|
972
|
|
|
$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
|
973
|
|
|
$oMessageObject = ModuleHandler::getModuleInstance('message', $type); |
|
974
|
|
|
$oMessageObject->setError(-1); |
|
975
|
|
|
$oMessageObject->setMessage($this->error); |
|
976
|
|
|
$oMessageObject->dispMessage(); |
|
977
|
|
|
|
|
978
|
|
|
if($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200') |
|
979
|
|
|
{ |
|
980
|
|
|
$this->_setHttpStatusMessage($oMessageObject->getHttpStatusCode()); |
|
981
|
|
|
$oMessageObject->setTemplateFile('http_status_code'); |
|
982
|
|
|
} |
|
983
|
|
|
|
|
984
|
|
|
// If module was called normally, change the templates of the module into ones of the message view module |
|
985
|
|
|
if($oModule) |
|
986
|
|
|
{ |
|
987
|
|
|
$oModule->setTemplatePath($oMessageObject->getTemplatePath()); |
|
988
|
|
|
$oModule->setTemplateFile($oMessageObject->getTemplateFile()); |
|
989
|
|
|
// Otherwise, set message instance as the target module |
|
990
|
|
|
} |
|
991
|
|
|
else |
|
992
|
|
|
{ |
|
993
|
|
|
$oModule = $oMessageObject; |
|
994
|
|
|
} |
|
995
|
|
|
|
|
996
|
|
|
$this->_clearErrorSession(); |
|
997
|
|
|
} |
|
998
|
|
|
|
|
999
|
|
|
// Check if layout_srl exists for the module |
|
1000
|
|
|
if(Mobile::isFromMobilePhone()) |
|
1001
|
|
|
{ |
|
1002
|
|
|
$layout_srl = $oModule->module_info->mlayout_srl; |
|
1003
|
|
|
} |
|
1004
|
|
|
else |
|
1005
|
|
|
{ |
|
1006
|
|
|
$layout_srl = $oModule->module_info->layout_srl; |
|
1007
|
|
|
} |
|
1008
|
|
|
|
|
1009
|
|
|
// if layout_srl is rollback by module, set default layout |
|
1010
|
|
|
if($layout_srl == -1) |
|
1011
|
|
|
{ |
|
1012
|
|
|
$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
|
1013
|
|
|
$oLayoutAdminModel = getAdminModel('layout'); |
|
1014
|
|
|
$layout_srl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $oModule->module_info->site_srl); |
|
1015
|
|
|
} |
|
1016
|
|
|
|
|
1017
|
|
|
if($layout_srl && !$oModule->getLayoutFile()) |
|
1018
|
|
|
{ |
|
1019
|
|
|
|
|
1020
|
|
|
// If layout_srl exists, get information of the layout, and set the location of layout_path/ layout_file |
|
1021
|
|
|
$oLayoutModel = getModel('layout'); |
|
1022
|
|
|
$layout_info = $oLayoutModel->getLayout($layout_srl); |
|
|
|
|
|
|
1023
|
|
|
if($layout_info) |
|
1024
|
|
|
{ |
|
1025
|
|
|
|
|
1026
|
|
|
// Input extra_vars into $layout_info |
|
1027
|
|
View Code Duplication |
if($layout_info->extra_var_count) |
|
1028
|
|
|
{ |
|
1029
|
|
|
|
|
1030
|
|
|
foreach($layout_info->extra_var as $var_id => $val) |
|
1031
|
|
|
{ |
|
1032
|
|
|
if($val->type == 'image') |
|
1033
|
|
|
{ |
|
1034
|
|
|
if(strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
1035
|
|
|
{ |
|
1036
|
|
|
$val->value = Context::getRequestUri() . substr($val->value, 2); |
|
1037
|
|
|
} |
|
1038
|
|
|
} |
|
1039
|
|
|
$layout_info->{$var_id} = $val->value; |
|
1040
|
|
|
} |
|
1041
|
|
|
} |
|
1042
|
|
|
// Set menus into context |
|
1043
|
|
|
if($layout_info->menu_count) |
|
1044
|
|
|
{ |
|
1045
|
|
|
foreach($layout_info->menu as $menu_id => $menu) |
|
1046
|
|
|
{ |
|
1047
|
|
|
// set default menu set(included home menu) |
|
1048
|
|
View Code Duplication |
if(!$menu->menu_srl || $menu->menu_srl == -1) |
|
1049
|
|
|
{ |
|
1050
|
|
|
$oMenuAdminController = getAdminController('menu'); |
|
1051
|
|
|
$homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile(); |
|
1052
|
|
|
|
|
1053
|
|
|
if(FileHandler::exists($homeMenuCacheFile)) |
|
|
|
|
|
|
1054
|
|
|
{ |
|
1055
|
|
|
include($homeMenuCacheFile); |
|
1056
|
|
|
} |
|
1057
|
|
|
|
|
1058
|
|
|
if(!$menu->menu_srl) |
|
1059
|
|
|
{ |
|
1060
|
|
|
$menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file); |
|
|
|
|
|
|
1061
|
|
|
$menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file); |
|
1062
|
|
|
$layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl; |
|
1063
|
|
|
} |
|
1064
|
|
|
else |
|
1065
|
|
|
{ |
|
1066
|
|
|
$menu->xml_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->xml_file); |
|
1067
|
|
|
$menu->php_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->php_file); |
|
1068
|
|
|
} |
|
1069
|
|
|
} |
|
1070
|
|
|
|
|
1071
|
|
|
$php_file = FileHandler::exists($menu->php_file); |
|
1072
|
|
|
if($php_file) |
|
|
|
|
|
|
1073
|
|
|
{ |
|
1074
|
|
|
include($php_file); |
|
1075
|
|
|
} |
|
1076
|
|
|
Context::set($menu_id, $menu); |
|
1077
|
|
|
} |
|
1078
|
|
|
} |
|
1079
|
|
|
|
|
1080
|
|
|
// Set layout information into context |
|
1081
|
|
|
Context::set('layout_info', $layout_info); |
|
1082
|
|
|
|
|
1083
|
|
|
$oModule->setLayoutPath($layout_info->path); |
|
1084
|
|
|
$oModule->setLayoutFile('layout'); |
|
1085
|
|
|
|
|
1086
|
|
|
// If layout was modified, use the modified version |
|
1087
|
|
|
$edited_layout = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl); |
|
1088
|
|
|
if(file_exists($edited_layout)) |
|
1089
|
|
|
{ |
|
1090
|
|
|
$oModule->setEditedLayoutFile($edited_layout); |
|
1091
|
|
|
} |
|
1092
|
|
|
} |
|
1093
|
|
|
} |
|
1094
|
|
|
$isLayoutDrop = Context::get('isLayoutDrop'); |
|
1095
|
|
|
if($isLayoutDrop) |
|
1096
|
|
|
{ |
|
1097
|
|
|
$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
|
1098
|
|
|
if($kind == 'admin') |
|
1099
|
|
|
{ |
|
1100
|
|
|
$oModule->setLayoutFile('popup_layout'); |
|
1101
|
|
|
} |
|
1102
|
|
|
else |
|
1103
|
|
|
{ |
|
1104
|
|
|
$oModule->setLayoutPath('common/tpl'); |
|
1105
|
|
|
$oModule->setLayoutFile('default_layout'); |
|
1106
|
|
|
} |
|
1107
|
|
|
} |
|
1108
|
|
|
} |
|
1109
|
|
|
|
|
1110
|
|
|
// Display contents |
|
1111
|
|
|
$oDisplayHandler = new DisplayHandler(); |
|
1112
|
|
|
$oDisplayHandler->printContent($oModule); |
|
1113
|
|
|
} |
|
1114
|
|
|
|
|
1115
|
|
|
/** |
|
1116
|
|
|
* returns module's path |
|
1117
|
|
|
* @param string $module module name |
|
1118
|
|
|
* @return string path of the module |
|
1119
|
|
|
* */ |
|
1120
|
|
|
function getModulePath($module) |
|
1121
|
|
|
{ |
|
1122
|
|
|
return sprintf('./modules/%s/', $module); |
|
1123
|
|
|
} |
|
1124
|
|
|
|
|
1125
|
|
|
/** |
|
1126
|
|
|
* It creates a module instance |
|
1127
|
|
|
* @param string $module module name |
|
1128
|
|
|
* @param string $type instance type, (e.g., view, controller, model) |
|
1129
|
|
|
* @param string $kind admin or svc |
|
1130
|
|
|
* @return ModuleObject module instance (if failed it returns null) |
|
1131
|
|
|
* @remarks if there exists a module instance created before, returns it. |
|
1132
|
|
|
* */ |
|
1133
|
|
|
function &getModuleInstance($module, $type = 'view', $kind = '') |
|
1134
|
|
|
{ |
|
1135
|
|
|
|
|
1136
|
|
|
if(__DEBUG__ == 3) |
|
1137
|
|
|
{ |
|
1138
|
|
|
$start_time = getMicroTime(); |
|
1139
|
|
|
} |
|
1140
|
|
|
|
|
1141
|
|
|
$parent_module = $module; |
|
1142
|
|
|
$kind = strtolower($kind); |
|
1143
|
|
|
$type = strtolower($type); |
|
1144
|
|
|
|
|
1145
|
|
|
$kinds = array('svc' => 1, 'admin' => 1); |
|
1146
|
|
|
if(!isset($kinds[$kind])) |
|
1147
|
|
|
{ |
|
1148
|
|
|
$kind = 'svc'; |
|
1149
|
|
|
} |
|
1150
|
|
|
|
|
1151
|
|
|
$key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type; |
|
1152
|
|
|
|
|
1153
|
|
|
if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) |
|
1154
|
|
|
{ |
|
1155
|
|
|
$module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key]; |
|
1156
|
|
|
} |
|
1157
|
|
|
|
|
1158
|
|
|
// if there is no instance of the module in global variable, create a new one |
|
1159
|
|
|
if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind])) |
|
1160
|
|
|
{ |
|
1161
|
|
|
ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name); |
|
1162
|
|
|
|
|
1163
|
|
|
if($extend_module && (!is_readable($high_class_file) || !is_readable($class_file))) |
|
|
|
|
|
|
1164
|
|
|
{ |
|
1165
|
|
|
$module = $parent_module; |
|
1166
|
|
|
ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name); |
|
1167
|
|
|
} |
|
1168
|
|
|
|
|
1169
|
|
|
// Check if the base class and instance class exist |
|
1170
|
|
|
if(!class_exists($module, true)) |
|
1171
|
|
|
{ |
|
1172
|
|
|
return NULL; |
|
1173
|
|
|
} |
|
1174
|
|
|
if(!class_exists($instance_name, true)) |
|
1175
|
|
|
{ |
|
1176
|
|
|
return NULL; |
|
1177
|
|
|
} |
|
1178
|
|
|
|
|
1179
|
|
|
// Create an instance |
|
1180
|
|
|
$oModule = new $instance_name(); |
|
1181
|
|
|
if(!is_object($oModule)) |
|
1182
|
|
|
{ |
|
1183
|
|
|
return NULL; |
|
1184
|
|
|
} |
|
1185
|
|
|
|
|
1186
|
|
|
// Load language files for the class |
|
1187
|
|
|
Context::loadLang($class_path . 'lang'); |
|
1188
|
|
|
if($extend_module) |
|
1189
|
|
|
{ |
|
1190
|
|
|
Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang'); |
|
1191
|
|
|
} |
|
1192
|
|
|
|
|
1193
|
|
|
// Set variables to the instance |
|
1194
|
|
|
$oModule->setModule($module); |
|
1195
|
|
|
$oModule->setModulePath($class_path); |
|
1196
|
|
|
|
|
1197
|
|
|
// If the module has a constructor, run it. |
|
1198
|
|
|
if(!isset($GLOBALS['_called_constructor'][$instance_name])) |
|
1199
|
|
|
{ |
|
1200
|
|
|
$GLOBALS['_called_constructor'][$instance_name] = TRUE; |
|
1201
|
|
|
if(@method_exists($oModule, $instance_name)) |
|
1202
|
|
|
{ |
|
1203
|
|
|
$oModule->{$instance_name}(); |
|
1204
|
|
|
} |
|
1205
|
|
|
} |
|
1206
|
|
|
|
|
1207
|
|
|
// Store the created instance into GLOBALS variable |
|
1208
|
|
|
$GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule; |
|
1209
|
|
|
} |
|
1210
|
|
|
|
|
1211
|
|
|
if(__DEBUG__ == 3) |
|
1212
|
|
|
{ |
|
1213
|
|
|
$GLOBALS['__elapsed_class_load__'] += getMicroTime() - $start_time; |
|
|
|
|
|
|
1214
|
|
|
} |
|
1215
|
|
|
|
|
1216
|
|
|
// return the instance |
|
1217
|
|
|
return $GLOBALS['_loaded_module'][$module][$type][$kind]; |
|
1218
|
|
|
} |
|
1219
|
|
|
|
|
1220
|
|
|
function _getModuleFilePath($module, $type, $kind, &$classPath, &$highClassFile, &$classFile, &$instanceName) |
|
1221
|
|
|
{ |
|
1222
|
|
|
$classPath = ModuleHandler::getModulePath($module); |
|
1223
|
|
|
|
|
1224
|
|
|
$highClassFile = sprintf('%s%s%s.class.php', _XE_PATH_, $classPath, $module); |
|
1225
|
|
|
$highClassFile = FileHandler::getRealPath($highClassFile); |
|
1226
|
|
|
|
|
1227
|
|
|
$types = array('view','controller','model','api','wap','mobile','class'); |
|
1228
|
|
|
if(!in_array($type, $types)) |
|
1229
|
|
|
{ |
|
1230
|
|
|
$type = $types[0]; |
|
1231
|
|
|
} |
|
1232
|
|
|
if($type == 'class') |
|
1233
|
|
|
{ |
|
1234
|
|
|
$instanceName = '%s'; |
|
1235
|
|
|
$classFile = '%s%s.%s.php'; |
|
1236
|
|
|
} |
|
1237
|
|
|
elseif($kind == 'admin' && array_search($type, $types) < 3) |
|
1238
|
|
|
{ |
|
1239
|
|
|
$instanceName = '%sAdmin%s'; |
|
1240
|
|
|
$classFile = '%s%s.admin.%s.php'; |
|
1241
|
|
|
} |
|
1242
|
|
|
else |
|
1243
|
|
|
{ |
|
1244
|
|
|
$instanceName = '%s%s'; |
|
1245
|
|
|
$classFile = '%s%s.%s.php'; |
|
1246
|
|
|
} |
|
1247
|
|
|
|
|
1248
|
|
|
$instanceName = sprintf($instanceName, $module, ucfirst($type)); |
|
1249
|
|
|
$classFile = FileHandler::getRealPath(sprintf($classFile, $classPath, $module, $type)); |
|
1250
|
|
|
} |
|
1251
|
|
|
|
|
1252
|
|
|
/** |
|
1253
|
|
|
* call a trigger |
|
1254
|
|
|
* @param string $trigger_name trigger's name to call |
|
1255
|
|
|
* @param string $called_position called position |
|
1256
|
|
|
* @param object $obj an object as a parameter to trigger |
|
1257
|
|
|
* @return Object |
|
1258
|
|
|
* */ |
|
1259
|
|
|
function triggerCall($trigger_name, $called_position, &$obj) |
|
1260
|
|
|
{ |
|
1261
|
|
|
// skip if not installed |
|
1262
|
|
|
if(!Context::isInstalled()) |
|
1263
|
|
|
{ |
|
1264
|
|
|
return new Object(); |
|
1265
|
|
|
} |
|
1266
|
|
|
|
|
1267
|
|
|
$oModuleModel = getModel('module'); |
|
1268
|
|
|
$triggers = $oModuleModel->getTriggers($trigger_name, $called_position); |
|
1269
|
|
|
if(!$triggers || count($triggers) < 1) |
|
1270
|
|
|
{ |
|
1271
|
|
|
return new Object(); |
|
1272
|
|
|
} |
|
1273
|
|
|
|
|
1274
|
|
|
//store before trigger call time |
|
1275
|
|
|
$before_trigger_time = NULL; |
|
|
|
|
|
|
1276
|
|
|
if(__LOG_SLOW_TRIGGER__> 0) |
|
1277
|
|
|
{ |
|
1278
|
|
|
$before_trigger_time = microtime(true); |
|
|
|
|
|
|
1279
|
|
|
} |
|
1280
|
|
|
|
|
1281
|
|
|
foreach($triggers as $item) |
|
1282
|
|
|
{ |
|
1283
|
|
|
$module = $item->module; |
|
1284
|
|
|
$type = $item->type; |
|
1285
|
|
|
$called_method = $item->called_method; |
|
1286
|
|
|
|
|
1287
|
|
|
// todo why don't we call a normal class object ? |
|
1288
|
|
|
$oModule = getModule($module, $type); |
|
1289
|
|
|
if(!$oModule || !method_exists($oModule, $called_method)) |
|
1290
|
|
|
{ |
|
1291
|
|
|
continue; |
|
1292
|
|
|
} |
|
1293
|
|
|
|
|
1294
|
|
|
$before_each_trigger_time = microtime(true); |
|
1295
|
|
|
|
|
1296
|
|
|
$output = $oModule->{$called_method}($obj); |
|
1297
|
|
|
|
|
1298
|
|
|
$after_each_trigger_time = microtime(true); |
|
1299
|
|
|
$elapsed_time_trigger = $after_each_trigger_time - $before_each_trigger_time; |
|
1300
|
|
|
|
|
1301
|
|
|
$slowlog = new stdClass; |
|
1302
|
|
|
$slowlog->caller = $trigger_name . '.' . $called_position; |
|
1303
|
|
|
$slowlog->called = $module . '.' . $called_method; |
|
1304
|
|
|
$slowlog->called_extension = $module; |
|
1305
|
|
|
if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1306
|
|
|
|
|
1307
|
|
|
if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) |
|
1308
|
|
|
{ |
|
1309
|
|
|
return $output; |
|
1310
|
|
|
} |
|
1311
|
|
|
unset($oModule); |
|
1312
|
|
|
} |
|
1313
|
|
|
|
|
1314
|
|
|
return new Object(); |
|
1315
|
|
|
} |
|
1316
|
|
|
|
|
1317
|
|
|
/** |
|
1318
|
|
|
* get http status message by http status code |
|
1319
|
|
|
* @param string $code |
|
1320
|
|
|
* @return string |
|
1321
|
|
|
* */ |
|
1322
|
|
|
function _setHttpStatusMessage($code) |
|
1323
|
|
|
{ |
|
1324
|
|
|
$statusMessageList = array( |
|
1325
|
|
|
'100' => 'Continue', |
|
1326
|
|
|
'101' => 'Switching Protocols', |
|
1327
|
|
|
'201' => 'OK', // todo check array key '201' |
|
1328
|
|
|
'201' => 'Created', |
|
1329
|
|
|
'202' => 'Accepted', |
|
1330
|
|
|
'203' => 'Non-Authoritative Information', |
|
1331
|
|
|
'204' => 'No Content', |
|
1332
|
|
|
'205' => 'Reset Content', |
|
1333
|
|
|
'206' => 'Partial Content', |
|
1334
|
|
|
'300' => 'Multiple Choices', |
|
1335
|
|
|
'301' => 'Moved Permanently', |
|
1336
|
|
|
'302' => 'Found', |
|
1337
|
|
|
'303' => 'See Other', |
|
1338
|
|
|
'304' => 'Not Modified', |
|
1339
|
|
|
'305' => 'Use Proxy', |
|
1340
|
|
|
'307' => 'Temporary Redirect', |
|
1341
|
|
|
'400' => 'Bad Request', |
|
1342
|
|
|
'401' => 'Unauthorized', |
|
1343
|
|
|
'402' => 'Payment Required', |
|
1344
|
|
|
'403' => 'Forbidden', |
|
1345
|
|
|
'404' => 'Not Found', |
|
1346
|
|
|
'405' => 'Method Not Allowed', |
|
1347
|
|
|
'406' => 'Not Acceptable', |
|
1348
|
|
|
'407' => 'Proxy Authentication Required', |
|
1349
|
|
|
'408' => 'Request Timeout', |
|
1350
|
|
|
'409' => 'Conflict', |
|
1351
|
|
|
'410' => 'Gone', |
|
1352
|
|
|
'411' => 'Length Required', |
|
1353
|
|
|
'412' => 'Precondition Failed', |
|
1354
|
|
|
'413' => 'Request Entity Too Large', |
|
1355
|
|
|
'414' => 'Request-URI Too Long', |
|
1356
|
|
|
'415' => 'Unsupported Media Type', |
|
1357
|
|
|
'416' => 'Requested Range Not Satisfiable', |
|
1358
|
|
|
'417' => 'Expectation Failed', |
|
1359
|
|
|
'500' => 'Internal Server Error', |
|
1360
|
|
|
'501' => 'Not Implemented', |
|
1361
|
|
|
'502' => 'Bad Gateway', |
|
1362
|
|
|
'503' => 'Service Unavailable', |
|
1363
|
|
|
'504' => 'Gateway Timeout', |
|
1364
|
|
|
'505' => 'HTTP Version Not Supported', |
|
1365
|
|
|
); |
|
1366
|
|
|
$statusMessage = $statusMessageList[$code]; |
|
1367
|
|
|
if(!$statusMessage) |
|
1368
|
|
|
{ |
|
1369
|
|
|
$statusMessage = 'OK'; |
|
1370
|
|
|
} |
|
1371
|
|
|
|
|
1372
|
|
|
Context::set('http_status_code', $code); |
|
1373
|
|
|
Context::set('http_status_message', $statusMessage); |
|
1374
|
|
|
} |
|
1375
|
|
|
|
|
1376
|
|
|
} |
|
1377
|
|
|
/* End of file ModuleHandler.class.php */ |
|
1378
|
|
|
/* Location: ./classes/module/ModuleHandler.class.php */ |
|
1379
|
|
|
|