3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2009 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * Class representing a skin
\r
15 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
16 * @copyright Copyright (C) 2002-2009 The Nucleus Group
\r
17 * @version $Id: SKIN.php 1621 2012-01-09 02:49:37Z sakamocchi $
\r
20 if ( !function_exists('requestVar') )
\r
24 require_once dirname(__FILE__) . '/ACTIONS.php';
\r
28 // after creating a SKIN object, evaluates to true when the skin exists
\r
31 // skin characteristics. Use the getXXX methods rather than accessing directly
\r
35 var $includeMode; // either 'normal' or 'skindir'
\r
40 * Constructor for a new SKIN object
\r
47 $this->id = intval($id);
\r
49 // read skin name/description/content type
\r
50 $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
\r
51 $obj = sql_fetch_object($res);
\r
52 $this->isValid = (sql_num_rows($res) > 0);
\r
53 if ( !$this->isValid )
\r
58 $this->name = $obj->sdname;
\r
59 $this->description = $obj->sddesc;
\r
60 $this->contentType = $obj->sdtype;
\r
61 $this->includeMode = $obj->sdincmode;
\r
62 $this->includePrefix = $obj->sdincpref;
\r
83 * Get SKIN description
\r
85 function getDescription()
\r
87 return $this->description;
\r
91 * Get SKIN content type
\r
93 * e.g. text/xml, text/html, application/atom+xml
\r
95 function getContentType()
\r
97 return $this->contentType;
\r
101 * Get include mode of the SKIN
\r
103 * Returns either 'normal' or 'skindir':
\r
104 * 'normal': if a all data of the skin can be found in the databse
\r
105 * 'skindir': if the skin has data in the it's skin driectory
\r
107 function getIncludeMode()
\r
109 return $this->includeMode;
\r
113 * Get include prefix of the SKIN
\r
115 * Get name of the subdirectory (with trailing slash) where
\r
116 * the files of the current skin can be found (e.g. 'default/')
\r
118 function getIncludePrefix()
\r
120 return $this->includePrefix;
\r
124 * Checks if a skin with a given shortname exists
\r
125 * @param string $name Skin short name
\r
126 * @return int number of skins with the given ID
\r
129 function exists($name)
\r
131 return quickQuery('select count(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdname="' . sql_real_escape_string($name) . '"') > 0;
\r
135 * Checks if a skin with a given ID exists
\r
136 * @param string $id Skin ID
\r
137 * @return int number of skins with the given ID
\r
140 function existsID($id)
\r
142 return quickQuery('select COUNT(*) as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id)) > 0;
\r
146 * Returns a skin given its shortname
\r
147 * @param string $name Skin shortname
\r
148 * @return object SKIN
\r
151 function createFromName($name)
\r
153 return new SKIN(SKIN::getIdFromName($name));
\r
157 * Returns a skin ID given its shortname
\r
158 * @param string $name Skin shortname
\r
159 * @return int Skin ID
\r
162 function getIdFromName($name)
\r
164 $query = 'SELECT sdnumber'
\r
165 . ' FROM ' . sql_table('skin_desc')
\r
166 . ' WHERE sdname="' . sql_real_escape_string($name) . '"';
\r
167 $res = sql_query($query);
\r
168 $obj = sql_fetch_object($res);
\r
169 return $obj->sdnumber;
\r
173 * Returns a skin shortname given its ID
\r
174 * @param string $name
\r
175 * @return string Skin short name
\r
178 function getNameFromId($id)
\r
180 return quickQuery('SELECT sdname as result FROM ' . sql_table('skin_desc') . ' WHERE sdnumber=' . intval($id));
\r
184 * SKIN::createNew()
\r
185 * Creates a new skin, with the given characteristics.
\r
188 * @param String $name value for nucleus_skin.sdname
\r
189 * @param String $desc value for nucleus_skin.sddesc
\r
190 * @param String $type value for nucleus_skin.sdtype
\r
191 * @param String $includeMode value for nucleus_skin.sdinclude
\r
192 * @param String $includePrefix value for nucleus_skin.sdincpref
\r
193 * @return Integer ID for just inserted record
\r
196 function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
\r
204 'description' => &$desc,
\r
206 'includeMode' => &$includeMode,
\r
207 'includePrefix' => &$includePrefix
\r
211 $query = "INSERT INTO %s (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('%s', '%s', '%s', '%s', '%s')";
\r
212 $query = sprintf($query, sql_table('skin_desc'), sql_real_escape_string($name), sql_real_escape_string($desc), sql_real_escape_string($type), sql_real_escape_string($includeMode), sql_real_escape_string($includePrefix));
\r
214 $newid = sql_insert_id();
\r
219 'skinid' => $newid,
\r
221 'description' => $desc,
\r
223 'includeMode' => $includeMode,
\r
224 'includePrefix' => $includePrefix
\r
233 * @param string $type
\r
235 function parse($type)
\r
237 global $manager, $CONF;
\r
239 $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
\r
242 sendContentType($this->getContentType(), 'skin');
\r
244 // set skin name as global var (so plugins can access it)
\r
245 global $currentSkinName;
\r
246 $currentSkinName = $this->getName();
\r
248 $contents = $this->getContent($type);
\r
252 // use base skin if this skin does not have contents
\r
253 $defskin = new SKIN($CONF['BaseSkin']);
\r
254 $contents = $defskin->getContent($type);
\r
262 $actions = $this->getAllowedActionsForType($type);
\r
264 $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
\r
266 // set IncludeMode properties of parser
\r
267 Parser::setProperty('IncludeMode',$this->getIncludeMode());
\r
268 Parser::setProperty('IncludePrefix',$this->getIncludePrefix());
\r
270 $handler = new Actions($type, $this);
\r
271 $parser = new Parser($actions, $handler);
\r
272 $handler->setParser($parser);
\r
273 $handler->setSkin($this);
\r
274 $parser->parse($contents);
\r
276 $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
\r
280 * Get content of the skin part from the database
\r
282 * @param $type type of the skin (e.g. index, item, search ...)
\r
284 function getContent($type)
\r
286 $query = 'SELECT scontent FROM '. sql_table('skin') . " WHERE sdesc=$this->id and stype='" . sql_real_escape_string($type) . "'";
\r
287 $res = sql_query($query);
\r
289 if ( sql_num_rows($res) == 0 )
\r
295 return sql_result($res, 0, 0);
\r
301 * Updates the contents for one part of the skin in the database
\r
303 * @param $type type of the skin part (e.g. index, item, search ...)
\r
304 * @param $content new content for this skin part
\r
308 function update($type, $content)
\r
312 $skinid = $this->id;
\r
314 $query = "SELECT sdesc FROM %s WHERE stype='%s' and sdesc=%d";
\r
315 $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $skinid);
\r
316 $res = sql_query($query);
\r
318 $skintypeexists = sql_fetch_object($res);
\r
319 $skintypevalue = ($content == true);
\r
321 if( $skintypevalue && $skintypeexists )
\r
323 // PreUpdateSkinPart event
\r
325 'PreUpdateSkinPart',
\r
327 'skinid' => $skinid,
\r
329 'content' => &$content
\r
333 else if( $skintypevalue && (!$skintypeexists) )
\r
335 // PreAddSkinPart event
\r
339 'skinid' => $skinid,
\r
341 'content' => &$content
\r
345 else if( (!$skintypevalue) && $skintypeexists )
\r
347 // PreDeleteSkinPart event
\r
349 'PreDeleteSkinPart',
\r
351 'skinid' => $skinid,
\r
357 // delete old thingie
\r
358 $query = "DELETE FROM %s WHERE stype='%s' and sdesc=%d";
\r
359 $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $skinid);
\r
362 // write new thingie
\r
365 $query = "INSERT INTO %s (scontent, stype, sdesc) VALUE ('%s', '%s', %d)";
\r
366 $query = sprintf($query, sql_table('skin'), sql_real_escape_string($content), sql_real_escape_string($type), (integer) $skinid);
\r
370 if( $skintypevalue && $skintypeexists )
\r
372 // PostUpdateSkinPart event
\r
374 'PostUpdateSkinPart',
\r
376 'skinid' => $skinid,
\r
378 'content' => &$content
\r
382 else if( $skintypevalue && (!$skintypeexists) )
\r
384 // PostAddSkinPart event
\r
388 'skinid' => $skinid,
\r
390 'content' => &$content
\r
394 else if( (!$skintypevalue) && $skintypeexists )
\r
396 // PostDeleteSkinPart event
\r
398 'PostDeleteSkinPart',
\r
400 'skinid' => $skinid,
\r
409 * Deletes all skin parts from the database
\r
411 function deleteAllParts()
\r
413 sql_query('DELETE FROM ' . sql_table('skin') . ' WHERE sdesc=' . $this->getID());
\r
417 * Updates the general information about the skin
\r
419 function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
\r
421 $query = 'UPDATE '.sql_table('skin_desc').' SET'
\r
422 . " sdname='" . sql_real_escape_string($name) . "',"
\r
423 . " sddesc='" . sql_real_escape_string($desc) . "',"
\r
424 . " sdtype='" . sql_real_escape_string($type) . "',"
\r
425 . " sdincmode='" . sql_real_escape_string($includeMode) . "',"
\r
426 . " sdincpref='" . sql_real_escape_string($includePrefix) . "'"
\r
427 . " WHERE sdnumber=" . $this->getID();
\r
432 * Get an array with the names of possible skin parts
\r
433 * Used to show all possible parts of a skin in the administration backend
\r
435 * static: returns an array of friendly names
\r
437 function getFriendlyNames()
\r
439 $skintypes = array(
\r
440 'index' => _SKIN_PART_MAIN,
\r
441 'item' => _SKIN_PART_ITEM,
\r
442 'archivelist' => _SKIN_PART_ALIST,
\r
443 'archive' => _SKIN_PART_ARCHIVE,
\r
444 'search' => _SKIN_PART_SEARCH,
\r
445 'error' => _SKIN_PART_ERROR,
\r
446 'member' => _SKIN_PART_MEMBER,
\r
447 'imagepopup' => _SKIN_PART_POPUP
\r
450 $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
\r
451 $res = sql_query($query);
\r
452 while ( $row = sql_fetch_array($res) )
\r
454 $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
\r
460 * Get the allowed actions for a skin type
\r
461 * returns an array with the allowed actions
\r
463 * @param $type type of the skin (e.g. index, item, search ...)
\r
465 function getAllowedActionsForType($type)
\r
469 // some actions that can be performed at any time, from anywhere
\r
470 $defaultActions = array('otherblog',
\r
479 'otherarchivelist',
\r
480 'otherarchivedaylist',
\r
481 'otherarchiveyearlist',
\r
504 // deprecated (Nucleus v2.0)
\r
508 // extra actions specific for a certain skin type
\r
509 $extraActions = array();
\r
514 $extraActions = array('blog',
\r
527 $extraActions = array('blog',
\r
543 case 'archivelist':
\r
544 $extraActions = array('blog',
\r
553 $extraActions = array('blog',
\r
559 'othersearchresults',
\r
567 $extraActions = array('image',
\r
568 // deprecated (Nucleus v2.0)
\r
573 $extraActions = array(
\r
581 $extraActions = array('blog',
\r
603 $extraActions = array(
\r
609 if ( $blogid && $blogid > 0 )
\r
611 $extraActions = array(
\r
629 return array_merge($defaultActions, $extraActions);
\r