* @author Jess Martin */ /** * Hidden Items * * This module provides the ability to hide items and allow them to be viewed only * by directly accessing the correct URL. * * @package Hidden */ class HiddenModule extends GalleryModule /* and GalleryEventListener */ { function HiddenModule() { global $gallery; $this->setId('hidden'); $this->setName($gallery->i18n('Hidden Items')); $this->setDescription($gallery->i18n('Hide items/albums from guests until directly ' . 'accessed with the right URL')); $this->setVersion('1.0.2'); $this->setGroup('display', $this->translate('Display')); $this->setCallbacks('registerEventListeners'); $this->setRequiredCoreApi(array(7, 0)); $this->setRequiredModuleApi(array(3, 0)); } /** * @see GalleryModule::registerEventListeners() */ function registerEventListeners() { GalleryCoreApi::registerEventListener('GalleryEntity::save', new HiddenModule()); } /** * @see GalleryModule::performFactoryRegistrations() */ function performFactoryRegistrations() { $ret = GalleryCoreApi::registerFactoryImplementation( 'GalleryOnLoadHandler', 'HiddenModule', 'Hidden', 'modules/hidden/module.inc', 'hidden', null); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } $ret = GalleryCoreApi::registerFactoryImplementation( 'ItemEditOption', 'HiddenItemOption', 'HiddenItemOption', 'modules/hidden/HiddenItemOption.inc', 'hidden', array('ItemEditItem')); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } $ret = GalleryCoreApi::registerFactoryImplementation( 'HiddenInterface_1_0', 'HiddenHelper', 'Hidden', 'modules/hidden/classes/HiddenHelper.class', 'hidden', null); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } return null; } /** * @see GalleryModule::getOnLoadHandlerIds() */ function getOnLoadHandlerIds() { return array('Hidden'); } /** * Unhide all hidden items. * @see GalleryModule::uninstall() */ function uninstall() { global $gallery; GalleryCoreApi::requireOnce('modules/hidden/classes/HiddenHelper.class'); $query = ' SELECT [GalleryEntity::id] FROM [GalleryEntity] WHERE [GalleryEntity::onLoadHandlers] LIKE \'%|Hidden|%\' '; list ($ret, $searchResults) = $gallery->search($query); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } while ($result = $searchResults->nextResult()) { $itemIds[] = (int)$result[0]; } while (!empty($itemIds)) { list ($ret, $items) = GalleryCoreApi::loadEntitiesById(array_splice($itemIds, 0, 100)); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } foreach ($items as $item) { $ret = HiddenHelper::unHideItem($item); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } } } $ret = parent::uninstall(); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } return null; } /** * Add session based permission when core.ShowItem accessed directly for this item */ function onLoad(&$item, $duringUpgrade) { list ($view, $itemId) = GalleryUtilities::getRequestVariables('view', 'itemId'); if ($view == 'core.ShowItem' && $itemId == $item->getId()) { list ($ret, $permissions) = GalleryCoreApi::getPermissions($itemId); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } if (!isset($permissions['core.view']) && (isset($permissions['core.viewResizes']) || isset($permissions['core.viewSource']))) { global $gallery; $session =& $gallery->getSession(); if (!$session->exists(GALLERY_PERMISSION_SESSION_KEY)) { $session->put(GALLERY_PERMISSION_SESSION_KEY, array()); } $sessionPerms =& $session->get(GALLERY_PERMISSION_SESSION_KEY); if (!in_array($itemId, $sessionPerms)) { $sessionPerms[] = (int)$itemId; } } } return null; } /** * Update permissions when items move in/out of hidden albums * @see GalleryEventListener::handleEvent */ function handleEvent($event) { $item = $event->getEntity(); if (GalleryUtilities::isA($item, 'GalleryItem') && !$item->testPersistentFlag(STORAGE_FLAG_NEWLY_CREATED) && $item->isModified('parentId') && !$item->hasOnLoadHandler('Hidden')) { GalleryCoreApi::requireOnce('modules/hidden/classes/HiddenHelper.class'); $ret = HiddenHelper::handleMoveItem($item); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } } return array(null, null); } } ?>