Convert config and user to globals.
This commit is contained in:
parent
4d177e4919
commit
52a77a3dc2
@ -46,7 +46,7 @@ function handle_setup_exception(SetupException $e){
|
|||||||
case 'table_contents':
|
case 'table_contents':
|
||||||
// Recoverable error.
|
// Recoverable error.
|
||||||
// Redirect to setup if we aren't already headed there.
|
// Redirect to setup if we aren't already headed there.
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$currentPath = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
|
$currentPath = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
|
||||||
|
|
||||||
if (strpos($currentPath, 'setup') === false) {
|
if (strpos($currentPath, 'setup') === false) {
|
||||||
|
@ -25,9 +25,17 @@ try {
|
|||||||
|
|
||||||
// Everything's loaded and setup is confirmed.
|
// Everything's loaded and setup is confirmed.
|
||||||
// Let's start ticking.
|
// Let's start ticking.
|
||||||
|
|
||||||
|
// Defining these as globals isn't great practice,
|
||||||
|
// but this is a small, single-user app and this data will rarely change.
|
||||||
global $db;
|
global $db;
|
||||||
|
global $config;
|
||||||
|
global $user;
|
||||||
|
|
||||||
$db = get_db();
|
$db = get_db();
|
||||||
$config = ConfigModel::load();
|
$config = ConfigModel::load();
|
||||||
|
$user = UserModel::load();
|
||||||
|
|
||||||
Session::start();
|
Session::start();
|
||||||
Session::generateCsrfToken();
|
Session::generateCsrfToken();
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ class AdminController extends Controller {
|
|||||||
// GET handler
|
// GET handler
|
||||||
// render the admin page
|
// render the admin page
|
||||||
public function index(){
|
public function index(){
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$user = UserModel::load();
|
global $user;
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
@ -31,8 +31,8 @@ class AdminController extends Controller {
|
|||||||
|
|
||||||
// save updated settings
|
// save updated settings
|
||||||
private function save(){
|
private function save(){
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$user = UserModel::load();
|
global $user;
|
||||||
|
|
||||||
// handle form submission
|
// handle form submission
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
class AuthController extends Controller {
|
class AuthController extends Controller {
|
||||||
function showLogin(?string $error = null){
|
function showLogin(?string $error = null){
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$csrf_token = Session::getCsrfToken();
|
$csrf_token = Session::getCsrfToken();
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
@ -14,7 +14,7 @@ class AuthController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleLogin(){
|
function handleLogin(){
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
|
|
||||||
$error = '';
|
$error = '';
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class AuthController extends Controller {
|
|||||||
|
|
||||||
function handleLogout(){
|
function handleLogout(){
|
||||||
Session::end();
|
Session::end();
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
header('Location: ' . $config->basePath);
|
header('Location: ' . $config->basePath);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
class CssController extends Controller {
|
class CssController extends Controller {
|
||||||
public function index() {
|
public function index() {
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$user = UserModel::load();
|
global $user;
|
||||||
$customCss = CssModel::load();
|
$customCss = CssModel::load();
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
@ -49,7 +49,7 @@ class CssController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handlePost() {
|
public function handlePost() {
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
|
|
||||||
switch ($_POST['action']) {
|
switch ($_POST['action']) {
|
||||||
case 'upload':
|
case 'upload':
|
||||||
|
@ -4,8 +4,8 @@ class HomeController extends Controller {
|
|||||||
// renders the homepage view.
|
// renders the homepage view.
|
||||||
public function index(){
|
public function index(){
|
||||||
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
|
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$user = UserModel::load();
|
global $user;
|
||||||
|
|
||||||
$limit = $config->itemsPerPage;
|
$limit = $config->itemsPerPage;
|
||||||
$offset = ($page - 1) * $limit;
|
$offset = ($page - 1) * $limit;
|
||||||
@ -40,7 +40,7 @@ class HomeController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the config
|
// get the config
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
|
|
||||||
// redirect to the index (will show the latest tick if one was sent)
|
// redirect to the index (will show the latest tick if one was sent)
|
||||||
header('Location: ' . $config->basePath);
|
header('Location: ' . $config->basePath);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class MoodController extends Controller {
|
class MoodController extends Controller {
|
||||||
public function index(){
|
public function index(){
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$user = UserModel::load();
|
global $user;
|
||||||
$view = new MoodView();
|
$view = new MoodView();
|
||||||
|
|
||||||
$moodPicker = $view->render_mood_picker(self::get_emojis_with_labels(), $user->mood);
|
$moodPicker = $view->render_mood_picker(self::get_emojis_with_labels(), $user->mood);
|
||||||
@ -23,8 +23,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the data we need
|
// Get the data we need
|
||||||
$config = ConfigModel::load();
|
global $config;
|
||||||
$user = UserModel::load();
|
global $user;
|
||||||
$mood = $_POST['mood'];
|
$mood = $_POST['mood'];
|
||||||
|
|
||||||
// set the mood
|
// set the mood
|
||||||
|
Loading…
x
Reference in New Issue
Block a user