OSDN Git Service

MERGE: リビジョン1818。Parserクラスのコンストラクタを変更。BaseActions派生クラスのメソッド名を変更
authorsakamocchi <o-takashi@sakamocchi.jp>
Thu, 3 May 2012 06:21:20 +0000 (15:21 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Thu, 3 May 2012 06:21:20 +0000 (15:21 +0900)
Parser::__construct()でBaseActions派生クラスのsetParser()を実行し、自身を登録するように変更。これに伴い、Parserクラスのインスタンスを作成する処理が変更となった。

また、BaseActions派生クラスのメソッド名も以下のように変更した。
・getDefaultSkinTypes()をgetAvailableSkinTypes()に
・getDefinedActions()をgetAvailableActions()に

Revision 1818:
CHANGE: constructor of Parser class, method names of BaseActions-derived
classes

Now Parser class set itself into BaseActions-derived class as $parser
calling setParser() within its constructor.

And rename two methods of  BaseActions-derived class:
getDefaultSkinTypes() to getAvailableSkinTypes()
getDefinedActions() to getAvailableActions()
http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1818

12 files changed:
nucleus/libs/ACTIONS.php
nucleus/libs/ADMIN.php
nucleus/libs/AdminActions.php
nucleus/libs/BLOG.php
nucleus/libs/BODYACTIONS.php
nucleus/libs/BaseActions.php
nucleus/libs/COMMENTACTIONS.php
nucleus/libs/COMMENTS.php
nucleus/libs/ITEMACTIONS.php
nucleus/libs/PARSER.php
nucleus/libs/SKIN.php
nucleus/libs/showlist.php

index be4c10f..5d5bc48 100644 (file)
@@ -13,9 +13,6 @@
  * This class contains the functions that get called by using\r
  * the special tags in the skins\r
  *\r
- * The allowed tags for a type of skinpart are defined by the\r
- * Skin::getAllowedActionsForType($type) method\r
- *\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
  * @version $Id: ACTIONS.php 1784 2012-04-22 04:28:30Z sakamocchi $\r
@@ -91,17 +88,50 @@ class Actions extends BaseActions
        );\r
        \r
        /**\r
-        * Actions::getDefinedActions()\r
+        * Actions::getAvailableSkinTypes()\r
         * \r
         * @static\r
-        * @param       string  $type   page type\r
+        * @param       void\r
+        * @return      array   list of friendly names for page actions\r
+        */\r
+       static public function getAvailableSkinTypes()\r
+       {\r
+               return self::$default_skin_types;\r
+       }\r
+       \r
+       /**\r
+        * Actions::__construct()\r
+        * Constructor for a new Actions object\r
+        * \r
+        * @param       string  $type\r
+        * @return      void\r
+        */\r
+       public function __construct($type)\r
+       {\r
+               global $catid;\r
+               \r
+               // call constructor of superclass first\r
+               parent::__construct();\r
+               $this->skintype = $type;\r
+               \r
+               if ( $catid )\r
+               {\r
+                       $this->linkparams = array('catid' => $catid);\r
+               }\r
+               return;\r
+       }\r
+       \r
+       /**\r
+        * Actions::getAvailableActions()\r
+        * \r
+        * @param       void\r
         * @return      array   allowed actions for the page type\r
         */\r
-       static public function getDefinedActions($type='')\r
+       public function getAvailableActions()\r
        {\r
                $extra_actions = array();\r
                \r
-               switch ( $type )\r
+               switch ( $this->skintype )\r
                {\r
                        case 'index':\r
                                $extra_actions = array(\r
@@ -226,41 +256,7 @@ class Actions extends BaseActions
                \r
                $defined_actions = array_merge(self::$default_actions, $extra_actions);\r
                \r
-               return array_merge($defined_actions, parent::getDefinedActions());\r
-       }\r
-       \r
-       /**\r
-        * Actions::getDefaultSkinTypes()\r
-        * \r
-        * @static\r
-        * @param       void\r
-        * @return      array   list of friendly names for page actions\r
-        */\r
-       static public function getDefaultSkinTypes()\r
-       {\r
-               return self::$default_skin_types;\r
-       }\r
-       \r
-       /**\r
-        * Actions::__construct()\r
-        * Constructor for a new Actions object\r
-        * \r
-        * @param       string  $type\r
-        * @return      void\r
-        */\r
-       public function __construct($type)\r
-       {\r
-               global $catid;\r
-               \r
-               // call constructor of superclass first\r
-               parent::__construct();\r
-               $this->skintype = $type;\r
-               \r
-               if ( $catid )\r
-               {\r
-                       $this->linkparams = array('catid' => $catid);\r
-               }\r
-               return;\r
+               return array_merge($defined_actions, parent::getAvailableActions());\r
        }\r
        \r
        /**\r
@@ -1254,16 +1250,17 @@ class Actions extends BaseActions
        public function parse_comments($template)\r
        {\r
                global $itemid, $manager, $blog, $highlight;\r
+               \r
                $template =& $manager->getTemplate($template);\r
+               $item = Item::getitem($itemid, 0, 0);\r
                \r
                // create parser object & action handler\r
                $handler = new ItemActions($blog);\r
-               $parser = new Parser($handler->getDefinedActions(),$handler);\r
                $handler->setTemplate($template);\r
-               $handler->setParser($parser);\r
-               $item = Item::getitem($itemid, 0, 0);\r
                $handler->setCurrentItem($item);\r
                \r
+               $parser = new Parser($handler);\r
+               \r
                $comments = new Comments($itemid);\r
                $comments->setItemActions($handler);\r
                // shows ALL comments\r
index 26f0fe2..0b988e3 100644 (file)
@@ -236,7 +236,7 @@ class Admin
                }\r
                elseif ( method_exists('Admin', $methodName) )\r
                {\r
-                       call_user_func(array(self, $methodName));\r
+                       call_user_func(array(__CLASS__, $methodName));\r
                }\r
                else if ( self::existsSkinContents('adminerrorpage') )\r
                {\r
@@ -5959,9 +5959,9 @@ class Admin
                        $actions = array_merge($actions, self::$skin->getAllowedActionsForType($type));\r
                }\r
                \r
-               $parser = new Parser($actions, $handler);\r
-               $handler->setParser($parser);\r
                $handler->setSkin(self::$skin);\r
+               \r
+               $parser = new Parser($handler);\r
                $parser->parse($contents);\r
                \r
                if ( $type == 'pagefoot' )\r
@@ -6073,12 +6073,11 @@ class Admin
                \r
                self::$skin                             = (object) $skn;\r
                $handler = new AdminActions($actnName, self::$skin, $this);\r
-               $actions = Skin::getAllowedActionsForType($actnName);\r
-               \r
-               $parser = new PARSER($actions, $handler);\r
-               $handler->setParser($parser);\r
                $handler->setSkin(self::$skin);\r
+               \r
+               $parser = new PARSER($handler);\r
                $parser->parse($contents);\r
+               \r
                return;\r
        }\r
        \r
index 7bd1d23..22e99bb 100644 (file)
@@ -10,10 +10,6 @@ class AdminActions extends BaseActions
        // reference to the skin object for which a part is being parsed
        private $skin;
        
-       // an instance of parser class
-//     private $parser;
-       protected $parser;
-       
        private $skintype;
        
        /* NOTE: list of whole available action names for tags
@@ -230,17 +226,60 @@ class AdminActions extends BaseActions
        );
        
        /**
-        * AdminActions::getDefinedActions()
+        * AdminActions::getAvailableSkinTypes()
         * 
         * @static
-        * @param       string  $type   page type
+        * @param       void
+        * @return      array   list of friendly names for page actions
+        */
+       static public function getAvailableSkinTypes()
+       {
+               return self::$default_skin_types;
+       }
+       
+       /**
+        * AdminActions::getDefaultTypes()
+        *
+        * @static
+        * @param       void
+        * @return      array   list of friendly names for page actions
+        */
+       static public function getDefaultTypes()
+       {
+               return self::$default_skin_types;
+       }
+       
+       /**
+        * AdminActions::__construct()
+        * Constructor for a new Actions object
+        * 
+        * @param       string  $type
+        * @return      void
+        */
+       public function __construct($type)
+       {
+               // call constructor of superclass first
+               parent::__construct();
+               $this->skintype = $type;
+               if ( !class_exists('Navlist') || !class_exists('Batch') )
+               {
+                       global $DIR_LIBS;
+                       include $DIR_LIBS . 'ENCAPSULATE.php';
+               }
+               return;
+       }
+       
+       /**
+        * AdminActions::getAvailableActions()
+        * 
+        * @param       void
         * @return      array   allowed actions for the page type
         */
-       static public function getDefinedActions($type = '')
+       public function getAvailableActions()
        {
                $extra_actions = array();
                
-               switch ( $type )
+               switch ( $this->skintype )
                {
                        case 'actionlog':
                                $extra_actions = array(
@@ -737,51 +776,7 @@ class AdminActions extends BaseActions
                
                $defined_actions = array_merge(self::$default_actions, $extra_actions);
                
-               return array_merge($defined_actions, parent::getDefinedActions());
-       }
-       
-       /**
-        * AdminActions::getDefaultSkinTypes()
-        * 
-        * @static
-        * @param       void
-        * @return      array   list of friendly names for page actions
-        */
-       static public function getDefaultSkinTypes()
-       {
-               return self::$default_skin_types;
-       }
-       
-       /**
-        * AdminActions::getDefaultTypes()
-        *
-        * @static
-        * @param       void
-        * @return      array   list of friendly names for page actions
-        */
-       static public function getDefaultTypes()
-       {
-               return self::$default_skin_types;
-       }
-       
-       /**
-        * AdminActions::__construct()
-        * Constructor for a new Actions object
-        * 
-        * @param       string  $type
-        * @return      void
-        */
-       public function __construct($type)
-       {
-               // call constructor of superclass first
-               parent::__construct();
-               $this->skintype = $type;
-               if ( !class_exists('Navlist') || !class_exists('Batch') )
-               {
-                       global $DIR_LIBS;
-                       include $DIR_LIBS . 'ENCAPSULATE.php';
-               }
-               return;
+               return array_merge($defined_actions, parent::getAvailableActions());
        }
        
        /**
@@ -797,19 +792,6 @@ class AdminActions extends BaseActions
        }
        
        /**
-        * AdminActions::setParser()
-        * Set the parser
-        * 
-        * @param       object  $parser an instance of Parser class
-        * @return      void
-        */
-       public function setParser(&$parser)
-       {
-               $this->parser =& $parser;
-               return;
-       }
-       
-       /**
         * AdminActions::parse_actionloglist()
         * Parse skinvar actionloglist
         * 
@@ -2358,7 +2340,8 @@ class AdminActions extends BaseActions
                                          . "<%name%></a> <%help%></li>\n";
                }
                $handler = new Actions('template', $template, new ADMIN);
-               $parser  = new PARSER(Actions::getDefinedActions(), $handler);
+               
+               $parser = new PARSER($handler);
                
                foreach ( $types as $type => $fName )
                {
@@ -3664,7 +3647,9 @@ class AdminActions extends BaseActions
                foreach ( $options as $option )
                {
                        $handler = new Actions($this->skintype, $template, $option);
-                       $parser  = new PARSER(Actions::getDefinedActions(), $handler);
+                       
+                       $parser = new PARSER($handler);
+                       
                        // new plugin?
                        if ( $prevPid != $option['pid'] )
                        {
@@ -4377,8 +4362,9 @@ class AdminActions extends BaseActions
                        {
                                $template['title'] = '<h2><%text(_QMENU_PLUGINS)%></h2>';
                        }
-                       $handler = new Actions($this->skintype, $template, $this->objAdmin);
-                       $parser  = new PARSER(Actions::getDefinedActions(), $handler);
+                       $handler = new Actions($this->skintype);
+                       
+                       $parser = new PARSER($handler);
                        $parser->parse($template['title']);
                        
                        if ( array_key_exists('PLUGIN_QUICKMENU_HEAD', $templates) || !empty($templates['PLUGIN_QUICKMENU_HEAD']) )
index d57a1ac..c6c6a1d 100644 (file)
@@ -187,13 +187,13 @@ class Blog
                \r
                // create parser object & action handler\r
                $handler = new ItemActions($this);\r
-               $parser = new Parser($handler->getDefinedActions(), $handler);\r
                $handler->setTemplate($template);\r
                $handler->setHighlight($highlight);\r
                $handler->setLastVisit($lastVisit);\r
-               $handler->setParser($parser);\r
                $handler->setShowComments($comments);\r
                \r
+               $parser = new Parser($handler);\r
+               \r
                // execute query\r
                $items = sql_query($query);\r
                \r
index 01d3c3d..e9db97a 100644 (file)
@@ -44,6 +44,18 @@ class BodyActions extends BaseActions
        }\r
        \r
        /**\r
+        * BodyActions::getAvailableActions()\r
+        * Get the defined actions in an item\r
+        * \r
+        * @param       void\r
+        * @return      array   self::$defined_actions\r
+        */\r
+       public function getAvailableActions()\r
+       {\r
+               return array_merge(self::$defined_actions, parent::getAvailableActions());\r
+       }\r
+       \r
+       /**\r
         * BodyActions::setCurrentItem()\r
         * Set the current item\r
         * \r
@@ -72,19 +84,6 @@ class BodyActions extends BaseActions
        }\r
        \r
        /**\r
-        * BodyActions::getDefinedActions()\r
-        * Get the defined actions in an item\r
-        * \r
-        * @static
-        * @param       void\r
-        * @return      Array   self::$defined_actions\r
-        */\r
-       static public function getDefinedActions()
-       {\r
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
-       }\r
-       \r
-       /**\r
         * BodyActions::parse_plugin()\r
         * Parse a plugin var\r
         * Called if <%plugin(...)%> in an item appears\r
index 00f6c2e..a949f82 100644 (file)
@@ -88,13 +88,12 @@ class BaseActions
        }
        
        /**
-        * BaseActions::getDefinedActions()
+        * BaseActions::getAvailableActions()
         * 
-        * @static
         * @param       void
         * @return      void
         */
-       static public function getDefinedActions()
+       public function getAvailableActions()
        {
                return self::$defined_actions;
        }
index 850772a..b41870d 100644 (file)
@@ -88,15 +88,14 @@ class CommentActions extends BaseActions
        }\r
        \r
        /**\r
-        * CommentActions::getDefinedActions()\r
+        * CommentActions::getAvailableActions()\r
         * \r
-        * @static
         * @param       void\r
         * @return array        actions array\r
         */\r
-       static public function getDefinedActions()
+       public function getAvailableActions()\r
        {\r
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
+               return array_merge(self::$defined_actions, parent::getAvailableActions());\r
        }\r
        \r
        /**\r
index fb18a44..751ae33 100644 (file)
@@ -72,10 +72,10 @@ class Comments
 \r
                // create parser object & action handler\r
                $handler = new CommentActions($this);\r
-               $parser = new Parser($handler->getDefinedActions(),$handler);\r
                $handler->setTemplate($template);\r
-               $handler->setParser($parser);\r
-\r
+               \r
+               $parser = new Parser($handler);\r
+               \r
                if ($maxToShow == 0) {\r
                        $this->commentcount = $this->amountComments();\r
                } else {\r
index 1a45013..81afd2c 100644 (file)
@@ -128,17 +128,16 @@ class ItemActions extends BaseActions
        }\r
        \r
        /**\r
-        * ItemActions::getDefinedActions()\r
+        * ItemActions::getAvailableActions()\r
         * Returns an array with the actions that are defined\r
         * in the ItemActions class\r
         * \r
-        * @static
         * @param       void\r
         * @return      void\r
         */\r
-       static public function getDefinedActions()
+       public function getAvailableActions()\r
        {\r
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
+               return array_merge(self::$defined_actions, parent::getAvailableActions());\r
        }\r
        \r
        /**\r
@@ -816,10 +815,11 @@ class ItemActions extends BaseActions
        public function highlightAndParse(&$data)\r
        {\r
                $handler = new BodyActions($this->blog);
-               $parser = new Parser($handler->getDefinedActions(), $handler);
                $handler->setTemplate($this->template);
                $handler->setHighlight($this->strHighlight);
                $handler->setCurrentItem($this->currentItem);
+               \r
+               $parser = new Parser($handler);\r
                $parser->parse($handler->highlight($data));
                return;\r
        }\r
index 390ed31..2c2dd73 100644 (file)
@@ -47,18 +47,20 @@ class Parser
         * 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
-       public function __construct($allowedActions, &$handler, $delim = '(<%|%>)', $pdelim = ',')\r
+       public function __construct( &$handler, $delim = '(<%|%>)', $pdelim = ',')\r
        {\r
-               $this->actions  = $allowedActions;\r
-               $this->handler  =& $handler;\r
-               $this->delim    = $delim;\r
-               $this->pdelim   = $pdelim;\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
+               $handler->setParser($this);\r
+               \r
                return;\r
        }\r
        \r
index 47ac99d..c873d4e 100644 (file)
@@ -282,16 +282,14 @@ class Skin
        {\r
                global $manager;\r
                \r
-               $manager->notify(\r
-                       'PreAddSkin',\r
-                       array(\r
+               $data = array(
                                'name' => &$name,\r
                                'description' => &$desc,\r
                                'type' => &$type,\r
                                'includeMode' => &$includeMode,\r
                                'includePrefix' => &$includePrefix\r
-                       )\r
                );\r
+               $manager->notify('PreAddSkin', $data);
                \r
                $query = "INSERT INTO %s (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('%s', '%s', '%s', '%s', '%s');";\r
                $sdname         = sql_real_escape_string($name);\r
@@ -303,17 +301,16 @@ class Skin
                sql_query($query);\r
                $newid = sql_insert_id();\r
                \r
-               $manager->notify(\r
-                       'PostAddSkin',\r
-                       array(\r
+               $data = array(
                                'skinid'                => $newid,\r
                                'name'                  => $name,\r
                                'description'   => $desc,\r
                                'type'                  => $type,\r
                                'includeMode'   => $includeMode,\r
                                'includePrefix' => $includePrefix\r
-                       )\r
                );\r
+               $manager->notify('PostAddSkin', $data);
+               
                return $newid;\r
        }\r
        \r
@@ -329,7 +326,11 @@ class Skin
        {\r
                global $currentSkinName, $manager, $CONF, $DIR_NUCLEUS;\r
                \r
-               $manager->notify("Init{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));\r
+               $data = array(
+                       'skin' => &$this,
+                       'type' => $type
+               );
+               $manager->notify("Init{$this->event_identifier}Parse", $data);
                \r
                // include skin locale file for <%text%> tag if useable\r
                $this->includeTranslation();\r
@@ -362,7 +363,12 @@ class Skin
                        }\r
                }\r
                \r
-               $manager->notify("Pre{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type, 'contents' => &$contents));\r
+               $data = array(
+                       'skin'          => &$this,
+                       'type'          => $type,
+                       'contents'      => &$contents
+               );
+               $manager->notify("Pre{$this->event_identifier}Parse", $data);
                \r
                // set IncludeMode properties of parser\r
                Parser::setProperty('IncludeMode', $this->getIncludeMode());\r
@@ -371,16 +377,18 @@ class Skin
                // call action handler\r
                $action_class = $this->action_class;\r
                $handler = new $action_class($type);\r
+               $handler->setSkin($this);\r
                \r
                // register action handler to parser\r
-               $actions = $handler->getDefinedActions($type);\r
-               $parser = new Parser($actions, $handler);\r
-               \r
-               $handler->setParser($parser);\r
-               $handler->setSkin($this);\r
+               $parser = new Parser($handler);\r
                $parser->parse($contents);\r
                \r
-               $manager->notify("Post{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));\r
+               $data = array(
+                       'skin' => &$this,
+                       'type' => $type
+               );
+               $manager->notify("Post{$this->event_identifier}Parse", $data);
+               
                return;\r
        }\r
        \r
@@ -622,7 +630,7 @@ class Skin
         */\r
        public function getDefaultTypes()\r
        {\r
-               return call_user_func(array($this->action_class, 'getDefaultSkinTypes'));\r
+               return call_user_func(array($this->action_class, 'getAvailableSkinTypes'));\r
        }\r
        \r
        /**\r
@@ -662,12 +670,13 @@ class Skin
         * Get the allowed actions for a skin type\r
         * returns an array with the allowed actions\r
         * \r
-        * @param       string  $type   type of the skin\r
+        * @param       string  $skintype       type of the skin\r
         * @return      array   allowed action types\r
         */\r
-       public function getAllowedActionsForType($type)\r
+       public function getAllowedActionsForType($skintype)\r
        {\r
-               return call_user_func(array($this->action_class, 'getDefinedActions'), $type);\r
+               $handler = new $this->action_class($skintype);\r
+               return $handler->getAvailableActions();\r
        }\r
        \r
 }\r
index 60d628e..2593c86 100644 (file)
@@ -136,9 +136,11 @@ function listplug_select($vars, $type, $templateName = '')
                include $DIR_LIBS . 'ACTIONS.php';\r
        }\r
        $template = Template::fill($template, $data);\r
-       $handler  = new Actions('template', $template, $data);\r
-       $parser   = new PARSER(Actions::getDefinedActions(), $handler);\r
+       $handler = new Actions('template', $template, $data);\r
+       \r
+       $parser = new Parser($handler);\r
        $parser->parse($template);\r
+       \r
        return;\r
 }\r
 \r
@@ -199,9 +201,12 @@ function listplug_table($vars, $type, $templateName = '')
                global $DIR_LIBS;\r
                include $DIR_LIBS . 'ACTIONS.php';\r
        }\r
-       $handler  = new Actions('template', $template, $data);\r
-       $parser   = new PARSER(Actions::getDefinedActions(), $handler);\r
+       \r
+       $handler = new Actions('template', $template, $data);\r
+       \r
+       $parser = new PARSER($handler);\r
        $parser->parse($template);\r
+       \r
        return;\r
 }\r
 \r