2 // vim: foldmethod=marker
4 * Ethna_Renderer_Smarty.php
6 * @author Kazuhiro Hosoi <hosoi@gree.co.jp>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
11 require_once 'Smarty/Smarty.class.php';
13 // {{{ Ethna_Renderer_Smarty
15 * Smartyレンダラクラス(Mojaviのまね)
17 * @author Kazuhiro Hosoi <hosoi@gree.co.jp>
21 class Ethna_Renderer_Smarty extends Ethna_Renderer
23 /** @var string compile directory */
27 * Ethna_Renderer_Smartyクラスのコンストラクタ
31 function Ethna_Renderer_Smarty(&$controller)
33 parent::Ethna_Renderer($controller);
35 $this->engine =& new Smarty;
37 $template_dir = $controller->getTemplatedir();
38 $compile_dir = $controller->getDirectory('template_c');
40 $this->setTemplateDir($template_dir);
41 $this->compile_dir = $compile_dir;
42 $this->engine->template_dir = $this->template_dir;
43 $this->engine->compile_dir = $this->compile_dir;
44 $this->engine->compile_id = md5($this->template_dir);
47 if (is_dir($this->engine->compile_dir) === false) {
48 Ethna_Util::mkdir($this->engine->compile_dir, 0755);
51 $this->engine->plugins_dir = array_merge(
52 $controller->getDirectory('plugins'),
53 array(ETHNA_BASE . '/class/Plugin/Smarty', SMARTY_DIR . 'plugins')
60 * @param string $template テンプレート名
61 * @param bool $capture true ならば出力を表示せずに返す
65 function perform($template = null, $capture = false)
67 if ($template === null && $this->template === null) {
68 return Ethna::raiseWarning('template is not defined');
71 if ($template !== null) {
72 $this->template = $template;
75 if ((is_absolute_path($this->template) && is_readable($this->template))
76 || is_readable($this->template_dir . $this->template)) {
77 if ($capture === true) {
78 $captured = $this->engine->fetch($this->template);
81 $this->engine->display($this->template);
84 return Ethna::raiseWarning('template not found ' . $this->template);
91 * @param string $name 変数名
97 function &getProp($name = null)
99 $property =& $this->engine->get_template_vars($name);
101 if ($property !== null) {
114 function removeProp($name)
116 $this->engine->clear_assign($name);
122 * @param array $array
126 function setPropArray($array)
128 $this->engine->assign($array);
132 * テンプレート変数に配列を参照として割り当てる
134 * @param array $array
138 function setPropArrayByRef(&$array)
140 $this->engine->assign_by_ref($array);
146 * @param string $name 変数名
147 * @param mixed $value 値
151 function setProp($name, $value)
153 $this->engine->assign($name, $value);
159 * @param string $name 変数名
160 * @param mixed $value 値
164 function setPropByRef($name, &$value)
166 $this->engine->assign_by_ref($name, $value);
172 * @param string $name プラグイン名
173 * @param string $type プラグインタイプ
174 * @param mixed $plugin プラグイン本体
178 function setPlugin($name, $type, $plugin)
181 if (is_callable($plugin) === false) {
182 return Ethna::raiseWarning('Does not exists.');
186 $register_method = 'register_' . $type;
187 if (method_exists($this->engine, $register_method) === false) {
188 return Ethna::raiseWarning('This plugin type does not exist');
192 if ($type === 'prefilter' || $type === 'postfilter' || $type === 'outputfilter') {
193 parent::setPlugin($name, $type, $plugin);
194 $this->engine->$register_method($plugin);
200 return Ethna::raiseWarning('Please set plugin name');
204 parent::setPlugin($name, $type, $plugin);
205 $this->engine->$register_method($name, $plugin);