Copyright 2011-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Michael J. Rubinsky (mrubinsk@horde.org)
Inheritance: extends Ansel_View_Base
Ejemplo n.º 1
0
 /**
  * Const'r
  *
  * @see Ansel_View_Base::__construct
  */
 public function __construct(array $params = array())
 {
     parent::__construct($params);
     if (!empty($params['gallery_slug'])) {
         $this->gallery = $this->_getGallery(null, $params['gallery_slug']);
     } elseif (!empty($params['gallery_id'])) {
         $this->gallery = $this->_getGallery($params['gallery_id']);
     } else {
         $this->gallery = $this->_getGallery();
     }
     // Check user age
     if (!$this->gallery->isOldEnough()) {
         if (!empty($params['api'])) {
             throw new Ansel_Exception('Locked galleries are not viewable via the api.');
         }
         $date = Ansel::getDateParameter(array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0, 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0, 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0));
         $galleryurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => empty($params['slug']) ? '' : $params['slug'], 'page' => empty($params['page']) ? 0 : $params['page'], 'view' => 'Gallery'), $date), true);
         $params = array('gallery' => $this->gallery->id, 'url' => $galleryurl);
         Horde::url('disclamer.php')->add($params)->setRaw(true)->redirect();
         exit;
     }
     if ($this->gallery->hasPasswd()) {
         if (!empty($params['api'])) {
             throw new Ansel_Exception(_("Locked galleries are not viewable via the api."));
         }
         $date = Ansel::getDateParameter(array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0, 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0, 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0));
         $galleryurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => empty($params['slug']) ? '' : $params['slug'], 'page' => empty($params['page']) ? 0 : $params['page'], 'view' => 'Gallery'), $date), true);
         $params = array('gallery' => $this->gallery->id, 'url' => $galleryurl);
         Horde::url('protect.php')->add($params)->setRaw(true)->redirect();
         exit;
     }
     if (!$this->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
         throw new Horde_Exception_PermissionDenied();
     }
     // Since this is a gallery view, the resource is the gallery.
     $this->resource = $this->gallery;
     // Do we have an explicit style set? If not, use the gallery's
     if (!empty($this->_params['style'])) {
         $style = Ansel::getStyleDefinition($this->_params['style']);
     } else {
         $style = $this->gallery->getStyle();
     }
     if (!empty($this->_params['gallery_view'])) {
         $renderer = $this->_params['gallery_view'];
     } else {
         $renderer = !empty($style->gallery_view) ? $style->gallery_view : 'Gallery';
     }
     // Load the helper
     $classname = 'Ansel_View_GalleryRenderer_' . basename($renderer);
     $this->_renderer = new $classname($this);
     $this->_renderer->init();
 }
Ejemplo n.º 2
0
Archivo: List.php Proyecto: horde/horde
 /**
  * Const'r
  *
  * @param array $params  Any parameters that the view might need.
  * <pre>
  *  In addition to the params taken by Ansel_View_Gallery, this view
  *  can also take:
  *
  *  groupby      -  Group the results (owner)
  *
  *  owner        -  The owner to group by
  *
  *  tags         -  Limit to galleries matching tags
  *
  *  gallery_ids  -  No fitering, just show these galleries
  *
  *  pager_url    -  The url for the pager to use see Ansel_Gallery for
  *                  more information on the url parameters.
  */
 public function __construct(array $params = array())
 {
     global $prefs, $notification, $registry;
     parent::__construct($params);
     $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
     // View
     $this->_view = $GLOBALS['injector']->createInstance('Horde_View');
     $this->_view->addTemplatePath(ANSEL_TEMPLATES . '/view');
     $this->_view->sortBy = !empty($this->_params['sort']) ? $this->_params['sort'] : 'name';
     $this->_view->sortDir = isset($this->_params['sort_dir']) ? $this->_params['sort_dir'] : 0;
     // Check for grouping.
     if (empty($this->_params['groupby'])) {
         $this->_view->groupby = Horde_Util::getFormData('groupby', $prefs->getValue('groupby'));
     } else {
         $this->_view->groupby = $this->_params['groupby'];
     }
     $this->_view->gPerPage = $prefs->getValue('tilesperpage');
     // Listing a single user?
     if (empty($this->_params['owner'])) {
         $this->_owner = Horde_Util::getFormData('owner');
         $this->_owner = empty($this->_owner) ? null : $this->_owner;
     } else {
         $this->_owner = $this->_params['owner'];
     }
     // Special?
     $this->_special = Horde_Util::getFormData('special');
     if (!$this->_owner && !$this->_special && $this->_view->groupby != 'none') {
         Ansel::getUrlFor('group', array('groupby' => $this->_view->groupby))->redirect();
         exit;
     }
     // If we aren't supplied with a page number, default to page 0.
     if (isset($this->_params['page'])) {
         $this->_page = $this->_params['page'];
     } else {
         $this->_page = Horde_Util::getFormData('page', 0);
     }
     // If we are calling from the api, we can just pass a list of ids
     if (!empty($this->_params['api']) && is_array($this->_params['gallery_ids'])) {
         $this->_view->start = $this->_page * $this->_view->gPerPage;
         $this->_view->numGalleries = count($this->_params['gallery_ids']);
         if ($this->_view->numGalleries > $this->_view->start) {
             $getThese = array_slice($this->_params['gallery_ids'], $this->_view->start, $this->_view->gPerPage);
             $this->_view->galleryList = $ansel_storage->getGalleries($getThese);
         } else {
             $this->_view->galleryList = array();
         }
     } else {
         // Set list filter/title
         $filter = array();
         if (!is_null($this->_owner)) {
             $filter['owner'] = $this->_owner;
         }
         $this->_view->numGalleries = $ansel_storage->countGalleries($registry->getAuth(), array('attributes' => $filter, 'all_levels' => false, 'tags' => !empty($params['tags']) ? $params['tags'] : null));
         if ($this->_view->numGalleries == 0 && empty($this->_params['api'])) {
             if ($this->_owner && $this->_owner == $registry->getAuth()) {
                 $notification->push(_("You have no photo galleries, add one!"), 'horde.message');
                 Horde::url('gallery.php')->add('actionID', 'add')->redirect();
                 exit;
             }
             $notification->push(_("There are no photo galleries available."), 'horde.message');
             $this->_view->galleryList = array();
         } else {
             $this->_view->galleryList = $ansel_storage->listGalleries(array('attributes' => $filter, 'all_levels' => false, 'from' => $this->_page * $this->_view->gPerPage, 'count' => $this->_view->gPerPage, 'sort_by' => $this->_view->sortBy, 'direction' => $this->_view->sortDir, 'tags' => !empty($params['tags']) ? $params['tags'] : null));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Const'r
  *
  * @param array  Parameters for the view.
  * @throws Ansel_Exception
  */
 public function __construct(array $params = array())
 {
     parent::__construct($params);
     // Get the Ansel_Image
     $this->resource = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($params['image_id']);
     // Get the Ansel_Gallery
     $this->gallery = $this->_getGallery();
     // Check user age
     if (!$this->gallery->isOldEnough()) {
         if (!empty($params['api'])) {
             throw new Ansel_Exception('Locked galleries are not viewable via the api.');
         }
         $date = Ansel::getDateParameter(array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0, 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0, 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0));
         $url = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => empty($params['slug']) ? '' : $params['slug'], 'page' => empty($params['page']) ? 0 : $params['page'], 'view' => 'Image', 'image' => $this->resource->id), $date), true);
         $params = array('gallery' => $this->gallery->id, 'url' => $url);
         Horde::url('disclamer.php')->add($params)->setRaw(true)->redirect();
         exit;
     }
     // Check password
     if ($this->gallery->hasPasswd()) {
         if (!empty($params['api'])) {
             throw new Ansel_Exception(_("Locked galleries are not viewable via the api."));
         }
         $date = Ansel::getDateParameter(array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0, 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0, 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0));
         $url = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => empty($params['slug']) ? '' : $params['slug'], 'page' => empty($params['page']) ? 0 : $params['page'], 'view' => 'Image', 'image' => $this->resource->id), $date), true);
         $params = array('gallery' => $this->gallery->id, 'url' => $url);
         Horde::url('protect.php')->add($params)->setRaw(true)->redirect();
         exit;
     }
     // Any script files we may need if not calling via the api
     if (empty($this->_params['api'])) {
         $GLOBALS['page_output']->addScriptFile('scriptaculous/effects.js', 'horde');
         $GLOBALS['page_output']->addScriptFile('stripe.js', 'horde');
     }
     $this->_includeViewSpecificScripts();
 }