2017-12-20 20:49:11 +00:00
|
|
|
<?
|
|
|
|
|
|
|
|
require_once($config['models_folder']."d.blog.php");
|
|
|
|
require_once($config['models_folder']."d.users.php");
|
|
|
|
|
|
|
|
$head['css'] = "d.index.css;d.blog.css";
|
|
|
|
|
2018-10-22 18:03:03 +00:00
|
|
|
$blogArticle = new Kabano\BlogArticle();
|
2017-12-20 20:49:11 +00:00
|
|
|
|
|
|
|
// In case we are in the list of articles, we set url to switch with according parameters
|
|
|
|
if (!isset($controller->splitted_url[1]) OR $controller->splitted_url[1]=="" OR is_numeric($controller->splitted_url[1])) {
|
|
|
|
$head['title'] = "Blog";
|
|
|
|
|
|
|
|
// Get the correct page number
|
|
|
|
if (!isset($controller->splitted_url[1]) OR $controller->splitted_url[1]=="") {
|
|
|
|
$page = 0;
|
|
|
|
} else {
|
|
|
|
$page = $controller->splitted_url[1] - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$controller->splitted_url[1] = "list";
|
|
|
|
$list = "html";
|
|
|
|
$articles_per_pages = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($controller->splitted_url[1]) {
|
|
|
|
case "rss":
|
|
|
|
$page = 0;
|
|
|
|
$list = "rss";
|
|
|
|
$articles_per_pages = 20;
|
|
|
|
case "list":
|
2018-10-22 18:03:03 +00:00
|
|
|
$blogArticles = new Kabano\BlogArticles();
|
2017-12-20 20:49:11 +00:00
|
|
|
|
2018-11-04 07:35:56 +00:00
|
|
|
$blogArticles->number(($user->rankIsHigher("premium")));
|
2017-12-20 20:49:11 +00:00
|
|
|
|
|
|
|
// In case the wanted page is too big
|
|
|
|
if($articles_per_pages * $page >= $blogArticles->number)
|
|
|
|
$page = 0;
|
|
|
|
|
2018-11-04 07:35:56 +00:00
|
|
|
$blogArticles->listArticles($page*$articles_per_pages,$articles_per_pages,($user->rankIsHigher("premium")));
|
2017-12-20 20:49:11 +00:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$blogArticles_list = array();
|
2019-01-23 12:32:54 +00:00
|
|
|
foreach ($blogArticles->objs as $row) {
|
|
|
|
$row->md2txt();
|
2018-10-22 18:03:03 +00:00
|
|
|
$tempUser = new Kabano\User();
|
2019-01-23 12:32:54 +00:00
|
|
|
$tempUser->checkId($row->author);
|
|
|
|
$row->author_name = $tempUser->name;
|
2017-12-20 20:49:11 +00:00
|
|
|
unset($tempUser);
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$first = $page*$articles_per_pages+1;
|
|
|
|
$last = (($page+1)*$articles_per_pages > $blogArticles->number ? $blogArticles->number : ($page+1)*$articles_per_pages);
|
|
|
|
|
|
|
|
if ($list == "rss") {
|
|
|
|
include ($config['views_folder']."d.blog.list.rss");
|
|
|
|
} else {
|
|
|
|
include ($config['views_folder']."d.blog.list.html");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "new":
|
2018-11-04 07:35:56 +00:00
|
|
|
if($user->rankIsHigher("moderator")) {
|
2017-12-20 20:49:11 +00:00
|
|
|
if(isset($_POST['submit'])) {
|
|
|
|
$blogArticle->content = $_POST['content'];
|
|
|
|
$blogArticle->locale = $_POST['locale'];
|
2018-11-05 20:35:21 +00:00
|
|
|
$blogArticle->name = $_POST['name'];
|
|
|
|
$blogArticle->is_commentable = isset($_POST['is_commentable'])?'t':'f';
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogArticle->author = $user->id;
|
2018-11-05 20:35:21 +00:00
|
|
|
if(!$blogArticle->checkPermalink($_POST['permalink'],1)) {
|
|
|
|
$blogArticle->permalink = $_POST['permalink'];
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogArticle->insert();
|
2018-11-05 20:35:21 +00:00
|
|
|
header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-05 20:35:21 +00:00
|
|
|
$head['title'] = $blogArticle->name;
|
|
|
|
$error = "permalink";
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$head['title'] = "Nouvel article";
|
|
|
|
}
|
2018-11-05 20:35:21 +00:00
|
|
|
|
|
|
|
$locales = new Kabano\Locales();
|
|
|
|
$locales->getAll();
|
|
|
|
|
|
|
|
$new = 1;
|
|
|
|
include ($config['views_folder']."d.blog.edit.html");
|
2017-12-20 20:49:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// If the page exists
|
2018-11-05 20:35:21 +00:00
|
|
|
if ($blogArticle->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"))) {
|
2018-11-04 07:35:56 +00:00
|
|
|
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogArticle->delete();
|
2018-11-05 21:29:14 +00:00
|
|
|
header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
2018-11-05 21:39:06 +00:00
|
|
|
else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "restore" && $user->rankIsHigher("moderator")) {
|
|
|
|
$blogArticle->restore();
|
|
|
|
header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
|
|
|
|
}
|
2018-11-04 07:35:56 +00:00
|
|
|
else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
|
2017-12-20 20:49:11 +00:00
|
|
|
if(isset($_POST['submit'])) {
|
|
|
|
$blogArticle->content = $_POST['content'];
|
|
|
|
$blogArticle->locale = $_POST['locale'];
|
2018-11-05 21:29:14 +00:00
|
|
|
$blogArticle->name = $_POST['name'];
|
|
|
|
$blogArticle->is_commentable = isset($_POST['is_commentable'])?'t':'f';
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogArticle->author = $user->id;
|
|
|
|
$blogArticle->update();
|
2018-11-05 21:29:14 +00:00
|
|
|
header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-05 21:29:14 +00:00
|
|
|
$locales = new Kabano\Locales();
|
|
|
|
$locales->getAll();
|
|
|
|
|
|
|
|
$head['title'] = $blogArticle->name;
|
2017-12-20 20:49:11 +00:00
|
|
|
include ($config['views_folder']."d.blog.edit.html");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Manage history of an article
|
2018-11-04 07:35:56 +00:00
|
|
|
if($user->rankIsHigher("premium")) {
|
2018-11-05 21:34:48 +00:00
|
|
|
$blogHistory = new Kabano\BlogArticles();
|
|
|
|
$blogHistory->getHistory($controller->splitted_url[1]);
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2]))
|
2018-11-05 20:35:21 +00:00
|
|
|
$blogArticle->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]);
|
2017-12-20 20:49:11 +00:00
|
|
|
|
|
|
|
// Manage comment creation
|
|
|
|
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") {
|
2018-11-04 07:35:56 +00:00
|
|
|
if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
|
2018-10-22 18:03:03 +00:00
|
|
|
$blogComment = new Kabano\BlogComment();
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogComment->locale = $user->locale;
|
|
|
|
$blogComment->author = $user->id;
|
2018-11-18 20:59:55 +00:00
|
|
|
$blogComment->content = $blogArticle->id;
|
|
|
|
$blogComment->comment = $_POST['comment'];
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogComment->insert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manage comment deletion
|
|
|
|
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete_comment") {
|
|
|
|
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
2018-10-22 18:03:03 +00:00
|
|
|
$blogComment = new Kabano\BlogComment();
|
2018-11-18 20:59:55 +00:00
|
|
|
if($blogComment->checkId($controller->splitted_url[3]))
|
|
|
|
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
|
|
|
$blogComment->delete();
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 21:29:14 +00:00
|
|
|
// Manage comment restoration
|
|
|
|
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore_comment") {
|
2017-12-20 20:49:11 +00:00
|
|
|
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
2018-10-22 18:03:03 +00:00
|
|
|
$blogComment = new Kabano\BlogComment();
|
2018-11-18 20:59:55 +00:00
|
|
|
if($blogComment->checkId($controller->splitted_url[3]))
|
|
|
|
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
|
|
|
$blogComment->restore();
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$blogArticle->md2html();
|
|
|
|
|
|
|
|
// Manage comments
|
2018-11-05 21:05:42 +00:00
|
|
|
if ($blogArticle->is_commentable == "t") {
|
2018-10-22 18:03:03 +00:00
|
|
|
$blogArticles_comments = new Kabano\BlogComments();
|
2018-11-04 07:35:56 +00:00
|
|
|
$blogArticles_comments->listComments($blogArticle->id, ($user->rankIsHigher("premium")));
|
2017-12-20 20:49:11 +00:00
|
|
|
|
|
|
|
$i = 0;
|
2018-11-18 20:59:55 +00:00
|
|
|
foreach ($blogArticles_comments->objs as $comment) {
|
|
|
|
$comment->md2html();
|
|
|
|
$comment->author_obj = new Kabano\User();
|
|
|
|
$comment->author_obj->checkId($comment->author);
|
2017-12-20 20:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-22 18:03:03 +00:00
|
|
|
$tempUser = new Kabano\User();
|
2018-11-05 21:05:42 +00:00
|
|
|
$tempUser->checkId($blogArticle->author);
|
2017-12-20 20:49:11 +00:00
|
|
|
$blogArticle->author_name = $tempUser->name;
|
|
|
|
unset($tempUser);
|
|
|
|
|
2018-11-05 21:05:42 +00:00
|
|
|
$head['title'] = $blogArticle->name;
|
2017-12-20 20:49:11 +00:00
|
|
|
include ($config['views_folder']."d.blog.view.html");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$notfound = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|