Skip to content

Commit a9468e7

Browse files
committed
Port plugin from htmlArticleGalley plugin
0 parents  commit a9468e7

6 files changed

Lines changed: 216 additions & 0 deletions

File tree

InlineHtmlGalleyPlugin.inc.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* @file plugins/generic/inlineHtmlGalley/InlineHtmlGalleyPlugin.inc.php
5+
*
6+
* Copyright (c) University of Pittsburgh
7+
* Copyright (c) 2014-2020 Simon Fraser University
8+
* Copyright (c) 2003-2020 John Willinsky
9+
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
10+
*
11+
* @class InlineHtmlGalleyPlugin
12+
* @ingroup plugins_generic_inlineHtmlGalley
13+
*
14+
* @brief Class for InlineHtmlGalley plugin
15+
*/
16+
17+
import('plugins.generic.htmlArticleGalley.HtmlArticleGalleyPlugin');
18+
19+
class InlineHtmlGalleyPlugin extends HtmlArticleGalleyPlugin {
20+
/**
21+
* @see Plugin::register()
22+
*/
23+
function register($category, $path, $mainContextId = null) {
24+
if (!parent::register($category, $path, $mainContextId)) return false;
25+
return true;
26+
}
27+
28+
/**
29+
* Get the display name of this plugin.
30+
* @return String
31+
*/
32+
function getDisplayName() {
33+
return __('plugins.generic.inlineHtmlGalley.displayName');
34+
}
35+
36+
/**
37+
* Get a description of the plugin.
38+
*/
39+
function getDescription() {
40+
return __('plugins.generic.inlineHtmlGalley.description');
41+
}
42+
43+
/**
44+
* Present the article wrapper page.
45+
* @param string $hookName
46+
* @param array $args
47+
*/
48+
function articleViewCallback($hookName, $args) {
49+
$request =& $args[0];
50+
$issue =& $args[1];
51+
$galley =& $args[2];
52+
$article =& $args[3];
53+
54+
if ($galley && $galley->getFileType() == 'text/html') {
55+
$templateMgr = TemplateManager::getManager($request);
56+
$templateMgr->assign(array(
57+
'issue' => $issue,
58+
'article' => $article,
59+
'galley' => $galley,
60+
));
61+
$inlineHtmlGalley = $this->_getHTMLContents($request, $galley);
62+
$inlineHtmlGalleyBody = $this->_extractBodyContents($inlineHtmlGalley);
63+
$templateMgr->assign('inlineHtmlGalley', $inlineHtmlGalleyBody);
64+
$templateMgr->display($this->getTemplateResource('displayInline.tpl'));
65+
66+
return true;
67+
}
68+
69+
return false;
70+
}
71+
72+
/**
73+
* Return string containing the contents of the HTML body
74+
* @param $html string
75+
* @return string
76+
*/
77+
function _extractBodyContents($html) {
78+
$bodyContent = '';
79+
try {
80+
$errorsEnabled = libxml_use_internal_errors();
81+
libxml_use_internal_errors(true);
82+
$dom = DOMDocument::loadHTML($html);
83+
$tags = $dom->getElementsByTagName('body');
84+
foreach ($tags as $body) {
85+
foreach ($body->childNodes as $child) {
86+
$bodyContent .= $dom->saveHTML($child);
87+
}
88+
last;
89+
}
90+
libxml_use_internal_errors($errorsEnabled);
91+
} catch (Exception $e) {
92+
$html = preg_replace('/.*<body[^>]*>/isA', '', $html);
93+
$html = preg_replace('/<\/body\s*>.*$/isD', '', $html);
94+
$bodyContent = $html;
95+
}
96+
return $bodyContent;
97+
}
98+
}

index.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @defgroup plugins_generic_inlineHtmlGalley Inline HTML Galley Plugin
4+
*/
5+
6+
/**
7+
* @file plugins/generic/inlineHtmlGalley/index.php
8+
*
9+
* Copyright (c) University of Pittsburgh
10+
* Copyright (c) 2014-2020 Simon Fraser University
11+
* Copyright (c) 2003-2020 John Willinsky
12+
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
13+
*
14+
* @ingroup plugins_generic_inlineHtmlGalley
15+
* @brief Wrapper for inline html galley plugin.
16+
*
17+
*/
18+
19+
require_once('InlineHtmlGalleyPlugin.inc.php');
20+
21+
return new InlineHtmlGalleyPlugin();
22+
23+

locale/en_US/locale.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE locale SYSTEM "../../../../../lib/pkp/dtd/locale.dtd">
3+
4+
<!--
5+
* plugins/generic/inlineHtmlGalley/locale/en_US/locale.xml
6+
*
7+
* Copyright (c) University of Pittsburgh
8+
* Copyright (c) 2014-2020 Simon Fraser University
9+
* Copyright (c) 2003-2020 John Willinsky
10+
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
11+
* Localization information: https://pkp.sfu.ca/wiki/index.php?title=Translating_OxS
12+
* Localization strings.
13+
-->
14+
15+
<locale name="en_US" full_name="U.S. English">
16+
<message key="plugins.generic.inlineHtmlGalley.displayName">Inline HTML Galley</message>
17+
<message key="plugins.generic.inlineHtmlGalley.description">This plugin provides inline rendering support for HTML Galleys.</message>
18+
</locale>

settings.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plugin_settings SYSTEM "../../../lib/pkp/dtd/pluginSettings.dtd">
3+
4+
<!--
5+
* plugins/generic/inlineHtmlGalley/settings.xml
6+
*
7+
* Copyright (c) 2014-2019 Simon Fraser University
8+
* Copyright (c) 2003-2019 John Willinsky
9+
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
10+
*
11+
* Default plugin settings.
12+
*
13+
-->
14+
15+
<plugin_settings>
16+
<setting type="bool">
17+
<name>enabled</name>
18+
<value>true</value>
19+
</setting>
20+
</plugin_settings>
21+

templates/displayInline.tpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{**
2+
* templates/frontend/pages/article.tpl
3+
*
4+
* Copyright (c) University of Pittsburgh
5+
* Copyright (c) 2014-2019 Simon Fraser University
6+
* Copyright (c) 2003-2019 John Willinsky
7+
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
8+
*
9+
* @brief Display the page to view an article with all of it's details.
10+
*
11+
* @uses $article Article This article
12+
* @uses $issue Issue The issue this article is assigned to
13+
* @uses $section Section The journal section this article is assigned to
14+
* @uses $journal Journal The journal currently being viewed.
15+
* @uses $primaryGalleys array List of article galleys that are not supplementary or dependent
16+
* @uses $supplementaryGalleys array List of article galleys that are supplementary
17+
* @uses $inlineHtmlGalley string The HTML content of the Article Galley
18+
*}
19+
{include file="frontend/components/header.tpl" pageTitleTranslated=$article->getLocalizedTitle()|escape}
20+
21+
<div class="page page_article">
22+
{if $section}
23+
{include file="frontend/components/breadcrumbs_article.tpl" currentTitle=$section->getLocalizedTitle()}
24+
{else}
25+
{include file="frontend/components/breadcrumbs_article.tpl" currentTitleKey="article.article"}
26+
{/if}
27+
28+
{* Show article inline *}
29+
{$inlineHtmlGalley}
30+
31+
{call_hook name="Templates::Article::Footer::PageFooter"}
32+
33+
</div><!-- .page -->
34+
35+
{include file="frontend/components/footer.tpl"}

version.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE version SYSTEM "../../../lib/pkp/dtd/pluginVersion.dtd">
3+
4+
<!--
5+
* plugins/generic/inlineHtmlGalley/version.xml
6+
*
7+
* Copyright (c) University of Pittsburgh
8+
* Copyright (c) 2014-2020 Simon Fraser University
9+
* Copyright (c) 2003-2020 John Willinsky
10+
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
11+
*
12+
* Plugin version information.
13+
-->
14+
<version>
15+
<application>inlineHtmlGalley</application>
16+
<type>plugins.generic</type>
17+
<release>1.0.0.0</release>
18+
<date>2020-10-14</date>
19+
<lazy-load>1</lazy-load>
20+
<class>InlineHtmlGalleyPlugin</class>
21+
</version>

0 commit comments

Comments
 (0)