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:  * Display most recently added images.
  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  Michael Rubinsky <mrubinsk@horde.org>
 11:  */
 12: class Ansel_Block_Recentlyadded extends Horde_Core_Block
 13: {
 14:     /**
 15:      * @var Ansel_Gallery
 16:      */
 17:     private $_gallery = null;
 18: 
 19:     /**
 20:      */
 21:     public function __construct($app, $params = array())
 22:     {
 23:         parent::__construct($app, $params);
 24:         $this->_name = _("Recently Added Photos");
 25:     }
 26: 
 27:     /**
 28:      */
 29:     protected function _params()
 30:     {
 31:         $params = array(
 32:             'gallery' => array(
 33:                 'name' => _("Gallery"),
 34:                 'type' => 'enum',
 35:                 'default' => '__random',
 36:                 'values' => array('all' => 'All')
 37:             ),
 38:             'limit' => array(
 39:                 'name' => _("Maximum number of photos"),
 40:                 'type' => 'int',
 41:                 'default' => 10
 42:             )
 43:         );
 44: 
 45:         if (empty($GLOBALS['conf']['gallery']['listlimit']) ||
 46:             ($GLOBALS['injector']
 47:                 ->getInstance('Ansel_Storage')
 48:                 ->countGalleries(
 49:                     $GLOBALS['registry']->getAuth(),
 50:                     array('perm' => Horde_Perms::READ)) < $GLOBALS['conf']['gallery']['listlimit'])) {
 51: 
 52:             foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('perm' => Horde_Perms::READ)) as $gal) {
 53:                 if (!$gal->hasPasswd() && $gal->isOldEnough()) {
 54:                     $params['gallery']['values'][$gal->id] = $gal->get('name');
 55:                 }
 56:             }
 57:         }
 58: 
 59:         return $params;
 60:     }
 61: 
 62:     /**
 63:      */
 64:     protected function _title()
 65:     {
 66:         if ($this->_params['gallery'] != 'all') {
 67:             try {
 68:                 $gallery = $this->_getGallery();
 69:             } catch (Exception $e) {
 70:                 return Ansel::getUrlFor(
 71:                     'view',
 72:                     array('view' => 'List'),
 73:                     true)
 74:                 ->link() . _("Gallery") . '</a>';
 75:             }
 76: 
 77:             $name = htmlspecialchars($gallery->get('name'));
 78:             $style = $gallery->getStyle();
 79:             $viewurl = Ansel::getUrlFor(
 80:                 'view',
 81:                 array(
 82:                     'slug' => $gallery->get('slug'),
 83:                     'gallery' => $gallery->id,
 84:                     'view' => 'Gallery'),
 85:                 true);
 86:             return sprintf(_("Recently Added Photos From %s"), $viewurl->link() . $name . '</a>');
 87:         }
 88:         $viewurl = Ansel::getUrlFor('view', array('view' => 'List'), true);
 89: 
 90:         return $this->getName();
 91:     }
 92: 
 93:     /**
 94:      */
 95:     protected function _content()
 96:     {
 97:         Horde::addScriptFile('block.js');
 98:         if ($this->_params['gallery'] == 'all') {
 99:             $galleries = array();
100:         } elseif (!is_array($this->_params['gallery'])) {
101:             $galleries = array($this->_params['gallery']);
102:         } else {
103:             $galleries = $this->_params['gallery'];
104:         }
105: 
106:         // Retrieve the images, but protect against very large values for limit.
107:         try {
108:             $results = $GLOBALS['injector']
109:                 ->getInstance('Ansel_Storage')
110:                 ->getRecentImages(
111:                     $galleries,
112:                     min($this->_params['limit'], 100));
113:         } catch (Ansel_Exception $e) {
114:             return $e->getMessage();
115:         }
116:         $preview_url = Horde::url('preview.php', true);
117:         $header = array(_("Date"), _("Photo"), _("Gallery"));
118: 
119:         $html = <<<HEADER
120: <table class="linedRow" cellspacing="0" style="width:100%">
121:  <thead><tr class="item nowrap">
122:   <th class="item leftAlign">$header[0]</th>
123:   <th class="item leftAlign">$header[1]</th>
124:   <th class="item leftAlign">$header[2]</th>
125: </tr></thead>
126: <tbody>
127: HEADER;
128:         foreach ($results as $image) {
129:             $gallery = $GLOBALS['injector']
130:                 ->getInstance('Ansel_Storage')
131:                 ->getGallery($image->gallery);
132: 
133:             // Don't show locked galleries in the block.
134:             if (!$gallery->isOldEnough() || $gallery->hasPasswd()) {
135:                 continue;
136:             }
137:             $style = $gallery->getStyle();
138: 
139:             $galleryLink = Ansel::getUrlFor(
140:                 'view',
141:                 array(
142:                     'slug' => $gallery->get('slug'),
143:                     'gallery' => $gallery->id,
144:                     'view' => 'Gallery'),
145:                 true);
146:             $galleryLink = $galleryLink->link()
147:                 . htmlspecialchars($gallery->get('name'))
148:                 . '</a>';
149: 
150:             $caption = substr($image->caption, 0, 30);
151:             if (strlen($image->caption) > 30) {
152:                 $caption .= '...';
153:             }
154: 
155:             /* Generate the image view url */
156:             $url = Ansel::getUrlFor(
157:                 'view',
158:                 array(
159:                     'view' => 'Image',
160:                     'slug' => $gallery->get('slug'),
161:                     'gallery' => $gallery->id,
162:                     'image' => $image->id,
163:                     'gallery_view' => $style->gallery_view));
164: 
165:             $html .= '<tr><td>' . strftime('%x', $image->uploaded)
166:                 . '</td><td class="nowrap">'
167:                 . $url->link(
168:                     array(
169:                         'onmouseout' => '$("ansel_preview").hide();$("ansel_preview").update("");',
170:                         'onmouseover' => 'Ansel.previewImage(event, ' . $image->id . ');'))
171:                 . htmlspecialchars(strlen($caption) ? $caption : $image->filename)
172:                 . '</a></td><td class="nowrap">' . $galleryLink . '</td></tr>';
173:         }
174:         $html .= '</tbody></table>';
175: 
176:         return $html;
177:     }
178: 
179:     /**
180:      * @return Ansel_Gallery
181:      */
182:     private function _getGallery()
183:     {
184:         /* Make sure we haven't already selected a gallery. */
185:         if ($this->_gallery instanceof Ansel_Gallery) {
186:             return $this->_gallery;
187:         }
188: 
189:         /* Get the gallery object and cache it. */
190:         if (isset($this->_params['gallery']) &&
191:             $this->_params['gallery'] != '__random') {
192:             $this->_gallery = $GLOBALS['injector']
193:                 ->getInstance('Ansel_Storage')
194:                 ->getGallery($this->_params['gallery']);
195:         } else {
196:             $this->_gallery = $GLOBALS['injector']
197:                 ->getInstance('Ansel_Storage')
198:                 ->getRandomGallery();
199:         }
200: 
201:         if (empty($this->_gallery)) {
202:             throw new Horde_Exception_NotFound(_("Gallery not found."));
203:         } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
204:             throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
205:         }
206: 
207:         /* Return a reference to the gallery. */
208:         return $this->_gallery;
209:     }
210: 
211: }
212: 
API documentation generated by ApiGen