Skip to content

Commit

Permalink
refactor: migrated comments page to controller (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Dec 1, 2024
1 parent 0e2fe6b commit a06db76
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 177 deletions.
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ server {
rewrite admin/api/(.*) /admin/api/index.php last;

# Administration pages
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;
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;

# REST API v3.0 and v3.1
rewrite ^api/v3\.[01]/(.*) /api/index.php last;
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
# Administration API
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
# Administration pages
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]
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]
# Private APIs
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]
# Setup APIs
Expand Down
62 changes: 0 additions & 62 deletions phpmyfaq/admin/comments.php

This file was deleted.

4 changes: 1 addition & 3 deletions phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
'stickyRecordsHeader'
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delquestion', 'question', 'ad_menu_open');
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delcomment', 'comments', 'ad_menu_comments');
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delcomment', 'comments', 'ad_menu_comments', 'comments');
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addattachment+editattachment+delattachment',
'attachments',
Expand Down Expand Up @@ -195,8 +195,6 @@
case 'delete-news':
case 'question':
case 'takequestion':
case 'comments':
case 'attachments':
case 'stickyfaqs':
$contentPage = true;
break;
Expand Down
3 changes: 0 additions & 3 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@
case 'question':
require 'open-questions.php';
break;
case 'comments':
require 'comments.php';
break;
case 'stickyfaqs':
require 'stickyfaqs.php';
break;
Expand Down
212 changes: 109 additions & 103 deletions phpmyfaq/assets/templates/admin/content/comments.twig
Original file line number Diff line number Diff line change
@@ -1,114 +1,120 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">
<i aria-hidden="true" class="bi bi-chat-right-dots"></i>
{{ 'adminHeaderComments' | translate }}
</h1>
</div>
{% extends '@admin/index.twig' %}

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

<ul class="nav nav-tabs" id="comments" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#faqs-tab-pane" type="button"
role="tab" aria-controls="home-tab-pane" aria-selected="true">
{{ 'msgAdminCommentFaqs' | translate }}
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#news-tab-pane" type="button"
role="tab" aria-controls="news-tab-pane" aria-selected="false">
{{ 'msgAdminCommentNews' | translate }}
</button>
</li>
</ul>
<div class="tab-content" id="commentsContent">
<div class="tab-pane fade show active mt-2" id="faqs-tab-pane" role="tabpanel" aria-labelledby="faqs-tab" tabindex="0">
<form id="pmf-comments-selected-faq" name="pmf-comments-selected-faq" method="post" accept-charset="utf-8">
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">
<div id="returnMessage"></div>

<table class="table table-striped border align-middle">
{% for comment in faqComments %}
<tr id="comments_{{ comment.id }}">
<td>
<label>
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
value="{{ comment.id }}">
</label>
</td>
<td>
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
<div class="border-end pe-3 me-3 mb-2">
<i aria-hidden="true" class="bi bi-person"></i>
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
</div>
<div class="d-flex mb-2">
<div class="d-flex border-end align-items-center pe-3 me-3">
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
{{ comment.date | format_datetime(locale=currentLocale) }}
</div>
<div class="d-flex align-items-center me-3">
<i aria-hidden="true" class="bi bi-chat-dots me-1"></i>
<a href="../?action=faq&cat={{ comment.categoryId }}&id={{ comment.recordId }}&artlang={{ currentLocale }}">
{{ comment.recordId | faqQuestion | raw }}
</a>
<ul class="nav nav-tabs" id="comments" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#faqs-tab-pane" type="button"
role="tab" aria-controls="home-tab-pane" aria-selected="true">
{{ 'msgAdminCommentFaqs' | translate }}
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#news-tab-pane" type="button"
role="tab" aria-controls="news-tab-pane" aria-selected="false">
{{ 'msgAdminCommentNews' | translate }}
</button>
</li>
</ul>
<div class="tab-content" id="commentsContent">
<div class="tab-pane fade show active mt-2" id="faqs-tab-pane" role="tabpanel" aria-labelledby="faqs-tab"
tabindex="0">
<form id="pmf-comments-selected-faq" name="pmf-comments-selected-faq" method="post" accept-charset="utf-8">
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">

<table class="table table-striped border align-middle">
{% for comment in faqComments %}
<tr id="comments_{{ comment.id }}">
<td>
<label>
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
value="{{ comment.id }}">
</label>
</td>
<td>
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
<div class="border-end pe-3 me-3 mb-2">
<i aria-hidden="true" class="bi bi-person"></i>
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
</div>
<div class="d-flex mb-2">
<div class="d-flex border-end align-items-center pe-3 me-3">
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
{{ comment.date | format_datetime(locale=currentLocale) }}
</div>
<div class="d-flex align-items-center me-3">
<i aria-hidden="true" class="bi bi-chat-dots me-1"></i>
<a
href="../?action=faq&cat={{ comment.categoryId }}&id={{ comment.recordId }}&artlang={{ currentLocale }}">
{{ comment.recordId | faqQuestion | raw }}
</a>
</div>
</div>
</div>
</div>
</div>
{{ comment.comment }}
</td>
</tr>
{% endfor %}
</table>
{{ comment.comment | striptags }}
</td>
</tr>
{% endfor %}
</table>

</form>
<div class="text-end">
<button class="btn btn-danger" id="pmf-button-delete-faq-comments" type="button">
{{ 'msgDelete' | translate }}
</button>
</form>
<div class="text-end">
<button class="btn btn-danger" id="pmf-button-delete-faq-comments" type="button">
{{ 'msgDelete' | translate }}
</button>
</div>
</div>
</div>
<div class="tab-pane fade mt-2" id="news-tab-pane" role="tabpanel" aria-labelledby="news-tab" tabindex="0">
<form id="pmf-comments-selected-news" name="pmf-comments-selected-news" method="post" accept-charset="utf-8">
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">
<div class="tab-pane fade mt-2" id="news-tab-pane" role="tabpanel" aria-labelledby="news-tab" tabindex="0">
<form id="pmf-comments-selected-news" name="pmf-comments-selected-news" method="post" accept-charset="utf-8">
<input type="hidden" id="pmf-csrf-token" name="pmf-csrf-token" value="{{ csrfToken }}">

<table class="table table-striped border align-middle">
{% for comment in newsComments %}
<tr id="comments_{{ comment.id }}">
<td>
<label>
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
value="{{ comment.id }}">
</label>
</td>
<td>
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
<div class="border-end pe-3 me-3 mb-2">
<i aria-hidden="true" class="bi bi-person"></i>
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
</div>
<div class="d-flex mb-2">
<div class="d-flex border-end align-items-center pe-3 me-3">
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
{{ comment.date | format_datetime(locale=currentLocale) }}
<table class="table table-striped border align-middle">
{% for comment in newsComments %}
<tr id="comments_{{ comment.id }}">
<td>
<label>
<input type="checkbox" class="form-check-input" id="comments[]" name="comments[]"
value="{{ comment.id }}">
</label>
</td>
<td>
<div class="d-flex align-items-center flex-wrap text-muted mb-md-0 mb-4 small">
<div class="border-end pe-3 me-3 mb-2">
<i aria-hidden="true" class="bi bi-person"></i>
<a href="mailto:{{ comment.email }}">{{ comment.username }}</a>
</div>
<div class="d-flex mb-2">
<div class="d-flex border-end align-items-center pe-3 me-3">
<i aria-hidden="true" class="bi bi-calendar-date me-1"></i>
{{ comment.date | format_datetime(locale=currentLocale) }}
</div>
<div class="d-flex align-items-center me-3">
<a href="../?action=news&newsid={{ comment.recordId }}&artlang={{ currentLocale }}">
<i class="bi bi-newspaper"></i>
</a>
</div>
</div>
</div>
<div class="d-flex align-items-center me-3">
<a href="../?action=news&newsid={{ comment.recordId }}&artlang={{ currentLocale }}">
<i class="bi bi-newspaper"></i>
</a>
</div>
</div>
</div>
{{ comment.comment }}
</td>
</tr>
{% endfor %}
</table>
{{ comment.comment }}
</td>
</tr>
{% endfor %}
</table>

</form>
<div class="text-end">
<button class="btn btn-danger" id="pmf-button-delete-news-comments" type="button">
{{ 'msgDelete' | translate }}
</button>
</form>
<div class="text-end">
<button class="btn btn-danger" id="pmf-button-delete-news-comments" type="button">
{{ 'msgDelete' | translate }}
</button>
</div>
</div>
</div>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions phpmyfaq/src/admin-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use phpMyFAQ\Controller\Administration\AdminLogController;
use phpMyFAQ\Controller\Administration\AttachmentsController;
use phpMyFAQ\Controller\Administration\BackupController;
use phpMyFAQ\Controller\Administration\CommentsController;
use phpMyFAQ\Controller\Administration\ConfigurationController;
use phpMyFAQ\Controller\Administration\ElasticsearchController;
use phpMyFAQ\Controller\Administration\ExportController;
Expand Down Expand Up @@ -62,6 +63,11 @@
'controller' => [BackupController::class, 'restore'],
'methods' => 'POST'
],
'admin.comments' => [
'path' => '/comments',
'controller' => [CommentsController::class, 'index'],
'methods' => 'GET'
],
'admin.configuration' => [
'path' => '/configuration',
'controller' => [ConfigurationController::class, 'index'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,26 @@ protected function getHeader(Request $request): array
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'delcomment',
'comments',
'ad_menu_comments'
'ad_menu_comments',
'comments'
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addattachment+editattachment+delattachment',
'attachments',
'ad_menu_attachments'
'ad_menu_attachments',
'attachments'
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
PermissionType::FAQ_EDIT->value,
'tags',
'ad_entry_tags'
'ad_entry_tags',
'tags'
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addglossary+editglossary+delglossary',
'glossary',
'ad_menu_glossary'
'ad_menu_glossary',
'glossary'
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addnews+editnews+delnews',
Expand Down Expand Up @@ -260,6 +264,7 @@ protected function getHeader(Request $request): array
$userPage = true;
break;
case 'admin.attachments':
case 'admin.comments':
case 'admin.glossary':
case 'admin.tags':
$contentPage = true;
Expand Down
Loading

0 comments on commit a06db76

Please sign in to comment.