Conditions | 99 |
Paths | > 20000 |
Total Lines | 489 |
Lines | 137 |
Ratio | 28.02 % |
Changes | 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 |
||
416 | function procModule() |
||
417 | { |
||
418 | $oModuleModel = getModel('module'); |
||
419 | $display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
||
420 | |||
421 | // If error occurred while preparation, return a message instance |
||
422 | if($this->error) |
||
423 | { |
||
424 | $this->_setInputErrorToContext(); |
||
425 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
426 | $oMessageObject->setError(-1); |
||
427 | $oMessageObject->setMessage($this->error); |
||
428 | $oMessageObject->dispMessage(); |
||
429 | if($this->httpStatusCode) |
||
430 | { |
||
431 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
432 | } |
||
433 | return $oMessageObject; |
||
434 | } |
||
435 | |||
436 | // Get action information with conf/module.xml |
||
437 | $xml_info = $oModuleModel->getModuleActionXml($this->module); |
||
438 | |||
439 | // If not installed yet, modify act |
||
440 | if($this->module == "install") |
||
441 | { |
||
442 | if(!$this->act || !$xml_info->action->{$this->act}) |
||
443 | { |
||
444 | $this->act = $xml_info->default_index_act; |
||
445 | } |
||
446 | } |
||
447 | |||
448 | // if act exists, find type of the action, if not use default index act |
||
449 | if(!$this->act) |
||
450 | { |
||
451 | $this->act = $xml_info->default_index_act; |
||
452 | } |
||
453 | |||
454 | // still no act means error |
||
455 | if(!$this->act) |
||
456 | { |
||
457 | $this->error = 'msg_module_is_not_exists'; |
||
458 | $this->httpStatusCode = '404'; |
||
459 | |||
460 | $this->_setInputErrorToContext(); |
||
461 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
462 | $oMessageObject->setError(-1); |
||
463 | $oMessageObject->setMessage($this->error); |
||
464 | $oMessageObject->dispMessage(); |
||
465 | if($this->httpStatusCode) |
||
466 | { |
||
467 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
468 | } |
||
469 | return $oMessageObject; |
||
470 | } |
||
471 | |||
472 | // get type, kind |
||
473 | $type = $xml_info->action->{$this->act}->type; |
||
474 | $ruleset = $xml_info->action->{$this->act}->ruleset; |
||
475 | $meta_noindex = $xml_info->action->{$this->act}->meta_noindex; |
||
476 | $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
||
477 | |||
478 | if ($meta_noindex === 'true') |
||
479 | { |
||
480 | Context::addMetaTag('robots', 'noindex'); |
||
481 | } |
||
482 | |||
483 | if(!$kind && $this->module == 'admin') |
||
484 | { |
||
485 | $kind = 'admin'; |
||
486 | } |
||
487 | |||
488 | // check REQUEST_METHOD in controller |
||
489 | View Code Duplication | if($type == 'controller') |
|
490 | { |
||
491 | $allowedMethod = $xml_info->action->{$this->act}->method; |
||
492 | |||
493 | if(!$allowedMethod) |
||
494 | { |
||
495 | $allowedMethodList[0] = 'POST'; |
||
496 | } |
||
497 | else |
||
498 | { |
||
499 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
||
500 | } |
||
501 | |||
502 | if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
||
503 | { |
||
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 | |||
513 | if($this->module_info->use_mobile != "Y") |
||
514 | { |
||
515 | Mobile::setMobile(FALSE); |
||
516 | } |
||
517 | |||
518 | $logged_info = Context::get('logged_info'); |
||
519 | |||
520 | // check CSRF for non-GET actions |
||
521 | $use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false'; |
||
522 | View Code Duplication | if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
523 | { |
||
524 | $this->error = 'msg_invalid_request'; |
||
525 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
526 | $oMessageObject->setError(-1); |
||
527 | $oMessageObject->setMessage($this->error); |
||
528 | $oMessageObject->dispMessage(); |
||
529 | return $oMessageObject; |
||
530 | } |
||
531 | |||
532 | // Admin ip |
||
533 | if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
||
534 | { |
||
535 | $this->_setInputErrorToContext(); |
||
536 | $this->error = "msg_not_permitted_act"; |
||
537 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
538 | $oMessageObject->setError(-1); |
||
539 | $oMessageObject->setMessage($this->error); |
||
540 | $oMessageObject->dispMessage(); |
||
541 | return $oMessageObject; |
||
542 | } |
||
543 | |||
544 | // if(type == view, and case for using mobilephone) |
||
545 | if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
||
546 | { |
||
547 | $orig_type = "view"; |
||
548 | $type = "mobile"; |
||
549 | // create a module instance |
||
550 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
551 | View Code Duplication | if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
552 | { |
||
553 | $type = $orig_type; |
||
554 | Mobile::setMobile(FALSE); |
||
555 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
556 | } |
||
557 | } |
||
558 | else |
||
559 | { |
||
560 | // create a module instance |
||
561 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
562 | } |
||
563 | |||
564 | View Code Duplication | if(!is_object($oModule)) |
|
565 | { |
||
566 | $this->_setInputErrorToContext(); |
||
567 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
568 | $oMessageObject->setError(-1); |
||
569 | $oMessageObject->setMessage($this->error); |
||
570 | $oMessageObject->dispMessage(); |
||
571 | if($this->httpStatusCode) |
||
572 | { |
||
573 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
574 | } |
||
575 | return $oMessageObject; |
||
576 | } |
||
577 | |||
578 | // If there is no such action in the module object |
||
579 | if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
||
580 | { |
||
581 | |||
582 | View Code Duplication | if(!Context::isInstalled()) |
|
583 | { |
||
584 | $this->_setInputErrorToContext(); |
||
585 | $this->error = 'msg_invalid_request'; |
||
586 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
587 | $oMessageObject->setError(-1); |
||
588 | $oMessageObject->setMessage($this->error); |
||
589 | $oMessageObject->dispMessage(); |
||
590 | if($this->httpStatusCode) |
||
591 | { |
||
592 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
593 | } |
||
594 | return $oMessageObject; |
||
595 | } |
||
596 | |||
597 | $forward = NULL; |
||
598 | // 1. Look for the module with action name |
||
599 | if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
||
600 | { |
||
601 | $module = strtolower($matches[2] . $matches[3]); |
||
602 | $xml_info = $oModuleModel->getModuleActionXml($module); |
||
603 | |||
604 | if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
||
605 | { |
||
606 | $forward = new stdClass(); |
||
607 | $forward->module = $module; |
||
608 | $forward->type = $xml_info->action->{$this->act}->type; |
||
609 | $forward->ruleset = $xml_info->action->{$this->act}->ruleset; |
||
610 | $forward->meta_noindex = $xml_info->action->{$this->act}->meta_noindex; |
||
611 | $forward->act = $this->act; |
||
612 | } |
||
613 | View Code Duplication | else |
|
614 | { |
||
615 | $this->error = 'msg_invalid_request'; |
||
616 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
617 | $oMessageObject->setError(-1); |
||
618 | $oMessageObject->setMessage($this->error); |
||
619 | $oMessageObject->dispMessage(); |
||
620 | |||
621 | return $oMessageObject; |
||
622 | } |
||
623 | } |
||
624 | |||
625 | if(!$forward) |
||
626 | { |
||
627 | $forward = $oModuleModel->getActionForward($this->act); |
||
628 | } |
||
629 | |||
630 | if($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
||
631 | { |
||
632 | $kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : ''; |
||
633 | $type = $forward->type; |
||
634 | $ruleset = $forward->ruleset; |
||
635 | $tpl_path = $oModule->getTemplatePath(); |
||
636 | $orig_module = $oModule; |
||
637 | |||
638 | if($forward->meta_noindex === 'true') { |
||
639 | Context::addMetaTag('robots', 'noindex'); |
||
640 | } |
||
641 | |||
642 | $xml_info = $oModuleModel->getModuleActionXml($forward->module); |
||
643 | |||
644 | // check CSRF for non-GET actions |
||
645 | $use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false'; |
||
646 | View Code Duplication | if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
647 | { |
||
648 | $this->error = 'msg_invalid_request'; |
||
649 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
650 | $oMessageObject->setError(-1); |
||
651 | $oMessageObject->setMessage($this->error); |
||
652 | $oMessageObject->dispMessage(); |
||
653 | return $oMessageObject; |
||
654 | } |
||
655 | |||
656 | // SECISSUE also check foward act method |
||
657 | // check REQUEST_METHOD in controller |
||
658 | View Code Duplication | if($type == 'controller') |
|
659 | { |
||
660 | $allowedMethod = $xml_info->action->{$forward->act}->method; |
||
661 | |||
662 | if(!$allowedMethod) |
||
663 | { |
||
664 | $allowedMethodList[0] = 'POST'; |
||
665 | } |
||
666 | else |
||
667 | { |
||
668 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
||
669 | } |
||
670 | |||
671 | if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
||
672 | { |
||
673 | $this->error = "msg_invalid_request"; |
||
674 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
675 | $oMessageObject->setError(-1); |
||
676 | $oMessageObject->setMessage($this->error); |
||
677 | $oMessageObject->dispMessage(); |
||
678 | return $oMessageObject; |
||
679 | } |
||
680 | } |
||
681 | |||
682 | if($type == "view" && Mobile::isFromMobilePhone()) |
||
683 | { |
||
684 | $orig_type = "view"; |
||
685 | $type = "mobile"; |
||
686 | // create a module instance |
||
687 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
688 | View Code Duplication | if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
689 | { |
||
690 | $type = $orig_type; |
||
691 | Mobile::setMobile(FALSE); |
||
692 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
693 | } |
||
694 | } |
||
695 | else |
||
696 | { |
||
697 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
698 | } |
||
699 | |||
700 | View Code Duplication | if(!is_object($oModule)) |
|
701 | { |
||
702 | $this->_setInputErrorToContext(); |
||
703 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
704 | $oMessageObject->setError(-1); |
||
705 | $oMessageObject->setMessage('msg_module_is_not_exists'); |
||
706 | $oMessageObject->dispMessage(); |
||
707 | if($this->httpStatusCode) |
||
708 | { |
||
709 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
710 | } |
||
711 | return $oMessageObject; |
||
712 | } |
||
713 | |||
714 | if($this->module == "admin" && $type == "view") |
||
715 | { |
||
716 | if($logged_info->is_admin == 'Y') |
||
717 | { |
||
718 | if($this->act != 'dispLayoutAdminLayoutModify') |
||
719 | { |
||
720 | $oAdminView = getAdminView('admin'); |
||
721 | $oAdminView->makeGnbUrl($forward->module); |
||
722 | $oModule->setLayoutPath("./modules/admin/tpl"); |
||
723 | $oModule->setLayoutFile("layout.html"); |
||
724 | } |
||
725 | } |
||
726 | View Code Duplication | else |
|
727 | { |
||
728 | $this->_setInputErrorToContext(); |
||
729 | |||
730 | $this->error = 'msg_is_not_administrator'; |
||
731 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
732 | $oMessageObject->setError(-1); |
||
733 | $oMessageObject->setMessage($this->error); |
||
734 | $oMessageObject->dispMessage(); |
||
735 | return $oMessageObject; |
||
736 | } |
||
737 | } |
||
738 | if($kind == 'admin') |
||
739 | { |
||
740 | $grant = $oModuleModel->getGrant($this->module_info, $logged_info); |
||
741 | if(!$grant->manager) |
||
742 | { |
||
743 | $this->_setInputErrorToContext(); |
||
744 | $this->error = 'msg_is_not_manager'; |
||
745 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
746 | $oMessageObject->setError(-1); |
||
747 | $oMessageObject->setMessage($this->error); |
||
748 | $oMessageObject->dispMessage(); |
||
749 | return $oMessageObject; |
||
750 | } |
||
751 | else |
||
752 | { |
||
753 | if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
||
754 | { |
||
755 | $this->_setInputErrorToContext(); |
||
756 | $this->error = 'msg_is_not_administrator'; |
||
757 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
758 | $oMessageObject->setError(-1); |
||
759 | $oMessageObject->setMessage($this->error); |
||
760 | $oMessageObject->dispMessage(); |
||
761 | return $oMessageObject; |
||
762 | } |
||
763 | } |
||
764 | } |
||
765 | } |
||
766 | else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
||
767 | { |
||
768 | $this->act = $xml_info->default_index_act; |
||
769 | } |
||
770 | else |
||
771 | { |
||
772 | $this->error = 'msg_invalid_request'; |
||
773 | $oModule->setError(-1); |
||
774 | $oModule->setMessage($this->error); |
||
775 | return $oModule; |
||
776 | } |
||
777 | } |
||
778 | |||
779 | // ruleset check... |
||
780 | if(!empty($ruleset)) |
||
781 | { |
||
782 | $rulesetModule = $forward->module ? $forward->module : $this->module; |
||
783 | $rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid); |
||
784 | if(!empty($rulesetFile)) |
||
785 | { |
||
786 | if($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
||
787 | { |
||
788 | $errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG']; |
||
789 | foreach($errorLang as $key => $val) |
||
790 | { |
||
791 | Context::setLang($key, $val); |
||
792 | } |
||
793 | unset($_SESSION['XE_VALIDATOR_ERROR_LANG']); |
||
794 | } |
||
795 | |||
796 | $Validator = new Validator($rulesetFile); |
||
797 | $result = $Validator->validate(); |
||
798 | if(!$result) |
||
799 | { |
||
800 | $lastError = $Validator->getLastError(); |
||
801 | $returnUrl = Context::get('error_return_url'); |
||
802 | $errorMsg = $lastError['msg'] ? $lastError['msg'] : 'validation error'; |
||
803 | |||
804 | //for xml response |
||
805 | $oModule->setError(-1); |
||
806 | $oModule->setMessage($errorMsg); |
||
807 | //for html redirect |
||
808 | $this->error = $errorMsg; |
||
809 | $_SESSION['XE_VALIDATOR_ERROR'] = -1; |
||
810 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $this->error; |
||
811 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = 'error'; |
||
812 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $returnUrl; |
||
813 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
||
814 | $this->_setInputValueToSession(); |
||
815 | return $oModule; |
||
816 | } |
||
817 | } |
||
818 | } |
||
819 | |||
820 | $oModule->setAct($this->act); |
||
821 | |||
822 | $this->module_info->module_type = $type; |
||
823 | $oModule->setModuleInfo($this->module_info, $xml_info); |
||
824 | |||
825 | $skipAct = array( |
||
826 | 'dispEditorConfigPreview' => 1, |
||
827 | 'dispLayoutPreviewWithModule' => 1 |
||
828 | ); |
||
829 | $db_use_mobile = Mobile::isMobileEnabled(); |
||
830 | if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
||
831 | { |
||
832 | global $lang; |
||
833 | $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>'; |
||
834 | $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>'; |
||
835 | Context::addHtmlHeader($header); |
||
836 | Context::addHtmlFooter($footer); |
||
837 | } |
||
838 | |||
839 | if(($type == 'view' || $type == 'mobile') && $kind != 'admin') |
||
840 | { |
||
841 | $module_config = $oModuleModel->getModuleConfig('module'); |
||
842 | if($module_config->htmlFooter) |
||
843 | { |
||
844 | Context::addHtmlFooter($module_config->htmlFooter); |
||
845 | } |
||
846 | if($module_config->siteTitle) |
||
847 | { |
||
848 | $siteTitle = Context::getBrowserTitle(); |
||
849 | if(!$siteTitle) |
||
850 | { |
||
851 | Context::setBrowserTitle($module_config->siteTitle); |
||
852 | } |
||
853 | } |
||
854 | } |
||
855 | |||
856 | if ($kind === 'admin') { |
||
857 | Context::addMetaTag('robots', 'noindex'); |
||
858 | } |
||
859 | |||
860 | // if failed message exists in session, set context |
||
861 | $this->_setInputErrorToContext(); |
||
862 | |||
863 | $procResult = $oModule->proc(); |
||
864 | |||
865 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
||
866 | if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
||
867 | { |
||
868 | $error = $oModule->getError(); |
||
869 | $message = $oModule->getMessage(); |
||
870 | $messageType = $oModule->getMessageType(); |
||
871 | $redirectUrl = $oModule->getRedirectUrl(); |
||
872 | if($messageType == 'error') debugPrint($message, 'ERROR'); |
||
873 | |||
874 | if(!$procResult) |
||
875 | { |
||
876 | $this->error = $message; |
||
877 | if(!$redirectUrl && Context::get('error_return_url')) |
||
878 | { |
||
879 | $redirectUrl = Context::get('error_return_url'); |
||
880 | } |
||
881 | $this->_setInputValueToSession(); |
||
882 | } |
||
883 | else |
||
884 | { |
||
885 | |||
886 | } |
||
887 | |||
888 | $_SESSION['XE_VALIDATOR_ERROR'] = $error; |
||
889 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
||
890 | if($message != 'success') |
||
891 | { |
||
892 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $message; |
||
893 | } |
||
894 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType; |
||
895 | |||
896 | if(Context::get('xeVirtualRequestMethod') != 'xml') |
||
897 | { |
||
898 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl; |
||
899 | } |
||
900 | } |
||
901 | |||
902 | unset($logged_info); |
||
903 | return $oModule; |
||
904 | } |
||
905 | |||
1445 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.