Skip to content

Commit a06db76

Browse files
committed
refactor: migrated comments page to controller (#3257)
1 parent 0e2fe6b commit a06db76

File tree

10 files changed

+182
-177
lines changed

10 files changed

+182
-177
lines changed

nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ server {
129129
rewrite admin/api/(.*) /admin/api/index.php last;
130130

131131
# Administration pages
132-
rewrite admin/(attachments|backup|configuration|elasticsearch|export|glossary|group|import|instance|instances|password|session-keep-alive|statistics|stopwords|system|tags|update|user) /admin/front.php last;
132+
rewrite admin/(attachments|backup|comments|configuration|elasticsearch|export|glossary|group|import|instance|instances|password|session-keep-alive|statistics|stopwords|system|tags|update|user) /admin/front.php last;
133133

134134
# REST API v3.0 and v3.1
135135
rewrite ^api/v3\.[01]/(.*) /api/index.php last;

phpmyfaq/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
143143
# Administration API
144144
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
145145
# Administration pages
146-
RewriteRule ^admin/(attachments|backup|configuration|elasticsearch|export|glossary|group|import|instance|instances|password|session-keep-alive|statistics|stopwords|system|tags|update|user) admin/front.php [L,QSA]
146+
RewriteRule ^admin/(attachments|backup|comments|configuration|elasticsearch|export|glossary|group|import|instance|instances|password|session-keep-alive|statistics|stopwords|system|tags|update|user) admin/front.php [L,QSA]
147147
# Private APIs
148148
RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
149149
# Setup APIs

phpmyfaq/admin/comments.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

phpmyfaq/admin/header.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
'stickyRecordsHeader'
8181
);
8282
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delquestion', 'question', 'ad_menu_open');
83-
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delcomment', 'comments', 'ad_menu_comments');
83+
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delcomment', 'comments', 'ad_menu_comments', 'comments');
8484
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
8585
'addattachment+editattachment+delattachment',
8686
'attachments',
@@ -195,8 +195,6 @@
195195
case 'delete-news':
196196
case 'question':
197197
case 'takequestion':
198-
case 'comments':
199-
case 'attachments':
200198
case 'stickyfaqs':
201199
$contentPage = true;
202200
break;

phpmyfaq/admin/index.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@
270270
case 'question':
271271
require 'open-questions.php';
272272
break;
273-
case 'comments':
274-
require 'comments.php';
275-
break;
276273
case 'stickyfaqs':
277274
require 'stickyfaqs.php';
278275
break;
Lines changed: 109 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,120 @@
1-
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
2-
<h1 class="h2">
3-
<i aria-hidden="true" class="bi bi-chat-right-dots"></i>
4-
{{ 'adminHeaderComments' | translate }}
5-
</h1>
6-
</div>
1+
{% extends '@admin/index.twig' %}
72

8-
<div id="returnMessage"></div>
3+
{% block content %}
4+
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
5+
<h1 class="h2">
6+
<i aria-hidden="true" class="bi bi-chat-right-dots"></i>
7+
{{ 'adminHeaderComments' | translate }}
8+
</h1>
9+
</div>
910

10-
<ul class="nav nav-tabs" id="comments" role="tablist">
11-
<li class="nav-item" role="presentation">
12-
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#faqs-tab-pane" type="button"
13-
role="tab" aria-controls="home-tab-pane" aria-selected="true">
14-
{{ 'msgAdminCommentFaqs' | translate }}
15-
</button>
16-
</li>
17-
<li class="nav-item" role="presentation">
18-
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#news-tab-pane" type="button"
19-
role="tab" aria-controls="news-tab-pane" aria-selected="false">
20-
{{ 'msgAdminCommentNews' | translate }}
21-
</button>
22-
</li>
23-
</ul>
24-
<div class="tab-content" id="commentsContent">
25-
<div class="tab-pane fade show active mt-2" id="faqs-tab-pane" role="tabpanel" aria-labelledby="faqs-tab" tabindex="0">
26-
<form id="pmf-comments-selected-faq" name="pmf-comments-selected-faq" method="post" accept-charset="utf-8">
27-
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">
11+
<div id="returnMessage"></div>
2812

29-
<table class="table table-striped border align-middle">
30-
{% for comment in faqComments %}
31-
<tr id="comments_{{ comment.id }}">
32-
<td>
33-
<label>
34-
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
35-
value="{{ comment.id }}">
36-
</label>
37-
</td>
38-
<td>
39-
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
40-
<div class="border-end pe-3 me-3 mb-2">
41-
<i aria-hidden="true" class="bi bi-person"></i>
42-
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
43-
</div>
44-
<div class="d-flex mb-2">
45-
<div class="d-flex border-end align-items-center pe-3 me-3">
46-
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
47-
{{ comment.date | format_datetime(locale=currentLocale) }}
48-
</div>
49-
<div class="d-flex align-items-center me-3">
50-
<i aria-hidden="true" class="bi bi-chat-dots me-1"></i>
51-
<a href="../?action=faq&cat={{ comment.categoryId }}&id={{ comment.recordId }}&artlang={{ currentLocale }}">
52-
{{ comment.recordId | faqQuestion | raw }}
53-
</a>
13+
<ul class="nav nav-tabs" id="comments" role="tablist">
14+
<li class="nav-item" role="presentation">
15+
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#faqs-tab-pane" type="button"
16+
role="tab" aria-controls="home-tab-pane" aria-selected="true">
17+
{{ 'msgAdminCommentFaqs' | translate }}
18+
</button>
19+
</li>
20+
<li class="nav-item" role="presentation">
21+
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#news-tab-pane" type="button"
22+
role="tab" aria-controls="news-tab-pane" aria-selected="false">
23+
{{ 'msgAdminCommentNews' | translate }}
24+
</button>
25+
</li>
26+
</ul>
27+
<div class="tab-content" id="commentsContent">
28+
<div class="tab-pane fade show active mt-2" id="faqs-tab-pane" role="tabpanel" aria-labelledby="faqs-tab"
29+
tabindex="0">
30+
<form id="pmf-comments-selected-faq" name="pmf-comments-selected-faq" method="post" accept-charset="utf-8">
31+
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">
32+
33+
<table class="table table-striped border align-middle">
34+
{% for comment in faqComments %}
35+
<tr id="comments_{{ comment.id }}">
36+
<td>
37+
<label>
38+
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
39+
value="{{ comment.id }}">
40+
</label>
41+
</td>
42+
<td>
43+
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
44+
<div class="border-end pe-3 me-3 mb-2">
45+
<i aria-hidden="true" class="bi bi-person"></i>
46+
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
47+
</div>
48+
<div class="d-flex mb-2">
49+
<div class="d-flex border-end align-items-center pe-3 me-3">
50+
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
51+
{{ comment.date | format_datetime(locale=currentLocale) }}
52+
</div>
53+
<div class="d-flex align-items-center me-3">
54+
<i aria-hidden="true" class="bi bi-chat-dots me-1"></i>
55+
<a
56+
href="../?action=faq&cat={{ comment.categoryId }}&id={{ comment.recordId }}&artlang={{ currentLocale }}">
57+
{{ comment.recordId | faqQuestion | raw }}
58+
</a>
59+
</div>
60+
</div>
5461
</div>
55-
</div>
56-
</div>
57-
{{ comment.comment }}
58-
</td>
59-
</tr>
60-
{% endfor %}
61-
</table>
62+
{{ comment.comment | striptags }}
63+
</td>
64+
</tr>
65+
{% endfor %}
66+
</table>
6267

63-
</form>
64-
<div class="text-end">
65-
<button class="btn btn-danger" id="pmf-button-delete-faq-comments" type="button">
66-
{{ 'msgDelete' | translate }}
67-
</button>
68+
</form>
69+
<div class="text-end">
70+
<button class="btn btn-danger" id="pmf-button-delete-faq-comments" type="button">
71+
{{ 'msgDelete' | translate }}
72+
</button>
73+
</div>
6874
</div>
69-
</div>
70-
<div class="tab-pane fade mt-2" id="news-tab-pane" role="tabpanel" aria-labelledby="news-tab" tabindex="0">
71-
<form id="pmf-comments-selected-news" name="pmf-comments-selected-news" method="post" accept-charset="utf-8">
72-
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">
75+
<div class="tab-pane fade mt-2" id="news-tab-pane" role="tabpanel" aria-labelledby="news-tab" tabindex="0">
76+
<form id="pmf-comments-selected-news" name="pmf-comments-selected-news" method="post" accept-charset="utf-8">
77+
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">
7378

74-
<table class="table table-striped border align-middle">
75-
{% for comment in newsComments %}
76-
<tr id="comments_{{ comment.id }}">
77-
<td>
78-
<label>
79-
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
80-
value="{{ comment.id }}">
81-
</label>
82-
</td>
83-
<td>
84-
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
85-
<div class="border-end pe-3 me-3 mb-2">
86-
<i aria-hidden="true" class="bi bi-person"></i>
87-
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
88-
</div>
89-
<div class="d-flex mb-2">
90-
<div class="d-flex border-end align-items-center pe-3 me-3">
91-
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
92-
{{ comment.date | format_datetime(locale=currentLocale) }}
79+
<table class="table table-striped border align-middle">
80+
{% for comment in newsComments %}
81+
<tr id="comments_{{ comment.id }}">
82+
<td>
83+
<label>
84+
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
85+
value="{{ comment.id }}">
86+
</label>
87+
</td>
88+
<td>
89+
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
90+
<div class="border-end pe-3 me-3 mb-2">
91+
<i aria-hidden="true" class="bi bi-person"></i>
92+
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
93+
</div>
94+
<div class="d-flex mb-2">
95+
<div class="d-flex border-end align-items-center pe-3 me-3">
96+
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
97+
{{ comment.date | format_datetime(locale=currentLocale) }}
98+
</div>
99+
<div class="d-flex align-items-center me-3">
100+
<a href="../?action=news&newsid={{ comment.recordId }}&artlang={{ currentLocale }}">
101+
<i class="bi bi-newspaper"></i>
102+
</a>
103+
</div>
104+
</div>
93105
</div>
94-
<div class="d-flex align-items-center me-3">
95-
<a href="../?action=news&newsid={{ comment.recordId }}&artlang={{ currentLocale }}">
96-
<i class="bi bi-newspaper"></i>
97-
</a>
98-
</div>
99-
</div>
100-
</div>
101-
{{ comment.comment }}
102-
</td>
103-
</tr>
104-
{% endfor %}
105-
</table>
106+
{{ comment.comment }}
107+
</td>
108+
</tr>
109+
{% endfor %}
110+
</table>
106111

107-
</form>
108-
<div class="text-end">
109-
<button class="btn btn-danger" id="pmf-button-delete-news-comments" type="button">
110-
{{ 'msgDelete' | translate }}
111-
</button>
112+
</form>
113+
<div class="text-end">
114+
<button class="btn btn-danger" id="pmf-button-delete-news-comments" type="button">
115+
{{ 'msgDelete' | translate }}
116+
</button>
117+
</div>
112118
</div>
113119
</div>
114-
</div>
120+
{% endblock %}

phpmyfaq/src/admin-routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpMyFAQ\Controller\Administration\AdminLogController;
1919
use phpMyFAQ\Controller\Administration\AttachmentsController;
2020
use phpMyFAQ\Controller\Administration\BackupController;
21+
use phpMyFAQ\Controller\Administration\CommentsController;
2122
use phpMyFAQ\Controller\Administration\ConfigurationController;
2223
use phpMyFAQ\Controller\Administration\ElasticsearchController;
2324
use phpMyFAQ\Controller\Administration\ExportController;
@@ -62,6 +63,11 @@
6263
'controller' => [BackupController::class, 'restore'],
6364
'methods' => 'POST'
6465
],
66+
'admin.comments' => [
67+
'path' => '/comments',
68+
'controller' => [CommentsController::class, 'index'],
69+
'methods' => 'GET'
70+
],
6571
'admin.configuration' => [
6672
'path' => '/configuration',
6773
'controller' => [ConfigurationController::class, 'index'],

phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,26 @@ protected function getHeader(Request $request): array
9696
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
9797
'delcomment',
9898
'comments',
99-
'ad_menu_comments'
99+
'ad_menu_comments',
100+
'comments'
100101
);
101102
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
102103
'addattachment+editattachment+delattachment',
103104
'attachments',
104-
'ad_menu_attachments'
105+
'ad_menu_attachments',
106+
'attachments'
105107
);
106108
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
107109
PermissionType::FAQ_EDIT->value,
108110
'tags',
109-
'ad_entry_tags'
111+
'ad_entry_tags',
112+
'tags'
110113
);
111114
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
112115
'addglossary+editglossary+delglossary',
113116
'glossary',
114-
'ad_menu_glossary'
117+
'ad_menu_glossary',
118+
'glossary'
115119
);
116120
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
117121
'addnews+editnews+delnews',
@@ -260,6 +264,7 @@ protected function getHeader(Request $request): array
260264
$userPage = true;
261265
break;
262266
case 'admin.attachments':
267+
case 'admin.comments':
263268
case 'admin.glossary':
264269
case 'admin.tags':
265270
$contentPage = true;

0 commit comments

Comments
 (0)