| Conditions | 89 |
| Paths | > 20000 |
| Total Lines | 459 |
| Code Lines | 264 |
| Lines | 119 |
| Ratio | 25.93 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | |||
| 1315 |