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