Source for file _blogcache.class.php
Documentation is available at _blogcache.class.php
* This file implements the BlogCache class.
* This file is part of the evoCore framework - {@link http://evocore.net/}
* See also {@link http://sourceforge.net/projects/evocms/}.
* @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
* {@internal License choice
* - If you have received this file as part of a package, please find the license.txt file in
* the same folder or the closest folder above for complete license terms.
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
* then you must choose one of the following licenses before using the file:
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
* {@internal Open Source relicensing agreement:
* Daniel HAHLER grants Francois PLANQUE the right to license
* Daniel HAHLER's contributions to this file and the b2evolution project
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
* @author blueyed: Daniel HAHLER.
* @author fplanque: Francois PLANQUE
* @version $Id: _blogcache.class.php,v 1.12 2010/02/08 17:52:09 efy-yury Exp $
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
load_class( '_core/model/dataobjects/_dataobjectcache.class.php', 'DataObjectCache' );
* Cache by absolute siteurl
parent::DataObjectCache( 'Blog', false, 'T_blogs', 'blog_', 'blog_ID', NULL, '',
/* TRANS: "None" select option */ T_('No blog'), 0 );
* Add object to cache, handling our own indices.
* @return boolean True on add, false if already existing.
if( ! empty($Blog->siteurl) &&
preg_match( '~^https?://~', $Blog->siteurl ) )
return parent::add( $Blog );
* Get an object from cache by its url ("siteurl")
* Load the cache if necessary
* This gets used in /index_multi.php to detect blogs according to the requested HostWithPath
* @todo fp> de-factorize. cleanup. make efficient. split access types.
* @param string URL of blog to load (should be the whole requested URL/path, e.g. "http://mr.example.com/permalink")
* @param boolean false if you want to return false on error
* @return Blog A Blog object on success, false on failure (may also halt!)
function & get_by_url( $req_url, $halt_on_error =
true )
if( strpos( $req_url, $siteurl ) ===
0 )
// Load just the requested object:
$Debuglog->add( "Loading <strong>$this->objtype($req_url)</strong> into cache", 'dataobjects' );
$req_url_wo_proto =
substr( $req_url, strpos( $req_url, '://' ) ); // req_url without protocol, so it matches http and https below
WHERE ( blog_access_type = "absolute"
AND ( '.
$DB->quote('http'.
$req_url_wo_proto).
' LIKE CONCAT( blog_siteurl, "%" )
OR '.
$DB->quote('https'.
$req_url_wo_proto).
' LIKE CONCAT( blog_siteurl, "%" ) ) )
OR ( blog_access_type = "subdom"
AND '.
$DB->quote($req_url_wo_proto).
' LIKE CONCAT( "://", blog_urlname, ".'.
$basedomain.
'/%" ) )';
// Match stubs like "http://base/url/STUB?param=1" on $baseurl
if( preg_match( "#^$baseurl([^/?]+)#", $req_url, $match ) )
$sql .= "\n OR ( blog_access_type = 'stub' AND blog_stub = ".$DB->quote($match[1])." )";
$row =
$DB->get_row( $sql, OBJECT, 0, 'Blog::get_by_url()' );
{ // Requested object does not exist
return $r; // we return by reference!
$Blog =
new Blog( $row );
* Get a blog from cache by its URL name.
* Load the object into cache, if necessary.
* @param string URL name of object to load
* @param boolean false if you want to return false on error
* @return Blog|falseA Blog object on success, false on failure (may also halt!)
// Load just the requested object:
$Debuglog->add( "Loading <strong>$this->objtype($req_urlname)</strong> into cache", 'dataobjects' );
WHERE blog_urlname = ".
$DB->quote($req_urlname);
$row =
$DB->get_row( $sql );
{ // Requested object does not exist
$Blog =
new Blog( $row );
* Load a list of public blogs into the cache
$Debuglog->add( "Loading <strong>$this->objtype(public)</strong> into cache", 'dataobjects' );
WHERE blog_in_bloglist <> 0
foreach( $DB->get_results( $sql, OBJECT, 'Load public blog list' ) as $row )
// Instantiate a custom object
return $DB->get_col( NULL, 0 );
* Load a list of blogs owner by specific ID into the cache
function load_owner_blogs( $owner_ID, $order_by = 'ID' )
$Debuglog->add( "Loading <strong>
$this->objtype(owner={
$owner_ID})</strong> into cache
", 'dataobjects' );
WHERE blog_owner_user_ID = {
$owner_ID}
foreach( $DB->get_results( $sql, OBJECT, 'Load owner blog list' ) as $row )
// Instantiate a custom object
return $DB->get_col( NULL, 0 );
* Load blogs a user has permissions for.
* @param string permission: 'member' (default), 'browse' (files)
* @return array The blog IDs
function load_user_blogs( $permname = 'blog_ismember', $permlevel = 'view', $user_ID = NULL, $order_by = 'ID', $limit = NULL )
$Debuglog->add( "Loading <strong>
$this->objtype(permission:
$permname)</strong> into cache
", 'dataobjects' );
$user_ID = $current_User->ID;
$for_User =
$current_User;
$UserCache = & get_UserCache();
$for_User = & $UserCache->get_by_ID( $user_ID );
$for_User->get_Group();// ensure Group is set
$Group =
$for_User->Group;
// First check if we have a global access perm:
if( $Group->check_perm( 'blogs', $permlevel ) )
{ // If group grants a global permission:
// Note: We only JOIN in the advanced perms if any given blog has them enabled,
// otherwise they are ignored!
$sql = "SELECT DISTINCT T_blogs.*
FROM T_blogs LEFT JOIN T_coll_user_perms ON (blog_advanced_perms <> 0
AND blog_ID = bloguser_blog_ID
AND bloguser_user_ID = {
$user_ID} )
LEFT JOIN T_coll_group_perms ON (blog_advanced_perms <> 0
AND blog_ID = bloggroup_blog_ID
AND bloggroup_group_ID = {
$Group->ID} )
if( $permname != 'blog_admin' )
{ // Only the admin perm is not convered by being the owner of the blog:
$sql .= "blog_owner_user_ID = {
$user_ID} ";
$sql .= "OR bloguser_ismember <> 0
OR bloggroup_ismember <> 0";
case 'blog_post_statuses':
$sql .= "OR bloguser_perm_poststatuses <> ''
OR bloggroup_perm_poststatuses <> ''";
$permname = 'blog_properties'; // TEMP
case 'blog_media_browse':
$short_permname = substr( $permname, 5 );
$sql .= "OR bloguser_perm_{
$short_permname} <> 0
OR bloggroup_perm_{
$short_permname} <> 0
";
debug_die( 'BlogCache::load_user_blogs() : Unsupported perm ['.$permname.']!' );
$sql .= " ORDER BY {
$this->dbprefix}{
$order_by}";
$sql .= " LIMIT {
$limit}";
foreach( $DB->get_results( $sql, OBJECT, 'Load user blog list' ) as $row )
// Instantiate a custom object
return $DB->get_col( NULL, 0 );
* Returns form option list with cache contents
* @param integer selected ID
* @param boolean provide a choice for "none" with ID 0
function get_option_list( $default = 0, $allow_none = false, $method = 'get_name' )
return parent::get_option_list( $default, $allow_none, $method );
* $Log: _blogcache.class.php,v $
* Revision 1.12 2010/02/08 17:52:09 efy-yury
* Revision 1.11 2009/09/26 12:00:42 tblue246
* Revision 1.10 2009/09/25 07:32:52 efy-cantor
* replace get_cache to get_*cache
* Revision 1.9 2009/09/14 12:43:05 efy-arrin
* Included the ClassName in load_class() call with proper UpperCase
* Revision 1.8 2009/09/05 18:17:40 tblue246
* DataObjectCache/BlogCache::get_option_list(): Back again... Allow custom value for "None" option and use 0 for BlogCache.
* Revision 1.6 2009/09/03 15:51:52 tblue246
* Doc, "refix", use "0" instead of an empty string for the "No blog" option.
* Revision 1.5 2009/03/08 23:57:42 fplanque
* Revision 1.4 2008/03/04 22:27:43 blueyed
* MFB: Fix SQL injection through requested URL (commented out?!); fix indent
* Revision 1.3 2008/01/21 09:35:26 fplanque
* Revision 1.2 2007/12/20 12:01:56 yabs
* Revision 1.1 2007/06/25 10:59:32 fplanque
* MODULES (refactored MVC)
* Revision 1.25 2007/05/31 03:02:23 fplanque
* Advanced perms now disabled by default (simpler interface).
* Enable advanced perms in blog settings -> features
* Revision 1.24 2007/05/30 01:18:56 fplanque
* blog owner gets all permissions except advanced/admin settings
* Revision 1.23 2007/05/29 01:17:20 fplanque
* advanced admin blog settings are now restricted by a special permission
* Revision 1.22 2007/05/09 01:58:57 fplanque
* Widget to display other blogs from same owner
* Revision 1.21 2007/05/09 01:00:24 fplanque
* optimized querying for blog lists
* Revision 1.20 2007/04/26 00:11:05 fplanque
* Revision 1.19 2007/03/25 15:07:38 fplanque
* Revision 1.18 2006/12/17 23:44:35 fplanque
* Revision 1.17 2006/12/07 23:13:10 fplanque
* @var needs to have only one argument: the variable type
* Otherwise, I can't code!
* Revision 1.16 2006/12/06 18:04:23 fplanque
* Revision 1.15 2006/12/05 01:35:27 blueyed
* Hooray for less complexity and the 8th param for DataObjectCache()
* Revision 1.14 2006/12/05 00:34:39 blueyed
* Implemented custom "None" option text in DataObjectCache; Added for $ItemStatusCache, $GroupCache, UserCache and BlogCache; Added custom text for Item::priority_options()
* Revision 1.13 2006/11/24 18:27:23 blueyed
* Fixed link to b2evo CVS browsing interface in file docblocks