From 5877b373852fecc82e4ebe5eac9afc4ee567f6cf Mon Sep 17 00:00:00 2001 From: sakamocchi Date: Sun, 22 Apr 2012 13:38:45 +0900 Subject: [PATCH] =?utf8?q?MERGE:=20=E3=83=AA=E3=83=93=E3=82=B8=E3=83=A7?= =?utf8?q?=E3=83=B31784=E3=80=82Skin::getFriendlyNames()=E3=82=92=E5=BB=83?= =?utf8?q?=E6=AD=A2=E3=81=97=E3=80=81=E4=BB=A3=E6=9B=BF=E3=83=A1=E3=82=BD?= =?utf8?q?=E3=83=83=E3=83=89=E3=82=922=E3=81=A4=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Skin::getDefaultTypes()とSkin::getAvailableTypes()を追加し関連する修正をした。 Revision 1784: ADD: Skin::getDefaultTypes() and Skin::getAvailableTypes() instead of Skin::getFriendlyNames() For easy understanding, rename some functions related to skin and did some modifications. Rename: Actions::getSkinTypeFriendlyNames() to Actions::getDefaultSkinTypes() Rename: Actions::$skin_type_friendly_names to Actions::$default_skin_types Change: Admin::action_skinedit() Change: Admin::action_skinedittype() Change: Admin::action_skinremovetype() Change: listplug_table_skinlist() http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1784 --- nucleus/libs/ACTIONS.php | 11 ++++----- nucleus/libs/ADMIN.php | 56 ++++++++++++++++++++++---------------------- nucleus/libs/SKIN.php | 59 ++++++++++++++++++++++++++++++++++++----------- nucleus/libs/showlist.php | 19 ++++----------- 4 files changed, 82 insertions(+), 63 deletions(-) diff --git a/nucleus/libs/ACTIONS.php b/nucleus/libs/ACTIONS.php index d497965..f1aedb4 100644 --- a/nucleus/libs/ACTIONS.php +++ b/nucleus/libs/ACTIONS.php @@ -18,7 +18,7 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2012 The Nucleus Group - * @version $Id: ACTIONS.php 1757 2012-04-15 09:02:32Z sakamocchi $ + * @version $Id: ACTIONS.php 1784 2012-04-22 04:28:30Z sakamocchi $ */ class Actions extends BaseActions @@ -79,7 +79,7 @@ class Actions extends BaseActions * Actions::$skin_type_friendly_names * friendly name for wrapped page types */ - static public $skin_type_friendly_names = array( + static public $default_skin_types = array( 'index' => _SKIN_PART_MAIN, 'item' => _SKIN_PART_ITEM, 'archivelist' => _SKIN_PART_ALIST, @@ -230,15 +230,15 @@ class Actions extends BaseActions } /** - * Actions::getSkinTypeFriendlyNames() + * Actions::getDefaultSkinTypes() * * @static * @param void * @return array list of friendly names for page actions */ - static public function getSkinTypeFriendlyNames() + static public function getDefaultSkinTypes() { - return self::$skin_type_friendly_names; + return self::$default_skin_types; } /** @@ -254,7 +254,6 @@ class Actions extends BaseActions // call constructor of superclass first parent::__construct(); - $this->skintype = $type; if ( $catid ) diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index faaa1b1..256a4ae 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -4355,7 +4355,8 @@ selector(); $member->isAdmin() or $this->disallow(); $skin = new SKIN($skinid); - $friendlyNames = $skin->getFriendlyNames(); + $default_skin_types = $skin->getDefaultTypes(); + $available_skin_types = $skin->getAvailableTypes(); $this->pagehead(); @@ -4369,8 +4370,7 @@ selector(); echo "\n"; - $query = "SELECT stype FROM %s WHERE stype NOT IN ('%s') and sdesc=%d;"; - $query = sprintf($query, sql_table('skin'), implode("', '", array_keys($friendlyNames)) , $skinid); - $res = sql_query($query); - echo '

' . _SKIN_PARTS_SPECIAL . '

'; echo "
\n"; echo "\n"; @@ -4394,23 +4390,27 @@ selector(); echo '\n"; echo "
\n"; - if ( $res && sql_num_rows($res) > 0 ) + /* NOTE: special skin parts has FALSE in its value */ + if ( in_array(FALSE, array_values($available_skin_types)) ) { $tabstart = 75; echo '
'; } @@ -4525,14 +4525,14 @@ selector(); } $skin = new SKIN($skinid); - $friendlyNames = $skin->getFriendlyNames(); - if ( !array_key_exists($type, $friendlyNames) || !isset($friendlyNames[$type]) ) + $skin_types = $skin->getAvailableTypes(); + if ( !array_key_exists($type, $skin_types) || !$skin_types[$type] ) { $friendlyName = ucfirst($type); } else { - $friendlyName = $friendlyNames[$type]; + $friendlyName = $skin_types[$type]; } $this->pagehead(); @@ -4558,7 +4558,7 @@ selector(); echo '' . "\n"; echo '(skin type: ' . Entity::hsc($friendlyName) . ")\n"; - if ( !in_array($type, array_keys($friendlyNames)) ) + if ( !array_key_exists($type, $skin_types) || !$skin_types[$type] ) { help('skinpartspecial'); } @@ -4585,7 +4585,7 @@ selector(); sort($actions); - while ($current = array_shift($actions)) + while ( $current = array_shift($actions) ) { // skip deprecated vars if ( in_array($current, array('ifcat', 'imagetext', 'vars')) ) @@ -4738,8 +4738,8 @@ selector(); // don't allow default skinparts to be deleted $skin = new Skin($skinid); - $friendlyNames = $skin->getFriendlyNames(); - if ( in_array($skintype, array_keys($friendlyNames)) ) + $default_skin_types = $skin->getDefaultTypes(); + if ( array_key_exists($skintype, $default_skin_types) ) { $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } @@ -4792,8 +4792,8 @@ selector(); // don't allow default skinparts to be deleted $skin = new Skin($skinid); - $friendlyNames = $skin->getFriendlyNames(); - if ( in_array($skintype, array_keys($friendlyNames)) ) + $default_skin_types = $skin->getDefaultTypes(); + if ( array_key_exists($skintype, $default_skin_types) ) { $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } diff --git a/nucleus/libs/SKIN.php b/nucleus/libs/SKIN.php index 7618688..ce44284 100644 --- a/nucleus/libs/SKIN.php +++ b/nucleus/libs/SKIN.php @@ -14,7 +14,7 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group - * @version $Id: SKIN.php 1779 2012-04-21 10:04:33Z sakamocchi $ + * @version $Id: SKIN.php 1784 2012-04-22 04:28:30Z sakamocchi $ */ if ( !function_exists('requestVar') ) @@ -568,28 +568,59 @@ class Skin } /** - * Skin::getAllowedActionsForType() - * Get the allowed actions for a skin type - * returns an array with the allowed actions + * Skin::getDefaultTypes() * - * @param string $type type of the skin (e.g. index, item, search ...) - * @return array allowed action types + * @param string void + * @return array default skin types */ - public function getAllowedActionsForType($type) + public function getDefaultTypes() { - return call_user_func(array($this->action_class, 'getDefinedActions'), $type); + return call_user_func(array($this->action_class, 'getDefaultSkinTypes')); } /** - * Skin::getFriendlyNames() - * Get an array with the names of possible skin parts - * Used to show all possible parts of a skin in the administration backend + * Skin::getAvailableTypes() * * @param string void - * @return array type of the skin + * @return array registered skin types + */ + public function getAvailableTypes() + { + $default_skintypes = $this->getDefaultTypes(); + $query = "SELECT stype FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $this->id); + + /* NOTE: force to put default types in the beginning */ + $in_default = array(); + $no_default = array(); + + $res = sql_query($query); + while ( $row = sql_fetch_array($res) ) + { + if ( !array_key_exists($row['stype'], $default_skintypes) ) + { + $no_default[$row['stype']] = FALSE; + } + else + { + $in_default[$row['stype']] = $default_skintypes[$row['stype']]; + } + } + + return array_merge($in_default, $no_default); + } + + /** + * Skin::getAllowedActionsForType() + * Get the allowed actions for a skin type + * returns an array with the allowed actions + * + * @param string $type type of the skin + * @return array allowed action types */ - public function getFriendlyNames() + public function getAllowedActionsForType($type) { - return call_user_func(array($this->action_class, 'getSkinTypeFriendlyNames')); + return call_user_func(array($this->action_class, 'getDefinedActions'), $type); } + } diff --git a/nucleus/libs/showlist.php b/nucleus/libs/showlist.php index fdfaa93..7eeda08 100644 --- a/nucleus/libs/showlist.php +++ b/nucleus/libs/showlist.php @@ -14,7 +14,7 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group - * @version $Id: showlist.php 1755 2012-04-14 10:05:49Z sakamocchi $ + * @version $Id: showlist.php 1784 2012-04-22 04:28:30Z sakamocchi $ */ @@ -825,32 +825,21 @@ function listplug_table_skinlist($template, $type) echo "\n"; echo '

' . Entity::hsc($current->sddesc) . "

\n"; - /* make list of registered skins */ - $query = "SELECT stype FROM %s WHERE sdesc=%d ORDER BY stype"; - $query = sprintf($query, sql_table('skin'), $current->sdnumber); - $r = sql_query($query); - $types = array(); - while ( $o = sql_fetch_object($r) ) - { - array_push($types, $o->stype); - } - /* make list of defined skins */ $skin = new Skin($current->sdnumber); - $friendlyNames = $skin->getFriendlyNames(); + $available_skin_types = $skin->getAvailableTypes(); echo _LIST_SKINS_DEFINED; echo "