Beispiel #1
0
 public function permissionResponse($restrictions)
 {
     if (is_array($restrictions) && !empty($restrictions)) {
         $return = array();
         foreach ($restrictions as $name => $value) {
             $invert = false;
             $status = false;
             // Might be zero, so do an expensive check
             if (!is_null($value) && !($value === "")) {
                 // Switch flag for inverted call
                 if (strpos($name, '_excluded') !== false) {
                     $invert = true;
                     $name = str_replace('_excluded', '', $name);
                 }
                 // Convert values to array or explode to array if none
                 if (!is_array($value)) {
                     if (strpos($value, ';') !== false) {
                         $check = explode(';', $value);
                     } else {
                         $check = array((int) $value);
                     }
                 } else {
                     $check = $value;
                 }
                 switch ($name) {
                     // Check for set userid
                     case 'userid':
                         if (is_object($this->cmsUser)) {
                             if ($this->cmsUser->id === $value) {
                                 $status = true;
                             }
                         }
                         break;
                         // Check for a certain GID
                     // Check for a certain GID
                     case 'fixgid':
                         if (is_object($this->cmsUser)) {
                             if ($this->hasGroup($value)) {
                                 $status = true;
                             }
                         }
                         break;
                         // Check for Minimum GID
                     // Check for Minimum GID
                     case 'mingid':
                         if (is_object($this->cmsUser)) {
                             if ($this->hasGroup($value)) {
                                 $status = true;
                             }
                         }
                         break;
                         // Check for Maximum GID
                     // Check for Maximum GID
                     case 'maxgid':
                         if (is_object($this->cmsUser)) {
                             $groups = xJACLhandler::getHigherACLGroups($value);
                             if (!$this->hasGroup($groups)) {
                                 $status = true;
                             }
                         } else {
                             // New user, so will always pass a max GID test
                             $status = true;
                         }
                         break;
                         // Check whether the user is currently in the right plan
                     // Check whether the user is currently in the right plan
                     case 'plan_present':
                         if ($this->hasSubscription) {
                             $subs = $this->getAllCurrentSubscriptionPlans();
                             foreach ($subs as $subid) {
                                 if (in_array((int) $subid, $check)) {
                                     $status = true;
                                 }
                             }
                         } else {
                             if (in_array(0, $check)) {
                                 // "None" chosen, so will always pass if new user
                                 $status = true;
                             }
                         }
                         break;
                         // Check whether the user was in the correct plan before
                     // Check whether the user was in the correct plan before
                     case 'plan_previous':
                         if ($this->hasSubscription) {
                             $previous = (int) $this->getPreviousPlan();
                             if (in_array($previous, $check) || in_array(0, $check) && is_null($previous)) {
                                 $status = true;
                             }
                         } else {
                             if (in_array(0, $check)) {
                                 // "None" chosen, so will always pass if new user
                                 $status = true;
                             }
                         }
                         break;
                         // Check whether the user has used the right plan before
                     // Check whether the user has used the right plan before
                     case 'plan_overall':
                         if ($this->hasSubscription) {
                             $subs = $this->getAllCurrentSubscriptionPlans();
                             $array = $this->meta->getUsedPlans();
                             foreach ($check as $v) {
                                 if (!empty($array[(int) $v]) || in_array($v, $subs)) {
                                     $status = true;
                                 }
                             }
                         } else {
                             if (in_array(0, $check)) {
                                 // "None" chosen, so will always pass if new user
                                 $status = true;
                             }
                         }
                         break;
                         // Check whether the user has used the plan at least a certain number of times
                     // Check whether the user has used the plan at least a certain number of times
                     case 'plan_amount_min':
                         if ($this->hasSubscription) {
                             $subs = $this->getAllCurrentSubscriptionPlans();
                             $usage = $this->meta->getUsedPlans();
                             if (!is_array($value)) {
                                 $check = array($value);
                             }
                             foreach ($check as $v) {
                                 $c = explode(',', $v);
                                 // Make sure we have an entry if the user is currently in this plan
                                 if (in_array($c[0], $subs)) {
                                     if (!isset($usage[(int) $c[0]])) {
                                         $usage[(int) $c[0]] = 1;
                                     }
                                 }
                                 if (isset($usage[(int) $c[0]])) {
                                     if ($usage[(int) $c[0]] >= (int) $c[1]) {
                                         $status = true;
                                     }
                                 }
                             }
                         }
                         break;
                         // Check whether the user has used the plan at max a certain number of times
                     // Check whether the user has used the plan at max a certain number of times
                     case 'plan_amount_max':
                         if ($this->hasSubscription) {
                             $subs = $this->getAllCurrentSubscriptionPlans();
                             $usage = $this->meta->getUsedPlans();
                             if (!is_array($value)) {
                                 $check = array($value);
                             }
                             foreach ($check as $v) {
                                 $c = explode(',', $v);
                                 // Make sure we have an entry if the user is currently in this plan
                                 if (in_array($c[0], $subs)) {
                                     if (!isset($usage[(int) $c[0]])) {
                                         $usage[(int) $c[0]] = 1;
                                     }
                                 }
                                 if (isset($usage[(int) $c[0]])) {
                                     if ($usage[(int) $c[0]] <= (int) $c[1]) {
                                         $status = true;
                                     }
                                 }
                             }
                         } else {
                             // New user will always pass max plan amount test
                             $status = true;
                         }
                         break;
                     default:
                         // If it's not there, it's super OK!
                         $status = true;
                         break;
                 }
             }
             // Swap if inverted and reestablish name
             if ($invert) {
                 $name .= '_excluded';
                 $return[$name] = !$status;
             } else {
                 $return[$name] = $status;
             }
         }
         return $return;
     } else {
         return array();
     }
 }