Skip to content
Merged
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
4 changes: 2 additions & 2 deletions InlineHtmlGalleyBlockPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ function getEnabled($contextId = null) {
* @return String
*/
function getDisplayName() {
return __('plugins.generic.inlineHtmlGalley.block.displayName');
return __('plugins.generic.inlineHtmlGalley.block.download.displayName');
}

/**
* Get a description of the plugin.
* @return String
*/
function getDescription() {
return __('plugins.generic.inlineHtmlGalley.block.description');
return __('plugins.generic.inlineHtmlGalley.block.download.description');
}

/**
Expand Down
163 changes: 140 additions & 23 deletions InlineHtmlGalleyPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,54 @@ function register($category, $path, $mainContextId = null) {
new InlineHtmlGalleyBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
$this->import('InlineHtmlGalleySidebarBlockPlugin');
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyAuthorsSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyKeywordsSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyDoiSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyCoverImageSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyPublishedDateSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyHowToCiteSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyLicenseSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyReferencesSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
PluginRegistry::register(
'blocks',
new InlineHtmlGalleyGalleysSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
$this->getPluginPath()
);
HookRegistry::register('ArticleHandler::view', array($this, 'articleViewCallback'), HOOK_SEQUENCE_LATE);
HookRegistry::register('TemplateResource::getFilename', array($this, '_overridePluginTemplates'), HOOK_SEQUENCE_CORE);
}

return true;
Expand All @@ -57,24 +105,30 @@ function getDescription() {
* @param array $args
*/
function articleViewCallback($hookName, $args) {
$request =& $args[0];
$issue =& $args[1];
$galley =& $args[2];
$article =& $args[3];
if ($hookName == "ArticleHandler::view") {
$request =& $args[0];
$issue =& $args[1];
$article =& $args[2];
$galleys = $article->getGalleys();
if (!$galleys) return false;

if ($galley && $galley->getFileType() == 'text/html') {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array(
'issue' => $issue,
'article' => $article,
'galley' => $galley,
));
$inlineHtmlGalley = $this->_getHTMLContents($request, $galley);
$inlineHtmlGalleyBody = $this->_extractBodyContents($inlineHtmlGalley);
$templateMgr->assign('inlineHtmlGalley', $inlineHtmlGalleyBody);
$templateMgr->display($this->getTemplateResource('displayInline.tpl'));
foreach ($galleys as $galley) {
if ($galley->getFileType() == 'text/html') {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array(
'issue' => $issue,
'article' => $article,
'galley' => $galley,
'orcidIcon' => $this->getOrcidIcon()
));
$inlineHtmlGalley = $this->_getHTMLContents($request, $galley);
$inlineHtmlGalleyBody = $this->_extractBodyContents($inlineHtmlGalley, $request->getContext()->getId());
$templateMgr->assign('inlineHtmlGalley', $inlineHtmlGalleyBody);
$templateMgr->display($this->getTemplateResource('displayInline.tpl'));

return true;
return true;
}
}
}

return false;
Expand All @@ -83,23 +137,33 @@ function articleViewCallback($hookName, $args) {
/**
* Return string containing the contents of the HTML body
* @param $html string
* @param $contextId int
* @return string
*/
function _extractBodyContents($html) {
function _extractBodyContents($html, $contextId) {
$bodyContent = '';
try {
if (!function_exists('libxml_use_internal_errors') || !class_exists('DOMDocument')) {
if (!function_exists('libxml_use_internal_errors') || !class_exists('DOMDocument') || !class_exists('DOMXPath')) {
throw new Exception('Missing libxml/dom requirements');
}
$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);
$xpath = $this->getSetting($contextId, 'xpath');
if (empty($xpath)) {
$tags = $dom->getElementsByTagName('body');
foreach ($tags as $body) {
foreach ($body->childNodes as $child) {
$bodyContent .= $dom->saveHTML($child);
}
last;
}
} else {
$domXpath = new DOMXPath($dom);
$tags = $domXpath->query($xpath);
foreach ($tags as $tag) {
$bodyContent .= $dom->saveHTML($tag);
}
last;
}
libxml_use_internal_errors($errorsEnabled);
} catch (Exception $e) {
Expand All @@ -109,4 +173,57 @@ function _extractBodyContents($html) {
}
return $bodyContent;
}

/**
* Return a string of the ORCiD SVG icon
*
* @return string
*/
function getOrcidIcon() {
$path = Core::getBaseDir() . '/' . $this->getPluginPath() . '/templates/images/orcid.svg';
return file_exists($path) ? file_get_contents($path) : '';
}

/**
* @copydoc Plugin::manage()
*/
function manage($args, $request) {
$this->import('InlineHtmlGalleySettingsForm');
if ($request->getUserVar('verb') == 'settings') {
$settingsForm = new InlineHtmlGalleySettingsForm($this, $request->getContext()->getId());
if ($request->getUserVar('save')) {
$settingsForm->readInputData();
if ($settingsForm->validate()) {
$settingsForm->execute();
return new JSONMessage(true);
}
} else {
$settingsForm->initData();
}
return new JSONMessage(true, $settingsForm->fetch($request));
}
return parent::manage($args, $request);
}

/**
* @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)
);
}
}
70 changes: 70 additions & 0 deletions InlineHtmlGalleySettingsForm.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* @file plugins/generic/inlineHtmlGalley/InlineHtmlGalleySettingsForm.inc.php
*
* Copyright (c) University of Pittsburgh
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
*
* @class InlineHtmlGalleySettingsForm
* @ingroup plugins_generic_inlineHtmlGalley
*
* @brief Form to provide settings for the InlineHtmlGalley plugin
*/

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

class InlineHtmlGalleySettingsForm extends Form {

/** @var $plugin InlineHtmlGalleyPlugin */
var $plugin;

/** @var $contextId int */
var $contextId;

/**
* Constructor
* @param $plugin InlineHtmlGalleyPlugin
* @param $contextId int
*/
function __construct($plugin, $contextId) {
$this->plugin = $plugin;
$this->contextId = $contextId;

parent::__construct(method_exists($plugin, 'getTemplateResource') ? $plugin->getTemplateResource('settingsForm.tpl') : $plugin->getTemplatePath() . 'settingsForm.tpl');

$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}

/**
* @copydoc Form::initData()
*/
function initData() {
$this->setData('xpath', $this->plugin->getSetting($this->contextId, 'xpath'));
}

/**
* @copydoc Form::readInputData()
*/
function readInputData() {
$this->readUserVars(array('xpath'));
}

/**
* @copydoc Form::fetch()
*/
function fetch($request) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->plugin->getName());

return parent::fetch($request);
}

/**
* @copydoc Form::execute()
*/
function execute() {
$this->plugin->updateSetting($this->contextId, 'xpath', $this->getData('xpath'));
}
}
Loading