| Conditions | 89 |
| Paths | > 20000 |
| Total Lines | 459 |
| Code Lines | 264 |
| Lines | 119 |
| Ratio | 25.93 % |
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 |
||
| 346 | function procModule() |
||
| 347 | { |
||
| 348 | $oModuleModel = getModel('module'); |
||
| 349 | $display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
||
| 350 | |||
| 351 | // If error occurred while preparation, return a message instance |
||
| 352 | if($this->error) |
||
| 353 | { |
||
| 354 | $this->_setInputErrorToContext(); |
||
| 355 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 356 | $oMessageObject->setError(-1); |
||
| 357 | $oMessageObject->setMessage($this->error); |
||
| 358 | $oMessageObject->dispMessage(); |
||
| 359 | if($this->httpStatusCode) |
||
| 360 | { |
||
| 361 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 362 | } |
||
| 363 | return $oMessageObject; |
||
| 364 | } |
||
| 365 | |||
| 366 | // Get action information with conf/module.xml |
||
| 367 | $xml_info = $oModuleModel->getModuleActionXml($this->module); |
||
| 368 | |||
| 369 | // If not installed yet, modify act |
||
| 370 | if($this->module == "install") |
||
| 371 | { |
||
| 372 | if(!$this->act || !$xml_info->action->{$this->act}) |
||
| 373 | { |
||
| 374 | $this->act = $xml_info->default_index_act; |
||
| 375 | } |
||
| 376 | } |
||
| 377 | |||
| 378 | // if act exists, find type of the action, if not use default index act |
||
| 379 | if(!$this->act) |
||
| 380 | { |
||
| 381 | $this->act = $xml_info->default_index_act; |
||
| 382 | } |
||
| 383 | |||
| 384 | // still no act means error |
||
| 385 | if(!$this->act) |
||
| 386 | { |
||
| 387 | $this->error = 'msg_module_is_not_exists'; |
||
| 388 | $this->httpStatusCode = '404'; |
||
| 389 | |||
| 390 | $this->_setInputErrorToContext(); |
||
| 391 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 392 | $oMessageObject->setError(-1); |
||
| 393 | $oMessageObject->setMessage($this->error); |
||
| 394 | $oMessageObject->dispMessage(); |
||
| 395 | if($this->httpStatusCode) |
||
| 396 | { |
||
| 397 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 398 | } |
||
| 399 | return $oMessageObject; |
||
| 400 | } |
||
| 401 | |||
| 402 | // get type, kind |
||
| 403 | $type = $xml_info->action->{$this->act}->type; |
||
| 404 | $ruleset = $xml_info->action->{$this->act}->ruleset; |
||
| 405 | $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
||
| 406 | if(!$kind && $this->module == 'admin') |
||
| 407 | { |
||
| 408 | $kind = 'admin'; |
||
| 409 | } |
||
| 410 | |||
| 411 | // check REQUEST_METHOD in controller |
||
| 412 | View Code Duplication | if($type == 'controller') |
|
| 413 | { |
||
| 414 | $allowedMethod = $xml_info->action->{$this->act}->method; |
||
| 415 | |||
| 416 | if(!$allowedMethod) |
||
| 417 | { |
||
| 418 | $allowedMethodList[0] = 'POST'; |
||
| 419 | } |
||
| 420 | else |
||
| 421 | { |
||
| 422 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
||
| 423 | } |
||
| 424 | |||
| 425 | if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
||
| 426 | { |
||
| 427 | $this->error = "msg_invalid_request"; |
||
| 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 | |||
| 436 | if($this->module_info->use_mobile != "Y") |
||
| 437 | { |
||
| 438 | Mobile::setMobile(FALSE); |
||
| 439 | } |
||
| 440 | |||
| 441 | $logged_info = Context::get('logged_info'); |
||
| 442 | |||
| 443 | // check CSRF for POST actions |
||
| 444 | if(Context::getRequestMethod() === 'POST' && Context::isInstalled() && $this->act !== 'procFileUpload' && !checkCSRF()) { |
||
| 445 | $this->error = 'msg_invalid_request'; |
||
| 446 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 447 | $oMessageObject->setError(-1); |
||
| 448 | $oMessageObject->setMessage($this->error); |
||
| 449 | $oMessageObject->dispMessage(); |
||
| 450 | return $oMessageObject; |
||
| 451 | } |
||
| 452 | |||
| 453 | // Admin ip |
||
| 454 | if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
||
| 455 | { |
||
| 456 | $this->_setInputErrorToContext(); |
||
| 457 | $this->error = "msg_not_permitted_act"; |
||
| 458 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 459 | $oMessageObject->setError(-1); |
||
| 460 | $oMessageObject->setMessage($this->error); |
||
| 461 | $oMessageObject->dispMessage(); |
||
| 462 | return $oMessageObject; |
||
| 463 | } |
||
| 464 | |||
| 465 | // if(type == view, and case for using mobilephone) |
||
| 466 | if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
||
| 467 | { |
||
| 468 | $orig_type = "view"; |
||
| 469 | $type = "mobile"; |
||
| 470 | // create a module instance |
||
| 471 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
| 472 | View Code Duplication | if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
| 473 | { |
||
| 474 | $type = $orig_type; |
||
| 475 | Mobile::setMobile(FALSE); |
||
| 476 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
| 477 | } |
||
| 478 | } |
||
| 479 | else |
||
| 480 | { |
||
| 481 | // create a module instance |
||
| 482 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
||
| 483 | } |
||
| 484 | |||
| 485 | View Code Duplication | if(!is_object($oModule)) |
|
| 486 | { |
||
| 487 | $this->_setInputErrorToContext(); |
||
| 488 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 489 | $oMessageObject->setError(-1); |
||
| 490 | $oMessageObject->setMessage($this->error); |
||
| 491 | $oMessageObject->dispMessage(); |
||
| 492 | if($this->httpStatusCode) |
||
| 493 | { |
||
| 494 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 495 | } |
||
| 496 | return $oMessageObject; |
||
| 497 | } |
||
| 498 | |||
| 499 | // If there is no such action in the module object |
||
| 500 | if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
||
| 501 | { |
||
| 502 | |||
| 503 | View Code Duplication | if(!Context::isInstalled()) |
|
| 504 | { |
||
| 505 | $this->_setInputErrorToContext(); |
||
| 506 | $this->error = 'msg_invalid_request'; |
||
| 507 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 508 | $oMessageObject->setError(-1); |
||
| 509 | $oMessageObject->setMessage($this->error); |
||
| 510 | $oMessageObject->dispMessage(); |
||
| 511 | if($this->httpStatusCode) |
||
| 512 | { |
||
| 513 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 514 | } |
||
| 515 | return $oMessageObject; |
||
| 516 | } |
||
| 517 | |||
| 518 | $forward = NULL; |
||
| 519 | // 1. Look for the module with action name |
||
| 520 | if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
||
| 521 | { |
||
| 522 | $module = strtolower($matches[2] . $matches[3]); |
||
| 523 | $xml_info = $oModuleModel->getModuleActionXml($module); |
||
| 524 | |||
| 525 | if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
||
| 526 | { |
||
| 527 | $forward = new stdClass(); |
||
| 528 | $forward->module = $module; |
||
| 529 | $forward->type = $xml_info->action->{$this->act}->type; |
||
| 530 | $forward->ruleset = $xml_info->action->{$this->act}->ruleset; |
||
| 531 | $forward->act = $this->act; |
||
| 532 | } |
||
| 533 | View Code Duplication | else |
|
| 534 | { |
||
| 535 | $this->error = 'msg_invalid_request'; |
||
| 536 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 537 | $oMessageObject->setError(-1); |
||
| 538 | $oMessageObject->setMessage($this->error); |
||
| 539 | $oMessageObject->dispMessage(); |
||
| 540 | |||
| 541 | return $oMessageObject; |
||
| 542 | } |
||
| 543 | } |
||
| 544 | |||
| 545 | if(!$forward) |
||
| 546 | { |
||
| 547 | $forward = $oModuleModel->getActionForward($this->act); |
||
| 548 | } |
||
| 549 | |||
| 550 | if($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
||
| 551 | { |
||
| 552 | $kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : ''; |
||
| 553 | $type = $forward->type; |
||
| 554 | $ruleset = $forward->ruleset; |
||
| 555 | $tpl_path = $oModule->getTemplatePath(); |
||
| 556 | $orig_module = $oModule; |
||
| 557 | |||
| 558 | $xml_info = $oModuleModel->getModuleActionXml($forward->module); |
||
| 559 | |||
| 560 | // SECISSUE also check foward act method |
||
| 561 | // check REQUEST_METHOD in controller |
||
| 562 | View Code Duplication | if($type == 'controller') |
|
| 563 | { |
||
| 564 | $allowedMethod = $xml_info->action->{$forward->act}->method; |
||
| 565 | |||
| 566 | if(!$allowedMethod) |
||
| 567 | { |
||
| 568 | $allowedMethodList[0] = 'POST'; |
||
| 569 | } |
||
| 570 | else |
||
| 571 | { |
||
| 572 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
||
| 573 | } |
||
| 574 | |||
| 575 | if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
||
| 576 | { |
||
| 577 | $this->error = "msg_invalid_request"; |
||
| 578 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 579 | $oMessageObject->setError(-1); |
||
| 580 | $oMessageObject->setMessage($this->error); |
||
| 581 | $oMessageObject->dispMessage(); |
||
| 582 | return $oMessageObject; |
||
| 583 | } |
||
| 584 | } |
||
| 585 | |||
| 586 | if($type == "view" && Mobile::isFromMobilePhone()) |
||
| 587 | { |
||
| 588 | $orig_type = "view"; |
||
| 589 | $type = "mobile"; |
||
| 590 | // create a module instance |
||
| 591 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
| 592 | View Code Duplication | if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
| 593 | { |
||
| 594 | $type = $orig_type; |
||
| 595 | Mobile::setMobile(FALSE); |
||
| 596 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
| 597 | } |
||
| 598 | } |
||
| 599 | else |
||
| 600 | { |
||
| 601 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
||
| 602 | } |
||
| 603 | |||
| 604 | View Code Duplication | if(!is_object($oModule)) |
|
| 605 | { |
||
| 606 | $this->_setInputErrorToContext(); |
||
| 607 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 608 | $oMessageObject->setError(-1); |
||
| 609 | $oMessageObject->setMessage('msg_module_is_not_exists'); |
||
| 610 | $oMessageObject->dispMessage(); |
||
| 611 | if($this->httpStatusCode) |
||
| 612 | { |
||
| 613 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
||
| 614 | } |
||
| 615 | return $oMessageObject; |
||
| 616 | } |
||
| 617 | |||
| 618 | if($this->module == "admin" && $type == "view") |
||
| 619 | { |
||
| 620 | if($logged_info->is_admin == 'Y') |
||
| 621 | { |
||
| 622 | if($this->act != 'dispLayoutAdminLayoutModify') |
||
| 623 | { |
||
| 624 | $oAdminView = getAdminView('admin'); |
||
| 625 | $oAdminView->makeGnbUrl($forward->module); |
||
| 626 | $oModule->setLayoutPath("./modules/admin/tpl"); |
||
| 627 | $oModule->setLayoutFile("layout.html"); |
||
| 628 | } |
||
| 629 | } |
||
| 630 | View Code Duplication | else |
|
| 631 | { |
||
| 632 | $this->_setInputErrorToContext(); |
||
| 633 | |||
| 634 | $this->error = 'msg_is_not_administrator'; |
||
| 635 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 636 | $oMessageObject->setError(-1); |
||
| 637 | $oMessageObject->setMessage($this->error); |
||
| 638 | $oMessageObject->dispMessage(); |
||
| 639 | return $oMessageObject; |
||
| 640 | } |
||
| 641 | } |
||
| 642 | if($kind == 'admin') |
||
| 643 | { |
||
| 644 | $grant = $oModuleModel->getGrant($this->module_info, $logged_info); |
||
| 645 | if(!$grant->manager) |
||
| 646 | { |
||
| 647 | $this->_setInputErrorToContext(); |
||
| 648 | $this->error = 'msg_is_not_manager'; |
||
| 649 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 650 | $oMessageObject->setError(-1); |
||
| 651 | $oMessageObject->setMessage($this->error); |
||
| 652 | $oMessageObject->dispMessage(); |
||
| 653 | return $oMessageObject; |
||
| 654 | } |
||
| 655 | else |
||
| 656 | { |
||
| 657 | if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
||
| 658 | { |
||
| 659 | $this->_setInputErrorToContext(); |
||
| 660 | $this->error = 'msg_is_not_administrator'; |
||
| 661 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
||
| 662 | $oMessageObject->setError(-1); |
||
| 663 | $oMessageObject->setMessage($this->error); |
||
| 664 | $oMessageObject->dispMessage(); |
||
| 665 | return $oMessageObject; |
||
| 666 | } |
||
| 667 | } |
||
| 668 | } |
||
| 669 | } |
||
| 670 | else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
||
| 671 | { |
||
| 672 | $this->act = $xml_info->default_index_act; |
||
| 673 | } |
||
| 674 | else |
||
| 675 | { |
||
| 676 | $this->error = 'msg_invalid_request'; |
||
| 677 | $oModule->setError(-1); |
||
| 678 | $oModule->setMessage($this->error); |
||
| 679 | return $oModule; |
||
| 680 | } |
||
| 681 | } |
||
| 682 | |||
| 683 | // ruleset check... |
||
| 684 | if(!empty($ruleset)) |
||
| 685 | { |
||
| 686 | $rulesetModule = $forward->module ? $forward->module : $this->module; |
||
| 687 | $rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid); |
||
| 688 | if(!empty($rulesetFile)) |
||
| 689 | { |
||
| 690 | if($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
||
| 691 | { |
||
| 692 | $errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG']; |
||
| 693 | foreach($errorLang as $key => $val) |
||
| 694 | { |
||
| 695 | Context::setLang($key, $val); |
||
| 696 | } |
||
| 697 | unset($_SESSION['XE_VALIDATOR_ERROR_LANG']); |
||
| 698 | } |
||
| 699 | |||
| 700 | $Validator = new Validator($rulesetFile); |
||
| 701 | $result = $Validator->validate(); |
||
| 702 | if(!$result) |
||
| 703 | { |
||
| 704 | $lastError = $Validator->getLastError(); |
||
| 705 | $returnUrl = Context::get('error_return_url'); |
||
| 706 | $errorMsg = $lastError['msg'] ? $lastError['msg'] : 'validation error'; |
||
| 707 | |||
| 708 | //for xml response |
||
| 709 | $oModule->setError(-1); |
||
| 710 | $oModule->setMessage($errorMsg); |
||
| 711 | //for html redirect |
||
| 712 | $this->error = $errorMsg; |
||
| 713 | $_SESSION['XE_VALIDATOR_ERROR'] = -1; |
||
| 714 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $this->error; |
||
| 715 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = 'error'; |
||
| 716 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $returnUrl; |
||
| 717 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
||
| 718 | $this->_setInputValueToSession(); |
||
| 719 | return $oModule; |
||
| 720 | } |
||
| 721 | } |
||
| 722 | } |
||
| 723 | |||
| 724 | $oModule->setAct($this->act); |
||
| 725 | |||
| 726 | $this->module_info->module_type = $type; |
||
| 727 | $oModule->setModuleInfo($this->module_info, $xml_info); |
||
| 728 | |||
| 729 | $skipAct = array( |
||
| 730 | 'dispEditorConfigPreview' => 1, |
||
| 731 | 'dispLayoutPreviewWithModule' => 1 |
||
| 732 | ); |
||
| 733 | $db_use_mobile = Mobile::isMobileEnabled(); |
||
| 734 | if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
||
| 735 | { |
||
| 736 | global $lang; |
||
| 737 | $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>'; |
||
| 738 | $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>'; |
||
| 739 | Context::addHtmlHeader($header); |
||
| 740 | Context::addHtmlFooter($footer); |
||
| 741 | } |
||
| 742 | |||
| 743 | if($type == "view" && $kind != 'admin') |
||
| 744 | { |
||
| 745 | $module_config = $oModuleModel->getModuleConfig('module'); |
||
| 746 | if($module_config->htmlFooter) |
||
| 747 | { |
||
| 748 | Context::addHtmlFooter($module_config->htmlFooter); |
||
| 749 | } |
||
| 750 | if($module_config->siteTitle) |
||
| 751 | { |
||
| 752 | $siteTitle = Context::getBrowserTitle(); |
||
| 753 | if(!$siteTitle) |
||
| 754 | { |
||
| 755 | Context::setBrowserTitle($module_config->siteTitle); |
||
| 756 | } |
||
| 757 | } |
||
| 758 | } |
||
| 759 | |||
| 760 | // if failed message exists in session, set context |
||
| 761 | $this->_setInputErrorToContext(); |
||
| 762 | |||
| 763 | $procResult = $oModule->proc(); |
||
| 764 | |||
| 765 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
||
| 766 | if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
||
| 767 | { |
||
| 768 | $error = $oModule->getError(); |
||
| 769 | $message = $oModule->getMessage(); |
||
| 770 | $messageType = $oModule->getMessageType(); |
||
| 771 | $redirectUrl = $oModule->getRedirectUrl(); |
||
| 772 | if($messageType == 'error') debugPrint($message, 'ERROR'); |
||
| 773 | |||
| 774 | if(!$procResult) |
||
| 775 | { |
||
| 776 | $this->error = $message; |
||
| 777 | if(!$redirectUrl && Context::get('error_return_url')) |
||
| 778 | { |
||
| 779 | $redirectUrl = Context::get('error_return_url'); |
||
| 780 | } |
||
| 781 | $this->_setInputValueToSession(); |
||
| 782 | } |
||
| 783 | else |
||
| 784 | { |
||
| 785 | |||
| 786 | } |
||
| 787 | |||
| 788 | $_SESSION['XE_VALIDATOR_ERROR'] = $error; |
||
| 789 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
||
| 790 | if($message != 'success') |
||
| 791 | { |
||
| 792 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $message; |
||
| 793 | } |
||
| 794 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType; |
||
| 795 | |||
| 796 | if(Context::get('xeVirtualRequestMethod') != 'xml') |
||
| 797 | { |
||
| 798 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl; |
||
| 799 | } |
||
| 800 | } |
||
| 801 | |||
| 802 | unset($logged_info); |
||
| 803 | return $oModule; |
||
| 804 | } |
||
| 805 | |||
| 1320 |