OSDN Git Service

NP_Moblog v1.17
[nucleus-jp/nucleus-plugins.git] / trunk / NP_Moblog / sharedlibs / cles / Template.php
index 24d2e93..09f3ac3 100644 (file)
@@ -1,76 +1,87 @@
-<?php
-// vim: tabstop=2:shiftwidth=2
-
-/**
-  * Template.php ($Revision: 1.1 $)
-  * 
-  * by hsur ( http://blog.cles.jp/np_cles )
-  * $Id: Template.php,v 1.1 2008-05-04 07:04:50 hsur Exp $
-*/
-
-/*
-  * Copyright (C) 2006 CLES. All rights reserved.
-  *
-  * This program is free software; you can redistribute it and/or
-  * modify it under the terms of the GNU General Public License
-  * as published by the Free Software Foundation; either version 2
-  * of the License, or (at your option) any later version.
-  * 
-  * This program is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  * GNU General Public License for more details.
-  * 
-  * You should have received a copy of the GNU General Public License
-  * along with this program; if not, write to the Free Software
-  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
-  * 
-  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
-  * permission to link the code of this program with those files in the PEAR
-  * library that are licensed under the PHP License (or with modified versions
-  * of those files that use the same license as those files), and distribute
-  * linked combinations including the two. You must obey the GNU General Public
-  * License in all respects for all of the code used other than those files in
-  * the PEAR library that are licensed under the PHP License. If you modify
-  * this file, you may extend this exception to your version of the file,
-  * but you are not obligated to do so. If you do not wish to do so, delete
-  * this exception statement from your version.
-*/
-
-class cles_Template {
-       var $defaultLang = 'japanese-utf8';
-       var $defalutPattern = '#{{(.*?)(\|)?}}#ie';
-       var $lang;
-       var $templateDir;
-
-       function cles_Template($templateDir) {
-               global $CONF;
-               $this->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);
-       }
-}
+<?php\r
+// vim: tabstop=2:shiftwidth=2\r
+\r
+/**\r
+  * Template.php ($Revision: 1.11 $)\r
+  * \r
+  * by hsur ( http://blog.cles.jp/np_cles )\r
+  * $Id: Template.php,v 1.11 2008/08/15 21:17:02 hsur Exp $\r
+*/\r
+\r
+/*\r
+  * Copyright (C) 2006-2008 CLES. All rights reserved.\r
+  *\r
+  * This program is free software; you can redistribute it and/or\r
+  * modify it under the terms of the GNU General Public License\r
+  * as published by the Free Software Foundation; either version 2\r
+  * of the License, or (at your option) any later version.\r
+  * \r
+  * This program is distributed in the hope that it will be useful,\r
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+  * GNU General Public License for more details.\r
+  * \r
+  * You should have received a copy of the GNU General Public License\r
+  * along with this program; if not, write to the Free Software\r
+  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA\r
+  * \r
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives\r
+  * permission to link the code of this program with those files in the PEAR\r
+  * library that are licensed under the PHP License (or with modified versions\r
+  * of those files that use the same license as those files), and distribute\r
+  * linked combinations including the two. You must obey the GNU General Public\r
+  * License in all respects for all of the code used other than those files in\r
+  * the PEAR library that are licensed under the PHP License. If you modify\r
+  * this file, you may extend this exception to your version of the file,\r
+  * but you are not obligated to do so. If you do not wish to do so, delete\r
+  * this exception statement from your version.\r
+*/\r
+\r
+if (!function_exists('getLanguageName')){\r
+       function getLanguageName(){\r
+               return 'japanese-utf8';\r
+       }\r
+}\r
+\r
+class cles_Template {\r
+       var $defaultLang = 'japanese-utf8';\r
+       var $defalutPattern = '#{{(.*?)(\|)?}}#ie';\r
+       var $lang;\r
+       var $templateDir;\r
+\r
+       function cles_Template($templateDir) {\r
+               global $CONF;\r
+               $this->templateDir = $templateDir;\r
+               $this->lang = ereg_replace( '[\\|/]', '', getLanguageName());\r
+       }\r
+\r
+       function fetch($name, $dir = null, $suffix = 'html') {\r
+               $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->lang.( $suffix ? '.'.strtolower($suffix) : '' );\r
+               if ( ! file_exists($path) ){\r
+                       $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->defaultLang.( $suffix ? '.'.strtolower($suffix) : '' );\r
+                       if ( ! file_exists($path) )\r
+                               return '';\r
+               }\r
+               \r
+               $fsize = filesize($path);\r
+               if ($fsize <= 0) return '';\r
+               \r
+               $fd = fopen($path, 'r');\r
+               $contents = fread($fd, $fsize);\r
+               fclose($fd);\r
+               return $contents;\r
+       }\r
+       \r
+       function fill($template, $values, $default = null) {\r
+               if( $default )\r
+                       return preg_replace($this->defalutPattern, 'isset($values[\'$1\']) ? (\'$2\' ? htmlspecialchars($values[\'$1\'], ENT_QUOTES) : $values[\'$1\']) : $default', $template);\r
+               if( $default === null )\r
+                       return preg_replace($this->defalutPattern, '(\'$2\') ? htmlspecialchars($values[\'$1\'], ENT_QUOTES) : $values[\'$1\']', $template);\r
+               return preg_replace($this->defalutPattern, 'isset($values[\'$1\']) ? (\'$2\' ? htmlspecialchars($values[\'$1\'], ENT_QUOTES) : $values[\'$1\']) : \'{{$1}}\' ', $template);\r
+       }\r
+       \r
+       function fetchAndFill($name, $values, $dir = null, $suffix = 'html', $default = null){\r
+               $tpl = $this->fetch($name, $dir, $suffix);\r
+               return $this->fill($tpl, $values, $default);\r
+       }\r
+}\r