-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathShariffBlockPlugin.php
More file actions
142 lines (118 loc) · 3.87 KB
/
ShariffBlockPlugin.php
File metadata and controls
142 lines (118 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* @file plugins/generic/shariff/ShariffBlockPlugin.inc.php
*
* Copyright (c) 2018 Center for Digital Systems (CeDiS), Freie Universität Berlin
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class ShariffBlockPlugin
* @ingroup plugins_generic_shariff
*
* @brief Class for block component of shariff plugin
*/
namespace APP\plugins\generic\shariff;
use PKP\facades\Locale;
use PKP\plugins\BlockPlugin;
use PKP\plugins\PluginRegistry;
class ShariffBlockPlugin extends BlockPlugin {
/** @var string Name an Path of parent plugin */
var $parentPluginName;
var $parentPluginPath;
/**
* Constructor
* @param $parentPluginName string Name of parent plugin.
* @param $parentPluginPath string Path of parent plugin.
*/
function __construct($parentPluginName, $parentPluginPath) {
parent::__construct();
$this->parentPluginName = $parentPluginName;
$this->parentPluginPath = $parentPluginPath;
}
/**
* @copydoc Plugin::getName()
*/
function getName() {
return 'ShariffBlockPlugin';
}
/**
* Hide this plugin from the management interface (it's subsidiary)
* @return bool
*/
function getHideManagement() {
return true;
}
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.shariff.block.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.shariff.block.description');
}
/**
* Get the shariff plugin
* @return ShariffPlugin
*/
function getShariffPlugin() {
return PluginRegistry::getPlugin('generic', $this->parentPluginName);
}
/**
* @copydoc Plugin::getPluginPath()
*/
function getPluginPath() {
return $this->parentPluginPath;
}
/**
* @copydoc BlockPlugin::getBlockTemplateFilename()
*/
function getBlockTemplateFilename():string {
// Return the shariff block template.
$plugin = $this->getShariffPlugin();
return (method_exists($plugin, 'getTemplateResource') ? '' : 'templates'.DIRECTORY_SEPARATOR) . 'shariffBlock.tpl';
}
/**
* Get the HTML contents for this block.
* @param $templateMgr object
* @param $request PKPRequest
* @return $string
*/
function getContents($templateMgr, $request = null) {
$context = $request->getContext();
if (strcmp($context->getData('shariffPositionSelected'),'sidebar') == 0) {
// services
$selectedServices = $context->getData('shariffServicesSelected');
$preparedServices = array_map(function($arrayElement){return $arrayElement;}, $selectedServices);
$dataServicesString = implode(",", $preparedServices);
// theme
$selectedTheme = $context->getData('shariffThemeSelected');
// orientation
$selectedOrientation = $context->getData('shariffOrientationSelected');
// get language from system
$locale = Locale::getLocale();
$publicationSharingLink = $context->getData('shariffPublicationSharingLink');
if ($publicationSharingLink == 'doiUrl') {
$publication = $templateMgr->getTemplateVars('currentPublication');
if ($publication && $publication->getData('doiObject')) {
$doiUrl = $publication->getData('doiObject')->getResolvingUrl();
}
}
// urls
$requestedUrl = $doiUrl ?: $request->getCompleteUrl();
$backendUrl = $request->getBaseUrl() .'/'. 'shariff-backend';
// assign variables to the templates
$templateMgr->assign('dataServicesString', $dataServicesString);
$templateMgr->assign('selectedTheme', $selectedTheme);
$templateMgr->assign('selectedOrientation', $selectedOrientation);
$templateMgr->assign('backendUrl', $backendUrl);
$templateMgr->assign('iso1Lang', $locale);
$templateMgr->assign('requestedUrl', $requestedUrl);
$templateMgr->assign('showBlockHeading', $context->getData('shariffShowBlockHeading'));
}
return parent::getContents($templateMgr, $request);
}
}
?>