b2evolution PHP Cross Reference Blogging Systems

Source: /inc/skins/model/_skincache.class.php - 188 lines - 4713 bytes - Summary - Text - Print

Description: This file implements the SkinCache class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the SkinCache class.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * {@internal Open Source relicensing agreement:
  20   * }}
  21   *
  22   * @package evocore
  23   *
  24   * @author fplanque: Francois PLANQUE
  25   *
  26   * @version $Id: _skincache.class.php 6136 2014-03-08 07:59:48Z manuel $
  27   */
  28  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  29  
  30  load_class( '_core/model/dataobjects/_dataobjectcache.class.php', 'DataObjectCache' );
  31  
  32  load_class( 'skins/model/_skin.class.php', 'Skin' );
  33  
  34  load_funcs( 'skins/_skin.funcs.php' );
  35  
  36  /**
  37   * Skin Cache Class
  38   *
  39   * @package evocore
  40   */
  41  class SkinCache extends DataObjectCache
  42  {
  43      /**
  44       * Cache by folder
  45       * @var array
  46       */
  47      var $cache_by_folder = array();
  48  
  49      var $loaded_types = array();
  50  
  51  
  52      /**
  53       * Constructor
  54       */
  55  	function SkinCache()
  56      {
  57          parent::DataObjectCache( 'Skin', false, 'T_skins__skin', 'skin_', 'skin_ID', 'skin_name', NULL,
  58              /* TRANS: "None" select option */ T_('No skin') );
  59      }
  60  
  61  
  62      /**
  63       * Add object to cache, handling our own indices.
  64       *
  65       * @param Skin
  66       * @return boolean True on add, false if already existing.
  67       */
  68  	function add( & $Skin )
  69      {
  70          $this->cache_by_folder[ $Skin->folder ] = & $Skin;
  71  
  72          return parent::add( $Skin );
  73      }
  74  
  75  
  76      /**
  77       * Get an object from cache by its folder name.
  78       *
  79       * Load the object into cache, if necessary.
  80       *
  81       * This is used to get a skin for an RSS/Aom type; also to check if a skin is installed.
  82       *
  83       * @param string folder name of object to load
  84       * @param boolean false if you want to return false on error
  85       * @return Skin A Skin object on success, false on failure (may also halt!)
  86       */
  87      function & get_by_folder( $req_folder, $halt_on_error = true )
  88      {
  89          global $DB, $Debuglog;
  90  
  91          if( isset($this->cache_by_folder[$req_folder]) )
  92          {
  93              return $this->cache_by_folder[$req_folder];
  94          }
  95  
  96          // Load just the requested object:
  97          $Debuglog->add( "Loading <strong>$this->objtype($req_folder)</strong> into cache", 'dataobjects' );
  98          $sql = "
  99                  SELECT *
 100                    FROM $this->dbtablename
 101                   WHERE skin_folder = ".$DB->quote($req_folder);
 102          $row = $DB->get_row( $sql );
 103  
 104          if( empty( $row ) )
 105          { // Requested object does not exist
 106              if( $halt_on_error ) debug_die( "Requested $this->objtype does not exist!" );
 107              $r = false;
 108              return $r;
 109          }
 110  
 111          $Skin = new Skin( $row ); // COPY!
 112          $this->add( $Skin );
 113  
 114          return $Skin;
 115      }
 116  
 117  
 118      /**
 119       * Load the cache by type
 120       *
 121       * @param string
 122        */
 123  	function load_by_type( $type )
 124      {
 125          /**
 126           * @var DB
 127           */
 128          global $DB;
 129          global $Debuglog;
 130  
 131          if( $this->all_loaded || !empty($this->loaded_types[$type]) )
 132          { // Already loaded
 133              return false;
 134          }
 135  
 136          $Debuglog->add( get_class($this).' - Loading <strong>'.$this->objtype.'('.$type.')</strong> into cache', 'dataobjects' );
 137          $sql = 'SELECT *
 138                              FROM T_skins__skin
 139                           WHERE skin_type = '.$DB->quote($type).'
 140                           ORDER BY skin_name';
 141  
 142          foreach( $DB->get_results( $sql, OBJECT, 'Loading Skins('.$type.') into cache' ) as $row )
 143          {
 144              // Instantiate a custom object
 145              $this->instantiate( $row );
 146          }
 147  
 148          $this->loaded_types[$type] = true;
 149  
 150          return true;
 151      }
 152  
 153  
 154      /**
 155       * Instanciate a new object within this cache
 156       */
 157      function & new_obj( $row = NULL, $skin_folder = NULL )
 158      {
 159          if( is_null($skin_folder) )
 160          {    // This happens when using the default skin
 161              $skin_folder = $row->skin_folder;
 162          }
 163  
 164          // Check if we have a custom class derived from Skin:
 165          if( skin_file_exists( $skin_folder, '_skin.class.php' ) )
 166          {
 167              global $skins_path;
 168              require_once ( $skins_path.$skin_folder.'/_skin.class.php' );
 169              $objtype = $skin_folder.'_Skin';
 170              if( ! class_exists($objtype) )
 171              {
 172                  debug_die( 'There seems to be a _skin.class.php file in the skin directory ['.$skin_folder.'], but it does not contain a properly named class. Expected class name is: '.$objtype );
 173              }
 174          }
 175          else
 176          {
 177              $objtype = 'Skin';
 178          }
 179  
 180          // Instantiate a custom object
 181          $obj = new $objtype( $row, $skin_folder ); // COPY !!
 182  
 183          return $obj;
 184      }
 185  
 186  }
 187  
 188  ?>

title

Description

title

Description

title

Description

title

title

Body