First work on article list

This commit is contained in:
Léo Serre 2018-11-04 08:35:56 +01:00
parent 002c7db88c
commit a3d964e9c5
3 changed files with 22 additions and 19 deletions

View File

@ -31,13 +31,13 @@ switch ($controller->splitted_url[1]) {
case "list": case "list":
$blogArticles = new Kabano\BlogArticles(); $blogArticles = new Kabano\BlogArticles();
$blogArticles->number(($user->role >= 600)); $blogArticles->number(($user->rankIsHigher("premium")));
// In case the wanted page is too big // In case the wanted page is too big
if($articles_per_pages * $page >= $blogArticles->number) if($articles_per_pages * $page >= $blogArticles->number)
$page = 0; $page = 0;
$blogArticles->listArticles($page*$articles_per_pages,$articles_per_pages,($user->role >= 600)); $blogArticles->listArticles($page*$articles_per_pages,$articles_per_pages,($user->rankIsHigher("premium")));
$i = 0; $i = 0;
$blogArticles_list = array(); $blogArticles_list = array();
@ -64,7 +64,7 @@ switch ($controller->splitted_url[1]) {
} }
break; break;
case "new": case "new":
if($user->role >= 800) { if($user->rankIsHigher("moderator")) {
if(isset($_POST['submit'])) { if(isset($_POST['submit'])) {
$blogArticle->content = $_POST['content']; $blogArticle->content = $_POST['content'];
$blogArticle->locale = $_POST['locale']; $blogArticle->locale = $_POST['locale'];
@ -91,12 +91,12 @@ switch ($controller->splitted_url[1]) {
} }
default: default:
// If the page exists // If the page exists
if ($blogArticle->checkUrl($controller->splitted_url[1],$user->role >= 600)) { if ($blogArticle->checkUrl($controller->splitted_url[1],$user->rankIsHigher("premium"))) {
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->role >= 800) { if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
$blogArticle->delete(); $blogArticle->delete();
header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url); header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url);
} }
else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->role >= 800) { else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
if(isset($_POST['submit'])) { if(isset($_POST['submit'])) {
$blogArticle->content = $_POST['content']; $blogArticle->content = $_POST['content'];
$blogArticle->locale = $_POST['locale']; $blogArticle->locale = $_POST['locale'];
@ -114,7 +114,7 @@ switch ($controller->splitted_url[1]) {
} }
else { else {
// Manage history of an article // Manage history of an article
if($user->role >= 600) { if($user->rankIsHigher("premium")) {
$blogArticles_history = new Kabano\BlogArticles(); $blogArticles_history = new Kabano\BlogArticles();
$blogArticles_history->getHistory($controller->splitted_url[1]); $blogArticles_history->getHistory($controller->splitted_url[1]);
@ -127,11 +127,11 @@ switch ($controller->splitted_url[1]) {
} }
} }
if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2])) if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2]))
$blogArticle->checkUrl($controller->splitted_url[1],$user->role>=600,$controller->splitted_url[2]); $blogArticle->checkUrl($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]);
// Manage comment creation // Manage comment creation
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") { if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") {
if (isset($_POST['submit']) && $user->role > 0) { if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
$blogComment = new Kabano\BlogComment(); $blogComment = new Kabano\BlogComment();
$blogComment->locale = $user->locale; $blogComment->locale = $user->locale;
$blogComment->author = $user->id; $blogComment->author = $user->id;
@ -147,7 +147,7 @@ switch ($controller->splitted_url[1]) {
$blogComment = new Kabano\BlogComment(); $blogComment = new Kabano\BlogComment();
$blogComment->id = $controller->splitted_url[3]; $blogComment->id = $controller->splitted_url[3];
$blogComment->populate(); $blogComment->populate();
if ($user->role >= 800 || $user->id == $blogComment->author) if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
$blogComment->delete(); $blogComment->delete();
} }
} }
@ -158,7 +158,7 @@ switch ($controller->splitted_url[1]) {
$blogComment = new Kabano\BlogComment(); $blogComment = new Kabano\BlogComment();
$blogComment->id = $controller->splitted_url[3]; $blogComment->id = $controller->splitted_url[3];
$blogComment->populate(); $blogComment->populate();
if ($user->role >= 800 || $user->id == $blogComment->author) if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
$blogComment->undelete(); $blogComment->undelete();
} }
} }
@ -169,7 +169,7 @@ switch ($controller->splitted_url[1]) {
// Manage comments // Manage comments
if ($blogArticle->comments == "t") { if ($blogArticle->comments == "t") {
$blogArticles_comments = new Kabano\BlogComments(); $blogArticles_comments = new Kabano\BlogComments();
$blogArticles_comments->listComments($blogArticle->id, ($user->role>400)); $blogArticles_comments->listComments($blogArticle->id, ($user->rankIsHigher("premium")));
$i = 0; $i = 0;
foreach ($blogArticles_comments->ids as $row) { foreach ($blogArticles_comments->ids as $row) {

View File

@ -218,7 +218,7 @@ class BlogArticle
class BlogArticles class BlogArticles
{ {
public $ids = array(); public $objs = array();
public $number = NULL; public $number = NULL;
/***** /*****
@ -232,10 +232,10 @@ class BlogArticles
if ($archive == 1) { if ($archive == 1) {
// You just want one per url and the criteria is ORDER BY archives = true, time DES=C // You just want one per url and the criteria is ORDER BY archives = true, time DES=C
$query = "SELECT id FROM (SELECT a.id, a.lastedit , ROW_NUMBER() OVER (PARTITION BY a.url ORDER BY CASE WHEN a.archive IS TRUE THEN 1 ELSE 0 END, a.lastedit DESC) AS r FROM blog_articles AS a) AS b WHERE r = 1 ORDER BY lastedit DESC"; $query = "SELECT * FROM (SELECT a.id, a.update_date , ROW_NUMBER() OVER (PARTITION BY a.permalink ORDER BY CASE WHEN a.is_archive IS TRUE THEN 1 ELSE 0 END, a.update_date DESC) AS r FROM contents WHERE type='blog' AS a) AS b WHERE r = 1 ORDER BY update_date DESC";
} }
else { else {
$query = "SELECT id FROM blog_articles WHERE archive IS NOT TRUE ORDER BY lastedit DESC"; $query = "SELECT * FROM contents WHERE is_archive IS NOT TRUE AND is_public IS TRUE AND type='blog' ORDER BY update_date DESC";
} }
$query .= " LIMIT $1 OFFSET $2"; $query .= " LIMIT $1 OFFSET $2";
@ -248,9 +248,11 @@ class BlogArticles
for($i = 0; $i < pg_num_rows($result); $i++) { for($i = 0; $i < pg_num_rows($result); $i++) {
$row = pg_fetch_assoc($result, $i); $row = pg_fetch_assoc($result, $i);
$this->ids[$i] = $row['id']; $this->objs[$i] = new BlogArticle;
$this->objs[$i]->populate($row);
} }
} }
/***** /*****
** Return the number of articles ** Return the number of articles
*****/ *****/
@ -262,10 +264,10 @@ class BlogArticles
if ($archive == 1) { if ($archive == 1) {
// You just want one per url and the criteria is ORDER BY archives = true, time DES=C // You just want one per url and the criteria is ORDER BY archives = true, time DES=C
$query = "SELECT id FROM (SELECT a.id, a.lastedit , ROW_NUMBER() OVER (PARTITION BY a.url ORDER BY CASE WHEN a.archive IS TRUE THEN 1 ELSE 0 END, a.lastedit DESC) AS r FROM blog_articles AS a) AS b WHERE r = 1 ORDER BY lastedit DESC"; $query = "SELECT * FROM (SELECT a.id, a.update_date , ROW_NUMBER() OVER (PARTITION BY a.permalink ORDER BY CASE WHEN a.is_archive IS TRUE THEN 1 ELSE 0 END, a.update_date DESC) AS r FROM contents WHERE type='blog' AS a) AS b WHERE r = 1 ORDER BY update_date DESC";
} }
else { else {
$query = "SELECT id FROM blog_articles WHERE archive IS NOT TRUE ORDER BY lastedit DESC"; $query = "SELECT * FROM contents WHERE is_archive IS NOT TRUE AND is_public IS TRUE AND type='blog' ORDER BY update_date DESC";
} }
pg_prepare($con, "prepare1", $query) pg_prepare($con, "prepare1", $query)
@ -277,6 +279,7 @@ class BlogArticles
$this->number = pg_num_rows($result); $this->number = pg_num_rows($result);
} }
/***** /*****
** Return the list of archived version of a blog article ** Return the list of archived version of a blog article
*****/ *****/

View File

@ -40,7 +40,7 @@
<li class="on-bar has-sub"><a class="on-bar" href="#"><i class="icon fas fa-question"></i></a> <li class="on-bar has-sub"><a class="on-bar" href="#"><i class="icon fas fa-question"></i></a>
<ul> <ul>
<li><a href="<?=$config['rel_root_folder']?>wiki/help">Aide</a></li> <li><a href="<?=$config['rel_root_folder']?>wiki/help">Aide</a></li>
<!--<li><a href="<?=$config['rel_root_folder']?>blog">Blog</a></li>--> <li><a href="<?=$config['rel_root_folder']?>blog">Blog</a></li>
<li><a href="<?=$config['rel_root_folder']?>contact">Contact</a></li> <li><a href="<?=$config['rel_root_folder']?>contact">Contact</a></li>
<li><a href="<?=$config['rel_root_folder']?>wiki/api">API Développeurs</a></li> <li><a href="<?=$config['rel_root_folder']?>wiki/api">API Développeurs</a></li>
<li><a href="<?=$config['rel_root_folder']?>wiki/about">À propos</a></li> <li><a href="<?=$config['rel_root_folder']?>wiki/about">À propos</a></li>