*/ class ShowItemController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest($form) { global $gallery; /* * Note that this always changes user preview mode; if we add management of other * variables to this controller then we should guard this properly. (Maybe delete this * comment after writing the unit test that verifies it). */ $guestPreviewMode = GalleryUtilities::getRequestVariables('guestPreviewMode'); if ($guestPreviewMode != null) { $session =& $gallery->getSession(); $session->put('theme.guestPreviewMode', $guestPreviewMode ? 1 : 0); } return array(null, array('return' => 1, 'status' => array(), 'error' => array())); } } /** * This controller will handle the rendering of an album or item. * * @package GalleryCore * @subpackage UserInterface */ class ShowItemView extends GalleryView { /** * @see GalleryView::loadTemplate */ function loadTemplate(&$template, &$form) { global $gallery; list ($ret, $item) = $this->_getItem(); if ($ret) { 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) { if ($ret->getErrorCode() & ERROR_PERMISSION_DENIED) { list ($ret2, $anonymousId) = GalleryCoreApi::getPluginParameter( 'module', 'core', 'id.anonymousUser'); if ($ret2) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($gallery->getActiveUserId() == $anonymousId) { /* Redirect to login view */ return array(null, array('redirect' => GalleryCapabilities::get('loginRedirect'))); } /* Try to redirect to root */ list ($ret2, $rootId) = GalleryCoreApi::getPluginParameter( 'module', 'core', 'id.rootAlbum'); if ($ret2) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($item->getId() == $rootId) { /* No permission on root album; redirect to login view */ return array(null, array('redirect' => GalleryCapabilities::get('loginRedirect'))); } return array(null, array('redirect' => array('view' => 'core.ShowItem', 'itemId' => $rootId))); } return array($ret->wrap(__FILE__, __LINE__), null); } /* Increment the view count */ $ret = GalleryCoreApi::incrementItemViewCount($item->getId()); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } return array(null, array()); } /** * @see GalleryView::_getItem() */ function _getItem() { list ($ret, $item, $wasSpecified) = parent::_getItem(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } /* Always return wasSpecified==true no itemId param still uses root album theme/params */ return array(null, $item, true); } /** * @see GalleryView::getViewDescription() */ function getViewDescription() { global $gallery; list ($ret, $item) = $this->_getItem(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } $typeName = $item->itemTypeName(true); return array(null, $typeName[1]); } /** * @see GalleryView::getViewType() */ function getViewType() { return VIEW_TYPE_SHOW_ITEM; } } ?>