-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
132 lines (114 loc) · 3.97 KB
/
Module.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
<?php
/**
* MIT License
* Copyright (c) 2019 Electronic Student Services @ Appalachian State University
*
* See LICENSE file in root directory for copyright and distribution permissions.
*
* @author Matthew McNaney <[email protected]>
* @license https://opensource.org/licenses/MIT
*/
namespace conference;
use Canopy\Request;
use Canopy\Response;
use Canopy\Server;
use Canopy\SettingDefaults;
use conference\Controller\Controller;
use conference\Factory\VisitorFactory;
$defineFile = PHPWS_SOURCE_DIR . 'mod/conference/config/defines.php';
if (is_file($defineFile)) {
require_once $defineFile;
} else {
require_once PHPWS_SOURCE_DIR . 'mod/conference/config/defines.dist.php';
}
class Module extends \Canopy\Module implements SettingDefaults
{
public function __construct()
{
parent::__construct();
$this->setTitle('conference');
$this->setProperName('Conference');
\spl_autoload_register('\conference\Module::autoloader', true, true);
}
public static function autoloader($class_name)
{
static $not_found = array();
if (strpos($class_name, 'conference') !== 0) {
return;
}
if (isset($not_found[$class_name])) {
return;
}
$class_array = explode('\\', $class_name);
$shifted = array_shift($class_array);
$class_dir = implode('/', $class_array);
$class_path = PHPWS_SOURCE_DIR . 'mod/conference/class/' . $class_dir . '.php';
if (is_file($class_path)) {
require_once $class_path;
return true;
} else {
$not_found[] = $class_name;
return false;
}
}
public function getSettingDefaults()
{
$settings = array('contactName' => '', 'contactEmail' => '', 'defaultConference' => 0, 'bannerApi' => 0, 'disabled' => 0);
return $settings;
}
public function runTime(Request $request)
{
if (empty(STUDENT_ORIENTATION_TABLE)) {
\Layout::add('<div class="alert alert-danger">Error: Orientation table and Banner URL are not set.</div>', 'conference');
return;
}
if (\Current_User::allow('conference')) {
$this->loadAdminBar();
}
if (empty($request->getModule())) {
$conferenceView = new View\ConferenceView;
$content = $conferenceView->frontPage();
\Layout::add($content);
}
}
public static function loadAdminBar()
{
$auth = \Current_User::getAuthorization();
$vars['is_deity'] = \Current_User::isDeity();
$vars['logout_uri'] = $auth->logout_link;
$vars['username'] = \Current_User::getDisplayName();
$template = new \phpws2\Template($vars);
$template->setModuleTemplate('conference', 'navbar.html');
$content = $template->get();
\Layout::plug($content, 'NAV_LINKS');
}
public function getController(Request $request)
{
try {
$controller = new Controller($this, $request);
return $controller;
} catch (\conference\Exception\PrivilegeMissing $e) {
if ($request->isGet() && !$request->isAjax()) {
\Current_User::requireLogin();
} else {
throw $e;
}
} catch (\conference\Exception\VisitorLoginRequired $e) {
if ($request->isAjax()) {
$controller = new \conference\Controller\AjaxLoginError($this);
return $controller;
} else {
VisitorFactory::setReturnUrl();
\Canopy\Server::forward('./conference/User/Visitor/login');
}
} catch (\Exception $e) {
if (CONFERENCE_SYSTEM_SETTINGS['friendlyErrors']) {
\phpws2\Error::log($e);
$controller = new \conference\Controller\FriendlyErrorController($this);
return $controller;
} else {
throw $e;
}
}
}
}