ContentReplaceBehavior.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. * Behavior of the system expansion: output template content replacement
  12. * @category Sen
  13. * @package Sen
  14. * @subpackage Behavior
  15. * @author ms134n <[email protected]>
  16. */
  17. class ContentReplaceBehavior extends Behavior {
  18. // Parameter defines the behavior
  19. protected $options = array(
  20. 'TMPL_PARSE_STRING' => array(),
  21. );
  22. // Behavior extension execution entry must be run
  23. public function run(&$content){
  24. $content = $this->templateContentReplace($content);
  25. }
  26. /**
  27. * Replace the contents of the template
  28. * @access protected
  29. * @param string $content Template content
  30. * @return string
  31. */
  32. protected function templateContentReplace($content) {
  33. // Special variable substitution system default
  34. $replace = array(
  35. '__TMPL__' => APP_TMPL_PATH, // Project template directory
  36. '__ROOT__' => __ROOT__, // Current website address
  37. '__APP__' => __APP__, // Current projects address
  38. '__GROUP__' => defined('GROUP_NAME')?__GROUP__:__APP__,
  39. '__ACTION__' => __ACTION__, // Address the current operation
  40. '__SELF__' => __SELF__, // Address of the current page
  41. '__URL__' => __URL__,
  42. '../Public' => APP_TMPL_PATH.'Public',// Public project template directory
  43. '__PUBLIC__' => __ROOT__.'/Public',// Public directory sites
  44. );
  45. // Allows users to customize the template string replacement
  46. if(is_array(C('TMPL_PARSE_STRING')) )
  47. $replace = array_merge($replace,C('TMPL_PARSE_STRING'));
  48. $content = str_replace(array_keys($replace),array_values($replace),$content);
  49. return $content;
  50. }
  51. }