*/ class LinkItemModule extends GalleryModule /* and GalleryEventListener */ { function LinkItemModule() { global $gallery; $this->setId('linkitem'); $this->setName($gallery->i18n('Link Items')); $this->setDescription($gallery->i18n('Create links to other albums or external urls')); $this->setVersion('1.0.4'); $this->setGroup('display', $gallery->i18n('Display')); $this->setCallbacks('registerEventListeners'); $this->setRequiredCoreApi(array(7, 0)); $this->setRequiredModuleApi(array(3, 0)); } /** * @see GalleryModule::upgrade() */ function upgrade($currentVersion) { global $gallery; $platform =& $gallery->getPlatform(); $slash = $platform->getDirectorySeparator(); $imageDir = $gallery->getConfig('data.gallery.plugins_data') . "modules${slash}linkitem"; list ($success) = GalleryUtilities::guaranteeDirExists($imageDir); if (!$success) { return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "Unable to create directory: $imageDir"); } $imageFile = "$imageDir${slash}arrow.png"; if (!$platform->is_file($imageFile) && !$platform->copy(dirname(__FILE__) . "${slash}images${slash}arrow.png", $imageFile)) { return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "Unable to copy arrow.png to $imageDir"); } return null; } /** * @see GalleryModule::performFactoryRegistrations() */ function performFactoryRegistrations() { $ret = GalleryCoreApi::registerFactoryImplementation( 'GalleryEntity', 'GalleryLinkItem', 'GalleryLinkItem', 'modules/linkitem/classes/GalleryLinkItem.class', 'linkitem', null); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } $ret = GalleryCoreApi::registerFactoryImplementation( 'ItemAddPlugin', 'ItemAddLinkItem', 'ItemAddLinkItem', 'modules/linkitem/ItemAddLinkItem.inc', 'linkitem', null); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } $ret = GalleryCoreApi::registerFactoryImplementation( 'ItemEditOption', 'LinkItemOption', 'LinkItemOption', 'modules/linkitem/LinkItemOption.inc', 'linkitem', array('ItemEditItem')); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } return null; } /** * @see GalleryModule::registerEventListeners() */ function registerEventListeners() { GalleryCoreApi::registerEventListener('GalleryEntity::delete', new LinkItemModule()); } /** * @see GalleryModule::getModuleEntityTypes() */ function getModuleEntityTypes() { return array('GalleryLinkItem'); } /** * Delete links to an album if the album is deleted. * @see GalleryEventListener::handleEvent */ function handleEvent($event) { $entity = $event->getEntity(); if (GalleryUtilities::isA($entity, 'GalleryAlbumItem')) { global $gallery; $query = ' SELECT [GalleryLinkItem::id] FROM [GalleryLinkItem] WHERE [GalleryLinkItem::link] = ? '; list ($ret, $searchResults) = $gallery->search($query, array((string)$entity->getId())); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } while ($result = $searchResults->nextResult()) { $ret = GalleryCoreApi::deleteEntityById($result[0]); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } } } return array(null, null); } } ?>