1
|
|
|
<?php |
2
|
|
|
namespace Flipside\Http; |
3
|
|
|
|
4
|
|
|
use \Psr\Http\Message\ServerRequestInterface as Request; |
5
|
|
|
use \Psr\Http\Message\ResponseInterface as Response; |
6
|
|
|
|
7
|
|
|
require __DIR__ . '/../vendor/autoload.php'; |
8
|
|
|
require_once(__DIR__ . '/../static.js_css.php'); |
9
|
|
|
|
10
|
|
|
class WebPage |
11
|
|
|
{ |
12
|
|
|
public $body = ''; |
13
|
|
|
protected $templateName = 'main.html'; |
14
|
|
|
public $content; |
15
|
|
|
public $user; |
16
|
|
|
|
17
|
|
|
public function __construct($title) |
18
|
|
|
{ |
19
|
|
|
\Sentry\init(['dsn' => 'https://[email protected]/4283882' ]); |
20
|
|
|
$this->settings = \Flipside\Settings::getInstance(); |
|
|
|
|
21
|
|
|
$this->loader = new \Twig_Loader_Filesystem(dirname(__FILE__).'/../templates'); |
|
|
|
|
22
|
|
|
|
23
|
|
|
$twigSettings = array(); |
24
|
|
|
if(\file_exists('/var/php_cache/twig')) |
25
|
|
|
{ |
26
|
|
|
$twigCache = $this->settings->getGlobalSetting('twig_cache', '/var/php_cache/twig'); |
27
|
|
|
$twigSettings['cache'] = $twigCache; |
28
|
|
|
//$twigSettings = array('cache' => $twigCache, 'debug' => true); |
29
|
|
|
} |
30
|
|
|
//$twigSettings['debug'] = true; |
31
|
|
|
|
32
|
|
|
$this->wwwUrl = $this->settings->getGlobalSetting('www_url', 'https://www.burningflipside.com'); |
|
|
|
|
33
|
|
|
$this->wikiUrl = $this->settings->getGlobalSetting('wiki_url', 'https://wiki.burningflipside.com'); |
|
|
|
|
34
|
|
|
$this->secureUrl = $this->settings->getGlobalSetting('secure_url', 'https://secure.burningflipside.com'); |
|
|
|
|
35
|
|
|
$this->profilesUrl = $this->settings->getGlobalSetting('profiles_url', 'https://profiles.burningflipside.com'); |
|
|
|
|
36
|
|
|
$this->registerUrl = $this->settings->getGlobalSetting('register_url', $this->profilesUrl.'/register.php'); |
|
|
|
|
37
|
|
|
$this->resetUrl = $this->settings->getGlobalSetting('reset_url', $this->profilesUrl.'/reset.php'); |
|
|
|
|
38
|
|
|
$this->loginUrl = $this->settings->getGlobalSetting('login_url', $this->profilesUrl.'/login.php'); |
|
|
|
|
39
|
|
|
$this->logoutUrl = $this->settings->getGlobalSetting('logout_url', $this->profilesUrl.'/logout.php'); |
|
|
|
|
40
|
|
|
|
41
|
|
|
$this->twig = new \Twig_Environment($this->loader, $twigSettings); |
|
|
|
|
42
|
|
|
//$this->twig->addExtension(new \Twig\Extension\DebugExtension()); |
43
|
|
|
$this->content = array('pageTitle' => $title); |
44
|
|
|
$this->user = \Flipside\FlipSession::getUser(); |
45
|
|
|
$this->content['user'] = $this->user; |
46
|
|
|
$this->content['header'] = array(); |
47
|
|
|
$this->content['header']['sites'] = array(); |
48
|
|
|
$this->content['header']['sites']['Profiles'] = $this->profilesUrl; |
49
|
|
|
$this->content['header']['sites']['WWW'] = $this->wwwUrl; |
50
|
|
|
$this->content['header']['sites']['Pyropedia'] = $this->wikiUrl; |
51
|
|
|
$this->content['header']['sites']['Secure'] = $this->secureUrl; |
52
|
|
|
|
53
|
|
|
$this->aboutUrl = $this->settings->getGlobalSetting('about_url', $this->wwwUrl.'/about'); |
|
|
|
|
54
|
|
|
$this->content['header']['right']['About'] = array( |
55
|
|
|
'url' => $this->aboutUrl, |
56
|
|
|
'menu' => $this->settings->getGlobalSetting('about_menu', array( |
57
|
|
|
'Burning Flipside' => $this->wwwUrl.'/about/event', |
58
|
|
|
'AAR, LLC' => $this->wwwUrl.'/organization/aar', |
59
|
|
|
'Privacy Policy' => $this->wwwUrl.'/about/privacy' |
60
|
|
|
))); |
61
|
|
|
|
62
|
|
|
$this->content['urls']['wwwUrl'] = $this->wwwUrl; |
63
|
|
|
$this->content['urls']['wikiUrl'] = $this->wikiUrl; |
64
|
|
|
$this->content['urls']['profilesUrl'] = $this->profilesUrl; |
65
|
|
|
$this->content['urls']['secureUrl'] = $this->secureUrl; |
66
|
|
|
|
67
|
|
|
$this->content['urls']['registerUrl'] = $this->registerUrl; |
68
|
|
|
$this->content['urls']['resetUrl'] = $this->resetUrl; |
69
|
|
|
$this->content['urls']['loginUrl'] = $this->loginUrl; |
70
|
|
|
$this->content['urls']['logoutUrl'] = $this->logoutUrl; |
71
|
|
|
|
72
|
|
|
if($this->user === false || $this->user === null) |
73
|
|
|
{ |
74
|
|
|
if(isset($_SERVER['REQUEST_URI']) && strstr($_SERVER['REQUEST_URI'], 'logout.php') === false) |
75
|
|
|
{ |
76
|
|
|
$this->addLink('Login', $this->loginUrl); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
else |
80
|
|
|
{ |
81
|
|
|
$this->addLink('Logout', $this->settings->getGlobalSetting('logout_url', $this->profilesUrl.'/logout.php')); |
82
|
|
|
$this->addLinks(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->minified = 'min'; |
|
|
|
|
86
|
|
|
$this->cdn = 'cdn'; |
|
|
|
|
87
|
|
|
if($this->settings->getGlobalSetting('use_minified', true) == false) |
88
|
|
|
{ |
89
|
|
|
$this->minified = 'no'; |
90
|
|
|
} |
91
|
|
|
if($this->settings->getGlobalSetting('use_cdn', true) == false) |
92
|
|
|
{ |
93
|
|
|
$this->cdn = 'no'; |
94
|
|
|
$this->content['useCDN'] = false; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function addTemplateDir($dir, $namespace) |
99
|
|
|
{ |
100
|
|
|
$this->loader->addPath($dir, $namespace); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function setTemplateName($name) |
104
|
|
|
{ |
105
|
|
|
$this->templateName = $name; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
public function addCSS($uri) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
if(!isset($this->content['css'])) |
111
|
|
|
{ |
112
|
|
|
$this->content['css'] = array($uri); |
113
|
|
|
return; |
114
|
|
|
} |
115
|
|
|
array_push($this->content['css'],$uri); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Add a JavaScript file from its src URI |
120
|
|
|
* |
121
|
|
|
* @param string $uri The webpath to the JavaScript file |
122
|
|
|
*/ |
123
|
|
View Code Duplication |
public function addJS($uri) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
if(!isset($this->content['js'])) |
126
|
|
|
{ |
127
|
|
|
$this->content['js'] = array($uri); |
128
|
|
|
return; |
129
|
|
|
} |
130
|
|
|
array_push($this->content['js'],$uri); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Add a JavaScript file from a set of files known to the framework |
135
|
|
|
* |
136
|
|
|
* @param string $jsFileID the ID of the JS file |
137
|
|
|
* @param boolean $async Can the JS file be loaded asynchronously? |
|
|
|
|
138
|
|
|
*/ |
139
|
|
|
public function addWellKnownJS($jsFileID) |
140
|
|
|
{ |
141
|
|
|
global $jsArray; |
142
|
|
|
$src = $jsArray[$jsFileID][$this->cdn][$this->minified]; |
143
|
|
|
if(is_array($src)) |
144
|
|
|
{ |
145
|
|
|
if(!isset($this->content['securejs'])) |
146
|
|
|
{ |
147
|
|
|
$this->content['securejs'] = array(); |
148
|
|
|
} |
149
|
|
|
array_push($this->content['securejs'], $src); |
150
|
|
|
} |
151
|
|
|
else |
152
|
|
|
{ |
153
|
|
|
$this->addJS($src); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Add a CSS file from a set of files known to the framework |
159
|
|
|
* |
160
|
|
|
* @param string $cssFileID the ID of the CSS file |
161
|
|
|
*/ |
162
|
|
|
public function addWellKnownCSS($cssFileID) |
163
|
|
|
{ |
164
|
|
|
global $cssArray; |
165
|
|
|
$src = $cssArray[$cssFileID][$this->cdn][$this->minified]; |
166
|
|
|
$this->addCSS($src); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Add a link to the header |
171
|
|
|
* |
172
|
|
|
* @param string $name The name of the link |
173
|
|
|
* @param boolean|string $url The URL to link to |
174
|
|
|
* @param boolean|array $submenu Any submenu items for the dropdown |
175
|
|
|
*/ |
176
|
|
|
public function addLink($name, $url = false, $submenu = false) |
177
|
|
|
{ |
178
|
|
|
$data = array('url' => $url); |
179
|
|
|
if(is_array($submenu)) |
180
|
|
|
{ |
181
|
|
|
$data['menu'] = $submenu; |
182
|
|
|
} |
183
|
|
|
$this->content['header']['right'] = array($name => $data)+$this->content['header']['right']; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** Notification that is green for success */ |
187
|
|
|
const NOTIFICATION_SUCCESS = 'alert-success'; |
188
|
|
|
/** Notification that is blue for infomrational messages */ |
189
|
|
|
const NOTIFICATION_INFO = 'alert-info'; |
190
|
|
|
/** Notification that is yellow for warning */ |
191
|
|
|
const NOTIFICATION_WARNING = 'alert-warning'; |
192
|
|
|
/** Notification that is red for error */ |
193
|
|
|
const NOTIFICATION_FAILED = 'alert-danger'; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Add a notification to the page |
197
|
|
|
* |
198
|
|
|
* @param string $message The message to show in the notifcation |
199
|
|
|
* @param string $severity The severity of the notifcation |
200
|
|
|
* @param boolean $dismissible Can the user dismiss the notificaton? |
201
|
|
|
*/ |
202
|
|
|
public function addNotification($message, $severity = self::NOTIFICATION_INFO, $dismissible = true) |
203
|
|
|
{ |
204
|
|
|
if(!isset($this->content['notifications'])) |
205
|
|
|
{ |
206
|
|
|
$this->content['notifications'] = array(); |
207
|
|
|
} |
208
|
|
|
array_push($this->content['notifications'], array('msg'=>$message, 'sev'=>$severity, 'dismissible'=>$dismissible)); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
protected function addLinks() |
212
|
|
|
{ |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
protected function getContent() |
216
|
|
|
{ |
217
|
|
|
if(!isset($this->content['body'])) |
218
|
|
|
{ |
219
|
|
|
$this->content['body'] = $this->body; |
220
|
|
|
} |
221
|
|
|
//Add page JS just before rednering so it is after any added by the page explicitly |
222
|
|
|
// $this->addJS('js/'.basename($_SERVER['SCRIPT_NAME'], '.php').'.js'); |
223
|
|
|
// this code assumes *.php pages have a corresponding *.js file (many don't) |
224
|
|
|
return $this->twig->render($this->templateName, $this->content); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function handleRequest($request, $response, $args) |
|
|
|
|
228
|
|
|
{ |
229
|
|
|
$body = $response->getBody(); |
230
|
|
|
$body->write($this->getContent()); |
231
|
|
|
return $response; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function printPage() |
235
|
|
|
{ |
236
|
|
|
echo $this->getContent(); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Get the currently requested URL |
241
|
|
|
* |
242
|
|
|
* @return string The full URL of the requested page |
243
|
|
|
* |
244
|
|
|
* @SuppressWarnings("Superglobals") |
245
|
|
|
*/ |
246
|
|
|
public function currentURL() |
247
|
|
|
{ |
248
|
|
|
if(!isset($_SERVER['REQUEST_URI'])) |
249
|
|
|
{ |
250
|
|
|
return ''; |
251
|
|
|
} |
252
|
|
|
$requestURI = $_SERVER['REQUEST_URI']; |
253
|
|
|
if($requestURI[0] === '/') |
254
|
|
|
{ |
255
|
|
|
$requestURI = substr($requestURI, 1); |
256
|
|
|
} |
257
|
|
|
return 'http'.(isset($_SERVER['HTTPS']) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].'/'.$requestURI; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
261
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: