OSDN Git Service

主だったスクリプトの改行コードを統一
[nucleus-jp/nucleus-next.git] / nucleus / libs / SKIN.php
index 652b726..107b20e 100644 (file)
-<?php
-/*
- * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2009 The Nucleus Group
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * (see nucleus/documentation/index.html#license for more info)
- */
-/**
- * Class representing a skin
- *
- * @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 $
- */
-
-if ( !function_exists('requestVar') ) 
-{
-       exit;
-}
-require_once dirname(__FILE__) . '/ACTIONS.php';
-
-class SKIN {
-       
-       // after creating a SKIN object, evaluates to true when the skin exists
-       var $isValid;
-       
-       // 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;
-       
-       /**
-        * Constructor for a new SKIN object
-        * 
-        * @param $id 
-        *                      id of the skin
-        */
-       function SKIN($id)
-       {
-               $this->id = intval($id);
-               
-               // read skin name/description/content type
-               $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
-               $obj = sql_fetch_object($res);
-               $this->isValid = (sql_num_rows($res) > 0);
-               if ( !$this->isValid )
-               {
-                       return;
-               }
-               
-               $this->name = $obj->sdname;
-               $this->description = $obj->sddesc;
-               $this->contentType = $obj->sdtype;
-               $this->includeMode = $obj->sdincmode;
-               $this->includePrefix = $obj->sdincpref;
-
-       }
-       
-       /**
-        * Get SKIN id
-        */
-       function getID()
-       {
-               return $this->id;
-       }
-       
-       /**
-        * Get SKIN name
-        */
-       function getName()
-       {
-               return $this->name;
-       }
-       
-       /**
-        * Get SKIN description
-        */
-       function getDescription()
-       {
-               return $this->description;
-       }
-       
-       /**
-        * Get SKIN content type
-        * 
-        * e.g. text/xml, text/html, application/atom+xml
-        */
-       function getContentType()
-       {
-               return $this->contentType;
-       }
-       
-       /**
-        * 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
-        */
-       function getIncludeMode()
-       {
-               return $this->includeMode;
-       }
-       
-       /**
-        * 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/')
-        */
-       function getIncludePrefix()
-       {
-               return $this->includePrefix;
-       }
-       
-       /**
-        * 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
-        */
-       function exists($name)
-       {
-               return quickQuery('select count(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdname="' . sql_real_escape_string($name) . '"') > 0;
-       }
-       
-       /**
-        * Checks if a skin with a given ID exists
-        * @param string $id Skin ID
-        * @return int number of skins with the given ID
-        * @static
-        */
-       function existsID($id)
-       {
-               return quickQuery('select COUNT(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id)) > 0;
-       }
-       
-       /**
-        * Returns a skin given its shortname
-        * @param string $name Skin shortname
-        * @return object SKIN
-        * @static
-        */
-       function createFromName($name)
-       {
-               return new SKIN(SKIN::getIdFromName($name));
-       }
-       
-       /**
-        * Returns a skin ID given its shortname
-        * @param string $name Skin shortname
-        * @return int Skin ID
-        * @static
-        */
-       function getIdFromName($name)
-       {
-               $query =  'SELECT sdnumber'
-                               . ' FROM ' . sql_table('skin_desc')
-                               . ' WHERE sdname="' . sql_real_escape_string($name) . '"';
-               $res = sql_query($query);
-               $obj = sql_fetch_object($res);
-               return $obj->sdnumber;
-       }
-       
-       /**
-        * Returns a skin shortname given its ID
-        * @param string $name
-        * @return string Skin short name
-        * @static
-        */
-       function getNameFromId($id)
-       {
-               return quickQuery('SELECT sdname as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id));
-       }
-       
-       /**
-        * SKIN::createNew()
-        * Creates a new skin, with the given characteristics.
-        *
-        * @static
-        * @param       String  $name   value for nucleus_skin.sdname
-        * @param       String  $desc   value for nucleus_skin.sddesc
-        * @param       String  $type   value for nucleus_skin.sdtype
-        * @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 = '')
-       {
-               global $manager;
-               
-               $manager->notify(
-                       'PreAddSkin',
-                       array(
-                               'name' => &$name,
-                               'description' => &$desc,
-                               'type' => &$type,
-                               'includeMode' => &$includeMode,
-                               'includePrefix' => &$includePrefix
-                       )
-               );
-               
-               $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));
-               sql_query($query);
-               $newid = sql_insert_id();
-               
-               $manager->notify(
-                       'PostAddSkin',
-                       array(
-                               'skinid' => $newid,
-                               'name' => $name,
-                               'description' => $desc,
-                               'type' => $type,
-                               'includeMode' => $includeMode,
-                               'includePrefix' => $includePrefix
-                       )
-               );
-               return $newid;
-       }
-       
-       /**
-        * Parse a SKIN
-        * 
-        * @param string $type
-        */
-       function parse($type)
-       {
-               global $manager, $CONF;
-               
-               $manager->notify('InitSkinParse',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);
-               
-               if ( !$contents )
-               {
-                       // use base skin if this skin does not have contents
-                       $defskin = new SKIN($CONF['BaseSkin']);
-                       $contents = $defskin->getContent($type);
-                       if ( !$contents )
-                       {
-                               echo _ERROR_SKIN;
-                               return;
-                       }
-               }
-               
-               $actions = $this->getAllowedActionsForType($type);
-               
-               $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
-               
-               // set IncludeMode properties of parser
-               PARSER::setProperty('IncludeMode',$this->getIncludeMode());
-               PARSER::setProperty('IncludePrefix',$this->getIncludePrefix());
-               
-               $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));
-       }
-       
-       /**
-        * Get content of the skin part from the database
-        * 
-        * @param $type type of the skin (e.g. index, item, search ...)
-        */
-       function getContent($type)
-       {
-               $query = 'SELECT scontent FROM '. sql_table('skin') . " WHERE sdesc=$this->id and stype='" . sql_real_escape_string($type) . "'";
-               $res = sql_query($query);
-               
-               if ( sql_num_rows($res) == 0 )
-               {
-                       return '';
-               }
-               else
-               {
-                       return sql_result($res, 0, 0);
-               }
-       }
-
-       /**
-        * 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
-        * 
-        */
-       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);
-               $res = sql_query($query);
-               
-               $skintypeexists = sql_fetch_object($res);
-               $skintypevalue = ($content == true);
-               
-               if( $skintypevalue && $skintypeexists )
-               {
-                       // PreUpdateSkinPart event
-                       $manager->notify(
-                               'PreUpdateSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
-                       );
-               }
-               else if( $skintypevalue && (!$skintypeexists) )
-               {
-                       // PreAddSkinPart event
-                       $manager->notify(
-                               'PreAddSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
-                       );
-               }
-               else if( (!$skintypevalue) && $skintypeexists )
-               {
-                       // PreDeleteSkinPart event
-                       $manager->notify(
-                               'PreDeleteSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type
-                               )
-                       );
-               }
-               
-               // 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);
-               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);
-                       sql_query($query);
-               }
-               
-               if( $skintypevalue && $skintypeexists )
-               {
-                       // PostUpdateSkinPart event
-                       $manager->notify(
-                       'PostUpdateSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
-                       );
-               }
-               else if( $skintypevalue && (!$skintypeexists) )
-               {
-                       // PostAddSkinPart event
-                       $manager->notify(
-                               'PostAddSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type,
-                                       'content' => &$content
-                               )
-                       );
-               }
-               else if( (!$skintypevalue) && $skintypeexists )
-               {
-                       // PostDeleteSkinPart event
-                       $manager->notify(
-                               'PostDeleteSkinPart',
-                               array(
-                                       'skinid' => $skinid,
-                                       'type' => $type
-                               )
-                       );
-               }
-               return;
-       }
-       
-       /**
-        * Deletes all skin parts from the database
-        */
-       function deleteAllParts()
-       {
-               sql_query('DELETE FROM ' . sql_table('skin') . ' WHERE sdesc=' . $this->getID());
-       }
-
-       /**
-        * Updates the general information about the skin
-        */
-       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();
-               sql_query($query);
-       }
-       
-       /**
-        * Get an array with the names of possible skin parts
-        * Used to show all possible parts of a skin in the administration backend
-        * 
-        * static: returns an array of friendly names
-        */
-       function getFriendlyNames()
-       {
-               $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;
-       }
-
-       /**
-        * Get the allowed actions for a skin type
-        * returns an array with the allowed actions
-        * 
-        * @param $type type of the skin (e.g. index, item, search ...)
-        */
-       function getAllowedActionsForType($type)
-       {
-               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 )
-               {
-                       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;
-               }
-               return array_merge($defaultActions, $extraActions);
-       }
-}
+<?php\r
+/*\r
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
+ * Copyright (C) 2002-2009 The Nucleus Group\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * (see nucleus/documentation/index.html#license for more info)\r
+ */\r
+/**\r
+ * Class representing a skin\r
+ *\r
+ * @license http://nucleuscms.org/license.txt GNU General Public License\r
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
+ * @version $Id: SKIN.php 1621 2012-01-09 02:49:37Z sakamocchi $\r
+ */\r
+\r
+if ( !function_exists('requestVar') ) \r
+{\r
+       exit;\r
+}\r
+require_once dirname(__FILE__) . '/ACTIONS.php';\r
+\r
+class SKIN {\r
+       \r
+       // after creating a SKIN object, evaluates to true when the skin exists\r
+       var $isValid;\r
+       \r
+       // skin characteristics. Use the getXXX methods rather than accessing directly\r
+       var $id;\r
+       var $description;\r
+       var $contentType;\r
+       var $includeMode;               // either 'normal' or 'skindir'\r
+       var $includePrefix;\r
+       var $name;\r
+       \r
+       /**\r
+        * Constructor for a new SKIN object\r
+        * \r
+        * @param $id \r
+        *                      id of the skin\r
+        */\r
+       function SKIN($id)\r
+       {\r
+               $this->id = intval($id);\r
+               \r
+               // read skin name/description/content type\r
+               $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);\r
+               $obj = sql_fetch_object($res);\r
+               $this->isValid = (sql_num_rows($res) > 0);\r
+               if ( !$this->isValid )\r
+               {\r
+                       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
+       }\r
+       \r
+       /**\r
+        * Get SKIN id\r
+        */\r
+       function getID()\r
+       {\r
+               return $this->id;\r
+       }\r
+       \r
+       /**\r
+        * Get SKIN name\r
+        */\r
+       function getName()\r
+       {\r
+               return $this->name;\r
+       }\r
+       \r
+       /**\r
+        * Get SKIN description\r
+        */\r
+       function getDescription()\r
+       {\r
+               return $this->description;\r
+       }\r
+       \r
+       /**\r
+        * Get SKIN content type\r
+        * \r
+        * e.g. text/xml, text/html, application/atom+xml\r
+        */\r
+       function getContentType()\r
+       {\r
+               return $this->contentType;\r
+       }\r
+       \r
+       /**\r
+        * Get include mode of the SKIN\r
+        * \r
+        * Returns either 'normal' or 'skindir':\r
+        * 'normal': if a all data of the skin can be found in the databse\r
+        * 'skindir': if the skin has data in the it's skin driectory\r
+        */\r
+       function getIncludeMode()\r
+       {\r
+               return $this->includeMode;\r
+       }\r
+       \r
+       /**\r
+        * Get include prefix of the SKIN\r
+        * \r
+        * Get name of the subdirectory (with trailing slash) where\r
+        * the files of the current skin can be found (e.g. 'default/')\r
+        */\r
+       function getIncludePrefix()\r
+       {\r
+               return $this->includePrefix;\r
+       }\r
+       \r
+       /**\r
+        * Checks if a skin with a given shortname exists\r
+        * @param string $name Skin short name\r
+        * @return int number of skins with the given ID\r
+        * @static\r
+        */\r
+       function exists($name)\r
+       {\r
+               return quickQuery('select count(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdname="' . sql_real_escape_string($name) . '"') > 0;\r
+       }\r
+       \r
+       /**\r
+        * Checks if a skin with a given ID exists\r
+        * @param string $id Skin ID\r
+        * @return int number of skins with the given ID\r
+        * @static\r
+        */\r
+       function existsID($id)\r
+       {\r
+               return quickQuery('select COUNT(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id)) > 0;\r
+       }\r
+       \r
+       /**\r
+        * Returns a skin given its shortname\r
+        * @param string $name Skin shortname\r
+        * @return object SKIN\r
+        * @static\r
+        */\r
+       function createFromName($name)\r
+       {\r
+               return new SKIN(SKIN::getIdFromName($name));\r
+       }\r
+       \r
+       /**\r
+        * Returns a skin ID given its shortname\r
+        * @param string $name Skin shortname\r
+        * @return int Skin ID\r
+        * @static\r
+        */\r
+       function getIdFromName($name)\r
+       {\r
+               $query =  'SELECT sdnumber'\r
+                               . ' FROM ' . sql_table('skin_desc')\r
+                               . ' WHERE sdname="' . sql_real_escape_string($name) . '"';\r
+               $res = sql_query($query);\r
+               $obj = sql_fetch_object($res);\r
+               return $obj->sdnumber;\r
+       }\r
+       \r
+       /**\r
+        * Returns a skin shortname given its ID\r
+        * @param string $name\r
+        * @return string Skin short name\r
+        * @static\r
+        */\r
+       function getNameFromId($id)\r
+       {\r
+               return quickQuery('SELECT sdname as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id));\r
+       }\r
+       \r
+       /**\r
+        * SKIN::createNew()\r
+        * Creates a new skin, with the given characteristics.\r
+        *\r
+        * @static\r
+        * @param       String  $name   value for nucleus_skin.sdname\r
+        * @param       String  $desc   value for nucleus_skin.sddesc\r
+        * @param       String  $type   value for nucleus_skin.sdtype\r
+        * @param       String  $includeMode    value for nucleus_skin.sdinclude\r
+        * @param       String  $includePrefix  value for nucleus_skin.sdincpref\r
+        * @return      Integer ID for just inserted record\r
+        * \r
+        */\r
+       function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')\r
+       {\r
+               global $manager;\r
+               \r
+               $manager->notify(\r
+                       'PreAddSkin',\r
+                       array(\r
+                               'name' => &$name,\r
+                               'description' => &$desc,\r
+                               'type' => &$type,\r
+                               'includeMode' => &$includeMode,\r
+                               'includePrefix' => &$includePrefix\r
+                       )\r
+               );\r
+               \r
+               $query = "INSERT INTO %s (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('%s', '%s', '%s', '%s', '%s')";\r
+               $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));\r
+               sql_query($query);\r
+               $newid = sql_insert_id();\r
+               \r
+               $manager->notify(\r
+                       'PostAddSkin',\r
+                       array(\r
+                               'skinid' => $newid,\r
+                               'name' => $name,\r
+                               'description' => $desc,\r
+                               'type' => $type,\r
+                               'includeMode' => $includeMode,\r
+                               'includePrefix' => $includePrefix\r
+                       )\r
+               );\r
+               return $newid;\r
+       }\r
+       \r
+       /**\r
+        * Parse a SKIN\r
+        * \r
+        * @param string $type\r
+        */\r
+       function parse($type)\r
+       {\r
+               global $manager, $CONF;\r
+               \r
+               $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));\r
+               \r
+               // set output type\r
+               sendContentType($this->getContentType(), 'skin');\r
+               \r
+               // set skin name as global var (so plugins can access it)\r
+               global $currentSkinName;\r
+               $currentSkinName = $this->getName();\r
+               \r
+               $contents = $this->getContent($type);\r
+               \r
+               if ( !$contents )\r
+               {\r
+                       // use base skin if this skin does not have contents\r
+                       $defskin = new SKIN($CONF['BaseSkin']);\r
+                       $contents = $defskin->getContent($type);\r
+                       if ( !$contents )\r
+                       {\r
+                               echo _ERROR_SKIN;\r
+                               return;\r
+                       }\r
+               }\r
+               \r
+               $actions = $this->getAllowedActionsForType($type);\r
+               \r
+               $manager->notify('PreSkinParse',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
+               $handler = new ACTIONS($type, $this);\r
+               $parser = new PARSER($actions, $handler);\r
+               $handler->setParser($parser);\r
+               $handler->setSkin($this);\r
+               $parser->parse($contents);\r
+               \r
+               $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));\r
+       }\r
+       \r
+       /**\r
+        * Get content of the skin part from the database\r
+        * \r
+        * @param $type type of the skin (e.g. index, item, search ...)\r
+        */\r
+       function getContent($type)\r
+       {\r
+               $query = 'SELECT scontent FROM '. sql_table('skin') . " WHERE sdesc=$this->id and stype='" . sql_real_escape_string($type) . "'";\r
+               $res = sql_query($query);\r
+               \r
+               if ( sql_num_rows($res) == 0 )\r
+               {\r
+                       return '';\r
+               }\r
+               else\r
+               {\r
+                       return sql_result($res, 0, 0);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * SKIN::update()\r
+        * Updates the contents for one part of the skin in the database\r
+        * \r
+        * @param $type type of the skin part (e.g. index, item, search ...) \r
+        * @param $content new content for this skin part\r
+        * @return      Void\r
+        * \r
+        */\r
+       function update($type, $content)\r
+       {\r
+               global $manager;\r
+               \r
+               $skinid = $this->id;\r
+               \r
+               $query = "SELECT sdesc FROM %s WHERE stype='%s' and sdesc=%d";\r
+               $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $skinid);\r
+               $res = sql_query($query);\r
+               \r
+               $skintypeexists = sql_fetch_object($res);\r
+               $skintypevalue = ($content == true);\r
+               \r
+               if( $skintypevalue && $skintypeexists )\r
+               {\r
+                       // PreUpdateSkinPart event\r
+                       $manager->notify(\r
+                               'PreUpdateSkinPart',\r
+                               array(\r
+                                       'skinid' => $skinid,\r
+                                       'type' => $type,\r
+                                       'content' => &$content\r
+                               )\r
+                       );\r
+               }\r
+               else if( $skintypevalue && (!$skintypeexists) )\r
+               {\r
+                       // PreAddSkinPart event\r
+                       $manager->notify(\r
+                               'PreAddSkinPart',\r
+                               array(\r
+                                       'skinid' => $skinid,\r
+                                       'type' => $type,\r
+                                       'content' => &$content\r
+                               )\r
+                       );\r
+               }\r
+               else if( (!$skintypevalue) && $skintypeexists )\r
+               {\r
+                       // PreDeleteSkinPart event\r
+                       $manager->notify(\r
+                               'PreDeleteSkinPart',\r
+                               array(\r
+                                       'skinid' => $skinid,\r
+                                       'type' => $type\r
+                               )\r
+                       );\r
+               }\r
+               \r
+               // delete old thingie\r
+               $query = "DELETE FROM %s WHERE stype='%s' and sdesc=%d";\r
+               $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $skinid);\r
+               sql_query($query);\r
+               \r
+               // write new thingie\r
+               if ( $content )\r
+               {\r
+                       $query = "INSERT INTO %s (scontent, stype, sdesc) VALUE ('%s', '%s', %d)";\r
+                       $query = sprintf($query, sql_table('skin'), sql_real_escape_string($content), sql_real_escape_string($type), (integer) $skinid);\r
+                       sql_query($query);\r
+               }\r
+               \r
+               if( $skintypevalue && $skintypeexists )\r
+               {\r
+                       // PostUpdateSkinPart event\r
+                       $manager->notify(\r
+                       'PostUpdateSkinPart',\r
+                               array(\r
+                                       'skinid' => $skinid,\r
+                                       'type' => $type,\r
+                                       'content' => &$content\r
+                               )\r
+                       );\r
+               }\r
+               else if( $skintypevalue && (!$skintypeexists) )\r
+               {\r
+                       // PostAddSkinPart event\r
+                       $manager->notify(\r
+                               'PostAddSkinPart',\r
+                               array(\r
+                                       'skinid' => $skinid,\r
+                                       'type' => $type,\r
+                                       'content' => &$content\r
+                               )\r
+                       );\r
+               }\r
+               else if( (!$skintypevalue) && $skintypeexists )\r
+               {\r
+                       // PostDeleteSkinPart event\r
+                       $manager->notify(\r
+                               'PostDeleteSkinPart',\r
+                               array(\r
+                                       'skinid' => $skinid,\r
+                                       'type' => $type\r
+                               )\r
+                       );\r
+               }\r
+               return;\r
+       }\r
+       \r
+       /**\r
+        * Deletes all skin parts from the database\r
+        */\r
+       function deleteAllParts()\r
+       {\r
+               sql_query('DELETE FROM ' . sql_table('skin') . ' WHERE sdesc=' . $this->getID());\r
+       }\r
+\r
+       /**\r
+        * Updates the general information about the skin\r
+        */\r
+       function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')\r
+       {\r
+               $query =  'UPDATE '.sql_table('skin_desc').' SET'\r
+                          . " sdname='" . sql_real_escape_string($name) . "',"\r
+                          . " sddesc='" . sql_real_escape_string($desc) . "',"\r
+                          . " sdtype='" . sql_real_escape_string($type) . "',"\r
+                          . " sdincmode='" . sql_real_escape_string($includeMode) . "',"\r
+                          . " sdincpref='" . sql_real_escape_string($includePrefix) . "'"\r
+                          . " WHERE sdnumber=" . $this->getID();\r
+               sql_query($query);\r
+       }\r
+       \r
+       /**\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
+        * static: returns an array of friendly names\r
+        */\r
+       function getFriendlyNames()\r
+       {\r
+               $skintypes = array(\r
+                       'index' => _SKIN_PART_MAIN,\r
+                       'item' => _SKIN_PART_ITEM,\r
+                       'archivelist' => _SKIN_PART_ALIST,\r
+                       'archive' => _SKIN_PART_ARCHIVE,\r
+                       'search' => _SKIN_PART_SEARCH,\r
+                       'error' => _SKIN_PART_ERROR,\r
+                       'member' => _SKIN_PART_MEMBER,\r
+                       'imagepopup' => _SKIN_PART_POPUP\r
+               );\r
+               \r
+               $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";\r
+               $res = sql_query($query);\r
+               while ( $row = sql_fetch_array($res) )\r
+               {\r
+                       $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);\r
+               }\r
+               return $skintypes;\r
+       }\r
+\r
+       /**\r
+        * Get the allowed actions for a skin type\r
+        * returns an array with the allowed actions\r
+        * \r
+        * @param $type type of the skin (e.g. index, item, search ...)\r
+        */\r
+       function getAllowedActionsForType($type)\r
+       {\r
+               global $blogid;\r
+               \r
+               // some actions that can be performed at any time, from anywhere\r
+               $defaultActions = array('otherblog',\r
+                                                               'plugin',\r
+                                                               'version',\r
+                                                               'nucleusbutton',\r
+                                                               'include',\r
+                                                               'phpinclude',\r
+                                                               'parsedinclude',\r
+                                                               'loginform',\r
+                                                               'sitevar',\r
+                                                               'otherarchivelist',\r
+                                                               'otherarchivedaylist',\r
+                                                               'otherarchiveyearlist',\r
+                                                               'self',\r
+                                                               'adminurl',\r
+                                                               'todaylink',\r
+                                                               'archivelink',\r
+                                                               'member',\r
+                                                               'category',\r
+                                                               'searchform',\r
+                                                               'referer',\r
+                                                               'skinname',\r
+                                                               'skinfile',\r
+                                                               'set',\r
+                                                               'if',\r
+                                                               'else',\r
+                                                               'endif',\r
+                                                               'elseif',\r
+                                                               'ifnot',\r
+                                                               'elseifnot',\r
+                                                               'charset',\r
+                                                               'bloglist',\r
+                                                               'addlink',\r
+                                                               'addpopupcode',\r
+                                                               'sticky',\r
+                                                               // deprecated (Nucleus v2.0)\r
+                                                               'ifcat'\r
+                                                               );\r
+               \r
+               // extra actions specific for a certain skin type\r
+               $extraActions = array();\r
+               \r
+               switch ( $type )\r
+               {\r
+                       case 'index':\r
+                               $extraActions = array('blog',\r
+                                                               'blogsetting',\r
+                                                               'preview',\r
+                                                               'additemform',\r
+                                                               'categorylist',\r
+                                                               'archivelist',\r
+                                                               'archivedaylist',\r
+                                                               'archiveyearlist',\r
+                                                               'nextlink',\r
+                                                               'prevlink'\r
+                                                               );\r
+                               break;\r
+                       case 'archive':\r
+                               $extraActions = array('blog',\r
+                                                               'archive',\r
+                                                               'otherarchive',\r
+                                                               'categorylist',\r
+                                                               'archivelist',\r
+                                                               'archivedaylist',\r
+                                                               'archiveyearlist',\r
+                                                               'blogsetting',\r
+                                                               'archivedate',\r
+                                                               'nextarchive',\r
+                                                               'prevarchive',\r
+                                                               'nextlink',\r
+                                                               'prevlink',\r
+                                                               'archivetype'\r
+                               );\r
+                               break;\r
+                       case 'archivelist':\r
+                               $extraActions = array('blog',\r
+                                                               'archivelist',\r
+                                                               'archivedaylist',\r
+                                                               'archiveyearlist',\r
+                                                               'categorylist',\r
+                                                               'blogsetting',\r
+                                                          );\r
+                               break;\r
+                       case 'search':\r
+                               $extraActions = array('blog',\r
+                                                               'archivelist',\r
+                                                               'archivedaylist',\r
+                                                               'archiveyearlist',\r
+                                                               'categorylist',\r
+                                                               'searchresults',\r
+                                                               'othersearchresults',\r
+                                                               'blogsetting',\r
+                                                               'query',\r
+                                                               'nextlink',\r
+                                                               'prevlink'\r
+                                                               );\r
+                               break;\r
+                       case 'imagepopup':\r
+                               $extraActions = array('image',\r
+                                                               // deprecated (Nucleus v2.0)\r
+                                                               'imagetext',\r
+                                                               );\r
+                               break;\r
+                       case 'member':\r
+                               $extraActions = array(\r
+                                                               'membermailform',\r
+                                                               'blogsetting',\r
+                                                               'nucleusbutton',\r
+                                                               'categorylist'\r
+                               );\r
+                               break;\r
+                       case 'item':\r
+                               $extraActions = array('blog',\r
+                                                               'item',\r
+                                                               'comments',\r
+                                                               'commentform',\r
+                                                               'vars',\r
+                                                               'blogsetting',\r
+                                                               'nextitem',\r
+                                                               'previtem',\r
+                                                               'nextlink',\r
+                                                               'prevlink',\r
+                                                               'nextitemtitle',\r
+                                                               'previtemtitle',\r
+                                                               'categorylist',\r
+                                                               'archivelist',\r
+                                                               'archivedaylist',\r
+                                                               'archiveyearlist',\r
+                                                               'itemtitle',\r
+                                                               'itemid',\r
+                                                               'itemlink',\r
+                                                               );\r
+                               break;\r
+                       case 'error':\r
+                               $extraActions = array(\r
+                                                               'errormessage',\r
+                                                               'categorylist'\r
+                               );\r
+                               break;\r
+                       default:\r
+                               if ( $blogid && $blogid > 0 )\r
+                               {\r
+                                       $extraActions = array(\r
+                                               'blog',\r
+                                               'blogsetting',\r
+                                               'preview',\r
+                                               'additemform',\r
+                                               'categorylist',\r
+                                               'archivelist',\r
+                                               'archivedaylist',\r
+                                               'archiveyearlist',\r
+                                               'nextlink',\r
+                                               'prevlink',\r
+                                               'membermailform',\r
+                                               'nucleusbutton',\r
+                                               'categorylist'\r
+                                       );\r
+                               }\r
+                               break;\r
+               }\r
+               return array_merge($defaultActions, $extraActions);\r
+       }\r
+}\r