<?php

/* 
 * Copyright (C) 2022 Echedey López Romero <elr@disroot.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Show errors in screen
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

// Repair output with Tidy
ini_set('tidy.clean_output', '1');

// Empty web browser cache
header('Cache-Control: no-cache');
header('Pragma: no-cache');

// Load dependencies paths
require './vendor/autoload.php';

// Load classes
require './connections/FirebaseCon.php';

require './models/User.php';
require './models/Comment.php';
require './models/Post.php';

require './controllers/ManageUsers.php';
require './controllers/ManageComments.php';
require './controllers/ManagePosts.php';

require './controllers/ManageBlog.php';

// Load variables
require './variables.php';

// Main functionality
if ((isset($_GET) && count($_GET) === 0) || !isset($_GET) || isset($_GET['XDEBUG_SESSION_START'])) {
    $Page = $ManageBlog->ShowPosts();
} else if (isset($_GET) && count($_GET) > 1) {
    header('Location:.');
} else {
    if (isset($_GET['post'])) {
        $PostId = $_GET['post'];
        $Page = $ManageBlog->ShowPost($PostId);
    } else if (isset($_GET['user'])) {
        $UserId = $_GET['user'];
        $Page = $ManageBlog->ShowUser($UserId);
    } else {
        header('Location:.');
    }
}

// Load view
require './view.php';
