OSDN Git Service

MERGE: リビジョン1784。Skin::getFriendlyNames()を廃止し、代替メソッドを2つ追加。
authorsakamocchi <o-takashi@sakamocchi.jp>
Sun, 22 Apr 2012 04:38:45 +0000 (13:38 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sun, 22 Apr 2012 04:38:45 +0000 (13:38 +0900)
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
nucleus/libs/ADMIN.php
nucleus/libs/SKIN.php
nucleus/libs/showlist.php

index d497965..f1aedb4 100644 (file)
@@ -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 )
index faaa1b1..256a4ae 100644 (file)
@@ -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 "<ul>\n";
                
                $tabindex = 10;
-               $types = array();
-               foreach ( $friendlyNames as $type => $friendly_name )
+               foreach ( $default_skin_types as $type => $friendly_name )
                {
                        echo "<li>\n";
                        echo "<a tabindex=\"{$tabindex}\" href=\"index.php?action=skinedittype&amp;skinid={$skinid}&amp;type={$type}\">";
@@ -4382,10 +4382,6 @@ selector();
                }
                echo "</ul>\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 '<h3>' . _SKIN_PARTS_SPECIAL . '</h3>';
                echo "<form method=\"get\" action=\"index.php\">\n";
                echo "<input type=\"hidden\" name=\"action\" value=\"skinedittype\" />\n";
@@ -4394,23 +4390,27 @@ selector();
                echo '<input type="submit" tabindex="140" value="' . _SKIN_CREATE . "\" onclick=\"return checkSubmit();\" />\n";
                echo "</form>\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 '<ul>';
-                       while ( $row = sql_fetch_assoc($res) )
+                       foreach ( $available_skin_types as $type => $friendly_name )
                        {
-                               $tabstart++;
-                               echo "<li>\n";
-                               echo "<a tabindex=\"{$tabstart}\" href=\"index.php?action=skinedittype&amp;skinid={$skinid}&amp;type=" . Entity::hsc(strtolower($row['stype'])) . "\">";
-                               echo Entity::hsc(ucfirst($row['stype']));
-                               echo "</a>\n";
-                               $tabstart++;
-                               echo "(<a tabindex=\"{$tabstart}\" href=\"index.php?action=skinremovetype&amp;skinid={$skinid}&amp;type=" . Entity::hsc(strtolower($row['stype'])) . "\">";
-                               echo _LISTS_DELETE;
-                               echo "</a>)\n";
-                               echo "</li>\n";
+                               if ( !$friendly_name )
+                               {
+                                       $tabstart++;
+                                       echo "<li>\n";
+                                       echo "<a tabindex=\"{$tabstart}\" href=\"index.php?action=skinedittype&amp;skinid={$skinid}&amp;type=" . Entity::hsc(strtolower($type)) . '">';
+                                       echo Entity::hsc(ucfirst($type));
+                                       echo "</a>\n";
+                                       $tabstart++;
+                                       echo "(<a tabindex=\"{$tabstart}\" href=\"index.php?action=skinremovetype&amp;skinid={$skinid}&amp;type=" . Entity::hsc(strtolower($type)) . '">';
+                                       echo _LISTS_DELETE;
+                                       echo "</a>)\n";
+                                       echo "</li>\n";
+                               }
                        }
                        echo '</ul>';
                }
@@ -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 '<input type="reset" value="' . _SKIN_RESET_BTN . '" />' . "\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);
                }
index 7618688..ce44284 100644 (file)
@@ -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);
        }
+       
 }
index fdfaa93..7eeda08 100644 (file)
@@ -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 "<td>\n";
                        echo '<p>' . Entity::hsc($current->sddesc) . "</p>\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 "<ul>\n";
-                       foreach ( $types as $type )
+                       foreach ( $available_skin_types as $type => $friendlyName )
                        {
-                               if ( !array_key_exists($type, $friendlyNames) )
+                               if ( $friendlyName === FALSE )
                                {
                                        $friendlyName = ucfirst($type);
                                        $article = 'skinpartspecial';
                                }
                                else
                                {
-                                       $friendlyName = $friendlyNames[$type];
                                        $article = "skinpart{$type}";
                                }
                                echo "<li>\n";