X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=trunk%2FNP_Clap%2Fsharedlibs%2Fcles%2FTemplate.php;fp=trunk%2FNP_Clap%2Fsharedlibs%2Fcles%2FTemplate.php;h=09f3ac32eba55645baece4cfd1c7a6cae19a966b;hb=4c562a33f42519fa9d6a197bf1998236c6371caf;hp=028f783e5d4b24b04d1446e9c50109a6d92bab88;hpb=4bcc44da2dd34c3c45592bc89967496c9458d032;p=nucleus-jp%2Fnucleus-plugins.git diff --git a/trunk/NP_Clap/sharedlibs/cles/Template.php b/trunk/NP_Clap/sharedlibs/cles/Template.php index 028f783..09f3ac3 100644 --- a/trunk/NP_Clap/sharedlibs/cles/Template.php +++ b/trunk/NP_Clap/sharedlibs/cles/Template.php @@ -1,76 +1,87 @@ -templateDir = $templateDir; - $this->lang = ereg_replace( '[\\|/]', '', getLanguageName()); - } - - function fetch($name, $dir = null, $suffix = 'html') { - $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->lang.( $suffix ? '.'.strtolower($suffix) : '' ); - if ( ! file_exists($path) ){ - $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->defaultLang.( $suffix ? '.'.strtolower($suffix) : '' ); - if ( ! file_exists($path) ) - return ''; - } - - $fsize = filesize($path); - if ($fsize <= 0) return ''; - - $fd = fopen($path, 'r'); - $contents = fread($fd, $fsize); - fclose($fd); - return $contents; - } - - function fill($template, $values, $default = null) { - if( $default ) - return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : $default', $template); - if( $default === null ) - return preg_replace($this->defalutPattern, '("$2") ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]', $template); - return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : "{{$1}}" ', $template); - } -} +templateDir = $templateDir; + $this->lang = ereg_replace( '[\\|/]', '', getLanguageName()); + } + + function fetch($name, $dir = null, $suffix = 'html') { + $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->lang.( $suffix ? '.'.strtolower($suffix) : '' ); + if ( ! file_exists($path) ){ + $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->defaultLang.( $suffix ? '.'.strtolower($suffix) : '' ); + if ( ! file_exists($path) ) + return ''; + } + + $fsize = filesize($path); + if ($fsize <= 0) return ''; + + $fd = fopen($path, 'r'); + $contents = fread($fd, $fsize); + fclose($fd); + return $contents; + } + + function fill($template, $values, $default = null) { + if( $default ) + return preg_replace($this->defalutPattern, 'isset($values[\'$1\']) ? (\'$2\' ? htmlspecialchars($values[\'$1\'], ENT_QUOTES) : $values[\'$1\']) : $default', $template); + if( $default === null ) + return preg_replace($this->defalutPattern, '(\'$2\') ? htmlspecialchars($values[\'$1\'], ENT_QUOTES) : $values[\'$1\']', $template); + return preg_replace($this->defalutPattern, 'isset($values[\'$1\']) ? (\'$2\' ? htmlspecialchars($values[\'$1\'], ENT_QUOTES) : $values[\'$1\']) : \'{{$1}}\' ', $template); + } + + function fetchAndFill($name, $values, $dir = null, $suffix = 'html', $default = null){ + $tpl = $this->fetch($name, $dir, $suffix); + return $this->fill($tpl, $values, $default); + } +}