3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 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)
12 * Class representing a skin
15 if ( !function_exists('requestVar') ) exit;
16 require_once dirname(__FILE__) . '/ACTIONS.php';
20 // after creating a SKIN object, evaluates to true when the skin exists
23 // skin characteristics. Use the getXXX methods rather than accessing directly
27 var $includeMode; // either 'normal' or 'skindir'
32 $this->id = intval($id);
34 // read skin name/description/content type
35 $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
36 $obj = sql_fetch_object($res);
37 $this->isValid = (sql_num_rows($res) > 0);
41 $this->name = $obj->sdname;
42 $this->description = $obj->sddesc;
43 $this->contentType = $obj->sdtype;
44 $this->includeMode = $obj->sdincmode;
45 $this->includePrefix = $obj->sdincpref;
49 function getID() { return $this->id; }
50 function getName() { return $this->name; }
51 function getDescription() { return $this->description; }
52 function getContentType() { return $this->contentType; }
53 function getIncludeMode() { return $this->includeMode; }
54 function getIncludePrefix() { return $this->includePrefix; }
57 * Checks if a skin with a given shortname exists
58 * @param string $name Skin short name
59 * @return int number of skins with the given ID
62 function exists($name) {
63 return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.sql_real_escape_string($name).'"') > 0;
67 * Checks if a skin with a given ID exists
68 * @param string $id Skin ID
69 * @return int number of skins with the given ID
72 function existsID($id) {
73 return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0;
77 * Returns a skin given its shortname
78 * @param string $name Skin shortname
82 function createFromName($name) {
83 return new SKIN(SKIN::getIdFromName($name));
87 * Returns a skin ID given its shortname
88 * @param string $name Skin shortname
92 function getIdFromName($name) {
93 $query = 'SELECT sdnumber'
94 . ' FROM '.sql_table('skin_desc')
95 . ' WHERE sdname="'.sql_real_escape_string($name).'"';
96 $res = sql_query($query);
97 $obj = sql_fetch_object($res);
98 return $obj->sdnumber;
102 * Returns a skin shortname given its ID
103 * @param string $name
104 * @return string Skin short name
107 function getNameFromId($id) {
108 return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id));
112 * Creates a new skin, with the given characteristics.
116 function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
121 'description' => &$desc,
123 'includeMode' => &$includeMode,
124 'includePrefix' => &$includePrefix
126 $manager->notify('PreAddSkin', $param);
128 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)."')");
129 $newid = sql_insert_id();
134 'description' => $desc,
136 'includeMode' => $includeMode,
137 'includePrefix' => $includePrefix
139 $manager->notify('PostAddSkin', $param);
144 function parse($type) {
145 global $manager, $CONF, $skinid;
151 $manager->notify('InitSkinParse', $param);
155 sendContentType($this->getContentType(), 'skin', _CHARSET);
157 // set skin name as global var (so plugins can access it)
158 global $currentSkinName;
159 $currentSkinName = $this->getName();
161 $contents = $this->getContent($type);
164 // use base skin if this skin does not have contents
165 $defskin = new SKIN($CONF['BaseSkin']);
166 $contents = $defskin->getContent($type);
173 $actions = $this->getAllowedActionsForType($type);
178 'contents' => &$contents
180 $manager->notify('PreSkinParse', $param);
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);
197 $manager->notify('PostSkinParse', $param);
203 function getContent($type) {
204 $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". sql_real_escape_string($type) ."'";
205 $res = sql_query($query);
207 if (sql_num_rows($res) == 0)
210 return sql_result($res, 0, 0);
214 * Updates the contents of one part of the skin
216 function update($type, $content) {
219 // delete old thingie
220 sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".sql_real_escape_string($type)."' and sdesc=" . intval($skinid));
224 sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . sql_real_escape_string($content) . "', stype='" . sql_real_escape_string($type) . "', sdesc=" . intval($skinid));
229 * Deletes all skin parts from the database
231 function deleteAllParts() {
232 sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID());
236 * Updates the general information about the skin
238 function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
239 $query = 'UPDATE '.sql_table('skin_desc').' SET'
240 . " sdname='" . sql_real_escape_string($name) . "',"
241 . " sddesc='" . sql_real_escape_string($desc) . "',"
242 . " sdtype='" . sql_real_escape_string($type) . "',"
243 . " sdincmode='" . sql_real_escape_string($includeMode) . "',"
244 . " sdincpref='" . sql_real_escape_string($includePrefix) . "'"
245 . " WHERE sdnumber=" . $this->getID();
250 * static: returns an array of friendly names
252 function getFriendlyNames() {
254 'index' => _SKIN_PART_MAIN,
255 'item' => _SKIN_PART_ITEM,
256 'archivelist' => _SKIN_PART_ALIST,
257 'archive' => _SKIN_PART_ARCHIVE,
258 'search' => _SKIN_PART_SEARCH,
259 'error' => _SKIN_PART_ERROR,
260 'member' => _SKIN_PART_MEMBER,
261 'imagepopup' => _SKIN_PART_POPUP
264 $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
265 $res = sql_query($query);
266 while ($row = sql_fetch_array($res)) {
267 $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
273 function getAllowedActionsForType($type) {
276 // some actions that can be performed at any time, from anywhere
277 $defaultActions = array('otherblog',
287 'otherarchivedaylist',
288 'otherarchiveyearlist',
294 'ifcat', // deprecated (Nucleus v2.0)
314 // extra actions specific for a certain skin type
315 $extraActions = array();
319 $extraActions = array('blog',
332 $extraActions = array('blog',
349 $extraActions = array('blog',
358 $extraActions = array('blog',
364 'othersearchresults',
372 $extraActions = array('image',
373 'imagetext', // deprecated (Nucleus v2.0)
377 $extraActions = array(
385 $extraActions = array('blog',
407 $extraActions = array(
413 if ($blogid && $blogid > 0) {
414 $extraActions = array(
433 return array_merge($defaultActions, $extraActions);