Overview

Packages

  • Ansel
  • None

Classes

  • Ansel
  • Ansel_Ajax_Application
  • Ansel_Ajax_Imple_EditCaption
  • Ansel_Ajax_Imple_EditFaces
  • Ansel_Ajax_Imple_EditGalleryFaces
  • Ansel_Ajax_Imple_Embed
  • Ansel_Ajax_Imple_GallerySlugCheck
  • Ansel_Ajax_Imple_ImageSaveGeotag
  • Ansel_Ajax_Imple_LocationAutoCompleter
  • Ansel_Ajax_Imple_MapLayerSelect
  • Ansel_Ajax_Imple_TagActions
  • Ansel_Ajax_Imple_ToggleGalleryActions
  • Ansel_Ajax_Imple_ToggleOtherGalleries
  • Ansel_Ajax_Imple_UploadNotification
  • Ansel_Api
  • Ansel_Exception
  • Ansel_Faces
  • Ansel_Faces_Base
  • Ansel_Faces_Facedetect
  • Ansel_Faces_User
  • Ansel_Factory_Faces
  • Ansel_Factory_Storage
  • Ansel_Factory_Styles
  • Ansel_Form_Ecard
  • Ansel_Form_Image
  • Ansel_Form_ImageDate
  • Ansel_Form_Upload
  • Ansel_Gallery
  • Ansel_Gallery_Decorator_Date
  • Ansel_GalleryMode_Base
  • Ansel_GalleryMode_Date
  • Ansel_GalleryMode_Normal
  • Ansel_Image
  • Ansel_ImageGenerator
  • Ansel_ImageGenerator_Mini
  • Ansel_ImageGenerator_PolaroidThumb
  • Ansel_ImageGenerator_PolaroidThumbStack
  • Ansel_ImageGenerator_RoundedThumb
  • Ansel_ImageGenerator_RoundedThumbStack
  • Ansel_ImageGenerator_Screen
  • Ansel_ImageGenerator_ShadowThumb
  • Ansel_ImageGenerator_ShadowThumbStack
  • Ansel_ImageGenerator_SquareThumb
  • Ansel_ImageGenerator_Thumb
  • Ansel_LoginTasks_SystemTask_Upgrade
  • Ansel_Report
  • Ansel_Report_letter
  • Ansel_Report_mail
  • Ansel_Report_tickets
  • Ansel_Search
  • Ansel_Search_exif
  • Ansel_Search_Tag
  • Ansel_Storage
  • Ansel_Style
  • Ansel_Tagger
  • Ansel_Test
  • Ansel_Tile_DateGallery
  • Ansel_Tile_Gallery
  • Ansel_Tile_Image
  • Ansel_View_Ansel
  • Ansel_View_Base
  • Ansel_View_EmbeddedRenderer_GalleryLink
  • Ansel_View_EmbeddedRenderer_Mini
  • Ansel_View_EmbeddedRenderer_Slideshow
  • Ansel_View_Gallery
  • Ansel_View_GalleryProperties
  • Ansel_View_GalleryRenderer_Base
  • Ansel_View_GalleryRenderer_Gallery
  • Ansel_View_GalleryRenderer_GalleryLightbox
  • Ansel_View_Image
  • Ansel_View_List
  • Ansel_View_Results
  • Ansel_View_Slideshow
  • Ansel_View_Upload
  • Ansel_Widget
  • Ansel_Widget_Actions
  • Ansel_Widget_Base
  • Ansel_Widget_GalleryFaces
  • Ansel_Widget_Geotag
  • Ansel_Widget_ImageFaces
  • Ansel_Widget_Links
  • Ansel_Widget_OtherGalleries
  • Ansel_Widget_OwnerFaces
  • Ansel_Widget_SimilarPhotos
  • Ansel_Widget_Tags
  • Ansel_XPPublisher
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Class to encapsulate the UI for adding/viewing/changing galleries.
  4:  *
  5:  * Copyright 2010-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 Chuck Hagenbuch <chuck@horde.org>
 11:  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
 12:  * @package Ansel
 13:  */
 14: class Ansel_View_GalleryProperties
 15: {
 16:     /**
 17:      * View parameters
 18:      *
 19:      * @var array
 20:      */
 21:     protected $_params;
 22: 
 23:     /**
 24:      * Hash of gallery properties.
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_properties;
 29: 
 30:     /**
 31:      * The view title
 32:      *
 33:      * @var string
 34:      */
 35:     protected $_title;
 36: 
 37:     /**
 38:      * Const'r
 39:      *
 40:      * @param array $params  Parameters for the view
 41:      */
 42:     public function __construct($params = array())
 43:     {
 44:         $this->_params = $params;
 45:     }
 46: 
 47:     /**
 48:      * Runs the view
 49:      *
 50:      * @return void
 51:      */
 52:     public function run()
 53:     {
 54:         switch ($this->_params['actionID']) {
 55:         case 'add':
 56:             $this->_runNew();
 57:             $this->_output();
 58:             break;
 59:         case 'addchild':
 60:             $this->_runNewChild();
 61:             $this->_output();
 62:             break;
 63:         case 'modify':
 64:             $this->_runEdit();
 65:             $this->_output();
 66:             break;
 67:         case 'save':
 68:             $this->_runSave();
 69:             break;
 70:         }
 71:     }
 72: 
 73:     private function _loadDefaults()
 74:     {
 75:         /*Gallery properties */
 76:         $this->_properties = array(
 77:             'name' => '',
 78:             'desc' => '',
 79:             'tags' => '',
 80:             'style' => Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle')),
 81:             'slug' => '',
 82:             'age' => 0,
 83:             'download' => $GLOBALS['prefs']->getValue('default_download'),
 84:             'parent' => null,
 85:             'id' => null,
 86:             'mode' => 'Normal',
 87:             'passwd' => '',
 88:             'owner' => ''
 89:         );
 90:     }
 91: 
 92:     /**
 93:      * Outputs the view to the browser.
 94:      *
 95:      * @return void
 96:      */
 97:     private function _output()
 98:     {
 99:         $view = new Horde_View(array('templatePath' => array(ANSEL_TEMPLATES . '/gallery',
100:                                                              ANSEL_TEMPLATES . '/gallery/partial',
101:                                                              ANSEL_TEMPLATES . '/gallery/layout')));
102:         $view->addHelper('Text');
103:         $view->properties = $this->_properties;
104:         $view->title = $this->_title;
105:         $view->action = $this->_params['actionID'];
106:         $view->url = $this->_params['url'];
107:         $view->availableThumbs = $this->_thumbStyles();
108:         $view->galleryViews = $this->_galleryViewStyles();
109:         $view->locked = array('download' => $GLOBALS['prefs']->isLocked('default_download'));
110:         $view->isOwner = $GLOBALS['registry']->getAuth() &&
111:                          $GLOBALS['registry']->getAuth() == $this->_properties['owner'];
112: 
113:         $view->havePretty = $GLOBALS['conf']['image']['prettythumbs'];
114:         $view->ages = $GLOBALS['conf']['ages']['limits'];
115: 
116:         $js = array('$("gallery_name").focus()');
117:         if ($GLOBALS['conf']['image']['type'] != 'png') {
118:             $js[] = 'function checkStyleSelection()
119:                 {
120:                     var s, bg = $F("background_color");
121:                     $A($("thumbnail_style").options).each(function(o) {
122:                         if (o.value == "Thumb" && o.selected == "1") {
123:                            s = true;
124:                         }
125:                     });
126:                     if (bg == "none" && !s) {
127:                         alert("' . _("Your server does not support thumbnails with transparent backgrounds.  Either select a background color or use the 'Basic Thumbnail' type. Please contact your server administrator for more information.") . '");
128:                         $A($("thumbnail_style").options).each(function(o) {
129:                             if (o.value == "Thumb") {
130:                                 o.selected = "1";
131:                             }
132:                         })
133:                     }
134:                 }';
135:             $js[] = '$("background_color").observe("change", checkStyleSelection); $("thumbnail_style").observe("change", checkStyleSelection);';
136:         }
137:         Horde::addInlineScript($js, 'dom');
138:         Horde::addScriptFile('stripe.js', 'horde');
139:         Horde::addScriptFile('popup.js', 'horde');
140: 
141:         /* Attach the slug check action to the form */
142:         $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('ansel', 'GallerySlugCheck'), array(
143:             'bindTo' => 'gallery_slug',
144:             'slug' => $this->_properties['slug']
145:         ));
146: 
147:         require $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc';
148:         echo Horde::menu();
149:         $GLOBALS['notification']->notify(array('listeners' => 'status'));
150:         echo $view->render('properties');
151:         require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc';
152:     }
153: 
154:     /**
155:      * Set up for adding new galleries.
156:      *
157:      * @return void
158:      */
159:     private function _runNew()
160:     {
161:         $this->_loadDefaults();
162:         $this->_title = _("Adding a New Gallery");
163:         $this->_properties['owner'] = $GLOBALS['registry']->getAuth();
164:     }
165: 
166:     /**
167:      * Set up for adding a new child gallery.
168:      *
169:      * @return void
170:      */
171:     private function _runNewChild()
172:     {
173:         $this->_loadDefaults();
174: 
175:         // Get the parent and make sure that it exists and that we have
176:         // permissions to add to it.
177:         $parentId = $this->_params['gallery'];
178:         try {
179:             $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($parentId);
180:         } catch (Ansel_Exception $e) {
181:             $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
182:             Horde::url('view.php?view=List', true)->redirect();
183:             exit;
184:         }
185: 
186:         if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
187:             $GLOBALS['notification']->push(sprintf(_("Access denied adding a gallery to \"%s\"."),
188:                                 $parent->get('name')), 'horde.error');
189:             Horde::url('view.php?view=List', true)->redirect();
190:             exit;
191:         }
192: 
193:         // Set up the gallery attributes.
194:         $this->_properties['style'] = $parent->get('style');
195:         $this->_properties['parent'] = $parentId;
196:         $this->_title = sprintf(_("Adding A Subgallery to %s"), $parent->get('name'));
197:     }
198: 
199:     /**
200:      * Handle setting up the form for editing an existing gallery
201:      *
202:      * @return void
203:      * @throws InvalidArgumentException
204:      */
205:     private function _runEdit()
206:     {
207:         if (empty($this->_params['gallery'])) {
208:             throw new InvalidArgumentException(_("Missing gallery parameter"));
209:         }
210: 
211:         try {
212:             $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->_params['gallery']);
213:             $parent = $gallery->getParent();
214:             $this->_properties = array(
215:                 'name' => $gallery->get('name'),
216:                 'desc' => $gallery->get('desc'),
217:                 'tags' => implode(',', $gallery->getTags()),
218:                 'slug' => $gallery->get('slug'),
219:                 'age' => (int)$gallery->get('age'),
220:                 'download' => $gallery->get('download'),
221:                 'mode' => $gallery->get('view_mode'),
222:                 'passwd' => $gallery->get('passwd'),
223:                 'parent' => !is_null($parent) ? $parent->id : $parent,
224:                 'id' => $gallery->id,
225:                 'owner' => $gallery->get('owner'),
226:                 'style' => $gallery->getStyle()
227:             );
228:             $this->_title = sprintf(_("Modifying: %s"), $this->_properties['name']);
229:         } catch (Ansel_Exception $e) {
230:             $title = _("Unknown Gallery");
231:         }
232:     }
233: 
234:     /**
235:      * Handles saving the gallery information from the form submission, and
236:      * redirects back to previous view when complete.
237:      *
238:      * @return void
239:      */
240:     private function _runSave()
241:     {
242:         // Check general permissions.
243:         if (!$GLOBALS['registry']->isAdmin() &&
244:             ($GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') &&
245:              !$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('ansel', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT))) {
246: 
247:             $GLOBALS['notification']->push(_("Access denied editing galleries."), 'horde.error');
248:             Horde::url('view.php?view=List', true)->redirect();
249:             exit;
250:         }
251: 
252:         // Get the form values.
253:         $galleryId = Horde_Util::getFormData('gallery');
254:         $gallery_name = Horde_Util::getFormData('gallery_name');
255:         $gallery_desc = Horde_Util::getFormData('gallery_desc');
256:         $gallery_slug = Horde_Util::getFormData('gallery_slug');
257:         $gallery_age = (int)Horde_Util::getFormData('gallery_age', 0);
258:         $gallery_download = Horde_Util::getFormData('gallery_download');
259:         $gallery_mode = Horde_Util::getFormData('view_mode', 'Normal');
260:         $gallery_passwd = Horde_Util::getFormData('gallery_passwd');
261:         $gallery_tags = Horde_Util::getFormData('gallery_tags');
262:         $gallery_thumbstyle = Horde_Util::getFormData('gallery_style');
263:         $gallery_parent = Horde_Util::getFormData('gallery_parent');
264: 
265:         // Style
266:         $style = new Ansel_Style(array(
267:             'thumbstyle' => Horde_Util::getFormData('thumbnail_style'),
268:             'background' => Horde_Util::getFormData('background_color'),
269:             'gallery_view' => Horde_Util::getFormData('gallery_view'),
270:             // temporary hack until widgets are also configurable.
271:             'widgets' => array(
272:                  'Tags' => array('view' => 'gallery'),
273:                  'OtherGalleries' => array(),
274:                  'Geotag' => array(),
275:                  'Links' => array(),
276:                  'GalleryFaces' => array(),
277:                  'OwnerFaces' => array())
278:         ));
279: 
280:         // Double check for an empty string instead of null
281:         if (empty($gallery_parent)) {
282:             $gallery_parent = null;
283:         }
284: 
285:         if ($galleryId &&
286:             ($exists = ($GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($galleryId)) === true)) {
287: 
288:             // Modifying an existing gallery.
289:             $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($galleryId);
290:             if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
291:                 $GLOBALS['notification']->push(sprintf(_("Access denied saving gallery \"%s\"."), $gallery->get('name')), 'horde.error');
292:             } else {
293:                 // Don't allow the display name to be nulled out.
294:                 if ($gallery_name) {
295:                     $gallery->set('name', $gallery_name);
296:                 }
297:                 $gallery->set('desc', $gallery_desc);
298:                 $gallery->setTags(!empty($gallery_tags) ? explode(',', $gallery_tags) : array());
299:                 $gallery->set('style', $style);
300:                 $gallery->set('slug', $gallery_slug);
301:                 $gallery->set('age', $gallery_age);
302:                 $gallery->set('download', $gallery_download);
303:                 $gallery->set('view_mode', $gallery_mode);
304:                 if ($GLOBALS['registry']->getAuth() &&
305:                     $gallery->get('owner') == $GLOBALS['registry']->getAuth()) {
306:                     $gallery->set('passwd', $gallery_passwd);
307:                 }
308: 
309:                 // Did the parent change?
310:                 $old_parent = $gallery->getParent();
311:                 if (!is_null($old_parent)) {
312:                     $old_parent_id = $old_parent->id;
313:                 } else {
314:                     $old_parent_id = null;
315:                 }
316:                 if ($gallery_parent != $old_parent_id) {
317:                     if (!is_null($gallery_parent)) {
318:                         $new_parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_parent);
319:                     } else {
320:                         $new_parent = null;
321:                     }
322:                     try {
323:                         $result = $gallery->setParent($new_parent);
324:                     } catch (Ansel_Exception $e) {
325:                         $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
326:                         Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
327:                         exit;
328:                     }
329:                 }
330:                 try {
331:                     $result = $gallery->save();
332:                     $GLOBALS['notification']->push(_("The gallery was saved."),'horde.success');
333:                 } catch (Ansel_Exception $e) {
334:                     $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
335:                 }
336:             }
337:         } else {
338:             // Is this a new subgallery?
339:             if ($gallery_parent) {
340:                 try {
341:                     $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_parent);
342:                 } catch (Ansel_Exception $e) {
343:                     $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
344:                     Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
345:                     exit;
346:                 }
347:                 if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
348:                     $GLOBALS['notification']->push(sprintf(
349:                         _("You do not have permission to add children to %s."),
350:                         $parent->get('name')), 'horde.error');
351: 
352:                     Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
353:                     exit;
354:                 }
355:             }
356: 
357:             // Require a display name.
358:             if (!$gallery_name) {
359:                 $GLOBALS['notification']->push(
360:                     _("You must provide a display name for your new gallery."),
361:                     'horde.warning');
362:                 $actionId = 'add';
363:                 $title = _("Adding A New Gallery");
364:             }
365: 
366:             // Create the new gallery.
367:             $perm = (!empty($parent)) ? $parent->getPermission() : null;
368: 
369:             try {
370:                 $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->createGallery(
371:                         array('name' => $gallery_name,
372:                               'desc' => $gallery_desc,
373:                               'tags' => explode(',', $gallery_tags),
374:                               'style' => $style,
375:                               'slug' => $gallery_slug,
376:                               'age' => $gallery_age,
377:                               'download' => $gallery_download,
378:                               'view_mode' => $gallery_mode,
379:                               'passwd' => $gallery_passwd,
380:                               ),
381:                         $perm, $gallery_parent);
382: 
383:                 $galleryId = $gallery->id;
384:                 $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
385:                 Horde::logMessage($msg, 'DEBUG');
386:                 $GLOBALS['notification']->push($msg, 'horde.success');
387:             } catch (Ansel_Exception $e) {
388:                 $galleryId = null;
389:                 $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"),
390:                                  $gallery_name, $e->getMessage());
391:                 Horde::logMessage($error, 'ERR');
392:                 $GLOBALS['notification']->push($error, 'horde.error');
393:                 Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
394:                 exit;
395:             }
396:         }
397: 
398:         // Make sure that the style hash is recorded, ignoring non-styled thumbs
399:         if ($style->thumbstyle != 'Thumb') {
400:             $GLOBALS['injector']->
401:                 getInstance('Ansel_Storage')
402:                 ->ensureHash($gallery->getStyle()->getHash('thumb'));
403:         }
404: 
405:         // Clear the OtherGalleries widget cache
406:         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
407:             $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
408:         }
409: 
410:         // Return to the last view.
411:         $url = Horde_Util::getFormData('url');
412:         if (empty($url) && empty($exists)) {
413:             // Redirect to the images upload page for newly creted galleries
414:             $url = Horde::url('img/upload.php')->add('gallery', $galleryId);
415:         } elseif (empty($url)) {
416:             $url = Horde::url('index.php', true);
417:         } else {
418:             $url = new Horde_Url($url);
419:         }
420:         $url->redirect();
421:     }
422: 
423:    /**
424:     * Get a list of available, currently usable thumbnail styles.
425:     *
426:     * @return array  An array of Classnames => titles
427:     */
428:     protected function _thumbStyles()
429:     {
430:         // Iterate all available thumbstyles:
431:         $dir = ANSEL_BASE . '/lib/ImageGenerator';
432:         $files = scandir($dir);
433:         $thumbs = array();
434:         foreach ($files as $file) {
435:             if (substr($file, -9) == 'Thumb.php') {
436:                 try {
437:                     $generator = Ansel_ImageGenerator::factory(
438:                         substr($file, 0, -4),
439:                         array('style' => Ansel::getStyleDefinition('ansel_default')));
440:                     $thumbs[substr($file, 0, -4)] = $generator->title;
441:                 } catch (Ansel_Exception $e) {}
442:             }
443:         }
444: 
445:         return $thumbs;
446:     }
447: 
448:     /**
449:      * Get a list of available Gallery View styles
450:      *
451:      * @return array
452:      */
453:     protected function _galleryViewStyles()
454:     {
455:         // Iterate all available thumbstyles:
456:         $dir = ANSEL_BASE . '/lib/View/GalleryRenderer';
457:         $files = scandir($dir);
458:         $views = array();
459:         foreach ($files as $file) {
460:             if ($file != 'Base.php' && strpos($file, '.') !== 0) {
461:                 $class = 'Ansel_View_GalleryRenderer_' . substr($file, 0, -4);
462:                 $view = new $class(null);
463:                 $views[substr($file, 0, -4)] = $view->title;
464:             }
465:         }
466: 
467:         return $views;
468:     }
469: }
470: 
471: 
API documentation generated by ApiGen