Skip to content

Commit ae29124

Browse files
committed
Add download options via link and block
1 parent e037fd1 commit ae29124

File tree

5 files changed

+170
-1
lines changed

5 files changed

+170
-1
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
/**
4+
* @file plugins/generic/inlineHtmlGalley/InlineHtmlGalleyBlockPlugin.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 InlineHtmlGalleyBlockPlugin
10+
* @ingroup plugins_generic_inlineHtmlGalley
11+
*
12+
* @brief Class for Inline HTML Galley block plugin
13+
*/
14+
15+
import('lib.pkp.classes.plugins.BlockPlugin');
16+
17+
class InlineHtmlGalleyBlockPlugin extends BlockPlugin {
18+
19+
/** @var $parentPluginName string name of InlineHtmlGalley plugin */
20+
var $parentPluginName;
21+
22+
/** @var $pluginPath string path to InlineHtmlGalley plugins */
23+
var $pluginPath;
24+
25+
/**
26+
* Constructor
27+
* @param $parentPluginName string
28+
* @param $pluginPath string
29+
*/
30+
function __construct($parentPluginName, $pluginPath) {
31+
parent::__construct();
32+
$this->parentPluginName = $parentPluginName;
33+
$this->pluginPath = $pluginPath;
34+
}
35+
36+
/**
37+
* Override currentVersion to prevent upgrade and delete management.
38+
* @return boolean
39+
*/
40+
function getCurrentVersion() {
41+
return false;
42+
}
43+
44+
/**
45+
* @copydoc LazyLoadPlugin::getEnabled()
46+
*/
47+
function getEnabled($contextId = null) {
48+
if (!Config::getVar('general', 'installed')) return true;
49+
return parent::getEnabled($contextId);
50+
}
51+
52+
/**
53+
* Get the display name of this plugin.
54+
* @return String
55+
*/
56+
function getDisplayName() {
57+
return __('plugins.generic.inlineHtmlGalley.block.displayName');
58+
}
59+
60+
/**
61+
* Get a description of the plugin.
62+
* @return String
63+
*/
64+
function getDescription() {
65+
return __('plugins.generic.inlineHtmlGalley.block.description');
66+
}
67+
68+
/**
69+
* Hide this plugin from the management interface (it's subsidiary)
70+
* @return boolean
71+
*/
72+
function getHideManagement() {
73+
return true;
74+
}
75+
76+
/**
77+
* Get the supported contexts (e.g. BLOCK_CONTEXT_...) for this block.
78+
* @return array
79+
*/
80+
function getSupportedContexts() {
81+
return array(BLOCK_CONTEXT_SIDEBAR);
82+
}
83+
84+
/**
85+
* Get the parent plugin
86+
* @return object
87+
*/
88+
function &getParentPlugin() {
89+
$plugin = PluginRegistry::getPlugin('generic', $this->parentPluginName);
90+
return $plugin;
91+
}
92+
93+
/**
94+
* Override the builtin to get the correct plugin path.
95+
* @return string
96+
*/
97+
function getPluginPath() {
98+
return $this->pluginPath;
99+
}
100+
101+
/**
102+
* Get the name of the block template file.
103+
* @return String
104+
*/
105+
function getBlockTemplateFilename() {
106+
return 'blockDownload.tpl';
107+
}
108+
109+
/**
110+
* @copydoc BlockPlugin::getContents()
111+
*/
112+
function getContents($templateMgr, $request = null) {
113+
if ($templateMgr && $request) {
114+
$router = $request->getRouter();
115+
if ($router->getRequestedPage($request) === 'article' && $router->getRequestedOp($request) === 'view') {
116+
$submission = $templateMgr->getTemplateVars('article');
117+
$galley = $templateMgr->getTemplateVars('galley');
118+
if ($submission && $galley) {
119+
$templateMgr->assign('submissionId', $submission->getBestArticleId());
120+
$templateMgr->assign('galleyId', $galley->getBestGalleyId());
121+
return parent::getContents($templateMgr);
122+
}
123+
}
124+
}
125+
return false;
126+
}
127+
}
128+
129+
?>

InlineHtmlGalleyPlugin.inc.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ class InlineHtmlGalleyPlugin extends HtmlArticleGalleyPlugin {
2121
* @see Plugin::register()
2222
*/
2323
function register($category, $path, $mainContextId = null) {
24-
if (!parent::register($category, $path, $mainContextId)) return false;
24+
$success = parent::register($category, $path, $mainContextId);
25+
if (!$success) return false;
26+
if ($success && $this->getEnabled()) {
27+
// Load this plugin as a block plugin as well
28+
$this->import('InlineHtmlGalleyBlockPlugin');
29+
PluginRegistry::register(
30+
'blocks',
31+
new InlineHtmlGalleyBlockPlugin($this->getName(), $this->getPluginPath()),
32+
$this->getPluginPath()
33+
);
34+
}
35+
2536
return true;
2637
}
2738

locale/en_US/locale.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
<locale name="en_US" full_name="U.S. English">
1616
<message key="plugins.generic.inlineHtmlGalley.displayName">Inline HTML Galley</message>
1717
<message key="plugins.generic.inlineHtmlGalley.description">This plugin provides inline rendering support for HTML Galleys.</message>
18+
<message key="plugins.generic.inlineHtmlGalley.block.displayName">HTML Galley Download Link</message>
19+
<message key="plugins.generic.inlineHtmlGalley.block.description">This block provides a link to download the HTML Galley directly.</message>
1820
</locale>

templates/blockDownload.tpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{**
2+
* plugins/generic/inlineHtmlGalley/blockDownload.tpl
3+
*
4+
* Copyright (c) University of Pittsburgh
5+
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
6+
*
7+
* Inline HTML Galley download block
8+
*
9+
*}
10+
<div class="pkp_block block_inline_html_download">
11+
<h2 class="title">{translate key="article.nonpdf.title"}</h2>
12+
<div class="content">
13+
<span class="downloadLinkContainer">
14+
<a class="obj_galley_link file" href="{url page="article" op="download" path=$submissionId|to_array:$galleyId}">
15+
{translate key="common.download"}
16+
</a>
17+
</span>
18+
</div>
19+
</div>
20+

templates/displayInline.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
{include file="frontend/components/breadcrumbs_article.tpl" currentTitleKey="article.article"}
2626
{/if}
2727

28+
{* Provide download link *}
29+
<div class="inline_html_galley_download">
30+
<a class="obj_galley_link file" href="{url page="article" op="download" path=$article->getBestArticleId()|to_array:$galley->getBestGalleyId()}">
31+
{translate key="common.download"}
32+
</a>
33+
</div>
34+
2835
{* Show article inline *}
2936
<div class="inline_html_galley">
3037
{$inlineHtmlGalley}

0 commit comments

Comments
 (0)