Source for file LibertyProtector.php
Documentation is available at LibertyProtector.php
* @version $Header: /cvsroot/bitweaver/_bit_protector/LibertyProtector.php,v 1.9 2006/11/09 19:47:49 squareing Exp $
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
* Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
* $Id: LibertyProtector.php,v 1.9 2006/11/09 19:47:49 squareing Exp $
require_once( LIBERTY_PKG_PATH. 'LibertyBase.php' );
* Protector class to illustrate best practices when creating a new bitweaver package that
* builds on core bitweaver functionality, such as the Liberty CMS engine
* @subpackage LibertyProtector
* @author spider <spider@steelsun.com>
* @version $Revision: 1.9 $ $Date: 2006/11/09 19:47:49 $ $Author: squareing $
* During initialisation, be sure to call our base constructors
$this->mContentId = $pContentId;
* Update the liberty_content_group_map table with corrected group_id(s)
* In -1 for anonymouse is not stored, switching content to anonymouse will clear array
$this->mDb->query( "DELETE FROM `". BIT_DB_PREFIX. "liberty_content_group_map` WHERE `content_id`=?", array( $pParamHash['content_id'] ) );
if( $gBitSystem->isFeatureActive( 'protector_single_group' ) ) {
if( $pParamHash['protector']['group_id'] != - 1 )
$this->mDb->query( "INSERT INTO `". BIT_DB_PREFIX. "liberty_content_group_map` ( `group_id`, `content_id` ) VALUES ( ?, ? )", array( $pParamHash['protector']['group_id'], $pParamHash['content_id'] ) );
foreach( $pParamHash['protector']['group_id'] AS $groupId ) {
$this->mDb->query( "INSERT INTO `". BIT_DB_PREFIX. "liberty_content_group_map` ( `group_id`, `content_id` ) VALUES ( ?, ? )", array( $groupId, $pParamHash['content_id'] ) );
* Return liberty_content_group_map for selected content_id
* Ret -1 for anonymouse if alternatives are not stored
$ret = array( '-1' <= $ContentId );
if( isset ( $ContentId ) ) {
$ret = $this->mDb->GetAssoc( "SELECT `group_id`, `content_id` FROM `". BIT_DB_PREFIX. "liberty_content_group_map` WHERE `content_id`=?", array( $ContentId ) );
'join_sql' => " LEFT JOIN `". BIT_DB_PREFIX. "liberty_content_group_map` lcgm ON ( lc.`content_id`=lcgm.`content_id` ) LEFT OUTER JOIN `". BIT_DB_PREFIX. "users_groups_map` ugm ON ( ugm.`user_id`=". $gBitUser->mUserId. " ) AND ( ugm.`group_id`=lcgm.`group_id` ) ",
'where_sql' => " AND (lcgm.`content_id` IS NULL OR lcgm.`group_id` IN(". implode(',', array_fill(0, count($groups), '?')) . " ) OR ugm.`user_id`=?) ",
'bind_vars' => array_merge( $groups, array( $gBitUser->mUserId ) ),
// $ret['bind_vars'] = array_merge( $groups, array( $gBitUser->mUserId ) );
'join_sql' => " LEFT JOIN `". BIT_DB_PREFIX. "liberty_content_group_map` lcgm ON ( lc.`content_id`=lcgm.`content_id` ) LEFT OUTER JOIN `". BIT_DB_PREFIX. "users_groups_map` ugm ON ( ugm.`group_id`=lcgm.`group_id` ) ",
'where_sql' => " AND (lcgm.`content_id` IS NULL OR lcgm.`group_id` IN(". implode(',', array_fill(0, count($groups), '?')) . " ) OR ugm.`user_id`=?) ",
'bind_vars' => array( $gBitUser->mUserId ),
$ret['bind_vars'] = array_merge( $groups, $ret['bind_vars'] );
global $gBitSystem, $gProtector;
// If a content access system is active, let's call it
if( $gBitSystem->isPackageActive( 'protector' ) ) {
$errors['protector'] = $gProtector->mErrors['security'];
global $gBitSystem, $gBitSmarty;
$pContent->hasUserPermission( $pParamHash['perm_name'] );
global $gBitUser, $gBitSystem;
global $gProtector, $gBitUser, $gBitSmarty;
$groups = $gBitUser->getGroups();
$groups[- 1]['group_name'] = "~~ System Default ~~";
$protectorGroupsId[$groupId] = $groups[$groupId]['group_name'];
$protectorGroupsId[$groupId] = "~~ System Default ~~";
$serviceHash['protector']['group'] = $gProtector->getProtectionList( $pContent->mContentId );
$prot = array_keys( $serviceHash['protector']['group'] );
$serviceHash['protector']['group_id'] = ( empty( $prot[0] ) ? - 1 : $prot[0] );
$gBitSmarty->assign_by_ref( 'serviceHash', $serviceHash );
$gBitSmarty->assign_by_ref( 'protectorGroupsId', $protectorGroupsId );
$gBitSmarty->assign_by_ref( 'protectorGroups', $groups );
|