OSDN Git Service

FIX: Skin::getFriendryName()と関係する箇所のコードを修正。Skin::$adminの廃止。
authorsakamocchi <o-takashi@sakamocchi.jp>
Sun, 8 Apr 2012 16:03:04 +0000 (01:03 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sun, 8 Apr 2012 16:03:04 +0000 (01:03 +0900)
Skin::getFriendryName()はstatic呼び出し専用のパブリックメソッドにも関わらず、内部ではインスタンス経由でオブジェクトのメンバーにアクセスしていた。この点を修正し、listplug_table_skinlist()はaction_skinoverview()で作られた$template経由でfriendly_names配列を受け取るようにした。listplug_table_adminskinlist()とそれを参照するメソッドも同様に実装するのが好ましい。

また、Skin::$adminを廃止し、Skin::$action_classとSkin::$event_identifierを新設。Actions/AdminActionsと同様の構造を持つアクションクラスのインスタンスをコンストラクタの引数に渡すようにした。

nucleus/libs/ADMIN.php
nucleus/libs/SKIN.php
nucleus/libs/showlist.php

index 0488734..f121248 100644 (file)
@@ -3284,8 +3284,9 @@ class Admin
                $query = 'SELECT * FROM '.sql_table('skin_desc').' ORDER BY sdname';
                $template['content'] = 'skinlist';
                $template['tabindex'] = 10;
+               $template['friendly_names'] = Skin::getFriendlyNames();
                showlist($query,'table',$template);
-
+               
                echo '<h3>' . _SKIN_NEW_TITLE . '</h3>';
 
                ?>
index d24d836..5923d1a 100644 (file)
@@ -35,24 +35,20 @@ class Skin
        private $includePrefix;\r
        private $name;\r
        \r
-       /* \r
-        * FIXME:\r
-        * whether to be used by Admin class or not\r
-        * the other way is preferrable instead of this\r
-        * for example, adding admindir to normal/skindir in nucleus_skin_desc.sdincmode \r
-        * \r
-        */\r
-       private $admin = FALSE;\r
+       /* action class */\r
+       private $action_class;\r
+       private $event_identifier;\r
        \r
        /**\r
         * Skin::__construct()\r
         * Constructor for a new SKIN object\r
         * \r
-        * @param       integer $id             id of the skin\r
-        * @param       boolean $admin  for admin pages or not\r
+        * @param       integer $id                                     id of the skin\r
+        * @param       string  $action_class           name of class extended from BaseActions\r
+        * @param       string  $event_identifier       event identifier. for example, InitAdminSkinParse if AdminSkin is used\r
         * @return      void\r
         */\r
-       public function __construct($id, $admin=FALSE)\r
+       public function __construct($id, $action_class='Actions', $event_identifier='Skin')\r
        {\r
                global $DIR_LIBS;\r
                \r
@@ -69,32 +65,37 @@ class Skin
                        return;\r
                }\r
                \r
-               $this->name = $obj->sdname;\r
-               $this->description = $obj->sddesc;\r
-               $this->contentType = $obj->sdtype;\r
-               $this->includeMode = $obj->sdincmode;\r
-               $this->includePrefix = $obj->sdincpref;\r
                /*\r
-                * FIXME: this key should be replaced by other way\r
-                * such that adding admin key into skin table and so on\r
+                * NOTE: include needed action class\r
                 */\r
-               if ( !$admin )\r
+               if ( $action_class != 'Actions' )\r
                {\r
-                       if ( !class_exists('Actions', FALSE) )\r
+                       if ( !class_exists($action_class, FALSE)\r
+                         && !file_exists("{$DIR_LIBS}{$action_class}.php")\r
+                         && !include("{$DIR_LIBS}{$action_class}.php") )\r
                        {\r
-                               include("{$DIR_LIBS}ACTIONS.php");\r
+                               return;\r
                        }\r
-                       $this->admin = FALSE;\r
                }\r
                else\r
                {\r
-                       if ( !class_exists('AdminActions', FALSE) )\r
+                       if ( !class_exists('Actions', FALSE)\r
+                         && !file_exists("{$DIR_LIBS}ACTIONS.php")\r
+                         && !include("{$DIR_LIBS}ACTIONS.php") )\r
                        {\r
-                               include("{$DIR_LIBS}AdminActions.php");\r
+                               return;\r
                        }\r
-                       $this->admin = TRUE;\r
                }\r
                \r
+               $this->action_class = $action_class;\r
+               $this->event_identifier = $event_identifier;\r
+               \r
+               $this->name = $obj->sdname;\r
+               $this->description = $obj->sddesc;\r
+               $this->contentType = $obj->sdtype;\r
+               $this->includeMode = $obj->sdincmode;\r
+               $this->includePrefix = $obj->sdincpref;\r
+               \r
                return;\r
        }\r
        \r
@@ -326,14 +327,7 @@ class Skin
        {\r
                global $currentSkinName, $manager, $CONF;\r
                \r
-               if ( !$this->admin )\r
-               {\r
-                       $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));\r
-               }\r
-               else\r
-               {\r
-                       $manager->notify('InitAdminSkinParse',array('skin' => &$this, 'type' => $type));\r
-               }\r
+               $manager->notify("Init{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));\r
                \r
                // set output type\r
                sendContentType($this->getContentType(), 'skin');\r
@@ -356,41 +350,21 @@ class Skin
                \r
                $actions = $this->getAllowedActionsForType($type);\r
                \r
-               if ( !$this->admin )\r
-               {\r
-                       $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));\r
-               }\r
-               else\r
-               {\r
-                       $manager->notify('PreAdminSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));\r
-               }\r
+               $manager->notify("Pre{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type, 'contents' => &$contents));\r
                \r
                // set IncludeMode properties of parser\r
                Parser::setProperty('IncludeMode', $this->getIncludeMode());\r
                Parser::setProperty('IncludePrefix', $this->getIncludePrefix());\r
                \r
-               if ( !$this->admin )\r
-               {\r
-                       $handler = new Actions($type);\r
-               }\r
-               else\r
-               {\r
-                       $handler = new AdminActions($type);\r
-               }\r
+               $action_class = $this->action_class;\r
+               $handler = new $action_class($type);\r
                \r
                $parser = new Parser($actions, $handler);\r
                $handler->setParser($parser);\r
                $handler->setSkin($this);\r
                $parser->parse($contents);\r
                \r
-               if ( !$this->admin )\r
-               {\r
-                       $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));\r
-               }\r
-               else\r
-               {\r
-                       $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));\r
-               }\r
+               $manager->notify("Post{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));\r
                return;\r
        }\r
        \r
@@ -443,14 +417,7 @@ class Skin
                        );\r
                        \r
                        // PreUpdateSkinPart event\r
-                       if ( !$this->admin )\r
-                       {\r
-                               $manager->notify('PreUpdateSkinPart', $data);\r
-                       }\r
-                       else\r
-                       {\r
-                               $manager->notify('PreUpdateAdminSkinPart', $data);\r
-                       }\r
+                       $manager->notify("PreUpdate{{$this->event_identifier}}Part", $data);\r
                }\r
                else if( $skintypevalue && !$skintypeexists )\r
                {\r
@@ -460,15 +427,7 @@ class Skin
                                'content' => &$content\r
                        );\r
                        \r
-                       // PreAddSkinPart event\r
-                       if ( !$this->admin )\r
-                       {\r
-                               $manager->notify('PreAddSkinPart', $data);\r
-                       }\r
-                       else\r
-                       {\r
-                               $manager->notify('PreAddAdminSkinPart', $data);\r
-                       }\r
+                       $manager->notify("PreAdd{$this->event_identifier}Part", $data);\r
                }\r
                else if( !$skintypevalue && $skintypeexists )\r
                {\r
@@ -477,15 +436,7 @@ class Skin
                                'type' => $type\r
                        );\r
                        \r
-                       // PreDeleteSkinPart event\r
-                       if ( !$this->admin )\r
-                       {\r
-                               $manager->notify('PreDeleteSkinPart', $data);\r
-                       }\r
-                       else\r
-                       {\r
-                               $manager->notify('PreDeleteAdminSkinPart', $data);\r
-                       }\r
+                       $manager->notify("PreDelete{$this->event_identifier}Part", $data);\r
                }\r
                \r
                // delete old thingie\r
@@ -510,14 +461,7 @@ class Skin
                        );\r
                        \r
                        // PostUpdateSkinPart event\r
-                       if ( !$this->admin )\r
-                       {\r
-                               $manager->notify('PostUpdateSkinPart', $data);\r
-                       }\r
-                       else\r
-                       {\r
-                               $manager->notify('PostUpdateAdminSkinPart', $data);\r
-                       }\r
+                       $manager->notify("PostUpdate{$this->event_identifier}Part", $data);\r
                }\r
                else if( $skintypevalue && (!$skintypeexists) )\r
                {\r
@@ -528,14 +472,7 @@ class Skin
                        );\r
                        \r
                        // PostAddSkinPart event\r
-                       if ( !$this->admin )\r
-                       {\r
-                               $manager->notify('PostAddSkinPart', $data);\r
-                       }\r
-                       else\r
-                       {\r
-                               $manager->notify('PostAddAdminSkinPart', $data);\r
-                       }\r
+                       $manager->notify("PostAdd{$this->event_identifier}Part", $data);\r
                }\r
                else if( (!$skintypevalue) && $skintypeexists )\r
                {\r
@@ -544,15 +481,7 @@ class Skin
                                'type'          => $type\r
                        );\r
                        \r
-                       // PostDeleteSkinPart event\r
-                       if ( !$this->admin )\r
-                       {\r
-                               $manager->notify('PostDeleteSkinPart', $data);\r
-                       }\r
-                       else\r
-                       {\r
-                               $manager->notify('PostDeleteAdminSkinPart', $data);\r
-                       }\r
+                       $manager->notify("PostDelete{$this->event_identifier}Part", $data);\r
                }\r
                return;\r
        }\r
@@ -598,24 +527,69 @@ class Skin
        }\r
        \r
        /**\r
+        * Skin::getAllowedActionsForType()\r
+        * 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 (e.g. index, item, search ...)\r
+        * @return      array   allowed action types\r
+        */\r
+       public function getAllowedActionsForType($type)\r
+       {\r
+               /**\r
+                * NOTE: static method with variable class name is supported since 5.3\r
+                *  So now we utilize eval function.\r
+                */\r
+               $page_action_names = array();\r
+               eval("\$page_action_names = {$this->action_class}::get_allowed_actions_for_type('{$type}');");\r
+               return $page_action_names;\r
+       }\r
+       \r
+       /**\r
         * Skin::getFriendlyNames()\r
         * Get an array with the names of possible skin parts\r
         * Used to show all possible parts of a skin in the administration backend\r
         * \r
-        * @param       void\r
+        * @static\r
+        * @param       string  $action_class   name of action class (optional)\r
         * @param       array   type of the skin\r
         */\r
-       static public function getFriendlyNames()\r
+       static public function getFriendlyNames($action_class='Actions')\r
        {\r
-               if ( !$this->$admin )\r
+               global $DIR_LIBS;\r
+               \r
+               /*\r
+                * NOTE: include needed action class\r
+                */\r
+               if ( $action_class != 'Actions' )\r
                {\r
-                       $friendly_names = Actions::get_page_type_friendly_names();\r
-                       $action_names = Actions::get_page_action_names();\r
+                       if ( !class_exists($action_class, FALSE)\r
+                         && !file_exists("{$DIR_LIBS}{$action_class}.php")\r
+                         || !include("{$DIR_LIBS}{$action_class}.php") )\r
+                       {\r
+                               return;\r
+                       }\r
                }\r
                else\r
                {\r
-                       $friendly_names = AdminActions::get_page_type_friendly_names();\r
-                       $action_names = AdminActions::get_page_action_names();\r
+                       if ( !class_exists('Actions', FALSE)\r
+                         && !file_exists("{$DIR_LIBS}ACTIONS.php")\r
+                         || !include("{$DIR_LIBS}ACTIONS.php") )\r
+                       {\r
+                               return;\r
+                       }\r
+               }\r
+               \r
+               /**\r
+                * NOTE: static method with variable class name is supported since 5.3\r
+                *  So now we utilize eval function.\r
+                */\r
+               eval("\$friendly_names = {$action_class}::get_page_type_friendly_names();");\r
+               \r
+               $action_names = array();\r
+               foreach ( $friendly_names as $action_name => $friendly_name )\r
+               {\r
+                       $action_names[] = $action_name;\r
                }\r
                \r
                $query = "SELECT stype FROM %s WHERE stype NOT IN ('%s');";\r
@@ -628,24 +602,4 @@ class Skin
                }\r
                return $friendly_names;\r
        }\r
-       \r
-       /**\r
-        * Skin::getAllowedActionsForType()\r
-        * 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 (e.g. index, item, search ...)\r
-        * @return      array   allowed action types\r
-        */\r
-       public function getAllowedActionsForType($type)\r
-       {\r
-               if ( !$this->admin )\r
-               {\r
-                       return Actions::get_allowed_actions_for_type($type);\r
-               }\r
-               else\r
-               {\r
-                       return AdminActions::get_allowed_actions_for_type($type);\r
-               }\r
-       }\r
 }\r
index 6c5b265..92af16d 100644 (file)
@@ -1558,21 +1558,10 @@ function listplug_table_skinlist($vars, $type, $templateName = '')
                        }\r
                        if ( sizeof($types) > 0 )\r
                        {\r
-                               $friendlyNames = Skin::getFriendlyNames();\r
-                               $defaultParts  = array(\r
-                                                                       'index',\r
-                                                                       'item',\r
-                                                                       'archivelist',\r
-                                                                       'archive',\r
-                                                                       'search',\r
-                                                                       'error',\r
-                                                                       'member',\r
-                                                                       'imagepopup',\r
-                                                                );\r
                                for ( $i = 0; $i < sizeof($types); $i++ )\r
                                {\r
                                        $type = $types[$i];\r
-                                       if ( !in_array($type, $defaultParts) )\r
+                                       if ( $i != $types[$i] )\r
                                        {\r
                                                $article = 'skinpartspecial';\r
                                        }\r
@@ -1582,8 +1571,10 @@ function listplug_table_skinlist($vars, $type, $templateName = '')
                                        }\r
                                        $types[$i]  = "<li>\n"\r
                                                                . helpHtml($article) . "\n"\r
-                                                               . "<a href=\"index.php?action=skinedittype&amp;skinid={$current->sdnumber}&amp;type={$type}\" tabindex=\"{$vars['tabindex']}\">" . Entity::hsc($friendlyNames[$type]) . "</a>\n"\r
-                                                               . "</li>\n";\r
+                                                   . "<a href=\"index.php?action=skinedittype&amp;skinid={$current->sdnumber}&amp;type={$type}\" tabindex=\"{$template['tabindex']}\">"\r
+                                                   . Entity::hsc($template['friendly_names'][$type])\r
+                                                   . "</a>\n"\r
+                                                   . "</li>\n";\r
                                }\r
                                $data['skinparts'] = '<br /><br />' . _LIST_SKINS_DEFINED . "<ul>\n" . implode($types, '') . "</ul>\n";\r
                        }\r
@@ -1920,12 +1911,12 @@ function listplug_table_adminskinlist($vars, $type, $templateName = '')
                        {\r
                                $data['skinname'] = Entity::hsc($current->sdname);\r
                        }\r
-\r
+                       \r
                        // add preview image when present\r
                        if ( $current->sdincpref && @file_exists("{$adminSkinDir}{$current->sdincpref}preview.png") )\r
                        {\r
                                $data['skinthumb'] = "<p>\n";\r
-\r
+                               \r
                                $alternatve_text = sprintf(_LIST_SKIN_PREVIEW, $current->sdname);\r
                                $has_enlargement = @file_exists($adminSkinDir . $current->sdincpref . 'preview-large.png');\r
                                if ( $has_enlargement )\r
@@ -1937,7 +1928,7 @@ function listplug_table_adminskinlist($vars, $type, $templateName = '')
                                {\r
                                        $data['skinthumb'] .= "</a><br />\n";\r
                                }\r
-\r
+                               \r
                                if ( @file_exists("{$DIR_SKINS}{$current->sdincpref}readme.html") )\r
                                {\r
                                        $url = $adminSkinURL . Entity::hsc($current->sdincpref) . 'readme.html';\r
@@ -1948,14 +1939,14 @@ function listplug_table_adminskinlist($vars, $type, $templateName = '')
                                {\r
                                        $data['readme'] ="";\r
                                }\r
-\r
+                               \r
                                $data['skinthumb'] .=  "</p>\n";\r
                        }\r
                        /* show list of defined parts */\r
                        $query = "SELECT stype FROM %s WHERE sdesc=%d ORDER BY stype";\r
                        $query = sprintf($query, sql_table('skin'), $current->sdnumber);\r
                        $r = sql_query($query);\r
-\r
+                       \r
                        $types = array();\r
                        while ( $o = sql_fetch_object($r) )\r
                        {\r
@@ -1963,8 +1954,6 @@ function listplug_table_adminskinlist($vars, $type, $templateName = '')
                        }\r
                        if ( sizeof($types) > 0 )\r
                        {\r
-                               $friendlyNames     = AdminActions::get_page_type_friendly_names();\r
-                               $adminDefaultTypes = AdminActions::get_page_action_names();\r
                                for ( $i = 0; $i < sizeof($types); $i++ )\r
                                {\r
                                        $type = $types[$i];\r
@@ -1977,30 +1966,32 @@ function listplug_table_adminskinlist($vars, $type, $templateName = '')
                                                $article = "skinpart{$type}";\r
                                        }\r
                                        $types[$i]  = "<li>\n"\r
-                                       . helpHtml($article) . "\n"\r
-                                       . "<a href=\"index.php?action=adminskinedittype&amp;skinid={$current->sdnumber}&amp;type={$type}\" tabindex=\"{$vars['tabindex']}\">" . Entity::hsc($friendlyNames[$type]) . "</a>\n"\r
-                                                       . "</li>\n";\r
+                                                   . helpHtml($article) . "\n"\r
+                                                   . "<a href=\"index.php?action=adminskinedittype&amp;skinid={$current->sdnumber}&amp;type={$type}\" tabindex=\"{$vars['tabindex']}\">"\r
+                                                   . Entity::hsc($template['friendly_names'][$type])\r
+                                                   . "</a>\n"\r
+                                                   . "</li>\n";\r
+                               }\r
+                               $data['skinparts'] = '<br /><br />' . _LIST_SKINS_DEFINED . "<ul>\n" . implode($types, '') . "</ul>\n";\r
                        }\r
-                       $data['skinparts'] = '<br /><br />' . _LIST_SKINS_DEFINED . "<ul>\n" . implode($types, '') . "</ul>\n";\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                       $data['skinparts'] = '';\r
-       }\r
-       break;\r
-       case 'FOOT':\r
-       if ( isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) )\r
-       {\r
-       $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'];\r
+                       else\r
+                       {\r
+                               $data['skinparts'] = '';\r
+                       }\r
+                       break;\r
+               case 'FOOT':\r
+                       if ( isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) )\r
+                       {\r
+                               $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'];\r
+                       }\r
+                       else\r
+                       {\r
+                               $template = "";\r
+                       }\r
+                       $data = array();\r
+                       break;\r
        }\r
-       else\r
-       {\r
-       $template = "";\r
-}\r
-$data = array();\r
-       break;\r
-}\r
-return Template::fill($template, $data);\r
+       return Template::fill($template, $data);\r
 }\r
 \r
 function listplug_table_admintemplatelist($vars, $type, $templateName = '')\r