forked from richardalberto/ojs-dynamicgalleys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicGalleysPlugin.inc.php
217 lines (179 loc) · 7.85 KB
/
DynamicGalleysPlugin.inc.php
1
<?php/** * @file DynamicGalleysPlugin.php * * Copyright (c) 2009-2011 Richard González Alberto * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING. * * @ingroup plugins_generic_dynamicGalleys * @brief Dynamic Galleys generic plugin. * */import('lib.pkp.classes.plugins.GenericPlugin');class DynamicGalleysPlugin extends GenericPlugin { function register($category, $path) { $success = parent::register($category, $path); $this->addLocaleData(); if ($success && $this->getEnabled()) { define('DYNAMIC_GALLEYS_PLUGIN_NAME', $this->getName()); $this->import('classes.ArticleDynamicGalleyDAO'); $dynamicGalleyDao = new ArticleDynamicGalleyDAO(); DAORegistry::registerDAO('ArticleDynamicGalleyDAO', $dynamicGalleyDao); // These hooks essentially modify/overload the existing ArticleGalleyDAO methods HookRegistry::register('PublishedArticleDAO::_returnPublishedArticleFromRow', array(&$dynamicGalleyDao, 'appendDynamicGalleys') ); HookRegistry::register('ArticleGalleyDAO::incrementGalleyViews', array(&$dynamicGalleyDao, 'incrementDynamicGalleyViews') ); HookRegistry::register('ArticleGalleyDAO::_returnGalleyFromRow', array(&$this, 'returnDynamicGalley') ); HookRegistry::register('ArticleGalleyDAO::getNewGalley', array(&$this, 'getDynamicGalley') ); // These hooks are required in the absence of hooks in the viewFile and download methods HookRegistry::register( 'ArticleHandler::viewFile', array(&$this, 'viewDynamicGalleyFile') ); HookRegistry::register( 'ArticleHandler::downloadFile', array(&$this, 'viewDynamicGalleyFile') ); HookRegistry::register( '$this->downloadFile', array(&$this, 'viewDynamicGalleyFile') ); // TODO: this is an ojs bug! // Handler HookRegistry::register('LoadHandler', array($this, 'setupPublicHandler')); // Editor page for editor access HookRegistry::register('Templates::Editor::Index::AdditionalItems', array($this, 'displayEditorHomeLink')); } return $success; } function getDisplayName() { return Locale::translate('plugins.generic.dynamicGalleys.displayName'); } function getDescription() { return Locale::translate('plugins.generic.dynamicGalleys.description'); } /** * Get the filename of the ADODB schema for this plugin. */ function getInstallSchemaFile() { return $this->getPluginPath() . '/' . 'schema.xml'; } /** * Get the template path for this plugin. */ function getTemplatePath() { return parent::getTemplatePath() . 'templates/'; } /** * Get the stylesheets path for this plugin. */ function getStylesPath(){ return parent::getTemplatePath() . 'styles/'; } /** * Get the handler path for this plugin. */ function getHandlerPath() { return $this->getPluginPath() . '/pages/'; } /** * Return Dynamic galley by ID from article_dynamic_galleys * (which does not exist in article_galleys) */ function getDynamicGalley($hookName, $args) { if (!$this->getEnabled()) return false; $galleyId =& $args[0]; $articleId =& $args[1]; $returner =& $args[2]; $dynamicGalleyDao = &DAORegistry::getDAO('ArticleDynamicGalleyDAO'); $dynamicGalley = $dynamicGalleyDao->_getDynamicGalleyFromId($galleyId, $articleId); if ($dynamicGalley) { //set template javascript and css // TODO: find a better place to put this code $templateMgr = &TemplateManager::getManager(); $templateMgr->addJavaScript('plugins/generic/dynamicGalleys/lightbox/js/jquery-1.7.2.min.js'); $templateMgr->addJavaScript('plugins/generic/dynamicGalleys/lightbox/js/lightbox.js'); $templateMgr->addStyleSheet(Request::getBaseUrl().'/plugins/generic/dynamicGalleys/styles/articleView_body.css'); $templateMgr->addStyleSheet(Request::getBaseUrl().'/plugins/generic/dynamicGalleys/lightbox/css/lightbox.css'); $dynamicGalley->setGalleyId($galleyId); $returner = $dynamicGalley; return true; } return false; } /** * Return Dynamic galley as a file; basically this is a PDF file */ function viewDynamicGalleyFile($hookName, $args) { if (!$this->getEnabled()) return false; $article =& $args[0]; $galley =& $args[1]; $fileId =& $args[2]; $journal = &Request::getJournal(); if (get_class($galley) == 'ArticleDynamicGalley') return $galley->viewFileContents(); else return false; } /** * Append some special attributes to a galley identified as XML, and * Return an ArticleDynamicGalley object as appropriate */ function returnDynamicGalley($hookName, $args) { if (!$this->getEnabled()) return false; $galley =& $args[0]; $row =& $args[1]; // If the galley is an XML file, then convert it from an HTML Galley to an XML Galley if ($galley->getFileType() == "text/xml") { $galley = $this->_returnDynamicGalleyFromArticleGalley($galley); return true; } return false; } /** * Internal function to return an ArticleDynamicGalley object from an ArticleGalley object * @param $galley ArticleGalley * @return ArticleDynamicGalley */ function _returnDynamicGalleyFromArticleGalley(&$galley) { $this->import('classes.ArticleDynamicGalley'); $articleDynamicGalley = new ArticleDynamicGalley(); // Create Galley with previous values $articleDynamicGalley->setGalleyId($galley->getGalleyId()); $articleDynamicGalley->setArticleId($galley->getArticleId()); $articleDynamicGalley->setFileId($galley->getFileId()); $articleDynamicGalley->setLabel($galley->getLabel()); $articleDynamicGalley->setSequence($galley->getSequence()); $articleDynamicGalley->setViews($galley->getViews()); $articleDynamicGalley->setFileName($galley->getFileName()); $articleDynamicGalley->setOriginalFileName($galley->getOriginalFileName()); $articleDynamicGalley->setFileType($galley->getFileType()); $articleDynamicGalley->setFileSize($galley->getFileSize()); $articleDynamicGalley->setStatus($galley->getStatus()); $articleDynamicGalley->setDateModified($galley->getDateModified()); $articleDynamicGalley->setDateUploaded($galley->getDateUploaded()); $articleDynamicGalley->setLocale($galley->getLocale()); $articleDynamicGalley->setType('public'); // Copy CSS and image file references from source galley if ($galley->isHTMLGalley()) { $articleDynamicGalley->setStyleFileId($galley->getStyleFileId()); $articleDynamicGalley->setStyleFile($galley->getStyleFile()); $articleDynamicGalley->setImageFiles($galley->getImageFiles()); } return $articleDynamicGalley; } /** * Displays a link to the plugin on the editor's page */ function displayEditorHomeLink($hookName, $params) { if ($this->getEnabled()) { $smarty =& $params[1]; $output =& $params[2]; $templateMgr = TemplateManager::getManager(); $url = $templateMgr->smartyUrl(array('page'=>'DynamicGalleysPlugin'), $smarty); $output .= '<h3>' . $templateMgr->smartyTranslate(array('key'=>'plugins.generic.dynamicGalleys.displayName'), $smarty) . '</h3><ul class="plain"><li>» <a href="' . $url . '">' . $templateMgr->smartyTranslate(array('key'=>'plugins.generic.dynamicGalleys.displayName'), $smarty) . '</a></li></ul>'; //echo $output; } return false; } /** * Setup plublic handler */ function setupPublicHandler($hookName, $params) { $page = &$params[0]; if ($page == 'DynamicGalleysPlugin') { define('HANDLER_CLASS', 'DynamicGalleysHandler'); Locale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON)); $handlerFile = &$params[2]; $handlerFile = $this->getHandlerPath() . '/' . 'DynamicGalleysHandler.inc.php'; } }}?>