From: Michael J. Rubinsky Date: Fri, 31 Jul 2009 14:53:22 +0000 (-0400) Subject: Rname lib/Views -> lib/View. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=acd86bb0fbdd06f1d387f9f026c7eb70be185501;p=horde.git Rname lib/Views -> lib/View. Ansel is still completley broken, but this is a step in fixing autoloading --- diff --git a/ansel/lib/View/Abstract.php b/ansel/lib/View/Abstract.php new file mode 100644 index 000000000..acbf521e9 --- /dev/null +++ b/ansel/lib/View/Abstract.php @@ -0,0 +1,188 @@ + + * @author Michael J. Rubinsky + * @package Ansel + */ +class Ansel_View_Abstract { + + var $_params = array(); + + /** + * The ansel resource this view is for. + * + * @var mixed Either an Ansel_Gallery or Ansel_Image + */ + var $resource; + + /** + * The gallery object (will be eq to $resource in a gallery view + * + * @var Ansel_Gallery + */ + var $gallery; + + /** + * Collection of Ansel_Widgets to display in this view. + * + * @var array + */ + var $_widgets = array(); + + 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)) { + return PEAR::raiseError(_("No gallery specified")); + } + + // If we have a slug, use it. + if (!empty($slug)) { + $gallery = &$GLOBALS['ansel_storage']->getGalleryBySlug($slug); + } else { + $gallery = &$GLOBALS['ansel_storage']->getGallery($galleryId); + } + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { + return PEAR::raiseError(sprintf(_("Access denied to gallery \"%s\"."), $gallery->get('name'))); + } + + /* 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; + } + + /** + * Add an Ansel_Widget to be displayed in this view. + * + * @param Ansel_Widget $widget The Ansel_Widget to display + */ + function addWidget($widget) + { + $result = $widget->attach($this); + if (!empty($result)) { + $this->_widgets[] = $widget; + } + } + + + /** + * Output any widgets associated with this view. + * + */ + function renderWidgets() + { + $this->_renderWidgets(); + } + + /** + * Count the number of widgets we have attached. + * + * @return integer The number of widgets attached to this view. + */ + function countWidgets() + { + return count($this->_widgets); + } + + /** + * Default widget rendering, can be overridden by any subclass. + * + */ + function _renderWidgets() + { + echo '
'; + foreach ($this->_widgets as $widget) { + if ($widget->autoRender) { + echo $widget->html(); + echo '
'; + } + } + echo '
'; + } + + /** + * JSON representation of this gallery's images. + * + * @param array $images An array of Ansel_Image objects. If this is null + * the images are fetched based on $from and $count. + * + * @param integer $from Image to start at. + * @param integer $count Number of images to get. + * + * @return string A serialized JSON array. + */ + function json($images = null, $full = false, $from = 0, $count = 0, + $image_view = 'screen', $view_links = false) + { + global $conf, $prefs; + + $json = array(); + $perpage = $prefs->getValue('tilesperpage', $conf['thumbnail']['perpage']); + $curimage = 0; + $curpage = 0; + + if (is_null($images)) { + $images = $this->gallery->getImages($from, $count); + } + + $style = $this->gallery->getStyle(); + + foreach ($images as $image) { + // Calculate the page this image will appear on in the + // gallery view. + if (++$curimage > $perpage) { + ++$curpage; + $curimage = 0; + } + + $data = array(Ansel::getImageUrl($image->id, $image_view, $full, $style['name']), + htmlspecialchars($image->filename, ENT_COMPAT, Horde_Nls::getCharset()), + Horde_Text_Filter::filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), + $image->id, + $curpage); + if ($view_links) { + $data[] = Ansel::getUrlFor('view', + array('gallery' => $this->gallery->id, + 'slug' => $this->gallery->get('slug'), + 'image' => $image->id, + 'view' => 'Image'), + true); + $data[] = Ansel::getUrlFor('view', + array('gallery' => $image->gallery, + 'slug' => $this->gallery->get('slug'), + 'view' => 'Gallery'), + true); + } + // Source, Width, Height, Name, Caption, Image Id, Gallery Page + $json[] = $data; + } + + return Horde_Serialize::serialize($json, Horde_Serialize::JSON, Horde_Nls::getCharset()); + } + + /** + * @abstract + * @return unknown_type + */ + function viewType() + { + } + +} diff --git a/ansel/lib/View/Embedded.php b/ansel/lib/View/Embedded.php new file mode 100644 index 000000000..7d303df71 --- /dev/null +++ b/ansel/lib/View/Embedded.php @@ -0,0 +1,87 @@ + tags that + * will embed the view. Provided as a way to output these views via the + * renderViews api call. The actual rendering is done via the + * EmbeddedRenderers/*.php files which are called from the Ajax_Imple_Embed + * class when it handles the request. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael J. Rubinsky + * @package Ansel + */ +class Ansel_View_Embedded { + + /** + * Initialize the view + * + * This view can take the following parameters: + * + * container The DOM id of the element to contain the embedded view. + * This parameter is required. + * + * gallery_id The gallery id + * + * gallery_slug The gallery slug + * + * gallery_view The specific view to embed this must match an existing + * EmbeddedRenderer (Mini, Slideshow, Carousel etc..) + * Defaults to 'Mini' + * + * start Start displaying at this image offset. Defaults to the start + * of the gallery. + * + * count Only return this many images. Defaults to returning the + * entire gallery (minus any subgalleries). + * + * perpage Some embedded views support paging. This sets the number of + * images per page. Note that all images are still returned. + * The paging is done via javascript only. + * + * images An array of image ids, not necessarily from the same + * gallery, to be displayed in this view. The gallery parameter + * will be ignored if present. + * + * thumbsize Which type of thumbnail images to display in the view. + * (mini, thumb, prettythumb etc...) Defaults to mini. + * @static + * @param array $params Parameters for this view + */ + function makeView($params) + { + global $ansel_storage; + + $view = new Ansel_View_Embedded(); + $view->_params = $params; + return $view; + } + + /** + * Return the HTML representing this view. + * + * @return string The HTML. + * + */ + function html() + { + /* Are we displaying a gallery or a group of images? */ + if (!empty($this->_params['images']) && count($this->_params['images'])) { + $this->_params['images'] = implode(':', $this->_params['images']); + } + + $html = Ansel::embedCode($this->_params); + + return $html; + } + + function viewType() + { + return 'Embedded'; + } + +} diff --git a/ansel/lib/View/EmbeddedRenderers/Carousel.php b/ansel/lib/View/EmbeddedRenderers/Carousel.php new file mode 100644 index 000000000..730ff52a0 --- /dev/null +++ b/ansel/lib/View/EmbeddedRenderers/Carousel.php @@ -0,0 +1,46 @@ + + * @package Ansel + */ +class Ansel_View_EmbeddedRenderer_Carousel extends Ansel_View_Gallery { + + /** + * Create a new renderer. + * + * @see Ansel_View_Embedded + * + * @param array $params + * + * @return Ansel_View_EmbeddedRenderer The renderer object. + */ + function makeView($params = array()) + { + $view = new Ansel_View_EmbeddedRenderer_Carousel(); + $view->_params = $params; + + return $view; + } + + /** + * Build the javascript that will render the view. + * + * @return string A string containing valid javascript. + */ + function html() + { + + } + +} diff --git a/ansel/lib/View/EmbeddedRenderers/GalleryLink.php b/ansel/lib/View/EmbeddedRenderers/GalleryLink.php new file mode 100644 index 000000000..34799fcd2 --- /dev/null +++ b/ansel/lib/View/EmbeddedRenderers/GalleryLink.php @@ -0,0 +1,150 @@ + + * + * + *
+ * + * + * + * @author Michael J. Rubinsky + * @package Ansel + */ +class Ansel_View_EmbeddedRenderer_GalleryLink extends Ansel_View_Gallery { + + /** + * Create a new renderer. + * + * @see Ansel_View_Embedded + * + * @param array $params + * + * @return Ansel_View_EmbeddedRenderer The renderer object. + */ + function makeView($params = array()) + { + $view = new Ansel_View_EmbeddedRenderer_GalleryLink(); + $view->_params = $params; + + return $view; + } + + /** + * Build the javascript that will render the view. + * + * @return string A string containing valid javascript. + */ + function html() + { + /* Read in parameters and set defaults */ + + /* Required */ + $node = $this->_params['container']; + if (empty($node)) { + return ''; + } + + /* Need at least one of these */ + $galleries = !empty($this->_params['gallery_slug']) ? explode(':', $this->_params['gallery_slug']) : ''; + $haveSlugs = true; + if (empty($galleries)) { + $galleries = !empty($this->_params['gallery_id']) ? explode(':', $this->_params['gallery_id']) : null; + $haveSlugs = false; + } + + /* Determine the style/thumnailsize etc... */ + $thumbsize = empty($this->_params['thumbsize']) ? + 'thumb' : + $this->_params['thumbsize']; + + foreach ($galleries as $identifier) { + if ($haveSlugs) { + $gallery = $this->getGallery(null, $identifier); + } else { + $gallery = $this->getGallery($identifier); + } + if (is_a($gallery, 'PEAR_Error')) { + Horde::logMessage($gallery, __FILE__, __LINE__, PEAR_LOG_ERR); + exit; + } + if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { + return ''; + } + + /*If a gallery_style is not specified, default to the gallery's + * defined style. Note that this only matters if the $thumbsize + * parameter is set to 'prettythumb' anyway. + */ + $gallery_style = empty($this->_params['style']) ? + $gallery->get('style') : + $this->_params['style']; + + /* Ideally, since gallery default images are unique in that each style + * needs it's own unique image_id, the thumbsize and style parameters + * are mutually exclusive - specifying a specific gallery style is only + * needed if requesting the prettythumb thumbsize value. Make sure that + * both were not passed in. + */ + if ($thumbsize == 'thumb') { + $images[] = $gallery->getDefaultImage('ansel_default'); + } else { + $images[] = $gallery->getDefaultImage($gallery_style); + } + } + $json = $GLOBALS['ansel_storage']->getImageJson($images, null, true, $thumbsize, true); + + /* Some paths */ + $cssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'ansel') . '/jsembed.css', true); + $js_path = $GLOBALS['registry']->get('jsuri', 'horde'); + $pturl = Horde::url($js_path . '/prototype.js', true); + $ansel_js_path = $GLOBALS['registry']->get('jsuri', 'ansel'); + $jsurl = Horde::url($ansel_js_path . '/embed.js', true); + + /* Start building the javascript - we use the same parameters as with + * the mini gallery view so we can use the same javascript to display it + */ + $html = <<'); + } + anselnodes = new Array(); + anseljson = new Object(); + document.write(''); + document.write(''); + } + anselnodes[anselnodes.length] = '$node'; + anseljson['$node'] = new Object(); + anseljson['$node']['data'] = $json; + anseljson['$node']['perpage'] = 0; + anseljson['$node']['page'] = 0; + anseljson['$node']['hideLinks'] = false; + anseljson['$node']['linkToGallery'] = true; + //]]> +EOT; + + return $html; + } + +} diff --git a/ansel/lib/View/EmbeddedRenderers/Mini.php b/ansel/lib/View/EmbeddedRenderers/Mini.php new file mode 100644 index 000000000..2abaf4064 --- /dev/null +++ b/ansel/lib/View/EmbeddedRenderers/Mini.php @@ -0,0 +1,181 @@ + + * @package Ansel + */ +class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery { + + /** + * Create a new renderer. + * + * @see Ansel_View_Embedded + * + * @param array $params + * + * @return Ansel_View_EmbeddedRenderer The renderer object. + */ + function makeView($params = array()) + { + $view = new Ansel_View_EmbeddedRenderer_Mini(); + $view->_params = $params; + + return $view; + } + + /** + * Build the javascript that will render the view. + * + * @return string A string containing valid javascript. + */ + function html() + { + /* Read in parameters and set defaults */ + + /* Required */ + $node = $this->_params['container']; + if (empty($node)) { + return ''; + } + + /* Optional */ + $gallery_slug = !empty($this->_params['gallery_slug']) ? $this->_params['gallery_slug'] : ''; + $gallery_id = !empty($this->_params['gallery_id']) ? $this->_params['gallery_id']: null; + + $start = (isset($this->_params['start'])) ? $this->_params['start'] : 0; + $count = (isset($this->_params['count'])) ? $this->_params['count'] : 0; + $perpage = (isset($this->_params['perpage'])) ? $this->_params['perpage'] : 0; + $thumbsize = (!empty($this->_params['thumbsize'])) ? $this->_params['thumbsize'] : 'mini'; + // Limit to these image views only. + if ($thumbsize != 'mini' && $thumbsize != 'thumb' && + $thumbsize != 'prettythumb' && $thumbsize != 'screen') { + + $thumbsize = 'mini'; + } + + /* An image list instead of a gallery? */ + $images = (!empty($this->_params['images'])) ? $this->_params['images'] : array(); + if (!empty($images)) { + // Images are filtered for age and password protected galleries + // in the ::getImageJson() call since they could all be from different + // galleries. + $images = explode(':', $images); + } else { + $this->gallery = $this->getGallery($gallery_id, $gallery_slug); + if (is_a($this->gallery, 'PEAR_Error')) { + Horde::logMessage($this->gallery, __FILE__, __LINE__, PEAR_LOG_ERR); + exit; + } + + // We don't allow age restricted or password locked galleries to be + // viewed via the mini embedded view since it shows *all* the images + if (!$this->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ) || + !$this->gallery->isOldEnough() || + $this->gallery->hasPasswd()) { + + return ''; + } + } + + if (empty($images)) { + $json = $this->json(null, true, $start, $count, $thumbsize, true); + $json_full = $this->json(null, true, $start, $count, 'screen', true); + } else { + $json = $GLOBALS['ansel_storage']->getImageJson($images, null, true, $thumbsize, true); + $json_full = $GLOBALS['ansel_storage']->getImageJson($images, null, true, 'screen', true); + } + + /* Some paths */ + $cssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'ansel') . '/embed.css', true); + $hcssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'horde') . '/embed.css', true); + $js_path = $GLOBALS['registry']->get('jsuri', 'horde'); + $pturl = Horde::url($js_path . '/prototype.js', true); + $hjsurl = Horde::url($js_path . '/tooltips.js', true); + $ansel_js_path = $GLOBALS['registry']->get('jsuri', 'ansel'); + $jsurl = Horde::url($ansel_js_path . '/embed.js', true); + $hideLinks = (bool)!empty($this->_params['hidelinks']); + + /* Lightbox specific URLs */ + if (!empty($this->_params['lightbox'])) { + $effectsurl = Horde::url($js_path . '/effects.js', true); + $lbjsurl = Horde::url($ansel_js_path . '/lightbox.js', true); + $lbcssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'ansel') . '/lightbox.css', true); + } + + /* Start building the javascript */ + $html = <<'); + } + if (typeof Horde_ToolTips == 'undefined') { + document.write(''); + document.write(''); + } + + anselnodes = new Array(); + anseljson = new Object(); + document.write(''); + document.write(''); + } + anselnodes[anselnodes.length] = '$node'; + anseljson['$node'] = new Object(); + anseljson['$node']['data'] = $json; + anseljson['$node']['perpage'] = $perpage; + anseljson['$node']['page'] = 0; + anseljson['$node']['hideLinks'] = '$hideLinks'; + //]]> + +EOT; + /* Special requirements for lightbox */ + if (!empty($lbjsurl)) { + $graphic_dir = Horde::applicationUrl($GLOBALS['registry']->getImageDir(), true, -1); + $imageText = _("Photo"); + $labelOf = _("of"); + $html .= <<'); + } + + /* Make sure we only include this stuff once */ + if (typeof lbOptions == 'undefined') { + + document.write(''); + document.write(''); + + lbOptions = { + fileLoadingImage: '$graphic_dir/lightbox/loading.gif', + fileBottomNavCloseImage: '$graphic_dir/lightbox/closelabel.gif', + overlayOpacity: 0.8, + animate: true, + resizeSpeed: 7, + borderSize: 10, + labelImage: '$imageText', + labelOf: '$labelOf', + returnURL: '#', + startPage: 0 + } + } + anseljson['$node']['lightbox'] = $json_full; +EOT; + } + return $html; + } + +} diff --git a/ansel/lib/View/EmbeddedRenderers/Slideshow.php b/ansel/lib/View/EmbeddedRenderers/Slideshow.php new file mode 100644 index 000000000..9a624fed2 --- /dev/null +++ b/ansel/lib/View/EmbeddedRenderers/Slideshow.php @@ -0,0 +1,46 @@ + + * @package Ansel + */ +class Ansel_View_EmbeddedRenderer_Slideshow extends Ansel_View_Gallery { + + /** + * Create a new renderer. + * + * @see Ansel_View_Embedded + * + * @param array $params + * + * @return Ansel_View_EmbeddedRenderer The renderer object. + */ + function makeView($params = array()) + { + $view = new Ansel_View_EmbeddedRenderer_Carousel(); + $view->_params = $params; + + return $view; + } + + /** + * Build the javascript that will render the view. + * + * @return string A string containing valid javascript. + */ + function html() + { + + } + +} diff --git a/ansel/lib/View/Gallery.php b/ansel/lib/View/Gallery.php new file mode 100644 index 000000000..a08559e63 --- /dev/null +++ b/ansel/lib/View/Gallery.php @@ -0,0 +1,202 @@ + + * @package Ansel + */ +class Ansel_View_Gallery extends Ansel_View_Abstract { + + /** Holds the object that does the actual rendering **/ + var $_renderer; + + /** + * @static + * + * @param array $params Any parameters that the view might need. + *
+     * gallery_id              The gallery id this view is for. If omitted, it
+     *                         looks for a query parameter called 'gallery'
+     *
+     * gallery_slug            Same as above, but a slug
+     *
+     * gallery_view_url        If set, this is used as the link to a gallery
+     *                         view. %g is replaced by the gallery_id and %s is
+     *                         replaced by the gallery_slug.
+     *
+     * gallery_view            The specific Renderer to use, if needed.
+     *                         (GalleryLightbox, Gallery etc...).
+     *
+     * image_view_url          If this is set, the image tiles will use this url
+     *                         for the image view link. %i and %g will be
+     *                         replaced by image_id and gallery_id respectively.
+     *                         %s will be replaced by the gallery_slug
+     *
+     * image_view_src          If this is set to true, the image view link will go
+     *                         directly to the actual image. This overrides any
+     *                         setting of image_view_url.
+     *
+     * image_view_attributes   An optional array of attribute => value pairs
+     *                         that are used as attributes of the image view
+     *                         link.
+     *
+     * image_view_title        Specifies which property of the image object
+     *                         to use as the image caption.
+     *
+     * image_onclick           Specifies a onclick handler for the image tile
+     *                         links.
+     *
+     * style                   Force the use of this named style.
+     *
+     * api                     If set, we are being called from the external api
+     *
+     * page                    The gallery page number to display if not the
+     *                         default value of the first page (page = 0)
+     *
+     * day, month, year        Numeric date part values to describe the gallery
+     *                         date grouping to view in date mode.
+     *
+     * force_date_grouping     Do not auto navigate to the first date grouping
+     *                         with more then one resource. Used from the api
+     *                         when clicking on breadcrumb links, for example.
+     * 
+ * + * @TODO use exceptions from the constructor instead of static + * instance-getting. + */ + function makeView($params = array()) + { + $view = new Ansel_View_Gallery(); + + if (count($params)) { + $view->_params = $params; + } + + if (!empty($params['gallery_slug'])) { + $view->gallery = $view->getGallery(null, $params['gallery_slug']); + } elseif (!empty($params['gallery_id'])) { + $view->gallery = $view->getGallery($params['gallery_id']); + } else { + $view->gallery = $view->getGallery(); + } + + if (is_a($view->gallery, 'PEAR_Error')) { + return $view->gallery; + } + + // Check user age + if (!$view->gallery->isOldEnough()) { + if (!empty($params['api'])) { + return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); + } + $date = Ansel::getDateParameter( + array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, + 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, + 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); + + $galleryurl = Ansel::getUrlFor('view', array_merge( + array('gallery' => $view->gallery->id, + 'slug' => empty($params['slug']) ? '' : $params['slug'], + 'page' => empty($params['page']) ? 0 : $params['page'], + 'view' => 'Gallery'), + $date), + true); + + $params = array('gallery' => $view->gallery->id, 'url' => $galleryurl); + header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('disclamer.php'), $params, null, false)); + exit; + } + + if ($view->gallery->hasPasswd()) { + if (!empty($params['api'])) { + return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); + } + $date = Ansel::getDateParameter( + array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, + 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, + 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); + + $galleryurl = Ansel::getUrlFor('view', array_merge( + array('gallery' => $view->gallery->id, + 'slug' => empty($params['slug']) ? '' : $params['slug'], + 'page' => empty($params['page']) ? 0 : $params['page'], + 'view' => 'Gallery'), + $date), + true); + + $params = array('gallery' => $view->gallery->id, 'url' => $galleryurl); + header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('protect.php'), $params, null, false)); + exit; + } + + if (!$view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { + return PEAR::raiseError(_("Access denied viewing this gallery.")); + } + + // Since this is a gallery view, the resource is just a reference to the + // gallery. We keep both instance variables becuase both gallery and + // image views are assumed to have a gallery object. + $view->resource = &$view->gallery; + + /* Do we have an explicit style set? If not, use the gallery's */ + if (!empty($view->_params['style'])) { + $style = Ansel::getStyleDefinition($view->_params['style']); + } else { + $style = $view->gallery->getStyle(); + } + + if (!empty($view->_params['gallery_view'])) { + $renderer = $view->_params['gallery_view']; + } else { + $renderer = (!empty($style['gallery_view'])) ? $style['gallery_view'] : 'Gallery'; + } + /* Load the helper */ + $classname = 'Ansel_View_GalleryRenderer_' . basename($renderer); + $view->_renderer = new $classname($view); + $view->_renderer->init(); + + return $view; + } + + function getGalleryCrumbData() + { + return $this->gallery->getGalleryCrumbData(); + } + + /** + * Get this gallery's title. + * + * @return string The gallery's title. + */ + function getTitle() + { + if (is_a($this->gallery, 'PEAR_Error')) { + return $this->gallery->getMessage(); + } + return $this->gallery->get('name'); + } + + /** + * Return the HTML representing this view. + * + * @return string The HTML. + * + */ + function html() + { + return $this->_renderer->html(); + } + + function viewType() + { + return 'Gallery'; + } + +} diff --git a/ansel/lib/View/GalleryRenderer.php b/ansel/lib/View/GalleryRenderer.php new file mode 100644 index 000000000..3056fd4fa --- /dev/null +++ b/ansel/lib/View/GalleryRenderer.php @@ -0,0 +1,219 @@ + + * @package Ansel + */ +class Ansel_View_GalleryRenderer { + + /** + * The Ansel_View_Gallery object that this Renderer belongs to. + * + * @var Ansel_View_Gallery + */ + var $view; + + /** + * The gallery id for this view's gallery + * + * @var integer + */ + var $galleryId; + + /** + * Gallery slug for current gallery. + * + * @var string + */ + var $gallerySlug; + + /** + * The current page we are viewing + * + * @var integer + */ + var $page = 0; + + /** + * The display mode of the current gallery. + * 0 == Normal + * 1 == Group by date + * + * @var integer + */ + var $mode; + + /** + * The style definition array for this gallery. + * + * @var array + */ + var $style; + + /** + * Holds number of tiles to display per page + * + * @var integer + */ + var $perpage; + + /** + * The tile number we are starting with on the current page. + * + * @var integer + */ + var $pagestart; + + /** + * The last tile number on the current page. + * + * @var integer + */ + var $pageend; + + /** + * The total number of tiles that this view contains + * + * @var integer + */ + var $numTiles; + + /** + * The Ansel_Image or Ansel_DateGallery objects that appear on the current + * page in the current view. + * + * @var array of Ansel_Image or Ansel_DateGallery objects. + */ + var $children; + + /** + * If we are grouping by date, this holds the currently selected date parts. + * + * @var array containing sufficient date parts for the current depth. + */ + var $date = array(); + + /** + * Constructor + * + * @param Ansel_View_Gallery The view object for this renderer. + * + * @return Ansel_View_Renderer_Gallery + */ + function Ansel_View_GalleryRenderer($view) + { + $this->view = $view; + } + + /** + * Initialize the renderer. This *must* be called before any attempt is made + * to display or otherwise interact with the renderer. + * + */ + function init() + { + global $prefs, $conf; + + $this->galleryId = $this->view->gallery->id; + $this->gallerySlug = $this->view->gallery->get('slug'); + if (isset($this->view->_params['page'])) { + $this->page = $this->view->_params['page']; + } + + /* Number perpage from prefs or config */ + $this->perpage = min($prefs->getValue('tilesperpage'), + $conf['thumbnail']['perpage']); + + /* Calculate the starting and ending images on this page */ + $this->pagestart = ($this->page * $this->perpage) + 1; + + /* Fetch the children */ + $this->fetchChildren($this->view->_params['force_grouping']); + + /* Do we have an explicit style set? If not, use the gallery's */ + if (!empty($this->view->_params['style'])) { + $this->style = Ansel::getStyleDefinition($this->view->_params['style']); + } else { + $this->style = $this->view->gallery->getStyle(); + } + + /* Include any widgets */ + if (!empty($this->style['widgets'])) { + /* Special case widgets - these are built in */ + if (array_key_exists('Actions', $this->style['widgets'])) { + /* Don't show action widget if no actions */ + if (Horde_Auth::getAuth() || + !empty($conf['report_content']['driver']) && + (($conf['report_content']['allow'] == 'authenticated' && Horde_Auth::isAuthenticated()) || + $conf['report_content']['allow'] == 'all')) { + + $this->view->addWidget(Ansel_Widget::factory('Actions')); + } + unset($this->style['widgets']['Actions']); + } + + // I *think* this is more efficient, iterate over the children + // since we already have them instead of calling listImages. + //$image_ids = $this->view->gallery->listImages($this->pagestart, $this->pagestart + $this->perpage); + $ids = array(); + foreach ($this->children as $child) { + if (is_a($child, 'Ansel_Image')) { + $ids[] = $child->id; + } + } + // Gallery widgets always receive an array of image ids for + // the current page. + foreach ($this->style['widgets'] as $wname => $wparams) { + $wparams = array_merge($wparams, array('images' => $ids)); + $this->view->addWidget(Ansel_Widget::factory($wname, $wparams)); + } + } + + /* See if any renderer specific tasks need to be done as well */ + $this->_init(); + } + + /** + * Default implementation for fetching children/images for this view. + * Other view classes can override this if they need anything special. + * + */ + function fetchChildren($noauto) + { + /* Total number of tiles for this gallery view */ + $this->numTiles = $this->view->gallery->countGalleryChildren(PERMS_SHOW, false, $noauto); + + /* Children to display on this page */ + $this->children = $this->view->gallery->getGalleryChildren( + PERMS_SHOW, + $this->page * $this->perpage, + $this->perpage, + !empty($this->view->_params['force_grouping'])); + + /* The last tile number to display on the current page */ + $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1); + } + + /** + * Return the HTML for this view. Done this way so we can override this in + * subclasses if desired. + * + * @return string + */ + function html() + { + if (is_a($this->view->gallery, 'PEAR_Error')) { + echo htmlspecialchars($this->view->gallery->getMessage(), ENT_COMPAT, Horde_Nls::getCharset()); + return; + } + + return $this->_html(); + } + +} diff --git a/ansel/lib/View/GalleryRenderers/Gallery.php b/ansel/lib/View/GalleryRenderers/Gallery.php new file mode 100644 index 000000000..af87d8206 --- /dev/null +++ b/ansel/lib/View/GalleryRenderers/Gallery.php @@ -0,0 +1,131 @@ + + * @package Ansel + */ +require_once ANSEL_BASE . '/lib/Views/GalleryRenderer.php'; + +class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer { + + /** + * Perform any tasks that should be performed before the view is rendered. + * + */ + function _init() + { + } + + /** + * Return the HTML representing this view. + * + * @return string The HTML. + * + */ + function _html() + { + global $conf, $prefs, $registry; + + $galleryOwner = $this->view->gallery->get('owner'); + $id = $this->view->gallery->getOwner(); + $owner = $id->getValue('fullname'); + if (!$owner) { + $owner = $galleryOwner; + } + + /* Only need these if not being called via the api */ + if (empty($this->view->_params['api'])) { + $option_edit = $this->view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT); + $option_select = $option_delete = $this->view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE); + $option_move = ($option_delete && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); + $option_copy = ($option_edit && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); + /* See if we requested a show_actions change */ + if (Horde_Util::getFormData('actionID', '') == 'show_actions') { + $prefs->setValue('show_actions', (int)!$prefs->getValue('show_actions')); + } + } + + /* Set up the pager */ + $date_params = Ansel::getDateParameter( + array('year' => isset($this->view->_params['year']) ? $this->view->_params['year'] : 0, + 'month' => isset($this->view->_params['month']) ? $this->view->_params['month'] : 0, + 'day' => isset($this->view->_params['day']) ? $this->view->_params['day'] : 0)); + + $vars = Horde_Variables::getDefaultVariables(); + if (!empty($this->view->_params['page'])) { + $vars->add('page', $this->view->_params['page']); + } + if (!empty($this->view->_params['gallery_view_url'])) { + $pagerurl = str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->_params['gallery_view_url'])); + $pagerurl = Horde_Util::addParameter($pagerurl, $date_params); + } 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); + } + + /* See what callback to use to tweak the pager urls */ + if (!empty($this->view->_params['urlCallback'])) { + $callback = $this->view->_params['urlCallback']; + } else { + $callback = null; + } + $params = array('num' => $this->numTiles, + 'url' => $pagerurl, + 'perpage' => $this->perpage, + 'url_callback' => $callback); + + $pager = new Horde_UI_Pager('page', $vars, $params); + + // Note that we can't use Horde_Util::bufferOutput() here since the include + // file would be included inside that method's scope, and not this one. + ob_start(); + if (!empty($this->view->_params['api'])) { + $includes = new Horde_Script_Files(); + $includes->disableAutoloadHordeJS(); + $includes->_add('prototype.js', 'horde', true, true); + $includes->includeFiles(); + } + + /* Needed in the template files */ + $tilesperrow = $prefs->getValue('tilesperrow'); + $cellwidth = round(100 / $tilesperrow); + $count = 0; + $action_links = array(); + if ($GLOBALS['conf']['gallery']['downloadzip']) { + $action_links[] = Horde::link('#', '', 'widget', '', 'downloadSelected(); return false;') . _("Download selected images") . ''; + + } + if (!empty($option_edit)) { + $action_links[] = Horde::link('#', '', 'widget', '', 'editDates(); return false;') . _("Edit Dates") . ''; + } + if (!empty($option_delete)) { + $action_links[] = Horde::link('#', '', 'widget', '', 'deleteSelected(); return false;') . _("Delete") . ''; + } + if (!empty($option_move)) { + $action_links[] = Horde::link('#', '', 'widget', '', 'moveSelected(); return false;') . _("Move") . ''; + } + if (!empty($option_copy)) { + $action_links[] = Horde::link('#', '', 'widget', '', 'copySelected(); return false;') . _("Copy") . ''; + } + + include ANSEL_TEMPLATES . '/view/gallery.inc'; + return ob_get_clean(); + } + +} diff --git a/ansel/lib/View/GalleryRenderers/GalleryLightbox.php b/ansel/lib/View/GalleryRenderers/GalleryLightbox.php new file mode 100644 index 000000000..3e8e8559a --- /dev/null +++ b/ansel/lib/View/GalleryRenderers/GalleryLightbox.php @@ -0,0 +1,156 @@ + + * @package Ansel + */ + +require_once ANSEL_BASE . '/lib/Views/GalleryRenderer.php'; + +class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRenderer { + + /** + * Perform any tasks that should be performed before the view is rendered. + * + */ + function _init() + { + if (empty($this->view->_params['image_onclick'])) { + $this->view->_params['image_onclick'] = 'return lb.start(%i);'; + } + + // Attach the script and CSS files here if we aren't being called via the api + if (empty($this->view->_params['api'])) { + Ansel::attachStylesheet('lightbox.css'); + Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('lightbox.js', 'ansel', true); + } + } + + /** + * Get the HTML representing this view. + * + * @return string The HTML + */ + function _html() + { + global $conf, $prefs, $registry; + + $galleryOwner = $this->view->gallery->get('owner'); + $id = $this->view->gallery->getOwner(); + $owner = $id->getValue('fullname'); + if (!$owner) { + $owner = $galleryOwner; + } + + /* Get JSON data for view */ + // 0 == normal, 1 == by date + if ($this->mode == 0) { + $json = $this->view->json(null, !empty($this->view->_params['api'])); + } else { + if (!empty($this->date['day']) && $this->numTiles) { + $json = $this->view->json(null, !empty($this->view->_params['api'])); + } else { + $json = '[]'; + } + } + + /* Don't bother if we are being called from the api */ + if (empty($this->view->_params['api'])) { + $option_edit = $this->view->gallery->hasPermission(Horde_Auth::getAuth(), + PERMS_EDIT); + $option_select = $option_delete = $this->view->gallery->hasPermission( + Horde_Auth::getAuth(), PERMS_DELETE); + $option_move = ($option_delete && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); + $option_copy = ($option_edit && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); + /* See if we requested a show_actions change (fallback for non-js) */ + if (Horde_Util::getFormData('actionID', '') == 'show_actions') { + $prefs->setValue('show_actions', (int)!$prefs->getValue('show_actions')); + } + } + + /* Set up the pager */ + $date_params = Ansel::getDateParameter( + array('year' => isset($this->view->_params['year']) ? $this->view->_params['year'] : 0, + 'month' => isset($this->view->_params['month']) ? $this->view->_params['month'] : 0, + 'day' => isset($this->view->_params['day']) ? $this->view->_params['day'] : 0)); + + $vars = Horde_Variables::getDefaultVariables(); + if (!empty($this->view->_params['page'])) { + $vars->add('page', $this->view->_params['page']); + $page = $this->view->_params['page']; + } else { + $page = 0; + } + if (!empty($this->view->_params['gallery_view_url'])) { + $pagerurl = str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->_params['gallery_view_url'])); + $pagerurl = Horde_Util::addParameter($pagerurl, $date_params, null, false); + } 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); + } + + if (!empty($this->view->_params['urlCallback'])) { + $callback = $this->view->_params['urlCallback']; + } else { + $callback = null; + } + $params = array('num' => $this->numTiles, + 'url' => $pagerurl, + 'perpage' => $this->perpage, + 'url_callback' => $callback); + + $pager = new Horde_UI_Pager('page', $vars, $params); + + /* Start buffering */ + ob_start(); + + /* Create the js variables to pass to the lightbox script */ + $jsvars = array('graphics_dir' => Horde::applicationUrl($registry->getImageDir(), true, -1), + 'image_text' => _("Photo"), + 'of_text' => _("of"), + 'start_page' => $page); + + $flipped = array_flip($date_params); + if (count($flipped) == 1 && !empty($flipped[0])) { + $jsvars['gallery_url'] = $pagerurl . '?'; + } else { + $jsvars['gallery_url'] = $pagerurl . '&'; + } + /* Output js/css here if we are calling via the api */ + if (!empty($this->view->_params['api'])) { + Ansel::attachStylesheet('lightbox.css', true); + $includes = new Horde_Script_Files(); + $includes->disableAutoloadHordeJS(); + $includes->_add('accesskeys.js', 'horde', true, true); + $includes->_add('effects.js', 'horde', true, true); + $includes->_add('lightbox.js', 'ansel', true, true); + $includes->includeFiles(); + } + + /* Needed in the template files */ + $tilesperrow = $prefs->getValue('tilesperrow'); + $cellwidth = round(100 / $tilesperrow); + $count = 0; + + include ANSEL_TEMPLATES . '/view/gallerylightbox.inc'; + return ob_get_clean(); + } + +} diff --git a/ansel/lib/View/GalleryRenderers/GalleryVimeo.php b/ansel/lib/View/GalleryRenderers/GalleryVimeo.php new file mode 100644 index 000000000..db0602449 --- /dev/null +++ b/ansel/lib/View/GalleryRenderers/GalleryVimeo.php @@ -0,0 +1,192 @@ + + * @package Ansel + */ +require_once ANSEL_BASE . '/lib/Views/GalleryRenderer.php'; + +class Ansel_View_GalleryRenderer_GalleryVimeo extends Ansel_View_GalleryRenderer { + /** + * + * @var Horde_Service_Vimeo object + */ + var $_vimeo; + var $_thumbs; + + /** + * Perform any tasks that should be performed before the view is rendered. + * + */ + function _init() + { + // Attach the script and CSS files here if we aren't being called via the api + if (empty($this->view->_params['api'])) { + Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('redbox.js', 'horde', true); + } + } + + /** + * Override the parent class' fetchChildren method so we can grab the video + * thumbnail information from Vimeo instead of from our local image storage. + * + * @param boolean $noauto Ignored in this class since we won't be doing any + * date browsing. Maybe another experiment? ;) + */ + function fetchChildren($noauto = true) + { + // Build a Horde_Service_Vimeo object + // It *requires* a http client object and can make use of a cache object, + // so let's take advantage of it. + $params = array('http_client' => new Horde_Http_Client(), + 'cache' => $GLOBALS['cache'], + 'cache_lifetime' => $GLOBALS['conf']['cache']['default_lifetime']); + + $this->_vimeo = Horde_Service_Vimeo::factory('Simple', $params); + + // The identifier for what we are requesting. + // If we are requesting a user's videos, this is the user's vimeo_id + // if we want to request a particular group, this would be the group_id + // etc... + // + // For this example, the id is hard coded here, but if I were to implement + // this on a live site I would add a new user pref to ansel for the + // user to enter his/her own vimeo_id and then grab the value from + // pref storage here. + $vimeo_id = 'user1015172'; //TODO: Get this from prefs? + + // This gets the data representing the videos. See the API docs for + // exactly what is returned, but for our purposes, we will be using: + // clip_id, url, caption, thumbnail_large etc... + $thumbs = unserialize($this->_vimeo->user($vimeo_id)->clips()->run()); + + // We fetch the information needed to embed each video now to make things + // easier for this example...the cache helps tremendously with load times + // after the first page is requested. + foreach ($thumbs as $thumb) { + $this->_json[$thumb['clip_id']] = $this->_vimeo->getEmbedJSON(array('url' => $thumb['url'], 'byline' => 'false', 'portrait' => 'false')); + $this->_thumbs[$thumb['clip_id']] = $thumb; + } + + // Vimeo's Simple API doesn't provide for paging - so we emulate it + // by only returning the video thumbnails that should appear on this + // current gallery page. Like stated above, the first load will take + // a bit of time depending on the number of videos the user has - but + // each subsequent page will load *much* faster as we don't have to + // contact Vimeo at all. + + // Total number of thumbnails in the gallery + $this->numTiles = count($thumbs); + + // The last one to display on this page + $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1); + + + $this->children = $this->view->gallery->getGalleryChildren( + PERMS_SHOW, + $this->page * $this->perpage, + $this->perpage, + !empty($this->view->_params['force_grouping'])); + } + + /** + * Get the HTML representing this view. + * + * Responsible for building the HTML for the view. It's stripped down + * somewhat from the other styles...sets up the variables needed for the + * template we put in ansel/templates/view - though there is really no + * reason we *have* to have a template file there if we can generate the + * entire HTML here, or load a template from this directory or....? + * + * @return string The HTML + */ + function _html() + { + global $conf, $prefs, $registry; + + // Deal with getting the correct gallery owner string, get any + // parameters we are interested in from the view + $galleryOwner = $this->view->gallery->get('owner'); + $id = $this->view->gallery->getOwner(); + $owner = $id->getValue('fullname'); + if (!$owner) { + $owner = $galleryOwner; + } + $vars = Horde_Variables::getDefaultVariables(); + if (!empty($this->view->_params['page'])) { + $vars->add('page', $this->view->_params['page']); + $page = $this->view->_params['page']; + } else { + $page = 0; + } + + // Build the proper pager urls + if (!empty($this->view->_params['gallery_view_url'])) { + $pagerurl = str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->_params['gallery_view_url'])); + } 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('gallery' => $this->galleryId, + 'view' => 'Gallery', + 'slug' => $this->view->gallery->get('slug')); + $pagerurl = Ansel::getUrlfor('view', $pager_params, true); + } + if (!empty($this->view->_params['urlCallback'])) { + $callback = $this->view->_params['urlCallback']; + } else { + $callback = null; + } + $params = array('num' => $this->numTiles, + 'url' => $pagerurl, + 'perpage' => $this->perpage, + 'url_callback' => $callback); + + $pager = new Horde_UI_Pager('page', $vars, $params); + + /* Start buffering */ + ob_start(); + + /* Output js/css here if we are calling via the api */ + if (!empty($this->view->_params['api'])) { + $includes = new Horde_Script_Files(); + $includes->disableAutoloadHordeJS(); + $includes->_add('redbox.js', 'horde', true, true); + $includes->includeFiles(); + } + + /* Needed in the template files */ + $tilesperrow = $prefs->getValue('tilesperrow'); + $cellwidth = round(100 / $tilesperrow); + $count = 0; + + include ANSEL_TEMPLATES . '/view/galleryvimeo.inc'; + return ob_get_clean(); + } + + function getTile($image, $video, $cnt) + { + $imgOnClick = 'return showVideo(' . $cnt . ');'; + $tile = '
' + . Horde::link($video->url, $video->title, '', '', $imgOnClick, $video->title) + . '' . ''; + $tile .= '
'; + $tile .= '
' . $video->caption . '
'; + + return $tile; + } + +} diff --git a/ansel/lib/View/Image.php b/ansel/lib/View/Image.php new file mode 100644 index 000000000..69a116839 --- /dev/null +++ b/ansel/lib/View/Image.php @@ -0,0 +1,407 @@ + + * @package Ansel + */ + +/** Ansel_View_Abstract */ +require_once ANSEL_BASE . '/lib/Views/Abstract.php'; + +class Ansel_View_Image extends Ansel_View_Abstract { + + /** + * The image selected for this view. + * + * @var Ansel_Image + */ + var $image; + + /** + * @static + * + * @TODO use exceptions from the constructor instead of static + * instance-getting. + */ + function makeView($params = array()) + { + /* Get the image */ + $image_id = $params['image_id']; + + $image = &$GLOBALS['ansel_storage']->getImage($image_id); + if (is_a($image, 'PEAR_Error')) { + return $image; + } + + /* Create the Ansel_View object */ + $view = new Ansel_View_Image; + + /* Save params */ + if (count($params)) { + $view->_params = $params; + } + + $view->gallery = $view->getGallery(); + if (is_a($view->gallery, 'PEAR_Error')) { + return $view->gallery; + } + + /* Save the image reference */ + $view->resource = $image; + + // Check user age + if (!$view->gallery->isOldEnough()) { + if (!empty($params['api'])) { + return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); + } + $date = Ansel::getDateParameter( + array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, + 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, + 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); + + $url = Ansel::getUrlFor('view', array_merge( + array('gallery' => $view->gallery->id, + 'slug' => empty($params['slug']) ? '' : $params['slug'], + 'page' => empty($params['page']) ? 0 : $params['page'], + 'view' => 'Image', + 'image' => $image->id), + $date), + true); + + $params = array('gallery' => $view->gallery->id, 'url' => $url); + + header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('disclamer.php'), $params, null, false)); + exit; + } + + // Check password + if ($view->gallery->hasPasswd()) { + if (!empty($params['api'])) { + return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); + } + $date = Ansel::getDateParameter( + array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, + 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, + 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); + + $url = Ansel::getUrlFor('view', array_merge( + array('gallery' => $view->gallery->id, + 'slug' => empty($params['slug']) ? '' : $params['slug'], + 'page' => empty($params['page']) ? 0 : $params['page'], + 'view' => 'Image', + 'image' => $image->id), + $date), + true); + + $params = array('gallery' => $view->gallery->id, 'url' => $url); + + header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('protect.php'), $params, null, false)); + exit; + } + + + /* Any script files we may need if not calling via the api */ + if (empty($view->_params['api'])) { + Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('stripe.js', 'horde', true); + } + + return $view; + } + + function getGalleryCrumbData() + { + return $this->gallery->getGalleryCrumbData(); + } + + /** + * Get the title for this view. + * + * @return string The title. + */ + function getTitle() + { + return $this->resource->filename; + } + + /** + * Get the HTML representing this view. + * + * @return string The HTML. + */ + function html() + { + global $browser, $conf, $prefs, $registry; + + if (is_a($this->gallery, 'PEAR_Error')) { + echo htmlspecialchars($this->gallery->getMessage()); + return; + } + + $page = isset($this->_params['page']) ? $this->_params['page'] : 0; + $galleryId = $this->gallery->id; + $gallerySlug = $this->gallery->get('slug'); + $imageId = $this->resource->id; + $galleryOwner = $this->gallery->get('owner'); + $date = $this->gallery->getDate(); + + /* Allow overriding the configured view_mode */ + if (isset($this->_params['mode'])) { + $mode = $this->_params['mode']; + } else { + $mode = $this->_params['mode'] = $this->gallery->get('view_mode'); + } + + /* Get any date infor the gallery has */ + $date = $this->gallery->getDate(); + + $style = (empty($this->_params['style']) ? + $this->gallery->getStyle() : + Ansel::getStyleDefinition($this->_params['style'])); + + /* Make sure the screen view is loaded and get the geometry */ + $geometry = $this->resource->getDimensions('screen'); + if (is_a($geometry, 'PEAR_Error')) { + Horde::logMessage($geometry->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); + $geometry = $conf['screen']; + } + + /* Get comments before any output in sent. */ + if (($conf['comments']['allow'] == 'all' || ($conf['comments']['allow'] == 'authenticated' && Horde_Auth::getAuth())) && + $registry->hasMethod('forums/doComments')) { + $hasComments = true; + $url = empty($this->_params['comment_url']) ? null : $this->_params['comment_url']; + $comments = $registry->call('forums/doComments', + array('ansel', $imageId, + 'commentCallback', true, null, + $url)); + if (is_a($comments, 'PEAR_Error')) { + Horde::logMessage($comments, __FILE__, __LINE__, PEAR_LOG_DEBUG); + $comments = array(); + } + } else { + $comments = array(); + $hasComments = false; + } + + /* Get the index of the starting image */ + $imageList = $this->gallery->listImages(); + $revList = array_flip($imageList); + $imageIndex = $revList[$imageId]; + + /* Not needed when being called via api */ + if (empty($this->_params['api'])) { + $ecardurl = Horde::applicationUrl( + Horde_Util::addParameter('img/ecard.php', array_merge( + array('gallery' => $galleryId, + 'image' => $imageId), + $date)), + true); + + $imageActionUrl = Horde_Util::addParameter( + 'image.php', array_merge( + array('gallery' => $galleryId, + 'image' => $imageId, + 'page' => $page), + $date)); + } + + /* Check for an explicit gallery view url to use */ + if (!empty($this->_params['gallery_view_url'])) { + $galleryurl = str_replace( + array('%g', '%s'), + array($galleryId, $gallerySlug), + urldecode($this->_params['gallery_view_url'])); + Horde_Util::addParameter($galleryurl, $date); + } else { + $galleryurl = Ansel::getUrlFor('view', array_merge( + array('gallery' => $galleryId, + 'slug' => $gallerySlug, + 'page' => $page, + 'view' => 'Gallery'), + $date), + true); + } + + /* Get the image src url */ + $imageUrl = Ansel::getImageUrl($imageId, 'screen', true, $style['name']); + + /* And a self url. Can't use Horde::selfUrl() since that would ignore + * pretty urls. */ + $selfUrl = Ansel::getUrlFor('view', array_merge( + array('gallery' => $galleryId, + 'slug' => $gallerySlug, + 'image' => $imageId, + 'view' => 'Image', + 'page' => $page), + $date)); + + /* Get the next and previous image ids */ + if (isset($imageList[$imageIndex + 1])) { + $next = $imageList[$imageIndex + 1]; + } else { + $next = $imageList[0]; + } + if (isset($imageList[$imageIndex - 1])) { + $prev = $imageList[$imageIndex - 1]; + } else { + $prev = $imageList[count($imageList) - 1]; + } + + /** Calculate the page number of the next/prev images */ + $perpage = $prefs->getValue('tilesperpage'); + $pagestart = $page * $perpage; + $pageend = min(count($imageList), $pagestart + $perpage - 1); + $page_next = $page; + + if ($revList[$imageId] + 1 > $pageend) { + $page_next++; + } + $page_prev = $page; + if ($revList[$imageId] - 1 < $pagestart) { + $page_prev--; + } + + /* Previous image link */ + if (!empty($this->_params['image_view_url'])) { + $prev_url = str_replace( + array('%i', '%g', '%s'), + array($prev, $galleryId, $gallerySlug), + urldecode($this->_params['image_view_url'])); + } else { + $prev_url = Ansel::getUrlFor('view', array_merge( + array('gallery' => $galleryId, + 'slug' => $gallerySlug, + 'image' => $prev, + 'view' => 'Image', + 'page' => $page_prev), + $date)); + } + $prvImgUrl = Ansel::getImageUrl($prev, 'screen', false, $style['name']); + + /* Next image link */ + if (!empty($this->_params['image_view_url'])) { + $next_url = str_replace( + array('%i', '%g', '%s'), + array($prev, $galleryId, $gallerySlug), + urldecode($this->_params['image_view_url'])); + } else { + $next_url = Ansel::getUrlFor('view', array_merge( + array('gallery' => $galleryId, + 'slug' => $gallerySlug, + 'image' => $next, + 'view' => 'Image', + 'page' => $page_next), + $date)); + } + $nextImgUrl = Ansel::getImageUrl($next, 'screen', false, $style['name']); + + /* Slideshow link */ + if (!empty($this->_params['slideshow_link'])) { + $slideshow_url = str_replace(array('%i', '%g'), + array($imageId, $galleryId), + urldecode($this->_params['slideshow_link'])); + } else { + $slideshow_url = Horde::applicationUrl( + Horde_Util::addParameter('view.php', array_merge( + array('gallery' => $galleryId, + 'image' => $imageId, + 'view' => 'Slideshow'), + $date))); + } + + $commentHtml = ''; + if (isset($hasComments)) { + if (!empty($comments['threads'])) { + $commentHtml .= '
' . $comments['threads']; + } + if (!empty($comments['comments'])) { + $commentHtml .= '
' . $comments['comments']; + } + } + + if ($prefs->getValue('showexif')) { + require_once ANSEL_BASE . '/lib/Exif.php'; + $exifHtml = $this->_getExifHtml(); + } else { + $exifHtml = ''; + } + + /* Buffer the template file and return the html */ + ob_start(); + + //@TODO: Refactor styles to allow dynamic inclusion/exclusion of widgets. + /* These items currently don't work when viewing through the api */ + if (empty($this->_params['api'])) { + /* Add the widgets */ + // Tag widget + $this->addWidget(Ansel_Widget::factory('Tags', array('view' => 'image'))); + + // Similar photos + $this->addWidget(Ansel_Widget::factory('SimilarPhotos')); + + // Geolocation + $this->addWidget(Ansel_Widget::factory('Geodata', array('images' => array($this->resource->id)))); + + // Faces + if ($conf['faces']['driver']) { + $this->addWidget(Ansel_Widget::factory('ImageFaces', array('selfUrl' => $selfUrl))); + } + + // Links + $this->addWidget(Ansel_Widget::factory('Links', array())); + + /* In line caption editing */ + if ($this->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) { + $imple = Horde_Ajax_Imple::factory(array('ansel', 'EditCaption'), + array('id' => $imageId, + 'domid' => "Caption", + 'cols' => 120)); + $imple->attach(); + } + } + + /* Output the js if we are calling via the api */ + if (!empty($this->_params['api'])) { + $includes = new Horde_Script_Files(); + $includes->disableAutoloadHordeJS(); + $includes->_add('prototype.js', 'horde', true, true); + $includes->_add('effects.js', 'horde',true, true); + $includes->_add('stripe.js', 'horde', true, true); + $includes->includeFiles(); + } + + require ANSEL_TEMPLATES . '/view/image.inc'; + return ob_get_clean(); + } + + /** + * Helper function for generating the HTML for EXIF data. + * + * @return string The HTML + */ + function _getExifHtml() + { + $data = Ansel_ImageData::getAttributes($this->resource, true); + + $html = ''; + if (count($data)) { + $data = array_chunk($data, 3); + $html .= ''; + $i = 0; + foreach ($data as $elem) { + $html .= '' . implode('', $elem) . ''; + } + $html .= '
'; + } + return $html; + } + + function viewType() + { + return 'Image'; + } + +} diff --git a/ansel/lib/View/List.php b/ansel/lib/View/List.php new file mode 100644 index 000000000..7882bf220 --- /dev/null +++ b/ansel/lib/View/List.php @@ -0,0 +1,270 @@ + + * @package Ansel + */ +class Ansel_View_List extends Ansel_View_Abstract { + + /** + * @static + * + * @param array $params Any parameters that the view might need. + *
+     *  In addition to the params taken by Ansel_View_Gallery, this view
+     *  can also take:
+     *
+     *  groupby      -  Group the results (owner, category etc...)
+     *
+     *  owner        -  The owner to group by
+     *
+     *  category     -  The category to group by
+     *
+     *  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.
+     *
+     * @TODO use exceptions from the constructor instead of static
+     * instance-getting.
+     */
+    function makeView($params = array())
+    {
+        $view = new Ansel_View_List;
+        $view->_params = $params;
+        return $view;
+    }
+
+    /**
+     * Get this view's title.
+     *
+     * @return string  The gallery's title.
+     */
+    function getTitle()
+    {
+        return _("Gallery List");
+    }
+
+    /**
+     * Return the HTML representing this view.
+     *
+     * @return string  The HTML.
+     *
+     */
+    function html()
+    {
+        global $conf, $prefs, $registry, $ansel_storage, $notification;
+
+        // If we aren't supplied with a page number, default to page 0.
+        if (isset($this->_params['page'])) {
+            $page = $this->_params['page'];
+        } else {
+            $page = Horde_Util::getFormData('page', 0);
+        }
+        $galleries_perpage = $prefs->getValue('tilesperpage');
+
+        // Check for grouping.
+        if (empty($this->_params['groupby'])) {
+            $groupby = Horde_Util::getFormData('groupby', $prefs->getValue('groupby'));
+        } else {
+            $groupby = $this->_params['groupby'];
+        }
+
+        if (empty($this->_params['owner'])) {
+            $owner = Horde_Util::getFormData('owner');
+            $owner = empty($owner) ? null : $owner;
+        } else {
+            $owner = $this->_params['owner'];
+        }
+
+        $special = Horde_Util::getFormData('special');
+
+        if (empty($this->_params['category'])) {
+            $category = Horde_Util::getFormData('category');
+            $category = empty($category) ? null : $category;
+        } else {
+            $category = $this->_params['category'];
+        }
+        if (!$owner && !$category && !$special && $groupby != 'none' ) {
+            header('Location: ' . Ansel::getUrlFor('group', array('groupby' => $groupby), true));
+            exit;
+        }
+
+        // We'll need this in the template.
+        $sortby = !empty($this->_params['sort']) ? $this->_params['sort'] : 'name';
+        $sortdir = isset($this->_params['sort_dir']) ? $this->_params['sort_dir'] : 0;
+
+        // If we are calling from the api, we can just pass a list of gallery
+        // ids instead of doing grouping stuff.
+        if (!empty($this->_params['api']) &&
+            !empty($this->_params['gallery_ids']) &&
+            count($this->_params['gallery_ids'])) {
+
+            $start = $page * $galleries_perpage;
+            $num_galleries = count($this->_params['gallery_ids']);
+            if ($num_galleries > $start) {
+                $getThese = array_slice($this->_params['gallery_ids'], $start, $galleries_perpage);
+                $try = $ansel_storage->getGalleries($getThese);
+                $gallerylist = array();
+                foreach ($try as $id => $gallery) {
+                    if ($gallery->hasPermission(Horde_Auth::getAuth(), PERMS_SHOW)) {
+                        $gallerylist[$id] = $gallery;
+                    }
+                }
+            } else {
+                $gallerylist = array();
+            }
+        } else {
+            // Set list filter/title
+            $filter = array();
+            if (!is_null($owner)) {
+                $filter['owner'] = $owner;
+            }
+
+            if (!is_null($category)) {
+                $filter['category'] = $category;
+            }
+
+            if ($owner) {
+                if ($owner == Horde_Auth::getAuth() && empty($this->_params['api'])) {
+                    $list_title = _("My Galleries");
+                } elseif (!empty($GLOBALS['conf']['gallery']['customlabel'])) {
+                    $uprefs = &Prefs::singleton($GLOBALS['conf']['prefs']['driver'],
+                                                'ansel', $owner, '', null, false);
+                    $fullname = $uprefs->getValue('grouptitle');
+                    if (!$fullname) {
+                        require_once 'Horde/Identity.php';
+                        $identity = &Identity::singleton('none', $owner);
+                        $fullname = $identity->getValue('fullname');
+                        if (!$fullname) {
+                            $fullname = $owner;
+                        }
+                        $list_title = sprintf(_("%s's Galleries"), $fullname);
+                    } else {
+                        $list_title = $fullname;
+                    }
+                } else {
+                    $list_title = sprintf(_("%s's Galleries"), $owner);
+                }
+            } elseif ($category || ($groupby == 'category' && $special)) {
+                if ($special == 'unfiled') {
+                    $list_title = sprintf(_("Galleries in category \"%s\""),
+                                          _("Unfiled"));
+                    $filter['category'] = '';
+                } else {
+                    $list_title = sprintf(_("Galleries in category \"%s\""), $category);
+                }
+            } else {
+                $list_title = _("Gallery List");
+            }
+
+            $num_galleries = $ansel_storage->countGalleries(
+                Horde_Auth::getAuth(), PERMS_SHOW, $filter, null, false);
+            if (is_a($num_galleries, 'PEAR_Error')) {
+                return $num_galleries->getMessage();
+            }
+
+            if ($num_galleries == 0 && empty($this->_params['api'])) {
+                if ($filter == $owner && $owner == Horde_Auth::getAuth()) {
+                    $notification->push(_("You have no photo galleries, add one!"),
+                                        'horde.message');
+                    header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('gallery.php'), 'actionID', 'add'));
+                    exit;
+                }
+                $notification->push(_("There are no photo galleries available."), 'horde.message');
+                $gallerylist = array();
+            } else {
+                $gallerylist = $ansel_storage->listGalleries(
+                    PERMS_SHOW, $filter, null, false, $page * $galleries_perpage,
+                    $galleries_perpage, $sortby, $sortdir);
+            }
+
+        }
+
+        $vars = Horde_Variables::getDefaultVariables();
+        if (!empty($this->_params['page'])) {
+            $vars->add('page', $this->_params['page']);
+        }
+
+        if (!empty($this->_params['pager_url'])) {
+            $pagerurl = $this->_params['pager_url'];
+            $override = true;
+        } else {
+            $override = false;
+            $pagerurl = Ansel::getUrlFor('view',
+                                    array('owner' => $owner,
+                                          'category' => $category,
+                                          'special' => $special,
+                                          'groupby' => $groupby,
+                                          'view' => 'List'));
+        }
+        $p_params = array('num' => $num_galleries,
+                          'url' => $pagerurl,
+                          'perpage' => $galleries_perpage);
+
+        if ($override) {
+            $p_params['url_callback'] = null;
+        }
+        $pager = new Horde_UI_Pager('page', $vars, $p_params);
+        $preserve = array('sort_dir' => $sortdir);
+        if (!empty($sortby)) {
+            $preserve['sort'] = $sortby;
+        }
+        $pager->preserve($preserve);
+
+        if ($num_galleries) {
+            $min = $page * $galleries_perpage;
+            $max = $min + $galleries_perpage;
+            if ($max > $num_galleries) {
+                $max = $num_galleries - $min;
+            }
+            $start = $min + 1;
+            $end = min($num_galleries, $min + $galleries_perpage);
+
+            if ($owner) {
+                $refresh_link = Ansel::getUrlFor('view',
+                                                 array('groupby' => $groupby,
+                                                       'owner' => $owner,
+                                                       'page' => $page,
+                                                       'view' => 'List'));
+
+            } else {
+                $refresh_link = Ansel::getUrlFor('view',
+                                                 array('view' => 'List',
+                                                       'groupby' => $groupby,
+                                                       'page' => $page,
+                                                       'category' => $category));
+            }
+
+            // Get top-level / default gallery style.
+            if (empty($this->_params['style'])) {
+                $style = Ansel::getStyleDefinition(
+                    $prefs->getValue('default_gallerystyle'));
+            } else {
+                $style = Ansel::getStyleDefinition($this->_params['style']);
+            }
+            $count = 0;
+            $width = round(100 / $prefs->getValue('tilesperrow'));
+
+            ob_start();
+            include ANSEL_TEMPLATES . '/view/list.inc';
+            $html = ob_get_clean();
+            return $html;
+        }
+        return '';
+    }
+
+    function viewType()
+    {
+        return 'List';
+    }
+
+}
diff --git a/ansel/lib/View/Results.php b/ansel/lib/View/Results.php
new file mode 100644
index 000000000..8af8b08f7
--- /dev/null
+++ b/ansel/lib/View/Results.php
@@ -0,0 +1,310 @@
+
+ * @package Ansel
+ */
+class Ansel_View_Results extends Ansel_View_Abstract {
+
+    /**
+     * Instance of our tag search
+     *
+     * @var Ansel_Tag_Search
+     */
+    var $_search;
+
+    /**
+     * Gallery owner id
+     *
+     * @var string
+     */
+    var $_owner;
+
+    /**
+     * Contructor - just set some instance variables.
+     *
+     * @return Ansel_View_Results
+     */
+    function Ansel_View_Results()
+    {
+        $this->_owner = Horde_Util::getFormData('owner', null);
+        $this->_search = Ansel_Tags::getSearch(null, $this->_owner);
+    }
+
+    /**
+     * @static
+     *
+     * @return Ansel_View_Results  The view object.
+     *
+     * @TODO use exceptions from the constructor instead of static
+     * instance-getting.
+     */
+    function makeView($params = array())
+    {
+        $view = new Ansel_View_Results();
+        if (count($params)) {
+            $view->_params = $params;
+        }
+        return $view;
+    }
+
+    /**
+     * Return the title for this view.
+     *
+     * @return string The title for this view.
+     */
+    function getTitle()
+    {
+        return (!empty($this->_owner))
+                ? sprintf(_("Searching %s's photos tagged: "), $this->_owner)
+                : _("Searching all photos tagged: ");
+    }
+
+    /**
+     * Get the HTML representing this view.
+     *
+     * @return string  The HTML
+     */
+    function html()
+    {
+        global $conf, $prefs, $registry, $ansel_storage;
+
+        $page = Horde_Util::getFormData('page', 0);
+        $action = Horde_Util::getFormData('actionID', '');
+        $image_id = Horde_Util::getFormData('image');
+
+        $vars = Horde_Variables::getDefaultVariables();
+
+        // Number perpage from prefs or config.
+        $perpage = min($prefs->getValue('tilesperpage'),
+                       $conf['thumbnail']['perpage']);
+
+        switch ($action) {
+        // Image related actions
+        case 'delete':
+             if (is_array($image_id)) {
+                 $images = array_keys($image_id);
+             } else {
+                 $images = array($image_id);
+             }
+
+             foreach ($images as $image) {
+                 // Need a gallery object to delete the image, but need
+                 // the image object to get the gallery.
+                 $img = $ansel_storage->getImage($image);
+                 $gallery = $ansel_storage->getgallery($img->gallery);
+                 if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) {
+                     $GLOBALS['notification']->push(
+                        sprintf(_("Access denied deleting photos from \"%s\"."), $image),
+                                'horde.error');
+                 } else {
+                     $result = $gallery->removeImage($image);
+                    if (is_a($result, 'PEAR_Error')) {
+                        $GLOBALS['notification']->push(
+                            sprintf(_("There was a problem deleting photos: %s"),
+                                    $result->getMessage()), 'horde.error');
+                    } else {
+                        $GLOBALS['notification']->push(_("Deleted the photo."),
+                                                       'horde.success');
+                        Ansel_Tags::clearCache();
+                    }
+                 }
+             }
+
+             // Reload the browse view again to get notifications.
+             header('Location: ' . Ansel::getUrlFor('view',
+                                                    array('view' => 'Results'),
+                                                    true));
+             exit;
+
+        case 'move':
+            if (is_array($image_id)) {
+                $images = array_keys($image_id);
+            } else {
+                $images = array($image_id);
+            }
+
+            // Move the images if we're provided with at least one
+            // valid image ID.
+            $newGallery = Horde_Util::getFormData('new_gallery');
+            if ($images && $newGallery) {
+                $newGallery = $ansel_storage->getGallery($newGallery);
+                if (is_a($newGallery, 'PEAR_Error')) {
+                    $GLOBALS['notification']->push(_("Bad input."),
+                                                   'horde.error');
+                } else {
+                    // Group by gallery first, then process in bulk by gallery.
+                    $galleries = array();
+                    foreach ($images as $image) {
+                        $img = $ansel_storage->getImage($image);
+                        $galleries[$img->gallery][] = $image;
+                    }
+                    foreach ($galleries as $gallery_id => $images) {
+                        $gallery = $ansel_storage->getGallery($gallery_id);
+                        $result = $gallery->moveImagesTo($images, $newGallery);
+                        if (is_a($result, 'PEAR_Error')) {
+                            $GLOBALS['notification']->push($result, 'horde.error');
+                        } else {
+                            $GLOBALS['notification']->push(
+                                sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
+                                                 "Moved %d photos from \"%s\" to \"%s\"",
+                                                 count($images)),
+                                        count($images), $gallery->get('name'),
+                                        $newGallery->get('name')),
+                                'horde.success');
+                        }
+                    }
+                }
+            }
+
+            // Return to the image list.
+            $imageurl = Horde_Util::addParameter('view.php',
+                                           array('view' => 'Results'));
+            header('Location: ' . Ansel::getUrlFor('view',
+                                                   array('view' => 'Results'),
+                                                   true));
+            exit;
+
+        case 'copy':
+            if (is_array($image_id)) {
+                $images = array_keys($image_id);
+            } else {
+                $images = array($image_id);
+            }
+
+            // Move the images if we're provided with at least one
+            // valid image ID.
+            $newGallery = Horde_Util::getFormData('new_gallery');
+            if ($images && $newGallery) {
+                $newGallery = $ansel_storage->getGallery($newGallery);
+                if (is_a($newGallery, 'PEAR_Error')) {
+                    $GLOBALS['notification']->push(_("Bad input."),
+                                                   'horde.error');
+                } else {
+                    // Group by gallery first, then process in bulk by gallery.
+                    $galleries = array();
+                    foreach ($images as $image) {
+                        $img = $ansel_storage->getImage($image);
+                        $galleries[$img->gallery][] = $image;
+                    }
+                    foreach ($galleries as $gallery_id => $images) {
+                        $gallery = $ansel_storage->getGallery($gallery_id);
+                        $result = $gallery->copyImagesTo($images, $newGallery);
+                        if (is_a($result, 'PEAR_Error')) {
+                            $GLOBALS['notification']->push($result,
+                                                           'horde.error');
+                        } else {
+                            $GLOBALS['notification']->push(
+                                sprintf(ngettext("Copied %d photo from %s to %s",
+                                                 "Copied %d photos from %s to %s",
+                                                 count($images)),
+                                        count($images), $gallery->get('name'),
+                                        $newGallery->get('name')),
+                                'horde.success');
+                        }
+                    }
+                }
+            }
+
+            // Return to the image list.
+            $imageurl = Horde_Util::addParameter('view.php',
+                                           array('view' => 'Results'));
+            header('Location: ' . Horde::applicationUrl($imageurl, true));
+            exit;
+
+        // Tag related actions
+        case 'remove':
+            $tag = Horde_Util::getFormData('tag');
+            if (isset($tag)) {
+                $tag = Ansel_Tags::getTagIds(array($tag));
+                $tag = array_pop($tag);
+                $this->_search->removeTag($tag);
+                $this->_search->save();
+            }
+            break;
+
+        case 'add':
+        default:
+            $tag = Horde_Util::getFormData('tag');
+            if (isset($tag)) {
+                $tag = Ansel_Tags::getTagIds(array($tag));
+                $tag = array_pop($tag);
+                $this->_search->addTag($tag);
+                $this->_search->save();
+            }
+            break;
+        }
+
+        // Check for empty tag search and redirect if empty
+        if ($this->_search->tagCount() < 1) {
+            header('Location: ' . Horde::applicationUrl('browse.php', true));
+            exit;
+        }
+
+        // Get the slice of galleries/images to view on this page.
+        $results = $this->_search->getSlice($page, $perpage);
+        $total = $this->_search->count();
+        $total = $total['galleries'] + $total['images'];
+
+        // The number of resources to display on this page.
+        $numimages = count($results);
+
+        // Get any related tags to display.
+        if ($conf['tags']['relatedtags']) {
+            $rtags = $this->_search->getRelatedTags();
+            $rtaghtml = '
    '; + $links = Ansel_Tags::getTagLinks($rtags, 'add'); + foreach ($rtags as $id => $taginfo) { + if (!empty($this->_owner)) { + $links[$id] = Horde_Util::addParameter($links[$id], 'owner', + $this->_owner); + } + $rtaghtml .= '
  • ' . Horde::link($links[$id], + sprintf(ngettext( + "%d photo", "%d photos", + $taginfo['total']), + $taginfo['total'])) + . $taginfo['tag_name'] . '
  • '; + } + $rtaghtml .= '
'; + } + $styleDef = Ansel::getStyleDefinition( + $GLOBALS['prefs']->getValue('default_gallerystyle')); + $style = $styleDef['name']; + $viewurl = Horde_Util::addParameter('view.php', array('view' => 'Results', + 'actionID' => 'add')); + + $vars = Horde_Variables::getDefaultVariables(); + $option_move = $option_copy = $ansel_storage->countGalleries(PERMS_EDIT); + + + $pagestart = ($page * $perpage) + 1; + $pageend = min($pagestart + $numimages - 1, $pagestart + $perpage - 1); + $pager = new Horde_UI_Pager('page', $vars, array('num' => $total, + 'url' => $viewurl, + 'perpage' => $perpage)); + ob_start(); + include ANSEL_TEMPLATES . '/view/results.inc'; + return ob_get_clean(); + } + + function viewType() + { + return 'Results'; + } + +} diff --git a/ansel/lib/View/Slideshow.php b/ansel/lib/View/Slideshow.php new file mode 100644 index 000000000..038a5f8ca --- /dev/null +++ b/ansel/lib/View/Slideshow.php @@ -0,0 +1,179 @@ + + * @author Michael J. Rubinsky + * @package Ansel + */ + +/** Ansel_View_Abstract */ +require_once ANSEL_BASE . '/lib/Views/Abstract.php'; + +class Ansel_View_Slideshow extends Ansel_View_Abstract { + + /** + * The Ansel_Image object representing the first image selected for view. + * + * @var Ansel_Image + */ + var $image; + + /** + * @static + * + * @return Ansel_View_Slidshow The view object. + * + * @TODO use exceptions from the constructor instead of static + * instance-getting. + */ + function makeView($params = array()) + { + if (empty($params['image_id'])) { + $image_id = Horde_Util::getFormData('image'); + } else { + $image_id = $params['image_id']; + } + $image = $GLOBALS['ansel_storage']->getImage($image_id); + if (is_a($image, 'PEAR_Error')) { + return $image; + } + + $view = new Ansel_View_Slideshow(); + if (count($params)) { + $view->_params = $params; + } + $view->gallery = $view->getGallery($image->gallery); + if (is_a($view->gallery, 'PEAR_Error')) { + return $view->gallery; + } + $view->image = $image; + + // Check user age + if (!$view->gallery->isOldEnough()) { + $date = Ansel::getDateParameter( + array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, + 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, + 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); + + $url = Ansel::getUrlFor('view', array_merge( + array('gallery' => $view->gallery->id, + 'slug' => empty($params['slug']) ? '' : $params['slug'], + 'page' => empty($params['page']) ? 0 : $params['page'], + 'view' => 'Slideshow', + 'image' => $image->id), + $date), + true); + + $params = array('gallery' => $view->gallery->id, 'url' => $url); + + header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('disclamer.php'), $params, null, false)); + exit; + } + + // Check password + if ($view->gallery->hasPasswd()) { + $date = Ansel::getDateParameter( + array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, + 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, + 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); + + $url = Ansel::getUrlFor('view', array_merge( + array('gallery' => $view->gallery->id, + 'slug' => empty($params['slug']) ? '' : $params['slug'], + 'page' => empty($params['page']) ? 0 : $params['page'], + 'view' => 'Slideshow', + 'image' => $image->id), + $date), + true); + + $params = array('gallery' => $view->gallery->id, 'url' => $url); + + header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('protect.php'), $params, null, false)); + exit; + } + + + Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('stripe.js', 'horde', true); + Horde::addScriptFile('slideshow.js', 'ansel', true); + + return $view; + } + + /** + * Get the title for this view. + * + * @return string The title. + */ + function getTitle() + { + return $this->image->filename; + } + + /** + * Get the HTML representing this view. + * + * @return string The HTML. + */ + function html() + { + global $browser, $conf, $prefs, $registry; + + if (is_a($this->gallery, 'PEAR_Error')) { + echo htmlspecialchars($this->gallery->getMessage()); + return; + } + $page = Horde_Util::getFormData('page', 0); + $galleryId = $this->gallery->id; + $imageId = $this->image->id; + $galleryOwner = $this->gallery->get('owner'); + $style = $this->gallery->getStyle(); + + /* Get date info to pass along the links */ + if (!empty($this->_params['year'])) { + $date = Ansel::getDateParameter( + array('year' => $this->_params['year'], + 'month' => $this->_params['month'], + 'day' => $this->_params['day'])); + } else { + $date = array(); + } + + /* Get the index of the starting image */ + $imageList = $this->gallery->listImages(); + + $style = $this->gallery->getStyle(); + $revList = array_flip($imageList); + $imageIndex = $revList[$imageId]; + if (isset($imageList[$imageIndex - 1])) { + $prev = $imageList[$imageIndex - 1]; + } else { + $prev = $imageList[count($imageList) - 1]; + } + + $ecardurl = Horde_Util::addParameter('img/ecard.php', + array('gallery' => $galleryId, + 'image' => $imageId)); + $galleryurl = Horde_Util::addParameter('view.php', array_merge( + array('gallery' => $galleryId, + 'page' => $page), + $date)); + $imageActionUrl = Horde_Util::addParameter('image.php', array_merge( + array('gallery' => $galleryId, + 'image' => $imageId, + 'page' => $page), + $date)); + $imageUrl = Ansel::getImageUrl($imageId, 'screen', false, $style['name']); + + ob_start(); + require ANSEL_TEMPLATES . '/view/slideshow.inc'; + return ob_get_clean(); + } + + function viewType() + { + return 'Slideshow'; + } + +} diff --git a/ansel/lib/Views/Abstract.php b/ansel/lib/Views/Abstract.php deleted file mode 100644 index acbf521e9..000000000 --- a/ansel/lib/Views/Abstract.php +++ /dev/null @@ -1,188 +0,0 @@ - - * @author Michael J. Rubinsky - * @package Ansel - */ -class Ansel_View_Abstract { - - var $_params = array(); - - /** - * The ansel resource this view is for. - * - * @var mixed Either an Ansel_Gallery or Ansel_Image - */ - var $resource; - - /** - * The gallery object (will be eq to $resource in a gallery view - * - * @var Ansel_Gallery - */ - var $gallery; - - /** - * Collection of Ansel_Widgets to display in this view. - * - * @var array - */ - var $_widgets = array(); - - 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)) { - return PEAR::raiseError(_("No gallery specified")); - } - - // If we have a slug, use it. - if (!empty($slug)) { - $gallery = &$GLOBALS['ansel_storage']->getGalleryBySlug($slug); - } else { - $gallery = &$GLOBALS['ansel_storage']->getGallery($galleryId); - } - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { - return PEAR::raiseError(sprintf(_("Access denied to gallery \"%s\"."), $gallery->get('name'))); - } - - /* 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; - } - - /** - * Add an Ansel_Widget to be displayed in this view. - * - * @param Ansel_Widget $widget The Ansel_Widget to display - */ - function addWidget($widget) - { - $result = $widget->attach($this); - if (!empty($result)) { - $this->_widgets[] = $widget; - } - } - - - /** - * Output any widgets associated with this view. - * - */ - function renderWidgets() - { - $this->_renderWidgets(); - } - - /** - * Count the number of widgets we have attached. - * - * @return integer The number of widgets attached to this view. - */ - function countWidgets() - { - return count($this->_widgets); - } - - /** - * Default widget rendering, can be overridden by any subclass. - * - */ - function _renderWidgets() - { - echo '
'; - foreach ($this->_widgets as $widget) { - if ($widget->autoRender) { - echo $widget->html(); - echo '
'; - } - } - echo '
'; - } - - /** - * JSON representation of this gallery's images. - * - * @param array $images An array of Ansel_Image objects. If this is null - * the images are fetched based on $from and $count. - * - * @param integer $from Image to start at. - * @param integer $count Number of images to get. - * - * @return string A serialized JSON array. - */ - function json($images = null, $full = false, $from = 0, $count = 0, - $image_view = 'screen', $view_links = false) - { - global $conf, $prefs; - - $json = array(); - $perpage = $prefs->getValue('tilesperpage', $conf['thumbnail']['perpage']); - $curimage = 0; - $curpage = 0; - - if (is_null($images)) { - $images = $this->gallery->getImages($from, $count); - } - - $style = $this->gallery->getStyle(); - - foreach ($images as $image) { - // Calculate the page this image will appear on in the - // gallery view. - if (++$curimage > $perpage) { - ++$curpage; - $curimage = 0; - } - - $data = array(Ansel::getImageUrl($image->id, $image_view, $full, $style['name']), - htmlspecialchars($image->filename, ENT_COMPAT, Horde_Nls::getCharset()), - Horde_Text_Filter::filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), - $image->id, - $curpage); - if ($view_links) { - $data[] = Ansel::getUrlFor('view', - array('gallery' => $this->gallery->id, - 'slug' => $this->gallery->get('slug'), - 'image' => $image->id, - 'view' => 'Image'), - true); - $data[] = Ansel::getUrlFor('view', - array('gallery' => $image->gallery, - 'slug' => $this->gallery->get('slug'), - 'view' => 'Gallery'), - true); - } - // Source, Width, Height, Name, Caption, Image Id, Gallery Page - $json[] = $data; - } - - return Horde_Serialize::serialize($json, Horde_Serialize::JSON, Horde_Nls::getCharset()); - } - - /** - * @abstract - * @return unknown_type - */ - function viewType() - { - } - -} diff --git a/ansel/lib/Views/Embedded.php b/ansel/lib/Views/Embedded.php deleted file mode 100644 index 7d303df71..000000000 --- a/ansel/lib/Views/Embedded.php +++ /dev/null @@ -1,87 +0,0 @@ - tags that - * will embed the view. Provided as a way to output these views via the - * renderViews api call. The actual rendering is done via the - * EmbeddedRenderers/*.php files which are called from the Ajax_Imple_Embed - * class when it handles the request. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (GPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. - * - * @author Michael J. Rubinsky - * @package Ansel - */ -class Ansel_View_Embedded { - - /** - * Initialize the view - * - * This view can take the following parameters: - * - * container The DOM id of the element to contain the embedded view. - * This parameter is required. - * - * gallery_id The gallery id - * - * gallery_slug The gallery slug - * - * gallery_view The specific view to embed this must match an existing - * EmbeddedRenderer (Mini, Slideshow, Carousel etc..) - * Defaults to 'Mini' - * - * start Start displaying at this image offset. Defaults to the start - * of the gallery. - * - * count Only return this many images. Defaults to returning the - * entire gallery (minus any subgalleries). - * - * perpage Some embedded views support paging. This sets the number of - * images per page. Note that all images are still returned. - * The paging is done via javascript only. - * - * images An array of image ids, not necessarily from the same - * gallery, to be displayed in this view. The gallery parameter - * will be ignored if present. - * - * thumbsize Which type of thumbnail images to display in the view. - * (mini, thumb, prettythumb etc...) Defaults to mini. - * @static - * @param array $params Parameters for this view - */ - function makeView($params) - { - global $ansel_storage; - - $view = new Ansel_View_Embedded(); - $view->_params = $params; - return $view; - } - - /** - * Return the HTML representing this view. - * - * @return string The HTML. - * - */ - function html() - { - /* Are we displaying a gallery or a group of images? */ - if (!empty($this->_params['images']) && count($this->_params['images'])) { - $this->_params['images'] = implode(':', $this->_params['images']); - } - - $html = Ansel::embedCode($this->_params); - - return $html; - } - - function viewType() - { - return 'Embedded'; - } - -} diff --git a/ansel/lib/Views/EmbeddedRenderers/Carousel.php b/ansel/lib/Views/EmbeddedRenderers/Carousel.php deleted file mode 100644 index 730ff52a0..000000000 --- a/ansel/lib/Views/EmbeddedRenderers/Carousel.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_EmbeddedRenderer_Carousel extends Ansel_View_Gallery { - - /** - * Create a new renderer. - * - * @see Ansel_View_Embedded - * - * @param array $params - * - * @return Ansel_View_EmbeddedRenderer The renderer object. - */ - function makeView($params = array()) - { - $view = new Ansel_View_EmbeddedRenderer_Carousel(); - $view->_params = $params; - - return $view; - } - - /** - * Build the javascript that will render the view. - * - * @return string A string containing valid javascript. - */ - function html() - { - - } - -} diff --git a/ansel/lib/Views/EmbeddedRenderers/GalleryLink.php b/ansel/lib/Views/EmbeddedRenderers/GalleryLink.php deleted file mode 100644 index 34799fcd2..000000000 --- a/ansel/lib/Views/EmbeddedRenderers/GalleryLink.php +++ /dev/null @@ -1,150 +0,0 @@ - - * - * - *
- * - * - * - * @author Michael J. Rubinsky - * @package Ansel - */ -class Ansel_View_EmbeddedRenderer_GalleryLink extends Ansel_View_Gallery { - - /** - * Create a new renderer. - * - * @see Ansel_View_Embedded - * - * @param array $params - * - * @return Ansel_View_EmbeddedRenderer The renderer object. - */ - function makeView($params = array()) - { - $view = new Ansel_View_EmbeddedRenderer_GalleryLink(); - $view->_params = $params; - - return $view; - } - - /** - * Build the javascript that will render the view. - * - * @return string A string containing valid javascript. - */ - function html() - { - /* Read in parameters and set defaults */ - - /* Required */ - $node = $this->_params['container']; - if (empty($node)) { - return ''; - } - - /* Need at least one of these */ - $galleries = !empty($this->_params['gallery_slug']) ? explode(':', $this->_params['gallery_slug']) : ''; - $haveSlugs = true; - if (empty($galleries)) { - $galleries = !empty($this->_params['gallery_id']) ? explode(':', $this->_params['gallery_id']) : null; - $haveSlugs = false; - } - - /* Determine the style/thumnailsize etc... */ - $thumbsize = empty($this->_params['thumbsize']) ? - 'thumb' : - $this->_params['thumbsize']; - - foreach ($galleries as $identifier) { - if ($haveSlugs) { - $gallery = $this->getGallery(null, $identifier); - } else { - $gallery = $this->getGallery($identifier); - } - if (is_a($gallery, 'PEAR_Error')) { - Horde::logMessage($gallery, __FILE__, __LINE__, PEAR_LOG_ERR); - exit; - } - if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { - return ''; - } - - /*If a gallery_style is not specified, default to the gallery's - * defined style. Note that this only matters if the $thumbsize - * parameter is set to 'prettythumb' anyway. - */ - $gallery_style = empty($this->_params['style']) ? - $gallery->get('style') : - $this->_params['style']; - - /* Ideally, since gallery default images are unique in that each style - * needs it's own unique image_id, the thumbsize and style parameters - * are mutually exclusive - specifying a specific gallery style is only - * needed if requesting the prettythumb thumbsize value. Make sure that - * both were not passed in. - */ - if ($thumbsize == 'thumb') { - $images[] = $gallery->getDefaultImage('ansel_default'); - } else { - $images[] = $gallery->getDefaultImage($gallery_style); - } - } - $json = $GLOBALS['ansel_storage']->getImageJson($images, null, true, $thumbsize, true); - - /* Some paths */ - $cssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'ansel') . '/jsembed.css', true); - $js_path = $GLOBALS['registry']->get('jsuri', 'horde'); - $pturl = Horde::url($js_path . '/prototype.js', true); - $ansel_js_path = $GLOBALS['registry']->get('jsuri', 'ansel'); - $jsurl = Horde::url($ansel_js_path . '/embed.js', true); - - /* Start building the javascript - we use the same parameters as with - * the mini gallery view so we can use the same javascript to display it - */ - $html = <<'); - } - anselnodes = new Array(); - anseljson = new Object(); - document.write(''); - document.write(''); - } - anselnodes[anselnodes.length] = '$node'; - anseljson['$node'] = new Object(); - anseljson['$node']['data'] = $json; - anseljson['$node']['perpage'] = 0; - anseljson['$node']['page'] = 0; - anseljson['$node']['hideLinks'] = false; - anseljson['$node']['linkToGallery'] = true; - //]]> -EOT; - - return $html; - } - -} diff --git a/ansel/lib/Views/EmbeddedRenderers/Mini.php b/ansel/lib/Views/EmbeddedRenderers/Mini.php deleted file mode 100644 index 2abaf4064..000000000 --- a/ansel/lib/Views/EmbeddedRenderers/Mini.php +++ /dev/null @@ -1,181 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery { - - /** - * Create a new renderer. - * - * @see Ansel_View_Embedded - * - * @param array $params - * - * @return Ansel_View_EmbeddedRenderer The renderer object. - */ - function makeView($params = array()) - { - $view = new Ansel_View_EmbeddedRenderer_Mini(); - $view->_params = $params; - - return $view; - } - - /** - * Build the javascript that will render the view. - * - * @return string A string containing valid javascript. - */ - function html() - { - /* Read in parameters and set defaults */ - - /* Required */ - $node = $this->_params['container']; - if (empty($node)) { - return ''; - } - - /* Optional */ - $gallery_slug = !empty($this->_params['gallery_slug']) ? $this->_params['gallery_slug'] : ''; - $gallery_id = !empty($this->_params['gallery_id']) ? $this->_params['gallery_id']: null; - - $start = (isset($this->_params['start'])) ? $this->_params['start'] : 0; - $count = (isset($this->_params['count'])) ? $this->_params['count'] : 0; - $perpage = (isset($this->_params['perpage'])) ? $this->_params['perpage'] : 0; - $thumbsize = (!empty($this->_params['thumbsize'])) ? $this->_params['thumbsize'] : 'mini'; - // Limit to these image views only. - if ($thumbsize != 'mini' && $thumbsize != 'thumb' && - $thumbsize != 'prettythumb' && $thumbsize != 'screen') { - - $thumbsize = 'mini'; - } - - /* An image list instead of a gallery? */ - $images = (!empty($this->_params['images'])) ? $this->_params['images'] : array(); - if (!empty($images)) { - // Images are filtered for age and password protected galleries - // in the ::getImageJson() call since they could all be from different - // galleries. - $images = explode(':', $images); - } else { - $this->gallery = $this->getGallery($gallery_id, $gallery_slug); - if (is_a($this->gallery, 'PEAR_Error')) { - Horde::logMessage($this->gallery, __FILE__, __LINE__, PEAR_LOG_ERR); - exit; - } - - // We don't allow age restricted or password locked galleries to be - // viewed via the mini embedded view since it shows *all* the images - if (!$this->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ) || - !$this->gallery->isOldEnough() || - $this->gallery->hasPasswd()) { - - return ''; - } - } - - if (empty($images)) { - $json = $this->json(null, true, $start, $count, $thumbsize, true); - $json_full = $this->json(null, true, $start, $count, 'screen', true); - } else { - $json = $GLOBALS['ansel_storage']->getImageJson($images, null, true, $thumbsize, true); - $json_full = $GLOBALS['ansel_storage']->getImageJson($images, null, true, 'screen', true); - } - - /* Some paths */ - $cssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'ansel') . '/embed.css', true); - $hcssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'horde') . '/embed.css', true); - $js_path = $GLOBALS['registry']->get('jsuri', 'horde'); - $pturl = Horde::url($js_path . '/prototype.js', true); - $hjsurl = Horde::url($js_path . '/tooltips.js', true); - $ansel_js_path = $GLOBALS['registry']->get('jsuri', 'ansel'); - $jsurl = Horde::url($ansel_js_path . '/embed.js', true); - $hideLinks = (bool)!empty($this->_params['hidelinks']); - - /* Lightbox specific URLs */ - if (!empty($this->_params['lightbox'])) { - $effectsurl = Horde::url($js_path . '/effects.js', true); - $lbjsurl = Horde::url($ansel_js_path . '/lightbox.js', true); - $lbcssurl = Horde::url($GLOBALS['registry']->get('themesuri', 'ansel') . '/lightbox.css', true); - } - - /* Start building the javascript */ - $html = <<'); - } - if (typeof Horde_ToolTips == 'undefined') { - document.write(''); - document.write(''); - } - - anselnodes = new Array(); - anseljson = new Object(); - document.write(''); - document.write(''); - } - anselnodes[anselnodes.length] = '$node'; - anseljson['$node'] = new Object(); - anseljson['$node']['data'] = $json; - anseljson['$node']['perpage'] = $perpage; - anseljson['$node']['page'] = 0; - anseljson['$node']['hideLinks'] = '$hideLinks'; - //]]> - -EOT; - /* Special requirements for lightbox */ - if (!empty($lbjsurl)) { - $graphic_dir = Horde::applicationUrl($GLOBALS['registry']->getImageDir(), true, -1); - $imageText = _("Photo"); - $labelOf = _("of"); - $html .= <<'); - } - - /* Make sure we only include this stuff once */ - if (typeof lbOptions == 'undefined') { - - document.write(''); - document.write(''); - - lbOptions = { - fileLoadingImage: '$graphic_dir/lightbox/loading.gif', - fileBottomNavCloseImage: '$graphic_dir/lightbox/closelabel.gif', - overlayOpacity: 0.8, - animate: true, - resizeSpeed: 7, - borderSize: 10, - labelImage: '$imageText', - labelOf: '$labelOf', - returnURL: '#', - startPage: 0 - } - } - anseljson['$node']['lightbox'] = $json_full; -EOT; - } - return $html; - } - -} diff --git a/ansel/lib/Views/EmbeddedRenderers/Slideshow.php b/ansel/lib/Views/EmbeddedRenderers/Slideshow.php deleted file mode 100644 index 9a624fed2..000000000 --- a/ansel/lib/Views/EmbeddedRenderers/Slideshow.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_EmbeddedRenderer_Slideshow extends Ansel_View_Gallery { - - /** - * Create a new renderer. - * - * @see Ansel_View_Embedded - * - * @param array $params - * - * @return Ansel_View_EmbeddedRenderer The renderer object. - */ - function makeView($params = array()) - { - $view = new Ansel_View_EmbeddedRenderer_Carousel(); - $view->_params = $params; - - return $view; - } - - /** - * Build the javascript that will render the view. - * - * @return string A string containing valid javascript. - */ - function html() - { - - } - -} diff --git a/ansel/lib/Views/Gallery.php b/ansel/lib/Views/Gallery.php deleted file mode 100644 index a08559e63..000000000 --- a/ansel/lib/Views/Gallery.php +++ /dev/null @@ -1,202 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_Gallery extends Ansel_View_Abstract { - - /** Holds the object that does the actual rendering **/ - var $_renderer; - - /** - * @static - * - * @param array $params Any parameters that the view might need. - *
-     * gallery_id              The gallery id this view is for. If omitted, it
-     *                         looks for a query parameter called 'gallery'
-     *
-     * gallery_slug            Same as above, but a slug
-     *
-     * gallery_view_url        If set, this is used as the link to a gallery
-     *                         view. %g is replaced by the gallery_id and %s is
-     *                         replaced by the gallery_slug.
-     *
-     * gallery_view            The specific Renderer to use, if needed.
-     *                         (GalleryLightbox, Gallery etc...).
-     *
-     * image_view_url          If this is set, the image tiles will use this url
-     *                         for the image view link. %i and %g will be
-     *                         replaced by image_id and gallery_id respectively.
-     *                         %s will be replaced by the gallery_slug
-     *
-     * image_view_src          If this is set to true, the image view link will go
-     *                         directly to the actual image. This overrides any
-     *                         setting of image_view_url.
-     *
-     * image_view_attributes   An optional array of attribute => value pairs
-     *                         that are used as attributes of the image view
-     *                         link.
-     *
-     * image_view_title        Specifies which property of the image object
-     *                         to use as the image caption.
-     *
-     * image_onclick           Specifies a onclick handler for the image tile
-     *                         links.
-     *
-     * style                   Force the use of this named style.
-     *
-     * api                     If set, we are being called from the external api
-     *
-     * page                    The gallery page number to display if not the
-     *                         default value of the first page (page = 0)
-     *
-     * day, month, year        Numeric date part values to describe the gallery
-     *                         date grouping to view in date mode.
-     *
-     * force_date_grouping     Do not auto navigate to the first date grouping
-     *                         with more then one resource. Used from the api
-     *                         when clicking on breadcrumb links, for example.
-     * 
- * - * @TODO use exceptions from the constructor instead of static - * instance-getting. - */ - function makeView($params = array()) - { - $view = new Ansel_View_Gallery(); - - if (count($params)) { - $view->_params = $params; - } - - if (!empty($params['gallery_slug'])) { - $view->gallery = $view->getGallery(null, $params['gallery_slug']); - } elseif (!empty($params['gallery_id'])) { - $view->gallery = $view->getGallery($params['gallery_id']); - } else { - $view->gallery = $view->getGallery(); - } - - if (is_a($view->gallery, 'PEAR_Error')) { - return $view->gallery; - } - - // Check user age - if (!$view->gallery->isOldEnough()) { - if (!empty($params['api'])) { - return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); - } - $date = Ansel::getDateParameter( - array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, - 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, - 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); - - $galleryurl = Ansel::getUrlFor('view', array_merge( - array('gallery' => $view->gallery->id, - 'slug' => empty($params['slug']) ? '' : $params['slug'], - 'page' => empty($params['page']) ? 0 : $params['page'], - 'view' => 'Gallery'), - $date), - true); - - $params = array('gallery' => $view->gallery->id, 'url' => $galleryurl); - header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('disclamer.php'), $params, null, false)); - exit; - } - - if ($view->gallery->hasPasswd()) { - if (!empty($params['api'])) { - return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); - } - $date = Ansel::getDateParameter( - array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, - 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, - 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); - - $galleryurl = Ansel::getUrlFor('view', array_merge( - array('gallery' => $view->gallery->id, - 'slug' => empty($params['slug']) ? '' : $params['slug'], - 'page' => empty($params['page']) ? 0 : $params['page'], - 'view' => 'Gallery'), - $date), - true); - - $params = array('gallery' => $view->gallery->id, 'url' => $galleryurl); - header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('protect.php'), $params, null, false)); - exit; - } - - if (!$view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { - return PEAR::raiseError(_("Access denied viewing this gallery.")); - } - - // Since this is a gallery view, the resource is just a reference to the - // gallery. We keep both instance variables becuase both gallery and - // image views are assumed to have a gallery object. - $view->resource = &$view->gallery; - - /* Do we have an explicit style set? If not, use the gallery's */ - if (!empty($view->_params['style'])) { - $style = Ansel::getStyleDefinition($view->_params['style']); - } else { - $style = $view->gallery->getStyle(); - } - - if (!empty($view->_params['gallery_view'])) { - $renderer = $view->_params['gallery_view']; - } else { - $renderer = (!empty($style['gallery_view'])) ? $style['gallery_view'] : 'Gallery'; - } - /* Load the helper */ - $classname = 'Ansel_View_GalleryRenderer_' . basename($renderer); - $view->_renderer = new $classname($view); - $view->_renderer->init(); - - return $view; - } - - function getGalleryCrumbData() - { - return $this->gallery->getGalleryCrumbData(); - } - - /** - * Get this gallery's title. - * - * @return string The gallery's title. - */ - function getTitle() - { - if (is_a($this->gallery, 'PEAR_Error')) { - return $this->gallery->getMessage(); - } - return $this->gallery->get('name'); - } - - /** - * Return the HTML representing this view. - * - * @return string The HTML. - * - */ - function html() - { - return $this->_renderer->html(); - } - - function viewType() - { - return 'Gallery'; - } - -} diff --git a/ansel/lib/Views/GalleryRenderer.php b/ansel/lib/Views/GalleryRenderer.php deleted file mode 100644 index 3056fd4fa..000000000 --- a/ansel/lib/Views/GalleryRenderer.php +++ /dev/null @@ -1,219 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_GalleryRenderer { - - /** - * The Ansel_View_Gallery object that this Renderer belongs to. - * - * @var Ansel_View_Gallery - */ - var $view; - - /** - * The gallery id for this view's gallery - * - * @var integer - */ - var $galleryId; - - /** - * Gallery slug for current gallery. - * - * @var string - */ - var $gallerySlug; - - /** - * The current page we are viewing - * - * @var integer - */ - var $page = 0; - - /** - * The display mode of the current gallery. - * 0 == Normal - * 1 == Group by date - * - * @var integer - */ - var $mode; - - /** - * The style definition array for this gallery. - * - * @var array - */ - var $style; - - /** - * Holds number of tiles to display per page - * - * @var integer - */ - var $perpage; - - /** - * The tile number we are starting with on the current page. - * - * @var integer - */ - var $pagestart; - - /** - * The last tile number on the current page. - * - * @var integer - */ - var $pageend; - - /** - * The total number of tiles that this view contains - * - * @var integer - */ - var $numTiles; - - /** - * The Ansel_Image or Ansel_DateGallery objects that appear on the current - * page in the current view. - * - * @var array of Ansel_Image or Ansel_DateGallery objects. - */ - var $children; - - /** - * If we are grouping by date, this holds the currently selected date parts. - * - * @var array containing sufficient date parts for the current depth. - */ - var $date = array(); - - /** - * Constructor - * - * @param Ansel_View_Gallery The view object for this renderer. - * - * @return Ansel_View_Renderer_Gallery - */ - function Ansel_View_GalleryRenderer($view) - { - $this->view = $view; - } - - /** - * Initialize the renderer. This *must* be called before any attempt is made - * to display or otherwise interact with the renderer. - * - */ - function init() - { - global $prefs, $conf; - - $this->galleryId = $this->view->gallery->id; - $this->gallerySlug = $this->view->gallery->get('slug'); - if (isset($this->view->_params['page'])) { - $this->page = $this->view->_params['page']; - } - - /* Number perpage from prefs or config */ - $this->perpage = min($prefs->getValue('tilesperpage'), - $conf['thumbnail']['perpage']); - - /* Calculate the starting and ending images on this page */ - $this->pagestart = ($this->page * $this->perpage) + 1; - - /* Fetch the children */ - $this->fetchChildren($this->view->_params['force_grouping']); - - /* Do we have an explicit style set? If not, use the gallery's */ - if (!empty($this->view->_params['style'])) { - $this->style = Ansel::getStyleDefinition($this->view->_params['style']); - } else { - $this->style = $this->view->gallery->getStyle(); - } - - /* Include any widgets */ - if (!empty($this->style['widgets'])) { - /* Special case widgets - these are built in */ - if (array_key_exists('Actions', $this->style['widgets'])) { - /* Don't show action widget if no actions */ - if (Horde_Auth::getAuth() || - !empty($conf['report_content']['driver']) && - (($conf['report_content']['allow'] == 'authenticated' && Horde_Auth::isAuthenticated()) || - $conf['report_content']['allow'] == 'all')) { - - $this->view->addWidget(Ansel_Widget::factory('Actions')); - } - unset($this->style['widgets']['Actions']); - } - - // I *think* this is more efficient, iterate over the children - // since we already have them instead of calling listImages. - //$image_ids = $this->view->gallery->listImages($this->pagestart, $this->pagestart + $this->perpage); - $ids = array(); - foreach ($this->children as $child) { - if (is_a($child, 'Ansel_Image')) { - $ids[] = $child->id; - } - } - // Gallery widgets always receive an array of image ids for - // the current page. - foreach ($this->style['widgets'] as $wname => $wparams) { - $wparams = array_merge($wparams, array('images' => $ids)); - $this->view->addWidget(Ansel_Widget::factory($wname, $wparams)); - } - } - - /* See if any renderer specific tasks need to be done as well */ - $this->_init(); - } - - /** - * Default implementation for fetching children/images for this view. - * Other view classes can override this if they need anything special. - * - */ - function fetchChildren($noauto) - { - /* Total number of tiles for this gallery view */ - $this->numTiles = $this->view->gallery->countGalleryChildren(PERMS_SHOW, false, $noauto); - - /* Children to display on this page */ - $this->children = $this->view->gallery->getGalleryChildren( - PERMS_SHOW, - $this->page * $this->perpage, - $this->perpage, - !empty($this->view->_params['force_grouping'])); - - /* The last tile number to display on the current page */ - $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1); - } - - /** - * Return the HTML for this view. Done this way so we can override this in - * subclasses if desired. - * - * @return string - */ - function html() - { - if (is_a($this->view->gallery, 'PEAR_Error')) { - echo htmlspecialchars($this->view->gallery->getMessage(), ENT_COMPAT, Horde_Nls::getCharset()); - return; - } - - return $this->_html(); - } - -} diff --git a/ansel/lib/Views/GalleryRenderers/Gallery.php b/ansel/lib/Views/GalleryRenderers/Gallery.php deleted file mode 100644 index af87d8206..000000000 --- a/ansel/lib/Views/GalleryRenderers/Gallery.php +++ /dev/null @@ -1,131 +0,0 @@ - - * @package Ansel - */ -require_once ANSEL_BASE . '/lib/Views/GalleryRenderer.php'; - -class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer { - - /** - * Perform any tasks that should be performed before the view is rendered. - * - */ - function _init() - { - } - - /** - * Return the HTML representing this view. - * - * @return string The HTML. - * - */ - function _html() - { - global $conf, $prefs, $registry; - - $galleryOwner = $this->view->gallery->get('owner'); - $id = $this->view->gallery->getOwner(); - $owner = $id->getValue('fullname'); - if (!$owner) { - $owner = $galleryOwner; - } - - /* Only need these if not being called via the api */ - if (empty($this->view->_params['api'])) { - $option_edit = $this->view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT); - $option_select = $option_delete = $this->view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE); - $option_move = ($option_delete && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); - $option_copy = ($option_edit && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); - /* See if we requested a show_actions change */ - if (Horde_Util::getFormData('actionID', '') == 'show_actions') { - $prefs->setValue('show_actions', (int)!$prefs->getValue('show_actions')); - } - } - - /* Set up the pager */ - $date_params = Ansel::getDateParameter( - array('year' => isset($this->view->_params['year']) ? $this->view->_params['year'] : 0, - 'month' => isset($this->view->_params['month']) ? $this->view->_params['month'] : 0, - 'day' => isset($this->view->_params['day']) ? $this->view->_params['day'] : 0)); - - $vars = Horde_Variables::getDefaultVariables(); - if (!empty($this->view->_params['page'])) { - $vars->add('page', $this->view->_params['page']); - } - if (!empty($this->view->_params['gallery_view_url'])) { - $pagerurl = str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->_params['gallery_view_url'])); - $pagerurl = Horde_Util::addParameter($pagerurl, $date_params); - } 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); - } - - /* See what callback to use to tweak the pager urls */ - if (!empty($this->view->_params['urlCallback'])) { - $callback = $this->view->_params['urlCallback']; - } else { - $callback = null; - } - $params = array('num' => $this->numTiles, - 'url' => $pagerurl, - 'perpage' => $this->perpage, - 'url_callback' => $callback); - - $pager = new Horde_UI_Pager('page', $vars, $params); - - // Note that we can't use Horde_Util::bufferOutput() here since the include - // file would be included inside that method's scope, and not this one. - ob_start(); - if (!empty($this->view->_params['api'])) { - $includes = new Horde_Script_Files(); - $includes->disableAutoloadHordeJS(); - $includes->_add('prototype.js', 'horde', true, true); - $includes->includeFiles(); - } - - /* Needed in the template files */ - $tilesperrow = $prefs->getValue('tilesperrow'); - $cellwidth = round(100 / $tilesperrow); - $count = 0; - $action_links = array(); - if ($GLOBALS['conf']['gallery']['downloadzip']) { - $action_links[] = Horde::link('#', '', 'widget', '', 'downloadSelected(); return false;') . _("Download selected images") . ''; - - } - if (!empty($option_edit)) { - $action_links[] = Horde::link('#', '', 'widget', '', 'editDates(); return false;') . _("Edit Dates") . ''; - } - if (!empty($option_delete)) { - $action_links[] = Horde::link('#', '', 'widget', '', 'deleteSelected(); return false;') . _("Delete") . ''; - } - if (!empty($option_move)) { - $action_links[] = Horde::link('#', '', 'widget', '', 'moveSelected(); return false;') . _("Move") . ''; - } - if (!empty($option_copy)) { - $action_links[] = Horde::link('#', '', 'widget', '', 'copySelected(); return false;') . _("Copy") . ''; - } - - include ANSEL_TEMPLATES . '/view/gallery.inc'; - return ob_get_clean(); - } - -} diff --git a/ansel/lib/Views/GalleryRenderers/GalleryLightbox.php b/ansel/lib/Views/GalleryRenderers/GalleryLightbox.php deleted file mode 100644 index 3e8e8559a..000000000 --- a/ansel/lib/Views/GalleryRenderers/GalleryLightbox.php +++ /dev/null @@ -1,156 +0,0 @@ - - * @package Ansel - */ - -require_once ANSEL_BASE . '/lib/Views/GalleryRenderer.php'; - -class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRenderer { - - /** - * Perform any tasks that should be performed before the view is rendered. - * - */ - function _init() - { - if (empty($this->view->_params['image_onclick'])) { - $this->view->_params['image_onclick'] = 'return lb.start(%i);'; - } - - // Attach the script and CSS files here if we aren't being called via the api - if (empty($this->view->_params['api'])) { - Ansel::attachStylesheet('lightbox.css'); - Horde::addScriptFile('effects.js', 'horde', true); - Horde::addScriptFile('lightbox.js', 'ansel', true); - } - } - - /** - * Get the HTML representing this view. - * - * @return string The HTML - */ - function _html() - { - global $conf, $prefs, $registry; - - $galleryOwner = $this->view->gallery->get('owner'); - $id = $this->view->gallery->getOwner(); - $owner = $id->getValue('fullname'); - if (!$owner) { - $owner = $galleryOwner; - } - - /* Get JSON data for view */ - // 0 == normal, 1 == by date - if ($this->mode == 0) { - $json = $this->view->json(null, !empty($this->view->_params['api'])); - } else { - if (!empty($this->date['day']) && $this->numTiles) { - $json = $this->view->json(null, !empty($this->view->_params['api'])); - } else { - $json = '[]'; - } - } - - /* Don't bother if we are being called from the api */ - if (empty($this->view->_params['api'])) { - $option_edit = $this->view->gallery->hasPermission(Horde_Auth::getAuth(), - PERMS_EDIT); - $option_select = $option_delete = $this->view->gallery->hasPermission( - Horde_Auth::getAuth(), PERMS_DELETE); - $option_move = ($option_delete && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); - $option_copy = ($option_edit && $GLOBALS['ansel_storage']->countGalleries(PERMS_EDIT)); - /* See if we requested a show_actions change (fallback for non-js) */ - if (Horde_Util::getFormData('actionID', '') == 'show_actions') { - $prefs->setValue('show_actions', (int)!$prefs->getValue('show_actions')); - } - } - - /* Set up the pager */ - $date_params = Ansel::getDateParameter( - array('year' => isset($this->view->_params['year']) ? $this->view->_params['year'] : 0, - 'month' => isset($this->view->_params['month']) ? $this->view->_params['month'] : 0, - 'day' => isset($this->view->_params['day']) ? $this->view->_params['day'] : 0)); - - $vars = Horde_Variables::getDefaultVariables(); - if (!empty($this->view->_params['page'])) { - $vars->add('page', $this->view->_params['page']); - $page = $this->view->_params['page']; - } else { - $page = 0; - } - if (!empty($this->view->_params['gallery_view_url'])) { - $pagerurl = str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->_params['gallery_view_url'])); - $pagerurl = Horde_Util::addParameter($pagerurl, $date_params, null, false); - } 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); - } - - if (!empty($this->view->_params['urlCallback'])) { - $callback = $this->view->_params['urlCallback']; - } else { - $callback = null; - } - $params = array('num' => $this->numTiles, - 'url' => $pagerurl, - 'perpage' => $this->perpage, - 'url_callback' => $callback); - - $pager = new Horde_UI_Pager('page', $vars, $params); - - /* Start buffering */ - ob_start(); - - /* Create the js variables to pass to the lightbox script */ - $jsvars = array('graphics_dir' => Horde::applicationUrl($registry->getImageDir(), true, -1), - 'image_text' => _("Photo"), - 'of_text' => _("of"), - 'start_page' => $page); - - $flipped = array_flip($date_params); - if (count($flipped) == 1 && !empty($flipped[0])) { - $jsvars['gallery_url'] = $pagerurl . '?'; - } else { - $jsvars['gallery_url'] = $pagerurl . '&'; - } - /* Output js/css here if we are calling via the api */ - if (!empty($this->view->_params['api'])) { - Ansel::attachStylesheet('lightbox.css', true); - $includes = new Horde_Script_Files(); - $includes->disableAutoloadHordeJS(); - $includes->_add('accesskeys.js', 'horde', true, true); - $includes->_add('effects.js', 'horde', true, true); - $includes->_add('lightbox.js', 'ansel', true, true); - $includes->includeFiles(); - } - - /* Needed in the template files */ - $tilesperrow = $prefs->getValue('tilesperrow'); - $cellwidth = round(100 / $tilesperrow); - $count = 0; - - include ANSEL_TEMPLATES . '/view/gallerylightbox.inc'; - return ob_get_clean(); - } - -} diff --git a/ansel/lib/Views/GalleryRenderers/GalleryVimeo.php b/ansel/lib/Views/GalleryRenderers/GalleryVimeo.php deleted file mode 100644 index db0602449..000000000 --- a/ansel/lib/Views/GalleryRenderers/GalleryVimeo.php +++ /dev/null @@ -1,192 +0,0 @@ - - * @package Ansel - */ -require_once ANSEL_BASE . '/lib/Views/GalleryRenderer.php'; - -class Ansel_View_GalleryRenderer_GalleryVimeo extends Ansel_View_GalleryRenderer { - /** - * - * @var Horde_Service_Vimeo object - */ - var $_vimeo; - var $_thumbs; - - /** - * Perform any tasks that should be performed before the view is rendered. - * - */ - function _init() - { - // Attach the script and CSS files here if we aren't being called via the api - if (empty($this->view->_params['api'])) { - Horde::addScriptFile('effects.js', 'horde', true); - Horde::addScriptFile('redbox.js', 'horde', true); - } - } - - /** - * Override the parent class' fetchChildren method so we can grab the video - * thumbnail information from Vimeo instead of from our local image storage. - * - * @param boolean $noauto Ignored in this class since we won't be doing any - * date browsing. Maybe another experiment? ;) - */ - function fetchChildren($noauto = true) - { - // Build a Horde_Service_Vimeo object - // It *requires* a http client object and can make use of a cache object, - // so let's take advantage of it. - $params = array('http_client' => new Horde_Http_Client(), - 'cache' => $GLOBALS['cache'], - 'cache_lifetime' => $GLOBALS['conf']['cache']['default_lifetime']); - - $this->_vimeo = Horde_Service_Vimeo::factory('Simple', $params); - - // The identifier for what we are requesting. - // If we are requesting a user's videos, this is the user's vimeo_id - // if we want to request a particular group, this would be the group_id - // etc... - // - // For this example, the id is hard coded here, but if I were to implement - // this on a live site I would add a new user pref to ansel for the - // user to enter his/her own vimeo_id and then grab the value from - // pref storage here. - $vimeo_id = 'user1015172'; //TODO: Get this from prefs? - - // This gets the data representing the videos. See the API docs for - // exactly what is returned, but for our purposes, we will be using: - // clip_id, url, caption, thumbnail_large etc... - $thumbs = unserialize($this->_vimeo->user($vimeo_id)->clips()->run()); - - // We fetch the information needed to embed each video now to make things - // easier for this example...the cache helps tremendously with load times - // after the first page is requested. - foreach ($thumbs as $thumb) { - $this->_json[$thumb['clip_id']] = $this->_vimeo->getEmbedJSON(array('url' => $thumb['url'], 'byline' => 'false', 'portrait' => 'false')); - $this->_thumbs[$thumb['clip_id']] = $thumb; - } - - // Vimeo's Simple API doesn't provide for paging - so we emulate it - // by only returning the video thumbnails that should appear on this - // current gallery page. Like stated above, the first load will take - // a bit of time depending on the number of videos the user has - but - // each subsequent page will load *much* faster as we don't have to - // contact Vimeo at all. - - // Total number of thumbnails in the gallery - $this->numTiles = count($thumbs); - - // The last one to display on this page - $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1); - - - $this->children = $this->view->gallery->getGalleryChildren( - PERMS_SHOW, - $this->page * $this->perpage, - $this->perpage, - !empty($this->view->_params['force_grouping'])); - } - - /** - * Get the HTML representing this view. - * - * Responsible for building the HTML for the view. It's stripped down - * somewhat from the other styles...sets up the variables needed for the - * template we put in ansel/templates/view - though there is really no - * reason we *have* to have a template file there if we can generate the - * entire HTML here, or load a template from this directory or....? - * - * @return string The HTML - */ - function _html() - { - global $conf, $prefs, $registry; - - // Deal with getting the correct gallery owner string, get any - // parameters we are interested in from the view - $galleryOwner = $this->view->gallery->get('owner'); - $id = $this->view->gallery->getOwner(); - $owner = $id->getValue('fullname'); - if (!$owner) { - $owner = $galleryOwner; - } - $vars = Horde_Variables::getDefaultVariables(); - if (!empty($this->view->_params['page'])) { - $vars->add('page', $this->view->_params['page']); - $page = $this->view->_params['page']; - } else { - $page = 0; - } - - // Build the proper pager urls - if (!empty($this->view->_params['gallery_view_url'])) { - $pagerurl = str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->_params['gallery_view_url'])); - } 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('gallery' => $this->galleryId, - 'view' => 'Gallery', - 'slug' => $this->view->gallery->get('slug')); - $pagerurl = Ansel::getUrlfor('view', $pager_params, true); - } - if (!empty($this->view->_params['urlCallback'])) { - $callback = $this->view->_params['urlCallback']; - } else { - $callback = null; - } - $params = array('num' => $this->numTiles, - 'url' => $pagerurl, - 'perpage' => $this->perpage, - 'url_callback' => $callback); - - $pager = new Horde_UI_Pager('page', $vars, $params); - - /* Start buffering */ - ob_start(); - - /* Output js/css here if we are calling via the api */ - if (!empty($this->view->_params['api'])) { - $includes = new Horde_Script_Files(); - $includes->disableAutoloadHordeJS(); - $includes->_add('redbox.js', 'horde', true, true); - $includes->includeFiles(); - } - - /* Needed in the template files */ - $tilesperrow = $prefs->getValue('tilesperrow'); - $cellwidth = round(100 / $tilesperrow); - $count = 0; - - include ANSEL_TEMPLATES . '/view/galleryvimeo.inc'; - return ob_get_clean(); - } - - function getTile($image, $video, $cnt) - { - $imgOnClick = 'return showVideo(' . $cnt . ');'; - $tile = '
' - . Horde::link($video->url, $video->title, '', '', $imgOnClick, $video->title) - . '' . ''; - $tile .= '
'; - $tile .= '
' . $video->caption . '
'; - - return $tile; - } - -} diff --git a/ansel/lib/Views/Image.php b/ansel/lib/Views/Image.php deleted file mode 100644 index 69a116839..000000000 --- a/ansel/lib/Views/Image.php +++ /dev/null @@ -1,407 +0,0 @@ - - * @package Ansel - */ - -/** Ansel_View_Abstract */ -require_once ANSEL_BASE . '/lib/Views/Abstract.php'; - -class Ansel_View_Image extends Ansel_View_Abstract { - - /** - * The image selected for this view. - * - * @var Ansel_Image - */ - var $image; - - /** - * @static - * - * @TODO use exceptions from the constructor instead of static - * instance-getting. - */ - function makeView($params = array()) - { - /* Get the image */ - $image_id = $params['image_id']; - - $image = &$GLOBALS['ansel_storage']->getImage($image_id); - if (is_a($image, 'PEAR_Error')) { - return $image; - } - - /* Create the Ansel_View object */ - $view = new Ansel_View_Image; - - /* Save params */ - if (count($params)) { - $view->_params = $params; - } - - $view->gallery = $view->getGallery(); - if (is_a($view->gallery, 'PEAR_Error')) { - return $view->gallery; - } - - /* Save the image reference */ - $view->resource = $image; - - // Check user age - if (!$view->gallery->isOldEnough()) { - if (!empty($params['api'])) { - return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); - } - $date = Ansel::getDateParameter( - array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, - 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, - 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); - - $url = Ansel::getUrlFor('view', array_merge( - array('gallery' => $view->gallery->id, - 'slug' => empty($params['slug']) ? '' : $params['slug'], - 'page' => empty($params['page']) ? 0 : $params['page'], - 'view' => 'Image', - 'image' => $image->id), - $date), - true); - - $params = array('gallery' => $view->gallery->id, 'url' => $url); - - header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('disclamer.php'), $params, null, false)); - exit; - } - - // Check password - if ($view->gallery->hasPasswd()) { - if (!empty($params['api'])) { - return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); - } - $date = Ansel::getDateParameter( - array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, - 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, - 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); - - $url = Ansel::getUrlFor('view', array_merge( - array('gallery' => $view->gallery->id, - 'slug' => empty($params['slug']) ? '' : $params['slug'], - 'page' => empty($params['page']) ? 0 : $params['page'], - 'view' => 'Image', - 'image' => $image->id), - $date), - true); - - $params = array('gallery' => $view->gallery->id, 'url' => $url); - - header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('protect.php'), $params, null, false)); - exit; - } - - - /* Any script files we may need if not calling via the api */ - if (empty($view->_params['api'])) { - Horde::addScriptFile('effects.js', 'horde', true); - Horde::addScriptFile('stripe.js', 'horde', true); - } - - return $view; - } - - function getGalleryCrumbData() - { - return $this->gallery->getGalleryCrumbData(); - } - - /** - * Get the title for this view. - * - * @return string The title. - */ - function getTitle() - { - return $this->resource->filename; - } - - /** - * Get the HTML representing this view. - * - * @return string The HTML. - */ - function html() - { - global $browser, $conf, $prefs, $registry; - - if (is_a($this->gallery, 'PEAR_Error')) { - echo htmlspecialchars($this->gallery->getMessage()); - return; - } - - $page = isset($this->_params['page']) ? $this->_params['page'] : 0; - $galleryId = $this->gallery->id; - $gallerySlug = $this->gallery->get('slug'); - $imageId = $this->resource->id; - $galleryOwner = $this->gallery->get('owner'); - $date = $this->gallery->getDate(); - - /* Allow overriding the configured view_mode */ - if (isset($this->_params['mode'])) { - $mode = $this->_params['mode']; - } else { - $mode = $this->_params['mode'] = $this->gallery->get('view_mode'); - } - - /* Get any date infor the gallery has */ - $date = $this->gallery->getDate(); - - $style = (empty($this->_params['style']) ? - $this->gallery->getStyle() : - Ansel::getStyleDefinition($this->_params['style'])); - - /* Make sure the screen view is loaded and get the geometry */ - $geometry = $this->resource->getDimensions('screen'); - if (is_a($geometry, 'PEAR_Error')) { - Horde::logMessage($geometry->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); - $geometry = $conf['screen']; - } - - /* Get comments before any output in sent. */ - if (($conf['comments']['allow'] == 'all' || ($conf['comments']['allow'] == 'authenticated' && Horde_Auth::getAuth())) && - $registry->hasMethod('forums/doComments')) { - $hasComments = true; - $url = empty($this->_params['comment_url']) ? null : $this->_params['comment_url']; - $comments = $registry->call('forums/doComments', - array('ansel', $imageId, - 'commentCallback', true, null, - $url)); - if (is_a($comments, 'PEAR_Error')) { - Horde::logMessage($comments, __FILE__, __LINE__, PEAR_LOG_DEBUG); - $comments = array(); - } - } else { - $comments = array(); - $hasComments = false; - } - - /* Get the index of the starting image */ - $imageList = $this->gallery->listImages(); - $revList = array_flip($imageList); - $imageIndex = $revList[$imageId]; - - /* Not needed when being called via api */ - if (empty($this->_params['api'])) { - $ecardurl = Horde::applicationUrl( - Horde_Util::addParameter('img/ecard.php', array_merge( - array('gallery' => $galleryId, - 'image' => $imageId), - $date)), - true); - - $imageActionUrl = Horde_Util::addParameter( - 'image.php', array_merge( - array('gallery' => $galleryId, - 'image' => $imageId, - 'page' => $page), - $date)); - } - - /* Check for an explicit gallery view url to use */ - if (!empty($this->_params['gallery_view_url'])) { - $galleryurl = str_replace( - array('%g', '%s'), - array($galleryId, $gallerySlug), - urldecode($this->_params['gallery_view_url'])); - Horde_Util::addParameter($galleryurl, $date); - } else { - $galleryurl = Ansel::getUrlFor('view', array_merge( - array('gallery' => $galleryId, - 'slug' => $gallerySlug, - 'page' => $page, - 'view' => 'Gallery'), - $date), - true); - } - - /* Get the image src url */ - $imageUrl = Ansel::getImageUrl($imageId, 'screen', true, $style['name']); - - /* And a self url. Can't use Horde::selfUrl() since that would ignore - * pretty urls. */ - $selfUrl = Ansel::getUrlFor('view', array_merge( - array('gallery' => $galleryId, - 'slug' => $gallerySlug, - 'image' => $imageId, - 'view' => 'Image', - 'page' => $page), - $date)); - - /* Get the next and previous image ids */ - if (isset($imageList[$imageIndex + 1])) { - $next = $imageList[$imageIndex + 1]; - } else { - $next = $imageList[0]; - } - if (isset($imageList[$imageIndex - 1])) { - $prev = $imageList[$imageIndex - 1]; - } else { - $prev = $imageList[count($imageList) - 1]; - } - - /** Calculate the page number of the next/prev images */ - $perpage = $prefs->getValue('tilesperpage'); - $pagestart = $page * $perpage; - $pageend = min(count($imageList), $pagestart + $perpage - 1); - $page_next = $page; - - if ($revList[$imageId] + 1 > $pageend) { - $page_next++; - } - $page_prev = $page; - if ($revList[$imageId] - 1 < $pagestart) { - $page_prev--; - } - - /* Previous image link */ - if (!empty($this->_params['image_view_url'])) { - $prev_url = str_replace( - array('%i', '%g', '%s'), - array($prev, $galleryId, $gallerySlug), - urldecode($this->_params['image_view_url'])); - } else { - $prev_url = Ansel::getUrlFor('view', array_merge( - array('gallery' => $galleryId, - 'slug' => $gallerySlug, - 'image' => $prev, - 'view' => 'Image', - 'page' => $page_prev), - $date)); - } - $prvImgUrl = Ansel::getImageUrl($prev, 'screen', false, $style['name']); - - /* Next image link */ - if (!empty($this->_params['image_view_url'])) { - $next_url = str_replace( - array('%i', '%g', '%s'), - array($prev, $galleryId, $gallerySlug), - urldecode($this->_params['image_view_url'])); - } else { - $next_url = Ansel::getUrlFor('view', array_merge( - array('gallery' => $galleryId, - 'slug' => $gallerySlug, - 'image' => $next, - 'view' => 'Image', - 'page' => $page_next), - $date)); - } - $nextImgUrl = Ansel::getImageUrl($next, 'screen', false, $style['name']); - - /* Slideshow link */ - if (!empty($this->_params['slideshow_link'])) { - $slideshow_url = str_replace(array('%i', '%g'), - array($imageId, $galleryId), - urldecode($this->_params['slideshow_link'])); - } else { - $slideshow_url = Horde::applicationUrl( - Horde_Util::addParameter('view.php', array_merge( - array('gallery' => $galleryId, - 'image' => $imageId, - 'view' => 'Slideshow'), - $date))); - } - - $commentHtml = ''; - if (isset($hasComments)) { - if (!empty($comments['threads'])) { - $commentHtml .= '
' . $comments['threads']; - } - if (!empty($comments['comments'])) { - $commentHtml .= '
' . $comments['comments']; - } - } - - if ($prefs->getValue('showexif')) { - require_once ANSEL_BASE . '/lib/Exif.php'; - $exifHtml = $this->_getExifHtml(); - } else { - $exifHtml = ''; - } - - /* Buffer the template file and return the html */ - ob_start(); - - //@TODO: Refactor styles to allow dynamic inclusion/exclusion of widgets. - /* These items currently don't work when viewing through the api */ - if (empty($this->_params['api'])) { - /* Add the widgets */ - // Tag widget - $this->addWidget(Ansel_Widget::factory('Tags', array('view' => 'image'))); - - // Similar photos - $this->addWidget(Ansel_Widget::factory('SimilarPhotos')); - - // Geolocation - $this->addWidget(Ansel_Widget::factory('Geodata', array('images' => array($this->resource->id)))); - - // Faces - if ($conf['faces']['driver']) { - $this->addWidget(Ansel_Widget::factory('ImageFaces', array('selfUrl' => $selfUrl))); - } - - // Links - $this->addWidget(Ansel_Widget::factory('Links', array())); - - /* In line caption editing */ - if ($this->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) { - $imple = Horde_Ajax_Imple::factory(array('ansel', 'EditCaption'), - array('id' => $imageId, - 'domid' => "Caption", - 'cols' => 120)); - $imple->attach(); - } - } - - /* Output the js if we are calling via the api */ - if (!empty($this->_params['api'])) { - $includes = new Horde_Script_Files(); - $includes->disableAutoloadHordeJS(); - $includes->_add('prototype.js', 'horde', true, true); - $includes->_add('effects.js', 'horde',true, true); - $includes->_add('stripe.js', 'horde', true, true); - $includes->includeFiles(); - } - - require ANSEL_TEMPLATES . '/view/image.inc'; - return ob_get_clean(); - } - - /** - * Helper function for generating the HTML for EXIF data. - * - * @return string The HTML - */ - function _getExifHtml() - { - $data = Ansel_ImageData::getAttributes($this->resource, true); - - $html = ''; - if (count($data)) { - $data = array_chunk($data, 3); - $html .= ''; - $i = 0; - foreach ($data as $elem) { - $html .= '' . implode('', $elem) . ''; - } - $html .= '
'; - } - return $html; - } - - function viewType() - { - return 'Image'; - } - -} diff --git a/ansel/lib/Views/List.php b/ansel/lib/Views/List.php deleted file mode 100644 index 7882bf220..000000000 --- a/ansel/lib/Views/List.php +++ /dev/null @@ -1,270 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_List extends Ansel_View_Abstract { - - /** - * @static - * - * @param array $params Any parameters that the view might need. - *
-     *  In addition to the params taken by Ansel_View_Gallery, this view
-     *  can also take:
-     *
-     *  groupby      -  Group the results (owner, category etc...)
-     *
-     *  owner        -  The owner to group by
-     *
-     *  category     -  The category to group by
-     *
-     *  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.
-     *
-     * @TODO use exceptions from the constructor instead of static
-     * instance-getting.
-     */
-    function makeView($params = array())
-    {
-        $view = new Ansel_View_List;
-        $view->_params = $params;
-        return $view;
-    }
-
-    /**
-     * Get this view's title.
-     *
-     * @return string  The gallery's title.
-     */
-    function getTitle()
-    {
-        return _("Gallery List");
-    }
-
-    /**
-     * Return the HTML representing this view.
-     *
-     * @return string  The HTML.
-     *
-     */
-    function html()
-    {
-        global $conf, $prefs, $registry, $ansel_storage, $notification;
-
-        // If we aren't supplied with a page number, default to page 0.
-        if (isset($this->_params['page'])) {
-            $page = $this->_params['page'];
-        } else {
-            $page = Horde_Util::getFormData('page', 0);
-        }
-        $galleries_perpage = $prefs->getValue('tilesperpage');
-
-        // Check for grouping.
-        if (empty($this->_params['groupby'])) {
-            $groupby = Horde_Util::getFormData('groupby', $prefs->getValue('groupby'));
-        } else {
-            $groupby = $this->_params['groupby'];
-        }
-
-        if (empty($this->_params['owner'])) {
-            $owner = Horde_Util::getFormData('owner');
-            $owner = empty($owner) ? null : $owner;
-        } else {
-            $owner = $this->_params['owner'];
-        }
-
-        $special = Horde_Util::getFormData('special');
-
-        if (empty($this->_params['category'])) {
-            $category = Horde_Util::getFormData('category');
-            $category = empty($category) ? null : $category;
-        } else {
-            $category = $this->_params['category'];
-        }
-        if (!$owner && !$category && !$special && $groupby != 'none' ) {
-            header('Location: ' . Ansel::getUrlFor('group', array('groupby' => $groupby), true));
-            exit;
-        }
-
-        // We'll need this in the template.
-        $sortby = !empty($this->_params['sort']) ? $this->_params['sort'] : 'name';
-        $sortdir = isset($this->_params['sort_dir']) ? $this->_params['sort_dir'] : 0;
-
-        // If we are calling from the api, we can just pass a list of gallery
-        // ids instead of doing grouping stuff.
-        if (!empty($this->_params['api']) &&
-            !empty($this->_params['gallery_ids']) &&
-            count($this->_params['gallery_ids'])) {
-
-            $start = $page * $galleries_perpage;
-            $num_galleries = count($this->_params['gallery_ids']);
-            if ($num_galleries > $start) {
-                $getThese = array_slice($this->_params['gallery_ids'], $start, $galleries_perpage);
-                $try = $ansel_storage->getGalleries($getThese);
-                $gallerylist = array();
-                foreach ($try as $id => $gallery) {
-                    if ($gallery->hasPermission(Horde_Auth::getAuth(), PERMS_SHOW)) {
-                        $gallerylist[$id] = $gallery;
-                    }
-                }
-            } else {
-                $gallerylist = array();
-            }
-        } else {
-            // Set list filter/title
-            $filter = array();
-            if (!is_null($owner)) {
-                $filter['owner'] = $owner;
-            }
-
-            if (!is_null($category)) {
-                $filter['category'] = $category;
-            }
-
-            if ($owner) {
-                if ($owner == Horde_Auth::getAuth() && empty($this->_params['api'])) {
-                    $list_title = _("My Galleries");
-                } elseif (!empty($GLOBALS['conf']['gallery']['customlabel'])) {
-                    $uprefs = &Prefs::singleton($GLOBALS['conf']['prefs']['driver'],
-                                                'ansel', $owner, '', null, false);
-                    $fullname = $uprefs->getValue('grouptitle');
-                    if (!$fullname) {
-                        require_once 'Horde/Identity.php';
-                        $identity = &Identity::singleton('none', $owner);
-                        $fullname = $identity->getValue('fullname');
-                        if (!$fullname) {
-                            $fullname = $owner;
-                        }
-                        $list_title = sprintf(_("%s's Galleries"), $fullname);
-                    } else {
-                        $list_title = $fullname;
-                    }
-                } else {
-                    $list_title = sprintf(_("%s's Galleries"), $owner);
-                }
-            } elseif ($category || ($groupby == 'category' && $special)) {
-                if ($special == 'unfiled') {
-                    $list_title = sprintf(_("Galleries in category \"%s\""),
-                                          _("Unfiled"));
-                    $filter['category'] = '';
-                } else {
-                    $list_title = sprintf(_("Galleries in category \"%s\""), $category);
-                }
-            } else {
-                $list_title = _("Gallery List");
-            }
-
-            $num_galleries = $ansel_storage->countGalleries(
-                Horde_Auth::getAuth(), PERMS_SHOW, $filter, null, false);
-            if (is_a($num_galleries, 'PEAR_Error')) {
-                return $num_galleries->getMessage();
-            }
-
-            if ($num_galleries == 0 && empty($this->_params['api'])) {
-                if ($filter == $owner && $owner == Horde_Auth::getAuth()) {
-                    $notification->push(_("You have no photo galleries, add one!"),
-                                        'horde.message');
-                    header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('gallery.php'), 'actionID', 'add'));
-                    exit;
-                }
-                $notification->push(_("There are no photo galleries available."), 'horde.message');
-                $gallerylist = array();
-            } else {
-                $gallerylist = $ansel_storage->listGalleries(
-                    PERMS_SHOW, $filter, null, false, $page * $galleries_perpage,
-                    $galleries_perpage, $sortby, $sortdir);
-            }
-
-        }
-
-        $vars = Horde_Variables::getDefaultVariables();
-        if (!empty($this->_params['page'])) {
-            $vars->add('page', $this->_params['page']);
-        }
-
-        if (!empty($this->_params['pager_url'])) {
-            $pagerurl = $this->_params['pager_url'];
-            $override = true;
-        } else {
-            $override = false;
-            $pagerurl = Ansel::getUrlFor('view',
-                                    array('owner' => $owner,
-                                          'category' => $category,
-                                          'special' => $special,
-                                          'groupby' => $groupby,
-                                          'view' => 'List'));
-        }
-        $p_params = array('num' => $num_galleries,
-                          'url' => $pagerurl,
-                          'perpage' => $galleries_perpage);
-
-        if ($override) {
-            $p_params['url_callback'] = null;
-        }
-        $pager = new Horde_UI_Pager('page', $vars, $p_params);
-        $preserve = array('sort_dir' => $sortdir);
-        if (!empty($sortby)) {
-            $preserve['sort'] = $sortby;
-        }
-        $pager->preserve($preserve);
-
-        if ($num_galleries) {
-            $min = $page * $galleries_perpage;
-            $max = $min + $galleries_perpage;
-            if ($max > $num_galleries) {
-                $max = $num_galleries - $min;
-            }
-            $start = $min + 1;
-            $end = min($num_galleries, $min + $galleries_perpage);
-
-            if ($owner) {
-                $refresh_link = Ansel::getUrlFor('view',
-                                                 array('groupby' => $groupby,
-                                                       'owner' => $owner,
-                                                       'page' => $page,
-                                                       'view' => 'List'));
-
-            } else {
-                $refresh_link = Ansel::getUrlFor('view',
-                                                 array('view' => 'List',
-                                                       'groupby' => $groupby,
-                                                       'page' => $page,
-                                                       'category' => $category));
-            }
-
-            // Get top-level / default gallery style.
-            if (empty($this->_params['style'])) {
-                $style = Ansel::getStyleDefinition(
-                    $prefs->getValue('default_gallerystyle'));
-            } else {
-                $style = Ansel::getStyleDefinition($this->_params['style']);
-            }
-            $count = 0;
-            $width = round(100 / $prefs->getValue('tilesperrow'));
-
-            ob_start();
-            include ANSEL_TEMPLATES . '/view/list.inc';
-            $html = ob_get_clean();
-            return $html;
-        }
-        return '';
-    }
-
-    function viewType()
-    {
-        return 'List';
-    }
-
-}
diff --git a/ansel/lib/Views/Results.php b/ansel/lib/Views/Results.php
deleted file mode 100644
index 8af8b08f7..000000000
--- a/ansel/lib/Views/Results.php
+++ /dev/null
@@ -1,310 +0,0 @@
-
- * @package Ansel
- */
-class Ansel_View_Results extends Ansel_View_Abstract {
-
-    /**
-     * Instance of our tag search
-     *
-     * @var Ansel_Tag_Search
-     */
-    var $_search;
-
-    /**
-     * Gallery owner id
-     *
-     * @var string
-     */
-    var $_owner;
-
-    /**
-     * Contructor - just set some instance variables.
-     *
-     * @return Ansel_View_Results
-     */
-    function Ansel_View_Results()
-    {
-        $this->_owner = Horde_Util::getFormData('owner', null);
-        $this->_search = Ansel_Tags::getSearch(null, $this->_owner);
-    }
-
-    /**
-     * @static
-     *
-     * @return Ansel_View_Results  The view object.
-     *
-     * @TODO use exceptions from the constructor instead of static
-     * instance-getting.
-     */
-    function makeView($params = array())
-    {
-        $view = new Ansel_View_Results();
-        if (count($params)) {
-            $view->_params = $params;
-        }
-        return $view;
-    }
-
-    /**
-     * Return the title for this view.
-     *
-     * @return string The title for this view.
-     */
-    function getTitle()
-    {
-        return (!empty($this->_owner))
-                ? sprintf(_("Searching %s's photos tagged: "), $this->_owner)
-                : _("Searching all photos tagged: ");
-    }
-
-    /**
-     * Get the HTML representing this view.
-     *
-     * @return string  The HTML
-     */
-    function html()
-    {
-        global $conf, $prefs, $registry, $ansel_storage;
-
-        $page = Horde_Util::getFormData('page', 0);
-        $action = Horde_Util::getFormData('actionID', '');
-        $image_id = Horde_Util::getFormData('image');
-
-        $vars = Horde_Variables::getDefaultVariables();
-
-        // Number perpage from prefs or config.
-        $perpage = min($prefs->getValue('tilesperpage'),
-                       $conf['thumbnail']['perpage']);
-
-        switch ($action) {
-        // Image related actions
-        case 'delete':
-             if (is_array($image_id)) {
-                 $images = array_keys($image_id);
-             } else {
-                 $images = array($image_id);
-             }
-
-             foreach ($images as $image) {
-                 // Need a gallery object to delete the image, but need
-                 // the image object to get the gallery.
-                 $img = $ansel_storage->getImage($image);
-                 $gallery = $ansel_storage->getgallery($img->gallery);
-                 if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) {
-                     $GLOBALS['notification']->push(
-                        sprintf(_("Access denied deleting photos from \"%s\"."), $image),
-                                'horde.error');
-                 } else {
-                     $result = $gallery->removeImage($image);
-                    if (is_a($result, 'PEAR_Error')) {
-                        $GLOBALS['notification']->push(
-                            sprintf(_("There was a problem deleting photos: %s"),
-                                    $result->getMessage()), 'horde.error');
-                    } else {
-                        $GLOBALS['notification']->push(_("Deleted the photo."),
-                                                       'horde.success');
-                        Ansel_Tags::clearCache();
-                    }
-                 }
-             }
-
-             // Reload the browse view again to get notifications.
-             header('Location: ' . Ansel::getUrlFor('view',
-                                                    array('view' => 'Results'),
-                                                    true));
-             exit;
-
-        case 'move':
-            if (is_array($image_id)) {
-                $images = array_keys($image_id);
-            } else {
-                $images = array($image_id);
-            }
-
-            // Move the images if we're provided with at least one
-            // valid image ID.
-            $newGallery = Horde_Util::getFormData('new_gallery');
-            if ($images && $newGallery) {
-                $newGallery = $ansel_storage->getGallery($newGallery);
-                if (is_a($newGallery, 'PEAR_Error')) {
-                    $GLOBALS['notification']->push(_("Bad input."),
-                                                   'horde.error');
-                } else {
-                    // Group by gallery first, then process in bulk by gallery.
-                    $galleries = array();
-                    foreach ($images as $image) {
-                        $img = $ansel_storage->getImage($image);
-                        $galleries[$img->gallery][] = $image;
-                    }
-                    foreach ($galleries as $gallery_id => $images) {
-                        $gallery = $ansel_storage->getGallery($gallery_id);
-                        $result = $gallery->moveImagesTo($images, $newGallery);
-                        if (is_a($result, 'PEAR_Error')) {
-                            $GLOBALS['notification']->push($result, 'horde.error');
-                        } else {
-                            $GLOBALS['notification']->push(
-                                sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
-                                                 "Moved %d photos from \"%s\" to \"%s\"",
-                                                 count($images)),
-                                        count($images), $gallery->get('name'),
-                                        $newGallery->get('name')),
-                                'horde.success');
-                        }
-                    }
-                }
-            }
-
-            // Return to the image list.
-            $imageurl = Horde_Util::addParameter('view.php',
-                                           array('view' => 'Results'));
-            header('Location: ' . Ansel::getUrlFor('view',
-                                                   array('view' => 'Results'),
-                                                   true));
-            exit;
-
-        case 'copy':
-            if (is_array($image_id)) {
-                $images = array_keys($image_id);
-            } else {
-                $images = array($image_id);
-            }
-
-            // Move the images if we're provided with at least one
-            // valid image ID.
-            $newGallery = Horde_Util::getFormData('new_gallery');
-            if ($images && $newGallery) {
-                $newGallery = $ansel_storage->getGallery($newGallery);
-                if (is_a($newGallery, 'PEAR_Error')) {
-                    $GLOBALS['notification']->push(_("Bad input."),
-                                                   'horde.error');
-                } else {
-                    // Group by gallery first, then process in bulk by gallery.
-                    $galleries = array();
-                    foreach ($images as $image) {
-                        $img = $ansel_storage->getImage($image);
-                        $galleries[$img->gallery][] = $image;
-                    }
-                    foreach ($galleries as $gallery_id => $images) {
-                        $gallery = $ansel_storage->getGallery($gallery_id);
-                        $result = $gallery->copyImagesTo($images, $newGallery);
-                        if (is_a($result, 'PEAR_Error')) {
-                            $GLOBALS['notification']->push($result,
-                                                           'horde.error');
-                        } else {
-                            $GLOBALS['notification']->push(
-                                sprintf(ngettext("Copied %d photo from %s to %s",
-                                                 "Copied %d photos from %s to %s",
-                                                 count($images)),
-                                        count($images), $gallery->get('name'),
-                                        $newGallery->get('name')),
-                                'horde.success');
-                        }
-                    }
-                }
-            }
-
-            // Return to the image list.
-            $imageurl = Horde_Util::addParameter('view.php',
-                                           array('view' => 'Results'));
-            header('Location: ' . Horde::applicationUrl($imageurl, true));
-            exit;
-
-        // Tag related actions
-        case 'remove':
-            $tag = Horde_Util::getFormData('tag');
-            if (isset($tag)) {
-                $tag = Ansel_Tags::getTagIds(array($tag));
-                $tag = array_pop($tag);
-                $this->_search->removeTag($tag);
-                $this->_search->save();
-            }
-            break;
-
-        case 'add':
-        default:
-            $tag = Horde_Util::getFormData('tag');
-            if (isset($tag)) {
-                $tag = Ansel_Tags::getTagIds(array($tag));
-                $tag = array_pop($tag);
-                $this->_search->addTag($tag);
-                $this->_search->save();
-            }
-            break;
-        }
-
-        // Check for empty tag search and redirect if empty
-        if ($this->_search->tagCount() < 1) {
-            header('Location: ' . Horde::applicationUrl('browse.php', true));
-            exit;
-        }
-
-        // Get the slice of galleries/images to view on this page.
-        $results = $this->_search->getSlice($page, $perpage);
-        $total = $this->_search->count();
-        $total = $total['galleries'] + $total['images'];
-
-        // The number of resources to display on this page.
-        $numimages = count($results);
-
-        // Get any related tags to display.
-        if ($conf['tags']['relatedtags']) {
-            $rtags = $this->_search->getRelatedTags();
-            $rtaghtml = '
    '; - $links = Ansel_Tags::getTagLinks($rtags, 'add'); - foreach ($rtags as $id => $taginfo) { - if (!empty($this->_owner)) { - $links[$id] = Horde_Util::addParameter($links[$id], 'owner', - $this->_owner); - } - $rtaghtml .= '
  • ' . Horde::link($links[$id], - sprintf(ngettext( - "%d photo", "%d photos", - $taginfo['total']), - $taginfo['total'])) - . $taginfo['tag_name'] . '
  • '; - } - $rtaghtml .= '
'; - } - $styleDef = Ansel::getStyleDefinition( - $GLOBALS['prefs']->getValue('default_gallerystyle')); - $style = $styleDef['name']; - $viewurl = Horde_Util::addParameter('view.php', array('view' => 'Results', - 'actionID' => 'add')); - - $vars = Horde_Variables::getDefaultVariables(); - $option_move = $option_copy = $ansel_storage->countGalleries(PERMS_EDIT); - - - $pagestart = ($page * $perpage) + 1; - $pageend = min($pagestart + $numimages - 1, $pagestart + $perpage - 1); - $pager = new Horde_UI_Pager('page', $vars, array('num' => $total, - 'url' => $viewurl, - 'perpage' => $perpage)); - ob_start(); - include ANSEL_TEMPLATES . '/view/results.inc'; - return ob_get_clean(); - } - - function viewType() - { - return 'Results'; - } - -} diff --git a/ansel/lib/Views/Slideshow.php b/ansel/lib/Views/Slideshow.php deleted file mode 100644 index 038a5f8ca..000000000 --- a/ansel/lib/Views/Slideshow.php +++ /dev/null @@ -1,179 +0,0 @@ - - * @author Michael J. Rubinsky - * @package Ansel - */ - -/** Ansel_View_Abstract */ -require_once ANSEL_BASE . '/lib/Views/Abstract.php'; - -class Ansel_View_Slideshow extends Ansel_View_Abstract { - - /** - * The Ansel_Image object representing the first image selected for view. - * - * @var Ansel_Image - */ - var $image; - - /** - * @static - * - * @return Ansel_View_Slidshow The view object. - * - * @TODO use exceptions from the constructor instead of static - * instance-getting. - */ - function makeView($params = array()) - { - if (empty($params['image_id'])) { - $image_id = Horde_Util::getFormData('image'); - } else { - $image_id = $params['image_id']; - } - $image = $GLOBALS['ansel_storage']->getImage($image_id); - if (is_a($image, 'PEAR_Error')) { - return $image; - } - - $view = new Ansel_View_Slideshow(); - if (count($params)) { - $view->_params = $params; - } - $view->gallery = $view->getGallery($image->gallery); - if (is_a($view->gallery, 'PEAR_Error')) { - return $view->gallery; - } - $view->image = $image; - - // Check user age - if (!$view->gallery->isOldEnough()) { - $date = Ansel::getDateParameter( - array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, - 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, - 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); - - $url = Ansel::getUrlFor('view', array_merge( - array('gallery' => $view->gallery->id, - 'slug' => empty($params['slug']) ? '' : $params['slug'], - 'page' => empty($params['page']) ? 0 : $params['page'], - 'view' => 'Slideshow', - 'image' => $image->id), - $date), - true); - - $params = array('gallery' => $view->gallery->id, 'url' => $url); - - header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('disclamer.php'), $params, null, false)); - exit; - } - - // Check password - if ($view->gallery->hasPasswd()) { - $date = Ansel::getDateParameter( - array('year' => isset($view->_params['year']) ? $view->_params['year'] : 0, - 'month' => isset($view->_params['month']) ? $view->_params['month'] : 0, - 'day' => isset($view->_params['day']) ? $view->_params['day'] : 0)); - - $url = Ansel::getUrlFor('view', array_merge( - array('gallery' => $view->gallery->id, - 'slug' => empty($params['slug']) ? '' : $params['slug'], - 'page' => empty($params['page']) ? 0 : $params['page'], - 'view' => 'Slideshow', - 'image' => $image->id), - $date), - true); - - $params = array('gallery' => $view->gallery->id, 'url' => $url); - - header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('protect.php'), $params, null, false)); - exit; - } - - - Horde::addScriptFile('effects.js', 'horde', true); - Horde::addScriptFile('stripe.js', 'horde', true); - Horde::addScriptFile('slideshow.js', 'ansel', true); - - return $view; - } - - /** - * Get the title for this view. - * - * @return string The title. - */ - function getTitle() - { - return $this->image->filename; - } - - /** - * Get the HTML representing this view. - * - * @return string The HTML. - */ - function html() - { - global $browser, $conf, $prefs, $registry; - - if (is_a($this->gallery, 'PEAR_Error')) { - echo htmlspecialchars($this->gallery->getMessage()); - return; - } - $page = Horde_Util::getFormData('page', 0); - $galleryId = $this->gallery->id; - $imageId = $this->image->id; - $galleryOwner = $this->gallery->get('owner'); - $style = $this->gallery->getStyle(); - - /* Get date info to pass along the links */ - if (!empty($this->_params['year'])) { - $date = Ansel::getDateParameter( - array('year' => $this->_params['year'], - 'month' => $this->_params['month'], - 'day' => $this->_params['day'])); - } else { - $date = array(); - } - - /* Get the index of the starting image */ - $imageList = $this->gallery->listImages(); - - $style = $this->gallery->getStyle(); - $revList = array_flip($imageList); - $imageIndex = $revList[$imageId]; - if (isset($imageList[$imageIndex - 1])) { - $prev = $imageList[$imageIndex - 1]; - } else { - $prev = $imageList[count($imageList) - 1]; - } - - $ecardurl = Horde_Util::addParameter('img/ecard.php', - array('gallery' => $galleryId, - 'image' => $imageId)); - $galleryurl = Horde_Util::addParameter('view.php', array_merge( - array('gallery' => $galleryId, - 'page' => $page), - $date)); - $imageActionUrl = Horde_Util::addParameter('image.php', array_merge( - array('gallery' => $galleryId, - 'image' => $imageId, - 'page' => $page), - $date)); - $imageUrl = Ansel::getImageUrl($imageId, 'screen', false, $style['name']); - - ob_start(); - require ANSEL_TEMPLATES . '/view/slideshow.inc'; - return ob_get_clean(); - } - - function viewType() - { - return 'Slideshow'; - } - -}