3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2007 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
14 * Class representing a skin
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2007 The Nucleus Group
18 * @version $Id: SKIN.php,v 1.8 2007-03-20 19:31:29 kmorimatsu Exp $
19 * @version $NucleusJP: SKIN.php,v 1.7 2007/02/04 06:28:46 kimitake Exp $
22 if ( !function_exists('requestVar') ) exit;
23 require_once dirname(__FILE__) . '/ACTIONS.php';
27 // after creating a SKIN object, evaluates to true when the skin exists
30 // skin characteristics. Use the getXXX methods rather than accessing directly
34 var $includeMode; // either 'normal' or 'skindir'
39 $this->id = intval($id);
41 // read skin name/description/content type
42 $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
43 $obj = mysql_fetch_object($res);
44 $this->isValid = (mysql_num_rows($res) > 0);
48 $this->name = $obj->sdname;
49 $this->description = $obj->sddesc;
50 $this->contentType = $obj->sdtype;
51 $this->includeMode = $obj->sdincmode;
52 $this->includePrefix = $obj->sdincpref;
56 function getID() { return $this->id; }
57 function getName() { return $this->name; }
58 function getDescription() { return $this->description; }
59 function getContentType() { return $this->contentType; }
60 function getIncludeMode() { return $this->includeMode; }
61 function getIncludePrefix() { return $this->includePrefix; }
64 * Checks if a skin with a given shortname exists
65 * @param string $name Skin short name
66 * @return int number of skins with the given ID
69 function exists($name) {
70 return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.addslashes($name).'"') > 0;
74 * Checks if a skin with a given ID exists
75 * @param string $id Skin ID
76 * @return int number of skins with the given ID
79 function existsID($id) {
80 return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0;
84 * Returns a skin given its shortname
85 * @param string $name Skin shortname
89 function createFromName($name) {
90 return new SKIN(SKIN::getIdFromName($name));
94 * Returns a skin ID given its shortname
95 * @param string $name Skin shortname
99 function getIdFromName($name) {
100 $query = 'SELECT sdnumber'
101 . ' FROM '.sql_table('skin_desc')
102 . ' WHERE sdname="'.addslashes($name).'"';
103 $res = sql_query($query);
104 $obj = mysql_fetch_object($res);
105 return $obj->sdnumber;
109 * Returns a skin shortname given its ID
110 * @param string $name
111 * @return string Skin short name
114 function getNameFromId($id) {
115 return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id));
119 * Creates a new skin, with the given characteristics.
123 function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
130 'description' => &$desc,
132 'includeMode' => &$includeMode,
133 'includePrefix' => &$includePrefix
137 sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "','".addslashes($type)."','".addslashes($includeMode)."','".addslashes($includePrefix)."')");
138 $newid = mysql_insert_id();
145 'description' => $desc,
147 'includeMode' => $includeMode,
148 'includePrefix' => $includePrefix
155 function parse($type) {
156 global $manager, $CONF;
158 $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
161 sendContentType($this->getContentType(), 'skin', _CHARSET);
163 // set skin name as global var (so plugins can access it)
164 global $currentSkinName;
165 $currentSkinName = $this->getName();
167 $contents = $this->getContent($type);
170 // use base skin if this skin does not have contents
171 $defskin =& new SKIN($CONF['BaseSkin']);
172 $contents = $defskin->getContent($type);
179 $actions = $this->getAllowedActionsForType($type);
181 $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
183 // set IncludeMode properties of parser
184 PARSER::setProperty('IncludeMode',$this->getIncludeMode());
185 PARSER::setProperty('IncludePrefix',$this->getIncludePrefix());
187 $handler =& new ACTIONS($type, $this);
188 $parser =& new PARSER($actions, $handler);
189 $handler->setParser($parser);
190 $handler->setSkin($this);
191 $parser->parse($contents);
193 $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
198 function getContent($type) {
199 $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". addslashes($type) ."'";
200 $res = sql_query($query);
202 if (mysql_num_rows($res) == 0)
205 return mysql_result($res, 0, 0);
209 * Updates the contents of one part of the skin
211 function update($type, $content) {
214 // delete old thingie
215 sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".addslashes($type)."' and sdesc=" . intval($skinid));
219 sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . addslashes($content) . "', stype='" . addslashes($type) . "', sdesc=" . intval($skinid));
224 * Deletes all skin parts from the database
226 function deleteAllParts() {
227 sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID());
231 * Updates the general information about the skin
233 function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
234 $query = 'UPDATE '.sql_table('skin_desc').' SET'
235 . " sdname='" . addslashes($name) . "',"
236 . " sddesc='" . addslashes($desc) . "',"
237 . " sdtype='" . addslashes($type) . "',"
238 . " sdincmode='" . addslashes($includeMode) . "',"
239 . " sdincpref='" . addslashes($includePrefix) . "'"
240 . " WHERE sdnumber=" . $this->getID();
245 * static: returns an array of friendly names
247 function getFriendlyNames() {
249 'index' => _SKIN_PART_MAIN,
250 'item' => _SKIN_PART_ITEM,
251 'archivelist' => _SKIN_PART_ALIST,
252 'archive' => _SKIN_PART_ARCHIVE,
253 'search' => _SKIN_PART_SEARCH,
254 'error' => _SKIN_PART_ERROR,
255 'member' => _SKIN_PART_MEMBER,
256 'imagepopup' => _SKIN_PART_POPUP
259 $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
260 $res = sql_query($query);
261 while ($row = mysql_fetch_array($res)) {
262 $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
268 function getAllowedActionsForType($type) {
271 // some actions that can be performed at any time, from anywhere
272 $defaultActions = array('otherblog',
282 'otherarchivedaylist',
288 'ifcat', // deprecated (Nucleus v2.0)
305 // extra actions specific for a certain skin type
306 $extraActions = array();
310 $extraActions = array('blog',
322 $extraActions = array('blog',
338 $extraActions = array('blog',
346 $extraActions = array('blog',
351 'othersearchresults',
359 $extraActions = array('image',
360 'imagetext', // deprecated (Nucleus v2.0)
364 $extraActions = array(
371 $extraActions = array('blog',
392 $extraActions = array(
397 if ($blogid && $blogid > 0) {
398 $extraActions = array(
417 return array_merge($defaultActions, $extraActions);