b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/model/_widgetcache.class.php - 165 lines - 5077 bytes - Summary - Text - Print

Description: This file implements the WidgetCache 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 WidgetCache 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: _widgetcache.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( 'widgets/model/_widget.class.php', 'ComponentWidget' );
  33  
  34  /**
  35   * Widget Cache Class
  36   *
  37   * @package evocore
  38   */
  39  class WidgetCache extends DataObjectCache
  40  {
  41      /**
  42       * Cache by container
  43       * @var array of coll_ID => array of container_name => array of Widget
  44       */
  45      var $cache_container_Widget_array = array();
  46  
  47      /**
  48       * Indicates whether to load enabled widgets only.
  49       * @var boolean
  50       */
  51      var $load_enabled_only;
  52  
  53      /**
  54       * Constructor
  55       *
  56       * @param boolean Load enabled widgets only?
  57       */
  58  	function WidgetCache( $enabled_only = false )
  59      {
  60          parent::DataObjectCache( 'ComponentWidget', false, 'T_widget', 'wi_', 'wi_ID', NULL, NULL, NULL );
  61          $this->load_enabled_only = $enabled_only;
  62      }
  63  
  64  
  65      /**
  66       * @param integer Collection (blog) ID
  67       * @return array of coll_ID => array of container_name => array of Widget
  68       */
  69      function & get_by_coll_ID( $coll_ID )
  70      {
  71          global $DB;
  72  
  73          if( ! isset( $this->cache_container_Widget_array[$coll_ID] ) )
  74          {    // Not in Cache yet:
  75              $sql = 'SELECT *
  76                            FROM T_widget
  77                           WHERE wi_coll_ID = '.$coll_ID;
  78              if ( $this->load_enabled_only )
  79              {    // We want to load enabled widgets only:
  80                  $sql .= ' AND wi_enabled = 1';
  81              }
  82              $sql .= ' ORDER BY wi_sco_name, wi_order';
  83  
  84              $widget_rs = $DB->get_results( $sql, OBJECT, 'Get list of widgets for collection' );
  85  
  86              $this->cache_container_Widget_array[$coll_ID] = array();
  87              $count = count( $widget_rs );
  88              for( $i = 0; $i < $count; $i++ )
  89              {
  90                  // fp> NOTE: object COPYing is weird here but it needs to be like this in PHP4 or all abjects from the loop will look the same
  91                  if( $ComponentWidget = & $this->new_obj( $widget_rs[$i] ) ) // fp> NOTE: no copy because we need copy on the next line anyway!!
  92                  {    // We were able to instantiate the widget:
  93                      // Add to regular cache (but not with $this->add() because we need a COPY!!):
  94                      $this->cache[$ComponentWidget->ID] = $ComponentWidget; // COPY!!!! WEIRD BUT NECESSARY / PHP 4 (fp)
  95                      // This is the cache we're interested in:
  96                      $this->cache_container_Widget_array[$ComponentWidget->coll_ID][$ComponentWidget->sco_name][] = & $this->cache[$ComponentWidget->ID];
  97                  }
  98  
  99                  // TODO: dh> try the next line, and you may be able to assign by reference to $cache or use add()
 100                  unset($ComponentWidget);
 101              }
 102              // pre_dump($this->cache_container_Widget_array[$coll_ID]);
 103          }
 104  
 105          return $this->cache_container_Widget_array[$coll_ID];
 106      }
 107  
 108  
 109      /**
 110       * Instanciate a new object within this cache
 111       */
 112      function & new_obj( $row = NULL )
 113      {
 114          global $inc_path;
 115  
 116          if( $row->wi_type == 'core' )
 117          {
 118          /* 
 119          fp>alex TODO: This feature is ok BUT please move this code into the offending widget files
 120                       there must not be any hard coced widget named in this class
 121          
 122              if( ! isset($GLOBALS['files_Module']) && in_array( $row->wi_code, array('coll_media_index', 'coll_avatar') ) )
 123              {    // Disable widgets dependent on files_Module
 124                  $r = NULL;
 125                  return $r;
 126              }
 127          */
 128          
 129              if( ! file_exists( $inc_path.'widgets/widgets/_'.$row->wi_code.'.widget.php' ) )
 130              {    // For some reason, that widget doesn't seem to exist... (any more?)
 131                  // echo "Widget $row->wi_code could not be loaded! ";
 132                  // TODO: replace with dummy widget in order to give a chance to clean up.
 133                  $r = NULL;
 134                  return $r;
 135              }
 136              require_once $inc_path.'widgets/widgets/_'.$row->wi_code.'.widget.php';
 137              $objtype = $row->wi_code.'_Widget';
 138          }
 139          else
 140          {
 141              $objtype = 'ComponentWidget';
 142          }
 143  
 144          // Instantiate a custom object
 145          $obj = new $objtype( $row ); // COPY !!
 146  
 147          return $obj;
 148      }
 149  
 150  
 151      /**
 152       * @param integer Collection (blog) ID
 153       * @param string Container
 154       * @return array of Widget
 155       */
 156      function & get_by_coll_container( $coll_ID, $container )
 157      {
 158          // Make sure collection is loaded:
 159          $this->get_by_coll_ID( $coll_ID );
 160  
 161          return $this->cache_container_Widget_array[$coll_ID][$container];
 162      }
 163  }
 164  
 165  ?>

title

Description

title

Description

title

Description

title

title

Body