SKIN.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00004  * Copyright (C) 2002-2007 The Nucleus Group
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * (see nucleus/documentation/index.html#license for more info)
00011  */
00021 if ( !function_exists('requestVar') ) exit;
00022 require_once dirname(__FILE__) . '/ACTIONS.php';
00023 
00024 class SKIN {
00025 
00026         // after creating a SKIN object, evaluates to true when the skin exists
00027         var $isValid;
00028 
00029         // skin characteristics. Use the getXXX methods rather than accessing directly
00030         var $id;
00031         var $description;
00032         var $contentType;
00033         var $includeMode;               // either 'normal' or 'skindir'
00034         var $includePrefix;
00035         var $name;
00036 
00037         function SKIN($id) {
00038                 $this->id = intval($id);
00039 
00040                 // read skin name/description/content type
00041                 $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
00042                 $obj = mysql_fetch_object($res);
00043                 $this->isValid = (mysql_num_rows($res) > 0);
00044                 if (!$this->isValid)
00045                         return;
00046 
00047                 $this->name = $obj->sdname;
00048                 $this->description = $obj->sddesc;
00049                 $this->contentType = $obj->sdtype;
00050                 $this->includeMode = $obj->sdincmode;
00051                 $this->includePrefix = $obj->sdincpref;
00052 
00053         }
00054 
00055         function getID() {                              return $this->id; }
00056         function getName() {                    return $this->name; }
00057         function getDescription() {     return $this->description; }
00058         function getContentType() {     return $this->contentType; }
00059         function getIncludeMode() {     return $this->includeMode; }
00060         function getIncludePrefix() {   return $this->includePrefix; }
00061 
00068         function exists($name) {
00069                 return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.addslashes($name).'"') > 0;
00070         }
00071 
00078         function existsID($id) {
00079                 return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0;
00080         }
00081 
00088         function createFromName($name) {
00089                 return new SKIN(SKIN::getIdFromName($name));
00090         }
00091 
00098         function getIdFromName($name) {
00099                 $query =  'SELECT sdnumber'
00100                            . ' FROM '.sql_table('skin_desc')
00101                            . ' WHERE sdname="'.addslashes($name).'"';
00102                 $res = sql_query($query);
00103                 $obj = mysql_fetch_object($res);
00104                 return $obj->sdnumber;
00105         }
00106 
00113         function getNameFromId($id) {
00114                 return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id));
00115         }
00116 
00122         function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
00123                 global $manager;
00124 
00125                 $manager->notify(
00126                         'PreAddSkin',
00127                         array(
00128                                 'name' => &$name,
00129                                 'description' => &$desc,
00130                                 'type' => &$type,
00131                                 'includeMode' => &$includeMode,
00132                                 'includePrefix' => &$includePrefix
00133                         )
00134                 );
00135 
00136                 sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "','".addslashes($type)."','".addslashes($includeMode)."','".addslashes($includePrefix)."')");
00137                 $newid = mysql_insert_id();
00138 
00139                 $manager->notify(
00140                         'PostAddSkin',
00141                         array(
00142                                 'skinid' => $newid,
00143                                 'name' => $name,
00144                                 'description' => $desc,
00145                                 'type' => $type,
00146                                 'includeMode' => $includeMode,
00147                                 'includePrefix' => $includePrefix
00148                         )
00149                 );
00150 
00151                 return $newid;
00152         }
00153 
00154         function parse($type) {
00155                 global $manager, $CONF;
00156 
00157                 $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
00158 
00159                 // set output type
00160                 sendContentType($this->getContentType(), 'skin', _CHARSET);
00161 
00162                 // set skin name as global var (so plugins can access it)
00163                 global $currentSkinName;
00164                 $currentSkinName = $this->getName();
00165 
00166                 $contents = $this->getContent($type);
00167 
00168                 if (!$contents) {
00169                         // use base skin if this skin does not have contents
00170                         $defskin =& new SKIN($CONF['BaseSkin']);
00171                         $contents = $defskin->getContent($type);
00172                         if (!$contents) {
00173                                 echo _ERROR_SKIN;
00174                                 return;
00175                         }
00176                 }
00177 
00178                 $actions = $this->getAllowedActionsForType($type);
00179 
00180                 $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
00181 
00182                 // set IncludeMode properties of parser
00183                 PARSER::setProperty('IncludeMode',$this->getIncludeMode());
00184                 PARSER::setProperty('IncludePrefix',$this->getIncludePrefix());
00185 
00186                 $handler =& new ACTIONS($type, $this);
00187                 $parser =& new PARSER($actions, $handler);
00188                 $handler->setParser($parser);
00189                 $handler->setSkin($this);
00190                 $parser->parse($contents);
00191 
00192                 $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
00193 
00194 
00195         }
00196 
00197         function getContent($type) {
00198                 $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". addslashes($type) ."'";
00199                 $res = sql_query($query);
00200 
00201                 if (mysql_num_rows($res) == 0)
00202                         return '';
00203                 else
00204                         return mysql_result($res, 0, 0);
00205         }
00206 
00210         function update($type, $content) {
00211                 $skinid = $this->id;
00212 
00213                 // delete old thingie
00214                 sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".addslashes($type)."' and sdesc=" . intval($skinid));
00215 
00216                 // write new thingie
00217                 if ($content) {
00218                         sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . addslashes($content) . "', stype='" . addslashes($type) . "', sdesc=" . intval($skinid));
00219                 }
00220         }
00221 
00225         function deleteAllParts() {
00226                 sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID());
00227         }
00228 
00232         function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
00233                 $query =  'UPDATE '.sql_table('skin_desc').' SET'
00234                            . " sdname='" . addslashes($name) . "',"
00235                            . " sddesc='" . addslashes($desc) . "',"
00236                            . " sdtype='" . addslashes($type) . "',"
00237                            . " sdincmode='" . addslashes($includeMode) . "',"
00238                            . " sdincpref='" . addslashes($includePrefix) . "'"
00239                            . " WHERE sdnumber=" . $this->getID();
00240                 sql_query($query);
00241         }
00242 
00246         function getFriendlyNames() {
00247                 $skintypes = array(
00248                         'index' => _SKIN_PART_MAIN,
00249                         'item' => _SKIN_PART_ITEM,
00250                         'archivelist' => _SKIN_PART_ALIST,
00251                         'archive' => _SKIN_PART_ARCHIVE,
00252                         'search' => _SKIN_PART_SEARCH,
00253                         'error' => _SKIN_PART_ERROR,
00254                         'member' => _SKIN_PART_MEMBER,
00255                         'imagepopup' => _SKIN_PART_POPUP
00256                 );
00257 
00258                 $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
00259                 $res = sql_query($query);
00260                 while ($row = mysql_fetch_array($res)) {
00261                         $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
00262                 }
00263 
00264                 return $skintypes;
00265         }
00266 
00267         function getAllowedActionsForType($type) {
00268                 global $blogid;
00269 
00270                 // some actions that can be performed at any time, from anywhere
00271                 $defaultActions = array('otherblog',
00272                                                                 'plugin',
00273                                                                 'version',
00274                                                                 'nucleusbutton',
00275                                                                 'include',
00276                                                                 'phpinclude',
00277                                                                 'parsedinclude',
00278                                                                 'loginform',
00279                                                                 'sitevar',
00280                                                                 'otherarchivelist',
00281                                                                 'otherarchivedaylist',
00282                                                                 'self',
00283                                                                 'adminurl',
00284                                                                 'todaylink',
00285                                                                 'archivelink',
00286                                                                 'member',
00287                                                                 'ifcat',                                        // deprecated (Nucleus v2.0)
00288                                                                 'category',
00289                                                                 'searchform',
00290                                                                 'referer',
00291                                                                 'skinname',
00292                                                                 'skinfile',
00293                                                                 'set',
00294                                                                 'if',
00295                                                                 'else',
00296                                                                 'endif',
00297                                                                 'elseif',
00298                                                                 'ifnot',
00299                                                                 'elseifnot',
00300                                                                 'charset',
00301                                                                 'bloglist'
00302                                                                 );
00303 
00304                 // extra actions specific for a certain skin type
00305                 $extraActions = array();
00306 
00307                 switch ($type) {
00308                         case 'index':
00309                                 $extraActions = array('blog',
00310                                                                 'blogsetting',
00311                                                                 'preview',
00312                                                                 'additemform',
00313                                                                 'categorylist',
00314                                                                 'archivelist',
00315                                                                 'archivedaylist',
00316                                                                 'nextlink',
00317                                                                 'prevlink'
00318                                                                 );
00319                                 break;
00320                         case 'archive':
00321                                 $extraActions = array('blog',
00322                                                                 'archive',
00323                                                                 'otherarchive',
00324                                                                 'categorylist',
00325                                                                 'archivelist',
00326                                                                 'archivedaylist',
00327                                                                 'blogsetting',
00328                                                                 'archivedate',
00329                                                                 'nextarchive',
00330                                                                 'prevarchive',
00331                                                                 'nextlink',
00332                                                                 'prevlink',
00333                                                                 'archivetype'
00334                                 );
00335                                 break;
00336                         case 'archivelist':
00337                                 $extraActions = array('blog',
00338                                                                 'archivelist',
00339                                                                 'archivedaylist',
00340                                                                 'categorylist',
00341                                                                 'blogsetting',
00342                                                            );
00343                                 break;
00344                         case 'search':
00345                                 $extraActions = array('blog',
00346                                                                 'archivelist',
00347                                                                 'archivedaylist',
00348                                                                 'categorylist',
00349                                                                 'searchresults',
00350                                                                 'othersearchresults',
00351                                                                 'blogsetting',
00352                                                                 'query',
00353                                                                 'nextlink',
00354                                                                 'prevlink'
00355                                                                 );
00356                                 break;
00357                         case 'imagepopup':
00358                                 $extraActions = array('image',
00359                                                                 'imagetext',                            // deprecated (Nucleus v2.0)
00360                                                                 );
00361                                 break;
00362                         case 'member':
00363                                 $extraActions = array(
00364                                                                 'membermailform',
00365                                                                 'blogsetting',
00366                                                                 'nucleusbutton'
00367                                 );
00368                                 break;
00369                         case 'item':
00370                                 $extraActions = array('blog',
00371                                                                 'item',
00372                                                                 'comments',
00373                                                                 'commentform',
00374                                                                 'vars',
00375                                                                 'blogsetting',
00376                                                                 'nextitem',
00377                                                                 'previtem',
00378                                                                 'nextlink',
00379                                                                 'prevlink',
00380                                                                 'nextitemtitle',
00381                                                                 'previtemtitle',
00382                                                                 'categorylist',
00383                                                                 'archivelist',
00384                                                                 'archivedaylist',
00385                                                                 'itemtitle',
00386                                                                 'itemid',
00387                                                                 'itemlink',
00388                                                                 );
00389                                 break;
00390                         case 'error':
00391                                 $extraActions = array(
00392                                                                 'errormessage'
00393                                 );
00394                                 break;
00395                         default:
00396                                 if ($blogid && $blogid > 0) {
00397                                         $extraActions = array(
00398                                                 'blog',
00399                                                 'blogsetting',
00400                                                 'preview',
00401                                                 'additemform',
00402                                                 'categorylist',
00403                                                 'archivelist',
00404                                                 'archivedaylist',
00405                                                 'nextlink',
00406                                                 'archivelist',
00407                                                 'archivedaylist',
00408                                                 'prevlink',
00409                                                 'membermailform',
00410                                                 'nucleusbutton'
00411                                         );
00412                                 }
00413                                 break;
00414                 }
00415 
00416                 return array_merge($defaultActions, $extraActions);
00417         }
00418 
00419 }
00420 
00421 ?>



Generated on Wed Jun 25 17:25:59 2008 by  doxygen 1.5.5