Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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('/.*<body[^>]*>/isA', '', $html);
$html = preg_replace('/<\/body\s*>.*$/isD', '', $html);
$bodyContent = $html;
}
return $bodyContent;
}

function _handleOjsUrl($matchArray) {
$request = Application::getRequest();
$url = $matchArray[2];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* @file plugins/generic/htmlArticleGalley/HtmlArticleGalleySettingsForm.inc.php
*
* Copyright (c) 2014-2019 Simon Fraser University
* Copyright (c) 2003-2019 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class HtmlArticleGalleySettingsForm
* @ingroup plugins_generic_htmlArticleGalley
*
* @brief Form for journal managers to modify how HTML Article Galleys are presented
*/

import('lib.pkp.classes.form.Form');

class HtmlArticleGalleySettingsForm extends Form {

/** @var int */
var $_journalId;

/** @var object */
var $_plugin;

/**
* Constructor
* @param $plugin HtmlArticleGalleyPlugin
* @param $journalId int
*/
function __construct($plugin, $journalId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstract out journalId to a contextId

$this->_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');
}
}

3 changes: 3 additions & 0 deletions plugins/generic/htmlArticleGalley/locale/en_US/locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<locale name="en_US" full_name="U.S. English">
<message key="plugins.generic.htmlArticleGalley.displayName">HTML Article Galley</message>
<message key="plugins.generic.htmlArticleGalley.description">This plugin provides rendering support for HTML Article Galleys.</message>
<message key="plugins.generic.htmlArticleGalley.manager.settings.title">Customize the display of HTML Galleys.</message>
<message key="plugins.generic.htmlArticleGalley.manager.settings.description">A HTML Galley may be displayed directly in the site inline, or via an iframe. The iframe will use a minimal header and footer and will maximize the presentation of the content. Displaying the article inline will merge the body of the article with the body of the site.</message>
<message key="plugins.generic.htmlArticleGalley.manager.settings.htmlArticleGalleyDisplayType">Display the HTML Galley inline, rather than via an iframe.</message>
</locale>
34 changes: 34 additions & 0 deletions plugins/generic/htmlArticleGalley/templates/displayInline.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{**
* templates/frontend/pages/article.tpl
*
* Copyright (c) 2014-2019 Simon Fraser University
* Copyright (c) 2003-2019 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @brief Display the page to view an article with all of it's details.
*
* @uses $article Article This article
* @uses $issue Issue The issue this article is assigned to
* @uses $section Section The journal section this article is assigned to
* @uses $journal Journal The journal currently being viewed.
* @uses $primaryGalleys array List of article galleys that are not supplementary or dependent
* @uses $supplementaryGalleys array List of article galleys that are supplementary
* @uses $htmlArticleGalley string The HTML content of the Article Galley
*}
{include file="frontend/components/header.tpl" pageTitleTranslated=$article->getLocalizedTitle()|escape}

<div class="page page_article">
{if $section}
{include file="frontend/components/breadcrumbs_article.tpl" currentTitle=$section->getLocalizedTitle()}
{else}
{include file="frontend/components/breadcrumbs_article.tpl" currentTitleKey="article.article"}
{/if}

{* Show article inline *}
{$htmlArticleGalley}

{call_hook name="Templates::Article::Footer::PageFooter"}

</div><!-- .page -->

{include file="frontend/components/footer.tpl"}
29 changes: 29 additions & 0 deletions plugins/generic/htmlArticleGalley/templates/settingsForm.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{**
* plugins/generic/htmlArticleGalley/settingsForm.tpl
*
* Copyright (c) 2014-2019 Simon Fraser University
* Copyright (c) 2003-2019 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* HTML Article Galley plugin settings
*
*}
<script>
$(function() {ldelim}
// Attach the form handler.
$('#hagSettingsForm').pkpHandler('$.pkp.controllers.form.AjaxFormHandler');
{rdelim});
</script>

<form class="pkp_form" id="hagSettingsForm" method="post" action="{url router=$smarty.const.ROUTE_COMPONENT op="manage" category="generic" plugin=$pluginName verb="settings" save=true}">
{csrf}
{include file="controllers/notification/inPlaceNotification.tpl" notificationId="hagSettingsFormNotification"}

{fbvFormArea id="htmlArticleGalleySettingsFormArea" title="plugins.generic.htmlArticleGalley.manager.settings.title"}
{fbvFormSection for="htmlArticleGalleyDisplayType" list=true description="plugins.generic.htmlArticleGalley.manager.settings.description"}
{fbvElement type="checkbox" id="htmlArticleGalleyDisplayType" value=HTML_ARTICLE_GALLEY_DISPLAY_INLINE checked=$htmlArticleGalleyDisplayType label="plugins.generic.htmlArticleGalley.manager.settings.htmlArticleGalleyDisplayType"}
{/fbvFormSection}
{/fbvFormArea}

{fbvFormButtons}
</form>
4 changes: 2 additions & 2 deletions plugins/generic/htmlArticleGalley/version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<version>
<application>htmlArticleGalley</application>
<type>plugins.generic</type>
<release>1.0.0.0</release>
<date>2013-07-02</date>
<release>1.0.1.0</release>
<date>2020-10-12</date>
<lazy-load>1</lazy-load>
<class>HtmlArticleGalleyPlugin</class>
</version>