Commit a2b96bcc authored by Corentin Bettiol's avatar Corentin Bettiol 💻

add rss support

parent 930c3774
blog.xml
projects.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>l3m website - projets</title>
<description>Site perso de Corentin Bettiol.</description>
<lastBuildDate>19/03/2019 à 21:32</lastBuildDate>
<link>https://l3m.in</link><item>
<title>assb</title>
<description>assb = another static site builder</description>
<link>https://l3m.in/assb-2</link>
</item><item>
<title>L'ancienne version</title>
<description>Pas de description.</description>
<link>https://l3m.in/old-l3m-in</link>
</item><item>
<title>AutoRPG</title>
<description>Pas de description.</description>
<link>https://l3m.in/autorpg</link>
</item><item>
<title>l3m website</title>
<description>Pas de description.</description>
<link>https://l3m.in/l3m-website</link>
</item></channel></rss>
\ No newline at end of file
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// classe pour l'administration du contenu du site // classe pour l'administration du contenu du site
require_once('site/model/AdminManager.php'); require_once('site/model/AdminManager.php');
// classe pour la màj des fichiers RSS
require_once('site/model/RssManager.php');
// tente de connecter l'administrateur // tente de connecter l'administrateur
function loginAdminPage($pageName){ function loginAdminPage($pageName){
if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){ if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){
......
...@@ -33,32 +33,50 @@ class AdminManager extends Base ...@@ -33,32 +33,50 @@ class AdminManager extends Base
public function updateBlogPost(){ public function updateBlogPost(){
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['id']); $blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$blog->update(); $blog->update();
$rss = new RssManager();
$rss->updateRssBlog();
} }
public function updateProject(){ public function updateProject(){
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']); $project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$project->update(); $project->update();
$rss = new RssManager();
$rss->updateRssProjects();
} }
public function sendBlogPost(){ public function sendBlogPost(){
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], null); $blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], null);
$blog->send(); $blog->send();
$rss = new RssManager();
$rss->updateRssBlog();
} }
public function sendProject(){ public function sendProject(){
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], null); $project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], null);
$project->send(); $project->send();
$rss = new RssManager();
$rss->updateRssProjects();
} }
public function deleteBlogPost($link){ public function deleteBlogPost($link){
$blog = new BlogManager(null, null, null, null, null, null); $blog = new BlogManager(null, null, null, null, null, null);
$blog->delete($link); $blog->delete($link);
$rss = new RssManager();
$rss->updateRssBlog();
} }
public function deleteProject($link){ public function deleteProject($link){
$project = new ProjectManager(null, null, null, null, null); $project = new ProjectManager(null, null, null, null, null);
$project->delete($link); $project->delete($link);
$rss = new RssManager();
$rss->updateRssProjects();
} }
} }
\ No newline at end of file
...@@ -51,6 +51,12 @@ class BlogManager extends Base ...@@ -51,6 +51,12 @@ class BlogManager extends Base
return $req; return $req;
} }
public function getBlogRss()
{
$req = self::$db->query('SELECT time, title, shortContent, slug FROM l3m_blog ORDER BY id DESC LIMIT 10');
return $req;
}
public function pagingList($current) public function pagingList($current)
{ {
$total = self::$db->query('select count(*) from l3m_blog')->fetchColumn(); $total = self::$db->query('select count(*) from l3m_blog')->fetchColumn();
......
...@@ -49,6 +49,12 @@ class ProjectManager extends Base ...@@ -49,6 +49,12 @@ class ProjectManager extends Base
]); ]);
} }
public function getProjectsRss()
{
$req = self::$db->query('SELECT name, shortContent, slug FROM l3m_projects ORDER BY id DESC LIMIT 10');
return $req;
}
public function send(){ public function send(){
if(strlen($this->name) < 1){ if(strlen($this->name) < 1){
header('Location:/patate'); header('Location:/patate');
......
<?php
class RssManager extends Base
{
function updateRssBlog(){
$contentBlog =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\">
<channel>
<title>l3m website - posts de blog</title>
<description>Site perso de Corentin Bettiol.</description>
<lastBuildDate>". date('d/m/Y à H:i') ."</lastBuildDate>
<link>https://l3m.in</link>";
$blog = new BlogManager(null, null, null, null, null);
$posts = $blog->getBlogRss();
foreach ($posts as $post) {
$post['datetime'] = new DateTime($post['time']);
$date = date_format($post['datetime'], 'd/m/Y à H:i');
$contentBlog .= "<item>
<title>". $post['title'] ."</title>
<description>". $post['shortContent'] ."</description>
<pubDate>". $date ."</pubDate>
<link>https://l3m.in/". $post['slug'] ."</link>
</item>";
}
$contentBlog .= "</channel></rss>";
file_put_contents(RSSBLOG, $contentBlog);
}
function updateRssProjects(){
$contentProject =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\">
<channel>
<title>l3m website - projets</title>
<description>Site perso de Corentin Bettiol.</description>
<lastBuildDate>". date('d/m/Y à H:i') ."</lastBuildDate>
<link>https://l3m.in</link>";
$projects = new ProjectManager(null, null, null, null, null);
$projects = $projects->getProjectsRss();
foreach ($projects as $project) {
$contentProject .= "<item>
<title>". $project['name'] ."</title>
<description>". $project['shortContent'] ."</description>
<link>https://l3m.in/". $project['slug'] ."</link>
</item>";
}
$contentProject .= "</channel></rss>";
file_put_contents(RSSPROJECTS, $contentProject);
}
}
\ No newline at end of file
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
// login config // login config
define('user', ''); define('user', '');
define('pass', ''); define('pass', '');
\ No newline at end of file
// rss config
define('RSSBLOG', '');
define('RSSPROJECTS', '');
\ No newline at end of file
<article>
<h3><a href="">19/03/19</a></h3>
<ul>
<li>Création des flux rss :
<ul>
<li>Classe RssManager</li>
<li>Fonctions updateRssBlog() & updateRssProjects()</li>
<li>Appel de ces fonctions lors de chaque ajout/edit/suppression de billet de blog/projet</li>
</ul>
</li>
</ul>
</article>
<article> <article>
<h3><a href="https://git.bitmycode.com/sodimel/l3m-website/commit/d4ee13c79b8bc2c43da23677f6c4d4d015700b69">12/03/19</a></h3> <h3><a href="https://git.bitmycode.com/sodimel/l3m-website/commit/d4ee13c79b8bc2c43da23677f6c4d4d015700b69">12/03/19</a></h3>
<ul> <ul>
......
TODO -- rss <article>
\ No newline at end of file <h3><a href="/rss/blog" title="flux rss blog">Flux RSS du blog</a></h3>
<p>
Ce flux RSS vous permet d'avoir accès aux dix derniers messages du blog postés.
</p>
</article>
<article>
<h3><a href="/rss/projets" title="flux rss projets">Flux RSS des projets</a></h3>
<p>
Ce flux RSS vous permet d'avoir accès aux dix derniers projets créés.
</p>
</article>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment