| Conditions | 56 |
| Paths | > 20000 |
| Total Lines | 295 |
| Code Lines | 184 |
| Lines | 2 |
| Ratio | 0.68 % |
| 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 |
||
| 441 | function getLayoutInfo($layout, $info = null, $layout_type = "P") |
||
| 442 | { |
||
| 443 | if($info) |
||
| 444 | { |
||
| 445 | $layout_title = $info->title; |
||
| 446 | $layout = $info->layout; |
||
| 447 | $layout_srl = $info->layout_srl; |
||
| 448 | $site_srl = $info->site_srl; |
||
| 449 | $vars = unserialize($info->extra_vars); |
||
| 450 | |||
| 451 | if($info->module_srl) |
||
| 452 | { |
||
| 453 | $layout_path = preg_replace('/([a-zA-Z0-9\_\.]+)(\.html)$/','',$info->layout_path); |
||
| 454 | $xml_file = sprintf('%sskin.xml', $layout_path); |
||
| 455 | } |
||
| 456 | } |
||
| 457 | |||
| 458 | // Get a path of the requested module. Return if not exists. |
||
| 459 | if(!$layout_path) $layout_path = $this->getLayoutPath($layout, $layout_type); |
||
| 460 | if(!is_dir($layout_path)) return; |
||
| 461 | |||
| 462 | // Read the xml file for module skin information |
||
| 463 | if(!$xml_file) $xml_file = sprintf("%sconf/info.xml", $layout_path); |
||
| 464 | if(!file_exists($xml_file)) |
||
| 465 | { |
||
| 466 | $layout_info = new stdClass; |
||
| 467 | $layout_info->title = $layout; |
||
| 468 | $layout_info->layout = $layout; |
||
| 469 | $layout_info->path = $layout_path; |
||
| 470 | $layout_info->layout_title = $layout_title; |
||
| 471 | if(!$layout_info->layout_type) |
||
| 472 | { |
||
| 473 | $layout_info->layout_type = $layout_type; |
||
| 474 | } |
||
| 475 | return $layout_info; |
||
| 476 | } |
||
| 477 | |||
| 478 | // Include the cache file if it is valid and then return $layout_info variable |
||
| 479 | if(!$layout_srl) |
||
| 480 | { |
||
| 481 | $cache_file = $this->getLayoutCache($layout, Context::getLangType(), $layout_type); |
||
| 482 | } |
||
| 483 | else |
||
| 484 | { |
||
| 485 | $cache_file = $this->getUserLayoutCache($layout_srl, Context::getLangType()); |
||
| 486 | } |
||
| 487 | |||
| 488 | if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file)) |
||
| 489 | { |
||
| 490 | include($cache_file); |
||
| 491 | |||
| 492 | if($layout_info->extra_var && $vars) |
||
| 493 | { |
||
| 494 | foreach($vars as $key => $value) |
||
| 495 | { |
||
| 496 | if(!$layout_info->extra_var->{$key} && !$layout_info->{$key}) |
||
| 497 | { |
||
| 498 | $layout_info->{$key} = $value; |
||
| 499 | } |
||
| 500 | } |
||
| 501 | } |
||
| 502 | |||
| 503 | if(!$layout_info->title) |
||
| 504 | { |
||
| 505 | $layout_info->title = $layout; |
||
| 506 | } |
||
| 507 | |||
| 508 | return $layout_info; |
||
| 509 | } |
||
| 510 | // If no cache file exists, parse the xml and then return the variable. |
||
| 511 | $oXmlParser = new XmlParser(); |
||
| 512 | $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file); |
||
| 513 | |||
| 514 | if($tmp_xml_obj->layout) $xml_obj = $tmp_xml_obj->layout; |
||
| 515 | elseif($tmp_xml_obj->skin) $xml_obj = $tmp_xml_obj->skin; |
||
| 516 | |||
| 517 | if(!$xml_obj) return; |
||
| 518 | |||
| 519 | $buff = array(); |
||
| 520 | $buff[] = '$layout_info = new stdClass;'; |
||
| 521 | $buff[] = sprintf('$layout_info->site_srl = "%s";', $site_srl); |
||
| 522 | |||
| 523 | if($xml_obj->version && $xml_obj->attrs->version == '0.2') |
||
| 524 | { |
||
| 525 | // Layout title, version and other information |
||
| 526 | sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d); |
||
| 527 | $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); |
||
| 528 | $buff[] = sprintf('$layout_info->layout = "%s";', $layout); |
||
| 529 | $buff[] = sprintf('$layout_info->type = "%s";', $xml_obj->attrs->type); |
||
| 530 | $buff[] = sprintf('$layout_info->path = "%s";', $layout_path); |
||
| 531 | $buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body); |
||
| 532 | $buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->description->body); |
||
| 533 | $buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->version->body); |
||
| 534 | $buff[] = sprintf('$layout_info->date = "%s";', $date); |
||
| 535 | $buff[] = sprintf('$layout_info->homepage = "%s";', $xml_obj->link->body); |
||
| 536 | $buff[] = sprintf('$layout_info->layout_srl = $layout_srl;'); |
||
| 537 | $buff[] = sprintf('$layout_info->layout_title = $layout_title;'); |
||
| 538 | $buff[] = sprintf('$layout_info->license = "%s";', $xml_obj->license->body); |
||
| 539 | $buff[] = sprintf('$layout_info->license_link = "%s";', $xml_obj->license->attrs->link); |
||
| 540 | $buff[] = sprintf('$layout_info->layout_type = "%s";', $layout_type); |
||
| 541 | |||
| 542 | // Author information |
||
| 543 | View Code Duplication | if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author; |
|
| 544 | else $author_list = $xml_obj->author; |
||
| 545 | |||
| 546 | $buff[] = '$layout_info->author = array();'; |
||
| 547 | for($i=0, $c=count($author_list); $i<$c; $i++) |
||
| 548 | { |
||
| 549 | $buff[] = sprintf('$layout_info->author[%d] = new stdClass;', $i); |
||
| 550 | $buff[] = sprintf('$layout_info->author[%d]->name = "%s";', $i, $author_list[$i]->name->body); |
||
| 551 | $buff[] = sprintf('$layout_info->author[%d]->email_address = "%s";', $i, $author_list[$i]->attrs->email_address); |
||
| 552 | $buff[] = sprintf('$layout_info->author[%d]->homepage = "%s";', $i, $author_list[$i]->attrs->link); |
||
| 553 | } |
||
| 554 | |||
| 555 | // Extra vars (user defined variables to use in a template) |
||
| 556 | $extra_var_groups = $xml_obj->extra_vars->group; |
||
| 557 | if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars; |
||
| 558 | if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups); |
||
| 559 | |||
| 560 | $buff[] = '$layout_info->extra_var = new stdClass;'; |
||
| 561 | $extra_var_count = 0; |
||
| 562 | foreach($extra_var_groups as $group) |
||
| 563 | { |
||
| 564 | $extra_vars = $group->var; |
||
| 565 | if($extra_vars) |
||
| 566 | { |
||
| 567 | if(!is_array($extra_vars)) $extra_vars = array($extra_vars); |
||
| 568 | |||
| 569 | $count = count($extra_vars); |
||
| 570 | $extra_var_count += $count; |
||
| 571 | |||
| 572 | for($i=0;$i<$count;$i++) |
||
| 573 | { |
||
| 574 | unset($var, $options); |
||
| 575 | $var = $extra_vars[$i]; |
||
| 576 | $name = $var->attrs->name; |
||
| 577 | |||
| 578 | $buff[] = sprintf('$layout_info->extra_var->%s = new stdClass;', $name); |
||
| 579 | $buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body); |
||
| 580 | $buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body); |
||
| 581 | $buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type); |
||
| 582 | $buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name); |
||
| 583 | $buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"','\"',$var->description->body)); |
||
| 584 | |||
| 585 | $options = $var->options; |
||
| 586 | if(!$options) continue; |
||
| 587 | if(!is_array($options)) $options = array($options); |
||
| 588 | |||
| 589 | $buff[] = sprintf('$layout_info->extra_var->%s->options = array();', $var->attrs->name); |
||
| 590 | $options_count = count($options); |
||
| 591 | $thumbnail_exist = false; |
||
| 592 | for($j=0; $j < $options_count; $j++) |
||
| 593 | { |
||
| 594 | $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"] = new stdClass;', $var->attrs->name, $options[$j]->attrs->value); |
||
| 595 | $thumbnail = $options[$j]->attrs->src; |
||
| 596 | if($thumbnail) |
||
| 597 | { |
||
| 598 | $thumbnail = $layout_path.$thumbnail; |
||
| 599 | if(file_exists($thumbnail)) |
||
| 600 | { |
||
| 601 | $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->thumbnail = "%s";', $var->attrs->name, $options[$j]->attrs->value, $thumbnail); |
||
| 602 | if(!$thumbnail_exist) |
||
| 603 | { |
||
| 604 | $buff[] = sprintf('$layout_info->extra_var->%s->thumbnail_exist = true;', $var->attrs->name); |
||
| 605 | $thumbnail_exist = true; |
||
| 606 | } |
||
| 607 | } |
||
| 608 | } |
||
| 609 | $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->attrs->value, $options[$j]->title->body); |
||
| 610 | } |
||
| 611 | } |
||
| 612 | } |
||
| 613 | } |
||
| 614 | $buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count); |
||
| 615 | // Menu |
||
| 616 | if($xml_obj->menus->menu) |
||
| 617 | { |
||
| 618 | $menus = $xml_obj->menus->menu; |
||
| 619 | if(!is_array($menus)) $menus = array($menus); |
||
| 620 | |||
| 621 | $menu_count = count($menus); |
||
| 622 | $buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count); |
||
| 623 | $buff[] = '$layout_info->menu = new stdClass;'; |
||
| 624 | for($i=0;$i<$menu_count;$i++) |
||
| 625 | { |
||
| 626 | $name = $menus[$i]->attrs->name; |
||
| 627 | if($menus[$i]->attrs->default == "true") $buff[] = sprintf('$layout_info->default_menu = "%s";', $name); |
||
| 628 | $buff[] = sprintf('$layout_info->menu->%s = new stdClass;', $name); |
||
| 629 | $buff[] = sprintf('$layout_info->menu->%s->name = "%s";',$name, $menus[$i]->attrs->name); |
||
| 630 | $buff[] = sprintf('$layout_info->menu->%s->title = "%s";',$name, $menus[$i]->title->body); |
||
| 631 | $buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";',$name, $menus[$i]->attrs->maxdepth); |
||
| 632 | |||
| 633 | $buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name); |
||
| 634 | $buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";',$name, $name); |
||
| 635 | $buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";',$name, $name); |
||
| 636 | } |
||
| 637 | } |
||
| 638 | } |
||
| 639 | else |
||
| 640 | { |
||
| 641 | // Layout title, version and other information |
||
| 642 | sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d); |
||
| 643 | $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); |
||
| 644 | $buff[] = sprintf('$layout_info->layout = "%s";', $layout); |
||
| 645 | $buff[] = sprintf('$layout_info->path = "%s";', $layout_path); |
||
| 646 | $buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body); |
||
| 647 | $buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->author->description->body); |
||
| 648 | $buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->attrs->version); |
||
| 649 | $buff[] = sprintf('$layout_info->date = "%s";', $date); |
||
| 650 | $buff[] = sprintf('$layout_info->layout_srl = $layout_srl;'); |
||
| 651 | $buff[] = sprintf('$layout_info->layout_title = $layout_title;'); |
||
| 652 | // Author information |
||
| 653 | $buff[] = sprintf('$layout_info->author[0]->name = "%s";', $xml_obj->author->name->body); |
||
| 654 | $buff[] = sprintf('$layout_info->author[0]->email_address = "%s";', $xml_obj->author->attrs->email_address); |
||
| 655 | $buff[] = sprintf('$layout_info->author[0]->homepage = "%s";', $xml_obj->author->attrs->link); |
||
| 656 | // Extra vars (user defined variables to use in a template) |
||
| 657 | $extra_var_groups = $xml_obj->extra_vars->group; |
||
| 658 | if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars; |
||
| 659 | if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups); |
||
| 660 | foreach($extra_var_groups as $group) |
||
| 661 | { |
||
| 662 | $extra_vars = $group->var; |
||
| 663 | if($extra_vars) |
||
| 664 | { |
||
| 665 | if(!is_array($extra_vars)) $extra_vars = array($extra_vars); |
||
| 666 | |||
| 667 | $extra_var_count = count($extra_vars); |
||
| 668 | |||
| 669 | $buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count); |
||
| 670 | for($i=0;$i<$extra_var_count;$i++) |
||
| 671 | { |
||
| 672 | unset($var, $options); |
||
| 673 | $var = $extra_vars[$i]; |
||
| 674 | $name = $var->attrs->name; |
||
| 675 | |||
| 676 | $buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body); |
||
| 677 | $buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body); |
||
| 678 | $buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type); |
||
| 679 | $buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name); |
||
| 680 | $buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"','\"',$var->description->body)); |
||
| 681 | |||
| 682 | $options = $var->options; |
||
| 683 | if(!$options) continue; |
||
| 684 | |||
| 685 | if(!is_array($options)) $options = array($options); |
||
| 686 | $options_count = count($options); |
||
| 687 | for($j=0;$j<$options_count;$j++) |
||
| 688 | { |
||
| 689 | $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->value->body, $options[$j]->title->body); |
||
| 690 | } |
||
| 691 | } |
||
| 692 | } |
||
| 693 | } |
||
| 694 | // Menu |
||
| 695 | if($xml_obj->menus->menu) |
||
| 696 | { |
||
| 697 | $menus = $xml_obj->menus->menu; |
||
| 698 | if(!is_array($menus)) $menus = array($menus); |
||
| 699 | |||
| 700 | $menu_count = count($menus); |
||
| 701 | $buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count); |
||
| 702 | for($i=0;$i<$menu_count;$i++) |
||
| 703 | { |
||
| 704 | $name = $menus[$i]->attrs->name; |
||
| 705 | if($menus[$i]->attrs->default == "true") $buff[] = sprintf('$layout_info->default_menu = "%s";', $name); |
||
| 706 | $buff[] = sprintf('$layout_info->menu->%s->name = "%s";',$name, $name); |
||
| 707 | $buff[] = sprintf('$layout_info->menu->%s->title = "%s";',$name, $menus[$i]->title->body); |
||
| 708 | $buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";',$name, $menus[$i]->maxdepth->body); |
||
| 709 | $buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name); |
||
| 710 | $buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";',$name, $name); |
||
| 711 | $buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";',$name, $name); |
||
| 712 | } |
||
| 713 | } |
||
| 714 | } |
||
| 715 | |||
| 716 | // header_script |
||
| 717 | $oModuleModel = getModel('module'); |
||
| 718 | $layout_config = $oModuleModel->getModulePartConfig('layout', $layout_srl); |
||
| 719 | $header_script = trim($layout_config->header_script); |
||
| 720 | |||
| 721 | if($header_script) |
||
| 722 | { |
||
| 723 | $buff[] = sprintf(' $layout_info->header_script = "%s"; ', str_replace(array('$','"'),array('\$','\\"'),$header_script)); |
||
| 724 | } |
||
| 725 | |||
| 726 | FileHandler::writeFile($cache_file, '<?php if(!defined("__XE__")) exit(); ' . join(PHP_EOL, $buff)); |
||
| 727 | if(FileHandler::exists($cache_file)) include($cache_file); |
||
| 728 | |||
| 729 | if(!$layout_info->title) |
||
| 730 | { |
||
| 731 | $layout_info->title = $layout; |
||
| 732 | } |
||
| 733 | |||
| 734 | return $layout_info; |
||
| 735 | } |
||
| 736 | |||
| 1045 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: