From 858b62054208a23a3628e6303f057f52e149cb24 Mon Sep 17 00:00:00 2001 From: Evg Date: Mon, 2 Jan 2023 16:38:36 +0300 Subject: [PATCH] =?UTF-8?q?DEV:=20SLUG=20=D0=BF=D0=BE=D1=81=D1=82=D0=B0=20?= =?UTF-8?q?(false/true)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controllers/ActionController.php | 6 +++--- app/Controllers/Answer/AddAnswerController.php | 2 +- app/Controllers/Answer/EditAnswerController.php | 2 +- app/Controllers/Comment/AddCommentController.php | 2 +- app/Controllers/Comment/EditCommentController.php | 3 +-- app/Controllers/Post/AddPostController.php | 2 +- app/Controllers/Post/EditPostController.php | 2 +- app/Controllers/Post/PostController.php | 12 +++++++----- app/Services/Audit.php | 2 +- app/helpers.php | 9 +++++++++ config/meta.php | 6 ++++++ config/user/setting.php | 2 +- modules/admin/view/default/audit/audits.php | 2 +- .../views/default/_block/latest-answers-tabs.php | 2 +- resources/views/default/_block/related-posts.php | 2 +- resources/views/default/content/answer/edit.php | 10 ++++------ resources/views/default/content/comment/comment.php | 4 ++-- resources/views/default/content/comment/comments.php | 2 +- resources/views/default/content/item/sites.php | 2 +- .../views/default/content/post/format-discussion.php | 2 +- resources/views/default/content/post/post-card.php | 4 ++-- .../views/default/content/post/post-classic.php | 2 +- resources/views/default/content/post/post-view.php | 4 ++-- resources/views/default/content/rss/rss-feed.php | 4 ++-- resources/views/default/content/rss/sitemap.php | 2 +- resources/views/default/content/rss/turbo-feed.php | 2 +- resources/views/default/content/search/search.php | 2 +- resources/views/default/content/user/draft.php | 2 +- .../views/default/content/user/favorite/all.php | 4 ++-- .../views/default/content/user/profile/index.php | 2 +- resources/views/default/global/base-header.php | 2 +- resources/views/minimum/content/post/post.php | 2 +- resources/views/qa/content/post/post.php | 2 +- routes/main.php | 2 +- 34 files changed, 63 insertions(+), 49 deletions(-) diff --git a/app/Controllers/ActionController.php b/app/Controllers/ActionController.php index 9700854b..878b6eaf 100644 --- a/app/Controllers/ActionController.php +++ b/app/Controllers/ActionController.php @@ -29,17 +29,17 @@ class ActionController extends Controller switch ($type) { case 'post': - $url = url('post', ['id' => $info_type['post_id'], 'slug' => $info_type['post_slug']]); + $url = post_slug($info_type['post_id'], $info_type['post_slug']); $action_type = 'post'; break; case 'comment': $post = PostModel::getPost($info_type['comment_post_id'], 'id', $this->user); - $url = url('post', ['id' => $info_type['comment_post_id'], 'slug' => $post['post_slug']]) . '#comment_' . $info_type['comment_id']; + $url = post_slug($info_type['comment_post_id'], $post['post_slug']) . '#comment_' . $info_type['comment_id']; $action_type = 'comment'; break; case 'answer': $post = PostModel::getPost($info_type['answer_post_id'], 'id', $this->user); - $url = url('post', ['id' => $info_type['answer_post_id'], 'slug' => $post['post_slug']]) . '#answer_' . $info_type['answer_id']; + $url = post_slug($info_type['answer_post_id'], $post['post_slug']) . '#answer_' . $info_type['answer_id']; $action_type = 'answer'; break; case 'reply': diff --git a/app/Controllers/Answer/AddAnswerController.php b/app/Controllers/Answer/AddAnswerController.php index be34c8b5..91554ec7 100644 --- a/app/Controllers/Answer/AddAnswerController.php +++ b/app/Controllers/Answer/AddAnswerController.php @@ -14,7 +14,7 @@ class AddAnswerController extends Controller { $post = PostPresence::index(Request::getPostInt('post_id'), 'id'); - $url_post = url('post', ['id' => $post['post_id'], 'slug' => $post['post_slug']]); + $url_post = post_slug($post['post_id'], $post['post_slug']); Validator::Length($content = $_POST['content'], 6, 5000, 'content', $url_post); diff --git a/app/Controllers/Answer/EditAnswerController.php b/app/Controllers/Answer/EditAnswerController.php index c58366f0..c69c9946 100644 --- a/app/Controllers/Answer/EditAnswerController.php +++ b/app/Controllers/Answer/EditAnswerController.php @@ -56,7 +56,7 @@ class EditAnswerController extends Controller $post = PostPresence::index($answer['answer_post_id'], 'id'); - $url_post = url('post', ['id' => $answer['answer_post_id'], 'slug' => $post['post_slug']]); + $url_post = post_slug($answer['answer_post_id'], $post['post_slug']); Validator::Length($content, 6, 5000, 'content', url('content.edit', ['type' => 'answer', 'id' => $answer['answer_id']])); diff --git a/app/Controllers/Comment/AddCommentController.php b/app/Controllers/Comment/AddCommentController.php index 90920359..ca8851bd 100644 --- a/app/Controllers/Comment/AddCommentController.php +++ b/app/Controllers/Comment/AddCommentController.php @@ -36,7 +36,7 @@ class AddCommentController extends Controller $post = PostPresence::index($answer['answer_post_id'], 'id'); - $url_post = url('post', ['id' => $post['post_id'], 'slug' => $post['post_slug']]); + $url_post = post_slug($post['post_id'], $post['post_slug']); Validator::Length($content = $_POST['comment'], 6, 2024, 'content', $url_post); diff --git a/app/Controllers/Comment/EditCommentController.php b/app/Controllers/Comment/EditCommentController.php index 1f3a2a66..98641660 100644 --- a/app/Controllers/Comment/EditCommentController.php +++ b/app/Controllers/Comment/EditCommentController.php @@ -44,8 +44,7 @@ class EditCommentController extends Controller $post = PostPresence::index($comment['comment_post_id'], 'id'); - $slug = url('post', ['id' => $post['post_id'], 'slug' => $post['post_slug']]); - $redirect = $slug . '#comment_' . $comment['comment_id']; + $redirect = post_slug($post['post_id'], $post['post_slug']) . '#comment_' . $comment['comment_id']; $content = $_POST['comment']; // для Markdown Validator::length($content, 3, 5500, 'content', $redirect); diff --git a/app/Controllers/Post/AddPostController.php b/app/Controllers/Post/AddPostController.php index 06dc5276..6abaa2f9 100644 --- a/app/Controllers/Post/AddPostController.php +++ b/app/Controllers/Post/AddPostController.php @@ -128,7 +128,7 @@ class AddPostController extends Controller (new \App\Services\Audit())->create('post', $last_id, url('admin.audits')); } - $url_content = url('post', ['id' => $last_id, 'slug' => $slug]); + $url_content = post_slug($last_id, $slug); if ($type == 'page') { $url_content = url('info.page', ['slug' => $slug]); } diff --git a/app/Controllers/Post/EditPostController.php b/app/Controllers/Post/EditPostController.php index ec2e778e..0bc56cc4 100644 --- a/app/Controllers/Post/EditPostController.php +++ b/app/Controllers/Post/EditPostController.php @@ -124,7 +124,7 @@ class EditPostController extends Controller ] ); - is_return(__('msg.change_saved'), 'success', '/post/' . $post['post_id']); + is_return(__('msg.change_saved'), 'success', url('post_id', ['id' => $post['post_id']])); } // Add fastes (blogs, topics) to the post diff --git a/app/Controllers/Post/PostController.php b/app/Controllers/Post/PostController.php index ce86094d..69514544 100644 --- a/app/Controllers/Post/PostController.php +++ b/app/Controllers/Post/PostController.php @@ -88,7 +88,7 @@ class PostController extends Controller 'type' => 'article', 'og' => true, 'imgurl' => $content_img, - 'url' => url('post', ['id' => $content['post_id'], 'slug' => $content['post_slug']]), + 'url' => post_slug($content['post_id'], $content['post_slug']), ]; // Sending Last-Modified and handling HTTP_IF_MODIFIED_SINCE @@ -169,14 +169,16 @@ class PostController extends Controller // If the post slug is different from the data in the database // Если slug поста отличается от данных в базе - if ($slug != $content['post_slug']) { - redirect(url('post', ['id' => $content['post_id'], 'slug' => $content['post_slug']])); + if (config('meta.slug_post') == true) { + if ($slug != $content['post_slug']) { + redirect(post_slug($content['post_id'], $content['post_slug'])); + } } // Redirect when merging a post // Редирект при слиянии поста if ($content['post_merged_id'] > 0 && !UserData::checkAdmin()) { - redirect('/post/' . $content['post_merged_id']); + redirect(url('post_id', ['id' => $content['post_merged_id']])); } return $content; @@ -189,7 +191,7 @@ class PostController extends Controller // Размещение своего поста у себя в профиле public function postProfile() { - $post = PostPresence::index($post_id = Request::getPostInt('post_id'), 'id'); + $post = PostPresence::index($post_id = Request::getPostInt('post_id'), 'id'); // Access check // Проверка доступа diff --git a/app/Services/Audit.php b/app/Services/Audit.php index 02c213f1..0347ef86 100644 --- a/app/Services/Audit.php +++ b/app/Services/Audit.php @@ -34,7 +34,7 @@ class Audit extends Base if (!in_array($content_type, ['post', 'answer', 'comment'])) return false; $type_id = $content_type == 'answer' ? 'answer_' . $content_id : 'comment_' . $content_id; - $url = '/post/' . $post['post_id'] . '/' . $post['post_slug'] . '#' . $type_id; + $url = post_slug($post['post_id'], $post['post_slug']) . '#' . $type_id; $this->create($content_type, $content_id, $url, 'report'); diff --git a/app/helpers.php b/app/helpers.php index b7837233..325d1157 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -29,6 +29,15 @@ function url(string $key = null, array $params = []) return hleb_get_by_name($key, $params); } +function post_slug(int $id, string $slug = '') +{ + if (config('meta.slug_post') == false) { + return hleb_get_by_name('post_id', ['id' => $id]); + } + + return hleb_get_by_name('post', ['id' => $id, 'slug' => $slug]); +} + function config(string $key = null) { if ($key === null) { diff --git a/config/meta.php b/config/meta.php index 72316128..b28aca2e 100644 --- a/config/meta.php +++ b/config/meta.php @@ -39,4 +39,10 @@ return [ // For site directory // Для каталог сайтов 'img_path_web' => '/assets/images/libarea-web.png', + + // If false, then the URL of the posts will be: /post/id + // otherwise: /post/id/slug + // Если false, то URL постов будет: /post/id + // в противном случае: /post/id/slug + 'slug_post' => true, ]; \ No newline at end of file diff --git a/config/user/setting.php b/config/user/setting.php index 45fb2d8b..789be502 100644 --- a/config/user/setting.php +++ b/config/user/setting.php @@ -52,7 +52,7 @@ return [ 'addition' => 'https://vk.com/', 'title' => 'vk', 'lang' => 'Vk', - 'help' => 'https://vk.com/NICK / id', + 'help' => 'https://vk.com/NICK', 'name' => 'vk' ], ]; \ No newline at end of file diff --git a/modules/admin/view/default/audit/audits.php b/modules/admin/view/default/audit/audits.php index cf0cce15..55d5c867 100644 --- a/modules/admin/view/default/audit/audits.php +++ b/modules/admin/view/default/audit/audits.php @@ -65,7 +65,7 @@ - + diff --git a/resources/views/default/_block/latest-answers-tabs.php b/resources/views/default/_block/latest-answers-tabs.php index c04a28bb..15fe2fcb 100644 --- a/resources/views/default/_block/latest-answers-tabs.php +++ b/resources/views/default/_block/latest-answers-tabs.php @@ -20,7 +20,7 @@ - + + ... diff --git a/resources/views/default/_block/related-posts.php b/resources/views/default/_block/related-posts.php index 0b0560f0..bee54209 100644 --- a/resources/views/default/_block/related-posts.php +++ b/resources/views/default/_block/related-posts.php @@ -7,7 +7,7 @@ - + diff --git a/resources/views/default/content/answer/edit.php b/resources/views/default/content/answer/edit.php index 09a86f2f..3727d4c3 100644 --- a/resources/views/default/content/answer/edit.php +++ b/resources/views/default/content/answer/edit.php @@ -1,15 +1,13 @@ - $post['post_id'], 'slug' => $post['post_slug']]); ?> +
/ : - +
- '300px', 'content' => $data['answer']['answer_content'], 'type' => 'answer', 'id' => $post['post_id']]); ?> + '300px', 'content' => $data['answer']['answer_content'], 'type' => 'answer', 'id' => $data['post']['post_id']]); ?> $data['user']]); ?> @@ -17,6 +15,6 @@ $url = url('post', ['id' => $post['post_id'], 'slug' => $post['post_slug']]); ?> - +
\ No newline at end of file diff --git a/resources/views/default/content/comment/comment.php b/resources/views/default/content/comment/comment.php index bd17194c..88944591 100644 --- a/resources/views/default/content/comment/comment.php +++ b/resources/views/default/content/comment/comment.php @@ -17,7 +17,7 @@ foreach ($comments as $comment) :
- +
@@ -36,7 +36,7 @@ foreach ($comments as $comment) :
- +
diff --git a/resources/views/default/content/comment/comments.php b/resources/views/default/content/comment/comments.php index c594cc67..8fa1986b 100644 --- a/resources/views/default/content/comment/comments.php +++ b/resources/views/default/content/comment/comments.php @@ -5,7 +5,7 @@ -
+
$data['comments']]); ?>
diff --git a/resources/views/default/content/item/sites.php b/resources/views/default/content/item/sites.php index a135dba6..bfd26fa6 100644 --- a/resources/views/default/content/item/sites.php +++ b/resources/views/default/content/item/sites.php @@ -104,7 +104,7 @@ diff --git a/resources/views/default/content/post/format-discussion.php b/resources/views/default/content/post/format-discussion.php index a75c6011..8a502d64 100644 --- a/resources/views/default/content/post/format-discussion.php +++ b/resources/views/default/content/post/format-discussion.php @@ -11,7 +11,7 @@ $post['post_id'], 'slug' => $post['post_slug']]); + $post_url = post_slug($post['post_id'], $post['post_slug']); ?>
diff --git a/resources/views/default/content/post/post-card.php b/resources/views/default/content/post/post-card.php index 6bfd072f..6f6ba879 100644 --- a/resources/views/default/content/post/post-card.php +++ b/resources/views/default/content/post/post-card.php @@ -7,7 +7,7 @@ - $post['post_id'], 'slug' => $post['post_slug']]); ?> +
- + diff --git a/resources/views/default/content/post/post-classic.php b/resources/views/default/content/post/post-classic.php index b267e91f..a27e7317 100644 --- a/resources/views/default/content/post/post-classic.php +++ b/resources/views/default/content/post/post-classic.php @@ -10,7 +10,7 @@ use Hleb\Constructor\Handlers\Request; ?> - $post['post_id'], 'slug' => $post['post_slug']]); ?> +
diff --git a/resources/views/default/content/post/post-view.php b/resources/views/default/content/post/post-view.php index b47b5d1f..38aa9641 100644 --- a/resources/views/default/content/post/post-view.php +++ b/resources/views/default/content/post/post-view.php @@ -215,7 +215,7 @@