OSDN Git Service

Completely delete $CONF['DisableEncodingCheck'] feature.
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / PARSER.php
index 1b3ea0d..cd14a3b 100755 (executable)
@@ -1,16 +1,24 @@
-<?php\r
-/**\r
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
-  * Copyright (C) 2002-2004 The Nucleus Group\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
-  * (see nucleus/documentation/index.html#license for more info)\r
-  *\r
-  */\r
\r
+<?php
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2009 The Nucleus Group
+ *
+ * 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.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+/**
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @version $Id$
+ * $NucleusJP: PARSER.php,v 1.7.2.1 2007/09/05 07:35:59 kimitake Exp $
+ */
+
+if ( !function_exists('requestVar') ) exit;\r
+require_once dirname(__FILE__) . '/BaseActions.php';\r
+\r
 /**\r
  * This is the parser class of Nucleus. It is used for various things (skin parsing,\r
  * form generation, ...)\r
@@ -19,27 +27,27 @@ class PARSER {
 \r
        // array with the names of all allowed actions\r
        var $actions;\r
-       \r
+\r
        // reference to actions handler\r
        var $handler;\r
-       \r
+\r
        // delimiters that can be used for skin/templatevars\r
        var $delim;\r
-       \r
+\r
        // parameter delimiter (to separate skinvar params)\r
        var $pdelim;\r
-       \r
+\r
        // usually set to 0. When set to 1, all skinvars are allowed regardless of $actions\r
        var $norestrictions;\r
-       \r
+\r
        /**\r
-        * Creates a new parser object with the given allowed actions \r
+        * Creates a new parser object with the given allowed actions\r
         * and the given handler\r
         *\r
         * @param $allowedActions array\r
         * @param $handler class object with functions for each action (reference)\r
         * @param $delim optional delimiter\r
-        * @param $paramdelim optional parameterdelimiter        \r
+        * @param $paramdelim optional parameterdelimiter\r
         */\r
        function PARSER($allowedActions, &$handler, $delim = '(<%|%>)', $pdelim = ',') {\r
                $this->actions = $allowedActions;\r
@@ -48,55 +56,57 @@ class PARSER {
                $this->pdelim = $pdelim;\r
                $this->norestrictions = 0;      // set this to 1 to disable checking for allowedActions\r
        }\r
-       \r
+\r
        /**\r
         * Parses the given contents and outputs it\r
         */\r
        function parse(&$contents) {\r
-       \r
+\r
                $pieces = preg_split('/'.$this->delim.'/',$contents);\r
-               \r
+\r
                $maxidx = sizeof($pieces);\r
-               for ($idx = 0;$idx<$maxidx;$idx++) {\r
-                       echo $pieces[$idx];             \r
+               for ($idx = 0; $idx < $maxidx; $idx++) {\r
+                       echo $pieces[$idx];\r
                        $idx++;\r
-                       $this->doAction($pieces[$idx]);\r
+                       if ($idx < $maxidx) {\r
+                               $this->doAction($pieces[$idx]);\r
+                       }\r
                }\r
        }\r
-       \r
+\r
 \r
        /**\r
-         * handle an action \r
+         * handle an action\r
          */\r
        function doAction($action) {\r
-               global $manager;\r
+               global $manager, $CONF;\r
 \r
                if (!$action) return;\r
-               \r
+\r
                // split into action name + arguments\r
                if (strstr($action,'(')) {\r
                        $paramStartPos = strpos($action, '(');\r
                        $params = substr($action, $paramStartPos + 1, strlen($action) - $paramStartPos - 2);\r
                        $action = substr($action, 0, $paramStartPos);\r
                        $params = explode ($this->pdelim, $params);\r
-                       \r
-                       // trim parameters \r
+\r
+                       // trim parameters\r
                        // for PHP versions lower than 4.0.6:\r
-                       //   - add // before '$params = ...' \r
+                       //   - add // before '$params = ...'\r
                        //   - remove // before 'foreach'\r
                        $params = array_map('trim',$params);\r
-                       // foreach ($params as $key => $value) { $params[$key] = trim($value); }                        \r
+                       // foreach ($params as $key => $value) { $params[$key] = trim($value); }\r
                } else {\r
                        // no parameters\r
                        $params = array();\r
                }\r
-       \r
+\r
                $actionlc = strtolower($action);\r
-               \r
+\r
                // skip execution of skinvars while inside an if condition which hides this part of the page\r
-               if (!$this->handler->if_currentlevel && ($actionlc != 'else') && ($actionlc != 'endif') && (substr($actionlc,0,2) != 'if'))\r
+               if (!$this->handler->if_currentlevel && ($actionlc != 'else') && ($actionlc != 'elseif') && ($actionlc != 'endif') && ($actionlc != 'ifnot') && ($actionlc != 'elseifnot') && (substr($actionlc,0,2) != 'if'))\r
                        return;\r
-       \r
+\r
                if (in_array($actionlc, $this->actions) || $this->norestrictions ) {\r
                        // when using PHP versions lower than 4.0.5, uncomment the line before\r
                        // and comment the call_user_func_array call\r
@@ -104,14 +114,18 @@ class PARSER {
                        call_user_func_array(array(&$this->handler,'parse_' . $actionlc), $params);\r
                } else {\r
                        // redirect to plugin action if possible\r
-                       if (in_array('plugin', $this->actions) && $manager->pluginInstalled('NP_'.$action))\r
+                       if (in_array('plugin', $this->actions) && $manager->pluginInstalled('NP_' . $action)) {\r
                                $this->doAction('plugin('.$action.$this->pdelim.implode($this->pdelim,$params).')');\r
-                       else\r
-                               echo '<b>DISALLOWED (' , $action , ')</b>';\r
+                       } else {\r
+                               if ($CONF['DebugVars']==true) {\r
+                                       echo '&lt;%' , $action , '(', implode($this->pdelim, $params), ')%&gt;';\r
+                               }\r
+                       }\r
+\r
                }\r
-               \r
+\r
        }\r
-       \r
+\r
        /**\r
          * Calls a method using an array of parameters (for use with PHP versions lower than 4.0.5)\r
          * ( = call_user_func_array() function )\r
@@ -119,7 +133,7 @@ class PARSER {
        function call_using_array($methodname, &$handler, $paramarray) {\r
 \r
                $methodname = 'parse_' . $methodname;\r
-               \r
+\r
                if (!method_exists($handler, $methodname)) {\r
                        return;\r
                }\r
@@ -130,230 +144,18 @@ class PARSER {
                $command .= ');';\r
                eval($command); // execute the correct method\r
        }\r
-       \r
+\r
        function setProperty($property, $value) {\r
                global $manager;\r
                $manager->setParserProperty($property, $value);\r
        }\r
-       \r
+\r
        function getProperty($name) {\r
                global $manager;\r
                return $manager->getParserProperty($name);\r
        }\r
-       \r
-       \r
-}\r
-\r
-/**\r
- * This class contains parse actions that are available in all ACTION classes\r
- * e.g. include, phpinclude, parsedinclude, skinfile, ...\r
- *\r
- * It should never be used on it's own\r
- */\r
-class BaseActions {\r
-       \r
-       // depth level for includes (max. level is 3)\r
-       var $level;\r
-       \r
-       // array of evaluated conditions (true/false). The element at the end is the one for the most nested\r
-       // if block.\r
-       var $if_conditions;\r
-       \r
-       // at all times, can be evaluated to either true if the current block needs to be displayed. This \r
-       // variable is used to decide to skip skinvars in parts that will never be outputted.\r
-       var $if_currentlevel;\r
-       \r
-       // contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight\r
-       var $strHighlight;\r
-       \r
-       // array of keywords that need to be highlighted in search results (see the highlight() \r
-       // and parseHighlight() methods)\r
-       var $aHighlight;\r
-       \r
-\r
-       // reference to the parser object that is using this object as actions-handler\r
-\r
-       var $parser;\r
-       \r
-\r
-       function BaseActions() {\r
-               $this->level = 0; \r
-               \r
-               // if nesting level\r
-               $this->if_conditions = array(); // array on which condition values are pushed/popped\r
-               $this->if_currentlevel = 1;             // 1 = current level is displayed; 0 = current level not displayed\r
-\r
-               // highlights           \r
-               $this->strHighlight = '';                       // full highlight\r
-               $this->aHighlight = array();            // parsed highlight\r
-               \r
-       }\r
 \r
-       // include file (no parsing of php)\r
-       function parse_include($filename) {\r
-               @readfile($this->getIncludeFileName($filename));\r
-       }\r
-       \r
-       // php-include file \r
-       function parse_phpinclude($filename) {\r
-               includephp($this->getIncludeFileName($filename));\r
-       }       \r
-       // parsed include\r
-       function parse_parsedinclude($filename) {\r
-               // check current level\r
-               if ($this->level > 3) return;   // max. depth reached (avoid endless loop)\r
-               $filename = $this->getIncludeFileName($filename);\r
-               if (!file_exists($filename)) return '';\r
-               \r
-               $fsize = filesize($filename);\r
-               \r
-               // nothing to include\r
-               if ($fsize <= 0)\r
-                       return;\r
-       \r
-               $this->level = $this->level + 1;        \r
-               \r
-               // read file \r
-               $fd = fopen ($filename, 'r');\r
-               $contents = fread ($fd, $fsize);\r
-               fclose ($fd);           \r
-               \r
-               // parse file contents\r
-               $this->parser->parse($contents);\r
-               \r
-               $this->level = $this->level - 1;                \r
-       }\r
-       \r
-       /**\r
-        * Returns the correct location of the file to be included, according to\r
-        * parser properties\r
-        *\r
-        * IF IncludeMode = 'skindir' => use skindir\r
-        */\r
-       function getIncludeFileName($filename) {\r
-               // leave absolute filenames and http urls as they are\r
-               if (\r
-                               (substr($filename,0,1) == '/')\r
-                       ||      (substr($filename,0,7) == 'http://')\r
-                       ||      (substr($filename,0,6) == 'ftp://')                     \r
-                       )\r
-                       return $filename;\r
-       \r
-               $filename = PARSER::getProperty('IncludePrefix') . $filename;\r
-               if (PARSER::getProperty('IncludeMode') == 'skindir') {\r
-                       global $DIR_SKINS;\r
-                       return $DIR_SKINS . $filename;\r
-               } else {\r
-                       return $filename;\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Inserts an url relative to the skindir (useful when doing import/export)\r
-        *\r
-        * e.g. <skinfile(default/myfile.sth)>\r
-        */\r
-       function parse_skinfile($filename) {\r
-               global $CONF;\r
-               \r
-               echo $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $filename;\r
-       }\r
-       \r
-       /**\r
-        * Sets a property for the parser\r
-        */\r
-       function parse_set($property, $value) {\r
-               PARSER::setProperty($property, $value);\r
-       }\r
-       \r
-       /**\r
-        * Helper function: add if condition\r
-        */\r
-       function _addIfCondition($condition) {\r
-       \r
-               array_push($this->if_conditions,$condition);\r
-       \r
-               $this->_updateTopIfCondition();\r
-                       \r
-               ob_start();             \r
-       }\r
-       \r
-       function _updateTopIfCondition() {\r
-               if (sizeof($this->if_conditions) == 0) \r
-                       $this->if_currentlevel = 1;\r
-               else\r
-                       $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1];\r
-       }\r
-       \r
-       /**\r
-        * returns the currently top if condition\r
-        */\r
-       function _getTopIfCondition() {\r
-               return $this->if_currentlevel;\r
-       }\r
-       \r
-       /**\r
-        * else\r
-        */\r
-       function parse_else() {\r
-               if (sizeof($this->if_conditions) == 0) return;\r
-               $old = $this->if_currentlevel;\r
-               if (array_pop($this->if_conditions)) {\r
-                       ob_end_flush();\r
-                       $this->_addIfCondition(0);\r
-               } else {\r
-                       ob_end_clean();\r
-                       $this->_addIfCondition(1);\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Ends a conditional if-block \r
-        * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY)\r
-        */\r
-       function parse_endif() {\r
-               // we can only close what has been opened\r
-               if (sizeof($this->if_conditions) == 0) return;\r
-               \r
-               if (array_pop($this->if_conditions)) {\r
-                       ob_end_flush();\r
-               } else {\r
-                       ob_end_clean();\r
-               }\r
-               \r
-               $this->_updateTopIfCondition();\r
-       }\r
-       \r
-       \r
-       /** \r
-        * Sets the search terms to be highlighted\r
-        *\r
-        * @param $highlight\r
-        *              A series of search terms\r
-        */\r
-       function setHighlight($highlight) {     \r
-               $this->strHighlight = $highlight;\r
-               if ($highlight) {\r
-                       $this->aHighlight = parseHighlight($highlight); \r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Applies the highlight to the given piece of text\r
-        *\r
-        * @param &$data\r
-        *              Data that needs to be highlighted\r
-        * @see setHighlight\r
-        */\r
-       function highlight(&$data) {\r
-               if ($this->aHighlight)\r
-                       return highlight($data,$this->aHighlight,$this->template['SEARCH_HIGHLIGHT']);\r
-               else\r
-                       return $data;\r
-       }\r
-       \r
-       \r
 \r
 }\r
\r
+\r
 ?>
\ No newline at end of file