From: Michael J. Rubinsky Date: Fri, 31 Jul 2009 16:20:15 +0000 (-0400) Subject: rename lib/GalleryRenderers -> lib/GalleryRenderer X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1db64436e1aed8c867d6170075b7329d9ff9ad3b;p=horde.git rename lib/GalleryRenderers -> lib/GalleryRenderer --- diff --git a/ansel/lib/View/Abstract.php b/ansel/lib/View/Abstract.php deleted file mode 100644 index bcd1bb751..000000000 --- a/ansel/lib/View/Abstract.php +++ /dev/null @@ -1,188 +0,0 @@ - - * @author Michael J. Rubinsky - * @package Ansel - */ -class Ansel_View_Base -{ - protected $_params = array(); - - /** - * The ansel resource this view is for. - * - * @var mixed Either an Ansel_Gallery or Ansel_Image - */ - public $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/GalleryRenderer/Gallery.php b/ansel/lib/View/GalleryRenderer/Gallery.php new file mode 100644 index 000000000..f806a4b20 --- /dev/null +++ b/ansel/lib/View/GalleryRenderer/Gallery.php @@ -0,0 +1,129 @@ + + * @package Ansel + */ +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/GalleryRenderer/GalleryLightbox.php b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php new file mode 100644 index 000000000..d70051b4b --- /dev/null +++ b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php @@ -0,0 +1,153 @@ + + * @package Ansel + */ +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/GalleryRenderer/GalleryVimeo.php b/ansel/lib/View/GalleryRenderer/GalleryVimeo.php new file mode 100644 index 000000000..db0602449 --- /dev/null +++ b/ansel/lib/View/GalleryRenderer/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/GalleryRenderers/Gallery.php b/ansel/lib/View/GalleryRenderers/Gallery.php deleted file mode 100644 index af87d8206..000000000 --- a/ansel/lib/View/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/View/GalleryRenderers/GalleryLightbox.php b/ansel/lib/View/GalleryRenderers/GalleryLightbox.php deleted file mode 100644 index 3e8e8559a..000000000 --- a/ansel/lib/View/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/View/GalleryRenderers/GalleryVimeo.php b/ansel/lib/View/GalleryRenderers/GalleryVimeo.php deleted file mode 100644 index db0602449..000000000 --- a/ansel/lib/View/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; - } - -}