OSDN Git Service

MERGE: リビジョン1775のマージ。fileparseスキンタイプを使用可能に
[nucleus-jp/nucleus-next.git] / nucleus / libs / SKIN.php
index 652b726..9bcc04d 100644 (file)
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
  * @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id: SKIN.php 1621 2012-01-09 02:49:37Z sakamocchi $
+ * @version $Id: SKIN.php 1755 2012-04-14 10:05:49Z sakamocchi $
  */
 
 if ( !function_exists('requestVar') ) 
 {
        exit;
 }
-require_once dirname(__FILE__) . '/ACTIONS.php';
 
-class SKIN {
-       
+class Skin
+{
        // after creating a SKIN object, evaluates to true when the skin exists
-       var $isValid;
+       private $valid;
        
        // skin characteristics. Use the getXXX methods rather than accessing directly
-       var $id;
-       var $description;
-       var $contentType;
-       var $includeMode;               // either 'normal' or 'skindir'
-       var $includePrefix;
-       var $name;
+       private $id;
+       private $description;
+       private $contentType;
+       private $includeMode;           // either 'normal' or 'skindir'
+       private $includePrefix;
+       private $name;
+       
+       /* action class */
+       private $action_class;
+       private $event_identifier;
        
        /**
+        * Skin::__construct()
         * Constructor for a new SKIN object
         * 
-        * @param $id 
-        *                      id of the skin
+        * @param       integer $id                                     id of the skin
+        * @param       string  $action_class           name of class extended from BaseActions
+        * @param       string  $event_identifier       event identifier. for example, InitAdminSkinParse if AdminSkin is used
+        * @return      void
         */
-       function SKIN($id)
+       public function __construct($id, $action_class='Actions', $event_identifier='Skin')
        {
-               $this->id = intval($id);
+               global $DIR_LIBS;
+               
+               $this->id = (integer) $id;
                
                // read skin name/description/content type
-               $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
+               $query = "SELECT * FROM %s WHERE sdnumber=%d";
+               $query = sprintf($query, sql_table('skin_desc'), (integer) $this->id);
+               $res = sql_query($query);
                $obj = sql_fetch_object($res);
-               $this->isValid = (sql_num_rows($res) > 0);
-               if ( !$this->isValid )
+               $this->valid = (sql_num_rows($res) > 0);
+               if ( !$this->valid )
                {
                        return;
                }
                
+               /*
+                * NOTE: include needed action class
+                */
+               if ( $action_class != 'Actions' )
+               {
+                       if ( !class_exists($action_class, FALSE)
+                         && (!file_exists("{$DIR_LIBS}{$action_class}.php")
+                          || !include("{$DIR_LIBS}{$action_class}.php")) )
+                       {
+                               return;
+                       }
+               }
+               else
+               {
+                       if ( !class_exists('Actions', FALSE)
+                         && (!file_exists("{$DIR_LIBS}ACTIONS.php")
+                          || !include("{$DIR_LIBS}ACTIONS.php")) )
+                       {
+                               return;
+                       }
+               }
+               
+               $this->action_class = $action_class;
+               $this->event_identifier = $event_identifier;
+               
                $this->name = $obj->sdname;
                $this->description = $obj->sddesc;
                $this->contentType = $obj->sdtype;
                $this->includeMode = $obj->sdincmode;
                $this->includePrefix = $obj->sdincpref;
-
+               
+               return;
        }
        
        /**
+        * Skin::getID()
         * Get SKIN id
+        * 
+        * @param       void
+        * @return      integer id for this skin instance
         */
-       function getID()
+       public function getID()
        {
-               return $this->id;
+               return (integer) $this->id;
        }
        
        /**
+        * Skin::isValid()
+        * 
+        * @param       void
+        * @return      boolean
+        */
+       public function isValid()
+       {
+               return (boolean) $this->valid;
+       }
+       
+       /**
+        * Skin::getName()
         * Get SKIN name
+        * 
+        * @param       void
+        * @return      string  name of this skin instance
         */
-       function getName()
+       public function getName()
        {
-               return $this->name;
+               return (string) $this->name;
        }
        
        /**
+        * Skin::getDescription()
         * Get SKIN description
+        * 
+        * @param       void
+        * @return      string  description of this skin instance
         */
-       function getDescription()
+       public function getDescription()
        {
-               return $this->description;
+               return (string) $this->description;
        }
        
        /**
+        * Skin::getContentType()
         * Get SKIN content type
-        * 
         * e.g. text/xml, text/html, application/atom+xml
+        * 
+        * @param       void
+        * @return      string  name of this skin instance
         */
-       function getContentType()
+       public function getContentType()
        {
-               return $this->contentType;
+               return (string) $this->contentType;
        }
        
        /**
+        * Skin::getIncludeMode()
         * Get include mode of the SKIN
         * 
         * Returns either 'normal' or 'skindir':
         * 'normal': if a all data of the skin can be found in the databse
         * 'skindir': if the skin has data in the it's skin driectory
+        * 
+        * @param       void
+        * @return      string  normal/skindir
         */
-       function getIncludeMode()
+       public function getIncludeMode()
        {
-               return $this->includeMode;
+               return (string) $this->includeMode;
        }
        
        /**
+        * Skin::getIncludePrefix()
         * Get include prefix of the SKIN
         * 
         * Get name of the subdirectory (with trailing slash) where
         * the files of the current skin can be found (e.g. 'default/')
+        * 
+        * @param       void
+        * @return      string  include prefix of this skin instance
         */
-       function getIncludePrefix()
+       public function getIncludePrefix()
        {
-               return $this->includePrefix;
+               return (string) $this->includePrefix;
        }
        
        /**
+        * Skin::exists()
         * Checks if a skin with a given shortname exists
-        * @param string $name Skin short name
-        * @return int number of skins with the given ID
+        * 
         * @static
+        * @param       string  $name   Skin short name
+        * @return      integer number of skins with the given ID
         */
-       function exists($name)
+       static public function exists($name)
        {
-               return quickQuery('select count(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdname="' . sql_real_escape_string($name) . '"') > 0;
+               $query = "SELECT COUNT(*) AS result FROM %s WHERE sdname='%s';";
+               $query = sprintf($query, sql_table('skin_desc'), sql_real_escape_string($name));
+               return (quickQuery($query) > 0);
        }
        
        /**
+        * Skin::existsID()
         * Checks if a skin with a given ID exists
-        * @param string $id Skin ID
-        * @return int number of skins with the given ID
+        * 
         * @static
+        * @param       string  $id     Skin ID
+        * @return      integer number of skins with the given ID
         */
-       function existsID($id)
+       static public function existsID($id)
        {
-               return quickQuery('select COUNT(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id)) > 0;
+               $query = "SELECT COUNT(*) AS result FROM %s WHERE sdnumber=%d;";
+               $query = sprintf($query, sql_table('skin_desc'), (integer) $id);
+               return (quickQuery($query) > 0);
        }
        
        /**
+        * Skin::createFromName()
         * Returns a skin given its shortname
-        * @param string $name Skin shortname
-        * @return object SKIN
+        * 
         * @static
+        * @param       string  $name   Skin shortname
+        * @return      object instance of Skin class
         */
-       function createFromName($name)
+       static public function createFromName($name)
        {
                return new SKIN(SKIN::getIdFromName($name));
        }
        
        /**
+        * Skin::getIdFromName()
         * Returns a skin ID given its shortname
-        * @param string $name Skin shortname
-        * @return int Skin ID
+        * 
         * @static
+        * @param       string  $name   Skin shortname
+        * @return      integer Skin ID
         */
-       function getIdFromName($name)
+       static public function getIdFromName($name)
        {
-               $query =  'SELECT sdnumber'
-                               . ' FROM ' . sql_table('skin_desc')
-                               . ' WHERE sdname="' . sql_real_escape_string($name) . '"';
+               $query = "SELECT sdnumber FROM %s WHERE sdname='%s';";
+               $query = sprintf($query, sql_table('skin_desc'), sql_real_escape_string($name));
                $res = sql_query($query);
                $obj = sql_fetch_object($res);
                return $obj->sdnumber;
        }
        
        /**
+        * Skin::getNameFromId()
         * Returns a skin shortname given its ID
-        * @param string $name
-        * @return string Skin short name
+        * 
         * @static
+        * @param       string  $name
+        * @return      string  Skin short name
         */
-       function getNameFromId($id)
+       static public function getNameFromId($id)
        {
-               return quickQuery('SELECT sdname as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id));
+               $query = "SELECT sdname AS result FROM %s WHERE sdnumber=%d;";
+               $query = sprintf($query, sql_table('skin_desc'), (integer) $id);
+               return quickQuery($query);
        }
        
        /**
@@ -191,9 +276,8 @@ class SKIN {
         * @param       String  $includeMode    value for nucleus_skin.sdinclude
         * @param       String  $includePrefix  value for nucleus_skin.sdincpref
         * @return      Integer ID for just inserted record
-        * 
         */
-       function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
+       public function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
        {
                global $manager;
                
@@ -208,44 +292,59 @@ class SKIN {
                        )
                );
                
-               $query = "INSERT INTO %s (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('%s', '%s', '%s', '%s', '%s')";
-               $query = sprintf($query, sql_table('skin_desc'), sql_real_escape_string($name), sql_real_escape_string($desc), sql_real_escape_string($type), sql_real_escape_string($includeMode), sql_real_escape_string($includePrefix));
+               $query = "INSERT INTO %s (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('%s', '%s', '%s', '%s', '%s');";
+               $sdname         = sql_real_escape_string($name);
+               $sddesc         = sql_real_escape_string($desc);
+               $sdtype         = sql_real_escape_string($type);
+               $sdincmode      = sql_real_escape_string($includeMode);
+               $sdincpref      = sql_real_escape_string($includePrefix);
+               $query = sprintf($query, sql_table('skin_desc'), $sdname, $sddesc, $sdtype, $sdincmode, $sdincpref);
                sql_query($query);
                $newid = sql_insert_id();
                
                $manager->notify(
                        'PostAddSkin',
                        array(
-                               'skinid' => $newid,
-                               'name' => $name,
-                               'description' => $desc,
-                               'type' => $type,
-                               'includeMode' => $includeMode,
-                               'includePrefix' => $includePrefix
+                               'skinid'                => $newid,
+                               'name'                  => $name,
+                               'description'   => $desc,
+                               'type'                  => $type,
+                               'includeMode'   => $includeMode,
+                               'includePrefix' => $includePrefix
                        )
                );
                return $newid;
        }
        
        /**
+        * Skin::parse()
         * Parse a SKIN
         * 
-        * @param string $type
+        * @param       string  $type
+        * @param       string  $path   path to file if using fileparser
+        * @return      void
         */
-       function parse($type)
+       public function parse($type, $path='')
        {
-               global $manager, $CONF;
+               global $currentSkinName, $manager, $CONF, $DIR_NUCLEUS;
                
-               $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
+               $manager->notify("Init{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));
                
                // set output type
                sendContentType($this->getContentType(), 'skin');
                
                // set skin name as global var (so plugins can access it)
-               global $currentSkinName;
                $currentSkinName = $this->getName();
                
-               $contents = $this->getContent($type);
+               $contents = FALSE;
+               if ( $type != 'fileparse' )
+               {
+                       $contents = $this->getContent($type);
+               }
+               else if ( $path !== ''  && i18n::strpos(realpath($path), realpath("$DIR_NUCLEUS/../")) == 0 )
+               {
+                       $contents = $this->getFileContent($path);
+               }
                
                if ( !$contents )
                {
@@ -259,60 +358,91 @@ class SKIN {
                        }
                }
                
-               $actions = $this->getAllowedActionsForType($type);
-               
-               $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
+               $manager->notify("Pre{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
                
                // set IncludeMode properties of parser
-               PARSER::setProperty('IncludeMode',$this->getIncludeMode());
-               PARSER::setProperty('IncludePrefix',$this->getIncludePrefix());
+               Parser::setProperty('IncludeMode', $this->getIncludeMode());
+               Parser::setProperty('IncludePrefix', $this->getIncludePrefix());
+               
+               $action_class = $this->action_class;
+               $handler = new $action_class($type);
+               
+               $actions = $handler->getDefinedActions($type);
+               $parser = new Parser($actions, $handler);
                
-               $handler = new ACTIONS($type, $this);
-               $parser = new PARSER($actions, $handler);
                $handler->setParser($parser);
                $handler->setSkin($this);
                $parser->parse($contents);
                
-               $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
+               $manager->notify("Post{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));
+               return;
        }
        
        /**
+        * Skin::getContent()
         * Get content of the skin part from the database
         * 
-        * @param $type type of the skin (e.g. index, item, search ...)
+        * @param       string  $type   type of the skin (e.g. index, item, search ...)
+        * @return      string  content of scontent
         */
-       function getContent($type)
+       public function getContent($type)
        {
-               $query = 'SELECT scontent FROM '. sql_table('skin') . " WHERE sdesc=$this->id and stype='" . sql_real_escape_string($type) . "'";
+               $query = "SELECT scontent FROM %s WHERE sdesc=%d and stype='%s';";
+               $query = sprintf($query, sql_table('skin'), (integer) $this->id, sql_real_escape_string($type));
                $res = sql_query($query);
                
                if ( sql_num_rows($res) == 0 )
                {
-                       return '';
+                       return FALSE;
                }
-               else
+               return sql_result($res, 0, 0);
+       }
+       
+       /**
+        * Skin::getFileContent()
+        * 
+        * @param       string  $fullpath       fullpath to the file to parse
+        * @return      mixed   file contents or FALSE
+        */
+       public function getFileContent($fullpath)
+       {
+               $fsize = filesize($fullpath);
+               if ( $fsize <= 0 )
                {
-                       return sql_result($res, 0, 0);
+                       return;
                }
+               
+               $fd = fopen ($fullpath, 'r');
+               if ( $fd === FALSE )
+               {
+                       return FALSE;
+               }
+               
+               $contents = fread ($fd, $fsize);
+               if ( $contents === FALSE )
+               {
+                       return FALSE;
+               }
+               
+               fclose ($fd);
+               return $contents;
        }
-
+       
        /**
         * SKIN::update()
         * Updates the contents for one part of the skin in the database
         * 
-        * @param $type type of the skin part (e.g. index, item, search ...) 
-        * @param $content new content for this skin part
-        * @return      Void
+        * @param       string  $type type of the skin part (e.g. index, item, search ...) 
+        * @param       string  $content new content for this skin part
+        * @return      void
         * 
         */
-       function update($type, $content)
+       public function update($type, $content)
        {
                global $manager;
                
-               $skinid = $this->id;
-               
-               $query = "SELECT sdesc FROM %s WHERE stype='%s' and sdesc=%d";
-               $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $skinid);
+               $query = "SELECT sdesc FROM %s WHERE stype='%s' and sdesc=%d;";
+               $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $this->id);
                $res = sql_query($query);
                
                $skintypeexists = sql_fetch_object($res);
@@ -320,312 +450,196 @@ class SKIN {
                
                if( $skintypevalue && $skintypeexists )
                {
-                       // PreUpdateSkinPart event
-                       $manager->notify(
-                               'PreUpdateSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
+                       $data = array(
+                               'skinid'        =>  $this->id,
+                               'type'          =>  $type,
+                               'content'       => &$content
                        );
+                       
+                       // PreUpdateSkinPart event
+                       $manager->notify("PreUpdate{{$this->event_identifier}}Part", $data);
                }
-               else if( $skintypevalue && (!$skintypeexists) )
+               else if( $skintypevalue && !$skintypeexists )
                {
-                       // PreAddSkinPart event
-                       $manager->notify(
-                               'PreAddSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
+                       $data = array(
+                               'skinid' => $this->id,
+                               'type' => $type,
+                               'content' => &$content
                        );
+                       
+                       $manager->notify("PreAdd{$this->event_identifier}Part", $data);
                }
-               else if( (!$skintypevalue) && $skintypeexists )
+               else if( !$skintypevalue && $skintypeexists )
                {
-                       // PreDeleteSkinPart event
-                       $manager->notify(
-                               'PreDeleteSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type
-                               )
+                       $data = array(
+                               'skinid' => $this->id,
+                               'type' => $type
                        );
+                       
+                       $manager->notify("PreDelete{$this->event_identifier}Part", $data);
                }
                
                // delete old thingie
                $query = "DELETE FROM %s WHERE stype='%s' and sdesc=%d";
-               $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $skinid);
+               $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $this->id);
                sql_query($query);
                
                // write new thingie
                if ( $content )
                {
                        $query = "INSERT INTO %s (scontent, stype, sdesc) VALUE ('%s', '%s', %d)";
-                       $query = sprintf($query, sql_table('skin'), sql_real_escape_string($content), sql_real_escape_string($type), (integer) $skinid);
+                       $query = sprintf($query, sql_table('skin'), sql_real_escape_string($content), sql_real_escape_string($type), (integer) $this->id);
                        sql_query($query);
                }
                
                if( $skintypevalue && $skintypeexists )
                {
-                       // PostUpdateSkinPart event
-                       $manager->notify(
-                       'PostUpdateSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
+                       $data = array(
+                               'skinid'        => $this->id,
+                               'type'          => $type,
+                               'content'       => &$content
                        );
+                       
+                       // PostUpdateSkinPart event
+                       $manager->notify("PostUpdate{$this->event_identifier}Part", $data);
                }
                else if( $skintypevalue && (!$skintypeexists) )
                {
-                       // PostAddSkinPart event
-                       $manager->notify(
-                               'PostAddSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
+                       $data = array(
+                               'skinid'        => $this->id,
+                               'type'          => $type,
+                               'content'       => &$content
                        );
+                       
+                       // PostAddSkinPart event
+                       $manager->notify("PostAdd{$this->event_identifier}Part", $data);
                }
                else if( (!$skintypevalue) && $skintypeexists )
                {
-                       // PostDeleteSkinPart event
-                       $manager->notify(
-                               'PostDeleteSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type
-                               )
+                       $data = array(
+                               'skinid'        => $this->id,
+                               'type'          => $type
                        );
+                       
+                       $manager->notify("PostDelete{$this->event_identifier}Part", $data);
                }
                return;
        }
        
        /**
+        * Skin::deleteAllParts()
         * Deletes all skin parts from the database
+        * 
+        * @param       void
+        * @return      void
         */
-       function deleteAllParts()
+       public function deleteAllParts()
        {
-               sql_query('DELETE FROM ' . sql_table('skin') . ' WHERE sdesc=' . $this->getID());
+               $query = "DELETE FROM %s WHERE sdesc=%d;";
+               $query = sprintf($query, sql_table('skin'), (integer) $this->id);
+               sql_query($query);
        }
-
+       
        /**
+        * Skin::updateGeneralInfo()
         * Updates the general information about the skin
+        * 
+        * @param       string  $name                   name of the skin
+        * @param       string  $desc                   description of the skin
+        * @param       string  $type                   type of the skin
+        * @param       string  $includeMode    include mode of the skin
+        * @param       string  $includePrefix  include prefix of the skin
+        * @return      void
         */
-       function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
+       public function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
        {
-               $query =  'UPDATE '.sql_table('skin_desc').' SET'
-                          . " sdname='" . sql_real_escape_string($name) . "',"
-                          . " sddesc='" . sql_real_escape_string($desc) . "',"
-                          . " sdtype='" . sql_real_escape_string($type) . "',"
-                          . " sdincmode='" . sql_real_escape_string($includeMode) . "',"
-                          . " sdincpref='" . sql_real_escape_string($includePrefix) . "'"
-                          . " WHERE sdnumber=" . $this->getID();
+               $name                   = sql_real_escape_string($name);
+               $desc                   = sql_real_escape_string($desc);
+               $type                   = sql_real_escape_string($type);
+               $includeMode    = sql_real_escape_string($includeMode);
+               $includePrefix  = sql_real_escape_string($includePrefix);
+               
+               $query ="UPDATE %s SET sdname='%s', sddesc='%s', sdtype='%s', sdincmode='%s', sdincpref='%s' WHERE sdnumber=%d";
+               $query = sprintf($query, sql_table('skin_desc'), $name, $desc, $type, $includeMode, $includePrefix, (integer) $this->id);
+               
                sql_query($query);
+               return;
        }
        
        /**
-        * Get an array with the names of possible skin parts
-        * Used to show all possible parts of a skin in the administration backend
+        * Skin::getAllowedActionsForType()
+        * Get the allowed actions for a skin type
+        * returns an array with the allowed actions
         * 
-        * static: returns an array of friendly names
+        * @param       string  $type   type of the skin (e.g. index, item, search ...)
+        * @return      array   allowed action types
         */
-       function getFriendlyNames()
+       public function getAllowedActionsForType($type)
        {
-               $skintypes = array(
-                       'index' => _SKIN_PART_MAIN,
-                       'item' => _SKIN_PART_ITEM,
-                       'archivelist' => _SKIN_PART_ALIST,
-                       'archive' => _SKIN_PART_ARCHIVE,
-                       'search' => _SKIN_PART_SEARCH,
-                       'error' => _SKIN_PART_ERROR,
-                       'member' => _SKIN_PART_MEMBER,
-                       'imagepopup' => _SKIN_PART_POPUP
-               );
-               
-               $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
-               $res = sql_query($query);
-               while ( $row = sql_fetch_array($res) )
-               {
-                       $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
-               }
-               return $skintypes;
+               /**
+                * NOTE: static method with variable class name is supported since PHP 5.3
+                *  So now we utilize eval function.
+                */
+               $page_action_names = array();
+               eval("\$defined_actions = {$this->action_class}::getDefinedActions('{$type}');");
+               return $defined_actions;
        }
-
+       
        /**
-        * Get the allowed actions for a skin type
-        * returns an array with the allowed actions
+        * 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
         * 
-        * @param $type type of the skin (e.g. index, item, search ...)
+        * @static
+        * @param       string  $action_class   name of action class (optional)
+        * @param       array   type of the skin
         */
-       function getAllowedActionsForType($type)
+       static public function getFriendlyNames($action_class='Actions')
        {
-               global $blogid;
-               
-               // some actions that can be performed at any time, from anywhere
-               $defaultActions = array('otherblog',
-                                                               'plugin',
-                                                               'version',
-                                                               'nucleusbutton',
-                                                               'include',
-                                                               'phpinclude',
-                                                               'parsedinclude',
-                                                               'loginform',
-                                                               'sitevar',
-                                                               'otherarchivelist',
-                                                               'otherarchivedaylist',
-                                                               'otherarchiveyearlist',
-                                                               'self',
-                                                               'adminurl',
-                                                               'todaylink',
-                                                               'archivelink',
-                                                               'member',
-                                                               'category',
-                                                               'searchform',
-                                                               'referer',
-                                                               'skinname',
-                                                               'skinfile',
-                                                               'set',
-                                                               'if',
-                                                               'else',
-                                                               'endif',
-                                                               'elseif',
-                                                               'ifnot',
-                                                               'elseifnot',
-                                                               'charset',
-                                                               'bloglist',
-                                                               'addlink',
-                                                               'addpopupcode',
-                                                               'sticky',
-                                                               // deprecated (Nucleus v2.0)
-                                                               'ifcat'
-                                                               );
-               
-               // extra actions specific for a certain skin type
-               $extraActions = array();
-               
-               switch ( $type )
+               global $DIR_LIBS;
+               
+               /*
+                * NOTE: include needed action class
+                */
+               if ( $action_class != 'Actions' )
+               {
+                       if ( !class_exists($action_class, FALSE)
+                         && (!file_exists("{$DIR_LIBS}{$action_class}.php")
+                          || !include("{$DIR_LIBS}{$action_class}.php")) )
+                       {
+                               return;
+                       }
+               }
+               else
+               {
+                       if ( !class_exists('Actions', FALSE)
+                         && (!file_exists("{$DIR_LIBS}ACTIONS.php")
+                          || !include("{$DIR_LIBS}ACTIONS.php")) )
+                       {
+                               return;
+                       }
+               }
+               
+               /**
+                * NOTE: static method with variable class name is supported since PHP 5.3
+                *  So now we utilize eval function.
+                */
+               eval("\$friendly_names = {$action_class}::getSkinTypeFriendlyNames();");
+               
+               $action_names = array();
+               foreach ( $friendly_names as $action_name => $friendly_name )
+               {
+                       $action_names[] = $action_name;
+               }
+               
+               $query = "SELECT stype FROM %s WHERE stype NOT IN ('%s');";
+               $query = sprintf($query, sql_table('skin'), implode("','", $action_names));
+               $res = sql_query($query);
+               
+               while ( $row = sql_fetch_array($res) )
                {
-                       case 'index':
-                               $extraActions = array('blog',
-                                                               'blogsetting',
-                                                               'preview',
-                                                               'additemform',
-                                                               'categorylist',
-                                                               'archivelist',
-                                                               'archivedaylist',
-                                                               'archiveyearlist',
-                                                               'nextlink',
-                                                               'prevlink'
-                                                               );
-                               break;
-                       case 'archive':
-                               $extraActions = array('blog',
-                                                               'archive',
-                                                               'otherarchive',
-                                                               'categorylist',
-                                                               'archivelist',
-                                                               'archivedaylist',
-                                                               'archiveyearlist',
-                                                               'blogsetting',
-                                                               'archivedate',
-                                                               'nextarchive',
-                                                               'prevarchive',
-                                                               'nextlink',
-                                                               'prevlink',
-                                                               'archivetype'
-                               );
-                               break;
-                       case 'archivelist':
-                               $extraActions = array('blog',
-                                                               'archivelist',
-                                                               'archivedaylist',
-                                                               'archiveyearlist',
-                                                               'categorylist',
-                                                               'blogsetting',
-                                                          );
-                               break;
-                       case 'search':
-                               $extraActions = array('blog',
-                                                               'archivelist',
-                                                               'archivedaylist',
-                                                               'archiveyearlist',
-                                                               'categorylist',
-                                                               'searchresults',
-                                                               'othersearchresults',
-                                                               'blogsetting',
-                                                               'query',
-                                                               'nextlink',
-                                                               'prevlink'
-                                                               );
-                               break;
-                       case 'imagepopup':
-                               $extraActions = array('image',
-                                                               // deprecated (Nucleus v2.0)
-                                                               'imagetext',
-                                                               );
-                               break;
-                       case 'member':
-                               $extraActions = array(
-                                                               'membermailform',
-                                                               'blogsetting',
-                                                               'nucleusbutton',
-                                                               'categorylist'
-                               );
-                               break;
-                       case 'item':
-                               $extraActions = array('blog',
-                                                               'item',
-                                                               'comments',
-                                                               'commentform',
-                                                               'vars',
-                                                               'blogsetting',
-                                                               'nextitem',
-                                                               'previtem',
-                                                               'nextlink',
-                                                               'prevlink',
-                                                               'nextitemtitle',
-                                                               'previtemtitle',
-                                                               'categorylist',
-                                                               'archivelist',
-                                                               'archivedaylist',
-                                                               'archiveyearlist',
-                                                               'itemtitle',
-                                                               'itemid',
-                                                               'itemlink',
-                                                               );
-                               break;
-                       case 'error':
-                               $extraActions = array(
-                                                               'errormessage',
-                                                               'categorylist'
-                               );
-                               break;
-                       default:
-                               if ( $blogid && $blogid > 0 )
-                               {
-                                       $extraActions = array(
-                                               'blog',
-                                               'blogsetting',
-                                               'preview',
-                                               'additemform',
-                                               'categorylist',
-                                               'archivelist',
-                                               'archivedaylist',
-                                               'archiveyearlist',
-                                               'nextlink',
-                                               'prevlink',
-                                               'membermailform',
-                                               'nucleusbutton',
-                                               'categorylist'
-                                       );
-                               }
-                               break;
+                       $friendly_names[strtolower($row['stype'])] = $row['stype'];
                }
-               return array_merge($defaultActions, $extraActions);
+               return $friendly_names;
        }
 }