* @author Georg Rehfeld */ /** * Exif Module * * This module provides support for adding exifs to items * * @package Exif */ class ExifModule extends GalleryModule { function ExifModule() { global $gallery; $this->setId('exif'); $this->setName($gallery->i18n('EXIF/IPTC')); $this->setDescription($gallery->i18n('Extract EXIF/IPTC data from JPEG photos')); $this->setVersion('1.0.0'); /* Update upgrade() function below too */ $this->setGroup('data', $this->translate('Extra Data')); $this->setCallbacks('getSiteAdminViews'); $this->setRequiredCoreApi(array(6, 0)); $this->setRequiredModuleApi(array(2, 0)); } /** * @see GalleryModule::upgrade() */ function upgrade($currentVersion) { global $gallery; if (!isset($currentVersion)) { /* Initial install */ GalleryCoreApi::relativeRequireOnce('modules/exif/classes/ExifHelper.class'); $ret = ExifHelper::setDefaultProperties(EXIF_SUMMARY); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } $ret = ExifHelper::setDefaultProperties(EXIF_DETAILED); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } /* Import IPTC keywords into item keywords, see comment below for reason. */ $ret = $this->setParameter('addOption', IPTC_ITEM_KEYWORDS); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } } else { switch ($currentVersion) { case '0.8.2': case '0.8.3': $ret = $this->setParameter('addOption', '0'); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } case '0.8.4': case '0.8.5': case '0.8.6': case '0.8.7': case '0.8.8': case '0.8.9': case '0.9.1': /* * New IPTC capabilities in 0.9.2, we add reasonable IPTC default properties to * summary and detailed view. We also enable extraction of IPTC keywords into item * keywords: item keywords are nowhere else set automatically and users adding * IPTC keywords to their images (which must be done actively, as opposed to EXIF * data generated by the camera) most probably will want to have them extracted. */ GalleryCoreApi::relativeRequireOnce('modules/exif/classes/ExifHelper.class'); $ret = ExifHelper::addDefaultIptcProperties(EXIF_SUMMARY); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } $ret = ExifHelper::addDefaultIptcProperties(EXIF_DETAILED); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } list($ret, $addOption) = $this->getParameter('addOption'); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } $ret = $this->setParameter('addOption', $addOption | IPTC_ITEM_KEYWORDS); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } case '0.9.2': case '0.9.3': case '0.9.4': case '0.9.5': case '0.9.6': case '0.9.7': case '0.9.8': case 'end of upgrade path': /* * Leave this bogus case at the end of the legitimate case statements so that we * always properly terminate our upgrade path with a break. */ break; default: return GalleryStatus::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__, sprintf('Unknown module version %s', $currentVersion)); } } return GalleryStatus::success(); } /** * @see GalleryModule::performFactoryRegistrations() */ function performFactoryRegistrations() { $ret = GalleryCoreApi::registerFactoryImplementation( 'ExifInterface_1_0', 'ExifExtractor', 'Exif', 'modules/exif/classes/ExifExtractor.class', 'exif', null); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } $ret = GalleryCoreApi::registerFactoryImplementation( 'GalleryToolkit', 'ExifToolkit', 'Exif', 'modules/exif/classes/ExifToolkit.class', 'exif', null); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } $ret = GalleryCoreApi::registerFactoryImplementation('ItemAddOption', 'ExifDescriptionOption', 'ExifDescriptionOption', 'modules/exif/ExifDescriptionOption.inc', 'exif', null); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } return GalleryStatus::success(); } /** * @see GalleryModule::activate */ function activate($postActivationEvent=true) { global $gallery; $ret = GalleryCoreApi::registerToolkitProperty( 'Exif', array('image/jpeg', 'image/jpeg-cmyk'), 'originationTimestamp', 'int', $gallery->i18n('Get the origination timestamp')); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $redirect) = parent::activate($postActivationEvent); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } return array(GalleryStatus::success(), $redirect); } /** * @see GalleryModule::isRecommendedDuringInstall */ function isRecommendedDuringInstall() { return true; } /** * @see GalleryModule::autoConfigure */ function autoConfigure() { /* We don't require any special configuration */ return array(GalleryStatus::success(), true); } /** * @see GalleryModule::getSiteAdminViews() */ function getSiteAdminViews() { global $gallery; return array(GalleryStatus::success(), array(array('name' => $this->translate('EXIF/IPTC'), 'view' => 'exif.AdminExif'))); } } ?>