OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@1020 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_TrackBack / trunk / trackback / template.php
1 <?php
2 class Trackback_Template {
3     var $vars; 
4
5     function Trackback_Template($file = null, $prefix = '') {
6         $this->file = ($prefix ? $prefix . '/' : '') . $file;
7                 $this->prefix = $prefix;
8     }
9
10     function set($name, $value) {
11         $this->vars[$name] = is_object($value) ? $value->fetch() : $value;
12     }
13         
14         function template($file = null) {
15                 $language = ereg_replace( '[\\|/]', '', getLanguageName());
16                 $this->file = (file_exists(($this->prefix ? $this->prefix . '/' : '') . $language.'.'.$file))? ($this->prefix ? $this->prefix . '/' : '') . $language.'.'.$file: ($this->prefix ? $this->prefix . '/' : '') . $file;
17         }
18
19     function fetch($file = null) {
20         if(!$file) $file = $this->file;
21                 else ($prefix ? $prefix . '/' : '') . $file;
22                 
23                 if ($file != null)
24                 {
25                 if (is_array($this->vars)) extract($this->vars);          
26         
27                         ob_start();
28                 include($file);
29                 $contents = ob_get_contents();
30                 ob_end_clean();
31         
32                         return $contents;
33                 }
34     }
35 }