-
Notifications
You must be signed in to change notification settings - Fork 16
/
ShariffBlockPlugin.inc.php
144 lines (120 loc) · 3.95 KB
/
ShariffBlockPlugin.inc.php
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
143
144
<?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
*/
use APP\i18n\AppLocale;
import('lib.pkp.classes.plugins.BlockPlugin');
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 supported contexts (e.g. BLOCK_CONTEXT_...) for this block.
* @return array
*/
function getSupportedContexts() {
return array(BLOCK_CONTEXT_SIDEBAR);
}
/**
* 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() {
// 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 = AppLocale::getLocale();
// javascript, css and backend url
$requestedUrl = $request->getCompleteUrl();
$baseUrl = $request->getBaseUrl();
$jsUrl = $baseUrl .'/'. $this->getShariffPlugin()->getPluginPath().'/shariff-3.2.1/shariff.complete.js';
$cssUrl = $baseUrl .'/' . $this->getShariffPlugin()->getPluginPath() . '/shariff-3.2.1/shariff.complete.css';
$backendUrl = $baseUrl .'/'. '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', $iso1Lang);
$templateMgr->assign('requestedUrl', $requestedUrl);
$templateMgr->assign('jsUrl', $jsUrl);
$templateMgr->assign('cssUrl', $cssUrl);
}
return parent::getContents($templateMgr, $request);
}
}
?>