[ Index ]

PHP Cross Reference of Nucleus CMS 3.64

title

Body

[close]

/nucleus3.64/nucleus/libs/ -> SKIN.php (source)

   1  <?php
   2  /*
   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   4   * Copyright (C) 2002-2009 The Nucleus Group
   5   *
   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)
  11   */
  12  /**
  13   * Class representing a skin
  14   *
  15   * @license http://nucleuscms.org/license.txt GNU General Public License
  16   * @copyright Copyright (C) 2002-2009 The Nucleus Group
  17   * @version $Id: SKIN.php 1470 2010-11-29 22:10:16Z ftruscot $
  18   */
  19  
  20  if ( !function_exists('requestVar') ) exit;
  21  require_once dirname(__FILE__) . '/ACTIONS.php';
  22  
  23  class SKIN {
  24  
  25      // after creating a SKIN object, evaluates to true when the skin exists
  26      var $isValid;
  27  
  28      // skin characteristics. Use the getXXX methods rather than accessing directly
  29      var $id;
  30      var $description;
  31      var $contentType;
  32      var $includeMode;        // either 'normal' or 'skindir'
  33      var $includePrefix;
  34      var $name;
  35  
  36  	function SKIN($id) {
  37          $this->id = intval($id);
  38  
  39          // read skin name/description/content type
  40          $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
  41          $obj = sql_fetch_object($res);
  42          $this->isValid = (sql_num_rows($res) > 0);
  43          if (!$this->isValid)
  44              return;
  45  
  46          $this->name = $obj->sdname;
  47          $this->description = $obj->sddesc;
  48          $this->contentType = $obj->sdtype;
  49          $this->includeMode = $obj->sdincmode;
  50          $this->includePrefix = $obj->sdincpref;
  51  
  52      }
  53  
  54  	function getID() {                return $this->id; }
  55  	function getName() {             return $this->name; }
  56  	function getDescription() {     return $this->description; }
  57  	function getContentType() {     return $this->contentType; }
  58  	function getIncludeMode() {     return $this->includeMode; }
  59  	function getIncludePrefix() {     return $this->includePrefix; }
  60  
  61      /**
  62       * Checks if a skin with a given shortname exists
  63       * @param string $name Skin short name
  64       * @return int number of skins with the given ID
  65       * @static
  66       */
  67  	function exists($name) {
  68          return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.sql_real_escape_string($name).'"') > 0;
  69      }
  70  
  71      /**
  72       * Checks if a skin with a given ID exists
  73       * @param string $id Skin ID
  74       * @return int number of skins with the given ID
  75       * @static
  76       */
  77  	function existsID($id) {
  78          return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0;
  79      }
  80  
  81      /**
  82       * Returns a skin given its shortname
  83       * @param string $name Skin shortname
  84       * @return object SKIN
  85       * @static
  86       */
  87  	function createFromName($name) {
  88          return new SKIN(SKIN::getIdFromName($name));
  89      }
  90  
  91      /**
  92       * Returns a skin ID given its shortname
  93       * @param string $name Skin shortname
  94       * @return int Skin ID
  95       * @static
  96       */
  97  	function getIdFromName($name) {
  98          $query =  'SELECT sdnumber'
  99                 . ' FROM '.sql_table('skin_desc')
 100                 . ' WHERE sdname="'.sql_real_escape_string($name).'"';
 101          $res = sql_query($query);
 102          $obj = sql_fetch_object($res);
 103          return $obj->sdnumber;
 104      }
 105  
 106      /**
 107       * Returns a skin shortname given its ID
 108       * @param string $name
 109       * @return string Skin short name
 110       * @static
 111       */
 112  	function getNameFromId($id) {
 113          return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id));
 114      }
 115  
 116      /**
 117       * Creates a new skin, with the given characteristics.
 118       *
 119       * @static
 120       */
 121  	function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
 122          global $manager;
 123  
 124          $manager->notify(
 125              'PreAddSkin',
 126              array(
 127                  'name' => &$name,
 128                  'description' => &$desc,
 129                  'type' => &$type,
 130                  'includeMode' => &$includeMode,
 131                  'includePrefix' => &$includePrefix
 132              )
 133          );
 134  
 135          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)."')");
 136          $newid = sql_insert_id();
 137  
 138          $manager->notify(
 139              'PostAddSkin',
 140              array(
 141                  'skinid' => $newid,
 142                  'name' => $name,
 143                  'description' => $desc,
 144                  'type' => $type,
 145                  'includeMode' => $includeMode,
 146                  'includePrefix' => $includePrefix
 147              )
 148          );
 149  
 150          return $newid;
 151      }
 152  
 153  	function parse($type) {
 154          global $manager, $CONF;
 155  
 156          $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type));
 157  
 158          // set output type
 159          sendContentType($this->getContentType(), 'skin', _CHARSET);
 160  
 161          // set skin name as global var (so plugins can access it)
 162          global $currentSkinName;
 163          $currentSkinName = $this->getName();
 164  
 165          $contents = $this->getContent($type);
 166  
 167          if (!$contents) {
 168              // use base skin if this skin does not have contents
 169              $defskin =& new SKIN($CONF['BaseSkin']);
 170              $contents = $defskin->getContent($type);
 171              if (!$contents) {
 172                  echo _ERROR_SKIN;
 173                  return;
 174              }
 175          }
 176  
 177          $actions = $this->getAllowedActionsForType($type);
 178  
 179          $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
 180  
 181          // set IncludeMode properties of parser
 182          PARSER::setProperty('IncludeMode',$this->getIncludeMode());
 183          PARSER::setProperty('IncludePrefix',$this->getIncludePrefix());
 184  
 185          $handler =& new ACTIONS($type, $this);
 186          $parser =& new PARSER($actions, $handler);
 187          $handler->setParser($parser);
 188          $handler->setSkin($this);
 189          $parser->parse($contents);
 190  
 191          $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
 192  
 193  
 194      }
 195  
 196  	function getContent($type) {
 197          $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". sql_real_escape_string($type) ."'";
 198          $res = sql_query($query);
 199  
 200          if (sql_num_rows($res) == 0)
 201              return '';
 202          else
 203              return sql_result($res, 0, 0);
 204      }
 205  
 206      /**
 207       * Updates the contents of one part of the skin
 208       */
 209  	function update($type, $content) {
 210          $skinid = $this->id;
 211  
 212          // delete old thingie
 213          sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".sql_real_escape_string($type)."' and sdesc=" . intval($skinid));
 214  
 215          // write new thingie
 216          if ($content) {
 217              sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . sql_real_escape_string($content) . "', stype='" . sql_real_escape_string($type) . "', sdesc=" . intval($skinid));
 218          }
 219      }
 220  
 221      /**
 222       * Deletes all skin parts from the database
 223       */
 224  	function deleteAllParts() {
 225          sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID());
 226      }
 227  
 228      /**
 229       * Updates the general information about the skin
 230       */
 231  	function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
 232          $query =  'UPDATE '.sql_table('skin_desc').' SET'
 233                 . " sdname='" . sql_real_escape_string($name) . "',"
 234                 . " sddesc='" . sql_real_escape_string($desc) . "',"
 235                 . " sdtype='" . sql_real_escape_string($type) . "',"
 236                 . " sdincmode='" . sql_real_escape_string($includeMode) . "',"
 237                 . " sdincpref='" . sql_real_escape_string($includePrefix) . "'"
 238                 . " WHERE sdnumber=" . $this->getID();
 239          sql_query($query);
 240      }
 241  
 242      /**
 243       * static: returns an array of friendly names
 244       */
 245  	function getFriendlyNames() {
 246          $skintypes = array(
 247              'index' => _SKIN_PART_MAIN,
 248              'item' => _SKIN_PART_ITEM,
 249              'archivelist' => _SKIN_PART_ALIST,
 250              'archive' => _SKIN_PART_ARCHIVE,
 251              'search' => _SKIN_PART_SEARCH,
 252              'error' => _SKIN_PART_ERROR,
 253              'member' => _SKIN_PART_MEMBER,
 254              'imagepopup' => _SKIN_PART_POPUP
 255          );
 256  
 257          $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')";
 258          $res = sql_query($query);
 259          while ($row = sql_fetch_array($res)) {
 260              $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']);
 261          }
 262  
 263          return $skintypes;
 264      }
 265  
 266  	function getAllowedActionsForType($type) {
 267          global $blogid;
 268  
 269          // some actions that can be performed at any time, from anywhere
 270          $defaultActions = array('otherblog',
 271                                  'plugin',
 272                                  'version',
 273                                  'nucleusbutton',
 274                                  'include',
 275                                  'phpinclude',
 276                                  'parsedinclude',
 277                                  'loginform',
 278                                  'sitevar',
 279                                  'otherarchivelist',
 280                                  'otherarchivedaylist',
 281                                  'otherarchiveyearlist',
 282                                  'self',
 283                                  'adminurl',
 284                                  'todaylink',
 285                                  'archivelink',
 286                                  'member',
 287                                  'ifcat',                    // deprecated (Nucleus v2.0)
 288                                  'category',
 289                                  'searchform',
 290                                  'referer',
 291                                  'skinname',
 292                                  'skinfile',
 293                                  'set',
 294                                  'if',
 295                                  'else',
 296                                  'endif',
 297                                  'elseif',
 298                                  'ifnot',
 299                                  'elseifnot',
 300                                  'charset',
 301                                  'bloglist',
 302                                  'addlink',
 303                                  'addpopupcode',
 304                                  'sticky'
 305                                  );
 306  
 307          // extra actions specific for a certain skin type
 308          $extraActions = array();
 309  
 310          switch ($type) {
 311              case 'index':
 312                  $extraActions = array('blog',
 313                                  'blogsetting',
 314                                  'preview',
 315                                  'additemform',
 316                                  'categorylist',
 317                                  'archivelist',
 318                                  'archivedaylist',
 319                                  'archiveyearlist',
 320                                  'nextlink',
 321                                  'prevlink'
 322                                  );
 323                  break;
 324              case 'archive':
 325                  $extraActions = array('blog',
 326                                  'archive',
 327                                  'otherarchive',
 328                                  'categorylist',
 329                                  'archivelist',
 330                                  'archivedaylist',
 331                                  'archiveyearlist',
 332                                  'blogsetting',
 333                                  'archivedate',
 334                                  'nextarchive',
 335                                  'prevarchive',
 336                                  'nextlink',
 337                                  'prevlink',
 338                                  'archivetype'
 339                  );
 340                  break;
 341              case 'archivelist':
 342                  $extraActions = array('blog',
 343                                  'archivelist',
 344                                  'archivedaylist',
 345                                  'archiveyearlist',
 346                                  'categorylist',
 347                                  'blogsetting',
 348                                 );
 349                  break;
 350              case 'search':
 351                  $extraActions = array('blog',
 352                                  'archivelist',
 353                                  'archivedaylist',
 354                                  'archiveyearlist',
 355                                  'categorylist',
 356                                  'searchresults',
 357                                  'othersearchresults',
 358                                  'blogsetting',
 359                                  'query',
 360                                  'nextlink',
 361                                  'prevlink'
 362                                  );
 363                  break;
 364              case 'imagepopup':
 365                  $extraActions = array('image',
 366                                  'imagetext',                // deprecated (Nucleus v2.0)
 367                                  );
 368                  break;
 369              case 'member':
 370                  $extraActions = array(
 371                                  'membermailform',
 372                                  'blogsetting',
 373                                  'nucleusbutton',
 374                                  'categorylist'
 375                  );
 376                  break;
 377              case 'item':
 378                  $extraActions = array('blog',
 379                                  'item',
 380                                  'comments',
 381                                  'commentform',
 382                                  'vars',
 383                                  'blogsetting',
 384                                  'nextitem',
 385                                  'previtem',
 386                                  'nextlink',
 387                                  'prevlink',
 388                                  'nextitemtitle',
 389                                  'previtemtitle',
 390                                  'categorylist',
 391                                  'archivelist',
 392                                  'archivedaylist',
 393                                  'archiveyearlist',
 394                                  'itemtitle',
 395                                  'itemid',
 396                                  'itemlink',
 397                                  );
 398                  break;
 399              case 'error':
 400                  $extraActions = array(
 401                                  'errormessage',
 402                                  'categorylist'
 403                  );
 404                  break;
 405              default:
 406                  if ($blogid && $blogid > 0) {
 407                      $extraActions = array(
 408                          'blog',
 409                          'blogsetting',
 410                          'preview',
 411                          'additemform',
 412                          'categorylist',
 413                          'archivelist',
 414                          'archivedaylist',
 415                          'archiveyearlist',
 416                          'nextlink',
 417                          'prevlink',
 418                          'membermailform',
 419                          'nucleusbutton',
 420                          'categorylist'
 421                      );
 422                  }
 423                  break;
 424          }
 425  
 426          return array_merge($defaultActions, $extraActions);
 427      }
 428  
 429  }
 430  
 431  ?>


Generated: Mon May 2 16:14:08 2011 Cross-referenced by PHPXref 0.7.1