Get a date parts array containing only enough date parts for the depth
we are at. If an empty array is passed, attempt to get the parts from
url parametrs. Any missing date parts must be set to 0.
public static getDateParameter ( array $date = [] ) : array | ||
$date | array | A full date parts array or an empty array. |
Результат | array | A trimmed down (if necessary) date parts array. |
/** * 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(); }
Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } try { $gallery = $injector->getInstance('Ansel_Storage')->getGallery($galleryId); } catch (Ansel_Excception $e) { $notification->push(_("There was an error accessing the gallery."), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing this gallery."), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); } $style = $gallery->getStyle(); $date = Ansel::getDateParameter(); $gallery->setDate($date); switch (Horde_Util::getFormData('action')) { case 'Sort': parse_str(Horde_Util::getPost('order'), $order); $order = $order['order']; foreach ($order as $pos => $id) { $gallery->setImageOrder($id, $pos); } $notification->push(_("Gallery sorted."), 'horde.success'); $style = $gallery->getStyle(); Ansel::getUrlFor('view', array_merge(array('view' => 'Gallery', 'gallery' => $galleryId, 'slug' => $gallery->get('slug')), $date), true)->redirect(); exit; case 'Reset': // Reset the sort order by date. $images = $injector->getInstance('Ansel_Storage')->listImages(array('gallery_id' => $galleryId, 'sort' => 'image_original_date'));
/** * Todo * * @param integer $galleryId The gallery id * @param string $slug The gallery slug * * @return Ansel_Gallery The requested Ansel_Gallery object * @throws Horde_Exception * @throws InvalidArgumentException * */ protected function _getGallery($galleryId = null, $slug = '') { if (is_null($galleryId) && empty($slug)) { $galleryId = !empty($this->_params['gallery_id']) ? $this->_params['gallery_id'] : null; $slug = !empty($this->_params['gallery_slug']) ? $this->_params['gallery_slug'] : null; } if (empty($galleryId) && empty($slug)) { throw new Ansel_Exception(_("No gallery specified")); } // If we have a slug, use it. try { if (!empty($slug)) { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleryBySlug($slug); } else { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($galleryId); } } catch (Ansel_Exception $e) { throw new Horde_Exception_NotFound($e->getmessage()); } if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { throw new Horde_Exception_PermissionDenied(_("Access denied to this gallery.")); } /* Set any date info we might have */ if (!empty($this->_params['year'])) { $date = Ansel::getDateParameter(array('year' => $this->_params['year'], 'month' => $this->_params['month'], 'day' => $this->_params['day'])); } else { $date = array(); } $gallery->setDate($date); return $gallery; }
/** * Check for, and handle, image editing actions. * * @param string $actionID The action identifier. * * @return boolean True if an action was handled, otherwise false. * @throws Ansel_Exception */ public static function editActions($actionID) { global $notification, $page_output, $registry; $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); $gallery_id = Horde_Util::getFormData('gallery'); $image_id = Horde_Util::getFormData('image'); $date = Ansel::getDateParameter(); $page = Horde_Util::getFormData('page', 0); $watermark_font = Horde_Util::getFormData('font'); $watermark_halign = Horde_Util::getFormData('whalign'); $watermark_valign = Horde_Util::getFormData('wvalign'); $watermark = Horde_Util::getFormData('watermark', $GLOBALS['prefs']->getValue('watermark_text')); // Get the gallery object and style information. try { $gallery = $ansel_storage->getGallery($gallery_id); } catch (Ansel_Exception $e) { $notification->push(sprintf(_("Gallery %s not found."), $gallery_id), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } switch ($actionID) { case 'modify': try { $image = $ansel_storage->getImage($image_id); $ret = Horde_Util::getFormData('ret', 'gallery'); } catch (Ansel_Exception $e) { $notification->push(_("Photo not found."), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } $title = sprintf(_("Edit properties :: %s"), $image->filename); // Set up the form object. $vars = Horde_Variables::getDefaultVariables(); if ($ret == 'gallery') { $vars->set('actionID', 'saveclose'); } else { $vars->set('actionID', 'savecloseimage'); } $form = new Ansel_Form_Image($vars, $title); $renderer = new Horde_Form_Renderer(); // Set up the gallery attributes. $vars->set('image_default', $image->id == $gallery->get('default')); $vars->set('image_desc', $image->caption); $vars->set('image_tags', implode(', ', $image->getTags())); $vars->set('image_originalDate', $image->originalDate); $vars->set('image_uploaded', $image->uploaded); $page_output->header(array('title' => $title)); $form->renderActive($renderer, $vars, Horde::url('image.php'), 'post', 'multipart/form-data'); $page_output->footer(); exit; case 'savecloseimage': case 'saveclose': case 'save': $title = _("Save Photo"); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving photo to this gallery."), 'horde.error'); Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'slug' => $gallery->get('slug'), 'view' => 'Gallery', 'page' => $page), $date), true)->redirect(); exit; } // Validate the form object. $vars = Horde_Variables::getDefaultVariables(); $vars->set('actionID', 'save'); $renderer = new Horde_Form_Renderer(); $form = new Ansel_Form_Image($vars, _("Edit a photo")); // Update existing image. if ($form->validate($vars)) { $form->getInfo($vars, $info); // Replacing photo if (!empty($info['file0']['file'])) { try { $GLOBALS['browser']->wasFileUploaded('file0'); if (filesize($info['file0']['file'])) { $data = file_get_contents($info['file0']['file']); if (getimagesize($info['file0']['file']) === false) { $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error'); unset($data); } } } catch (Horde_Browser_Exception $e) { } } $image = $ansel_storage->getImage($image_id); $image->caption = $vars->get('image_desc'); $image->setTags(explode(',', $vars->get('image_tags'))); $newDate = new Horde_Date($vars->get('image_originalDate')); $image->originalDate = (int) $newDate->timestamp(); if (!empty($data)) { try { $image->replace($data); } catch (Ansel_Exception $e) { $notification->push(_("There was an error replacing the photo."), 'horde.error'); } } $image->save(); if ($vars->get('image_default')) { if ($gallery->get('default') != $image_id) { // Changing default - force refresh of stack // If we have a default-pretty already, make sure we delete it $ids = unserialize($gallery->get('default_prettythumb')); if (is_array($ids)) { foreach ($ids as $imageId) { $gallery->removeImage($imageId, true); } } $gallery->set('default_prettythumb', ''); } $gallery->set('default', $image_id); $gallery->set('default_type', 'manual'); } elseif ($gallery->get('default') == $image_id) { // Currently set as default, but we no longer wish it. $gallery->set('default', 0); $gallery->set('default_type', 'auto'); // If we have a default-pretty already, make sure we delete it $ids = unserialize($gallery->get('default_prettythumb')); if (is_array($ids)) { foreach ($ids as $imageId) { $gallery->removeImage($imageId); } } $gallery->set('default_prettythumb', ''); } $gallery->save(); $imageurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page), $date), true); if ($actionID == 'save') { $imageurl->redirect(); } elseif ($actionID == 'saveclose') { $page_output->addInlineScript(array('window.opener.location.href = window.opener.location.href;', 'window.close();')); $page_output->outputInlineScript(); } else { $page_output->addInlineScript(array('window.opener.location.href = "' . $imageurl . '";', 'window.close();')); $page_output->outputInlineScript(); } exit; } break; case 'editimage': case 'cropedit': case 'resizeedit': $imageGenerator_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page), $date), true); $imageurl = Horde::url('image.php')->add(array_merge(array('gallery' => $gallery_id, 'slug' => $gallery->get('slug'), 'image' => $image_id, 'page' => $page), $date)); $galleryurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'page' => $page, 'view' => 'Gallery', 'slug' => $gallery->get('slug')), $date)); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing the photo."), 'horde.error'); // Return to the image view. $imageGenerator_url->redirect(); exit; } // Retrieve image details. $image = $ansel_storage->getImage($image_id); $title = sprintf(_("Edit %s :: %s"), $gallery->get('name'), $image->filename); if ($actionID == 'cropedit') { $geometry = $image->getDimensions('full'); $x1 = 0; $y1 = 0; $x2 = $geometry['width']; $y2 = $geometry['height']; // js and css files $page_output->addScriptFile('scriptaculous/builder.js', 'horde'); $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $page_output->addScriptFile('scriptaculous/controls.js', 'horde'); $page_output->addScriptFile('scriptaculous/dragdrop.js', 'horde'); $page_output->addScriptFile('cropper.js'); $page_output->addInlineScript('imageCropper.init();', true); $page_output->addThemeStylesheet('cropper.css'); } elseif ($actionID == 'resizeedit') { // js and css files $geometry = $image->getDimensions('full'); $page_output->addScriptFile('scriptaculous/builder.js', 'horde'); $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $page_output->addScriptFile('scriptaculous/controls.js', 'horde'); $page_output->addScriptFile('scriptaculous/dragdrop.js', 'horde'); $page_output->addScriptFile('scriptaculous/slider.js', 'horde'); $page_output->addScriptFile('resizeimage.js'); $js = array('window.Ansel = window.Ansel || {}', 'Ansel.image_geometry = ' . Horde_Serialize::serialize($geometry, Horde_Serialize::JSON), "Ansel.slider = new Control.Slider(\n 'handle1',\n 'slider-track',\n {\n minimum: 1,\n maximum: Ansel.image_geometry['width'],\n sliderValue: Ansel.image_geometry['width'],\n handleImage: 'ansel_slider_img',\n axis: 'horizontal',\n onChange: function(e) { resizeImage(e * Ansel.image_geometry['width']); },\n onSlide: function(e) { resizeImage(e * Ansel.image_geometry['width']); }\n }\n );"); $page_output->addInlineScript($js, true); } $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status')); if ($actionID == 'cropedit') { require ANSEL_TEMPLATES . '/image/crop_image.inc'; } elseif ($actionID == 'resizeedit') { require ANSEL_TEMPLATES . '/image/resize_image.inc'; } else { require ANSEL_TEMPLATES . '/image/edit_image.inc'; } $page_output->footer(); exit; case 'watermark': if ($watermark) { $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(); $name = $identity->getValue('fullname'); if (empty($name)) { $name = $registry->getAuth(); } // Set up array of possible substitutions. $watermark_array = array('%N' => $name, '%L' => $registry->getAuth()); $watermark = str_replace(array_keys($watermark_array), array_values($watermark_array), $watermark); $watermark = strftime($watermark); } if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving photo to this gallery."), 'horde.error'); // Return to the image view Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page, 'slug' => $gallery->get('slug')), $date), true)->redirect(); exit; } else { $image = $ansel_storage->getImage($image_id); $image->watermark('screen', $watermark, $watermark_halign, $watermark_valign, $watermark_font); $image->updateData($image->raw('screen'), 'screen'); Horde::url('image.php', true)->add(array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'actionID' => 'editimage', 'page' => $page), $date))->redirect(); exit; } case 'rotate90': case 'rotate180': case 'rotate270': case 'flip': case 'mirror': case 'grayscale': case 'crop': case 'resize': if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving photo to this gallery."), 'horde.error'); } else { try { $image = $ansel_storage->getImage($image_id); } catch (Ansel_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } switch ($actionID) { case 'rotate90': case 'rotate180': case 'rotate270': $angle = intval(substr($actionID, 6)); try { $image->rotate('full', $angle); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'flip': try { $image->flip('full'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'mirror': try { $image->mirror('full'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'grayscale': try { $image->grayscale('full'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'crop': $image->load('full'); $params = Horde_Util::getFormData('params'); list($x1, $y1, $x2, $y2) = explode('.', $params); try { $image->crop($x1, $y1, $x2, $y2); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'resize': $image->load('full'); $width = Horde_Util::getFormData('width'); $height = Horde_Util::getFormData('height'); try { $image->resize($width, $height, true); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; } if (empty($error)) { $image->updateData($image->raw()); } } Horde::url('image.php', true)->add(array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'actionID' => 'editimage', 'page' => $page), $date))->redirect(); exit; case 'setwatermark': $title = _("Watermark"); try { $image = $ansel_storage->getImage($image_id); } catch (Ansel_Exception $e) { $notification->push($image->getMessage(), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } $vars = Horde_Variables::getDefaultVariables(); $vars->set('actionID', 'previewcustomwatermark'); $form = new Ansel_Form_Watermark($vars, _("Watermark")); $renderer = new Horde_Form_Renderer(); $page_output->header(array('title' => $title)); $form->renderActive($renderer, $vars, Horde::url('image.php'), 'post'); $page_output->footer(); exit; case 'previewcustomwatermark': $imageurl = Horde::url('image.php', true)->add(array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'page' => $page, 'watermark' => $watermark, 'font' => $watermark_font, 'whalign' => $watermark_halign, 'wvalign' => $watermark_valign, 'actionID' => 'previewwatermark'), $date)); $page_output->addInlineScript(array('window.opener.location.href = "' . $imageurl . '";', 'window.close();')); $page_output->outputInlineScript(); exit; case 'previewgrayscale': case 'previewwatermark': case 'previewflip': case 'previewmirror': case 'previewrotate90': case 'previewrotate180': case 'previewrotate270': $title = _("Edit Photo"); $action = substr($actionID, 7); $image = $ansel_storage->getImage($image_id); $title = sprintf(_("Preview changes for %s :: %s"), $gallery->get('name'), $image->filename); $page_output->header(array('title' => $title)); require ANSEL_TEMPLATES . '/image/preview_image.inc'; $page_output->footer(); exit; case 'imagerotate90': case 'imagerotate180': case 'imagerotate270': $view = Horde_Util::getFormData('view'); $angle = intval(substr($actionID, 11)); $image = $ansel_storage->getImage($image_id); $image->rotate($view, $angle); $image->display($view); exit; case 'imageflip': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->flip($view); $image->display($view); exit; case 'imagemirror': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->mirror($view); $image->display($view); exit; case 'imagegrayscale': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->grayscale($view); $image->display($view); exit; case 'imagewatermark': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->watermark($view, $watermark, $watermark_halign, $watermark_valign, $watermark_font); $image->display($view); exit; case 'previewcrop': if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing the photo."), 'horde.error'); Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page))->redirect(); } else { $x1 = (int) Horde_Util::getFormData('x1'); $y1 = (int) Horde_Util::getFormData('y1'); $x2 = (int) Horde_Util::getFormData('x2'); $y2 = (int) Horde_Util::getFormData('y2'); $title = _("Crop"); $action = substr($actionID, 7); $image = $ansel_storage->getImage($image_id); $title = sprintf(_("Preview changes for %s :: %s"), $gallery->get('name'), $image->filename); $params = $x1 . '.' . $y1 . '.' . $x2 . '.' . $y2; $page_output->header(array('title' => $title)); require ANSEL_TEMPLATES . '/image/preview_cropimage.inc'; $page_output->footer(); } exit; case 'imagecrop': if ($gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $params = Horde_Util::getFormData('params'); list($x1, $y1, $x2, $y2) = explode('.', $params); $image = $ansel_storage->getImage($image_id); $image->load('full'); $image->crop($x1, $y1, $x2, $y2); $image->display(); } exit; } return false; }
/** * 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(); }
Ansel::getUrlFor('default_view', array())->redirect(); exit; } try { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id); } catch (Ansel_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Ansel::getUrlFor('view', array('gallery' => $gallery_id))->redirect(); exit; } if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing this gallery."), 'horde.error'); Ansel::getUrlFor('view', array('gallery' => $gallery_id))->redirect(); exit; } $gallery->setDate(Ansel::getDateParameter()); $page = Horde_Util::getFormData('page', 0); $perpage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']); $images = $gallery->getImages($page * $perpage, $perpage); $reloadimage = Horde::img('reload.png'); $customimage = Horde::img('layout.png'); $customurl = Horde::url('faces/custom.php')->add('page', $page); $face = $injector->getInstance('Ansel_Faces'); $autogenerate = $face->canAutogenerate(); $vars = Horde_Variables::getDefaultVariables(); $pager = new Horde_Core_Ui_Pager('page', $vars, array('num' => $gallery->countImages(), 'url' => 'faces/gallery.php', 'perpage' => $perpage)); $pager->preserve('gallery', $gallery_id); $title = sprintf(_("Searching for faces in %s"), Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'view' => 'Gallery'))->link() . $gallery->get('name') . '</a>'); $page_output->addScriptFile('stripe.js', 'horde'); $page_output->addScriptFile('popup.js', 'horde'); $page_output->header(array('title' => $title));
/** * Return the current pagerurl. * * @return Horde_Url The url */ protected function _getPagerUrl() { $date_params = Ansel::getDateParameter(array('year' => !empty($this->view->year) ? $this->view->year : 0, 'month' => !empty($this->view->month) ? $this->view->month : 0, 'day' => !empty($this->view->day) ? $this->view->day : 0)); if (!empty($this->view->gallery_view_url)) { $pagerurl = new Horde_Url(str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->gallery_view_url))); $pagerurl->add($date_params)->setRaw(true); } else { // Build the pager url. Add the needed variables directly to the // url instead of passing it as a preserved variable to the pager // since the logic to build the URL is already in getUrlFor() $pager_params = array_merge(array('gallery' => $this->galleryId, 'view' => 'Gallery', 'slug' => $this->view->gallery->get('slug')), $date_params); $pagerurl = Ansel::getUrlfor('view', $pager_params, true); } return $pagerurl; }
/** * Get the HTML representing this view. * * @return string The HTML */ public function html() { global $conf, $prefs, $registry; // Initialize the Horde_View instance. $view = $this->_getHordeView(); // Get JSON data for view if ($this->mode == Ansel_GalleryMode_Base::MODE_NORMAL) { $json = Ansel_View_Base::json($this->view->gallery, array('full' => !empty($this->view->api), 'perpage' => $this->perpage)); } else { if (!empty($this->date['day']) && $this->numTiles) { $json = Ansel_View_Base::json($this->view->gallery, array('full' => !empty($this->view->api), 'perpage' => $this->perpage)); } else { $json = '[]'; } } $date_params = Ansel::getDateParameter(array('year' => !empty($this->view->year) ? $this->view->year : 0, 'month' => !empty($this->view->month) ? $this->view->month : 0, 'day' => !empty($this->view->day) ? $this->view->day : 0)); $pagerurl = $this->_getPagerUrl(); $graphics_dir = Horde::url(Horde_Themes::img(), true, -1); $image_text = _("Photo"); $of = _("of"); $flipped = array_flip($date_params); if (count($flipped) == 1 && !empty($flipped[0])) { $gallery_url = $pagerurl . '?'; } else { $gallery_url = $pagerurl . '&'; } $js = array(); $js[] = <<<EOT LightboxOptions = { gallery_json: {$json}, fileLoadingImage: '{$graphics_dir}/lightbox/loading.gif', fileBottomNavCloseImage: '{$graphics_dir}/lightbox/closelabel.gif', overlayOpacity: 0.8, // controls transparency of shadow overlay animate: true, // toggles resizing animations resizeSpeed: 7, // controls the speed of the image resizing animations (1=slowest and 10=fastest) borderSize: 10, // if you adjust the padding in the CSS, you will need to update this variable // Used to write: Image # of #. labelImage: '{$image_text}', labelOf: '{$of}', //URL to return to when the lightbox closes returnURL: '{$gallery_url}', startPage: '{$view->page}' }; document.lb = new Lightbox(LightboxOptions); if (window.location.hash.length) document.lb.start(window.location.hash.substring(1)); EOT; $GLOBALS['page_output']->addInlineScript($js, true); // Output js/css here if we are calling via the api if ($this->view->api) { Horde::startBuffer(); global $page_output; $page_output->addThemeStylesheet('lightbox.css'); $page_output->includeStylesheetFiles(array('nobase' => true), true); foreach (array('prototype.js', 'accesskeys.js', 'scriptaculous/effects.js') as $val) { $tmp = new Horde_Script_File_JsDir($val, 'horde'); echo $tmp->tag_full; } $tmp = new Horde_Script_File_JsDir('lightbox.js'); echo $tmp->tag_full; $page_output->outputInlineScript(); $html = Horde::endBuffer(); return $html . $view->render('gallery'); } return $view->render('gallery'); }
/** * Downloads all requested images as a zip file. Assumes all permissions * have been checked on the requested resource. Can request either a * single gallery of images, OR an array of individual image ids. * * @param Ansel_Gallery $gallery The galleries to download * @param array $images The images to download */ public static function downloadImagesAsZip($gallery = null, $images = array()) { global $session; if (empty($GLOBALS['conf']['gallery']['downloadzip'])) { $GLOBALS['notification']->push(_("Downloading zip files is not enabled. Talk to your server administrator.")); Horde::url('view.php?view=List', true)->redirect(); exit; } // Requested a gallery if (!is_null($gallery)) { // We can name the zip file with the slug if we have it $slug = $gallery->get('slug'); // Set the date in case we are viewing in date mode $gallery->setDate(Ansel::getDateParameter()); $images = $gallery->listImages(); } // At this point, we should always have a list of images if (!count($images)) { $notification->push(sprintf(_("There are no photos in %s to download."), $gallery->get('name')), 'horde.message'); Horde::url('view.php?view=List', true)->redirect(); exit; } // Try to close off the current session to avoid locking it while the // gallery is downloading. $session->close(); if (!is_null($gallery)) { // Check full photo permissions if ($gallery->canDownload()) { $view = 'full'; } else { $view = 'screen'; } } $zipfiles = array(); foreach ($images as $id) { $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id); // If we didn't select an entire gallery, check the download // size for each image. if (!isset($view)) { $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery); $v = $g->canDownload() ? 'full' : 'screen'; } else { $v = $view; } $zipfiles[] = array('data' => $image->raw($v), 'name' => $image->filename); } $zip = Horde_Compress::factory('zip'); $body = $zip->compress($zipfiles); if (!empty($gallery)) { $filename = (!empty($slug) ? $slug : $gallery->id) . '.zip'; } else { $filename = 'Ansel.zip'; } $GLOBALS['browser']->downloadHeaders($filename, 'application/zip', false, strlen($body)); echo $body; exit; }