Source for file gacl.class.php

Documentation is available at gacl.class.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */ 
  14.  
  15. /*
  16.  * phpGACL - Generic Access Control List
  17.  * Copyright (C) 2002,2003 Mike Benoit
  18.  *
  19.  * This library is free software; you can redistribute it and/or
  20.  * modify it under the terms of the GNU Lesser General Public
  21.  * License as published by the Free Software Foundation; either
  22.  * version 2.1 of the License, or (at your option) any later version.
  23.  *
  24.  * This library is distributed in the hope that it will be useful,
  25.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  27.  * Lesser General Public License for more details.
  28.  *
  29.  * You should have received a copy of the GNU Lesser General Public
  30.  * License along with this library; if not, write to the Free Software
  31.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  32.  *
  33.  * For questions, help, comments, discussion, etc., please join the
  34.  * phpGACL mailing list. http://sourceforge.net/mail/?group_id=57103
  35.  *
  36.  * You may contact the author of phpGACL by e-mail at:
  37.  * ipso@snappymail.ca
  38.  *
  39.  * The latest version of phpGACL can be obtained from:
  40.  * http://phpgacl.sourceforge.net/
  41.  *
  42.  */
  43.  
  44. /** ensure this file is being included by a parent file */
  45. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  46.  
  47. // NOTE, this is a temporary solution until phpGACL libraries are fully implemented
  48.  
  49. /* -- Code to manually add a group to the ARO Groups
  50. SET @parent_name = 'Registered';
  51. SET @new_name = 'Support';
  52.  
  53. -- Select the parent node to insert after
  54. SELECT @ins_id := group_id, @ins_lft := lft, @ins_rgt := rgt
  55. FROM mos_core_acl_aro_groups
  56. WHERE name = @parent_name;
  57.  
  58. SELECT @new_id := MAX(group_id) + 1 FROM mos_core_acl_aro_groups;
  59.  
  60. -- Make room for the new node
  61. UPDATE mos_core_acl_aro_groups SET rgt=rgt+2 WHERE rgt>=@ins_rgt;
  62. UPDATE mos_core_acl_aro_groups SET lft=lft+2 WHERE lft>@ins_rgt;
  63.  
  64. -- Insert the new node
  65. INSERT INTO mos_core_acl_aro_groups (group_id,parent_id,name,lft,rgt)
  66. VALUES (@new_id,@ins_id,@new_name,@ins_rgt,@ins_rgt+1);
  67. */
  68.  
  69. class gacl {
  70.  
  71.     // --- Private properties ---
  72.  
  73.     /*
  74.      * Enable Debug output.
  75.      */    
  76.     var $_debug = FALSE;
  77.  
  78.     /*
  79.      * Database configuration.
  80.      */
  81.     var $db=null;
  82.     var $_db_table_prefix = '#__core_acl_';
  83.  
  84.     /*
  85.      * NOTE:     This cache must be manually cleaned each time ACL's are modified.
  86.      *         Alternatively you could wait for the cache to expire.
  87.      */
  88.     var $_caching = FALSE;
  89.     var $_force_cache_expire = TRUE;
  90.  
  91.     // --- Fudge properties
  92.     var $acl=null;
  93.     var $acl_count=0;
  94.  
  95.     /*
  96.      * Constructor
  97.      */
  98.     function gacl$db=null {
  99.         global $database;
  100.  
  101.         $this->db = $db $db $database;
  102.  
  103.         // ARO value is currently the user type,
  104.         // this changes to user id in proper implementation
  105.         // No hierarchial inheritance so have to do that the long way
  106.         $this->acl = array();
  107.         
  108.         // backend login
  109.         $this->_mos_add_acl'administration''login''users''administrator'nullnull );
  110.         $this->_mos_add_acl'administration''login''users''super administrator'nullnull );
  111.         $this->_mos_add_acl'administration''login''users''manager'nullnull );
  112.         // backend menus
  113.         //$this->_mos_add_acl( 'administration', 'config', 'users', 'administrator', null, null );
  114.         $this->_mos_add_acl'administration''config''users''super administrator'nullnull );
  115.  
  116.         // access to db admin
  117.         //$this->_mos_add_acl( 'administration', 'manage', 'users', 'super administrator', 'components', 'com_dbadmin' );
  118.  
  119.         // access to templates
  120.         //$this->_mos_add_acl( 'administration', 'manage', 'user', 'administrator', 'components', 'com_templates' )
  121.         $this->_mos_add_acl'administration''manage''users''super administrator''components''com_templates' );
  122.         $this->_mos_add_acl'administration''install''users''super administrator''templates''all' );
  123.  
  124.         // access to trash
  125.         $this->_mos_add_acl'administration''manage''users''administrator''components''com_trash' );
  126.         $this->_mos_add_acl'administration''manage''users''super administrator''components''com_trash' );
  127.         
  128.         // access to menu manager
  129.         $this->_mos_add_acl'administration''manage''users''administrator''components''com_menumanager' );
  130.         $this->_mos_add_acl'administration''manage''users''super administrator''components''com_menumanager' );
  131.         
  132.         // access to languages
  133.         $this->_mos_add_acl'administration''manage''users''super administrator''components''com_languages' );
  134.         $this->_mos_add_acl'administration''manage''users''administrator''components''com_languages' );
  135.         $this->_mos_add_acl'administration''install''users''super administrator''languages''all' );
  136.         $this->_mos_add_acl'administration''install''users''administrator''languages''all' );
  137.  
  138.         // access to modules
  139.         $this->_mos_add_acl'administration''install''users''administrator''modules''all' );
  140.         $this->_mos_add_acl'administration''install''users''super administrator''modules''all' );
  141.  
  142.         $this->_mos_add_acl'administration''edit''users''super administrator''modules''all' );
  143.         $this->_mos_add_acl'administration''edit''users''administrator''modules''all' );
  144.  
  145.         // access to modules
  146.         $this->_mos_add_acl'administration''install''users''administrator''mambots''all' );
  147.         $this->_mos_add_acl'administration''install''users''super administrator''mambots''all' );
  148.  
  149.         $this->_mos_add_acl'administration''edit''users''super administrator''mambots''all' );
  150.         $this->_mos_add_acl'administration''edit''users''administrator''mambots''all' );
  151.         // uncomment following to allow managers to edit modules
  152.         //array( 'administration', 'edit', 'users', 'manager', 'modules', 'all' );
  153.  
  154.         // access to universal installer
  155.         $this->_mos_add_acl'administration''install''users''administrator''universals''all' );
  156.         $this->_mos_add_acl'administration''install''users''super administrator''universals''all' );
  157.  
  158.         // access to components
  159.         $this->_mos_add_acl'administration''install''users''administrator''components''all' );
  160.         $this->_mos_add_acl'administration''install''users''super administrator''components''all' );
  161.  
  162.         // access to parameters
  163.         $this->_mos_add_acl'administration''install''users''administrator''parameters''all' );
  164.         $this->_mos_add_acl'administration''install''users''super administrator''parameters''all' );
  165.  
  166.         // access to includes
  167.         $this->_mos_add_acl'administration''install''users''administrator''includes''all' );
  168.         $this->_mos_add_acl'administration''install''users''super administrator''includes''all' );
  169.  
  170.         $this->_mos_add_acl'administration''edit''users''super administrator''components''all' );
  171.         $this->_mos_add_acl'administration''edit''users''administrator''components''all' );
  172.  
  173.         $this->_mos_add_acl'administration''edit''users''manager''components''com_newsflash' );
  174.         $this->_mos_add_acl'administration''edit''users''manager''components''com_frontpage' );
  175.         $this->_mos_add_acl'administration''edit''users''manager''components''com_media' );
  176.             // ** add additional components for a manager as desired, or give access to all
  177.  
  178.         // massmail
  179.         $this->_mos_add_acl'administration''manage''users''super administrator''components''com_massmail' );
  180.  
  181.         // manage users
  182.         $this->_mos_add_acl'administration''manage''users''administrator''components''com_users' );
  183.         $this->_mos_add_acl'administration''manage''users''super administrator''components''com_users' );
  184.  
  185.         // email block users property
  186.         $this->_mos_add_acl'administration''edit''users''administrator''user properties''block_user' );
  187.         $this->_mos_add_acl'administration''edit''users''super administrator''user properties''block_user' );
  188.         
  189.         // email system events
  190.         $this->_mos_add_acl'workflow''email_events''users''administrator'nullnull );
  191.         $this->_mos_add_acl'workflow''email_events''users''super administrator'nullnull );
  192.  
  193.         // actions
  194.         $this->_mos_add_acl'action''add''users''author''content''all' );
  195.         $this->_mos_add_acl'action''add''users''editor''content''all' );
  196.         $this->_mos_add_acl'action''add''users''publisher''content''all' );
  197.         $this->_mos_add_acl'action''edit''users''author''content''own' );
  198.         $this->_mos_add_acl'action''edit''users''editor''content''all' );
  199.         $this->_mos_add_acl'action''edit''users''publisher''content''all' );
  200.         $this->_mos_add_acl'action''publish''users''publisher''content''all' );
  201.  
  202.         $this->_mos_add_acl'action''add''users''manager''content''all' );
  203.         $this->_mos_add_acl'action''edit''users''manager''content''all' );
  204.         $this->_mos_add_acl'action''publish''users''manager''content''all' );
  205.  
  206.         $this->_mos_add_acl'action''add''users''administrator''content''all' );
  207.         $this->_mos_add_acl'action''edit''users''administrator''content''all' );
  208.         $this->_mos_add_acl'action''publish''users''administrator''content''all' );
  209.  
  210.         $this->_mos_add_acl'action''add''users''super administrator''content''all' );
  211.         $this->_mos_add_acl'action''edit''users''super administrator''content''all' );
  212.  
  213.         $this->_mos_add_acl'action''publish''users''super administrator''content''all' );
  214.  
  215.         $this->acl_count = count$this->acl );
  216.     }
  217.  
  218.     /*
  219.         This is a temporary function to allow 3PD's to add basic ACL checks for their
  220.         modules and components.  NOTE: this information will be compiled in the db
  221.         in future versions
  222.     */
  223.     function _mos_add_acl$aco_section_value$aco_value,
  224.         $aro_section_value$aro_value$axo_section_value=NULL$axo_value=NULL {
  225.  
  226.         $this->acl[array$aco_section_value$aco_value$aro_section_value$aro_value$axo_section_value$axo_value );
  227.         $this->acl_count = count$this->acl );
  228.     }
  229.  
  230.     /*======================================================================*\
  231.         Function:   $gacl_api->debug_text()
  232.         Purpose:    Prints debug text if debug is enabled.
  233.     \*======================================================================*/
  234.     function debug_text($text{
  235.  
  236.         if ($this->_debug{
  237.             echo "$text<br>\n";
  238.         }
  239.  
  240.         return true;
  241.     }
  242.  
  243.     /*======================================================================*\
  244.         Function:   $gacl_api->debug_db()
  245.         Purpose:    Prints database debug text if debug is enabled.
  246.     \*======================================================================*/
  247.     function debug_db($function_name ''{
  248.         if ($function_name != ''{
  249.             $function_name .= ' (): ';
  250.         }
  251.  
  252.         return $this->debug_text ($function_name .'database error: '$this->db->getErrorMsg(.' ('$this->db->getErrorNum(.')');
  253.     }
  254.  
  255.     /*======================================================================*\
  256.         Function:   acl_check()
  257.         Purpose:    Function that wraps the actual acl_query() function.
  258.                         It is simply here to return TRUE/FALSE accordingly.
  259.     \*======================================================================*/
  260.     function acl_check$aco_section_value$aco_value,
  261.         $aro_section_value$aro_value$axo_section_value=NULL$axo_value=NULL {
  262.         $acl_result 0;
  263.         for ($i=0$i $this->acl_count$i++{
  264.             if (strcasecmp$aco_section_value$this->acl[$i][0== 0{
  265.                 if (strcasecmp$aco_value$this->acl[$i][1== 0{
  266.                     if (strcasecmp$aro_section_value$this->acl[$i][2== 0{
  267.                         if (strcasecmp$aro_value$this->acl[$i][3== 0{
  268.                             if (strcasecmp$axo_section_value$this->acl[$i][4== 0{
  269.                                 if (strcasecmp$axo_value$this->acl[$i][5== 0{
  270.                                     $acl_result 1;
  271.                                     break;
  272.                                 }
  273.                             }
  274.                         }
  275.                     }
  276.                 }
  277.             }
  278.         }
  279.         return $acl_result;
  280.     }
  281.  
  282. }
  283.  
  284. ?>

Documentation generated on Mon, 05 May 2008 16:19:48 +0400 by phpDocumentor 1.4.0