Browse Source

RSS feed is now valid

develop
acab.io 1 year ago
parent
commit
7850eb8381
2 changed files with 159 additions and 196 deletions
  1. +147
    -186
      models/Reports.class.php
  2. +12
    -10
      templates/feed.xml.twig

+ 147
- 186
models/Reports.class.php View File

@ -1,186 +1,147 @@
<?php
/**
*
* Class to manage reports
*/
class Reports
{
/**
*
* DB connection
*/
private static $db;
/**
*
* DB connection contructor
*/
function __construct()
{
$dsn = 'sqlite:db/reports.sqlite3';
try{
self::$db=new PDO($dsn);
// We can now log any exceptions on Fatal error.
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Disable emulation of prepared statements, use REAL prepared statements instead.
self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$db->exec('PRAGMA foreign_keys = ON;');
}
catch(PDOException $e){
printf("Échec de la connexion : %s\n", $e->getMessage());
$this->db = null;
}
}
/**
*
* Get last 5 entries
*/
function Get_public()
{
$sql="SELECT REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC
LIMIT 5";
$data=self::$db->query($sql);
return $data;
}
/**
*
* Get last 10 entries
*/
function Get_rss()
{
$sql="SELECT REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC
LIMIT 10";
$data=self::$db->query($sql);
return $data;
}
/**
*
* Get last 5 entries
*/
function Get_last_reports()
{
$sql="SELECT REPORTS.ID, REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.ID,'|') AS MSGID,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC
LIMIT 5";
$data=self::$db->query($sql);
return $data;
}
/**
*
* Get all DB entries
*/
function Get_all_reports()
{
$sql="SELECT REPORTS.ID, REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.ID,'|') AS MSGID,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC";
$data=self::$db->query($sql);
return $data;
}
/**
*
* Add report
*/
function Add_report($data)
{
$sql = "INSERT INTO REPORTS(DATE,TITLE,MAINDESCRIPTION) values (?,?,?)";
$stmt = self::$db->prepare($sql);
return $stmt->execute(array($data['date'], $data['title'], $data['maindescription']));
}
/**
*
* Add report description
*/
function Add_description_report($data)
{
$sql = "INSERT INTO REPORT_DETAILS(REPORT_ID,DATE,DESCRIPTION) values (?,?,?)";
$stmt = self::$db->prepare($sql);
return $stmt->execute(array($data['report_id'], $data['date'], $data['description']));
}
/**
*
* Get report by ID
*/
function Get_report_by_id($id)
{
$sql="SELECT * FROM REPORTS WHERE ID=:id";
$stmt=self::$db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_OBJ);
}
/**
*
* Remove report by ID
*/
function Delete_report_by_id($id)
{
$sql="DELETE FROM REPORTS WHERE REPORTS.ID=:id";
$stmt=self::$db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
return $stmt->execute();
}
/**
*
* Remove report description by ID
*/
function Delete_description_by_id($id)
{
$sql="DELETE FROM REPORT_DETAILS WHERE ID=:id";
$stmt=self::$db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
return $stmt->execute();
}
/**
*
* Update report by ID
*/
function Update($id, $date, $title, $maindescription, $state)
{
$sql = "UPDATE `REPORTS`
SET `DATE` = :date,
`TITLE` = :title,
`MAINDESCRIPTION` = :maindescription,
`STATE` = :state
WHERE `REPORTS`.`ID` = :id";
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':id', $id);
$stmt->bindParam(':date', $date);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':maindescription', $maindescription);
$stmt->bindParam(':state', $state);
return $stmt->execute();
}
}
<?php
/** Class to manage reports */
class Reports {
/** DB connection */
private static $db;
/** DB connection contructor */
function __construct()
{
$dsn = 'sqlite:db/reports.sqlite3';
try{
self::$db=new PDO($dsn);
# We can now log any exceptions on Fatal error.
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Disable emulation of prepared statements, use REAL prepared statements instead.
self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$db->exec('PRAGMA foreign_keys = ON;');
}
catch(PDOException $e){
printf("Échec de la connexion : %s\n", $e->getMessage());
$this->db = NULL;
}
}
/** Get last 5 entries */
function Get_public()
{
$sql="SELECT REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC
LIMIT 5";
$data=self::$db->query($sql);
return $data;
}
/** Get last 10 entries */
function Get_rss()
{
$sql="SELECT REPORTS.ID, REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.ID,'|') AS MSGID,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC
LIMIT 10";
$data=self::$db->query($sql);
return $data;
}
/** Get last 5 entries */
function Get_last_reports()
{
$sql="SELECT REPORTS.ID, REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.ID,'|') AS MSGID,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC
LIMIT 5";
$data=self::$db->query($sql);
return $data;
}
/** Get all DB entries */
function Get_all_reports()
{
$sql="SELECT REPORTS.ID, REPORTS.DATE, REPORTS.TITLE, REPORTS.MAINDESCRIPTION, REPORTS.STATE,
GROUP_CONCAT(REPORT_DETAILS.ID,'|') AS MSGID,
GROUP_CONCAT(REPORT_DETAILS.DATE,'|') AS MSGDATE,
GROUP_CONCAT(REPORT_DETAILS.DESCRIPTION,'|') AS MSGDESCRIPTION
FROM REPORTS
LEFT JOIN REPORT_DETAILS ON REPORT_ID = REPORTS.ID
GROUP BY REPORTS.ID
ORDER BY REPORTS.DATE DESC";
$data=self::$db->query($sql);
return $data;
}
/** Add report */
function Add_report($data)
{
$sql = "INSERT INTO REPORTS(DATE,TITLE,MAINDESCRIPTION) values (?,?,?)";
$stmt = self::$db->prepare($sql);
return $stmt->execute(array($data['date'], $data['title'], $data['maindescription']));
}
/** Add report description */
function Add_description_report($data)
{
$sql = "INSERT INTO REPORT_DETAILS(REPORT_ID,DATE,DESCRIPTION) values (?,?,?)";
$stmt = self::$db->prepare($sql);
return $stmt->execute(array($data['report_id'], $data['date'], $data['description']));
}
/** Get report by ID */
function Get_report_by_id($id)
{
$sql="SELECT * FROM REPORTS WHERE ID=:id";
$stmt=self::$db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_OBJ);
}
/** Remove report by ID */
function Delete_report_by_id($id)
{
$sql="DELETE FROM REPORTS WHERE REPORTS.ID=:id";
$stmt=self::$db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
return $stmt->execute();
}
/** Remove report description by ID */
function Delete_description_by_id($id)
{
$sql="DELETE FROM REPORT_DETAILS WHERE ID=:id";
$stmt=self::$db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
return $stmt->execute();
}
/** Update report by ID */
function Update($id, $date, $title, $maindescription, $state)
{
$sql = "UPDATE `REPORTS`
SET `DATE` = :date,
`TITLE` = :title,
`MAINDESCRIPTION` = :maindescription,
`STATE` = :state
WHERE `REPORTS`.`ID` = :id";
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':id', $id);
$stmt->bindParam(':date', $date);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':maindescription', $maindescription);
$stmt->bindParam(':state', $state);
return $stmt->execute();
}
}

+ 12
- 10
templates/feed.xml.twig View File

@ -4,8 +4,8 @@
<title>{{ page_title }}</title>
<link>{{ page_url }}</link>
<atom:link href="{{ page_url }}/rss.xml" rel="self" type="application/rss+xml"></atom:link>
<description>RSS feed</description>
<language>en-us</language>
<description>Be inform when a problem occur on any acab.io services.</description>
<language>en-gb</language>
{% for report in reports %}
{% if loop.first %}
{% set datemsg = report.MSGDATE|split('|') %}
@ -13,13 +13,13 @@
{% if cycle(datemsg, i) is not empty %}
{% for i in 0..datecycle %}
{% if loop.last %}
<pubDate>{{ cycle(datemsg, i)|date("D, d M Y H:i:s T") }}</pubDate>
<lastBuildDate>{{ cycle(datemsg, i)|date("D, d M Y H:i:s T") }}</lastBuildDate>
<pubDate>{{ cycle(datemsg, i)|date('D, d M y H:i:s O') }}</pubDate>
<lastBuildDate>{{ cycle(datemsg, i)|date('D, d M y H:i:s O') }}</lastBuildDate>
{% endif %}
{% endfor %}
{% else %}
<pubDate>{{ report.DATE|date("D, d M Y H:i:s T") }}</pubDate>
<lastBuildDate>b{{ report.DATE|date("D, d M Y H:i:s T") }}</lastBuildDate>
<pubDate>{{ report.DATE|date('D, d M y H:i:s O') }}</pubDate>
<lastBuildDate>{{ report.DATE|date('D, d M y H:i:s O') }}</lastBuildDate>
{% endif %}
{% endif %}
{% set descriptions = report.MSGDESCRIPTION|split('|') %}
@ -29,17 +29,19 @@
{% for i in 0..nbcycle %}
<item>
<title>{{ report.TITLE }}</title>
<description>{{ cycle(descriptions, i) }}</description>
<pubDate>{{ cycle(date, i)|date("D, d M Y H:i:s T") }}</pubDate>
<link>{{ page_url }}</link>
<description>{{ cycle(descriptions, i) }}</description>
<pubDate>{{ cycle(date, i)|date('D, d M y H:i:s O') }}</pubDate>
<guid>https://status.acab.io/msg-{{ report.MSGID }}</guid>
</item>
{% endfor %}
{% endif %}
<item>
<title>{{ report.TITLE }}</title>
<description>{{ report.MAINDESCRIPTION }}</description>
<pubDate>{{ report.DATE|date("D, d M Y H:i:s T") }}</pubDate>
<link>{{ page_url }}</link>
<description>{{ report.MAINDESCRIPTION }}</description>
<pubDate>{{ report.DATE|date('D, d M y H:i:s O') }}</pubDate>
<guid>https://status.acab.io/report-{{ report.ID }}</guid>
</item>
{% endfor %}
</channel>

Loading…
Cancel
Save