Ansel_Gallery::isOldEnough PHP Method

isOldEnough() public method

Check user age limtation
public isOldEnough ( ) : boolean
return boolean
    public function isOldEnough()
    {
        global $session;
        if ($GLOBALS['registry']->getAuth() && $this->get('owner') == $GLOBALS['registry']->getAuth() || empty($GLOBALS['conf']['ages']['limits']) || !$this->get('age')) {
            return true;
        }
        // Do we have the user age already cheked?
        if (!$session->exists('ansel', 'user_age')) {
            $session->set('ansel', 'user_age', 0);
            $user_age = 0;
        } else {
            $user_age = $session->get('ansel', 'user_age');
            if ($user_age >= $this->get('age')) {
                return true;
            }
        }
        // Can we hook user's age?
        if ($GLOBALS['conf']['ages']['hook'] && $GLOBALS['registry']->isAuthenticated()) {
            try {
                $result = Horde::callHook('user_age', array(), 'ansel');
            } catch (Horde_Exception_HookNotSet $e) {
            }
            if (is_int($result)) {
                $session->set('ansel', 'user_age', $result);
                $user_age = $result;
            }
        }
        return $user_age >= $this->get('age');
    }

Usage Example

示例#1
0
文件: Gallery.php 项目: horde/horde
 /**
  * @param boolean $retry
  *
  * @return Ansel_Gallery
  */
 private function _getGallery($retry = false)
 {
     // Make sure we haven't already selected a gallery.
     if ($this->_gallery instanceof Ansel_Gallery) {
         return $this->_gallery;
     }
     // Get the gallery object and cache it.
     if (isset($this->_params['gallery']) && $this->_params['gallery'] != '__random') {
         $this->_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->_params['gallery']);
     } else {
         $this->_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getRandomGallery();
     }
     // Protect at least a little bit against getting an empty gallery. We
     // can't just loop until we get one with images since it's possible we
     // actually don't *have* any with images yet.
     if ($this->_params['gallery'] == '__random' && !empty($this->_gallery) && !$this->_gallery->countImages() && $this->_gallery->hasSubGalleries() && !$retry) {
         $this->_gallery = null;
         $this->_gallery = $this->_getGallery(true);
     }
     if (empty($this->_gallery)) {
         throw new Horde_Exception_NotFound(_("Gallery does not exist."));
     } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW) || !$this->_gallery->isOldEnough() || $this->_gallery->hasPasswd()) {
         throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
     }
     // Return the gallery.
     return $this->_gallery;
 }