hasPermission() 공개 메소드

Checks to see if a user has a given permission.
public hasPermission ( string $userid, integer $permission, string $creator = null ) : boolean
$userid string The userid of the user.
$permission integer A Horde_Perms::* constant to test for.
$creator string The creator of the event.
리턴 boolean Whether or not $userid has $permission.
예제 #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;
 }
예제 #2
0
 /**
  * @return Ansel_Gallery
  */
 private function _getGallery()
 {
     /* 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();
     }
     if (empty($this->_gallery)) {
         throw new Horde_Exception_NotFound(_("Gallery not found."));
     } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
         throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
     }
     /* Return a reference to the gallery. */
     return $this->_gallery;
 }
예제 #3
0
 /**
  * Copy image and related data to specified gallery.
  *
  * @param array $images           An array of image ids.
  * @param Ansel_Gallery $gallery  The gallery to copy images to.
  *
  * @return integer The number of images copied
  * @throws Ansel_Exception
  */
 public function copyImagesTo(array $images, Ansel_Gallery $gallery)
 {
     if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
         throw new Horde_Exception_PermissionDenied(_("Access denied copying photos to this gallery."));
     }
     $imgCnt = 0;
     foreach ($images as $imageId) {
         $img = $this->getImage($imageId);
         // Note that we don't pass the tags when adding the image..see below
         $newId = $gallery->addImage(array('image_caption' => $img->caption, 'data' => $img->raw(), 'image_filename' => $img->filename, 'image_type' => $img->getType(), 'image_uploaded_date' => $img->uploaded));
         /* Copy any tags */
         $tags = $img->getTags();
         $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($newId, $tags, $gallery->get('owner'), 'image');
         // Check that new image_id doesn't have existing attributes,
         // throw exception if it does.
         $newAttributes = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImageAttributes($newId);
         if (count($newAttributes)) {
             throw new Ansel_Exception(_("Image already has existing attributes."));
         }
         $exif = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImageAttributes($imageId);
         if (is_array($exif) && count($exif) > 0) {
             foreach ($exif as $name => $value) {
                 $GLOBALS['injector']->getInstance('Ansel_Storage')->saveImageAttribute($newId, $name, $value);
             }
         }
         ++$imgCnt;
     }
     return $imgCnt;
 }
예제 #4
0
파일: Date.php 프로젝트: horde/horde
 /**
  * Moves images from one gallery to another. Since we're viewing by date
  * some images might belong to a subgallery so we need to take care to
  * udate the appropriate gallery data.
  *
  * @param array $images           An array of image_ids to move.
  * @param Ansel_Gallery $gallery  The Ansel_Gallery to move them to.
  *
  * @return boolean
  */
 public function moveImagesTo($images, $gallery)
 {
     if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
         throw new Horde_Exception_PermissionDenied(_("Access denied moving photos to this gallery."));
     } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
         throw new Horde_Exception_PermissionDenied(_("Access denied removing photos from this gallery."));
     }
     /* Sanitize image ids, and see if we're removing our key image. */
     $ids = array();
     foreach ($images as $imageId) {
         $ids[] = (int) $imageId;
         if ($imageId == $this->_gallery->get('default')) {
             $this->_gallery->set('default', null, true);
         }
     }
     /* If we have subgalleries, we need to go the more expensive route. Note
      * we can't use $gallery->hasSubgalleries() since that would be
      * overridden here since we are in date mode and thus would return false
      */
     if ($this->_gallery->get('has_subgalleries')) {
         $gallery_ids = array();
         $images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImages(array('ids' => $ids));
         foreach ($images as $image) {
             if (empty($gallery_ids[$image->gallery])) {
                 $gallery_ids[$image->gallery] = 1;
             } else {
                 $gallery_ids[$image->gallery]++;
             }
         }
     }
     /* Bulk update the images to their new gallery_id */
     $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id);
     /* Update the gallery counts for each affected gallery */
     if ($this->_gallery->get('has_subgalleries')) {
         foreach ($gallery_ids as $id => $count) {
             $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($id)->updateImageCount($count, false);
         }
     } else {
         $this->_gallery->updateImageCount(count($ids), false);
     }
     $gallery->updateImageCount(count($ids), true);
     /* Expire the cache since we have no reason to save() the gallery */
     if ($GLOBALS['conf']['ansel_cache']['usecache']) {
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
     }
     return count($ids);
 }
예제 #5
0
파일: Normal.php 프로젝트: jubinpatel/horde
 /**
  * Move images from this gallery to another.
  *
  * @param array $images           The image ids to move.
  * @param Ansel_Gallery $gallery  The gallery to move images into.
  *
  * @return boolean
  * @throws Ansel_Exception
  * @throws Horde_Exception_PermissionDenied
  */
 public function moveImagesTo($images, $gallery)
 {
     if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
         throw new Horde_Exception_PermissionDenied("Access denied moving photos to this gallery.");
     } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
         throw new Horde_Exception_PermissionDenied(_("Access denied removing photos from this gallery."));
     }
     /* Sanitize image ids, and see if we're removing our key image. */
     $ids = array();
     foreach ($images as $imageId) {
         $ids[] = (int) $imageId;
         if ($imageId == $this->_gallery->get('default')) {
             $this->_gallery->set('default', null, true);
         }
     }
     $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id);
     $this->_gallery->updateImageCount(count($ids), false);
     $gallery->updateImageCount(count($ids), true);
     /* Expire the cache since we have no reason to save() the gallery */
     if ($GLOBALS['conf']['ansel_cache']['usecache']) {
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
     }
     return count($ids);
 }
예제 #6
0
파일: Gallery.php 프로젝트: horde/horde
 /**
  * Outputs the html for a gallery tile.
  *
  * @param Ansel_Gallery $gallery  The Ansel_Gallery we are displaying.
  * @param Ansel_Style $style      A style object.
  * @param boolean $mini           Force the use of a mini thumbail?
  * @param array $params           An array containing additional parameters.
  *                                Currently, gallery_view_url and
  *                                image_view_url are used to override the
  *                                respective urls. %g and %i are replaced
  *                                with image id and gallery id, respectively
  *
  *
  * @return  Outputs the HTML for the tile.
  */
 public static function getTile(Ansel_Gallery $gallery, Ansel_Style $style = null, $mini = false, array $params = array())
 {
     global $prefs, $registry, $injector;
     // Create view
     $view = $injector->createInstance('Horde_View');
     $view->addTemplatePath(ANSEL_TEMPLATES . '/tile');
     $view->gallery = $gallery;
     $view_type = Horde_Util::getFormData('view', 'Gallery');
     $haveSearch = $view_type == 'Results' ? 1 : 0;
     if ($view_type == 'Results' || $view_type == 'List' || basename($_SERVER['PHP_SELF']) == 'index.php' && $prefs->getValue('defaultview') == 'galleries') {
         $showOwner = true;
     } else {
         $showOwner = false;
     }
     // Use the galleries style if not explicitly passed.
     if (is_null($style)) {
         $style = $gallery->getStyle();
     }
     // If the gallery has subgalleries, and no images, use one of the
     // subgalleries' stack image. hasSubGalleries already takes
     // permissions into account.
     if ($gallery->hasPermission($registry->getAuth(), Horde_Perms::READ) && !$gallery->countImages() && $gallery->hasSubGalleries()) {
         try {
             $galleries = $injector->getInstance('Ansel_Storage')->listGalleries(array('parent' => $gallery->id, 'all_levels' => false, 'perm' => Horde_Perms::READ));
             foreach ($galleries as $sgallery) {
                 if ($default_img = $sgallery->getKeyImage($style)) {
                     $view->gallery_image = Ansel::getImageUrl($default_img, $mini ? 'mini' : 'thumb', true, $style);
                 }
             }
         } catch (Ansel_Exception $e) {
         }
     } elseif ($gallery->hasPermission($registry->getAuth(), Horde_Perms::READ) && $gallery->countImages()) {
         $thumbstyle = $mini ? 'mini' : 'thumb';
         if ($gallery->hasPasswd()) {
             $view->gallery_image = Horde_Themes::img('gallery-locked.png');
         } else {
             $view->gallery_image = Ansel::getImageUrl($gallery->getKeyImage($style), $thumbstyle, true, $style);
         }
     }
     // If no image at this point, we can't get one.
     if (empty($view->gallery_image)) {
         $view->gallery_image = Horde_Themes::img('thumb-error.png');
     }
     // Check for being called via the api and generate correct view links
     if (!isset($params['gallery_view_url'])) {
         $view->view_link = Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'view' => 'Gallery', 'havesearch' => $haveSearch, 'slug' => $gallery->get('slug')));
     } else {
         $view->view_link = new Horde_Url(str_replace(array('%g', '%s'), array($gallery->id, $gallery->get('slug')), urldecode($params['gallery_view_url'])));
     }
     if ($gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT) && !$mini) {
         $view->properties_link = Horde::url('gallery.php', true)->add(array('gallery' => $gallery->id, 'actionID' => 'modify', 'havesearch' => $haveSearch, 'url' => Horde::selfUrl(true, false, true)));
     }
     if ($showOwner && !$mini && $registry->getAuth() != $gallery->get('owner')) {
         $view->owner_link = Ansel::getUrlFor('view', array('view' => 'List', 'owner' => $gallery->get('owner'), 'groupby' => 'owner'), true);
         $view->owner_string = $gallery->getIdentity()->getValue('fullname');
         if (empty($view->owner_string)) {
             $view->owner_string = $gallery->get('owner');
         }
     }
     $view->background_color = $style->background;
     $view->gallery_count = $gallery->countImages(true);
     $view->date_format = $prefs->getValue('date_format');
     return $view->render('gallery' . ($mini ? 'mini' : ''));
 }