yet.
+++ /dev/null
-<?php
-/**
- * Ansel_Gallery_Mode_Normal:: Class for encapsulating gallery methods that
- * depend on the current display mode of the gallery.
- *
- * 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 <mrubinsk@horde.org>
- */
-class Ansel_GalleryMode_RemoteVimeo {
-
- var $_vimeo;
- var $_thumbs;
-
- /**
- * @var Ansel_Gallery
- */
- var $_gallery;
- var $_features = array();
-
- /**
- * Constructor
- *
- * @param Ansel_Gallery $gallery The gallery to bind to.
- *
- * @return Ansel_Gallery_ModeNormal
- */
- function Ansel_GalleryMode_RemoteVimeo($gallery)
- {
- // Build a Horde_Service_Vimeo object
- // It *requires* a http client object and can make use of a cache object,
- $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);
- $vimeo_id = 'user1015172'; //TODO: Get this from prefs?
- $this->_thumbs = unserialize($this->_vimeo->user($vimeo_id)->clips()->run());
- $this->_gallery = $gallery;
- }
-
- function init()
- {
- $remote_ids = array();
-
- // Get the remote video_ids
- foreach ($this->_thumbs as $thumb) {
- $remote_ids[$thumb['clip_id']] = false;
- }
-
- // Get localimage objects...
- $images = $this->getImages();
- if (!is_a($images, 'PEAR_Error')) {
- foreach ($images as $image) {
- $caption = $image->caption;
- if (in_array($caption, array_keys($remote_ids))) {
- // We still have this video on Vimeo.
- // AND we know that we will be checking for this locally
- // later, so save the info now.
- $remote_ids[$caption] = true;
- } else {
- // Remote no longer exists - delete the local thumbnail
- $this->removeImage($image, false);
- }
- }
-
- // Now check the other direction
- foreach($this->_thumbs as $thumb) {
- if (!$remote_ids[$thumb['clip_id']]) {
- // We didn't find a match in any of our local images earlier
- // create one now.
- $hc = new Horde_Http_Client();
- $response = $hc->get($thumb['thumbnail_large']);
-
- $image_id = $this->_gallery->addImage(array(
- 'image_filename' => $thumb['title'],
- 'image_caption' => $thumb['clip_id'],
- 'data' => $response->getBody(),
- 'image_type' => $response->getHeader('Content-Type')
- ));
- }
- }
- }
- }
-
- function hasFeature($feature)
- {
- return in_array($feature, $this->_features);
- }
-
- /**
- * Get the children of this gallery.
- *
- * Should never be called with a RemoteVimeo gallery since we override
- * fetchChildren() in Ansel_GalleryRenderer...but implement something
- * sensible just in case that ever changes.
- *
- * @param integer $perm The permissions to limit to.
- * @param integer $from The child to start at.
- * @param integer $to The child to end with.
- *
- * @return A mixed array of Ansel_Gallery and Ansel_Image objects that are
- * children of this gallery.
- */
- function getGalleryChildren($perm = PERMS_SHOW, $from = 0, $to = 0)
- {
- if ($this->_gallery->data['attribute_images']) {
- $images = $this->getImages($from, $to);
- if (is_a($images, 'PEAR_Error')) {
- Horde::logMessage($images->message, __FILE__, __LINE__,
- PEAR_LOG_ERR);
- $images = array();
- }
- } else {
- $images = array();
- }
-
- return $images;
- }
-
- /**
- * Get an array describing where this gallery is in a breadcrumb trail.
- *
- * @return An array of 'title' and 'navdata' hashes with the [0] element
- * being the deepest part.
- */
- function getGalleryCrumbData()
- {
- $trail = array();
- $text = htmlspecialchars($this->_gallery->get('name'));
- $navdata = array('view' => 'Gallery',
- 'gallery' => $this->_gallery->id,
- 'slug' => $this->_gallery->get('slug'));
- $trail[] = array('title' => $text, 'navdata' => $navdata);
- $parent_list = array_reverse($this->_gallery->getParents());
- foreach ($parent_list as $p) {
- $text = htmlspecialchars($p->get('name'));
- $navdata = array('view' => 'Gallery',
- 'gallery' => $p->id,
- 'slug' => $p->get('slug'));
- $trail[] = array('title' => $text, 'navdata' => $navdata);
- }
-
- return $trail;
- }
-
- function setDate($date = array())
- {
- //noop
- }
-
- function getDate()
- {
- return array();
- }
-
- /**
- * Return the count this gallery's children
- *
- * @param integer $perm The permissions to require.
- * @param boolean $galleries_only Only include galleries, no images.
- *
- * @return integer The count of this gallery's children.
- */
- function countGalleryChildren($perm = PERMS_SHOW, $galleries_only = false)
- {
- return count($this->_thumbs);
- }
-
- /**
- * Lists a slice of the image ids in this gallery.
- *
- * @param integer $from The image to start listing.
- * @param integer $count The numer of images to list.
- *
- * @return mixed An array of image_ids | PEAR_Error
- */
- function listImages($from = 0, $count = 0)
- {
- return $GLOBALS['ansel_storage']->listImages($this->_gallery->id, $from,
- $count);
- }
-
- function moveImagesTo($images, $gallery)
- {
- return false;
- }
-
- function removeImage($image, $isStack)
- {
- return false;
- }
-
- /**
- * Gets a slice of the images in this gallery.
- *
- * @param integer $from The image to start fetching.
- * @param integer $count The numer of images to return.
- *
- * @param mixed An array of Ansel_Image objects | PEAR_Error
- */
- function getImages($from = 0, $count = 0)
- {
- $this->_gallery->_shareOb->_db->setLimit($count, $from);
- $images = $this->_gallery->_shareOb->_db->query('SELECT image_id, gallery_id, image_filename, image_type, image_caption, image_uploaded_date, image_sort FROM ansel_images WHERE gallery_id = ' . $this->_gallery->id . ' ORDER BY image_sort');
- if (is_a($images, 'PEAR_Error')) {
- return $images;
- }
-
- $objects = array();
- while ($image = $images->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $image['image_filename'] = Horde_String::convertCharset($image['image_filename'], $GLOBALS['conf']['sql']['charset']);
- $image['image_caption'] = Horde_String::convertCharset($image['image_caption'], $GLOBALS['conf']['sql']['charset']);
- $objects[$image['image_id']] = new Ansel_Image($image);
- $GLOBALS['ansel_storage']->images[(int)$image['image_id']] = &$objects[$image['image_id']];
- }
- $images->free();
-
- $ccounts = $GLOBALS['ansel_storage']->_getImageCommentCounts(array_keys($objects));
- if (!is_a($ccounts, 'PEAR_Error') && count($ccounts)) {
- foreach ($objects as $key => $image) {
- $objects[$key]->commentCount = (!empty($ccounts[$key]) ? $ccounts[$key] : 0);
- }
- }
- return array_values($objects);
- }
-
- /**
- * Checks if the gallery has any subgallery
- *
- * @return boolean
- */
- function hasSubGalleries()
- {
- return false;
- }
-
- /**
- * Returns the number of images in this gallery and, optionally, all
- * sub-galleries.
- *
- * @param boolean $subgalleries Determines whether subgalleries should
- * be counted or not.
- *
- * @return integer number of images in this gallery
- */
- function countImages($subgalleries = false)
- {
- return count($this->_thumbs);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Ansel_View_GalleryRenderer_GalleryVimeo:: An example of extending Ansel by
- * adding a new gallery style. This fetches a list of videos from the Vimeo
- * video service, and displays them as a gallery. The videos are viewed in a
- * redbox overlay when the thumbnails are clicked.
- *
- * 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 <mrubinsk@horde.org>
- * @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 = '<div class="image-tile" id="imagetile_' . (int)$video->clip_id . '">'
- . Horde::link($video->url, $video->title, '', '', $imgOnClick, $video->title)
- . '<img src="' . Ansel::getImageUrl($image->id, 'prettythumb', true, $this->view->gallery->get('style')) . '" />' . '</a>';
- $tile .= '<div style="valign: bottom;">';
- $tile .= ' <div class="image-tile-caption" id="' . (int)$video->clip_id . 'caption">' . $video->caption . '</div></div></div>';
-
- return $tile;
- }
-
-}
+++ /dev/null
-<script type="text/javascript">
- //<![CDATA[
- var clips = [];
- <?php foreach(array_reverse($this->_thumbs) as $video):?>
- clips.push(<?php echo $this->_json[$video['clip_id']]?>);
- <?php endforeach ?>
-
- function showVideo(index)
- {
- RedBox.showHtml('<div id="RB_info">' + clips[index]['html'] + '</div>');
- $('RB_window').setStyle({top: '100px'});
- $('RB_overlay').observe('click', function() {RedBox.close()});
- return false;
- }
- //]]>
-
-</script>
-<div class="header" id="galleryHeader">
- <?php echo ($this->numTiles ? '<span class="rightFloat">' . ($this->numTiles > $this->perpage ? sprintf(_("%d to %d of %d Items"), $this->pagestart, $this->pageend, $this->numTiles) : sprintf(ngettext("%d Item", "%d Items", $this->numTiles), $this->numTiles)) . '</span>' : '') . Ansel::getBreadCrumbs(); ?>
-</div>
-<?php if ($this->view->gallery->get('desc')): ?>
-<div class="gallery-desc" id="galleryDescription">
-<?php echo Text_Filter::filter($this->view->gallery->get('desc'), 'text2html', array('parselevel' => TEXT_HTML_MICRO)) ?>
-</div>
-<?php endif;?>
-<table width="100%" cellspacing="0">
- <tr>
- <td style="vertical-align:top;width:<?php echo ($this->view->countWidgets() ? "75%" : "100%") ?>;">
- <?php if (!$this->numTiles): ?>
- <div class="text"><em><?php echo _("There are no videos in this gallery.") ?></em></div>
- <?php else: ?>
- <table width="100%" style="background-color:<?php echo $this->style['background'] ?>;">
- <tr><td colspan="<?php echo $tilesperrow ?>"><?php echo $pager->render() ?></td></tr>
- <tr>
- <?php
- $cnt = 0;
- foreach ($this->children as $child) {
- echo '<td width="' . $cellwidth . '%" class="ansel-tile">'
- . $this->getTile($child, new Horde_Support_Array($this->_thumbs[$child->caption]), $cnt++) . '</td>';
- if (!(++$count % $tilesperrow)) {
- echo '</tr><tr>';
- }
- }
- while ($count % $tilesperrow) {
- echo '<td width="' . $cellwidth . '%" valign="top"> </td>';
- $count++;
- }?>
- </tr>
- <tr><td colspan="<?php echo $tilesperrow ?>"><?php echo $pager->render() ?></td></tr>
- </table>
- <?php endif;?>
- </td>
- <td class="anselWidgets">
- <?php if (empty($this->view->_params['api'])):?>
- <?php echo $this->view->renderWidgets(); ?>
- <?php endif;?>
- </td>
- </tr>
-</table>
-<?php if ($this->view->countWidgets()): ?>
- </div>
-<?php endif; ?>