Skip to content

Commit 9f2d676

Browse files
authored
Merge pull request #2 from ulsdevteam/bootstraptheming
Convert plugin align with Bootstrap3 standards
2 parents bad09a3 + ba12481 commit 9f2d676

23 files changed

Lines changed: 1060 additions & 30 deletions

InlineHtmlGalleyBlockPlugin.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ function getEnabled($contextId = null) {
5454
* @return String
5555
*/
5656
function getDisplayName() {
57-
return __('plugins.generic.inlineHtmlGalley.block.displayName');
57+
return __('plugins.generic.inlineHtmlGalley.block.download.displayName');
5858
}
5959

6060
/**
6161
* Get a description of the plugin.
6262
* @return String
6363
*/
6464
function getDescription() {
65-
return __('plugins.generic.inlineHtmlGalley.block.description');
65+
return __('plugins.generic.inlineHtmlGalley.block.download.description');
6666
}
6767

6868
/**

InlineHtmlGalleyPlugin.inc.php

Lines changed: 140 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,54 @@ function register($category, $path, $mainContextId = null) {
3131
new InlineHtmlGalleyBlockPlugin($this->getName(), $this->getPluginPath()),
3232
$this->getPluginPath()
3333
);
34+
$this->import('InlineHtmlGalleySidebarBlockPlugin');
35+
PluginRegistry::register(
36+
'blocks',
37+
new InlineHtmlGalleyAuthorsSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
38+
$this->getPluginPath()
39+
);
40+
PluginRegistry::register(
41+
'blocks',
42+
new InlineHtmlGalleyKeywordsSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
43+
$this->getPluginPath()
44+
);
45+
PluginRegistry::register(
46+
'blocks',
47+
new InlineHtmlGalleyDoiSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
48+
$this->getPluginPath()
49+
);
50+
PluginRegistry::register(
51+
'blocks',
52+
new InlineHtmlGalleyCoverImageSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
53+
$this->getPluginPath()
54+
);
55+
PluginRegistry::register(
56+
'blocks',
57+
new InlineHtmlGalleyPublishedDateSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
58+
$this->getPluginPath()
59+
);
60+
PluginRegistry::register(
61+
'blocks',
62+
new InlineHtmlGalleyHowToCiteSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
63+
$this->getPluginPath()
64+
);
65+
PluginRegistry::register(
66+
'blocks',
67+
new InlineHtmlGalleyLicenseSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
68+
$this->getPluginPath()
69+
);
70+
PluginRegistry::register(
71+
'blocks',
72+
new InlineHtmlGalleyReferencesSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
73+
$this->getPluginPath()
74+
);
75+
PluginRegistry::register(
76+
'blocks',
77+
new InlineHtmlGalleyGalleysSidebarBlockPlugin($this->getName(), $this->getPluginPath()),
78+
$this->getPluginPath()
79+
);
80+
HookRegistry::register('ArticleHandler::view', array($this, 'articleViewCallback'), HOOK_SEQUENCE_LATE);
81+
HookRegistry::register('TemplateResource::getFilename', array($this, '_overridePluginTemplates'), HOOK_SEQUENCE_CORE);
3482
}
3583

3684
return true;
@@ -57,24 +105,30 @@ function getDescription() {
57105
* @param array $args
58106
*/
59107
function articleViewCallback($hookName, $args) {
60-
$request =& $args[0];
61-
$issue =& $args[1];
62-
$galley =& $args[2];
63-
$article =& $args[3];
108+
if ($hookName == "ArticleHandler::view") {
109+
$request =& $args[0];
110+
$issue =& $args[1];
111+
$article =& $args[2];
112+
$galleys = $article->getGalleys();
113+
if (!$galleys) return false;
64114

65-
if ($galley && $galley->getFileType() == 'text/html') {
66-
$templateMgr = TemplateManager::getManager($request);
67-
$templateMgr->assign(array(
68-
'issue' => $issue,
69-
'article' => $article,
70-
'galley' => $galley,
71-
));
72-
$inlineHtmlGalley = $this->_getHTMLContents($request, $galley);
73-
$inlineHtmlGalleyBody = $this->_extractBodyContents($inlineHtmlGalley);
74-
$templateMgr->assign('inlineHtmlGalley', $inlineHtmlGalleyBody);
75-
$templateMgr->display($this->getTemplateResource('displayInline.tpl'));
115+
foreach ($galleys as $galley) {
116+
if ($galley->getFileType() == 'text/html') {
117+
$templateMgr = TemplateManager::getManager($request);
118+
$templateMgr->assign(array(
119+
'issue' => $issue,
120+
'article' => $article,
121+
'galley' => $galley,
122+
'orcidIcon' => $this->getOrcidIcon()
123+
));
124+
$inlineHtmlGalley = $this->_getHTMLContents($request, $galley);
125+
$inlineHtmlGalleyBody = $this->_extractBodyContents($inlineHtmlGalley, $request->getContext()->getId());
126+
$templateMgr->assign('inlineHtmlGalley', $inlineHtmlGalleyBody);
127+
$templateMgr->display($this->getTemplateResource('displayInline.tpl'));
76128

77-
return true;
129+
return true;
130+
}
131+
}
78132
}
79133

80134
return false;
@@ -83,23 +137,33 @@ function articleViewCallback($hookName, $args) {
83137
/**
84138
* Return string containing the contents of the HTML body
85139
* @param $html string
140+
* @param $contextId int
86141
* @return string
87142
*/
88-
function _extractBodyContents($html) {
143+
function _extractBodyContents($html, $contextId) {
89144
$bodyContent = '';
90145
try {
91-
if (!function_exists('libxml_use_internal_errors') || !class_exists('DOMDocument')) {
146+
if (!function_exists('libxml_use_internal_errors') || !class_exists('DOMDocument') || !class_exists('DOMXPath')) {
92147
throw new Exception('Missing libxml/dom requirements');
93148
}
94149
$errorsEnabled = libxml_use_internal_errors();
95150
libxml_use_internal_errors(true);
96151
$dom = DOMDocument::loadHTML($html);
97-
$tags = $dom->getElementsByTagName('body');
98-
foreach ($tags as $body) {
99-
foreach ($body->childNodes as $child) {
100-
$bodyContent .= $dom->saveHTML($child);
152+
$xpath = $this->getSetting($contextId, 'xpath');
153+
if (empty($xpath)) {
154+
$tags = $dom->getElementsByTagName('body');
155+
foreach ($tags as $body) {
156+
foreach ($body->childNodes as $child) {
157+
$bodyContent .= $dom->saveHTML($child);
158+
}
159+
last;
160+
}
161+
} else {
162+
$domXpath = new DOMXPath($dom);
163+
$tags = $domXpath->query($xpath);
164+
foreach ($tags as $tag) {
165+
$bodyContent .= $dom->saveHTML($tag);
101166
}
102-
last;
103167
}
104168
libxml_use_internal_errors($errorsEnabled);
105169
} catch (Exception $e) {
@@ -109,4 +173,57 @@ function _extractBodyContents($html) {
109173
}
110174
return $bodyContent;
111175
}
176+
177+
/**
178+
* Return a string of the ORCiD SVG icon
179+
*
180+
* @return string
181+
*/
182+
function getOrcidIcon() {
183+
$path = Core::getBaseDir() . '/' . $this->getPluginPath() . '/templates/images/orcid.svg';
184+
return file_exists($path) ? file_get_contents($path) : '';
185+
}
186+
187+
/**
188+
* @copydoc Plugin::manage()
189+
*/
190+
function manage($args, $request) {
191+
$this->import('InlineHtmlGalleySettingsForm');
192+
if ($request->getUserVar('verb') == 'settings') {
193+
$settingsForm = new InlineHtmlGalleySettingsForm($this, $request->getContext()->getId());
194+
if ($request->getUserVar('save')) {
195+
$settingsForm->readInputData();
196+
if ($settingsForm->validate()) {
197+
$settingsForm->execute();
198+
return new JSONMessage(true);
199+
}
200+
} else {
201+
$settingsForm->initData();
202+
}
203+
return new JSONMessage(true, $settingsForm->fetch($request));
204+
}
205+
return parent::manage($args, $request);
206+
}
207+
208+
/**
209+
* @copydoc Plugin::getActions()
210+
*/
211+
function getActions($request, $verb) {
212+
$router = $request->getRouter();
213+
import('lib.pkp.classes.linkAction.request.AjaxModal');
214+
return array_merge(
215+
$this->getEnabled()?array(
216+
new LinkAction(
217+
'settings',
218+
new AjaxModal(
219+
$router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
220+
$this->getDisplayName()
221+
),
222+
__('manager.plugins.settings'),
223+
null
224+
),
225+
):array(),
226+
parent::getActions($request, $verb)
227+
);
228+
}
112229
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/**
4+
* @file plugins/generic/inlineHtmlGalley/InlineHtmlGalleySettingsForm.inc.php
5+
*
6+
* Copyright (c) University of Pittsburgh
7+
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
8+
*
9+
* @class InlineHtmlGalleySettingsForm
10+
* @ingroup plugins_generic_inlineHtmlGalley
11+
*
12+
* @brief Form to provide settings for the InlineHtmlGalley plugin
13+
*/
14+
15+
import('lib.pkp.classes.form.Form');
16+
17+
class InlineHtmlGalleySettingsForm extends Form {
18+
19+
/** @var $plugin InlineHtmlGalleyPlugin */
20+
var $plugin;
21+
22+
/** @var $contextId int */
23+
var $contextId;
24+
25+
/**
26+
* Constructor
27+
* @param $plugin InlineHtmlGalleyPlugin
28+
* @param $contextId int
29+
*/
30+
function __construct($plugin, $contextId) {
31+
$this->plugin = $plugin;
32+
$this->contextId = $contextId;
33+
34+
parent::__construct(method_exists($plugin, 'getTemplateResource') ? $plugin->getTemplateResource('settingsForm.tpl') : $plugin->getTemplatePath() . 'settingsForm.tpl');
35+
36+
$this->addCheck(new FormValidatorPost($this));
37+
$this->addCheck(new FormValidatorCSRF($this));
38+
}
39+
40+
/**
41+
* @copydoc Form::initData()
42+
*/
43+
function initData() {
44+
$this->setData('xpath', $this->plugin->getSetting($this->contextId, 'xpath'));
45+
}
46+
47+
/**
48+
* @copydoc Form::readInputData()
49+
*/
50+
function readInputData() {
51+
$this->readUserVars(array('xpath'));
52+
}
53+
54+
/**
55+
* @copydoc Form::fetch()
56+
*/
57+
function fetch($request) {
58+
$templateMgr = TemplateManager::getManager($request);
59+
$templateMgr->assign('pluginName', $this->plugin->getName());
60+
61+
return parent::fetch($request);
62+
}
63+
64+
/**
65+
* @copydoc Form::execute()
66+
*/
67+
function execute() {
68+
$this->plugin->updateSetting($this->contextId, 'xpath', $this->getData('xpath'));
69+
}
70+
}

0 commit comments

Comments
 (0)