Skip to content

Commit

Permalink
refactor: migrated news 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 a06db76 commit 87392d8
Show file tree
Hide file tree
Showing 15 changed files with 519 additions and 459 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|comments|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|news|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|comments|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|news|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
5 changes: 3 additions & 2 deletions phpmyfaq/admin/assets/src/api/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @link https://www.phpmyfaq.de
* @since 2024-04-21
*/

import { pushErrorNotification, pushNotification } from '../utils';

export const addNews = async (data = {}) => {
Expand All @@ -32,7 +33,7 @@ export const addNews = async (data = {}) => {
if (result.success) {
pushNotification(result.success);
setTimeout(function () {
window.location.href = '?action=news';
window.location.href = './news';
}, 3000);
} else {
pushErrorNotification(result.error);
Expand Down Expand Up @@ -91,7 +92,7 @@ export const updateNews = async (data = {}) => {
if (result.success) {
pushNotification(result.success);
setTimeout(function () {
window.location.href = '?action=news';
window.location.href = './news';
}, 3000);
} else {
pushErrorNotification(result.error);
Expand Down
9 changes: 2 additions & 7 deletions phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addnews+editnews+delnews',
'news',
'ad_menu_news_edit'
'ad_menu_news_edit',
'news'
);

$secLevelEntries['statistics'] = $adminHelper->addMenuEntry(
Expand Down Expand Up @@ -187,12 +188,6 @@
case 'faqs-overview':
case 'editentry':
case 'copyentry':
case 'news':
case 'add-news':
case 'edit-news':
case 'save-news':
case 'update-news':
case 'delete-news':
case 'question':
case 'takequestion':
case 'stickyfaqs':
Expand Down
9 changes: 0 additions & 9 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,6 @@
case 'stickyfaqs':
require 'stickyfaqs.php';
break;
// news administration
case 'news':
case 'add-news':
case 'edit-news':
case 'save-news':
case 'update-news':
case 'delete-news':
require 'news.php';
break;
// category administration
case 'savecategory':
case 'updatecategory':
Expand Down
133 changes: 0 additions & 133 deletions phpmyfaq/admin/news.php

This file was deleted.

4 changes: 2 additions & 2 deletions phpmyfaq/admin/open-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

$templateVars = [
'msgOpenQuestions' => Translation::get('msgOpenQuestions'),
'csrfTokenDeleteQuestion' => Token::getInstance()->getTokenString('delete-questions'),
'csrfTokenDeleteQuestion' => Token::getInstance($container->get('session'))->getTokenString('delete-questions'),
'currentLocale' => $faqConfig->getLanguage()->getLanguage(),
'msgAuthor' => Translation::get('ad_entry_author'),
'msgQuestion' => Translation::get('ad_entry_theme'),
Expand All @@ -78,7 +78,7 @@
'enableCloseQuestion' => $faqConfig->get('records.enableCloseQuestion'),
'msg2answerFAQ' => Translation::get('msg2answerFAQ'),
'msgTakeQuestion' => Translation::get('ad_ques_take'),
'csrfTokenToggleVisibility' => Token::getInstance()->getTokenString('toggle-question-visibility'),
'csrfTokenToggleVisibility' => Token::getInstance($container->get('session'))->getTokenString('toggle-question-visibility'),
'msgDeleteAllOpenQuestions' => Translation::get('msgDelete'),
];

Expand Down
135 changes: 135 additions & 0 deletions phpmyfaq/assets/templates/admin/content/news.add.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{% extends '@admin/index.twig' %}

{% 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-pencil"></i>
{{ ad_news_add }}
</h1>
</div>

<div class="row">
<div class="col-12">
<form id="faqEditor" name="faqEditor" novalidate
data-pmf-enable-editor="{{ enableWysiwyg }}"
data-pmf-editor-language="en"
data-pmf-default-url="{{ defaultUrl }}">
<input type="hidden" name="pmf-csrf-token" id="pmf-csrf-token" value="{{ csrfToken_saveNews }}" />

<div class="row mb-2">
<label class="col-3 col-form-label" for="newsheader">
{{ ad_news_header }}
</label>
<div class="col-9">
<input class="form-control" type="text" name="newsheader" id="newsheader">
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label" for="news">{{ ad_news_text }}:</label>
<div class="col-9">
<textarea rows="5" class="form-control" id="editor"></textarea>
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label" for="authorName">
{{ ad_news_author_name }}
</label>
<div class="col-9">
<input class="form-control" type="text" name="authorName" id="authorName"
value="{{ userName }}">
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label" for="authorEmail">
{{ ad_news_author_email }}
</label>
<div class="col-9">
<input class="form-control" type="email" name="authorEmail" id="authorEmail"
value="{{ userEmail }}">
</div>
</div>

<div class="row mb-2">
<div class="offset-3 col-9">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="y" id="active" name="active">
<label class="form-check-label" for="active">
{{ ad_news_set_active }}
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="y" id="comment" name="comment">
<label class="form-check-label" for="comment">
{{ ad_news_allowComments }}
</label>
</div>
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label" for="link">
{{ ad_news_link_url }}
</label>
<div class="col-9">
<input class="form-control" type="text" name="link" id="link"
placeholder="https://www.example.com/">
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label" for="linkTitle">
{{ ad_news_link_title }}
</label>
<div class="col-9">
<input type="text" name="linkTitle" id="linkTitle" class="form-control">
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label">{{ ad_news_link_target }}</label>
<div class="col-9 radio">
<div class="form-check">
<input class="form-check-input" type="radio" id="target" value="blank">
<label class="form-check-label" for="blank">
{{ ad_news_link_window }}
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" id="target" value="self">
<label class="form-check-label" for="self">
{{ ad_news_link_faq }}
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" id="target" value="parent">
<label class="form-check-label" for="parent">
{{ ad_news_link_parent }}
</label>
</div>
</div>
</div>

<div class="row mb-2">
<label class="col-3 col-form-label" for="langTo">{{ ad_entry_locale }}:</label>
<div class="col-9">
{{ selectLanguage|raw }}
</div>
</div>

<div class="row my-4">
<div class="col-12 text-end">
<a class="btn btn-secondary" href="./news">
{{ ad_entry_back }}
</a>
<a class="btn btn-primary" id="submitAddNews">
{{ ad_news_add }}
</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %}
Loading

0 comments on commit 87392d8

Please sign in to comment.