*/ /** * This implements a gallery layout with a scrollable view of all image thumbnails * and slideshow support in a single dynamic page. Displays inline items ONLY; subalbums * or other items types are NOT shown. * * @package GalleryLayout * @subpackage Layout */ class SliderLayout extends GalleryLayout { /** * Constructor */ function SliderLayout() { global $gallery; $this->setId('slider'); $this->setName('Slider'); $this->setDescription($gallery->i18n('Image viewer/slideshow; subalbums/other items not shown')); $this->setVersion('0.8.1'); $this->setL10Domain('layouts_slider'); $this->setRequiredLayoutApi(array(0, 8)); $this->setRequiredCoreApi(array(4, 0)); return GalleryStatus::success(); } function loadTemplate(&$template, $item) { global $gallery; $renderId = GalleryUtilities::getRequestVariables('renderId'); if (!$item->getCanContainChildren() && !empty($renderId)) { /* Render this item */ list ($ret, $image) = GalleryCoreApi::loadEntitiesById($renderId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $layout = array('item' => $item->getMemberData(), 'image' => $image->getMemberData()); $template->setVariable('layout', $layout); return array(GalleryStatus::success(), array('html' => 'layouts/slider/templates/render.tpl')); } if (!$item->getCanContainChildren()) { /* Load parent with initial view of this item */ $viewItemId = $item->getId(); list ($ret, $item) = GalleryCoreApi::loadEntitiesById($item->getParentId()); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } list ($ret, $childIds) = GalleryCoreApi::fetchChildItemIds($item); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $ret = $this->loadLayoutTemplate($template, $item, array('parents', 'systemLinks', 'systemContent', 'itemLinks'), $childIds); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $layout =& $template->getVariableByReference('layout'); list ($ret, $imageWidths, $imageHeights, $maxTW, $maxTH) = $this->_buildItemList($childIds, $layout['children']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $layout['show']['parents'] = true; $layout['show']['systemLinks'] = true; $layout['imageWidths'] = implode(',',$imageWidths); $layout['imageHeights'] = implode(',',$imageHeights); $layout['maxThumbWidth'] = $maxTW; $layout['maxThumbHeight'] = $maxTH; $layout['imageCount'] = count($imageWidths); $layout['show']['sidebarActions'] = false; $urlGenerator =& $gallery->getUrlGenerator(); $cookiePath = preg_replace('|^[^/]*//[^/]*/|', '/', $urlGenerator->getCurrentUrlDir()); $layout['cookiePath'] = $cookiePath; $layout['layoutUrl'] = $urlGenerator->generateUrl(array('href' => 'layouts/slider'), false); /* Init view with specific image */ if (isset($viewItemId)) { foreach ($layout['children'] as $tmp) { if ($tmp['id'] == $viewItemId) { if (isset($tmp['imageIndex'])) { $layout['viewIndex'] = $tmp['imageIndex']; /* Set cookie to popup image just once */ $cook = 'G2_slider_' . $item->getId(); setcookie($cook, '-2' . (GalleryUtilities::getCookieVar($cook) ? strstr(GalleryUtilities::getCookieVar($cook), ';') : ';'), 0, $cookiePath); } break; } } } $template->head('layouts/slider/templates/header.tpl'); return array(GalleryStatus::success(), array('body' => 'layouts/slider/templates/slider.tpl')); } function _buildItemList($childIds, &$children) { $imageWidths = $imageHeights = $childItems = array(); $maxTW = $maxTH = 0; if (!empty($childIds)) { $ret = GalleryCoreApi::studyPermissions($childIds); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } list ($ret, $childItems) = GalleryCoreApi::loadEntitiesById($childIds); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } list ($ret, $preferredFullImages) = GalleryCoreApi::fetchPreferredsByItemIds($childIds); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } list ($ret, $resizedImages) = GalleryCoreApi::fetchResizesByItemIds($childIds); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } list ($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($childIds); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } } $i = 0; foreach ($childItems as $child) { $childId = $child->getId(); if (isset($thumbnails[$childId])) { if (!($thumbnails[$childId]->getWidth() && $thumbnails[$childId]->getHeight())) { list ($ret, $thumbnails[$childId]) = GalleryCoreApi::rebuildDerivativeCache($thumbnails[$childId]->getId()); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } } $children[$i]['thumbnail'] = $thumbnails[$childId]->getMemberData(); if ($thumbnails[$childId]->getWidth() > $maxTW) { $maxTW = $thumbnails[$childId]->getWidth(); } if ($thumbnails[$childId]->getHeight() > $maxTH) { $maxTH = $thumbnails[$childId]->getHeight(); } } if (!(GalleryUtilities::isA($child, 'GalleryDataItem') && $child->canBeViewedInline())) { continue; } list ($ret, $permissions) = GalleryCoreApi::getPermissions($childId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } $images = array(); if (isset($permissions['core.viewSource'])) { // Full size; check for preferred copy if (isset($preferredFullImages[$childId])) { $images[] = $preferredFullImages[$childId]; } else { $images[] = $child; } } if (isset($permissions['core.viewResizes']) && isset($resizedImages[$childId])) { foreach ($resizedImages[$childId] as $resize) { $images[] = $resize; } } if (isset($thumbnails[$childId])) { $images[] = $thumbnails[$childId]; } if (!empty($images)) { $image = $images[0]; // Rebuild derivative if needed so width/height known.. if (GalleryUtilities::isA($image, 'GalleryDerivativeImage') && !($image->getWidth() && $image->getHeight())) { list ($ret, $image) = GalleryCoreApi::rebuildDerivativeCache($image->getId()); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null, null, null); } } $image = $image->getMemberData(); $children[$i]['image'] = $image; $children[$i]['imageIndex'] = count($imageWidths); if (GalleryUtilities::isExactlyA($child, 'GalleryPhotoItem') && $image['width'] > 0 && $image['height'] > 0) { // Display in $imageWidths[] = $image['width']; $imageHeights[] = $image['height']; } else { // Item must render itself $children[$i]['renderItem'] = 1; $imageWidths[] = $imageHeights[] = -1; } } $i++; } return array(GalleryStatus::success(), $imageWidths, $imageHeights, $maxTW, $maxTH); } } ?>