forked from Bagus05/customHeader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomHeaderPlugin.inc.php
148 lines (132 loc) · 3.96 KB
/
CustomHeaderPlugin.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
145
146
147
148
<?php
/**
* @file CustomHeaderPlugin.inc.php
*
* Copyright (c) 2013-2019 Simon Fraser University
* Copyright (c) 2003-2019 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class CustomHeaderPlugin
* @ingroup plugins_generic_customHeader
*
* @brief CustomHeader plugin class
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class CustomHeaderPlugin extends GenericPlugin {
/** @var bool Whether or not the header has been injected */
var $injected = false;
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
$success = parent::register($category, $path, $mainContextId);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {
// Insert CustomHeader page tag to page header
HookRegistry::register('TemplateManager::display', array($this, 'displayTemplateHook'));
// Insert custom script to the page footer
HookRegistry::register('Templates::Common::Footer::PageFooter', array($this, 'insertFooter'));
}
return $success;
}
/**
* Get the plugin display name.
* @return string
*/
function getDisplayName() {
return __('plugins.generic.customHeader.displayName');
}
/**
* Get the plugin description.
* @return string
*/
function getDescription() {
return __('plugins.generic.customHeader.description');
}
/**
* @copydoc Plugin::getActions()
*/
function getActions($request, $verb) {
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'settings',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
),
):array(),
parent::getActions($request, $verb)
);
}
/**
* @copydoc Plugin::manage()
*/
function manage($args, $request) {
switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER);
$templateMgr = TemplateManager::getManager($request);
$this->import('CustomHeaderSettingsForm');
$form = new CustomHeaderSettingsForm($this, $context?$context->getId():CONTEXT_ID_NONE);
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute($request);
return new JSONMessage(true);
}
} else {
$form->initData();
}
return new JSONMessage(true, $form->fetch($request));
}
return parent::manage($args, $request);
}
/**
* Register the CustomHeader script tag
* @param $hookName string
* @param $params array
*/
function displayTemplateHook($hookName, $params) {
if (!$this->injected) {
$this->injected = true;
$templateMgr =& $params[0];
$request = Application::getRequest();
$context = $request->getContext();
$templateMgr->addHeader('custom', $this->getSetting($context?$context->getId():CONTEXT_ID_NONE, 'content'));
}
return false;
}
/**
* Add custom footer to the page
*
* @param $hookName string
* @param $params array
*/
function insertFooter($hookName, $params) {
$templateMgr =& $params[0];
$output =& $params[2];
$request = Application::getRequest();
$context = $request->getContext();
$output .= $this->getSetting($context?$context->getId():CONTEXT_ID_NONE, 'footerContent');
return false;
}
/**
* 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();
}
}