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':
|
||||
// Recoverable error.
|
||||
// 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), '/');
|
||||
|
||||
if (strpos($currentPath, 'setup') === false) {
|
||||
|
@ -25,9 +25,17 @@ try {
|
||||
|
||||
// Everything's loaded and setup is confirmed.
|
||||
// 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 $config;
|
||||
global $user;
|
||||
|
||||
$db = get_db();
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
|
||||
Session::start();
|
||||
Session::generateCsrfToken();
|
||||
|
||||
|
@ -3,8 +3,8 @@ class AdminController extends Controller {
|
||||
// GET handler
|
||||
// render the admin page
|
||||
public function index(){
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
global $config;
|
||||
global $user;
|
||||
|
||||
$vars = [
|
||||
'user' => $user,
|
||||
@ -31,8 +31,8 @@ class AdminController extends Controller {
|
||||
|
||||
// save updated settings
|
||||
private function save(){
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
global $config;
|
||||
global $user;
|
||||
|
||||
// handle form submission
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
class AuthController extends Controller {
|
||||
function showLogin(?string $error = null){
|
||||
$config = ConfigModel::load();
|
||||
global $config;
|
||||
$csrf_token = Session::getCsrfToken();
|
||||
|
||||
$vars = [
|
||||
@ -14,7 +14,7 @@ class AuthController extends Controller {
|
||||
}
|
||||
|
||||
function handleLogin(){
|
||||
$config = ConfigModel::load();
|
||||
global $config;
|
||||
|
||||
$error = '';
|
||||
|
||||
@ -48,7 +48,7 @@ class AuthController extends Controller {
|
||||
|
||||
function handleLogout(){
|
||||
Session::end();
|
||||
$config = ConfigModel::load();
|
||||
global $config;
|
||||
header('Location: ' . $config->basePath);
|
||||
exit;
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
class CssController extends Controller {
|
||||
public function index() {
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
global $config;
|
||||
global $user;
|
||||
$customCss = CssModel::load();
|
||||
|
||||
$vars = [
|
||||
@ -49,7 +49,7 @@ class CssController extends Controller {
|
||||
}
|
||||
|
||||
public function handlePost() {
|
||||
$config = ConfigModel::load();
|
||||
global $config;
|
||||
|
||||
switch ($_POST['action']) {
|
||||
case 'upload':
|
||||
|
@ -4,8 +4,8 @@ class HomeController extends Controller {
|
||||
// renders the homepage view.
|
||||
public function index(){
|
||||
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
global $config;
|
||||
global $user;
|
||||
|
||||
$limit = $config->itemsPerPage;
|
||||
$offset = ($page - 1) * $limit;
|
||||
@ -40,7 +40,7 @@ class HomeController extends Controller {
|
||||
}
|
||||
|
||||
// get the config
|
||||
$config = ConfigModel::load();
|
||||
global $config;
|
||||
|
||||
// redirect to the index (will show the latest tick if one was sent)
|
||||
header('Location: ' . $config->basePath);
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
class MoodController extends Controller {
|
||||
public function index(){
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
global $config;
|
||||
global $user;
|
||||
$view = new MoodView();
|
||||
|
||||
$moodPicker = $view->render_mood_picker(self::get_emojis_with_labels(), $user->mood);
|
||||
@ -23,8 +23,8 @@
|
||||
}
|
||||
|
||||
// Get the data we need
|
||||
$config = ConfigModel::load();
|
||||
$user = UserModel::load();
|
||||
global $config;
|
||||
global $user;
|
||||
$mood = $_POST['mood'];
|
||||
|
||||
// set the mood
|
||||
|
Loading…
x
Reference in New Issue
Block a user