122 lines
3.5 KiB
PHP
122 lines
3.5 KiB
PHP
<?php
|
|
session_start();
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
require('lib/config.inc.php');
|
|
|
|
$router = new \Bramus\Router\Router();
|
|
|
|
$views_dir = __DIR__ . '/views/';
|
|
$class_dir = scandir("lib/classes");
|
|
|
|
/* these can't be defined as it breaks logging in hence vscode is displaying errors about them
|
|
being undefined */
|
|
@$website;
|
|
@$conn;
|
|
|
|
foreach ($class_dir as $class) {
|
|
if (preg_match("/.php/i", $class)) {
|
|
require("lib/classes/" . $class);
|
|
}
|
|
}
|
|
|
|
$router->all('/', function() use ($views_dir, $website, $conn) {
|
|
if (!isset($_SESSION["user"])) {
|
|
require($views_dir . 'main.php');
|
|
} else {
|
|
require($views_dir . "/dupes/home/feed_micros.php");
|
|
}
|
|
|
|
return;
|
|
});
|
|
|
|
$router->get('/feed/(\w+)', function($feed_type) use ($views_dir, $website, $conn) {
|
|
if (!isset($_SESSION["user"]) || htmlspecialchars($feed_type) == NULL) {
|
|
header("Location: /");
|
|
} else {
|
|
switch(htmlspecialchars($feed_type)) {
|
|
case "micros":
|
|
require($views_dir . "/dupes/home/feed_micros.php");
|
|
break;
|
|
case "marcos":
|
|
require($views_dir . "/dupes/home/feed_marcos.php");
|
|
break;
|
|
case "gallery":
|
|
require($views_dir . "/dupes/home/feed_gallery.php");
|
|
break;
|
|
default:
|
|
header("Location: /");
|
|
}
|
|
}
|
|
|
|
return;
|
|
});
|
|
|
|
|
|
$router->get('/quack/(\w+)', function($post_id) use ($views_dir, $website, $conn) {
|
|
if (!$post_id) {
|
|
header("Location: /");
|
|
} else {
|
|
require($views_dir . "/post.php");
|
|
}
|
|
});
|
|
|
|
$router->get('/delete_quack/(\w+)', function($post_id) use ($conn) {
|
|
$hasTitle = false;
|
|
|
|
if (!isset($_SESSION["user"])) {
|
|
header("Location: /");
|
|
} else {
|
|
$post = new Post($_SESSION["user"], $conn);
|
|
if ($post->getSpecifcPost(htmlspecialchars($post_id)) != NULL) {
|
|
$post_details = $post->getSpecifcPost(htmlspecialchars($post_id)) ;
|
|
|
|
if ($post_details["author"] == $_SESSION["user"])
|
|
if ($post_details["title"] != NULL)
|
|
$hasTitle = true;
|
|
|
|
$post->deletePost($post_id);
|
|
}
|
|
|
|
if ($hasTitle) {
|
|
header("Location: /feed/marcos");
|
|
} else {
|
|
header("Location: /");
|
|
}
|
|
}
|
|
return;
|
|
});
|
|
|
|
$router->all('/settings', function() use ($views_dir, $website, $conn) {
|
|
require($views_dir . 'settings.php');
|
|
return;
|
|
});
|
|
|
|
$router->all('/apply', function() use ($views_dir, $website) {
|
|
require($views_dir . 'apply.php');
|
|
return;
|
|
});
|
|
|
|
$router->all('/temp_register', function() use ($views_dir, $website, $conn) {
|
|
require($views_dir . 'temp_reg.php');
|
|
return;
|
|
});
|
|
|
|
$router->all('/login', function() use ($views_dir, $website, $conn) {
|
|
require($views_dir . 'login.php');
|
|
return;
|
|
});
|
|
|
|
$router->all('/logout', function() use ($views_dir, $website, $conn) {
|
|
session_destroy();
|
|
header("Location: /");
|
|
return;
|
|
});
|
|
|
|
$router->set404(function() {
|
|
header('HTTP/1.1 404 Not Found');
|
|
echo "Waddled to nowhere";
|
|
return;
|
|
});
|
|
|
|
$router->run();
|
|
?>
|