OSDN Git Service

Add some codes from 3.61. Currently files under /nucleus/libs and /nucleus/libs/sql...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / SKIN.php
index ab6ab19..7a48b60 100755 (executable)
-<?php\r
-\r
-\r
-/**\r
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
-  * Copyright (C) 2002-2004 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
-  * Class representing a skin\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
-       function SKIN($id) {\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 = mysql_fetch_object($res);\r
-               $this->isValid = (mysql_num_rows($res) > 0);\r
-               if (!$this->isValid)\r
-                       return;\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
-       function getID() {                              return $this->id; }\r
-       function getName() {                    return $this->name; }\r
-       function getDescription() {     return $this->description; }\r
-       function getContentType() {     return $this->contentType; }\r
-       function getIncludeMode() {     return $this->includeMode; }\r
-       function getIncludePrefix() {   return $this->includePrefix; }\r
-       \r
-       // returns true if there is a skin with the given shortname (static)\r
-       function exists($name) {\r
-               return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.addslashes($name).'"') > 0;\r
-       }\r
-\r
-       // returns true if there is a skin with the given ID (static)\r
-       function existsID($id) {\r
-               return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0;\r
-       }       \r
-       \r
-       // (static)\r
-       function createFromName($name) {\r
-               return new SKIN(SKIN::getIdFromName($name));\r
-       }       \r
-       \r
-       // (static)\r
-       function getIdFromName($name) {\r
-               $query =  'SELECT sdnumber'\r
-                      . ' FROM '.sql_table('skin_desc')\r
-                      . ' WHERE sdname="'.addslashes($name).'"';\r
-               $res = sql_query($query);\r
-               $obj = mysql_fetch_object($res);\r
-               return $obj->sdnumber;  \r
-       }\r
-       \r
-       // (static)\r
-       function getNameFromId($id) {\r
-               return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id));\r
-       }\r
-       \r
-       /**\r
-        * Creates a new skin, with the given characteristics.\r
-        *\r
-        * (static)\r
-        */\r
-       function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {\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
-               sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "','".addslashes($type)."','".addslashes($includeMode)."','".addslashes($includePrefix)."')");\r
-               $newid = mysql_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
-               \r
-               return $newid;\r
-       }\r
-       \r
-       function parse($type) {\r
-               global $manager, $CONF;\r
-\r
-               // set output type\r
-               sendContentType($this->getContentType(), 'skin', _CHARSET);\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
-                       // 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
-                               echo _ERROR_SKIN;\r
-                               return;\r
-                       }\r
-               }\r
-\r
-               $actions = $this->getAllowedActionsForType($type);\r
-\r
-               $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type));\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
-\r
-       function getContent($type) {\r
-               $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". addslashes($type) ."'";\r
-               $res = sql_query($query);\r
-\r
-               if (mysql_num_rows($res) == 0)\r
-                       return '';\r
-               else\r
-                       return mysql_result($res, 0, 0);\r
-       }\r
-\r
-       /**\r
-        * Updates the contents of one part of the skin\r
-        */\r
-       function update($type, $content) {\r
-               $skinid = $this->id;\r
-               $content = trim($content);\r
-\r
-               // delete old thingie\r
-               sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".addslashes($type)."' and sdesc=" . intval($skinid));\r
-\r
-               // write new thingie\r
-               if ($content) {\r
-                       sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . addslashes($content) . "', stype='" . addslashes($type) . "', sdesc=" . intval($skinid));\r
-               }       \r
-       }\r
-       \r
-       /**\r
-        * Deletes all skin parts from the database\r
-        */\r
-       function deleteAllParts() {\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
-               $query =  'UPDATE '.sql_table('skin_desc').' SET'\r
-                      . " sdname='" . addslashes($name) . "',"\r
-                      . " sddesc='" . addslashes($desc) . "',"\r
-                      . " sdtype='" . addslashes($type) . "',"\r
-                          . " sdincmode='" . addslashes($includeMode) . "',"\r
-                          . " sdincpref='" . addslashes($includePrefix) . "'"                 \r
-                      . " WHERE sdnumber=" . $this->getID();\r
-               sql_query($query);              \r
-       }\r
-       \r
-       /**\r
-        * static: returns an array of friendly names\r
-        */\r
-       function getFriendlyNames() {\r
-               return 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
-       \r
-       function getAllowedActionsForType($type) {\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
-                                                               'self',\r
-                                                               'adminurl',\r
-                                                               'todaylink',\r
-                                                               'archivelink',\r
-                                                               'member',\r
-                                                               'ifcat',                                        // deprecated (Nucleus v2.0)\r
-                                                               'category',\r
-                                                               'searchform',\r
-                                                               'referer',\r
-                                                               'skinname',\r
-                                                               'skinfile',\r
-                                                               'set',\r
-                                                               'if',\r
-                                                               'else',\r
-                                                               'endif'\r
-                                                               );\r
-               \r
-               // extra actions specific for a certain skin type\r
-               $extraActions = array();\r
-\r
-               switch ($type) {\r
-                       case 'index':\r
-                               $extraActions = array('blog', \r
-                                                   'blogsetting',\r
-                                                   'preview',\r
-                                                   'additemform',\r
-                                                               'categorylist',                                             \r
-                                                   'archivelist',\r
-                                                   'archivedaylist',\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
-                                                               '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
-                                                               'categorylist',\r
-                                                           'blogsetting',\r
-                                                          );\r
-                               break;\r
-                       case 'search':\r
-                               $extraActions = array('blog',\r
-                                                               'archivelist',\r
-                                                   'archivedaylist',\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
-                                                               'imagetext',                            // deprecated (Nucleus v2.0)\r
-                                                               );\r
-                               break;\r
-                       case 'member':\r
-                               $extraActions = array(\r
-                                                               'membermailform',\r
-                                                               'blogsetting',\r
-                                                               'nucleusbutton'\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
-                                                           'itemtitle',\r
-                                                           'itemid',\r
-                                                           'itemlink',\r
-                                                           );\r
-                               break;\r
-                       case 'error':\r
-                               $extraActions = array(\r
-                                                               'errormessage'\r
-                               );\r
-                               break;\r
-               }\r
-               return array_merge($defaultActions, $extraActions);\r
-       }\r
-       \r
-}\r
-\r
-\r
-/*\r
- * This class contains the functions that get called by using\r
- * the special tags in the skins\r
- *\r
- * The allowed tags for a type of skinpart are defined by the \r
- * SKIN::getAllowedActionsForType($type) method\r
- */\r
-class ACTIONS extends BaseActions {\r
-\r
-       // part of the skin currently being parsed ('index', 'item', 'archive',\r
-       // 'archivelist', 'member', 'search', 'error', 'imagepopup')\r
-       var $skintype;\r
-       \r
-       // contains an assoc array with parameters that need to be included when\r
-       // generating links to items/archives/... (e.g. catid)  \r
-       var $linkparams;\r
-       \r
-       // reference to the skin object for which a part is being parsed\r
-       var $skin;\r
-       \r
-\r
-       // used when including templated forms from the include/ dir. The $formdata var \r
-       // contains the values to fill out in there (assoc array name -> value)\r
-       var $formdata;\r
-       \r
-\r
-       // filled out with the number of displayed items after calling one of the \r
-\r
-       // (other)blog/(other)searchresults skinvars.\r
-\r
-       var $amountfound;\r
-\r
-       function ACTIONS($type) {\r
-               // call constructor of superclass first\r
-               $this->BaseActions();\r
-\r
-               $this->skintype = $type;\r
-\r
-               global $catid;\r
-               if ($catid) \r
-                       $this->linkparams = array('catid' => $catid);\r
-       }\r
-\r
-       function setSkin(&$skin) {\r
-               $this->skin =& $skin;\r
-       }\r
-       \r
-       function setParser(&$parser) {\r
-               $this->parser =& $parser;\r
-       }\r
-       \r
-       /*\r
-               Forms get parsedincluded now, using an extra <formdata> skinvar\r
-       */\r
-       function doForm($filename) {\r
-               global $DIR_NUCLEUS;\r
-               array_push($this->parser->actions,'formdata','text');\r
-               $oldIncludeMode = PARSER::getProperty('IncludeMode');\r
-               $oldIncludePrefix = PARSER::getProperty('IncludePrefix');\r
-               PARSER::setProperty('IncludeMode','normal');\r
-               PARSER::setProperty('IncludePrefix','');\r
-               $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');\r
-               PARSER::setProperty('IncludeMode',$oldIncludeMode);\r
-               PARSER::setProperty('IncludePrefix',$oldIncludePrefix);\r
-               array_pop($this->parser->actions);              \r
-               array_pop($this->parser->actions);              \r
-       }\r
-       function parse_formdata($what) {\r
-               echo $this->formdata[$what];\r
-       }\r
-       function parse_text($which) {\r
-               // constant($which) only available from 4.0.4 :(\r
-               if (defined($which)) {  \r
-                       eval("echo $which;");\r
-               }\r
-       }\r
-       \r
-       function parse_skinname() {\r
-               echo $this->skin->getName();\r
-       }\r
-       \r
-       function parse_if($field, $name='', $value = '') {\r
-               global $catid, $blog, $member, $itemidnext, $itemidprev, $manager;\r
-\r
-               $condition = 0;\r
-               switch($field) {\r
-                       case 'category':\r
-                               $condition = ($blog && $blog->isValidCategory($catid));\r
-                               break;\r
-                       case 'blogsetting':\r
-                               if ($name == 'trackback' && $manager->pluginInstalled('NP_TrackBack')) {\r
-                                       $plugin =& $manager->getPlugin('NP_TrackBack');\r
-                                       if ($plugin != NULL && $blog){\r
-                                               $bid = $blog->getID();\r
-                                               if ($value === '1') $value = 'yes';\r
-                                               if ($value === '0') $value = 'no';\r
-                                               if ($plugin->getOption('AcceptPing') == 'no' ) {\r
-                                                       $condition = ($value == 'no');\r
-                                                       } else {\r
-                                                       $tb_option = $plugin->getBlogOption($bid,'AllowTrackBack');\r
-                                                       if (!$tb_option) {\r
-                                                               $condition = ($value == 'yes');\r
-                                                       } else {\r
-                                                               $condition = ($tb_option == $value);\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       break;\r
-                               }\r
-                               $condition = ($blog && ($blog->getSetting($name) == $value));\r
-                               break;\r
-                       case 'loggedin':\r
-                               $condition = $member->isLoggedIn();\r
-                               break;\r
-                       case 'onteam':\r
-                               $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);\r
-                               break;\r
-                       case 'admin':\r
-                               $condition = $member->isLoggedIn() && $this->_ifAdmin($name);\r
-                               break;                          \r
-                       case 'nextitem':\r
-                               $condition = ($itemidnext != '');\r
-                               break;\r
-                       case 'previtem':\r
-                               $condition = ($itemidprev != ''); \r
-                               break;\r
-                       case 'skintype':\r
-                               $condition = ($name == $this->skintype);\r
-                               break;\r
-                       /*\r
-                               hasplugin,PlugName\r
-                                       -> checks if plugin exists\r
-                               hasplugin,PlugName,OptionName\r
-                                       -> checks if the option OptionName from plugin PlugName is not set to 'no'\r
-                               hasplugin,PlugName,OptionName=value\r
-                                       -> checks if the option OptionName from plugin PlugName is set to value\r
-                       */\r
-                       case 'hasplugin':\r
-                $condition = false;\r
-                // (pluginInstalled method won't write a message in the actionlog on failure)\r
-                if ($manager->pluginInstalled('NP_'.$name)) \r
-                {\r
-                       $plugin =& $manager->getPlugin('NP_' . $name);\r
-                       if ($plugin != NULL){\r
-                           if ($value == "") {\r
-                               $condition = true;\r
-                           } else {\r
-                               list($name2, $value2) = explode('=', $value, 2);\r
-                               if ($value2 == "" && $plugin->getOption($name2) != 'no') {\r
-                                   $condition = true;\r
-                               } else if ($plugin->getOption($name2) == $value2) {\r
-                                   $condition = true;\r
-                               }\r
-                           }\r
-                       }\r
-                }\r
-                break;                         \r
-                       default:        \r
-                               return;\r
-               }\r
-               $this->_addIfCondition($condition);\r
-       }\r
-       \r
-       function _ifOnTeam($blogName = '') {\r
-               global $blog, $member, $manager;\r
-               \r
-               // when no blog found\r
-               if (($blogName == '') && (!is_object($blog)))\r
-                       return 0;\r
-               \r
-               // explicit blog selection\r
-               if ($blogName != '') \r
-                       $blogid = getBlogIDFromName($blogName); \r
-               \r
-               if (($blogName == '') || !$manager->existsBlogID($blogid))\r
-                       // use current blog\r
-                       $blogid = $blog->getID();\r
-                       \r
-               return $member->teamRights($blogid);\r
-       }\r
-       \r
-       function _ifAdmin($blogName = '') {\r
-               global $blog, $member, $manager;\r
-\r
-               // when no blog found\r
-               if (($blogName == '') && (!is_object($blog)))\r
-                       return 0;\r
-\r
-               // explicit blog selection\r
-               if ($blogName != '')\r
-                       $blogid = getBlogIDFromName($blogName);\r
-\r
-               if (($blogName == '') || !$manager->existsBlogID($blogid))\r
-                       // use current blog\r
-                       $blogid = $blog->getID();\r
-\r
-               return $member->isBlogAdmin($blogid);\r
-       }       \r
-       \r
-       function parse_ifcat($text = '') {\r
-               if ($text == '') {\r
-                       // new behaviour\r
-                       $this->parse_if('category');\r
-               } else {\r
-                       // old behaviour\r
-                       global $catid, $blog;\r
-                       if ($blog->isValidCategory($catid))\r
-                               echo $text;\r
-               }\r
-       }\r
-       \r
-       // a link to the today page (depending on selected blog, etc...)\r
-       function parse_todaylink($linktext = '') {\r
-               global $blog, $CONF;\r
-               if ($blog)\r
-                       echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext);\r
-               else\r
-                       echo $this->_link($CONF['SiteUrl'], $linktext);\r
-       }\r
-       \r
-       // a link to the archives for the current blog (or for default blog)\r
-       function parse_archivelink($linktext = '') {\r
-               global $blog, $CONF;\r
-               if ($blog)\r
-                       echo $this->_link(createArchiveListLink($blog->getID(),$this->linkparams), $linktext);\r
-               else\r
-                       echo $this->_link(createArchiveListLink(), $linktext);\r
-       }\r
-\r
-       // include itemid of prev item\r
-       function parse_previtem() {\r
-               global $itemidprev;\r
-               echo $itemidprev;\r
-       }\r
-\r
-       // include itemtitle of prev item\r
-       function parse_previtemtitle() {\r
-               global $itemtitleprev;\r
-               echo htmlspecialchars($itemtitleprev);\r
-       }\r
-\r
-       // include itemid of next item\r
-       function parse_nextitem() {\r
-               global $itemidnext;\r
-               echo $itemidnext;\r
-       }\r
-\r
-       // include itemtitle of next item\r
-       function parse_nextitemtitle() {\r
-               global $itemtitlenext;\r
-               echo htmlspecialchars($itemtitlenext);\r
-       }\r
-\r
-       function parse_prevarchive() {\r
-               global $archiveprev;\r
-               echo $archiveprev;\r
-       }\r
-\r
-       function parse_nextarchive() {\r
-               global $archivenext;\r
-               echo $archivenext;\r
-       }\r
-\r
-       function parse_archivetype() {\r
-               global $archivetype;\r
-               echo $archivetype;\r
-       }\r
-\r
-       function parse_prevlink($linktext = '', $amount = 10) {\r
-               global $itemidprev, $archiveprev, $startpos;\r
-\r
-               if ($this->skintype == 'item')\r
-                       $this->_itemlink($itemidprev, $linktext);\r
-           else if ($this->skintype == 'search' || $this->skintype == 'index')\r
-               $this->_searchlink($amount, $startpos, 'prev', $linktext);\r
-               else\r
-                       $this->_archivelink($archiveprev, $linktext);\r
-       }\r
-       \r
-       function parse_nextlink($linktext = '', $amount = 10) {\r
-               global $itemidnext, $archivenext, $startpos;\r
-               if ($this->skintype == 'item')\r
-                       $this->_itemlink($itemidnext, $linktext);\r
-           else if ($this->skintype == 'search' || $this->skintype == 'index')\r
-               $this->_searchlink($amount, $startpos, 'next', $linktext);\r
-               else\r
-                       $this->_archivelink($archivenext, $linktext);\r
-       }\r
-       \r
-       /**\r
-        * returns either\r
-        *              - a raw link (html/xml encoded) when no linktext is provided\r
-        *              - a (x)html <a href... link when a text is present (text htmlencoded)\r
-        */\r
-       function _link($url, $linktext = '')\r
-       {\r
-               $u = htmlspecialchars($url);\r
-               $u = preg_replace("/&amp;amp;/",'&amp;',$u); // fix URLs that already had encoded ampersands\r
-               if ($linktext != '')\r
-                       $l = '<a href="' . $u .'">'.htmlspecialchars($linktext).'</a>';\r
-               else\r
-                       $l = $u;\r
-               return $l;      \r
-       }\r
-\r
-       /**\r
-        * Outputs a next/prev link\r
-        *\r
-        * @param $maxresults\r
-        *              The maximum amount of items shown per page (e.g. 10)\r
-        * @param $startpos\r
-        *              Current start position (requestVar('startpos'))\r
-        * @param $direction\r
-        *              either 'prev' or 'next'\r
-        * @param $linktext\r
-        *              When present, the output will be a full <a href...> link. When empty,\r
-        *              only a raw link will be outputted\r
-        */\r
-    function _searchlink($maxresults, $startpos, $direction, $linktext = '') {\r
-        global $CONF, $blog, $query, $amount;\r
-        // TODO: Move request uri to linkparams. this is ugly. sorry for that.\r
-        $startpos      = intval($startpos);            // will be 0 when empty. \r
-        $parsed                = parse_url(serverVar('REQUEST_URI'));\r
-        $parsed                = $parsed['query'];\r
-               $url            = '';\r
-        \r
-        switch ($direction) {\r
-            case 'prev':\r
-                if ( intval($startpos) - intval($maxresults) >= 0) {\r
-                    $startpos  = intval($startpos) - intval($maxresults);\r
-                    $url               = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);\r
-                }\r
-                break;\r
-            case 'next':\r
-                $iAmountOnPage = $this->amountfound;\r
-                if ($iAmountOnPage == 0)\r
-                {\r
-                       // [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]\r
-                       // try a count query\r
-                       switch ($this->skintype)\r
-                       {\r
-                               case 'index':\r
-                                       $sqlquery = $blog->getSqlBlog('', 'count');\r
-                                       break;\r
-                               case 'search':\r
-                                       $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');\r
-                                       break;\r
-                       }\r
-                       if ($sqlquery) \r
-                               $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);\r
-                }\r
-                if (intval($iAmountOnPage) >= intval($maxresults)) {\r
-                       $startpos       = intval($startpos) + intval($maxresults);                \r
-                       $url            = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);\r
-                }\r
-                break;\r
-            default:\r
-                break;\r
-        } // switch($direction)\r
-\r
-               if ($url != '')\r
-                       echo $this->_link($url, $linktext);        \r
-    }\r
-\r
-       function _itemlink($id, $linktext = '') {\r
-               global $CONF;\r
-               if ($id)\r
-                       echo $this->_link(createItemLink($id, $this->linkparams), $linktext);\r
-               else\r
-                       $this->parse_todaylink($linktext);\r
-       }\r
-\r
-       function _archivelink($id, $linktext = '') {\r
-               global $CONF, $blog;\r
-               if ($id)\r
-                       echo $this->_link(createArchiveLink($blog->getID(), $id, $this->linkparams), $linktext);\r
-               else\r
-                       $this->parse_todaylink($linktext);\r
-       }\r
-       \r
-       \r
-       function parse_itemlink($linktext = '') {       \r
-               $this->_itemlink($itemid, $linktext);\r
-       }\r
-       \r
-       /**\r
-         * %archivedate(locale,date format)%\r
-         */\r
-       function parse_archivedate($locale = '-def-') {\r
-               global $archive;\r
-               \r
-               if ($locale == '-def-')\r
-                       setlocale(LC_TIME,$template['LOCALE']);\r
-               else\r
-                       setlocale(LC_TIME,$locale);\r
-               \r
-               // get archive date\r
-               sscanf($archive,'%d-%d-%d',$y,$m,$d);\r
-\r
-               // get format           \r
-               $args = func_get_args();\r
-               // format can be spread over multiple parameters\r
-               if (sizeof($args) > 1) {\r
-                       // take away locale\r
-                       array_shift($args);\r
-                       // implode\r
-                       $format=implode(',',$args);\r
-               } elseif ($d == 0) {\r
-                       $format = '%B %Y';      \r
-               } else {\r
-                       $format = '%d %B %Y';   \r
-               }\r
-               \r
-               echo strftime($format,mktime(0,0,0,$m,$d?$d:1,$y));             \r
-       }\r
-       \r
-       function parse_blog($template, $amount = 10, $category = '') {\r
-               global $blog, $startpos;\r
-               \r
-               list($limit, $offset) = sscanf($amount, '%d(%d)');\r
-               $this->_setBlogCategory($blog, $category);\r
-               $this->_preBlogContent('blog',$blog);\r
-               $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);\r
-               $this->_postBlogContent('blog',$blog);\r
-       }\r
-\r
-       function parse_otherblog($blogname, $template, $amount = 10, $category = '') {\r
-               global $manager;\r
-\r
-               list($limit, $offset) = sscanf($amount, '%d(%d)');\r
-\r
-               $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
-               $this->_setBlogCategory($b, $category);\r
-               $this->_preBlogContent('otherblog',$b);\r
-               $this->amountfound = $b->readLog($template, $limit, $offset);\r
-               $this->_postBlogContent('otherblog',$b);\r
-       }\r
-\r
-       // include one item (no comments)\r
-       function parse_item($template) {\r
-               global $blog, $itemid, $highlight;\r
-               $this->_setBlogCategory($blog, '');     // need this to select default category\r
-               $this->_preBlogContent('item',$blog);\r
-               $r = $blog->showOneitem($itemid, $template, $highlight);\r
-               if ($r == 0)\r
-                       echo _ERROR_NOSUCHITEM;\r
-               $this->_postBlogContent('item',$blog);\r
-       }\r
-\r
-       function parse_itemid() {\r
-               global $itemid;\r
-               echo $itemid;\r
-       }\r
-\r
-\r
-       // include comments for one item\r
-       function parse_comments($template) {\r
-               global $itemid, $manager, $blog, $highlight;\r
-               $template = TEMPLATE::read($template);\r
-\r
-               // create parser object & action handler\r
-               $actions = new ITEMACTIONS($blog);\r
-               $parser = new PARSER($actions->getDefinedActions(),$actions);\r
-               $actions->setTemplate($template);\r
-               $actions->setParser($parser);\r
-               $item = ITEM::getitem($itemid, 0, 0);\r
-               $actions->setCurrentItem($item);\r
-\r
-               $comments = new COMMENTS($itemid);\r
-               $comments->setItemActions($actions);\r
-               $comments->showComments($template, -1, 1, $highlight);  // shows ALL comments\r
-       }\r
-\r
-       function parse_archive($template, $category = '') {\r
-               global $blog, $archive;\r
-               // can be used with either yyyy-mm or yyyy-mm-dd\r
-               sscanf($archive,'%d-%d-%d',$y,$m,$d);\r
-               $this->_setBlogCategory($blog, $category);\r
-               $this->_preBlogContent('achive',$blog);\r
-               $blog->showArchive($template, $y, $m, $d);\r
-               $this->_postBlogContent('achive',$blog);\r
-\r
-       }\r
-\r
-       function parse_otherarchive($blogname, $template, $category = '') {\r
-               global $archive, $manager;\r
-               sscanf($archive,'%d-%d-%d',$y,$m,$d);\r
-               $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
-               $this->_setBlogCategory($b, $category);\r
-               $this->_preBlogContent('otherachive',$b);\r
-               $b->showArchive($template, $y, $m, $d);\r
-               $this->_postBlogContent('otherachive',$b);\r
-       }\r
-\r
-       function parse_archivelist($template, $category = 'all', $limit = 0) {\r
-               global $blog;\r
-               if ($category == 'all') $category = '';\r
-               $this->_preBlogContent('archivelist',$blog);\r
-               $this->_setBlogCategory($blog, $category);\r
-               $blog->showArchiveList($template, 'month', $limit);\r
-               $this->_postBlogContent('archivelist',$blog);\r
-       }\r
-\r
-       function parse_archivedaylist($template, $category = 'all', $limit = 0) {\r
-               global $blog;\r
-               if ($category == 'all') $category = '';\r
-               $this->_preBlogContent('archivelist',$blog);\r
-               $this->_setBlogCategory($blog, $category);\r
-               $blog->showArchiveList($template, 'day', $limit);\r
-               $this->_postBlogContent('archivelist',$blog);\r
-       }\r
-\r
-\r
-       function parse_itemtitle() {\r
-               global $manager, $itemid;\r
-               $item =& $manager->getItem($itemid,0,0);\r
-               echo htmlspecialchars(strip_tags($item['title']));\r
-       }\r
-\r
-       function parse_categorylist($template, $blogname = '') {\r
-               global $blog, $manager;\r
-\r
-               if ($blogname == '') {\r
-                       $this->_preBlogContent('categorylist',$blog);\r
-                       $blog->showCategoryList($template);\r
-                       $this->_postBlogContent('categorylist',$blog);\r
-               } else {\r
-                       $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
-                       $this->_preBlogContent('categorylist',$b);\r
-                       $b->showCategoryList($template);\r
-                       $this->_postBlogContent('categorylist',$b);\r
-               }\r
-       }\r
-\r
-       function parse_category($type = 'name') {\r
-               global $catid, $blog;\r
-               if (!$blog->isValidCategory($catid))\r
-                       return;\r
-\r
-               switch($type) {\r
-                       case 'name':\r
-                               echo $blog->getCategoryName($catid);\r
-                               break;\r
-                       case 'desc':\r
-                               echo $blog->getCategoryDesc($catid);\r
-                               break;\r
-                       case 'id':\r
-                               echo $catid;\r
-                               break;\r
-               }\r
-       }\r
-\r
-       function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {\r
-               global $manager;\r
-               if ($category == 'all') $category = '';\r
-               $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
-               $this->_setBlogCategory($b, $category);\r
-               $this->_preBlogContent('otherarchivelist',$b);\r
-               $b->showArchiveList($template, 'month', $limit);\r
-               $this->_postBlogContent('otherarchivelist',$b);\r
-       }\r
-\r
-       function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {\r
-               global $manager;\r
-               if ($category == 'all') $category = '';\r
-               $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
-               $this->_setBlogCategory($b, $category);\r
-               $this->_preBlogContent('otherarchivelist',$b);\r
-               $b->showArchiveList($template, 'day', $limit);\r
-               $this->_postBlogContent('otherarchivelist',$b);\r
-       }\r
-\r
-       function parse_searchresults($template, $maxresults = 50 ) {\r
-               global $blog, $query, $amount, $startpos;\r
-\r
-               $this->_setBlogCategory($blog, '');     // need this to select default category\r
-               $this->_preBlogContent('searchresults',$blog);\r
-               $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);\r
-               $this->_postBlogContent('searchresults',$blog);\r
-       }\r
-\r
-       function parse_othersearchresults($blogname, $template, $maxresults = 50) {\r
-               global $query, $amount, $manager, $startpos;\r
-               $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
-               $this->_setBlogCategory($b, '');        // need this to select default category\r
-               $this->_preBlogContent('othersearchresults',$b);\r
-               $b->search($query, $template, $amount, $maxresults, $startpos);\r
-               $this->_postBlogContent('othersearchresults',$b);\r
-       }\r
-\r
-       // includes the search query\r
-       function parse_query() {\r
-               global $query;\r
-               echo htmlspecialchars($query);\r
-       }\r
-                       \r
-       // include nucleus versionnumber\r
-       function parse_version() {\r
-               global $nucleus;\r
-               echo 'Nucleus ' . $nucleus['version'];\r
-       }\r
-       \r
-\r
-       function parse_errormessage() {\r
-               global $errormessage;\r
-               echo $errormessage;\r
-       }\r
-\r
-\r
-       function parse_imagetext() {                    \r
-               echo htmlspecialchars(requestVar('imagetext'));\r
-       }\r
-       \r
-       function parse_image($what = 'imgtag') {\r
-               global $CONF;\r
-\r
-               $imagetext      = htmlspecialchars(requestVar('imagetext'));\r
-               $imagepopup = requestVar('imagepopup');\r
-               $width          = intRequestVar('width');\r
-               $height         = intRequestVar('height');\r
-               $fullurl        = htmlspecialchars($CONF['MediaURL'] . $imagepopup);\r
-               \r
-               switch($what)\r
-               {\r
-                       case 'url':\r
-                               echo $fullurl;\r
-                               break;\r
-                       case 'width':\r
-                               echo $width;\r
-                               break;\r
-                       case 'height':\r
-                               echo $height;\r
-                               break;\r
-                       case 'caption':\r
-                       case 'text':                    \r
-                               echo $imagetext;\r
-                               break;\r
-                       case 'imgtag':\r
-                       default:\r
-                               echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" />";\r
-                               break;\r
-               }\r
-       }\r
-       \r
-       // When commentform is not used, to include a hidden field with itemid\r
-       function parse_vars() {\r
-               global $itemid;\r
-               echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';\r
-       }\r
-       \r
-       // include a sitevar\r
-       function parse_sitevar($which) {\r
-               global $CONF;\r
-               switch($which) {\r
-                       case 'url':\r
-                               echo $CONF['IndexURL'];\r
-                               break;\r
-                       case 'name':\r
-                               echo $CONF['SiteName'];\r
-                               break;\r
-                       case 'admin':\r
-                               echo $CONF['AdminEmail'];\r
-                               break;\r
-                       case 'adminurl':\r
-                               echo $CONF['AdminURL'];\r
-               }                       \r
-       }\r
-       \r
-       // shortcut for admin url\r
-       function parse_adminurl() { $this->parse_sitevar('adminurl'); }\r
-       \r
-       function parse_blogsetting($which) {\r
-               global $blog;\r
-               switch($which) {\r
-                       case 'id':\r
-                               echo $blog->getID();\r
-                               break;\r
-                       case 'url':\r
-                               echo $blog->getURL();\r
-                               break;\r
-                       case 'name':\r
-                               echo $blog->getName();\r
-                               break;\r
-                       case 'desc':\r
-                               echo $blog->getDescription();\r
-                               break;\r
-                       case 'short':\r
-                               echo $blog->getShortName();\r
-                               break;                          \r
-               }       \r
-       }\r
-       \r
-       // includes a member info thingie\r
-       function parse_member($what) {\r
-               global $memberinfo, $member;\r
-               \r
-               // 1. only allow the member-details-page specific variables on member pages\r
-               if ($this->skintype == 'member') {\r
-\r
-                       switch($what) {\r
-                               case 'name':\r
-                                       echo $memberinfo->getDisplayName();\r
-                                       break;\r
-                               case 'realname':\r
-                                       echo $memberinfo->getRealName();\r
-                                       break;\r
-                               case 'notes':\r
-                                       echo $memberinfo->getNotes();\r
-                                       break;\r
-                               case 'url':\r
-                                       echo $memberinfo->getURL();\r
-                                       break;\r
-                               case 'email':\r
-                                       echo $memberinfo->getEmail();\r
-                                       break;\r
-                               case 'id':\r
-                                       echo $memberinfo->getID();\r
-                                       break;                                  \r
-                       }       \r
-               }\r
-               \r
-               // 2. the next bunch of options is available everywhere, as long as the user is logged in\r
-               if ($member->isLoggedIn())\r
-               {\r
-                       switch($what) {\r
-                               case 'yourname':\r
-                                       echo $member->getDisplayName();\r
-                                       break;\r
-                               case 'yourrealname':\r
-                                       echo $member->getRealName();\r
-                                       break;\r
-                               case 'yournotes':\r
-                                       echo $member->getNotes();\r
-                                       break;\r
-                               case 'yoururl':\r
-                                       echo $member->getURL();\r
-                                       break;\r
-                               case 'youremail':\r
-                                       echo $member->getEmail();\r
-                                       break;\r
-                               case 'yourid':\r
-                                       echo $member->getID();\r
-                                       break;                                                                  \r
-                       }       \r
-               }\r
-\r
-       }\r
-       \r
-       function parse_preview($template) {\r
-               global $blog, $CONF;\r
-               \r
-               $template = TEMPLATE::read($template);\r
-               $row['body'] = '<span id="prevbody"></span>';\r
-               $row['title'] = '<span id="prevtitle"></span>';\r
-               $row['more'] = '<span id="prevmore"></span>';\r
-               $row['itemlink'] = '';\r
-               $row['itemid'] = 0; $row['blogid'] = $blog->getID();\r
-               echo TEMPLATE::fill($template['ITEM_HEADER'],$row);\r
-               echo TEMPLATE::fill($template['ITEM'],$row);\r
-               echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);\r
-       }\r
-       \r
-       function parse_additemform() {\r
-               global $blog, $CONF;\r
-               $this->formdata = array(\r
-                       'adminurl' => htmlspecialchars($CONF['AdminURL']),\r
-                       'catid' => $blog->getDefaultCategory()\r
-               );\r
-               $blog->InsertJavaScriptInfo(); \r
-               $this->doForm('additemform');\r
-       }\r
-\r
-       /**\r
-         * Executes a plugin skinvar\r
-         *\r
-         * @param pluginName name of plugin (without the NP_)\r
-         * \r
-         * extra parameters can be added\r
-         */\r
-       function parse_plugin($pluginName) {\r
-               global $manager;\r
-               \r
-               // only continue when the plugin is really installed\r
-               if (!$manager->pluginInstalled('NP_' . $pluginName))\r
-                       return;\r
-               \r
-               $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
-               if (!$plugin) return;\r
-\r
-               // get arguments\r
-               $params = func_get_args();\r
-               \r
-               // remove plugin name \r
-               array_shift($params);\r
-               \r
-               // add skin type on front\r
-               array_unshift($params, $this->skintype);\r
-               \r
-               call_user_func_array(array(&$plugin,'doSkinVar'), $params);\r
-       }\r
-\r
-                       \r
-       function parse_commentform($destinationurl = '') {\r
-               global $blog, $itemid, $member, $CONF, $manager;\r
-               \r
-               // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)\r
-               if (stristr($destinationurl, 'action.php')) {\r
-                       $args = func_get_args();\r
-                       $destinationurl = $args[1];\r
-                       ACTIONLOG::add(WARNING,'actionurl is not longer a parameter on commentform skinvars. Moved to be a global setting instead.');\r
-               }\r
-               \r
-               $actionurl = $CONF['ActionURL'];\r
-               \r
-               // if item is closed, show message and do nothing\r
-               $item =& $manager->getItem($itemid,0,0);\r
-               if ($item['closed'] || !$blog->commentsEnabled()) {\r
-                       $this->doForm('commentform-closed');\r
-                       return;\r
-               }\r
-               \r
-               if (!$destinationurl)\r
-                       $destinationurl = createItemLink($itemid, $this->linkparams);\r
-\r
-               $this->formdata = array(\r
-                       'destinationurl' => htmlspecialchars($destinationurl),\r
-                       'actionurl' => htmlspecialchars($actionurl),\r
-                       'itemid' => $itemid,\r
-                       'user' => htmlspecialchars(cookieVar('comment_user')),\r
-                       'userid' => htmlspecialchars(cookieVar('comment_userid')),                      \r
-                       'membername' => $member->getDisplayName(),\r
-                       'rememberchecked' => cookieVar('comment_user')?'checked="checked"':''\r
-               );\r
-               \r
-               if (!$member->isLoggedIn()) {\r
-                       $this->doForm('commentform-notloggedin');\r
-               } else {\r
-                       $this->doForm('commentform-loggedin');          \r
-               }\r
-       }\r
-\r
-       function parse_loginform() {\r
-               global $member, $CONF;\r
-               if (!$member->isLoggedIn()) {\r
-                       $filename = 'loginform-notloggedin';\r
-                       $this->formdata = array();\r
-               } else {\r
-                       $filename = 'loginform-loggedin';\r
-                       $this->formdata = array(\r
-                               'membername' => $member->getDisplayName(),\r
-                       );\r
-               }\r
-               $this->doForm($filename);\r
-       }       \r
-       \r
-       \r
-       function parse_membermailform($rows = 10, $cols = 40, $desturl = '') {\r
-               global $member, $CONF, $memberid;\r
-               \r
-               if ($desturl == '') {\r
-                       if ($CONF['URLMode'] == 'pathinfo')\r
-                               $desturl = createMemberLink($memberid);\r
-                       else\r
-                               $desturl = $CONF['IndexURL'] . createMemberLink($memberid);                             \r
-               }\r
-                       \r
-               $this->formdata = array(\r
-                       'url' => $desturl,\r
-                       'actionurl' => $CONF['ActionURL'],\r
-                       'memberid' => $memberid,\r
-                       'rows' => $rows,\r
-                       'cols' => $cols\r
-               );\r
-               if ($member->isLoggedIn()) {\r
-                       $this->doForm('membermailform-loggedin');\r
-               } else if ($CONF['NonmemberMail']) {\r
-                       $this->doForm('membermailform-notloggedin');            \r
-               } else {\r
-                       $this->doForm('membermailform-disallowed');             \r
-               }\r
-\r
-       }\r
-\r
-       function parse_searchform($blogname = '') {\r
-               global $CONF, $manager, $maxresults;\r
-               if ($blogname) {\r
-                       $blog =& $manager->getBlog(getBlogIDFromName($blogname));\r
-               } else {\r
-                       global $blog;\r
-               }\r
-               // use default blog when no blog is selected\r
-               $this->formdata = array(\r
-                       'id' => $blog?$blog->getID():$CONF['DefaultBlog'],\r
-                       'query' => htmlspecialchars(getVar('query')),\r
-               );\r
-               $this->doForm('searchform');\r
-       }\r
-\r
-       function parse_nucleusbutton($imgurl = '',\r
-                                                            $imgwidth = '85',\r
-                                                            $imgheight = '31') {\r
-               global $CONF;\r
-               if ($imgurl == '') {\r
-                       $imgurl = $CONF['AdminURL'] . 'nucleus.gif';\r
-               } else if (PARSER::getProperty('IncludeMode') == 'skindir'){\r
-                       // when skindit IncludeMode is used: start from skindir\r
-                       $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;\r
-               }\r
-\r
-               $this->formdata = array(\r
-                       'imgurl' => $imgurl,\r
-                       'imgwidth' => $imgwidth,\r
-                       'imgheight' => $imgheight,\r
-               );\r
-               $this->doForm('nucleusbutton');\r
-       }\r
-       \r
-       function parse_self() {\r
-               global $CONF;\r
-               echo $CONF['Self'];\r
-       }\r
-       \r
-       function parse_referer() {\r
-               echo htmlspecialchars(serverVar('HTTP_REFERER'));\r
-       }\r
-       \r
-       /**\r
-         * Helper function that sets the category that a blog will need to use \r
-         *\r
-         * @param $blog\r
-         *             An object of the blog class, passed by reference (we want to make changes to it)\r
-         * @param $catname\r
-         *             The name of the category to use\r
-         */\r
-       function _setBlogCategory(&$blog, $catname) {\r
-               global $catid;\r
-               if ($catname != '')\r
-                       $blog->setSelectedCategoryByName($catname);\r
-               else\r
-                       $blog->setSelectedCategory($catid);\r
-       }\r
-       \r
-       function _preBlogContent($type, &$blog) {\r
-               global $manager;\r
-               $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));\r
-       }\r
-\r
-       function _postBlogContent($type, &$blog) {\r
-               global $manager;\r
-               $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type));\r
-       }\r
-\r
-}\r
-\r
-?>\r
+<?php
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2010 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-2010 The Nucleus Group
+ * @version $Id$
+ * @version $NucleusJP: SKIN.php,v 1.8.2.1 2007/09/05 07:45:01 kimitake Exp $
+ */
+
+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;
+
+       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;
+
+       }
+
+       function getID() {                              return $this->id; }
+       function getName() {                    return $this->name; }
+       function getDescription() {     return $this->description; }
+       function getContentType() {     return $this->contentType; }
+       function getIncludeMode() {     return $this->includeMode; }
+       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));
+       }
+
+       /**
+        * Creates a new skin, with the given characteristics.
+        *
+        * @static
+        */
+       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
+                       )
+               );
+
+               sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . 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)."')");
+               $newid = sql_insert_id();
+
+               $manager->notify(
+                       'PostAddSkin',
+                       array(
+                               'skinid' => $newid,
+                               'name' => $name,
+                               'description' => $desc,
+                               'type' => $type,
+                               'includeMode' => $includeMode,
+                               'includePrefix' => $includePrefix
+                       )
+               );
+
+               return $newid;
+       }
+
+       function parse($type) {
+               global $manager, $CONF, $skinid;
+               
+               $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
+               $skinid = $this->id;
+               
+               // set output type
+               sendContentType($this->getContentType(), 'skin', _CHARSET);
+               
+               // 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));
+               $skinid = $this->id;
+               
+               // 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));
+               $skinid = $this->id;
+
+
+       }
+
+       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);
+       }
+
+       /**
+        * Updates the contents of one part of the skin
+        */
+       function update($type, $content) {
+               $skinid = $this->id;
+
+               // delete old thingie
+               sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".sql_real_escape_string($type)."' and sdesc=" . intval($skinid));
+
+               // write new thingie
+               if ($content) {
+                       sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . sql_real_escape_string($content) . "', stype='" . sql_real_escape_string($type) . "', sdesc=" . intval($skinid));
+               }
+       }
+
+       /**
+        * 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);
+       }
+
+       /**
+        * 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;
+       }
+
+       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',
+                                                               'ifcat',                                        // deprecated (Nucleus v2.0)
+                                                               'category',
+                                                               'searchform',
+                                                               'referer',
+                                                               'skinname',
+                                                               'skinfile',
+                                                               'set',
+                                                               'if',
+                                                               'else',
+                                                               'endif',
+                                                               'elseif',
+                                                               'ifnot',
+                                                               'elseifnot',
+                                                               'charset',
+                                                               'bloglist',
+                                                               'addlink',
+                                                               'addpopupcode',
+                                                               'sticky'
+                                                               );
+
+               // 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',
+                                                               'imagetext',                            // deprecated (Nucleus v2.0)
+                                                               );
+                               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);
+       }
+
+}
+
+?>