diff --git a/plugins/generic/htmlArticleGalley/HtmlArticleGalleyPlugin.inc.php b/plugins/generic/htmlArticleGalley/HtmlArticleGalleyPlugin.inc.php index 1e33e6695e8..11923ab731a 100644 --- a/plugins/generic/htmlArticleGalley/HtmlArticleGalleyPlugin.inc.php +++ b/plugins/generic/htmlArticleGalley/HtmlArticleGalleyPlugin.inc.php @@ -15,6 +15,9 @@ import('lib.pkp.classes.plugins.GenericPlugin'); +define('HTML_ARTICLE_GALLEY_DISPLAY_IFRAME', 0); +define('HTML_ARTICLE_GALLEY_DISPLAY_INLINE', 1); + class HtmlArticleGalleyPlugin extends GenericPlugin { /** * @see Plugin::register() @@ -69,7 +72,14 @@ function articleViewCallback($hookName, $args) { 'article' => $article, 'galley' => $galley, )); - $templateMgr->display($this->getTemplateResource('display.tpl')); + $template = 'display.tpl'; + if ($this->getSetting($request->getContext()->getId(), 'htmlArticleGalleyDisplayType') === HTML_ARTICLE_GALLEY_DISPLAY_INLINE) { + $htmlArticleGalley = $this->_getHTMLContents($request, $galley); + $htmlArticleGalley = $this->_extractBodyContents($htmlArticleGalley); + $templateMgr->assign('htmlArticleGalley', $htmlArticleGalley); + $template = 'displayInline.tpl'; + } + $templateMgr->display($this->getTemplateResource($template)); return true; } @@ -100,6 +110,55 @@ function articleDownloadCallback($hookName, $args) { return false; } + /** + * @copydoc Plugin::getActions() + */ + function getActions($request, $verb) { + $router = $request->getRouter(); + import('lib.pkp.classes.linkAction.request.AjaxModal'); + return array_merge( + $this->getEnabled()?array( + new LinkAction( + 'settings', + new AjaxModal( + $router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')), + $this->getDisplayName() + ), + __('manager.plugins.settings'), + null + ), + ):array(), + parent::getActions($request, $verb) + ); + } + + /** + * @copydoc Plugin::manage() + */ + function manage($args, $request) { + $verb = $request->getUserVar('verb'); + switch ($verb) { + case 'settings': + $templateMgr = TemplateManager::getManager(); + $templateMgr->register_function('plugin_url', array($this, 'smartyPluginUrl')); + $context = $request->getContext(); + + $this->import('HtmlArticleGalleySettingsForm'); + $form = new HtmlArticleGalleySettingsForm($this, $context->getId()); + if ($request->getUserVar('save')) { + $form->readInputData(); + if ($form->validate()) { + $form->execute(); + return new JSONMessage(true); + } + } else { + $form->initData(); + } + return new JSONMessage(true, $form->fetch($request)); + } + return parent::manage($args, $request); + } + /** * Return string containing the contents of the HTML file. * This function performs any necessary filtering, like image URL replacement. @@ -187,6 +246,33 @@ function _getHTMLContents($request, $galley) { return $contents; } + /** + * Return string containing the contents of the HTML body + * @param $html string + * @return string + */ + function _extractBodyContents($html) { + $bodyContent = ''; + try { + $errorsEnabled = libxml_use_internal_errors(); + libxml_use_internal_errors(true); + $dom = DOMDocument::loadHTML($html); + $tags = $dom->getElementsByTagName('body'); + foreach ($tags as $body) { + foreach ($body->childNodes as $child) { + $bodyContent .= $dom->saveHTML($child); + } + last; + } + libxml_use_internal_errors($errorsEnabled); + } catch (Exception $e) { + $html = preg_replace('/.*
]*>/isA', '', $html); + $html = preg_replace('/<\/body\s*>.*$/isD', '', $html); + $bodyContent = $html; + } + return $bodyContent; + } + function _handleOjsUrl($matchArray) { $request = Application::getRequest(); $url = $matchArray[2]; diff --git a/plugins/generic/htmlArticleGalley/HtmlArticleGalleySettingsForm.inc.php b/plugins/generic/htmlArticleGalley/HtmlArticleGalleySettingsForm.inc.php new file mode 100644 index 00000000000..63eebc13cc4 --- /dev/null +++ b/plugins/generic/htmlArticleGalley/HtmlArticleGalleySettingsForm.inc.php @@ -0,0 +1,73 @@ +_journalId = $journalId; + $this->_plugin = $plugin; + + parent::__construct($plugin->getTemplateResource('settingsForm.tpl')); + + $this->addCheck(new FormValidatorPost($this)); + $this->addCheck(new FormValidatorCSRF($this)); + } + + /** + * Initialize form data. + */ + function initData() { + $this->_data = array( + 'htmlArticleGalleyDisplayType' => $this->_plugin->getSetting($this->_journalId, 'htmlArticleGalleyDisplayType'), + ); + } + + /** + * Assign form data to user-submitted data. + */ + function readInputData() { + $this->readUserVars(array('htmlArticleGalleyDisplayType')); + } + + /** + * @copydoc Form::fetch() + */ + function fetch($request, $template = null, $display = false) { + $templateMgr = TemplateManager::getManager($request); + $templateMgr->assign('pluginName', $this->_plugin->getName()); + return parent::fetch($request, $template, $display); + } + + /** + * Save settings. + */ + function execute(...$functionArgs) { + $this->_plugin->updateSetting($this->_journalId, 'htmlArticleGalleyDisplayType', $this->getData('htmlArticleGalleyDisplayType'), 'int'); + } +} + diff --git a/plugins/generic/htmlArticleGalley/locale/en_US/locale.xml b/plugins/generic/htmlArticleGalley/locale/en_US/locale.xml index 118b8c633d7..d7a6dbcd15b 100644 --- a/plugins/generic/htmlArticleGalley/locale/en_US/locale.xml +++ b/plugins/generic/htmlArticleGalley/locale/en_US/locale.xml @@ -14,4 +14,7 @@