protector
[ class tree: protector ] [ index: protector ] [ all elements ]

Source for file LibertyProtector.php

Documentation is available at LibertyProtector.php

  1. <?php
  2. /**
  3.  * @version $Header: /cvsroot/bitweaver/_bit_protector/LibertyProtector.php,v 1.9 2006/11/09 19:47:49 squareing Exp $
  4.  *
  5.  *  Copyright (c) 2004 bitweaver.org
  6.  *  Copyright (c) 2003 tikwiki.org
  7.  *  Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  8.  *  All Rights Reserved. See copyright.txt for details and a complete list of authors.
  9.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
  10.  *
  11.  *  $Id: LibertyProtector.php,v 1.9 2006/11/09 19:47:49 squareing Exp $
  12.  * @package protector
  13.  */
  14.  
  15. /**
  16.  * required setup
  17.  */
  18. require_onceLIBERTY_PKG_PATH.'LibertyBase.php' );
  19.  
  20. /**
  21.  * Protector class to illustrate best practices when creating a new bitweaver package that
  22.  * builds on core bitweaver functionality, such as the Liberty CMS engine
  23.  *
  24.  * @package protector
  25.  * @subpackage LibertyProtector
  26.  *
  27.  *  created 2004/8/15
  28.  *
  29.  * @author spider <spider@steelsun.com>
  30.  *
  31.  * @version $Revision: 1.9 $ $Date: 2006/11/09 19:47:49 $ $Author: squareing $
  32.  */
  33. class LibertyProtector extends LibertyBase {
  34.     /**
  35.     * During initialisation, be sure to call our base constructors
  36.     **/
  37.  
  38.     function LibertyProtector$pContentId=NULL {
  39.         $this->mContentId $pContentId;
  40.         LibertyBase::LibertyBase();
  41.     }
  42.  
  43.     /**
  44.     * Update the liberty_content_group_map table with corrected group_id(s)
  45.     * In -1 for anonymouse is not stored, switching content to anonymouse will clear array
  46.     **/
  47.  
  48.     function storeProtection&$pParamHash {
  49.         global $gBitSystem;
  50.         if@BitBase::verifyId$pParamHash['protector']['group_id') ) {
  51.             $this->mDb->query"DELETE FROM `".BIT_DB_PREFIX."liberty_content_group_map` WHERE `content_id`=?"array$pParamHash['content_id') );
  52.             if$gBitSystem->isFeatureActive'protector_single_group' ) ) {
  53.                 if$pParamHash['protector']['group_id'!= -)
  54.                     $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') );
  55.             else {
  56.                 foreach$pParamHash['protector']['group_id'AS $groupId {
  57.                     if$groupId != -)
  58.                     $this->mDb->query"INSERT INTO `".BIT_DB_PREFIX."liberty_content_group_map` ( `group_id`, `content_id` ) VALUES ( ?, ? )"array$groupId$pParamHash['content_id') );
  59.                 }
  60.             }
  61.         }
  62.         returncount$this->mErrors == );
  63.     }
  64.  
  65.     /**
  66.     * Return liberty_content_group_map for selected content_id
  67.     * Ret -1 for anonymouse if alternatives are not stored
  68.     **/
  69.  
  70.     function getProtectionList$ContentId=NULL {
  71.         global $gBitSystem;
  72.         $ret array'-1' <= $ContentId );
  73.         ifisset$ContentId ) ) {
  74.             $ret $this->mDb->GetAssoc"SELECT `group_id`, `content_id` FROM `".BIT_DB_PREFIX."liberty_content_group_map` WHERE `content_id`=?"array$ContentId ) );
  75.         }
  76.         return $ret;
  77.     }
  78. }
  79.  
  80. function protector_content_list({
  81.     global $gBitUser;
  82.     $groups array_keys($gBitUser->mGroups);
  83.     $ret array(
  84.         '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` ) ",
  85.         'where_sql' => " AND (lcgm.`content_id` IS NULL OR lcgm.`group_id` IN("implode(','array_fill(0count($groups)'?')) ." ) OR ugm.`user_id`=?) ",
  86.         'bind_vars' => array_merge$groupsarray$gBitUser->mUserId ) ),
  87.     );
  88. //    $ret['bind_vars'] = array_merge( $groups, array( $gBitUser->mUserId ) );
  89.     return $ret;
  90. }
  91.  
  92. function protector_content_load({
  93.     global $gBitUser;
  94.     $groups array_keys($gBitUser->mGroups);
  95.     $ret array(
  96.         '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` ) ",
  97.         'where_sql' => " AND (lcgm.`content_id` IS NULL OR lcgm.`group_id` IN("implode(','array_fill(0count($groups)'?')) ." ) OR ugm.`user_id`=?) ",
  98.         'bind_vars' => array$gBitUser->mUserId ),
  99.     );
  100.     $ret['bind_vars'array_merge$groups$ret['bind_vars');
  101.     return $ret;
  102. }
  103.  
  104. function protector_content_store&$pObject&$pParamHash {
  105.     global $gBitSystem$gProtector;
  106.     $errors NULL;
  107.     // If a content access system is active, let's call it
  108.     if$gBitSystem->isPackageActive'protector' ) ) {
  109.         if!$gProtector->storeProtection$pParamHash ) ) {
  110.             $errors['protector'$gProtector->mErrors['security'];
  111.         }
  112.     }
  113.     return$errors );
  114. }
  115.  
  116. function protector_content_display&$pContent&$pParamHash {
  117.     global $gBitSystem$gBitSmarty;
  118.     $pContent->hasUserPermission$pParamHash['perm_name');
  119. }
  120.  
  121. function protector_content_verify_access&$pContent&$pHash {
  122.     global $gBitUser$gBitSystem;
  123.     $error NULL;
  124.     return $error;
  125. }
  126.  
  127. function protector_content_edit&$pContent {
  128.     global $gProtector$gBitUser$gBitSmarty;
  129.     $groups $gBitUser->getGroups();
  130.     $groups[-1]['group_name'"~~ System Default ~~";
  131.     ksort$groups );
  132.     foreacharray_keys$groups as $groupId {
  133.         if$groupId != -{
  134.             $protectorGroupsId[$groupId$groups[$groupId]['group_name'];
  135.         else {
  136.             $protectorGroupsId[$groupId"~~ System Default ~~";
  137.         }
  138.     }
  139.     $serviceHash['protector']['group'$gProtector->getProtectionList$pContent->mContentId );
  140.     $prot array_keys$serviceHash['protector']['group');
  141.     $serviceHash['protector']['group_id'empty$prot[0? -$prot[0);
  142.     $gBitSmarty->assign_by_ref'serviceHash'$serviceHash );
  143.     $gBitSmarty->assign_by_ref'protectorGroupsId'$protectorGroupsId );
  144.     $gBitSmarty->assign_by_ref'protectorGroups'$groups );
  145. }
  146.  
  147. global $gProtector;
  148. $gProtector new LibertyProtector();
  149.  
  150. ?>

Documentation generated on Thu, 15 Feb 2007 20:42:27 +0000 by phpDocumentor 1.3.0