forked from pkp/staticPages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticPagesPlugin.inc.php
196 lines (173 loc) · 5.84 KB
/
StaticPagesPlugin.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
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
188
189
190
191
192
193
194
195
196
<?php
/**
* @file StaticPagesPlugin.inc.php
*
* Copyright (c) 2014-2019 Simon Fraser University
* Copyright (c) 2003-2019 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @package plugins.generic.staticPages
* @class StaticPagesPlugin
* Static pages plugin main class
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class StaticPagesPlugin extends GenericPlugin {
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.staticPages.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
$description = __('plugins.generic.staticPages.description');
if (!$this->isTinyMCEInstalled())
$description .= __('plugins.generic.staticPages.requirement.tinymce');
return $description;
}
/**
* Check whether or not the TinyMCE plugin is installed.
* @return boolean True iff TinyMCE is installed.
*/
function isTinyMCEInstalled() {
$application = Application::getApplication();
$products = $application->getEnabledProducts('plugins.generic');
return (isset($products['tinymce']));
}
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled($mainContextId)) {
// Register the static pages DAO.
import('plugins.generic.staticPages.classes.StaticPagesDAO');
$staticPagesDao = new StaticPagesDAO();
DAORegistry::registerDAO('StaticPagesDAO', $staticPagesDao);
HookRegistry::register('Template::Settings::website', array($this, 'callbackShowWebsiteSettingsTabs'));
// Intercept the LoadHandler hook to present
// static pages when requested.
HookRegistry::register('LoadHandler', array($this, 'callbackHandleContent'));
// Register the components this plugin implements to
// permit administration of static pages.
HookRegistry::register('LoadComponentHandler', array($this, 'setupGridHandler'));
}
return true;
}
return false;
}
/**
* Extend the website settings tabs to include static pages
* @param $hookName string The name of the invoked hook
* @param $args array Hook parameters
* @return boolean Hook handling status
*/
function callbackShowWebsiteSettingsTabs($hookName, $args) {
$templateMgr = $args[1];
$output =& $args[2];
$request =& Registry::get('request');
$dispatcher = $request->getDispatcher();
$output .= $templateMgr->fetch($this->getTemplateResource('staticPagesTab.tpl'));
// Permit other plugins to continue interacting with this hook
return false;
}
/**
* Declare the handler function to process the actual page PATH
* @param $hookName string The name of the invoked hook
* @param $args array Hook parameters
* @return boolean Hook handling status
*/
function callbackHandleContent($hookName, $args) {
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$page =& $args[0];
$op =& $args[1];
$staticPagesDao = DAORegistry::getDAO('StaticPagesDAO');
if ($page == 'pages' && $op == 'preview') {
// This is a preview request; mock up a static page to display.
// The handler class ensures that only managers and administrators
// can do this.
$staticPage = $staticPagesDao->newDataObject();
$staticPage->setContent((array) $request->getUserVar('content'), null);
$staticPage->setTitle((array) $request->getUserVar('title'), null);
} else {
// Construct a path to look for
$path = $page;
if ($op !== 'index') $path .= "/$op";
if ($ops = $request->getRequestedArgs()) $path .= '/' . implode('/', $ops);
// Look for a static page with the given path
$context = $request->getContext();
$staticPage = $staticPagesDao->getByPath(
$context?$context->getId():CONTEXT_ID_NONE,
$path
);
}
// Check if this is a request for a static page or preview.
if ($staticPage) {
// Trick the handler into dealing with it normally
$page = 'pages';
$op = 'view';
// It is -- attach the static pages handler.
define('HANDLER_CLASS', 'StaticPagesHandler');
$this->import('StaticPagesHandler');
// Allow the static pages page handler to get the plugin object
StaticPagesHandler::setPlugin($this);
StaticPagesHandler::setPage($staticPage);
return true;
}
return false;
}
/**
* Permit requests to the static pages 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.staticPages.controllers.grid.StaticPageGridHandler') {
// Allow the static page grid handler to get the plugin object
import($component);
StaticPageGridHandler::setPlugin($this);
return true;
}
return false;
}
/**
* @copydoc Plugin::getActions()
*/
function getActions($request, $actionArgs) {
$dispatcher = $request->getDispatcher();
import('lib.pkp.classes.linkAction.request.RedirectAction');
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'settings',
new RedirectAction($dispatcher->url(
$request, ROUTE_PAGE,
null, 'management', 'settings', 'website',
array('uid' => uniqid()), // Force reload
'staticPages' // Anchor for tab
)),
__('plugins.generic.staticPages.editAddContent'),
null
),
):array(),
parent::getActions($request, $actionArgs)
);
}
/**
* Get the filename of the ADODB schema for this plugin.
* @return string Full path and filename to schema descriptor.
*/
function getInstallSchemaFile() {
return $this->getPluginPath() . '/schema.xml';
}
/**
* Get the JavaScript URL for this plugin.
*/
function getJavaScriptURL($request) {
return $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js';
}
}