forked from pkp/customBlockManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomBlockManagerPlugin.inc.php
More file actions
187 lines (167 loc) · 5.26 KB
/
Copy pathCustomBlockManagerPlugin.inc.php
File metadata and controls
187 lines (167 loc) · 5.26 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* @file plugins/generic/customBlockManager/CustomBlockManagerPlugin.inc.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @package plugins.generic.customBlockManager
* @class CustomBlockManagerPlugin
*
* Plugin to let managers add and delete custom sidebar blocks
*
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class CustomBlockManagerPlugin extends GenericPlugin {
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.customBlockManager.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.customBlockManager.description');
}
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
// If the system isn't installed, or is performing an upgrade, don't
// register hooks. This will prevent DB access attempts before the
// schema is installed.
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($this->getEnabled($mainContextId)) {
$this->import('CustomBlockPlugin');
// Ensure that there is a context (journal or press)
if ($request = Application::getRequest()) {
if ($mainContextId) {
$contextId = $mainContextId;
} else {
$context = $request->getContext();
$contextId = $context ? $context->getId() : CONTEXT_SITE;
}
// Load the custom blocks we have created
$blocks = $this->getSetting($contextId, 'blocks');
if (!is_array($blocks)) $blocks = array();
// Loop through each custom block and register it
$i=0;
foreach ($blocks as $block) {
PluginRegistry::register(
'blocks',
new CustomBlockPlugin($block, $this),
$this->getPluginPath()
);
}
}
// This hook is used to register the components this plugin implements to
// permit administration of custom block plugins.
HookRegistry::register('LoadComponentHandler', array($this, 'setupGridHandler'));
}
return true;
}
return false;
}
/**
* Register as a block plugin, even though this is a generic plugin.
* This will allow the plugin to behave as a block plugin, i.e. to
* have layout tasks performed on it.
* @param $hookName string The name of the hook being invoked
* @param $args array The parameters to the invoked hook
*/
function callbackLoadCategory($hookName, $args) {
$category =& $args[0];
$plugins =& $args[1];
$request =& $this->getRequest();
switch ($category) {
case 'blocks': // The system is registering block plugins
$this->import('CustomBlockPlugin');
// Ensure that there is a context (journal or press)
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
// Load the custom blocks we have created
$blocks = $this->getSetting($contextId, 'blocks');
if (!is_array($blocks)) break;
// Loop through each custom block and register it
$i=0;
foreach ($blocks as $block) {
// Add the plugin to the list of registered plugins
$plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath() . $i] = new CustomBlockPlugin($block, $this);
$i++;
}
break;
}
return false;
}
/**
* Permit requests to the custom block grid handler
* @param $hookName string The name of the hook being invoked
* @param $args array The parameters to the invoked hook
*/
function setupGridHandler($hookName, $params) {
$component =& $params[0];
if ($component == 'plugins.generic.customBlockManager.controllers.grid.CustomBlockGridHandler') {
define('CUSTOMBLOCKMANAGER_PLUGIN_NAME', $this->getName());
return true;
}
return false;
}
/**
* @copydoc Plugin::getActions()
*/
function getActions($request, $actionArgs) {
import('lib.pkp.classes.linkAction.request.AjaxModal');
$router = $request->getRouter();
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'settings',
new AjaxModal(
$router->url(
$request, null, null, 'manage', null, array(
'plugin' => $this->getName(),
'category' => $this->getCategory(),
'action' => 'index'
)
),
$this->getDisplayName()
),
__('plugins.generic.customBlockManager.manage'),
null
)
):array(),
parent::getActions($request, $actionArgs)
);
}
/**
* @copydoc Plugin::manage()
*/
function manage($args, $request) {
$templateMgr = TemplateManager::getManager($request);
$dispatcher = $request->getDispatcher();
return $templateMgr->fetchAjax(
'customBlockGridUrlGridContainer',
$dispatcher->url(
$request, ROUTE_COMPONENT, null,
'plugins.generic.customBlockManager.controllers.grid.CustomBlockGridHandler', 'fetchGrid'
)
);
}
/**
* This plugin can be used site-wide or in a specific context. The
* isSitePlugin check is used to grant access to different users, so this
* plugin must return true only if the user is currently in the site-wide
* context.
*
* @see PluginGridRow::_canEdit()
* @return boolean
*/
function isSitePlugin() {
return !Application::getRequest()->getContext();
}
}
?>