forked from pkp/staticPages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticPagesHandler.inc.php
86 lines (71 loc) · 2.59 KB
/
StaticPagesHandler.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
<?php
/**
* @file StaticPagesHandler.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 StaticPagesHandler
* Find static page content and display it when requested.
*/
import('classes.handler.Handler');
class StaticPagesHandler extends Handler {
/** @var StaticPagesPlugin The static pages plugin */
static $plugin;
/** @var StaticPage The static page to view */
static $staticPage;
/**
* Provide the static pages plugin to the handler.
* @param $plugin StaticPagesPlugin
*/
static function setPlugin($plugin) {
self::$plugin = $plugin;
}
/**
* Set a static page to view.
* @param $staticPage StaticPage
*/
static function setPage($staticPage) {
self::$staticPage = $staticPage;
}
/**
* Handle index request (redirect to "view")
* @param $args array Arguments array.
* @param $request PKPRequest Request object.
*/
function index($args, $request) {
$request->redirect(null, null, 'view', $request->getRequestedOp());
}
/**
* Handle view page request (redirect to "view")
* @param $args array Arguments array.
* @param $request PKPRequest Request object.
*/
function view($args, $request) {
$path = array_shift($args);
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_COMMON, LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_USER);
$context = $request->getContext();
$contextId = $context?$context->getId():CONTEXT_ID_NONE;
// Ensure that if we're previewing, the current user is a manager or admin.
$roles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
if (!self::$staticPage->getId() && count(array_intersect(array(ROLE_ID_MANAGER, ROLE_ID_SITE_ADMIN), $roles))==0) {
fatalError('The current user is not permitted to preview.');
}
// Assign the template vars needed and display
$templateMgr = TemplateManager::getManager($request);
$this->setupTemplate($request);
$templateMgr->assign('title', self::$staticPage->getLocalizedTitle());
$vars = array();
if ($context) $vars = array(
'{$contactName}' => $context->getData('contactName'),
'{$contactEmail}' => $context->getData('contactEmail'),
'{$supportName}' => $context->getData('supportName'),
'{$supportPhone}' => $context->getData('supportPhone'),
'{$supportEmail}' => $context->getData('supportEmail'),
);
$templateMgr->assign('content', strtr(self::$staticPage->getLocalizedContent(), $vars));
$templateMgr->display(self::$plugin->getTemplateResource('content.tpl'));
}
}