OSDN Git Service

MERGE: リビジョン1818。Parserクラスのコンストラクタを変更。BaseActions派生クラスのメソッド名を変更
authorsakamocchi <o-takashi@sakamocchi.jp>
Thu, 3 May 2012 04:25:55 +0000 (13:25 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Thu, 3 May 2012 04:25:55 +0000 (13:25 +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/bookmarklet.php
nucleus/libs/ACTIONS.php
nucleus/libs/ADMIN.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/PAGEFACTORY.php
nucleus/libs/PARSER.php
nucleus/libs/SKIN.php

index 41a8755..6278c97 100644 (file)
@@ -298,7 +298,7 @@ function bm_doShowForm()
        $contents = $handler->getTemplateFor('bookmarklet', 'add');
        $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog));
        
-       $parser = new Parser($handler->getDefinedActions(), $handler);
+       $parser = new Parser($handler);
        $parser->parse($contents);
        
        return;
@@ -336,7 +336,7 @@ function bm_doEditForm()
        
        $contents = $handler->getTemplateFor('bookmarklet', 'edit');
        
-       $parser = new Parser($handler->getDefinedActions(), $handler);
+       $parser = new Parser($handler);
        $parser->parse($contents);
        
        return;
index c302f8d..d13813e 100644 (file)
@@ -13,9 +13,6 @@
  * This class contains the functions that get called by using
  * the special tags in the skins
  *
- * The allowed tags for a type of skinpart are defined by the
- * Skin::getAllowedActionsForType($type) method
- *
  * @license http://nucleuscms.org/license.txt GNU General Public License
  * @copyright Copyright (C) 2002-2012 The Nucleus Group
  * @version $Id: ACTIONS.php 1784 2012-04-22 04:28:30Z sakamocchi $
@@ -91,17 +88,50 @@ class Actions extends BaseActions
        );
        
        /**
-        * Actions::getDefinedActions()
+        * Actions::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;
+       }
+       
+       /**
+        * Actions::__construct()
+        * Constructor for a new Actions object
+        * 
+        * @param       string  $type
+        * @return      void
+        */
+       public function __construct($type)
+       {
+               global $catid;
+               
+               // call constructor of superclass first
+               parent::__construct();
+               $this->skintype = $type;
+               
+               if ( $catid )
+               {
+                       $this->linkparams = array('catid' => $catid);
+               }
+               return;
+       }
+       
+       /**
+        * Actions::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 'index':
                                $extra_actions = array(
@@ -226,41 +256,7 @@ class Actions extends BaseActions
                
                $defined_actions = array_merge(self::$default_actions, $extra_actions);
                
-               return array_merge($defined_actions, parent::getDefinedActions());
-       }
-       
-       /**
-        * Actions::getDefaultSkinTypes()
-        * 
-        * @static
-        * @param       void
-        * @return      array   list of friendly names for page actions
-        */
-       static public function getDefaultSkinTypes()
-       {
-               return self::$default_skin_types;
-       }
-       
-       /**
-        * Actions::__construct()
-        * Constructor for a new Actions object
-        * 
-        * @param       string  $type
-        * @return      void
-        */
-       public function __construct($type)
-       {
-               global $catid;
-               
-               // call constructor of superclass first
-               parent::__construct();
-               $this->skintype = $type;
-               
-               if ( $catid )
-               {
-                       $this->linkparams = array('catid' => $catid);
-               }
-               return;
+               return array_merge($defined_actions, parent::getAvailableActions());
        }
        
        /**
@@ -1254,16 +1250,17 @@ class Actions extends BaseActions
        public function parse_comments($template)
        {
                global $itemid, $manager, $blog, $highlight;
+               
                $template =& $manager->getTemplate($template);
+               $item = Item::getitem($itemid, 0, 0);
                
                // create parser object & action handler
                $handler = new ItemActions($blog);
-               $parser = new Parser($handler->getDefinedActions(),$handler);
                $handler->setTemplate($template);
-               $handler->setParser($parser);
-               $item = Item::getitem($itemid, 0, 0);
                $handler->setCurrentItem($item);
                
+               $parser = new Parser($handler);
+               
                $comments = new Comments($itemid);
                $comments->setItemActions($handler);
                // shows ALL comments
index ba622d4..0f2f91e 100644 (file)
@@ -1278,7 +1278,7 @@ class Admin
                $contents = $handler->getTemplateFor('admin', 'add');
                $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog));
                
-               $parser = new Parser($handler->getDefinedActions(), $handler);
+               $parser = new Parser($handler);
                
                $this->pagehead();
                $parser->parse($contents);
@@ -1319,7 +1319,7 @@ class Admin
                
                $content = $handler->getTemplateFor('admin', 'edit');
                
-               $parser = new Parser($handler->getDefinedActions(), $handler);
+               $parser = new Parser($handler);
                
                $this->pagehead();
                $parser->parse($content);
index bf9984d..52cf12a 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 = DB::getResult($query);\r
                \r
index e26b1ae..137af90 100644 (file)
@@ -44,6 +44,18 @@ class BodyActions extends BaseActions
        }
        
        /**
+        * BodyActions::getAvailableActions()
+        * Get the defined actions in an item
+        * 
+        * @param       void
+        * @return      array   self::$defined_actions
+        */
+       public function getAvailableActions()
+       {
+               return array_merge(self::$defined_actions, parent::getAvailableActions());
+       }
+       
+       /**
         * BodyActions::setCurrentItem()
         * Set the current item
         * 
@@ -72,19 +84,6 @@ class BodyActions extends BaseActions
        }
        
        /**
-        * BodyActions::getDefinedActions()
-        * Get the defined actions in an item
-        * 
-        * @static
-        * @param       void
-        * @return      Array   self::$defined_actions
-        */
-       static public function getDefinedActions()
-       {
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
-       }
-       
-       /**
         * BodyActions::parse_plugin()
         * Parse a plugin var
         * Called if <%plugin(...)%> in an item appears
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 7bd116a..b320145 100644 (file)
@@ -88,15 +88,14 @@ class CommentActions extends BaseActions
        }
        
        /**
-        * CommentActions::getDefinedActions()
+        * CommentActions::getAvailableActions()
         * 
-        * @static
         * @param       void
         * @return array        actions array
         */
-       static public function getDefinedActions()
+       public function getAvailableActions()
        {
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
+               return array_merge(self::$defined_actions, parent::getAvailableActions());
        }
        
        /**
index db3b4ec..851080d 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 d2fd5c1..9aa96d4 100644 (file)
@@ -129,17 +129,16 @@ class ItemActions extends BaseActions
        }
        
        /**
-        * ItemActions::getDefinedActions()
+        * ItemActions::getAvailableActions()
         * Returns an array with the actions that are defined
         * in the ItemActions class
         * 
-        * @static
         * @param       void
         * @return      void
         */
-       static public function getDefinedActions()
+       public function getAvailableActions()
        {
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
+               return array_merge(self::$defined_actions, parent::getAvailableActions());
        }
        
        /**
@@ -813,10 +812,11 @@ class ItemActions extends BaseActions
        public function highlightAndParse(&$data)
        {
                $handler = new BodyActions($this->blog);
-               $parser = new Parser($handler->getDefinedActions(), $handler);
                $handler->setTemplate($this->template);
                $handler->setHighlight($this->strHighlight);
                $handler->setCurrentItem($this->currentItem);
+               
+               $parser = new Parser($handler);
                $parser->parse($handler->highlight($data));
                return;
        }
index 35e325b..5c488b0 100644 (file)
@@ -30,7 +30,7 @@ class PageFactory extends BaseActions
        
        /**
         * PageFactory::$type
-        * One of the types got by self::getDefaultSkinTypes()
+        * One of the types got by self::getAvailableSkinTypes()
         */
        private $type = '';
        
@@ -78,26 +78,13 @@ class PageFactory extends BaseActions
        );
        
        /**
-        * PageFactory::getDefinedActions()
-        * 
-        * @static
-        * @param       void
-        * @return      array   array for defined action names
-        * 
-        */
-       static public function getDefinedActions($type='')
-       {
-               return array_merge(self::$defined_actions, parent::getDefinedActions());
-       }
-       
-       /**
         * AdminActions::getSkinTypeFriendlyNames()
         * 
         * @static
         * @param       void
         * @return      array   list of friendly names for page actions
         */
-       static public function getDefaultSkinTypes()
+       static public function getAvailableSkinTypes()
        {
                return self::$default_skin_types;
        }
@@ -121,6 +108,18 @@ class PageFactory extends BaseActions
        }
        
        /**
+        * PageFactory::getAvailableActions()
+        * 
+        * @param       void
+        * @return      array   array for defined action names
+        * 
+        */
+       public function getAvailableActions()
+       {
+               return array_merge(self::$defined_actions, parent::getAvailableActions());
+       }
+       
+       /**
         * PageFactory::setVariables()
         * 
         * @param       array   $variables      associated array for item data
@@ -145,7 +144,7 @@ class PageFactory extends BaseActions
                global $DIR_LIBS;
                
                // the $type is not in the allowed types array
-               if ( !array_key_exists($type, $this->getDefaultSkinTypes()) )
+               if ( !array_key_exists($type, $this->getAvailableSkinTypes()) )
                {
                        return '';
                }
index 14181ac..96c3141 100644 (file)
@@ -47,18 +47,20 @@ class Parser
         * Creates a new parser object with the given allowed actions
         * and the given handler
         *
-        * @param $allowedActions array
         * @param $handler class object with functions for each action (reference)
         * @param $delim optional delimiter
         * @param $paramdelim optional parameterdelimiter
         */
-       public function __construct($allowedActions, &$handler, $delim = '(<%|%>)', $pdelim = ',')
+       public function __construct( &$handler, $delim = '(<%|%>)', $pdelim = ',')
        {
-               $this->actions  = $allowedActions;
-               $this->handler  =& $handler;
-               $this->delim    = $delim;
-               $this->pdelim   = $pdelim;
+               $this->handler  = &$handler;
+               $this->actions  =  $handler->getAvailableActions();
+               $this->delim    =  $delim;
+               $this->pdelim   =  $pdelim;
                $this->norestrictions = 0;      // set this to 1 to disable checking for allowedActions
+               
+               $handler->setParser($this);
+               
                return;
        }
        
index 4925961..46dbfe1 100644 (file)
@@ -372,13 +372,10 @@ class Skin
                // call action handler
                $action_class = $this->action_class;
                $handler = new $action_class($type);
+               $handler->setSkin($this);
                
                // register action handler to parser
-               $actions = $handler->getDefinedActions($type);
-               $parser = new Parser($actions, $handler);
-               
-               $handler->setParser($parser);
-               $handler->setSkin($this);
+               $parser = new Parser($handler);
                $parser->parse($contents);
                
                $data = array(
@@ -623,7 +620,7 @@ class Skin
         */
        public function getDefaultTypes()
        {
-               return call_user_func(array($this->action_class, 'getDefaultSkinTypes'));
+               return call_user_func(array($this->action_class, 'getAvailableSkinTypes'));
        }
        
        /**
@@ -663,12 +660,13 @@ class Skin
         * Get the allowed actions for a skin type
         * returns an array with the allowed actions
         * 
-        * @param       string  $type   type of the skin
+        * @param       string  $skintype       type of the skin
         * @return      array   allowed action types
         */
-       public function getAllowedActionsForType($type)
+       public function getAllowedActionsForType($skintype)
        {
-               return call_user_func(array($this->action_class, 'getDefinedActions'), $type);
+               $handler = new $this->action_class($skintype);
+               return $handler->getAvailableActions();
        }
        
 }