Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ModuleHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ModuleHandler, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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 = '') |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action |
||
| 115 | * @return boolean true: OK, false: redirected |
||
| 116 | * */ |
||
| 117 | function init() |
||
| 118 | { |
||
| 119 | $oModuleModel = getModel('module'); |
||
| 120 | $site_module_info = Context::get('site_module_info'); |
||
| 121 | |||
| 122 | // if success_return_url and error_return_url is incorrect |
||
| 123 | $urls = array(Context::get('success_return_url'), Context::get('error_return_url')); |
||
| 124 | foreach($urls as $url) |
||
| 125 | { |
||
| 126 | if(empty($url)) |
||
| 127 | { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | |||
| 131 | $urlInfo = parse_url($url); |
||
| 132 | $host = $urlInfo['host']; |
||
| 133 | |||
| 134 | $dbInfo = Context::getDBInfo(); |
||
| 135 | $defaultUrlInfo = parse_url($dbInfo->default_url); |
||
| 136 | $defaultHost = $defaultUrlInfo['host']; |
||
| 137 | |||
| 138 | if($host && ($host != $defaultHost && $host != $site_module_info->domain)) |
||
| 139 | { |
||
| 140 | throw new Exception('msg_default_url_is_null'); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | if(!$this->document_srl && $this->mid && $this->entry) |
||
| 145 | { |
||
| 146 | $oDocumentModel = getModel('document'); |
||
| 147 | $this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry); |
||
| 148 | if($this->document_srl) |
||
| 149 | { |
||
| 150 | Context::set('document_srl', $this->document_srl); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | // Get module's information based on document_srl, if it's specified |
||
| 155 | if($this->document_srl) |
||
| 156 | { |
||
| 157 | |||
| 158 | $module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl); |
||
| 159 | // If the document does not exist, remove document_srl |
||
| 160 | if(!$module_info) |
||
| 161 | { |
||
| 162 | unset($this->document_srl); |
||
| 163 | } |
||
| 164 | else |
||
| 165 | { |
||
| 166 | // If it exists, compare mid based on the module information |
||
| 167 | // if mids are not matching, set it as the document's mid |
||
| 168 | if(!$this->mid || ($this->mid != $module_info->mid)) |
||
| 169 | { |
||
| 170 | |||
| 171 | if(Context::getRequestMethod() == 'GET') |
||
| 172 | { |
||
| 173 | $this->mid = $module_info->mid; |
||
| 174 | header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
||
| 175 | return FALSE; |
||
| 176 | } |
||
| 177 | else |
||
| 178 | { |
||
| 179 | $this->mid = $module_info->mid; |
||
| 180 | Context::set('mid', $this->mid); |
||
| 181 | } |
||
| 182 | |||
| 183 | } |
||
| 184 | // if requested module is different from one of the document, remove the module information retrieved based on the document number |
||
| 185 | if($this->module && $module_info->module != $this->module) |
||
| 186 | { |
||
| 187 | unset($module_info); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | } |
||
| 192 | |||
| 193 | // If module_info is not set yet, and there exists mid information, get module information based on the mid |
||
| 194 | if(!$module_info && $this->mid) |
||
| 195 | { |
||
| 196 | $module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl); |
||
| 197 | //if($this->module && $module_info->module != $this->module) unset($module_info); |
||
| 198 | } |
||
| 199 | |||
| 200 | // redirect, if module_site_srl and site_srl are different |
||
| 201 | if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0) |
||
| 202 | { |
||
| 203 | $site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl); |
||
| 204 | header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid)); |
||
| 205 | return FALSE; |
||
| 206 | } |
||
| 207 | |||
| 208 | // If module_info is not set still, and $module does not exist, find the default module |
||
| 209 | if(!$module_info && !$this->module && !$this->mid) |
||
| 210 | { |
||
| 211 | $module_info = $site_module_info; |
||
| 212 | } |
||
| 213 | |||
| 214 | if(!$module_info && !$this->module && $site_module_info->module_site_srl) |
||
| 215 | { |
||
| 216 | $module_info = $site_module_info; |
||
| 217 | } |
||
| 218 | |||
| 219 | // redirect, if site_srl of module_info is different from one of site's module_info |
||
| 220 | if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) |
||
| 221 | { |
||
| 222 | // If the module is of virtual site |
||
| 223 | if($module_info->site_srl) |
||
| 224 | { |
||
| 225 | $site_info = $oModuleModel->getSiteInfo($module_info->site_srl); |
||
| 226 | $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')); |
||
| 227 | // If it's called from a virtual site, though it's not a module of the virtual site |
||
| 228 | } |
||
| 229 | else |
||
| 230 | { |
||
| 231 | $db_info = Context::getDBInfo(); |
||
| 232 | if(!$db_info->default_url) |
||
| 233 | { |
||
| 234 | return Context::getLang('msg_default_url_is_not_defined'); |
||
| 235 | } |
||
| 236 | else |
||
| 237 | { |
||
| 238 | $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')); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | header("location:" . $redirect_url); |
||
| 242 | return FALSE; |
||
| 243 | } |
||
| 244 | |||
| 245 | // If module info was set, retrieve variables from the module information |
||
| 246 | if($module_info) |
||
| 247 | { |
||
| 248 | $this->module = $module_info->module; |
||
| 249 | $this->mid = $module_info->mid; |
||
| 250 | $this->module_info = $module_info; |
||
| 251 | Context::setBrowserTitle($module_info->browser_title); |
||
| 252 | |||
| 253 | $viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
||
| 254 | $targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl'; |
||
| 255 | |||
| 256 | // use the site default layout. |
||
| 257 | if($module_info->{$targetSrl} == -1) |
||
| 258 | { |
||
| 259 | $oLayoutAdminModel = getAdminModel('layout'); |
||
| 260 | $layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl); |
||
| 261 | } |
||
| 262 | else |
||
| 263 | { |
||
| 264 | $layoutSrl = $module_info->{$targetSrl}; |
||
| 265 | } |
||
| 266 | |||
| 267 | // reset a layout_srl in module_info. |
||
| 268 | $module_info->{$targetSrl} = $layoutSrl; |
||
| 269 | |||
| 270 | $part_config = $oModuleModel->getModulePartConfig('layout', $layoutSrl); |
||
| 271 | Context::addHtmlHeader($part_config->header_script); |
||
| 272 | } |
||
| 273 | |||
| 274 | // Set module and mid into module_info |
||
| 275 | if(!isset($this->module_info)) |
||
| 276 | { |
||
| 277 | $this->module_info = new stdClass(); |
||
| 278 | } |
||
| 279 | $this->module_info->module = $this->module; |
||
| 280 | $this->module_info->mid = $this->mid; |
||
| 281 | |||
| 282 | // Set site_srl add 2011 08 09 |
||
| 283 | $this->module_info->site_srl = $site_module_info->site_srl; |
||
| 284 | |||
| 285 | // Still no module? it's an error |
||
| 286 | if(!$this->module) |
||
| 287 | { |
||
| 288 | $this->error = 'msg_module_is_not_exists'; |
||
| 289 | $this->httpStatusCode = '404'; |
||
| 290 | } |
||
| 291 | |||
| 292 | // If mid exists, set mid into context |
||
| 293 | if($this->mid) |
||
| 294 | { |
||
| 295 | Context::set('mid', $this->mid, TRUE); |
||
| 296 | } |
||
| 297 | |||
| 298 | // Call a trigger after moduleHandler init |
||
| 299 | $output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info); |
||
| 300 | if(!$output->toBool()) |
||
| 301 | { |
||
| 302 | $this->error = $output->getMessage(); |
||
| 303 | return TRUE; |
||
| 304 | } |
||
| 305 | |||
| 306 | // Set current module info into context |
||
| 307 | Context::set('current_module_info', $this->module_info); |
||
| 308 | |||
| 309 | return TRUE; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * get a module instance and execute an action |
||
| 314 | * @return ModuleObject executed module instance |
||
| 315 | * */ |
||
| 316 | function procModule() |
||
| 317 | { |
||
| 318 | $oModuleModel = getModel('module'); |
||
| 319 | $display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
||
| 320 | |||
| 321 | // If error occurred while preparation, return a message instance |
||
| 322 | if($this->error) |
||
| 323 | { |
||
| 324 | $this->_setInputErrorToContext(); |
||
| 325 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 326 | $oMessageObject->setError(-1); |
||
| 327 | $oMessageObject->setMessage($this->error); |
||
| 328 | $oMessageObject->dispMessage(); |
||
| 329 | if($this->httpStatusCode) |
||
| 330 | { |
||
| 331 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 332 | } |
||
| 333 | return $oMessageObject; |
||
| 334 | } |
||
| 335 | |||
| 336 | // Get action information with conf/module.xml |
||
| 337 | $xml_info = $oModuleModel->getModuleActionXml($this->module); |
||
| 338 | |||
| 339 | // If not installed yet, modify act |
||
| 340 | if($this->module == "install") |
||
| 341 | { |
||
| 342 | if(!$this->act || !$xml_info->action->{$this->act}) |
||
| 343 | { |
||
| 344 | $this->act = $xml_info->default_index_act; |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 348 | // if act exists, find type of the action, if not use default index act |
||
| 349 | if(!$this->act) |
||
| 350 | { |
||
| 351 | $this->act = $xml_info->default_index_act; |
||
| 352 | } |
||
| 353 | |||
| 354 | // still no act means error |
||
| 355 | if(!$this->act) |
||
| 356 | { |
||
| 357 | $this->error = 'msg_module_is_not_exists'; |
||
| 358 | $this->httpStatusCode = '404'; |
||
| 359 | |||
| 360 | $this->_setInputErrorToContext(); |
||
| 361 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 362 | $oMessageObject->setError(-1); |
||
| 363 | $oMessageObject->setMessage($this->error); |
||
| 364 | $oMessageObject->dispMessage(); |
||
| 365 | if($this->httpStatusCode) |
||
| 366 | { |
||
| 367 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 368 | } |
||
| 369 | return $oMessageObject; |
||
| 370 | } |
||
| 371 | |||
| 372 | // get type, kind |
||
| 373 | $type = $xml_info->action->{$this->act}->type; |
||
| 374 | $ruleset = $xml_info->action->{$this->act}->ruleset; |
||
| 375 | $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
||
| 376 | if(!$kind && $this->module == 'admin') |
||
| 377 | { |
||
| 378 | $kind = 'admin'; |
||
| 379 | } |
||
| 380 | |||
| 381 | // check REQUEST_METHOD in controller |
||
| 382 | View Code Duplication | if($type == 'controller') |
|
| 383 | { |
||
| 384 | $allowedMethod = $xml_info->action->{$this->act}->method; |
||
| 385 | |||
| 386 | if(!$allowedMethod) |
||
| 387 | { |
||
| 388 | $allowedMethodList[0] = 'POST'; |
||
| 389 | } |
||
| 390 | else |
||
| 391 | { |
||
| 392 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
||
| 393 | } |
||
| 394 | |||
| 395 | if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
||
| 396 | { |
||
| 397 | $this->error = "msg_invalid_request"; |
||
| 398 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 399 | $oMessageObject->setError(-1); |
||
| 400 | $oMessageObject->setMessage($this->error); |
||
| 401 | $oMessageObject->dispMessage(); |
||
| 402 | return $oMessageObject; |
||
| 403 | } |
||
| 404 | } |
||
| 405 | |||
| 406 | if($this->module_info->use_mobile != "Y") |
||
| 407 | { |
||
| 408 | Mobile::setMobile(FALSE); |
||
| 409 | } |
||
| 410 | |||
| 411 | $logged_info = Context::get('logged_info'); |
||
| 412 | |||
| 413 | // check CSRF for POST actions |
||
| 414 | if($_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && $this->act !== 'procFileUpload' && !checkCSRF()) { |
||
| 415 | $this->error = 'msg_invalid_request'; |
||
| 416 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 417 | $oMessageObject->setError(-1); |
||
| 418 | $oMessageObject->setMessage($this->error); |
||
| 419 | $oMessageObject->dispMessage(); |
||
| 420 | return $oMessageObject; |
||
| 421 | } |
||
| 422 | |||
| 423 | // Admin ip |
||
| 424 | if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
||
| 425 | { |
||
| 426 | $this->_setInputErrorToContext(); |
||
| 427 | $this->error = "msg_not_permitted_act"; |
||
| 428 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 429 | $oMessageObject->setError(-1); |
||
| 430 | $oMessageObject->setMessage($this->error); |
||
| 431 | $oMessageObject->dispMessage(); |
||
| 432 | return $oMessageObject; |
||
| 433 | } |
||
| 434 | |||
| 435 | // if(type == view, and case for using mobilephone) |
||
| 436 | if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
||
| 437 | { |
||
| 438 | $orig_type = "view"; |
||
| 439 | $type = "mobile"; |
||
| 440 | // create a module instance |
||
| 441 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
| 442 | View Code Duplication | if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
| 443 | { |
||
| 444 | $type = $orig_type; |
||
| 445 | Mobile::setMobile(FALSE); |
||
| 446 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
| 447 | } |
||
| 448 | } |
||
| 449 | else |
||
| 450 | { |
||
| 451 | // create a module instance |
||
| 452 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
| 453 | } |
||
| 454 | |||
| 455 | View Code Duplication | if(!is_object($oModule)) |
|
| 456 | { |
||
| 457 | $this->_setInputErrorToContext(); |
||
| 458 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 459 | $oMessageObject->setError(-1); |
||
| 460 | $oMessageObject->setMessage($this->error); |
||
| 461 | $oMessageObject->dispMessage(); |
||
| 462 | if($this->httpStatusCode) |
||
| 463 | { |
||
| 464 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 465 | } |
||
| 466 | return $oMessageObject; |
||
| 467 | } |
||
| 468 | |||
| 469 | // If there is no such action in the module object |
||
| 470 | if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
||
| 471 | { |
||
| 472 | |||
| 473 | View Code Duplication | if(!Context::isInstalled()) |
|
| 474 | { |
||
| 475 | $this->_setInputErrorToContext(); |
||
| 476 | $this->error = 'msg_invalid_request'; |
||
| 477 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 478 | $oMessageObject->setError(-1); |
||
| 479 | $oMessageObject->setMessage($this->error); |
||
| 480 | $oMessageObject->dispMessage(); |
||
| 481 | if($this->httpStatusCode) |
||
| 482 | { |
||
| 483 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 484 | } |
||
| 485 | return $oMessageObject; |
||
| 486 | } |
||
| 487 | |||
| 488 | $forward = NULL; |
||
| 489 | // 1. Look for the module with action name |
||
| 490 | if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
||
| 491 | { |
||
| 492 | $module = strtolower($matches[2] . $matches[3]); |
||
| 493 | $xml_info = $oModuleModel->getModuleActionXml($module); |
||
| 494 | |||
| 495 | if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
||
| 496 | { |
||
| 497 | $forward = new stdClass(); |
||
| 498 | $forward->module = $module; |
||
| 499 | $forward->type = $xml_info->action->{$this->act}->type; |
||
| 500 | $forward->ruleset = $xml_info->action->{$this->act}->ruleset; |
||
| 501 | $forward->act = $this->act; |
||
| 502 | } |
||
| 503 | View Code Duplication | else |
|
| 504 | { |
||
| 505 | $this->error = 'msg_invalid_request'; |
||
| 506 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 507 | $oMessageObject->setError(-1); |
||
| 508 | $oMessageObject->setMessage($this->error); |
||
| 509 | $oMessageObject->dispMessage(); |
||
| 510 | |||
| 511 | return $oMessageObject; |
||
| 512 | } |
||
| 513 | } |
||
| 514 | |||
| 515 | if(!$forward) |
||
| 516 | { |
||
| 517 | $forward = $oModuleModel->getActionForward($this->act); |
||
| 518 | } |
||
| 519 | |||
| 520 | if($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
||
| 521 | { |
||
| 522 | $kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : ''; |
||
| 523 | $type = $forward->type; |
||
| 524 | $ruleset = $forward->ruleset; |
||
| 525 | $tpl_path = $oModule->getTemplatePath(); |
||
| 526 | $orig_module = $oModule; |
||
| 527 | |||
| 528 | $xml_info = $oModuleModel->getModuleActionXml($forward->module); |
||
| 529 | |||
| 530 | // SECISSUE also check foward act method |
||
| 531 | // check REQUEST_METHOD in controller |
||
| 532 | View Code Duplication | if($type == 'controller') |
|
| 533 | { |
||
| 534 | $allowedMethod = $xml_info->action->{$forward->act}->method; |
||
| 535 | |||
| 536 | if(!$allowedMethod) |
||
| 537 | { |
||
| 538 | $allowedMethodList[0] = 'POST'; |
||
| 539 | } |
||
| 540 | else |
||
| 541 | { |
||
| 542 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
||
| 543 | } |
||
| 544 | |||
| 545 | if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
||
| 546 | { |
||
| 547 | $this->error = "msg_invalid_request"; |
||
| 548 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 549 | $oMessageObject->setError(-1); |
||
| 550 | $oMessageObject->setMessage($this->error); |
||
| 551 | $oMessageObject->dispMessage(); |
||
| 552 | return $oMessageObject; |
||
| 553 | } |
||
| 554 | } |
||
| 555 | |||
| 556 | if($type == "view" && Mobile::isFromMobilePhone()) |
||
| 557 | { |
||
| 558 | $orig_type = "view"; |
||
| 559 | $type = "mobile"; |
||
| 560 | // create a module instance |
||
| 561 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
| 562 | View Code Duplication | if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
| 563 | { |
||
| 564 | $type = $orig_type; |
||
| 565 | Mobile::setMobile(FALSE); |
||
| 566 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
| 567 | } |
||
| 568 | } |
||
| 569 | else |
||
| 570 | { |
||
| 571 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
| 572 | } |
||
| 573 | |||
| 574 | View Code Duplication | if(!is_object($oModule)) |
|
| 575 | { |
||
| 576 | $this->_setInputErrorToContext(); |
||
| 577 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 578 | $oMessageObject->setError(-1); |
||
| 579 | $oMessageObject->setMessage('msg_module_is_not_exists'); |
||
| 580 | $oMessageObject->dispMessage(); |
||
| 581 | if($this->httpStatusCode) |
||
| 582 | { |
||
| 583 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 584 | } |
||
| 585 | return $oMessageObject; |
||
| 586 | } |
||
| 587 | |||
| 588 | if($this->module == "admin" && $type == "view") |
||
| 589 | { |
||
| 590 | if($logged_info->is_admin == 'Y') |
||
| 591 | { |
||
| 592 | if($this->act != 'dispLayoutAdminLayoutModify') |
||
| 593 | { |
||
| 594 | $oAdminView = getAdminView('admin'); |
||
| 595 | $oAdminView->makeGnbUrl($forward->module); |
||
| 596 | $oModule->setLayoutPath("./modules/admin/tpl"); |
||
| 597 | $oModule->setLayoutFile("layout.html"); |
||
| 598 | } |
||
| 599 | } |
||
| 600 | View Code Duplication | else |
|
| 601 | { |
||
| 602 | $this->_setInputErrorToContext(); |
||
| 603 | |||
| 604 | $this->error = 'msg_is_not_administrator'; |
||
| 605 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 606 | $oMessageObject->setError(-1); |
||
| 607 | $oMessageObject->setMessage($this->error); |
||
| 608 | $oMessageObject->dispMessage(); |
||
| 609 | return $oMessageObject; |
||
| 610 | } |
||
| 611 | } |
||
| 612 | if($kind == 'admin') |
||
| 613 | { |
||
| 614 | $grant = $oModuleModel->getGrant($this->module_info, $logged_info); |
||
| 615 | if(!$grant->manager) |
||
| 616 | { |
||
| 617 | $this->_setInputErrorToContext(); |
||
| 618 | $this->error = 'msg_is_not_manager'; |
||
| 619 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 620 | $oMessageObject->setError(-1); |
||
| 621 | $oMessageObject->setMessage($this->error); |
||
| 622 | $oMessageObject->dispMessage(); |
||
| 623 | return $oMessageObject; |
||
| 624 | } |
||
| 625 | else |
||
| 626 | { |
||
| 627 | if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
||
| 628 | { |
||
| 629 | $this->_setInputErrorToContext(); |
||
| 630 | $this->error = 'msg_is_not_administrator'; |
||
| 631 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 632 | $oMessageObject->setError(-1); |
||
| 633 | $oMessageObject->setMessage($this->error); |
||
| 634 | $oMessageObject->dispMessage(); |
||
| 635 | return $oMessageObject; |
||
| 636 | } |
||
| 637 | } |
||
| 638 | } |
||
| 639 | } |
||
| 640 | else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
||
| 641 | { |
||
| 642 | $this->act = $xml_info->default_index_act; |
||
| 643 | } |
||
| 644 | else |
||
| 645 | { |
||
| 646 | $this->error = 'msg_invalid_request'; |
||
| 647 | $oModule->setError(-1); |
||
| 648 | $oModule->setMessage($this->error); |
||
| 649 | return $oModule; |
||
| 650 | } |
||
| 651 | } |
||
| 652 | |||
| 653 | // ruleset check... |
||
| 654 | if(!empty($ruleset)) |
||
| 655 | { |
||
| 656 | $rulesetModule = $forward->module ? $forward->module : $this->module; |
||
| 657 | $rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid); |
||
| 658 | if(!empty($rulesetFile)) |
||
| 659 | { |
||
| 660 | if($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
||
| 661 | { |
||
| 662 | $errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG']; |
||
| 663 | foreach($errorLang as $key => $val) |
||
| 664 | { |
||
| 665 | Context::setLang($key, $val); |
||
| 666 | } |
||
| 667 | unset($_SESSION['XE_VALIDATOR_ERROR_LANG']); |
||
| 668 | } |
||
| 669 | |||
| 670 | $Validator = new Validator($rulesetFile); |
||
| 671 | $result = $Validator->validate(); |
||
| 672 | if(!$result) |
||
| 673 | { |
||
| 674 | $lastError = $Validator->getLastError(); |
||
| 675 | $returnUrl = Context::get('error_return_url'); |
||
| 676 | $errorMsg = $lastError['msg'] ? $lastError['msg'] : 'validation error'; |
||
| 677 | |||
| 678 | //for xml response |
||
| 679 | $oModule->setError(-1); |
||
| 680 | $oModule->setMessage($errorMsg); |
||
| 681 | //for html redirect |
||
| 682 | $this->error = $errorMsg; |
||
| 683 | $_SESSION['XE_VALIDATOR_ERROR'] = -1; |
||
| 684 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $this->error; |
||
| 685 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = 'error'; |
||
| 686 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $returnUrl; |
||
| 687 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
||
| 688 | $this->_setInputValueToSession(); |
||
| 689 | return $oModule; |
||
| 690 | } |
||
| 691 | } |
||
| 692 | } |
||
| 693 | |||
| 694 | $oModule->setAct($this->act); |
||
| 695 | |||
| 696 | $this->module_info->module_type = $type; |
||
| 697 | $oModule->setModuleInfo($this->module_info, $xml_info); |
||
| 698 | |||
| 699 | $skipAct = array( |
||
| 700 | 'dispEditorConfigPreview' => 1, |
||
| 701 | 'dispLayoutPreviewWithModule' => 1 |
||
| 702 | ); |
||
| 703 | $db_use_mobile = Mobile::isMobileEnabled(); |
||
| 704 | if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
||
| 705 | { |
||
| 706 | global $lang; |
||
| 707 | $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>'; |
||
| 708 | $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>'; |
||
| 709 | Context::addHtmlHeader($header); |
||
| 710 | Context::addHtmlFooter($footer); |
||
| 711 | } |
||
| 712 | |||
| 713 | if($type == "view" && $kind != 'admin') |
||
| 714 | { |
||
| 715 | $module_config = $oModuleModel->getModuleConfig('module'); |
||
| 716 | if($module_config->htmlFooter) |
||
| 717 | { |
||
| 718 | Context::addHtmlFooter($module_config->htmlFooter); |
||
| 719 | } |
||
| 720 | if($module_config->siteTitle) |
||
| 721 | { |
||
| 722 | $siteTitle = Context::getBrowserTitle(); |
||
| 723 | if(!$siteTitle) |
||
| 724 | { |
||
| 725 | Context::setBrowserTitle($module_config->siteTitle); |
||
| 726 | } |
||
| 727 | } |
||
| 728 | } |
||
| 729 | |||
| 730 | // if failed message exists in session, set context |
||
| 731 | $this->_setInputErrorToContext(); |
||
| 732 | |||
| 733 | $procResult = $oModule->proc(); |
||
| 734 | |||
| 735 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
||
| 736 | if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
||
| 737 | { |
||
| 738 | $error = $oModule->getError(); |
||
| 739 | $message = $oModule->getMessage(); |
||
| 740 | $messageType = $oModule->getMessageType(); |
||
| 741 | $redirectUrl = $oModule->getRedirectUrl(); |
||
| 742 | if($messageType == 'error') debugPrint($message, 'ERROR'); |
||
| 743 | |||
| 744 | if(!$procResult) |
||
| 745 | { |
||
| 746 | $this->error = $message; |
||
| 747 | if(!$redirectUrl && Context::get('error_return_url')) |
||
| 748 | { |
||
| 749 | $redirectUrl = Context::get('error_return_url'); |
||
| 750 | } |
||
| 751 | $this->_setInputValueToSession(); |
||
| 752 | } |
||
| 753 | else |
||
| 754 | { |
||
| 755 | |||
| 756 | } |
||
| 757 | |||
| 758 | $_SESSION['XE_VALIDATOR_ERROR'] = $error; |
||
| 759 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
||
| 760 | if($message != 'success') |
||
| 761 | { |
||
| 762 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $message; |
||
| 763 | } |
||
| 764 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType; |
||
| 765 | |||
| 766 | if(Context::get('xeVirtualRequestMethod') != 'xml') |
||
| 767 | { |
||
| 768 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl; |
||
| 769 | } |
||
| 770 | } |
||
| 771 | |||
| 772 | unset($logged_info); |
||
| 773 | return $oModule; |
||
| 774 | } |
||
| 775 | |||
| 776 | /** |
||
| 777 | * set error message to Session. |
||
| 778 | * @return void |
||
| 779 | * */ |
||
| 780 | function _setInputErrorToContext() |
||
| 809 | |||
| 810 | /** |
||
| 811 | * clear error message to Session. |
||
| 812 | * @return void |
||
| 813 | * */ |
||
| 814 | function _clearErrorSession() |
||
| 823 | |||
| 824 | /** |
||
| 825 | * occured error when, set input values to session. |
||
| 826 | * @return void |
||
| 827 | * */ |
||
| 828 | function _setInputValueToSession() |
||
| 837 | |||
| 838 | /** |
||
| 839 | * display contents from executed module |
||
| 840 | * @param ModuleObject $oModule module instance |
||
| 841 | * @return void |
||
| 842 | * */ |
||
| 843 | function displayContent($oModule = NULL) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * returns module's path |
||
| 1028 | * @param string $module module name |
||
| 1029 | * @return string path of the module |
||
| 1030 | * */ |
||
| 1031 | function getModulePath($module) |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * It creates a module instance |
||
| 1038 | * @param string $module module name |
||
| 1039 | * @param string $type instance type, (e.g., view, controller, model) |
||
| 1040 | * @param string $kind admin or svc |
||
| 1041 | * @return ModuleObject module instance (if failed it returns null) |
||
| 1042 | * @remarks if there exists a module instance created before, returns it. |
||
| 1043 | * */ |
||
| 1044 | function &getModuleInstance($module, $type = 'view', $kind = '') |
||
| 1130 | |||
| 1131 | function _getModuleFilePath($module, $type, $kind, &$classPath, &$highClassFile, &$classFile, &$instanceName) |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * call a trigger |
||
| 1165 | * @param string $trigger_name trigger's name to call |
||
| 1166 | * @param string $called_position called position |
||
| 1167 | * @param object $obj an object as a parameter to trigger |
||
| 1168 | * @return Object |
||
| 1169 | * */ |
||
| 1170 | function triggerCall($trigger_name, $called_position, &$obj) |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * get http status message by http status code |
||
| 1230 | * @param string $code |
||
| 1231 | * @return string |
||
| 1232 | * */ |
||
| 1233 | function _setHttpStatusMessage($code) |
||
| 1311 | |||
| 1312 | } |
||
| 1313 | /* End of file ModuleHandler.class.php */ |
||
| 1315 |