3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2012 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 1727 2012-04-07 02:54:22Z 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
33 private $description;
\r
34 private $contentType;
\r
35 private $includeMode; // either 'normal' or 'skindir'
\r
36 private $includePrefix;
\r
40 * Skin::__construct()
\r
41 * Constructor for a new SKIN object
\r
43 * @param integer $id id of the skin
\r
46 public function __construct($id)
\r
48 $this->id = (integer) $id;
\r
50 // read skin name/description/content type
\r
51 $query = "SELECT * FROM %s WHERE sdnumber=%d";
\r
52 $query = sprintf($query, sql_table('skin_desc'), (integer) $this->id);
\r
53 $res = sql_query($query);
\r
54 $obj = sql_fetch_object($res);
\r
55 $this->valid = (sql_num_rows($res) > 0);
\r
56 if ( !$this->valid )
\r
61 $this->name = $obj->sdname;
\r
62 $this->description = $obj->sddesc;
\r
63 $this->contentType = $obj->sdtype;
\r
64 $this->includeMode = $obj->sdincmode;
\r
65 $this->includePrefix = $obj->sdincpref;
\r
74 * @return integer id for this skin instance
\r
76 public function getID()
\r
78 return (integer) $this->id;
\r
87 public function isValid()
\r
89 return (boolean) $this->valid;
\r
97 * @return string name of this skin instance
\r
99 public function getName()
\r
101 return (string) $this->name;
\r
105 * Skin::getDescription()
\r
106 * Get SKIN description
\r
109 * @return string description of this skin instance
\r
111 public function getDescription()
\r
113 return (string) $this->description;
\r
117 * Skin::getContentType()
\r
118 * Get SKIN content type
\r
119 * e.g. text/xml, text/html, application/atom+xml
\r
122 * @return string name of this skin instance
\r
124 public function getContentType()
\r
126 return (string) $this->contentType;
\r
130 * Skin::getIncludeMode()
\r
131 * Get include mode of the SKIN
\r
133 * Returns either 'normal' or 'skindir':
\r
134 * 'normal': if a all data of the skin can be found in the databse
\r
135 * 'skindir': if the skin has data in the it's skin driectory
\r
138 * @return string normal/skindir
\r
140 public function getIncludeMode()
\r
142 return (string) $this->includeMode;
\r
146 * Skin::getIncludePrefix()
\r
147 * Get include prefix of the SKIN
\r
149 * Get name of the subdirectory (with trailing slash) where
\r
150 * the files of the current skin can be found (e.g. 'default/')
\r
153 * @return string include prefix of this skin instance
\r
155 public function getIncludePrefix()
\r
157 return (string) $this->includePrefix;
\r
162 * Checks if a skin with a given shortname exists
\r
165 * @param string $name Skin short name
\r
166 * @return integer number of skins with the given ID
\r
168 static public function exists($name)
\r
170 $query = "SELECT COUNT(*) AS result FROM %s WHERE sdname='%s';";
\r
171 $query = sprintf($query, sql_table('skin_desc'), sql_real_escape_string($name));
\r
172 return quickQuery($query) > 0;
\r
177 * Checks if a skin with a given ID exists
\r
180 * @param string $id Skin ID
\r
181 * @return integer number of skins with the given ID
\r
183 static public function existsID($id)
\r
185 $query = "SELECT COUNT(*) AS result FROM %s WHERE sdnumber=%d;";
\r
186 $query = sprintf($query, sql_table('skin_desc'), (integer) $id);
\r
187 return quickQuery($query) > 0;
\r
191 * Skin::createFromName()
\r
192 * Returns a skin given its shortname
\r
195 * @param string $name Skin shortname
\r
196 * @return object instance of Skin class
\r
198 static public function createFromName($name)
\r
200 return new SKIN(SKIN::getIdFromName($name));
\r
204 * Skin::getIdFromName()
\r
205 * Returns a skin ID given its shortname
\r
208 * @param string $name Skin shortname
\r
209 * @return integer Skin ID
\r
211 static public function getIdFromName($name)
\r
213 $query = "SELECT sdnumber FROM %s WHERE sdname='%s';";
\r
214 $query = sprintf($query, sql_table('skin_desc'), sql_real_escape_string($name));
\r
215 $res = sql_query($query);
\r
216 $obj = sql_fetch_object($res);
\r
217 return $obj->sdnumber;
\r
221 * Skin::getNameFromId()
\r
222 * Returns a skin shortname given its ID
\r
225 * @param string $name
\r
226 * @return string Skin short name
\r
228 static public function getNameFromId($id)
\r
230 $query = "SELECT sdname AS result FROM %s WHERE sdnumber=%d;";
\r
231 $query = sprintf($query, sql_table('skin_desc'), (integer) $id);
\r
232 return quickQuery($query);
\r
236 * SKIN::createNew()
\r
237 * Creates a new skin, with the given characteristics.
\r
240 * @param String $name value for nucleus_skin.sdname
\r
241 * @param String $desc value for nucleus_skin.sddesc
\r
242 * @param String $type value for nucleus_skin.sdtype
\r
243 * @param String $includeMode value for nucleus_skin.sdinclude
\r
244 * @param String $includePrefix value for nucleus_skin.sdincpref
\r
245 * @return Integer ID for just inserted record
\r
247 function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
\r
255 'description' => &$desc,
\r
257 'includeMode' => &$includeMode,
\r
258 'includePrefix' => &$includePrefix
\r
262 $query = "INSERT INTO %s (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('%s', '%s', '%s', '%s', '%s');";
\r
263 $sdname = sql_real_escape_string($name);
\r
264 $sddesc = sql_real_escape_string($desc);
\r
265 $sdtype = sql_real_escape_string($type);
\r
266 $sdincmode = sql_real_escape_string($includeMode);
\r
267 $sdincpref = sql_real_escape_string($includePrefix);
\r
268 $query = sprintf($query, sql_table('skin_desc'), $sdname, $sddesc, $sdtype, $sdincmode, $sdincpref);
\r
270 $newid = sql_insert_id();
\r
275 'skinid' => $newid,
\r
277 'description' => $desc,
\r
279 'includeMode' => $includeMode,
\r
280 'includePrefix' => $includePrefix
\r
290 * @param string $type
\r
293 public function parse($type)
\r
295 global $currentSkinName, $manager, $CONF;
\r
297 $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
\r
300 sendContentType($this->getContentType(), 'skin');
\r
302 // set skin name as global var (so plugins can access it)
\r
303 $currentSkinName = $this->getName();
\r
304 $contents = $this->getContent($type);
\r
308 // use base skin if this skin does not have contents
\r
309 $defskin = new SKIN($CONF['BaseSkin']);
\r
310 $contents = $defskin->getContent($type);
\r
318 $actions = $this->getAllowedActionsForType($type);
\r
320 $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
\r
322 // set IncludeMode properties of parser
\r
323 Parser::setProperty('IncludeMode', $this->getIncludeMode());
\r
324 Parser::setProperty('IncludePrefix', $this->getIncludePrefix());
\r
326 $handler = new Actions($type, $this);
\r
327 $parser = new Parser($actions, $handler);
\r
328 $handler->setParser($parser);
\r
329 $handler->setSkin($this);
\r
330 $parser->parse($contents);
\r
332 $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
\r
337 * Skin::getContent()
\r
338 * Get content of the skin part from the database
\r
340 * @param string $type type of the skin (e.g. index, item, search ...)
\r
341 * @return string content of scontent
\r
343 function getContent($type)
\r
345 $query = "SELECT scontent FROM %s WHERE sdesc=%d and stype='%s';";
\r
346 $query = sprintf($query, sql_table('skin'), (integer) $this->id, sql_real_escape_string($type));
\r
347 $res = sql_query($query);
\r
349 if ( sql_num_rows($res) == 0 )
\r
353 return sql_result($res, 0, 0);
\r
358 * Updates the contents for one part of the skin in the database
\r
360 * @param string $type type of the skin part (e.g. index, item, search ...)
\r
361 * @param string $content new content for this skin part
\r
365 function update($type, $content)
\r
369 $query = "SELECT sdesc FROM %s WHERE stype='%s' and sdesc=%d;";
\r
370 $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $this->id);
\r
371 $res = sql_query($query);
\r
373 $skintypeexists = sql_fetch_object($res);
\r
374 $skintypevalue = ($content == true);
\r
376 if( $skintypevalue && $skintypeexists )
\r
378 // PreUpdateSkinPart event
\r
380 'PreUpdateSkinPart',
\r
382 'skinid' => $this->id,
\r
384 'content' => &$content
\r
388 else if( $skintypevalue && !$skintypeexists )
\r
390 // PreAddSkinPart event
\r
394 'skinid' => $this->id,
\r
396 'content' => &$content
\r
400 else if( !$skintypevalue && $skintypeexists )
\r
402 // PreDeleteSkinPart event
\r
404 'PreDeleteSkinPart',
\r
406 'skinid' => $this->id,
\r
412 // delete old thingie
\r
413 $query = "DELETE FROM %s WHERE stype='%s' and sdesc=%d";
\r
414 $query = sprintf($query, sql_table('skin'), sql_real_escape_string($type), (integer) $this->id);
\r
417 // write new thingie
\r
420 $query = "INSERT INTO %s (scontent, stype, sdesc) VALUE ('%s', '%s', %d)";
\r
421 $query = sprintf($query, sql_table('skin'), sql_real_escape_string($content), sql_real_escape_string($type), (integer) $this->id);
\r
425 if( $skintypevalue && $skintypeexists )
\r
427 // PostUpdateSkinPart event
\r
429 'PostUpdateSkinPart',
\r
431 'skinid' => $this->id,
\r
433 'content' => &$content
\r
437 else if( $skintypevalue && (!$skintypeexists) )
\r
439 // PostAddSkinPart event
\r
443 'skinid' => $this->id,
\r
445 'content' => &$content
\r
449 else if( (!$skintypevalue) && $skintypeexists )
\r
451 // PostDeleteSkinPart event
\r
453 'PostDeleteSkinPart',
\r
455 'skinid' => $this->id,
\r
464 * Skin::deleteAllParts()
\r
465 * Deletes all skin parts from the database
\r
470 function deleteAllParts()
\r
472 $query = "DELETE FROM %s WHERE sdesc=%d;";
\r
473 $query = sprintf($query, sql_table('skin'), (integer) $this->id);
\r
478 * Skin::updateGeneralInfo()
\r
479 * Updates the general information about the skin
\r
481 * @param string $name name of the skin
\r
482 * @param string $desc description of the skin
\r
483 * @param string $type type of the skin
\r
484 * @param string $includeMode include mode of the skin
\r
485 * @param string $includePrefix include prefix of the skin
\r
488 function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '')
\r
490 $name = sql_real_escape_string($name);
\r
491 $desc = sql_real_escape_string($desc);
\r
492 $type = sql_real_escape_string($type);
\r
493 $includeMode = sql_real_escape_string($includeMode);
\r
494 $includePrefix = sql_real_escape_string($includePrefix);
\r
496 $query ="UPDATE %s SET sdname='', sddesc='%s', sdtype='%s', sdincmode='%s', sdincpref='%s' WHERE sdnumber=%d:";
\r
497 $query = sprintf($query, $name, $desc, $type, $includeMode, $includePrefix, (integer) $this->id);
\r
504 * Skin::getFriendlyNames()
\r
505 * Get an array with the names of possible skin parts
\r
506 * Used to show all possible parts of a skin in the administration backend
\r
509 * @param array type of the skin
\r
511 static public function getFriendlyNames()
\r
513 $skintypes = array(
\r
514 'index' => _SKIN_PART_MAIN,
\r
515 'item' => _SKIN_PART_ITEM,
\r
516 'archivelist' => _SKIN_PART_ALIST,
\r
517 'archive' => _SKIN_PART_ARCHIVE,
\r
518 'search' => _SKIN_PART_SEARCH,
\r
519 'error' => _SKIN_PART_ERROR,
\r
520 'member' => _SKIN_PART_MEMBER,
\r
521 'imagepopup' => _SKIN_PART_POPUP
\r
524 $query = "SELECT stype FROM " . sql_table('skin')
\r
525 . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
\r
526 $res = sql_query($query);
\r
527 while ( $row = sql_fetch_array($res) )
\r
529 /* TODO: ucfirst() depends on the current locale */
\r
530 $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
\r
536 * Skin::getAllowedActionsForType()
\r
537 * Get the allowed actions for a skin type
\r
538 * returns an array with the allowed actions
\r
540 * @param string $type type of the skin (e.g. index, item, search ...)
\r
541 * @return array allowed action types
\r
543 function getAllowedActionsForType($type)
\r
547 // some actions that can be performed at any time, from anywhere
\r
548 $defaultActions = array(
\r
558 'otherarchivelist',
\r
559 'otherarchivedaylist',
\r
560 'otherarchiveyearlist',
\r
583 // deprecated (Nucleus v2.0)
\r
584 /* TODO: remove this */
\r
588 // extra actions specific for a certain skin type
\r
589 $extraActions = array();
\r
594 $extraActions = array(
\r
608 $extraActions = array(
\r
625 case 'archivelist':
\r
626 $extraActions = array(
\r
636 $extraActions = array(
\r
643 'othersearchresults',
\r
651 $extraActions = array(
\r
653 // deprecated (Nucleus v2.0)
\r
654 /* TODO: remove this */
\r
659 $extraActions = array(
\r
667 $extraActions = array(
\r
690 $extraActions = array(
\r
696 if ( $blogid && $blogid > 0 )
\r
698 $extraActions = array(
\r
716 return array_merge($defaultActions, $extraActions);
\r