2018-04-14 04:58:53 +02:00
|
|
|
<?php
|
2019-03-18 20:53:05 +01:00
|
|
|
use Misuzu\Request\RequestVar;
|
|
|
|
|
2018-10-04 22:30:55 +02:00
|
|
|
require_once '../misuzu.php';
|
2018-04-14 04:58:53 +02:00
|
|
|
|
2019-03-18 20:53:05 +01:00
|
|
|
if (RequestVar::get()->isset('n')) {
|
|
|
|
header(sprintf('Location: %s', url('news-post', [
|
2019-03-18 20:59:46 +01:00
|
|
|
'post' => RequestVar::get()->select('n')->int(),
|
2019-03-18 20:53:05 +01:00
|
|
|
])));
|
|
|
|
http_response_code(301);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-18 20:59:46 +01:00
|
|
|
$categoryId = RequestVar::get()->select('c')->int();
|
|
|
|
$postId = RequestVar::get()->select('p')->int();
|
2018-04-14 04:58:53 +02:00
|
|
|
|
2019-03-18 20:53:05 +01:00
|
|
|
if ($postId > 0) {
|
2018-10-10 11:21:57 +02:00
|
|
|
$post = news_post_get($postId);
|
|
|
|
|
|
|
|
if (!$post) {
|
2018-05-26 22:33:05 +02:00
|
|
|
echo render_error(404);
|
2018-04-14 04:58:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-10 06:20:54 +02:00
|
|
|
if ($post['comment_section_id'] === null) {
|
|
|
|
$commentsInfo = comments_category_create("news-{$post['post_id']}");
|
|
|
|
|
|
|
|
if ($commentsInfo) {
|
|
|
|
$post['comment_section_id'] = $commentsInfo['category_id'];
|
2018-10-10 11:21:57 +02:00
|
|
|
news_post_comments_set(
|
|
|
|
$post['post_id'],
|
|
|
|
$post['comment_section_id'] = $commentsInfo['category_id']
|
|
|
|
);
|
2018-08-10 06:20:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$commentsInfo = comments_category_info($post['comment_section_id']);
|
|
|
|
}
|
|
|
|
|
2018-08-15 03:12:58 +02:00
|
|
|
echo tpl_render('news.post', [
|
2018-08-10 06:20:54 +02:00
|
|
|
'post' => $post,
|
2018-10-03 00:34:05 +02:00
|
|
|
'comments_perms' => comments_get_perms(user_session_current('user_id', 0)),
|
2018-08-10 06:20:54 +02:00
|
|
|
'comments_category' => $commentsInfo,
|
2018-10-03 00:34:05 +02:00
|
|
|
'comments' => comments_category_get($commentsInfo['category_id'], user_session_current('user_id', 0)),
|
2018-08-10 06:20:54 +02:00
|
|
|
]);
|
2018-04-14 04:58:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-18 20:53:05 +01:00
|
|
|
if ($categoryId > 0) {
|
2018-10-11 23:43:52 +02:00
|
|
|
$category = news_category_get($categoryId, true);
|
2018-10-10 11:21:57 +02:00
|
|
|
|
2019-01-03 01:33:02 +01:00
|
|
|
if (empty($category)) {
|
|
|
|
echo render_error(404);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$categoryPagination = pagination_create($category['posts_count'], 5);
|
|
|
|
$postsOffset = pagination_offset($categoryPagination, pagination_param('page'));
|
|
|
|
|
|
|
|
if (!pagination_is_valid_offset($postsOffset)) {
|
2018-05-26 22:33:05 +02:00
|
|
|
echo render_error(404);
|
2018-04-14 04:58:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 11:21:57 +02:00
|
|
|
$posts = news_posts_get(
|
|
|
|
$postsOffset,
|
2019-01-03 01:33:02 +01:00
|
|
|
$categoryPagination['range'],
|
2018-10-10 11:21:57 +02:00
|
|
|
$category['category_id']
|
|
|
|
);
|
|
|
|
|
|
|
|
$featured = news_posts_get(0, 10, $category['category_id'], true);
|
2018-05-16 04:58:21 +02:00
|
|
|
|
2019-01-03 01:33:02 +01:00
|
|
|
tpl_var('news_pagination', $categoryPagination);
|
2018-08-15 03:12:58 +02:00
|
|
|
echo tpl_render('news.category', compact('category', 'posts', 'featured'));
|
2018-04-14 04:58:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 11:21:57 +02:00
|
|
|
$categories = news_categories_get(0, 0, true);
|
2018-05-16 22:48:33 +02:00
|
|
|
|
2019-01-03 01:33:02 +01:00
|
|
|
$newsPagination = pagination_create(news_posts_count(null, true), 5);
|
|
|
|
$postsOffset = pagination_offset($newsPagination, pagination_param('page'));
|
2018-05-16 22:48:33 +02:00
|
|
|
|
2019-01-03 01:33:02 +01:00
|
|
|
if (!pagination_is_valid_offset($postsOffset)) {
|
2018-05-26 22:33:05 +02:00
|
|
|
echo render_error(404);
|
2018-05-16 22:48:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 11:21:57 +02:00
|
|
|
$posts = news_posts_get(
|
|
|
|
$postsOffset,
|
2019-01-03 01:33:02 +01:00
|
|
|
$newsPagination['range'],
|
2018-10-10 11:21:57 +02:00
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2018-05-16 04:58:21 +02:00
|
|
|
|
2018-05-16 22:48:33 +02:00
|
|
|
if (!$posts) {
|
2018-05-26 22:33:05 +02:00
|
|
|
echo render_error(404);
|
2018-04-16 02:33:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-14 04:58:53 +02:00
|
|
|
|
2019-01-03 01:33:02 +01:00
|
|
|
tpl_var('news_pagination', $newsPagination);
|
2018-08-15 03:12:58 +02:00
|
|
|
echo tpl_render('news.index', compact('categories', 'posts'));
|