3
* This file implements the WidgetCache class.
5
* This file is part of Quam Plures - {@link http://quamplures.net/}
6
* See also {@link https://launchpad.net/quam-plures}.
8
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
9
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
11
* {@internal License choice
12
* - If you have received this file as part of a package, please find the license.txt file in
13
* the same folder or the closest folder above for complete license terms.
14
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
15
* then you must choose one of the following licenses before using the file:
16
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
17
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
20
* {@internal Open Source relicensing agreement:
23
* @author fplanque: Francois PLANQUE
3
* This file implements the WidgetCache class
5
* This is a (partial?) list of authors who have contributed to this file:
6
* @author {@link http://wonderwinds.com/ Ed Bennett}
7
* @author {@link http://fplanque.net/ Francois PLANQUE}
8
* @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
9
* @copyright (c) 2003 by Francois PLANQUE - {@link http://fplanque.net/}
10
* @license {@link http://www.gnu.org/licenses/gpl.txt GNU General Public License v3}
11
* @todo (1111): vars type 'foo' need useful/valid descriptions
27
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
29
load_class('_core/model/dataobjects/_dataobjectcache.class.php');
31
load_class( 'widgets/model/_widget.class.php' );
14
if(!defined('QP_MAIN_INIT')) die('fail');
38
20
class WidgetCache extends DataObjectCache
42
24
* @var array of coll_ID => array of container_name => array of Widget
44
26
var $cache_container_Widget_array = array();
47
* Indicates whether to load enabled widgets only.
28
* Indicates whether to load enabled widgets only
50
31
var $load_enabled_only;
55
35
* @param boolean Load enabled widgets only?
57
37
function WidgetCache( $enabled_only = false )
45
* Get Widget by Blog ID
65
46
* @param integer Collection (blog) ID
66
47
* @return array of coll_ID => array of container_name => array of Widget
68
function & get_by_coll_ID( $coll_ID )
49
function & get_by_blogID( $coll_ID )
72
53
if( ! isset( $this->cache_container_Widget_array[$coll_ID] ) )
73
{ // Not in Cache yet:
76
WHERE wi_coll_ID = '.$coll_ID;
77
if ( $this->load_enabled_only )
78
{ // We want to load enabled widgets only:
56
$sql = 'SELECT * FROM T_widget WHERE wi_coll_ID = '.$coll_ID;
57
if( $this->load_enabled_only )
59
// We want to load enabled widgets only
79
60
$sql .= ' AND wi_enabled = 1';
81
62
$sql .= ' ORDER BY wi_sco_name, wi_order';
86
67
$count = count( $widget_rs );
87
68
for( $i = 0; $i < $count; $i++ )
89
// 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
90
if( $ComponentWidget = & $this->new_obj( $widget_rs[$i] ) ) // fp> NOTE: no copy because we need copy on the next line anyway!!
91
{ // We were able to instantiate the widget:
92
// Add to regular cache (but not with $this->add() because we need a COPY!!):
70
// fp> NOTE: object COPYing is weird here but it needs to be like
71
// this in PHP4 or all objects from the loop will look the same
72
if( $ComponentWidget = & $this->new_obj( $widget_rs[$i] ) )
74
// We were able to instantiate the widget, add to regular cache
75
// (but not with $this->add() because we need a COPY!!)
93
76
$this->cache[$ComponentWidget->ID] = $ComponentWidget; // COPY!!!! WEIRD BUT NECESSARY / PHP 4 (fp)
94
// This is the cache we're interested in:
77
// This is the cache we're interested in
95
78
$this->cache_container_Widget_array[$ComponentWidget->coll_ID][$ComponentWidget->sco_name][] = & $this->cache[$ComponentWidget->ID];
98
// TODO: dh> try the next line, and you may be able to assign by reference to $cache or use add()
99
unset($ComponentWidget);
80
unset( $ComponentWidget );
104
83
return $this->cache_container_Widget_array[$coll_ID];
109
88
* Instanciate a new object within this cache
89
* @todo (0000): from TODO_HERE, replace with dummy widget in order to give a chance to clean up
111
91
function & new_obj( $row = NULL )
114
93
if( $row->wi_type == 'widget' )
116
if( !$this->load_widget( $row->wi_code ) )
95
if( ! $this->load_widget( $row->wi_code ) )
118
// TODO: replace with dummy widget in order to give a chance to clean up.
137
* Loads appropriate widget class file.
116
* Loads appropriate widget class file
139
117
* @param string $wi_code widget to load
140
* @return boolean Whether the class file could be loaded. Note that this method will return true
141
* if the file has been included before (there is no way to find out whether require_once()
142
* really included a file).
118
* @return boolean Whether the class file could be loaded. Note this method will return true if the file
119
* has been included before (there is no way to find out whether require_once() really included a file)
144
121
function load_widget( $wi_code )
146
global $plugins_path, $Debuglog;
148
// Note: file_exists() should not have a big impact on IO performance since PHP caches the
150
if( file_exists( $plugins_path.$wi_code.'_widget/_'.$wi_code.'.widget.php' ) )
151
{ // widget is in its own folder
152
//$Debuglog->add( 'Loading class: '.$wi_code, 'widgets' );
153
// require_once makes sure each widget class is only loaded once.
154
require_once $plugins_path.$wi_code.'_widget/_'.$wi_code.'.widget.php';
125
// file_exists() should not have a big impact on IO performance since PHP caches the results
126
if( file_exists( $inc_path.'widgets/_'.$wi_code.'.widget.php' ) )
128
// widget is in its own folder ... require_once makes sure each widget class is only loaded once
129
require_once $inc_path.'widgets/_'.$wi_code.'.widget.php';
163
* @param integer Collection (blog) ID
164
* @param string Container
137
* Function without a Title
138
* @param integer blog ID
139
* @param string Container name
165
140
* @return array of Widget
167
142
function & get_by_coll_container( $coll_ID, $container )
169
// Make sure collection is loaded:
170
$this->get_by_coll_ID( $coll_ID );
144
// Make sure collection is loaded
145
$this->get_by_blogID( $coll_ID );
172
146
return $this->cache_container_Widget_array[$coll_ID][$container];