*/ /** * This controller will handle the rendering of an album or item. * * @package GalleryCore * @subpackage UserInterface */ class ShowItemView extends GalleryView { /** * @see GalleryView::getThemeName */ function getThemeName() { global $gallery; list ($ret, $item) = $this->_getItem(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* * In the near term, we don't allow data items to have their own theme, even though * there's room for it. Instead, draw them theme from the parent album. */ $theme = null; if (GalleryUtilities::isA($item, 'GalleryAlbumItem')) { $theme = $item->getTheme(); } else { $parentId = $item->getParentId(); list ($ret, $parent) = GalleryCoreApi::loadEntitiesById($parentId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $theme = $parent->gettheme(); } return array(GalleryStatus::success(), $theme); } /** * @see GalleryView::loadTemplate */ function loadTemplate(&$template, &$form) { global $gallery; list ($ret, $item) = $this->_getItem(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Make sure we have permission to view this item */ $ret = GalleryCoreApi::assertHasItemPermission($item->getId(), 'core.view'); if ($ret->isError()) { if ($ret->getErrorCode() & ERROR_PERMISSION_DENIED) { list ($ret2, $anonymousId) = GalleryCoreApi::getPluginParameter( 'module', 'core', 'id.anonymousUser'); if ($ret2->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null); } if ($gallery->getActiveUserId() == $anonymousId) { /* Redirect to login view */ return array(GalleryStatus::success(), array('redirect' => GalleryCapabilities::get('loginRedirect'))); } /* Try to redirect to root */ list ($ret2, $rootId) = GalleryCoreApi::getPluginParameter( 'module', 'core', 'id.rootAlbum'); if ($ret2->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null); } if ($item->getId() == $rootId) { /* No permission on root album; redirect to login view */ return array(GalleryStatus::success(), array('redirect' => GalleryCapabilities::get('loginRedirect'))); } return array(GalleryStatus::success(), array('redirect' => array('view' => 'core:ShowItem', 'itemId' => $rootId))); } return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $layoutId) = GalleryCoreApi::fetchLayoutId($item); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $validLayout = false; list ($ret, $layout) = GalleryCoreApi::loadPlugin('layout', $layoutId); if ($ret->isError() && !($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH)) { return array($ret->wrap(__FILE__, __LINE__), null); } if (isset($layout)) { list ($ret, $validLayout) = $layout->isActive(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } if (!$validLayout) { return array(GalleryStatus::success(), array('redirect' => array('view' => 'core:ShowItemError', 'problem' => 'missingLayout', 'itemId' => $item->getId()))); } /* Let the layout load the template and get its body file */ list ($ret, $results) = $layout->loadTemplate($template, $item); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } if (isset($results['redirect'])) { return array(GalleryStatus::success(), $results); } /* Update the view count for non-data items, like Albums */ if (GalleryUtilities::isA($item, 'GalleryItem') && !GalleryUtilities::isA($item, 'GalleryDataItem')) { $ret = GalleryCoreApi::incrementItemViewCount($item->getId()); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } if (isset($results['html'])) { return array(GalleryStatus::success(), $results); } $ShowItem = array('item' => $item->getMemberData(), 'layoutL10Domain' => $layout->getL10Domain()); if (isset($results['body'])) { $ShowItem['layoutBodyFile'] = $results['body']; } $template->setVariable('ShowItem', $ShowItem); /* Provide a title if the layout doesn't */ $head = $template->getVariable('head'); if (empty($head['tpl']) && empty($head['title'])) { $template->head('modules/core/templates/ShowItemHead.tpl'); } return array(GalleryStatus::success(), array('body' => 'modules/core/templates/ShowItem.tpl')); } /** * @see GalleryView::getViewDescription() */ function getViewDescription() { global $gallery; list ($ret, $item) = $this->_getItem(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $typeName = $item->itemTypeName(true); return array(GalleryStatus::success(), $typeName[1]); } /** * @see GalleryView::rewriteQueryString */ function rewriteQueryString($params) { global $gallery; /* We know who we are */ unset($params['view']); /* Transform the id into a path */ $buf = ''; if (isset($params['itemId'])) { list ($ret, $entity) = GalleryCoreApi::loadEntitiesById($params['itemId']); if ($ret->isSuccess()) { list ($ret, $path) = $entity->fetchLogicalPath(); if ($ret->isSuccess()) { $buf .= $path; unset($params['itemId']); } } if (!GalleryUtilities::isA($entity, 'GalleryAlbumItem')) { $buf .= '.html'; } } /* Add in anything else as a standard query element */ if (!empty($params)) { $buf .= GalleryUrlGenerator::buildQueryString($params); } return $buf; } /** * @see GalleryView::parseQueryString() */ function parseQueryString($queryString) { /* Treat the input as a path and get the right item id out */ $itemId = null; if (substr($queryString, -5, 5) == '.html') { $queryString = substr($queryString, 0, strlen($queryString) - 5); $queryString .= '/'; } $origQueryString = $queryString; while ($itemId == null && !empty($queryString)) { list ($ret, $itemId) = GalleryCoreApi::fetchItemIdByPath(urldecode($queryString)); if ($ret->isError() && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($ret->isSuccess()) { break; } else { /* Object is missing -- try trimming the query string */ $queryString = preg_replace('|/[^/]*$|', '', $queryString); } } GalleryUtilities::putRequestVariable('itemId', $itemId); if ($origQueryString == $queryString) { return array(GalleryStatus::success(), null); } else { return array(GalleryStatus::success(), $queryString); } } } ?>