forked from ojsde/shariff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShariffBlockPlugin.inc.php
More file actions
142 lines (119 loc) · 3.6 KB
/
ShariffBlockPlugin.inc.php
File metadata and controls
142 lines (119 loc) · 3.6 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) 2014-2017 Simon Fraser University
* Copyright (c) 2003-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ShariffBlockPlugin
* @ingroup plugins_generic_shariff
*
* @brief Class for block component of shariff plugin
*/
import('lib.pkp.classes.plugins.BlockPlugin');
class ShariffBlockPlugin extends BlockPlugin {
/** @var string Name of parent plugin */
var $parentPluginName;
function __construct($parentPluginName) {
parent::__construct();
$this->parentPluginName = $parentPluginName;
}
/**
* Get the name of this plugin. The name must be unique within
* its category.
* @return String name of plugin
*/
function getName() {
return 'ShariffBlockPlugin';
}
/**
* Hide this plugin from the management interface (it's subsidiary)
*/
function getHideManagement() {
return true;
}
/**
* Get the display name of this plugin.
* @return String
*/
function getDisplayName() {
return __('plugins.generic.shariff.block.displayName');
}
/**
* Get a description of the plugin.
*/
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 web feed plugin
* @return ShariffPlugin
*/
function getShariffPlugin() {
return PluginRegistry::getPlugin('generic', $this->parentPluginName);
}
/**
* Override the builtin to get the correct plugin path.
* @return string
*/
function getPluginPath() {
return $this->getShariffPlugin()->getPluginPath();
}
/**
* @copydoc PKPPlugin::getTemplatePath
*/
function getTemplatePath($inCore = false) {
return $this->getShariffPlugin()->getTemplatePath($inCore);
}
/**
* @copydoc BlockPlugin::getBlockTemplateFilename()
*/
function getBlockTemplateFilename() {
// Return the opt-out template.
return '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();
$contextId = $context->getId();
$plugin = $this->getShariffPlugin();
// services
$selectedServices = $plugin->getSetting($contextId, 'selectedServices');
$preparedServices = array_map(create_function('$arrayElement', 'return \'"\'.$arrayElement.\'"\';'), $selectedServices);
$dataServicesString = implode(",", $preparedServices);
// theme
$selectedTheme = $plugin->getSetting($contextId, 'selectedTheme');
// get language from system
$locale = AppLocale::getLocale();
$iso1Lang = AppLocale::getIso1FromLocale($locale);
// javascript, css and backend url
$requestedUrl = $request->getCompleteUrl();
$baseUrl = $request->getBaseUrl();
$jsUrl = $baseUrl .'/'. $this->getPluginPath().'/shariff.complete.js';
$cssUrl = $baseUrl .'/' . $this->getPluginPath() . '/' . 'shariff.complete.css';
$backendUrl = $baseUrl .'/'. 'shariff-backend';
// assign variables to the templates
$templateMgr->assign('dataServicesString', $dataServicesString);
$templateMgr->assign('selectedTheme', $selectedTheme);
$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);
}
}
?>