/** * @copydoc ContextSettingsForm::execute() */ function execute($request) { parent::execute($request); $coverThumbnailsResize = $this->getData('coverThumbnailsResize'); if ($coverThumbnailsResize) { $context = $request->getContext(); // new thumbnails max width and max height $coverThumbnailsMaxWidth = $this->getData('coverThumbnailsMaxWidth'); $coverThumbnailsMaxHeight = $this->getData('coverThumbnailsMaxHeight'); // resize cover thumbainls for all press categories import('lib.pkp.classes.file.ContextFileManager'); $pressFileManager = new ContextFileManager($context->getId()); $categoryBasePath = $pressFileManager->getBasePath() . 'categories/'; $categoryDao = DAORegistry::getDAO('CategoryDAO'); $this->_resizeCoverThumbnails($context, $categoryDao, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight, $categoryBasePath); // resize cover thumbainls for all press series $seriesBasePath = $pressFileManager->getBasePath() . 'series/'; $seriesDao = DAORegistry::getDAO('SeriesDAO'); $this->_resizeCoverThumbnails($context, $seriesDao, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight, $seriesBasePath); // resize cover thumbnails for all press published monographs $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO'); $this->_resizeCoverThumbnails($context, $publishedMonographDao, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight, ''); } }
/** * Get the base path for file storage. */ function getBasePath() { $dirNames = Application::getFileDirectories(); return parent::getBasePath() . $dirNames['submission'] . $this->_submissionId . '/'; }
/** * Save series. * @param $args array * @param $request PKPRequest */ function execute($args, $request) { $seriesDao = DAORegistry::getDAO('SeriesDAO'); $press = $request->getPress(); // Get or create the series object if ($this->getSeriesId()) { $series = $seriesDao->getById($this->getSeriesId(), $press->getId()); } else { $series = $seriesDao->newDataObject(); $series->setPressId($press->getId()); } // Populate/update the series object from the form $series->setPath($this->getData('path')); $series->setFeatured($this->getData('featured')); $series->setTitle($this->getData('title'), null); // Localized $series->setDescription($this->getData('description'), null); // Localized $series->setPrefix($this->getData('prefix'), null); // Localized $series->setSubtitle($this->getData('subtitle'), null); // Localized $series->setEditorRestricted($this->getData('restricted')); $series->setOnlineISSN($this->getData('onlineIssn')); $series->setPrintISSN($this->getData('printIssn')); $series->setSortOption($this->getData('sortOption')); // Insert or update the series in the DB if ($this->getSeriesId()) { $seriesDao->updateObject($series); } else { $this->setSeriesId($seriesDao->insertObject($series)); } // Handle the image upload if there was one. 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('lib.pkp.classes.file.ContextFileManager'); $pressFileManager = new ContextFileManager($press->getId()); $basePath = $pressFileManager->getBasePath() . '/series/'; // Delete the old file if it exists $oldSetting = $series->getImage(); if ($oldSetting) { $pressFileManager->deleteFile($basePath . $oldSetting['thumbnailName']); $pressFileManager->deleteFile($basePath . $oldSetting['name']); } // The following variables were fetched in validation assert($this->_sizeArray && $this->_imageExtension); // Generate the surrogate image. switch ($this->_imageExtension) { case '.jpg': $image = imagecreatefromjpeg($temporaryFilePath); break; case '.png': $image = imagecreatefrompng($temporaryFilePath); break; case '.gif': $image = imagecreatefromgif($temporaryFilePath); break; default: $image = null; // Suppress warn } assert($image); $coverThumbnailsMaxWidth = $press->getSetting('coverThumbnailsMaxWidth'); $coverThumbnailsMaxHeight = $press->getSetting('coverThumbnailsMaxHeight'); $thumbnailFilename = $series->getId() . '-series-thumbnail' . $this->_imageExtension; $xRatio = min(1, $coverThumbnailsMaxWidth / $this->_sizeArray[0]); $yRatio = min(1, $coverThumbnailsMaxHeight / $this->_sizeArray[1]); $ratio = min($xRatio, $yRatio); $thumbnailWidth = round($ratio * $this->_sizeArray[0]); $thumbnailHeight = round($ratio * $this->_sizeArray[1]); $thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight); imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $this->_sizeArray[0], $this->_sizeArray[1]); // Copy the new file over $filename = $series->getId() . '-series' . $this->_imageExtension; $pressFileManager->copyFile($temporaryFile->getFilePath(), $basePath . $filename); switch ($this->_imageExtension) { case '.jpg': imagejpeg($thumbnail, $basePath . $thumbnailFilename); break; case '.png': imagepng($thumbnail, $basePath . $thumbnailFilename); break; case '.gif': imagegif($thumbnail, $basePath . $thumbnailFilename); break; } imagedestroy($thumbnail); imagedestroy($image); $series->setImage(array('name' => $filename, 'width' => $this->_sizeArray[0], 'height' => $this->_sizeArray[1], 'thumbnailName' => $thumbnailFilename, 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, '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); } // Update series object to store image information. $seriesDao->updateObject($series); import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler'); // Save the series editor associations. ListbuilderHandler::unpack($request, $this->getData('subEditors'), array(&$this, 'deleteSubEditorEntry'), array(&$this, 'insertSubEditorEntry'), array(&$this, 'updateSubEditorEntry')); // Save the category associations. ListbuilderHandler::unpack($request, $this->getData('categories'), array(&$this, 'deleteCategoryEntry'), array(&$this, 'insertCategoryEntry'), array(&$this, 'updateCategoryEntry')); return true; }
/** * Serve the thumbnail for a category or series. */ function thumbnail($args, $request) { $press = $request->getPress(); $type = $request->getUserVar('type'); $id = $request->getUserVar('id'); $imageInfo = array(); $path = null; // Scrutinizer switch ($type) { case 'category': $path = '/categories/'; $categoryDao = DAORegistry::getDAO('CategoryDAO'); $category = $categoryDao->getById($id, $press->getId()); if ($category) { $imageInfo = $category->getImage(); } break; case 'series': $path = '/series/'; $seriesDao = DAORegistry::getDAO('SeriesDAO'); $series = $seriesDao->getById($id, $press->getId()); if ($series) { $imageInfo = $series->getImage(); } break; default: fatalError('invalid type specified'); break; } if ($imageInfo) { import('lib.pkp.classes.file.ContextFileManager'); $pressFileManager = new ContextFileManager($press->getId()); $pressFileManager->downloadFile($pressFileManager->getBasePath() . $path . $imageInfo['thumbnailName'], null, true); } }
/** * @see Form::execute() */ function execute($request) { $categoryId = $this->getCategoryId(); $categoryDao = DAORegistry::getDAO('CategoryDAO'); // Get a category object to edit or create if ($categoryId == null) { $category = $categoryDao->newDataObject(); $category->setPressId($this->getPressId()); } else { $category = $categoryDao->getById($categoryId, $this->getPressId()); } // Set the editable properties of the category object $category->setTitle($this->getData('name'), null); // Localized $category->setDescription($this->getData('description'), null); // Localized $category->setParentId($this->getData('parentId')); $category->setPath($this->getData('path')); $category->setSortOption($this->getData('sortOption')); // Update or insert the category object if ($categoryId == null) { $category->setId($categoryDao->insertObject($category)); } else { $category->setSequence(REALLY_BIG_NUMBER); $categoryDao->updateObject($category); $categoryDao->resequenceCategories($this->getPressId()); } // Handle the image upload if there was one. 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('lib.pkp.classes.file.ContextFileManager'); $pressFileManager = new ContextFileManager($this->getPressId()); $basePath = $pressFileManager->getBasePath() . '/categories/'; // Delete the old file if it exists $oldSetting = $category->getImage(); if ($oldSetting) { $pressFileManager->deleteFile($basePath . $oldSetting['thumbnailName']); $pressFileManager->deleteFile($basePath . $oldSetting['name']); } // The following variables were fetched in validation assert($this->_sizeArray && $this->_imageExtension); // Generate the surrogate images. switch ($this->_imageExtension) { case '.jpg': $image = imagecreatefromjpeg($temporaryFilePath); break; case '.png': $image = imagecreatefrompng($temporaryFilePath); break; case '.gif': $image = imagecreatefromgif($temporaryFilePath); break; default: $image = null; // Suppress warn } assert($image); $press = $request->getPress(); $coverThumbnailsMaxWidth = $press->getSetting('coverThumbnailsMaxWidth'); $coverThumbnailsMaxHeight = $press->getSetting('coverThumbnailsMaxHeight'); $thumbnailFilename = $category->getId() . '-category-thumbnail' . $this->_imageExtension; $xRatio = min(1, $coverThumbnailsMaxWidth / $this->_sizeArray[0]); $yRatio = min(1, $coverThumbnailsMaxHeight / $this->_sizeArray[1]); $ratio = min($xRatio, $yRatio); $thumbnailWidth = round($ratio * $this->_sizeArray[0]); $thumbnailHeight = round($ratio * $this->_sizeArray[1]); $thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight); imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $this->_sizeArray[0], $this->_sizeArray[1]); // Copy the new file over $filename = $category->getId() . '-category' . $this->_imageExtension; $pressFileManager->copyFile($temporaryFile->getFilePath(), $basePath . $filename); switch ($this->_imageExtension) { case '.jpg': imagejpeg($thumbnail, $basePath . $thumbnailFilename); break; case '.png': imagepng($thumbnail, $basePath . $thumbnailFilename); break; case '.gif': imagegif($thumbnail, $basePath . $thumbnailFilename); break; } imagedestroy($thumbnail); imagedestroy($image); $category->setImage(array('name' => $filename, 'width' => $this->_sizeArray[0], 'height' => $this->_sizeArray[1], 'thumbnailName' => $thumbnailFilename, 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, '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); } // Update category object to store image information. $categoryDao->updateObject($category); return $category; }
/** * Delete a press. * @param $args array * @param $request PKPRequest * @return string Serialized JSON object */ function deleteContext($args, $request) { // Identify the current context. $context = $request->getContext(); // Identify the press Id. $pressId = $request->getUserVar('rowId'); $pressDao = DAORegistry::getDAO('PressDAO'); $press = $pressDao->getById($pressId); if ($pressId) { $pressDao->deleteById($pressId); // Add publication formats tombstones for all press published monographs. import('classes.publicationFormat.PublicationFormatTombstoneManager'); $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager(); $publicationFormatTombstoneMgr->insertTombstonesByPress($press); // Delete press file tree // FIXME move this somewhere better. import('lib.pkp.classes.file.ContextFileManager'); $pressFileManager = new ContextFileManager($pressId); $pressFileManager->rmtree($pressFileManager->getBasePath()); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $publicFileManager->rmtree($publicFileManager->getPressFilesPath($pressId)); // If user is deleting the same press where he is... if ($context && $context->getId() == $pressId) { // return a redirect js event to index handler. $dispatcher = $request->getDispatcher(); $url = $dispatcher->url($request, ROUTE_PAGE, null, 'index'); return $request->redirectUrlJson($url); } return DAO::getDataChangedEvent($pressId); } return new JSONMessage(); }
/** * Save press settings. * @param $request PKPRequest */ function execute($request) { $pressDao = DAORegistry::getDAO('PressDAO'); if (isset($this->contextId)) { $press = $pressDao->getById($this->contextId); /* @var $press Press */ import('classes.publicationFormat.PublicationFormatTombstoneManager'); $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager(); if ($press->getEnabled() && !$this->getData('enabled')) { // Will disable the press. Create tombstones for all // published monographs publication formats. $publicationFormatTombstoneMgr->insertTombstonesByPress($press); } elseif (!$press->getEnabled() && $this->getData('enabled')) { // Will enable the press. Delete all tombstones. $publicationFormatTombstoneMgr->deleteTombstonesByPressId($press->getId()); } } if (!isset($press)) { $press = $pressDao->newDataObject(); } // Check if the press path has changed. $pathChanged = false; $pressPath = $press->getPath(); if ($pressPath != $this->getData('path')) { $pathChanged = true; } $press->setPath($this->getData('path')); $press->setEnabled($this->getData('enabled')); $isNewPress = false; $site = $request->getSite(); if ($press->getId() != null) { $pressDao->updateObject($press); } else { $isNewPress = true; // Give it a default primary locale $press->setPrimaryLocale($site->getPrimaryLocale()); $contextId = $pressDao->insertObject($press); $pressDao->resequence(); // Make the file directories for the press import('lib.pkp.classes.file.ContextFileManager'); $pressFileManager = new ContextFileManager($contextId); $pressFileManager->mkdir($pressFileManager->getBasePath()); $pressFileManager->mkdir($pressFileManager->getBasePath() . '/monographs'); $installedLocales = $site->getInstalledLocales(); // Install default genres $genreDao = DAORegistry::getDAO('GenreDAO'); $genreDao->installDefaults($contextId, $installedLocales); /* @var $genreDao GenreDAO */ // load the default user groups and stage assignments. $this->_loadDefaultUserGroups($press->getId()); $this->_assignManagerGroup($press->getId()); // Install default press settings $pressSettingsDao = DAORegistry::getDAO('PressSettingsDAO'); $titles = $this->getData('title'); AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_PKP_DEFAULT); $pressSettingsDao->installSettings($contextId, 'registry/pressSettings.xml', array('indexUrl' => $request->getIndexUrl(), 'pressPath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'contextName' => $titles[$site->getPrimaryLocale()], 'ldelim' => '{', 'rdelim' => '}')); } $press->updateSetting('supportedLocales', $site->getSupportedLocales()); $press->updateSetting('name', $this->getData('name'), 'string', true); $press->updateSetting('description', $this->getData('description'), 'string', true); // Make sure all plugins are loaded for settings preload PluginRegistry::loadAllPlugins(); HookRegistry::call('PressSiteSettingsForm::execute', array(&$this, &$press, &$isNewPress)); if ($isNewPress || $pathChanged) { return $press->getPath(); } }