<?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';

$User1 = new User('001', 'Echedey', 'elr@disroot.org',
        (new DateTime())->format('d/m/Y H:i'), 0);
$User2 = new User('002', 'Tomy', 'tomy@tomy.tomy',
        (new DateTime())->format('d/m/Y H:i'), 1);
$User3 = new User('003', 'Dani', 'dani@dani.dani',
        (new DateTime())->format('d/m/Y H:i'), 1);
$User4 = new User('004', 'Gabriel', 'gabriel@gabriel.gabriel',
        (new DateTime())->format('d/m/Y H:i'), 2);

$Comment1 = new Comment('0001', '001', 'Good post',
        (new DateTime())->format('d/m/Y H:i'),
        'I like this post');
$Comment2 = new Comment('0002', '004', 'Garbage',
        (new DateTime())->format('d/m/Y H:i'),
        'This post is too summarized');
$Comment3 = new Comment('0003', '002', 'A typo',
        (new DateTime())->format('d/m/Y H:i'),
        'You said "more complete then" when should be "more complete than" '
        . 'in the second sentence.');

$Post1 = new Post('001', '002',
        'Structure and Interpretation of Computer Programs',
        (new DateTime())->format('d/m/Y H:i'),
        './images/SICP.jpg',
        'The SICP book is a complete book for practicing maths while learning '
        . 'how to program in the best way. It is old but more complete then '
        . 'current programming books.', ['0001', '0003']);
$Post2 = new Post('002', '003', 'Doctor Who with new Doctor',
        (new DateTime())->format('d/m/Y H:i'),
        './images/doctor_who.png', 'With the fall of 11st season of the modern '
        . 'series of Doctor Who, a new Doctor appears being a full woman.',
        ['0002']);

$Page = '<p>THE TEST MODE BEGINS</p>' . PHP_EOL . PHP_EOL;

$Page .= '<p>USERS</p>' . PHP_EOL;

$Page .= '<p>Adding first user...<p>' . PHP_EOL;
$Page .= '<p>' . $ManageUsers->AddUser($User1) . '</p>' . PHP_EOL;

$Page .= '<p>Adding second user...</p>' . PHP_EOL;
$Page .= '<p>' . $ManageUsers->AddUser($User2) . '</p>' . PHP_EOL;

$Page .= '<p>Adding third user...</p>' . PHP_EOL;
$Page .= '<p>' . $ManageUsers->AddUser($User3) . '</p>' . PHP_EOL;

$Page .= '<p>Adding forth user...</p>' . PHP_EOL;
$Page .= '<p>' . $ManageUsers->AddUser($User4) . '</p>' . PHP_EOL . PHP_EOL;

$Page .= '<p>Comments</p>' . PHP_EOL;

$Page .= '<p>Adding first comment</p>' . PHP_EOL;
$Page .= '<p>' . $ManageComments->AddComment($Comment1) . '</p>' . PHP_EOL;

$Page .= '<p>Adding second comment</p>' . PHP_EOL;
$Page .= '<p>' . $ManageComments->AddComment($Comment2) . '</p>' . PHP_EOL;

$Page .= '<p>Adding third comment</p>' . PHP_EOL;
$Page .= '<p>' . $ManageComments->AddComment($Comment3) . '</p>' . PHP_EOL . PHP_EOL;

$Page .= '<p>Posts</p>' . PHP_EOL;

$Page .= '<p>Adding first post</p>' . PHP_EOL;
$Page .= '<p>' . $ManagePosts->AddPost($Post1) . '</p>' . PHP_EOL;

$Page .= '<p>Adding second post</p>' . PHP_EOL;
$Page .= '<p>' . $ManagePosts->AddPost($Post2) . '</p>' . PHP_EOL . PHP_EOL;

$Page .= '<p>THE TEST MODE ENDS</p>' . PHP_EOL . PHP_EOL;

$Page .= $ManageBlog->ShowPosts();

require './view.php';
