2018-04-14 02:58:53 +00:00
|
|
|
<?php
|
2018-10-04 20:30:55 +00:00
|
|
|
require_once '../misuzu.php';
|
2018-04-14 02:58:53 +00:00
|
|
|
|
2018-05-27 00:20:35 +00:00
|
|
|
$categoryId = isset($_GET['c']) ? (int)$_GET['c'] : null;
|
|
|
|
$postId = isset($_GET['p']) ? (int)$_GET['p'] : (isset($_GET['n']) ? (int)$_GET['n'] : null);
|
|
|
|
$postsOffset = (int)($_GET['o'] ?? 0);
|
|
|
|
$postsTake = 5;
|
2018-05-16 20:48:33 +00:00
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
tpl_vars([
|
2018-05-27 00:20:35 +00:00
|
|
|
'posts_offset' => $postsOffset,
|
|
|
|
'posts_take' => $postsTake,
|
|
|
|
]);
|
2018-04-14 02:58:53 +00:00
|
|
|
|
2018-05-27 00:20:35 +00:00
|
|
|
if ($postId !== null) {
|
2018-10-10 09:21:57 +00:00
|
|
|
$post = news_post_get($postId);
|
|
|
|
|
|
|
|
if (!$post) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-04-14 02:58:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-10 04:20:54 +00: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 09:21:57 +00:00
|
|
|
news_post_comments_set(
|
|
|
|
$post['post_id'],
|
|
|
|
$post['comment_section_id'] = $commentsInfo['category_id']
|
|
|
|
);
|
2018-08-10 04:20:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$commentsInfo = comments_category_info($post['comment_section_id']);
|
|
|
|
}
|
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('news.post', [
|
2018-08-10 04:20:54 +00:00
|
|
|
'post' => $post,
|
2018-10-02 22:34:05 +00:00
|
|
|
'comments_perms' => comments_get_perms(user_session_current('user_id', 0)),
|
2018-08-10 04:20:54 +00:00
|
|
|
'comments_category' => $commentsInfo,
|
2018-10-02 22:34:05 +00:00
|
|
|
'comments' => comments_category_get($commentsInfo['category_id'], user_session_current('user_id', 0)),
|
2018-08-10 04:20:54 +00:00
|
|
|
]);
|
2018-04-14 02:58:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-27 00:20:35 +00:00
|
|
|
if ($categoryId !== null) {
|
2018-10-11 21:43:52 +00:00
|
|
|
$category = news_category_get($categoryId, true);
|
2018-10-10 09:21:57 +00:00
|
|
|
|
|
|
|
if (!$category || $postsOffset < 0 || $postsOffset >= $category['posts_count']) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-04-14 02:58:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:21:57 +00:00
|
|
|
$posts = news_posts_get(
|
|
|
|
$postsOffset,
|
|
|
|
$postsTake,
|
|
|
|
$category['category_id']
|
|
|
|
);
|
|
|
|
|
|
|
|
$featured = news_posts_get(0, 10, $category['category_id'], true);
|
2018-05-16 02:58:21 +00:00
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('news.category', compact('category', 'posts', 'featured'));
|
2018-04-14 02:58:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:21:57 +00:00
|
|
|
$categories = news_categories_get(0, 0, true);
|
|
|
|
$postsCount = news_posts_count(null, true);
|
2018-05-16 20:48:33 +00:00
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
tpl_var('posts_count', $postsCount);
|
2018-05-16 20:48:33 +00:00
|
|
|
|
2018-05-27 00:20:35 +00:00
|
|
|
if ($postsOffset < 0 || $postsOffset >= $postsCount) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-05-16 20:48:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:21:57 +00:00
|
|
|
$posts = news_posts_get(
|
|
|
|
$postsOffset,
|
|
|
|
$postsTake,
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2018-05-16 02:58:21 +00:00
|
|
|
|
2018-05-16 20:48:33 +00:00
|
|
|
if (!$posts) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-04-16 00:33:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-14 02:58:53 +00:00
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('news.index', compact('categories', 'posts'));
|