Browse Source

CodeSniffer cleaning

develop
acab.io 1 year ago
parent
commit
3c5e8053ae
3 changed files with 188 additions and 161 deletions
  1. +101
    -80
      controller.inc.php
  2. +86
    -80
      controller.php
  3. +1
    -1
      models/Reports.class.php

+ 101
- 80
controller.inc.php View File

@ -2,102 +2,123 @@
require_once 'models/Reports.class.php';
// https://gist.github.com/rchrd2/c94eb4701da57ce9a0ad4d2b00794131
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
);
if ($is_not_authenticated) {
header('HTTP/1.1 401 Authorization Required');
header('WWW-Authenticate: Basic realm="Access denied"');
exit;
}
function require_auth()
{
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
);
if ($is_not_authenticated) {
header('HTTP/1.1 401 Authorization Required');
header('WWW-Authenticate: Basic realm="Access denied"');
exit;
}
}
function listrss_action($cont,$twig,$message){
$reports = $cont->get_rss();
$template = $twig->load('feed.xml.twig');
$page_title="acab.io::status feed";
$page_url="https://status.acab.io";
$content = $template->render(array(
'page_title' => $page_title,
'page_url' => $page_url,
'reports' => $reports,
'bla' => $reports,
'message' => $message,
));
$xmlfile = fopen('rss.xml', 'r+');
fseek($xmlfile, 0); // On remet le curseur au début du fichier
fputs($xmlfile, $content); // On écrit le nouveau nombre de pages vues
fclose($xmlfile);
function listrss_action($cont,$twig,$message)
{
$reports = $cont->get_rss();
$template = $twig->load('feed.xml.twig');
$page_title="acab.io::status feed";
$page_url="https://status.acab.io";
$content = $template->render(
array(
'page_title' => $page_title,
'page_url' => $page_url,
'reports' => $reports,
'bla' => $reports,
'message' => $message,
)
);
$xmlfile = fopen('rss.xml', 'r+');
fseek($xmlfile, 0); // On remet le curseur au début du fichier
fputs($xmlfile, $content); // On écrit le nouveau nombre de pages vues
fclose($xmlfile);
}
function listpublic_action($cont,$twig,$message){
$reports = $cont->get_public();
$template = $twig->load('public.html.twig');
$page_title="Last 5 reports";
echo $template->render(array(
'page_title' => $page_title,
'reports' => $reports,
'message' => $message
));
function listpublic_action($cont,$twig,$message)
{
$reports = $cont->get_public();
$template = $twig->load('public.html.twig');
$page_title="Last 5 reports";
echo $template->render(
array(
'page_title' => $page_title,
'reports' => $reports,
'message' => $message
)
);
}
function listlast_action($cont,$twig,$message,$now){
$reports = $cont->get_last_reports();
$template = $twig->load('reports.html.twig');
$page_title="Last 5 reports";
echo $template->render(array(
'page_title' => $page_title,
'reports' => $reports,
'message' => $message,
'now' => $now
));
function listlast_action($cont,$twig,$message,$now)
{
$reports = $cont->get_last_reports();
$template = $twig->load('reports.html.twig');
$page_title="Last 5 reports";
echo $template->render(
array(
'page_title' => $page_title,
'reports' => $reports,
'message' => $message,
'now' => $now
)
);
}
function listall_action($cont,$twig,$message,$now){
$reports = $cont->get_all_reports();
$template = $twig->load('reports.html.twig');
$page_title="All reports";
echo $template->render(array(
'page_title' => $page_title,
'reports' => $reports,
'message' => $message,
'now' => $now
));
function listall_action($cont,$twig,$message,$now)
{
$reports = $cont->get_all_reports();
$template = $twig->load('reports.html.twig');
$page_title="All reports";
echo $template->render(
array(
'page_title' => $page_title,
'reports' => $reports,
'message' => $message,
'now' => $now
)
);
}
function detail_action($cont,$twig,$now,$id,$message=''){
$report = $cont->get_report_by_id($id);
$template = $twig->load('report.html.twig');
$page_title="Update report";
echo $template->render(array(
'page_title' => $page_title,
'report' => $report,
'now' => $now,
'message' => $message
));
function detail_action($cont,$twig,$now,$id,$message='')
{
$report = $cont->get_report_by_id($id);
$template = $twig->load('report.html.twig');
$page_title="Update report";
echo $template->render(
array(
'page_title' => $page_title,
'report' => $report,
'now' => $now,
'message' => $message
)
);
}
function suppr_action($cont,$id){
return ($cont->delete_report_by_id($id));
function suppr_action($cont,$id)
{
return ($cont->delete_report_by_id($id));
}
function suppr_description_action($cont, $id){
return ($cont->delete_description_by_id($id));
function suppr_description_action($cont, $id)
{
return ($cont->delete_description_by_id($id));
}
function update_action($cont,$id,$date,$page_title,$maindescription,$state){
return ($cont->update($id,$date,$page_title,$maindescription,$state));
function update_action($cont,$id,$date,$page_title,$maindescription,$state)
{
return ($cont->update($id, $date, $page_title, $maindescription, $state));
}
function add_action($cont,$report){
return ($cont->add_report($report));
function add_action($cont,$report)
{
return ($cont->add_report($report));
}
function add_description_action($cont,$report){
return ($cont->add_description_report($report));
function add_description_action($cont,$report)
{
return ($cont->add_description_report($report));
}

+ 86
- 80
controller.php View File

@ -1,80 +1,86 @@
<?php
require_once 'models/Reports.class.php';
$cont = new Reports;
include 'vendor/autoload.php';
// Templates location
$loader = new Twig\Loader\FilesystemLoader('templates');
// On your mark Twig !
$twig = new Twig\Environment($loader);
include 'controller.inc.php';
// Checking actions and parameters
// default to listpublic
$action = $_GET['action'] ?? 'listpublic';
$message = "";
$now = date("Y-m-d H:i:s");
switch ($action) {
case "listpublic":
listpublic_action($cont,$twig,$message);
break;
case "listrss":
listrss_action($cont,$twig,$message);
break;
case "listlast":
require_auth();
listlast_action($cont,$twig,$message,$now);
break;
case "listall":
require_auth();
listall_action($cont,$twig,$message,$now);
break;
case "detail":
require_auth();
detail_action($cont,$twig,$now,$_GET['id']);
break;
case "suppr":
require_auth();
if (suppr_action($cont,$_GET['id']))
$message = "Report successfully removed ! !";
else $message = "Something went wrong !";
listlast_action($cont,$twig,$message,$now);
listrss_action($cont,$twig,$message);
break;
case "suppr_description":
require_auth();
if (suppr_description_action($cont,$_GET['id']))
$message = "Report detail successfully removed ! !";
else $message = "Something went wrong !";
listlast_action($cont,$twig,$message,$now);
listrss_action($cont,$twig,$message);
break;
case "update":
require_auth();
if (!empty($_GET['id']) and !empty($_GET['date']) and !empty($_GET['title']) and !empty($_GET['maindescription']))
$res = update_action($cont,$_GET['id'],$_GET['date'],$_GET['title'],$_GET['maindescription'],$_GET['state']);
if (!empty($res))
$message = "Report successfully updated !";
else
$message = "Something went wrong !";
listlast_action($cont,$twig,$message,$now);
listrss_action($cont,$twig,$message);
break;
case "add":
require_auth();
if (add_action($cont, $_GET))
$message = "Report successfully added !";
else $message = "Something went wrong !";
listlast_action($cont,$twig,$message,$now);
listrss_action($cont,$twig,$message);
break;
case "add_description":
require_auth();
if (add_description_action($cont,$_GET))
$message = "Report detail successfully added !";
else $message = "Something went wrong !";
listlast_action($cont,$twig,$message,$now);
listrss_action($cont,$twig,$message);
break;
default:
listpublic_action($cont,$twig,$message,$now);
}
<?php
require_once 'models/Reports.class.php';
$cont = new Reports;
require 'vendor/autoload.php';
// Templates location
$loader = new Twig\Loader\FilesystemLoader('templates');
// On your mark Twig !
$twig = new Twig\Environment($loader);
require 'controller.inc.php';
// Checking actions and parameters
// default to listpublic
$action = $_GET['action'] ?? 'listpublic';
$message = "";
$now = date("Y-m-d H:i:s");
switch ($action) {
case "listpublic":
listpublic_action($cont, $twig, $message);
break;
case "listrss":
listrss_action($cont, $twig, $message);
break;
case "listlast":
require_auth();
listlast_action($cont, $twig, $message, $now);
break;
case "listall":
require_auth();
listall_action($cont, $twig, $message, $now);
break;
case "detail":
require_auth();
detail_action($cont, $twig, $now, $_GET['id']);
break;
case "suppr":
require_auth();
if (suppr_action($cont, $_GET['id'])) {
$message = "Report successfully removed ! !";
} else { $message = "Something went wrong !";
}
listlast_action($cont, $twig, $message, $now);
listrss_action($cont, $twig, $message);
break;
case "suppr_description":
require_auth();
if (suppr_description_action($cont, $_GET['id'])) {
$message = "Report detail successfully removed ! !";
} else { $message = "Something went wrong !";
}
listlast_action($cont, $twig, $message, $now);
listrss_action($cont, $twig, $message);
break;
case "update":
require_auth();
if (!empty($_GET['id']) and !empty($_GET['date']) and !empty($_GET['title']) and !empty($_GET['maindescription'])) {
$res = update_action($cont, $_GET['id'], $_GET['date'], $_GET['title'], $_GET['maindescription'], $_GET['state']);
}
if (!empty($res)) {
$message = "Report successfully updated !";
} else {
$message = "Something went wrong !";
}
listlast_action($cont, $twig, $message, $now);
listrss_action($cont, $twig, $message);
break;
case "add":
require_auth();
if (add_action($cont, $_GET)) {
$message = "Report successfully added !";
} else { $message = "Something went wrong !";
}
listlast_action($cont, $twig, $message, $now);
listrss_action($cont, $twig, $message);
break;
case "add_description":
require_auth();
if (add_description_action($cont, $_GET)) {
$message = "Report detail successfully added !";
} else { $message = "Something went wrong !";
}
listlast_action($cont, $twig, $message, $now);
listrss_action($cont, $twig, $message);
break;
default:
listpublic_action($cont, $twig, $message, $now);
}

+ 1
- 1
models/Reports.class.php View File

@ -5,7 +5,7 @@ class Reports {
/** DB connection */
private static $db;
/** DB conncection contructor */
/** DB connection contructor */
function __construct()
{
$dsn = 'sqlite:db/reports.sqlite3';


Loading…
Cancel
Save