LocationTemplateBehavior.class.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +--------------------------------------------------------------------------
  3. // | Senthot [ DEVELOPED BY ME ]
  4. // +--------------------------------------------------------------------------
  5. // | Copyright (c) 2005-2013 http://www.senthot.com All rights reserved.
  6. // | License ( http://www.apache.org/licenses/LICENSE-2.0 )
  7. // | Author: ms134n ( [email protected] )
  8. // +--------------------------------------------------------------------------
  9. defined('SEN_PATH') or exit();
  10. /**
  11. * System behavior extension : Locate the template file
  12. * @category Sen
  13. * @package Sen
  14. * @subpackage Behavior
  15. * @author ms134n <[email protected]>
  16. */
  17. class LocationTemplateBehavior extends Behavior {
  18. // Behavior extension execution entry must be run
  19. public function run(&$templateFile){
  20. // Automatic positioning template file
  21. if(!file_exists_case($templateFile))
  22. $templateFile = $this->parseTemplateFile($templateFile);
  23. }
  24. /**
  25. * Automatic positioning template file
  26. * @access private
  27. * @param string $templateFile File Name
  28. * @return string
  29. */
  30. private function parseTemplateFile($templateFile) {
  31. if(''==$templateFile) {
  32. // If the template file name is empty Positioned in accordance with the default rule
  33. $templateFile = C('TEMPLATE_NAME');
  34. }elseif(false === strpos($templateFile,C('TMPL_TEMPLATE_SUFFIX'))){
  35. // Parsing rules Template Theme:Module:Operating Not Support Cross-project and cross-grouping called
  36. $path = explode(':',$templateFile);
  37. $action = array_pop($path);
  38. $module = !empty($path)?array_pop($path):MODULE_NAME;
  39. if(!empty($path)) {// Set Template Theme
  40. $path = dirname(THEME_PATH).'/'.array_pop($path).'/';
  41. }else{
  42. $path = THEME_PATH;
  43. }
  44. $templateFile = $path.$module.C('TMPL_FILE_DEPR').$action.C('TMPL_TEMPLATE_SUFFIX');
  45. }
  46. if(!file_exists_case($templateFile))
  47. throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
  48. return $templateFile;
  49. }
  50. }