Overview

Packages

  • Ansel
  • None

Classes

  • Ansel_Application
  • Ansel_Block_Cloud
  • Ansel_Block_Gallery
  • Ansel_Block_MyGalleries
  • Ansel_Block_RandomPhoto
  • Ansel_Block_RecentComments
  • Ansel_Block_RecentFaces
  • Ansel_Block_Recentlyadded
  • Ansel_Block_RecentlyAddedGeodata
  • Ansel_Config
  • Ansel_Form_Watermark
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Displays mini thumbnails of images in the selected (or random) gallery.
  4:  *
  5:  * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Duck <Duck@obla.net>
 11:  * @author  Marcus Ryan <marcus@horde.org>
 12:  */
 13: class Ansel_Block_Gallery extends Horde_Core_Block
 14: {
 15:     /**
 16:      * @var Ansel_Gallery
 17:      */
 18:     private $_gallery = null;
 19: 
 20:     /**
 21:      */
 22:     public function __construct($app, $params = array())
 23:     {
 24:         parent::__construct($app, $params);
 25: 
 26:         $this->_name = _("Gallery");
 27:     }
 28: 
 29:     /**
 30:      */
 31:     protected function _params()
 32:     {
 33:         $params = array(
 34:             'gallery' => array(
 35:                 'name' => _("Gallery"),
 36:                 'type' => 'enum',
 37:                 'default' => '__random',
 38:                 'values' => array('__random' => _("Random gallery"))
 39:             ),
 40:             'perpage' => array(
 41:                 'name' => _("Maximum number of photos to display (0 means unlimited)"),
 42:                 'type' => 'int',
 43:                 'default' => 20
 44:             ),
 45:             'use_lightbox' => array(
 46:                 'name' => _("Use a lightbox to view photos"),
 47:                 'type' => 'checkbox',
 48:                 'default' => true
 49:             )
 50:         );
 51: 
 52:         $storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
 53:         if (empty($GLOBALS['conf']['gallery']['listlimit']) ||
 54:             ($storage->countGalleries(
 55:                 $GLOBALS['registry']->getAuth(),
 56:                 array('perm' => Horde_Perms::READ)) < $GLOBALS['conf']['gallery']['listlimit'])) {
 57: 
 58:             foreach ($storage->listGalleries() as $gal) {
 59:                 $params['gallery']['values'][$gal->id] = $gal->get('name');
 60:             }
 61:         }
 62: 
 63:         return $params;
 64:     }
 65: 
 66:     /**
 67:      */
 68:     protected function _title()
 69:     {
 70:         try {
 71:             $gallery = $this->_getGallery();
 72:         } catch (Horde_Exception $e) {
 73:             return Ansel::getUrlFor('view', array('view' => 'List'), true)->link() . $this->getName() . '</a>';
 74:         }
 75: 
 76:         // Build the gallery name.
 77:         if (isset($this->_params['gallery']) &&
 78:             $this->_params['gallery'] == '__random') {
 79:             $name = _("Random Gallery") . ': ' . $gallery->get('name');
 80:         } else {
 81:             $name = $gallery->get('name');
 82:         }
 83:         $viewurl = Ansel::getUrlFor('view',
 84:             array('view' => 'Gallery',
 85:                   'gallery' => $gallery->id,
 86:                   'slug' => $gallery->get('slug')),
 87:             true);
 88: 
 89:         return $viewurl->link() . htmlspecialchars($name) . '</a>';
 90:     }
 91: 
 92:     /**
 93:      */
 94:     protected function _content()
 95:     {
 96:         try {
 97:            $gallery = $this->_getGallery();
 98:         } catch (Horde_Exception $e) {
 99:             return $e->getMessage();
100:         }
101: 
102:         $params = array('gallery_id' => $gallery->id,
103:                         'count' => $this->_params['perpage']);
104:         if (!empty($this->_params['use_lightbox'])) {
105:             $params['lightbox'] = true;
106:         }
107:         $html = Ansel::embedCode($params);
108: 
109:         // Be nice to people with <noscript>
110:         $viewurl = Ansel::getUrlFor('view', array('view' => 'Gallery',
111:                                                   'gallery' => $gallery->id,
112:                                                   'slug' => $gallery->get('slug')),
113:                                     true);
114:         $html .= '<noscript>';
115:         $html .= $viewurl->link(array('title' => sprintf(_("View %s"), $gallery->get('name'))));
116:         if ($iid = $gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')) &&
117:             $gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
118: 
119:             $html .= '<img src="' . Ansel::getImageUrl($gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')), 'thumb', true) . '" alt="' . htmlspecialchars($gallery->get('name')) . '" />';
120:         } else {
121:             $html .= Horde::img('thumb-error.png');
122:         }
123: 
124:         return $html . '</a></noscript>';
125:     }
126: 
127:     /**
128:      * @param boolean $retry
129:      *
130:      * @return Ansel_Gallery
131:      */
132:     private function _getGallery($retry = false)
133:     {
134:         // Make sure we haven't already selected a gallery.
135:         if ($this->_gallery instanceof Ansel_Gallery) {
136:             return $this->_gallery;
137:         }
138: 
139:         // Get the gallery object and cache it.
140:         if (isset($this->_params['gallery']) && $this->_params['gallery'] != '__random') {
141:             $this->_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->_params['gallery']);
142:         } else {
143:             $this->_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getRandomGallery();
144:         }
145: 
146:         // Protect at least a little bit against getting an empty gallery. We
147:         // can't just loop until we get one with images since it's possible we
148:         // actually don't *have* any with images yet.
149:         if ($this->_params['gallery'] == '__random' &&
150:             !empty($this->_gallery) &&
151:             !$this->_gallery->countImages() &&
152:             $this->_gallery->hasSubGalleries() && !$retry) {
153: 
154:             $this->_gallery = null;
155:             $this->_gallery = $this->_getGallery(true);
156:         }
157: 
158:         if (empty($this->_gallery)) {
159:             throw new Horde_Exception_NotFound(_("Gallery does not exist."));
160:         } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW) ||
161:                   !$this->_gallery->isOldEnough() || $this->_gallery->hasPasswd()) {
162:             throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
163:         }
164: 
165:         // Return the gallery.
166:         return $this->_gallery;
167:     }
168: 
169: }
170: 
API documentation generated by ApiGen