Skip to content

Commit 87392d8

Browse files
committed
refactor: migrated news page to controller (#3257)
1 parent a06db76 commit 87392d8

File tree

15 files changed

+519
-459
lines changed

15 files changed

+519
-459
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|comments|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|news|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|comments|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|news|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/assets/src/api/news.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @link https://www.phpmyfaq.de
1414
* @since 2024-04-21
1515
*/
16+
1617
import { pushErrorNotification, pushNotification } from '../utils';
1718

1819
export const addNews = async (data = {}) => {
@@ -32,7 +33,7 @@ export const addNews = async (data = {}) => {
3233
if (result.success) {
3334
pushNotification(result.success);
3435
setTimeout(function () {
35-
window.location.href = '?action=news';
36+
window.location.href = './news';
3637
}, 3000);
3738
} else {
3839
pushErrorNotification(result.error);
@@ -91,7 +92,7 @@ export const updateNews = async (data = {}) => {
9192
if (result.success) {
9293
pushNotification(result.success);
9394
setTimeout(function () {
94-
window.location.href = '?action=news';
95+
window.location.href = './news';
9596
}, 3000);
9697
} else {
9798
pushErrorNotification(result.error);

phpmyfaq/admin/header.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
103103
'addnews+editnews+delnews',
104104
'news',
105-
'ad_menu_news_edit'
105+
'ad_menu_news_edit',
106+
'news'
106107
);
107108

108109
$secLevelEntries['statistics'] = $adminHelper->addMenuEntry(
@@ -187,12 +188,6 @@
187188
case 'faqs-overview':
188189
case 'editentry':
189190
case 'copyentry':
190-
case 'news':
191-
case 'add-news':
192-
case 'edit-news':
193-
case 'save-news':
194-
case 'update-news':
195-
case 'delete-news':
196191
case 'question':
197192
case 'takequestion':
198193
case 'stickyfaqs':

phpmyfaq/admin/index.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,6 @@
273273
case 'stickyfaqs':
274274
require 'stickyfaqs.php';
275275
break;
276-
// news administration
277-
case 'news':
278-
case 'add-news':
279-
case 'edit-news':
280-
case 'save-news':
281-
case 'update-news':
282-
case 'delete-news':
283-
require 'news.php';
284-
break;
285276
// category administration
286277
case 'savecategory':
287278
case 'updatecategory':

phpmyfaq/admin/news.php

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

phpmyfaq/admin/open-questions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
$templateVars = [
6969
'msgOpenQuestions' => Translation::get('msgOpenQuestions'),
70-
'csrfTokenDeleteQuestion' => Token::getInstance()->getTokenString('delete-questions'),
70+
'csrfTokenDeleteQuestion' => Token::getInstance($container->get('session'))->getTokenString('delete-questions'),
7171
'currentLocale' => $faqConfig->getLanguage()->getLanguage(),
7272
'msgAuthor' => Translation::get('ad_entry_author'),
7373
'msgQuestion' => Translation::get('ad_entry_theme'),
@@ -78,7 +78,7 @@
7878
'enableCloseQuestion' => $faqConfig->get('records.enableCloseQuestion'),
7979
'msg2answerFAQ' => Translation::get('msg2answerFAQ'),
8080
'msgTakeQuestion' => Translation::get('ad_ques_take'),
81-
'csrfTokenToggleVisibility' => Token::getInstance()->getTokenString('toggle-question-visibility'),
81+
'csrfTokenToggleVisibility' => Token::getInstance($container->get('session'))->getTokenString('toggle-question-visibility'),
8282
'msgDeleteAllOpenQuestions' => Translation::get('msgDelete'),
8383
];
8484

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{% extends '@admin/index.twig' %}
2+
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-pencil"></i>
7+
{{ ad_news_add }}
8+
</h1>
9+
</div>
10+
11+
<div class="row">
12+
<div class="col-12">
13+
<form id="faqEditor" name="faqEditor" novalidate
14+
data-pmf-enable-editor="{{ enableWysiwyg }}"
15+
data-pmf-editor-language="en"
16+
data-pmf-default-url="{{ defaultUrl }}">
17+
<input type="hidden" name="pmf-csrf-token" id="pmf-csrf-token" value="{{ csrfToken_saveNews }}" />
18+
19+
<div class="row mb-2">
20+
<label class="col-3 col-form-label" for="newsheader">
21+
{{ ad_news_header }}
22+
</label>
23+
<div class="col-9">
24+
<input class="form-control" type="text" name="newsheader" id="newsheader">
25+
</div>
26+
</div>
27+
28+
<div class="row mb-2">
29+
<label class="col-3 col-form-label" for="news">{{ ad_news_text }}:</label>
30+
<div class="col-9">
31+
<textarea rows="5" class="form-control" id="editor"></textarea>
32+
</div>
33+
</div>
34+
35+
<div class="row mb-2">
36+
<label class="col-3 col-form-label" for="authorName">
37+
{{ ad_news_author_name }}
38+
</label>
39+
<div class="col-9">
40+
<input class="form-control" type="text" name="authorName" id="authorName"
41+
value="{{ userName }}">
42+
</div>
43+
</div>
44+
45+
<div class="row mb-2">
46+
<label class="col-3 col-form-label" for="authorEmail">
47+
{{ ad_news_author_email }}
48+
</label>
49+
<div class="col-9">
50+
<input class="form-control" type="email" name="authorEmail" id="authorEmail"
51+
value="{{ userEmail }}">
52+
</div>
53+
</div>
54+
55+
<div class="row mb-2">
56+
<div class="offset-3 col-9">
57+
<div class="form-check">
58+
<input class="form-check-input" type="checkbox" value="y" id="active" name="active">
59+
<label class="form-check-label" for="active">
60+
{{ ad_news_set_active }}
61+
</label>
62+
</div>
63+
<div class="form-check">
64+
<input class="form-check-input" type="checkbox" value="y" id="comment" name="comment">
65+
<label class="form-check-label" for="comment">
66+
{{ ad_news_allowComments }}
67+
</label>
68+
</div>
69+
</div>
70+
</div>
71+
72+
<div class="row mb-2">
73+
<label class="col-3 col-form-label" for="link">
74+
{{ ad_news_link_url }}
75+
</label>
76+
<div class="col-9">
77+
<input class="form-control" type="text" name="link" id="link"
78+
placeholder="https://www.example.com/">
79+
</div>
80+
</div>
81+
82+
<div class="row mb-2">
83+
<label class="col-3 col-form-label" for="linkTitle">
84+
{{ ad_news_link_title }}
85+
</label>
86+
<div class="col-9">
87+
<input type="text" name="linkTitle" id="linkTitle" class="form-control">
88+
</div>
89+
</div>
90+
91+
<div class="row mb-2">
92+
<label class="col-3 col-form-label">{{ ad_news_link_target }}</label>
93+
<div class="col-9 radio">
94+
<div class="form-check">
95+
<input class="form-check-input" type="radio" id="target" value="blank">
96+
<label class="form-check-label" for="blank">
97+
{{ ad_news_link_window }}
98+
</label>
99+
</div>
100+
<div class="form-check">
101+
<input class="form-check-input" type="radio" id="target" value="self">
102+
<label class="form-check-label" for="self">
103+
{{ ad_news_link_faq }}
104+
</label>
105+
</div>
106+
<div class="form-check">
107+
<input class="form-check-input" type="radio" id="target" value="parent">
108+
<label class="form-check-label" for="parent">
109+
{{ ad_news_link_parent }}
110+
</label>
111+
</div>
112+
</div>
113+
</div>
114+
115+
<div class="row mb-2">
116+
<label class="col-3 col-form-label" for="langTo">{{ ad_entry_locale }}:</label>
117+
<div class="col-9">
118+
{{ selectLanguage|raw }}
119+
</div>
120+
</div>
121+
122+
<div class="row my-4">
123+
<div class="col-12 text-end">
124+
<a class="btn btn-secondary" href="./news">
125+
{{ ad_entry_back }}
126+
</a>
127+
<a class="btn btn-primary" id="submitAddNews">
128+
{{ ad_news_add }}
129+
</a>
130+
</div>
131+
</div>
132+
</form>
133+
</div>
134+
</div>
135+
{% endblock %}

0 commit comments

Comments
 (0)