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

Source for file permissions.inc.php

Documentation is available at permissions.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2008-10-31 15:33:34 +0000 (Fr, 31 Okt 2008) $
  5.      * @package            permissions
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_permissions extends ipbwi {
  12.         private $ipbwi            null;
  13.         /**
  14.          * @desc            Loads and checks different vars when class is initiating
  15.          * @author            Matthias Reuter
  16.          * @since            2.0
  17.          * @ignore
  18.          */
  19.         public function __construct($ipbwi){
  20.             // loads common classes
  21.             $this->ipbwi $ipbwi;
  22.         }
  23.         /**
  24.          * @desc            Finds out if a user has permission to do something...
  25.          * @param    string    $perm the permission to be worked out
  26.          * @param    int        $user the user to have permissions checked. If left blank, currently logged in user used.
  27.          * @return    bool    true if user has perm, otherwise false
  28.          * @author            Matthias Reuter
  29.          * @sample
  30.          *  <code>
  31.          *  $ipbwi->permissions->has('g_access_cp',55);
  32.          *  </code>
  33.          * @since            2.0
  34.          */
  35.         public function has($perm,$user=false){
  36.             if(substr($perm,0,2!= "g_"){
  37.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badPermID'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  38.                 return false;
  39.             }
  40.             $perm preg_replace('#[^a-z_]#','',$perm);
  41.             $info $this->ipbwi->member->info($user);
  42.             if(!is_array($info)){
  43.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badMemID'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  44.                 return false;
  45.             }
  46.             if($info[$perm]){
  47.                 return true;
  48.             // Take a look at secondary groups
  49.             }elseif(isset($info['mgroup_others'])){
  50.                 $info['mgroup_others'substr($info['mgroup_others'],1,strlen($info['mgroup_others'])-2);
  51.                 if($info['mgroup_others'!= ''){
  52.                     $this->ipbwi->ips_wrapper->DB->query('SELECT '.$perm.' FROM '.$this->ipbwi->board['sql_tbl_prefix'].'groups WHERE g_id IN('.$info['mgroup_others'].')');
  53.                     while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  54.                         if($row[$perm]){
  55.                             return true;
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.             return false;
  61.         }
  62.         /**
  63.          * @desc            Attempts to sort out the weird permissions array.
  64.          * @param    string    $permArray the permission array to be sorted
  65.          * @return    array    sorted permissions
  66.          * @author            Matthias Reuter
  67.          * @sample
  68.          *  <code>
  69.          *  $ipbwi->permissions->sort(array('show' => '*','read' => '*','start' => '*','reply' => '*','upload' => '*','download' => '*'));
  70.          *  </code>
  71.          * @since            2.0
  72.          */
  73.         public function sort($permArray){
  74.             $perms unserialize(stripslashes($permArray));
  75.             $fr['read_perms']   $perms['read_perms'];
  76.             $fr['reply_perms']  $perms['reply_perms'];
  77.             $fr['start_perms']  $perms['start_perms'];
  78.             $fr['upload_perms'$perms['upload_perms'];
  79.             $fr['show_perms']   $perms['show_perms'];
  80.             return $fr;
  81.         }
  82.         /**
  83.          * @desc            Returns the best perms a user has for something...
  84.          * @param    string    $perm the permission to be worked out
  85.          * @param    int        $user the user to have permissions checked. if left blank, currently logged in user used.
  86.          * @param    bool    $zero if true, zero is best
  87.          * @return    array    best permissions
  88.          * @author            Matthias Reuter
  89.          * @sample
  90.          *  <code>
  91.          *  $ipbwi->permissions->best(array('g_max_messages');
  92.          *  </code>
  93.          * @since            2.0
  94.          */
  95.         public function best($perm,$user=false,$zero=true){
  96.             if(substr($perm,0,2!= 'g_'){
  97.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badPermID'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  98.                 return false;
  99.             }
  100.             $perm preg_replace('#[^a-z_]#','',$perm);
  101.             $info $this->ipbwi->member->info($user);
  102.             if(!is_array($info)){
  103.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badMemID'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  104.                 return false;
  105.             }
  106.             $init $info[$perm];
  107.             if(intval($init== && $zero){
  108.                 return 0;
  109.             }
  110.             // Take a look at secondary groups
  111.             $info['mgroup_others'substr($info['mgroup_others'],1,strlen($info['mgroup_others'])-2);
  112.             if($info['mgroup_others'!= ''){
  113.                 $this->ipbwi->ips_wrapper->DB->query('SELECT '.$perm.' FROM '.$this->ipbwi->board['sql_tbl_prefix'].'groups WHERE g_id IN('.$info['mgroup_others'].')');
  114.                 while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  115.                     if($row[$perm$init){
  116.                         $init $row[$perm];
  117.                     }
  118.                     if(intval($init== && $zero){
  119.                         return 0;
  120.                     }
  121.                 }
  122.             }
  123.             return $init;
  124.         }
  125.     }
  126. ?>

Documentation generated on Sat, 23 Oct 2010 23:36:00 +0200 by phpDocumentor 1.4.3