/**
  * Save the metadata and store the catalog data for this published
  * monograph.
  */
 function execute($request)
 {
     parent::execute();
     $monograph = $this->getMonograph();
     $monographDao = DAORegistry::getDAO('MonographDAO');
     $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
     $publishedMonograph = $publishedMonographDao->getById($monograph->getId(), null, false);
     /* @var $publishedMonograph PublishedMonograph */
     $isExistingEntry = $publishedMonograph ? true : false;
     if (!$publishedMonograph) {
         $publishedMonograph = $publishedMonographDao->newDataObject();
         $publishedMonograph->setId($monograph->getId());
     }
     // Populate the published monograph with the cataloging metadata
     $publishedMonograph->setAudience($this->getData('audience'));
     $publishedMonograph->setAudienceRangeQualifier($this->getData('audienceRangeQualifier'));
     $publishedMonograph->setAudienceRangeFrom($this->getData('audienceRangeFrom'));
     $publishedMonograph->setAudienceRangeTo($this->getData('audienceRangeTo'));
     $publishedMonograph->setAudienceRangeExact($this->getData('audienceRangeExact'));
     // If a cover image was uploaded, deal with it.
     if ($temporaryFileId = $this->getData('temporaryFileId')) {
         // Fetch the temporary file storing the uploaded library file
         $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
         $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $this->_userId);
         $temporaryFilePath = $temporaryFile->getFilePath();
         import('classes.file.SimpleMonographFileManager');
         $simpleMonographFileManager = new SimpleMonographFileManager($monograph->getPressId(), $publishedMonograph->getId());
         $basePath = $simpleMonographFileManager->getBasePath();
         // Delete the old file if it exists
         $oldSetting = $publishedMonograph->getCoverImage();
         if ($oldSetting) {
             $simpleMonographFileManager->deleteFile($basePath . $oldSetting['thumbnailName']);
             $simpleMonographFileManager->deleteFile($basePath . $oldSetting['catalogName']);
             $simpleMonographFileManager->deleteFile($basePath . $oldSetting['name']);
         }
         // The following variables were fetched in validation
         assert($this->_sizeArray && $this->_imageExtension);
         // Load the cover image for surrogate production
         $cover = null;
         // Scrutinizer
         switch ($this->_imageExtension) {
             case '.jpg':
                 $cover = imagecreatefromjpeg($temporaryFilePath);
                 break;
             case '.png':
                 $cover = imagecreatefrompng($temporaryFilePath);
                 break;
             case '.gif':
                 $cover = imagecreatefromgif($temporaryFilePath);
                 break;
         }
         assert(isset($cover));
         // Copy the new file over (involves creating the appropriate subdirectory too)
         $filename = 'cover' . $this->_imageExtension;
         $simpleMonographFileManager->copyFile($temporaryFile->getFilePath(), $basePath . $filename);
         // Generate surrogate images (thumbnail and catalog image)
         $press = $request->getPress();
         $coverThumbnailsMaxWidth = $press->getSetting('coverThumbnailsMaxWidth');
         $coverThumbnailsMaxHeight = $press->getSetting('coverThumbnailsMaxHeight');
         $thumbnailImageInfo = $this->_buildSurrogateImage($cover, $basePath, SUBMISSION_IMAGE_TYPE_THUMBNAIL, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight);
         $catalogImageInfo = $this->_buildSurrogateImage($cover, $basePath, SUBMISSION_IMAGE_TYPE_CATALOG);
         // Clean up
         imagedestroy($cover);
         $publishedMonograph->setCoverImage(array('name' => $filename, 'width' => $this->_sizeArray[0], 'height' => $this->_sizeArray[1], 'thumbnailName' => $thumbnailImageInfo['filename'], 'thumbnailWidth' => $thumbnailImageInfo['width'], 'thumbnailHeight' => $thumbnailImageInfo['height'], 'catalogName' => $catalogImageInfo['filename'], 'catalogWidth' => $catalogImageInfo['width'], 'catalogHeight' => $catalogImageInfo['height'], 'uploadName' => $temporaryFile->getOriginalFileName(), 'dateUploaded' => Core::getCurrentDate()));
         // Clean up the temporary file
         import('lib.pkp.classes.file.TemporaryFileManager');
         $temporaryFileManager = new TemporaryFileManager();
         $temporaryFileManager->deleteFile($temporaryFileId, $this->_userId);
     }
     if ($this->getData('attachPermissions')) {
         $monograph->setCopyrightYear($this->getData('copyrightYear'));
         $monograph->setCopyrightHolder($this->getData('copyrightHolder'), null);
         // Localized
         $monograph->setLicenseURL($this->getData('licenseURL'));
     } else {
         $monograph->setCopyrightYear(null);
         $monograph->setCopyrightHolder(null, null);
         $monograph->setLicenseURL(null);
     }
     $monographDao->updateObject($monograph);
     // Update the modified fields or insert new.
     if ($isExistingEntry) {
         $publishedMonographDao->updateObject($publishedMonograph);
     } else {
         $publishedMonographDao->insertObject($publishedMonograph);
     }
     import('classes.publicationFormat.PublicationFormatTombstoneManager');
     $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
     $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
     $publicationFormatFactory = $publicationFormatDao->getBySubmissionId($monograph->getId());
     $publicationFormats = $publicationFormatFactory->toAssociativeArray();
     $notificationMgr = new NotificationManager();
     if ($this->getData('confirm')) {
         // Update the monograph status.
         $monograph->setStatus(STATUS_PUBLISHED);
         $monographDao->updateObject($monograph);
         $publishedMonograph->setDatePublished(Core::getCurrentDate());
         $publishedMonographDao->updateObject($publishedMonograph);
         $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_APPROVE_SUBMISSION), null, ASSOC_TYPE_MONOGRAPH, $publishedMonograph->getId());
         // Remove publication format tombstones.
         $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats($publicationFormats);
         // Update the search index for this published monograph.
         import('classes.search.MonographSearchIndex');
         MonographSearchIndex::indexMonographMetadata($monograph);
         // Log the publication event.
         import('lib.pkp.classes.log.SubmissionLog');
         SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_METADATA_PUBLISH, 'submission.event.metadataPublished');
     } else {
         if ($isExistingEntry) {
             // Update the monograph status.
             $monograph->setStatus(STATUS_QUEUED);
             $monographDao->updateObject($monograph);
             // Unpublish monograph.
             $publishedMonograph->setDatePublished(null);
             $publishedMonographDao->updateObject($publishedMonograph);
             $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_APPROVE_SUBMISSION), null, ASSOC_TYPE_MONOGRAPH, $publishedMonograph->getId());
             // Create tombstones for each publication format.
             $publicationFormatTombstoneMgr->insertTombstonesByPublicationFormats($publicationFormats, $request->getContext());
             // Log the unpublication event.
             import('lib.pkp.classes.log.SubmissionLog');
             SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_METADATA_UNPUBLISH, 'submission.event.metadataUnpublished');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Resize cover thumnails for all given press objects (categories, series and published monographs).
  * @param $context Context
  * @param $objectDao CategoriesDAO, SeriesDAO or PublishedMonographsDAO
  * @param $coverThumbnailsMaxWidth int
  * @param $coverThumbnailsMaxHeight int
  * @param $basePath string Base path for the given object
  */
 function _resizeCoverThumbnails($context, $objectDao, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight, $basePath)
 {
     import('classes.file.SimpleMonographFileManager');
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     $objects = $objectDao->getByPressId($context->getId());
     while ($object = $objects->next()) {
         if (is_a($object, 'PublishedMonograph')) {
             $cover = $object->getCoverImage();
             $simpleMonographFileManager = new SimpleMonographFileManager($context->getId(), $object->getId());
             $basePath = $simpleMonographFileManager->getBasePath();
         } else {
             $cover = $object->getImage();
         }
         if ($cover) {
             // delete old cover thumbnail
             $fileManager->deleteFile($basePath . $cover['thumbnailName']);
             // get settings necessary for the new thumbnail
             $coverExtension = $fileManager->getExtension($cover['name']);
             $xRatio = min(1, $coverThumbnailsMaxWidth / $cover['width']);
             $yRatio = min(1, $coverThumbnailsMaxHeight / $cover['height']);
             $ratio = min($xRatio, $yRatio);
             $thumbnailWidth = round($ratio * $cover['width']);
             $thumbnailHeight = round($ratio * $cover['height']);
             // create a thumbnail image of the defined size
             $thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
             // generate the image of the original cover
             switch ($coverExtension) {
                 case 'jpg':
                     $coverImage = imagecreatefromjpeg($basePath . $cover['name']);
                     break;
                 case 'png':
                     $coverImage = imagecreatefrompng($basePath . $cover['name']);
                     break;
                 case 'gif':
                     $coverImage = imagecreatefromgif($basePath . $cover['name']);
                     break;
                 default:
                     $coverImage = null;
                     // Suppress warn
             }
             assert($coverImage);
             // copy the cover image to the thumbnail
             imagecopyresampled($thumbnail, $coverImage, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $cover['width'], $cover['height']);
             // create the thumbnail file
             switch ($coverExtension) {
                 case 'jpg':
                     imagejpeg($thumbnail, $basePath . $cover['thumbnailName']);
                     break;
                 case 'png':
                     imagepng($thumbnail, $basePath . $cover['thumbnailName']);
                     break;
                 case 'gif':
                     imagegif($thumbnail, $basePath . $cover['thumbnailName']);
                     break;
             }
             imagedestroy($thumbnail);
             if (is_a($object, 'PublishedMonograph')) {
                 $object->setCoverImage(array('name' => $cover['name'], 'width' => $cover['width'], 'height' => $cover['height'], 'thumbnailName' => $cover['thumbnailName'], 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'catalogName' => $cover['catalogName'], 'catalogWidth' => $cover['v'], 'catalogHeight' => $cover['catalogHeight'], 'uploadName' => $cover['uploadName'], 'dateUploaded' => $cover['dateUploaded']));
             } else {
                 $object->setImage(array('name' => $cover['name'], 'width' => $cover['width'], 'height' => $cover['height'], 'thumbnailName' => $cover['thumbnailName'], 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'uploadName' => $cover['uploadName'], 'dateUploaded' => $cover['dateUploaded']));
             }
             // Update category object to store new thumbnail information.
             $objectDao->updateObject($object);
         }
         unset($object);
     }
 }
Exemplo n.º 3
0
 /**
  * Serve the cover thumbnail for a published monograph.
  */
 function thumbnail($args, $request)
 {
     // use ASSOC_TYPE_MONOGRAPH to set the cover at any workflow stage
     // i.e. also if the monograph has not been published yet
     $monograph = $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
     $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
     $publishedMonograph = $publishedMonographDao->getById($monograph->getId(), null, false);
     if (!$publishedMonograph || !($coverImage = $publishedMonograph->getCoverImage())) {
         // Can't use Request::redirectUrl; FireFox doesn't
         // seem to like it for images.
         header('Location: ' . $request->getBaseUrl() . '/templates/images/book-default-small.png');
         exit;
     }
     import('classes.file.SimpleMonographFileManager');
     $simpleMonographFileManager = new SimpleMonographFileManager($publishedMonograph->getPressId(), $publishedMonograph->getId());
     $simpleMonographFileManager->downloadFile($simpleMonographFileManager->getBasePath() . $coverImage['thumbnailName'], null, true);
 }
Exemplo n.º 4
0
 /**
  * Serve the cover catalog image for a published monograph.
  */
 function catalog($args, $request)
 {
     $publishedMonograph = $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLISHED_MONOGRAPH);
     if (!($coverImage = $publishedMonograph->getCoverImage())) {
         // Can't use Request::redirectUrl; FireFox doesn't
         // seem to like it for images.
         header('Location: ' . $request->getBaseUrl() . '/templates/images/book-default.png');
         exit;
     }
     import('classes.file.SimpleMonographFileManager');
     $simpleMonographFileManager = new SimpleMonographFileManager($publishedMonograph->getPressId(), $publishedMonograph->getId());
     $simpleMonographFileManager->downloadFile($simpleMonographFileManager->getBasePath() . $coverImage['catalogName'], null, true);
 }