Browse Source

Fix blog list page

leosw 5 months ago
parent
commit
f215a6cf08
3 changed files with 18 additions and 22 deletions
  1. 4 8
      controllers/d.blog.php
  2. 3 3
      models/d.blog.php
  3. 11 11
      views/d.blog.list.html

+ 4 - 8
controllers/d.blog.php

@@ -41,15 +41,11 @@ switch ($controller->splitted_url[1]) {
 
 		$i = 0;
 		$blogArticles_list = array();
-		foreach ($blogArticles->ids as $row) {
-			$blogArticles_list[$i] = new Kabano\BlogArticle();
-			$blogArticles_list[$i]->id = $row;
-			$blogArticles_list[$i]->populate();
-			$blogArticles_list[$i]->md2txt();
+		foreach ($blogArticles->objs as $row) {
+			$row->md2txt();
 			$tempUser = new Kabano\User();
-			$tempUser->id = $blogArticles_list[$i]->author;
-			$tempUser->populate();
-			$blogArticles_list[$i]->author_name = $tempUser->name;
+			$tempUser->checkId($row->author);
+			$row->author_name = $tempUser->name;
 			unset($tempUser);
 			$i++;
 		}

+ 3 - 3
models/d.blog.php

@@ -263,7 +263,7 @@ class BlogArticles
 
 		if ($archive == 1) {
 			// You just want one per url and the criteria is ORDER BY archives = true, time DES=C
-			$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 AS a) AS b WHERE r = 1 ORDER BY update_date DESC";
+			$query = "SELECT * FROM (SELECT *, 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 AS a WHERE type='blog') AS b WHERE r = 1 ORDER BY update_date DESC";
 		}
 		else {
 			$query = "SELECT * FROM contents WHERE is_archive IS NOT TRUE AND is_public IS TRUE AND type='blog' ORDER BY update_date DESC";
@@ -295,10 +295,10 @@ class BlogArticles
 
 		if ($archive == 1) {
 			// You just want one per url and the criteria is ORDER BY archives = true, time DES=C
-			$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 AS a) AS b WHERE r = 1 ORDER BY update_date DESC";
+			$query = "SELECT * FROM (SELECT 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 AS a WHERE type='blog') AS b WHERE r = 1 ORDER BY update_date DESC";
 		}
 		else {
-			$query = "SELECT * FROM contents WHERE is_archive IS NOT TRUE AND is_public IS TRUE AND type='blog' ORDER BY update_date DESC";
+			$query = "SELECT update_date 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) 

+ 11 - 11
views/d.blog.list.html

@@ -10,25 +10,25 @@
 		<section id="blog_list">
 			<h1>Blog.</h1>
 			<p class="subtitle">
-				<? if ($user->role >= 800) { ?>
-					<a href="<?=$config['rel_root_folder']?>blog/new"><i class="fa fa-plus"></i> Nouvel article</a> &mdash; 
+				<? if ($user->rankIsHigher("moderator")) { ?>
+					<a href="<?=$config['rel_root_folder']?>blog/new"><i class="fas fa-plus"></i> Nouvel article</a> &mdash; 
 				<? } ?>
-				<a href="<?=$config['rel_root_folder']?>blog/rss"><i class="fa fa-rss" aria-hidden="true"></i> Flux RSS</a> &mdash; 
+				<a href="<?=$config['rel_root_folder']?>blog/rss"><i class="fas fa-rss" aria-hidden="true"></i> Flux RSS</a> &mdash; 
 				Articles <?=$first?> à <?=$last?> sur <?=$blogArticles->number?>
 			</p>
 
 			<div id="articles_list">
 
-				<? foreach ($blogArticles_list as $row) { ?>
+				<? foreach ($blogArticles->objs as $row) { ?>
 
-					<article <? if($row->archive == 't') echo 'class="article_archive" '; ?>>
-						<h2 class="article_title"><?=$row->title?>.</h2>
+					<article <? if($row->is_archive == 't') echo 'class="article_archive" '; ?>>
+						<h2 class="article_title"><?=$row->name?>.</h2>
 						<div class="article_content"><?=mb_substr($row->content_txt,0,200)?>...</div>
 						<p class="article_legend">
-							<a class="article_link" href="<?=$config['rel_root_folder']?>blog/<?=$row->url?>">Lire la suite...</a>
+							<a class="article_link" href="<?=$config['rel_root_folder']?>blog/<?=$row->permalink?>">Lire la suite...</a>
 							<span class="article_infos">
-								Le <? echo strftime('%e %B %G',strtotime($row->lastedit)) ?> par 
-								<? if ($user->role > 0) { ?>
+								Le <? echo strftime('%e %B %G',strtotime($row->update_date)) ?> par 
+								<? if ($user->rankIsHigher("registered")) { ?>
 									<a href="<?=$config['rel_root_folder']?>user/p/<?=$row->author?>"><?=$row->author_name?></a>
 								<? } 
 								else { ?>
@@ -43,8 +43,8 @@
 			</div>
 			
 			<div class="pagebuttons">
-				<? if ($page != 0) { ?><a class="previous" href="<?=$config['rel_root_folder']?>blog/<?=$page?>"><i class="fa fa-chevron-left fa-fw"></i></a><? }
-				if (($page+1)*$articles_per_pages < $blogArticles->number) { ?><a class="next" href="<?=$config['rel_root_folder']?>blog/<?=$page+2?>"><i class="fa fa-chevron-right fa-fw"></i></a><? } ?>
+				<? if ($page != 0) { ?><a class="previous" href="<?=$config['rel_root_folder']?>blog/<?=$page?>"><i class="fas fa-chevron-left fa-fw"></i></a><? }
+				if (($page+1)*$articles_per_pages < $blogArticles->number) { ?><a class="next" href="<?=$config['rel_root_folder']?>blog/<?=$page+2?>"><i class="fas fa-chevron-right fa-fw"></i></a><? } ?>
 			</div>
 
 		</section>