| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
require_once 'HTML/Template/Smarty/Smarty.class.php'; |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
class Framework_Template_Smarty |
|---|
| 26 |
extends Smarty |
|---|
| 27 |
implements Framework_Template_Interface |
|---|
| 28 |
{ |
|---|
| 29 |
|
|---|
| 30 |
* $module |
|---|
| 31 |
* |
|---|
| 32 |
* @access private |
|---|
| 33 |
* @var string $module |
|---|
| 34 |
*/ |
|---|
| 35 |
protected $module = ''; |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
* $template |
|---|
| 39 |
* |
|---|
| 40 |
* @access private |
|---|
| 41 |
* @var string $template |
|---|
| 42 |
*/ |
|---|
| 43 |
protected $template = ''; |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
* __construct |
|---|
| 47 |
* |
|---|
| 48 |
* @access public |
|---|
| 49 |
* @param string $module |
|---|
| 50 |
* @param string $template |
|---|
| 51 |
* @return void |
|---|
| 52 |
*/ |
|---|
| 53 |
public function __construct($module, $template = 'Default') |
|---|
| 54 |
{ |
|---|
| 55 |
$this->module = $module; |
|---|
| 56 |
$this->template = $template; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
* display |
|---|
| 61 |
* |
|---|
| 62 |
* @access public |
|---|
| 63 |
* @param string $template |
|---|
| 64 |
* @param string $cache_id |
|---|
| 65 |
* @param string $compile_id |
|---|
| 66 |
* @return void |
|---|
| 67 |
*/ |
|---|
| 68 |
public function display($template, $cache_id = '', $compile_id = '') |
|---|
| 69 |
{ |
|---|
| 70 |
$this->setPaths($template); |
|---|
| 71 |
$compile_id = $this->getCompileID($template, $compile_id); |
|---|
| 72 |
parent::display($template, $cache_id, $compile_id); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
* fetch |
|---|
| 77 |
* |
|---|
| 78 |
* @access public |
|---|
| 79 |
* @param string $template |
|---|
| 80 |
* @param string $cache_id |
|---|
| 81 |
* @param string $compile_id |
|---|
| 82 |
* @return string |
|---|
| 83 |
*/ |
|---|
| 84 |
public function fetch($template, $cache_id = '', $compile_id = '', $display = false) |
|---|
| 85 |
{ |
|---|
| 86 |
$this->setPaths($template); |
|---|
| 87 |
$compile_id = $this->getCompileID($template, $compile_id); |
|---|
| 88 |
return parent::fetch($template, $cache_id, $compile_id, $display); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
* setPaths |
|---|
| 93 |
* |
|---|
| 94 |
* @access public |
|---|
| 95 |
* @param string $template |
|---|
| 96 |
* @return void |
|---|
| 97 |
*/ |
|---|
| 98 |
protected function setPaths($template) |
|---|
| 99 |
{ |
|---|
| 100 |
$this->template_dir = Framework_Template::getPath($template, $this->module, $this->template); |
|---|
| 101 |
$path = realpath(Framework::$site->getPath() . '/Templates/'. $this->template); |
|---|
| 102 |
$this->compile_dir = $path . '/templates_c'; |
|---|
| 103 |
$this->cache_dir = $path . '/cache'; |
|---|
| 104 |
$this->config_dir = $path . '/config'; |
|---|
| 105 |
$this->plugins_dir = array_merge($this->plugins_dir, array('Framework/Template/Smarty/plugins','plugins', $path.'/plugins')); |
|---|
| 106 |
|
|---|
| 107 |
if (!is_writeable($this->compile_dir) || |
|---|
| 108 |
!is_writeable($this->cache_dir)) { |
|---|
| 109 |
throw new Framework_Exception('Cannot write to template cache/compile dirs: ' . $path); |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
* getCompileID |
|---|
| 115 |
* |
|---|
| 116 |
* Creates a unique compile_id for a given template. |
|---|
| 117 |
* |
|---|
| 118 |
* @author Joe Stump <joe@joestump.net> |
|---|
| 119 |
* @access private |
|---|
| 120 |
* @param string $template Name of template |
|---|
| 121 |
* @param string $compile_id Old $compile_id |
|---|
| 122 |
* @return string |
|---|
| 123 |
*/ |
|---|
| 124 |
private function getCompileID($template, $compile_id) |
|---|
| 125 |
{ |
|---|
| 126 |
if (strlen($compile_id)) { |
|---|
| 127 |
return $compile_id; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
$compile_id = $this->template_dir . $this->template . $template; |
|---|
| 131 |
return sha1($compile_id); |
|---|
| 132 |
} |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
?> |
|---|
| 136 |
|
|---|