OSDN Git Service

REMOVE: Adminクラスの不要なメソッドを削除
[nucleus-jp/nucleus-next.git] / nucleus / libs / PARSER.php
index b523410..06f67cb 100644 (file)
 /**\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
  * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
- * @version $Id: PARSER.php 1529 2011-06-21 11:07:14Z sakamocchi $\r
+ * @version $Id: PARSER.php 1757 2012-04-15 09:02:32Z sakamocchi $\r
  */\r
 \r
-if ( !function_exists('requestVar') ) exit;\r
+if ( !function_exists('requestVar') )\r
+{\r
+       exit;\r
+}\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
+ * This is the parser class of Nucleus. It is used for various things\r
+ * (skin parsing, form generation, ...)\r
  */\r
 class Parser\r
 {\r
        // array with the names of all allowed actions\r
-       var $actions;\r
-\r
+       public $actions;\r
+       \r
        // reference to actions handler\r
-       var $handler;\r
-\r
+       public $handler;\r
+       \r
+       // reference to an instance of Skin class\r
+       public $skin = NULL;\r
+       \r
        // delimiters that can be used for skin/templatevars\r
-       var $delim;\r
-\r
+       public $delim;\r
+       \r
        // parameter delimiter (to separate skinvar params)\r
-       var $pdelim;\r
-\r
+       public $pdelim;\r
+       \r
        // usually set to 0. When set to 1, all skinvars are allowed regardless of $actions\r
-       var $norestrictions;\r
-\r
+       public $norestrictions;\r
+       \r
        /**\r
+        * Parset::__construct()\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
         */\r
-       function PARSER($allowedActions, &$handler, $delim = '(<%|%>)', $pdelim = ',') {\r
-               $this->actions = $allowedActions;\r
-               $this->handler =& $handler;\r
-               $this->delim = $delim;\r
-               $this->pdelim = $pdelim;\r
+       public function __construct( &$handler, $delim = '(<%|%>)', $pdelim = ',')\r
+       {\r
+               $this->handler  = &$handler;\r
+               $this->actions  =  $handler->getAvailableActions();\r
+               $this->delim    =  $delim;\r
+               $this->pdelim   =  $pdelim;\r
                $this->norestrictions = 0;      // set this to 1 to disable checking for allowedActions\r
+               \r
+               $this->skin             = NULL;\r
+               \r
+               $handler->setParser($this);\r
+               \r
+               return;\r
        }\r
-\r
+       \r
        /**\r
         * Parses the given contents and outputs it\r
         */\r
-       function parse(&$contents) {\r
-\r
-               $pieces = preg_split('/'.$this->delim.'/',$contents);\r
-\r
+       public function parse(&$contents)\r
+       {\r
+               /* escaping only pcre delimiter */\r
+               $pcre = preg_replace('#\##', '#', $this->delim);\r
+               \r
+               $pieces = preg_split("#{$pcre}#", $contents);\r
+               \r
                $maxidx = sizeof($pieces);\r
-               for ($idx = 0; $idx < $maxidx; $idx++) {\r
+               for ( $idx = 0; $idx < $maxidx; $idx++ )\r
+               {\r
                        echo $pieces[$idx];\r
                        $idx++;\r
-                       if ($idx < $maxidx) {\r
+                       if ( $idx < $maxidx )\r
+                       {\r
                                $this->doAction($pieces[$idx]);\r
                        }\r
                }\r
+               return;\r
        }\r
 \r
 \r
        /**\r
-         * Called from the parser to handle an action\r
-         * \r
-         * @param $action name of the action (e.g. blog, image ...)\r
-         */\r
-       function doAction($action) {\r
+        * Parset::doAction()\r
+        * Called from the parser to handle an action\r
+        * \r
+        * @param       string  $action name of the action (e.g. blog, image ...)\r
+        * @return      void\r
+        */\r
+       public function doAction($action)\r
+       {\r
                global $manager, $CONF;\r
 \r
-               if (!$action) return;\r
-\r
+               if ( !$action )\r
+               {\r
+                       return;\r
+               }\r
+               \r
                // split into action name + arguments\r
-               if (strstr($action,'(')) {\r
-                       $paramStartPos = i18n::strpos($action, '(');\r
-                       $params = i18n::substr($action, $paramStartPos + 1, i18n::strlen($action) - $paramStartPos - 2);\r
-                       $action = i18n::substr($action, 0, $paramStartPos);\r
-                       $params = preg_split ('#' . $this->pdelim . '#', $params);\r
-\r
-                       // trim parameters\r
-                       // for PHP versions lower than 4.0.6:\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
-               } else {\r
+               if ( i18n::strpos($action, '(') != FALSE )\r
+               {\r
+                       $paramStartPos  = i18n::strpos($action, '(');\r
+                       $params                 = i18n::substr($action, $paramStartPos + 1, i18n::strlen($action) - $paramStartPos - 2);\r
+                       $action                 = i18n::substr($action, 0, $paramStartPos);\r
+                       $params                 = preg_split ('#' . preg_quote($this->pdelim, '#') . '#', $params);\r
+                       $params                 = array_map('trim', $params);\r
+               }\r
+               else\r
+               {\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 != 'elseif') && ($actionlc != 'endif') && ($actionlc != 'ifnot') && ($actionlc != 'elseifnot') && (i18n::substr($actionlc,0,2) != 'if'))\r
+               $if_tags = array('else', 'elseif', 'endif', 'ifnot', 'elseifnot');\r
+               if ( !$this->handler->getTopIfCondition()\r
+                 && !in_array($actionlc, $if_tags)\r
+                 && (i18n::substr($actionlc, 0, 2) != 'if') )\r
+               {\r
                        return;\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
-                       //$this->call_using_array($action, $this->handler, $params);\r
-                       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
-                               $this->doAction('plugin('.$action.$this->pdelim.implode($this->pdelim,$params).')');\r
-                       } else {\r
-                               if ($CONF['DebugVars']==true) {\r
-                               echo '&lt;%' , $action , '(', implode($this->pdelim, $params), ')%&gt;';\r
                }\r
+               \r
+               if ( in_array($actionlc, $this->actions) || $this->norestrictions )\r
+               {\r
+                       call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params);\r
+               }\r
+               else\r
+               {\r
+                       // redirect to plugin action if possible\r
+                       if ( in_array('plugin', $this->actions) && $manager->pluginInstalled("NP_{$action}") )\r
+                       {\r
+                               $this->doAction('plugin(' . $action . $this->pdelim . implode($this->pdelim,$params) . ')');\r
+                       }\r
+                       else\r
+                       {\r
+                               if ( $CONF['DebugVars']==true )\r
+                               {\r
+                                       echo '&lt;%' , $action , '(', implode($this->pdelim, $params), ')%&gt;';\r
+                               }\r
                        }\r
-                       \r
                }\r
-\r
+               return;\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
-         */\r
-       function call_using_array($methodname, &$handler, $paramarray) {\r
-\r
-               $methodname = 'parse_' . $methodname;\r
-\r
-               if (!method_exists($handler, $methodname)) {\r
-                       return;\r
-               }\r
-\r
-               $command = 'call_user_func(array(&$handler,$methodname)';\r
-               for ($i = 0; $i<count($paramarray); $i++)\r
-                       $command .= ',$paramarray[' . $i . ']';\r
-               $command .= ');';\r
-               eval($command); // execute the correct method\r
+        * Parser::setSkin()\r
+        * Set the skin\r
+        * @param       object  $skin   an instance of Skin class\r
+        * @return      void\r
+        */\r
+       public function setSkin(&$skin)\r
+       {\r
+               $this->skin = &$skin;\r
+               return;\r
        }\r
-\r
+       \r
        /**\r
+        * Parser::setProperty()\r
         * Set a property of the parser in the manager\r
         * \r
-        * @param $property additional parser property (e.g. include prefix of the skin)\r
-        * @param $value new value\r
+        * @static\r
+        * @param       string  $property       additional parser property (e.g. include prefix of the skin)\r
+        * @param       string  $value          new value\r
+        * @return      void\r
         */\r
-       function setProperty($property, $value) {\r
+       static public function setProperty($property, $value)\r
+       {\r
                global $manager;\r
                $manager->setParserProperty($property, $value);\r
+               return;\r
        }\r
 \r
        /**\r
+        * Parser::getProperty()\r
         * Get a property of the parser from the manager\r
         * \r
-        * @param $name name of the property\r
+        * @static\r
+        * @param       string  $name   name of the property\r
+        * @return      string  value of the property\r
         */\r
-       function getProperty($name) {\r
+       static public function getProperty($name)\r
+       {\r
                global $manager;\r
                return $manager->getParserProperty($name);\r
        }\r
-\r
-\r
 }\r
-\r
-?>\r