summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-05 18:05:18 +0200
committerSimon Rettberg2014-06-05 18:05:18 +0200
commit0cd315e811ea15e5dbd45a07b22de8efe163f579 (patch)
treeba9be363436f8b3eaf8b1e066b6d58867d9da4b9 /index.php
parentDelete more old files (diff)
downloadslx-admin-0cd315e811ea15e5dbd45a07b22de8efe163f579.tar.gz
slx-admin-0cd315e811ea15e5dbd45a07b22de8efe163f579.tar.xz
slx-admin-0cd315e811ea15e5dbd45a07b22de8efe163f579.zip
Handle message rendering a bit different if running in AJAX mode
Diffstat (limited to 'index.php')
-rw-r--r--index.php59
1 files changed, 46 insertions, 13 deletions
diff --git a/index.php b/index.php
index 31a7bcc7..a14bda6a 100644
--- a/index.php
+++ b/index.php
@@ -7,17 +7,43 @@ require_once 'config.php';
*/
abstract class Page
{
- protected function doPreprocess() {}
- protected function doRender() {}
- protected function doAjax() {}
- public static function preprocess() { self::$instance->doPreprocess(); }
- public static function render() { self::$instance->doRender(); }
- public static function ajax() { self::$instance->doAjax(); }
+
+ protected function doPreprocess()
+ {
+
+ }
+
+ protected function doRender()
+ {
+
+ }
+
+ protected function doAjax()
+ {
+
+ }
+
+ public static function preprocess()
+ {
+ self::$instance->doPreprocess();
+ }
+
+ public static function render()
+ {
+ self::$instance->doRender();
+ }
+
+ public static function ajax()
+ {
+ self::$instance->doAjax();
+ }
+
/**
*
* @var \Page
*/
private static $instance = false;
+
public static function set($name)
{
$name = preg_replace('/[^A-Za-z]/', '', $name);
@@ -32,28 +58,35 @@ abstract class Page
}
self::$instance = new $className();
}
+
}
// Error reporting (hopefully goind to stderr, not being printed on pages)
error_reporting(E_ALL);
// Set variable if this is an ajax request
-$isAsync = (isset($_REQUEST['async']))
- || (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
+if ((isset($_REQUEST['async'])) || (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')) {
+ define('AJAX', true);
+} else {
+ define('AJAX', false);
+}
// Autoload classes from ./inc which adhere to naming scheme <lowercasename>.inc.php
-function slxAutoloader($class) {
+function slxAutoloader($class)
+{
$file = 'inc/' . preg_replace('/[^a-z0-9]/', '', mb_strtolower($class)) . '.inc.php';
- if (!file_exists($file)) return;
+ if (!file_exists($file))
+ return;
require_once $file;
}
+
spl_autoload_register('slxAutoloader');
// Now determine which module to run
Page::set(empty($_REQUEST['do']) ? 'Main' : $_REQUEST['do']);
// Deserialize any messages to display
-if (!$isAsync && isset($_REQUEST['message'])) {
+if (!AJAX && isset($_REQUEST['message'])) {
Message::fromRequest();
}
@@ -61,7 +94,7 @@ if (!$isAsync && isset($_REQUEST['message'])) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
User::load();
if (!Util::verifyToken()) {
- if ($isAsync) {
+ if (AJAX) {
die('CSRF/XSS? Missing token in POST request!');
} else {
Util::redirect('?do=Main');
@@ -70,7 +103,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
// AJAX Stuff? Just do so. Otherwise, run preprocessing
-if ($isAsync) {
+if (AJAX) {
Page::ajax();
exit(0);
}