Skip to content

Commit 2e18856

Browse files
committed
feat: added cancel buttons, improved error page when database is offline
1 parent 0dd2114 commit 2e18856

File tree

10 files changed

+24
-14
lines changed

10 files changed

+24
-14
lines changed

phpmyfaq/add.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* This is the page there a user can add a FAQ record.
4+
* This is the page where a user can add a FAQ record.
55
*
66
* This Source Code Form is subject to the terms of the Mozilla Public License,
77
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
@@ -74,7 +74,8 @@
7474
$readonly = ' readonly';
7575
}
7676

77-
// Display full form even if user switched off single fields because of use together with answering open questions
77+
// Display full form even if the user switched off single fields because of use together with answering open
78+
// questions
7879
$displayFullForm = true;
7980
}
8081

@@ -90,7 +91,7 @@
9091
$categories = $category->getAllCategoryIds();
9192

9293
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/');
93-
$twig->addFilter(new TwigFilter('repeat', fn($string, $times) => str_repeat((string) $string, $times)));
94+
$twig->addFilter(new TwigFilter('repeat', fn($string, $times): string => str_repeat((string) $string, $times)));
9495
$twigTemplate = $twig->loadTemplate('./add.twig');
9596

9697
// Twig template variables

phpmyfaq/ask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
$categories = $category->getAllCategoryIds();
6363

6464
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/');
65-
$twig->addFilter(new TwigFilter('repeat', fn($string, $times) => str_repeat((string) $string, $times)));
65+
$twig->addFilter(new TwigFilter('repeat', fn($string, $times): string => str_repeat((string) $string, $times)));
6666
$twigTemplate = $twig->loadTemplate('./ask.twig');
6767

6868
$templateVars = [

phpmyfaq/assets/templates/admin/content/category.add.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@
190190

191191
<div class="row mb-2">
192192
<div class="offset-lg-2 col-lg-4 text-end">
193+
<a class="btn btn-secondary" href="./category">
194+
{{ buttonCancel }}
195+
</a>
193196
<button class="btn btn-primary" type="submit" name="submit">
194197
{{ ad_categ_add }}
195198
</button>

phpmyfaq/assets/templates/admin/content/category.edit.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@
184184

185185
<div class="row mb-2">
186186
<div class="offset-lg-2 col-lg-4 text-end">
187+
<a class="btn btn-secondary" href="./category">
188+
{{ buttonCancel }}
189+
</a>
187190
<button class="btn btn-primary" type="submit" name="submit">
188191
{{ buttonUpdate }}
189192
</button>

phpmyfaq/search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
}
143143
}
144144

145-
uasort($relatedTags, static fn($a, $b) => $b - $a);
145+
uasort($relatedTags, static fn($a, $b): int => $b - $a);
146146
$numTags = 0;
147147

148148
foreach ($relatedTags as $tagId => $relevance) {
@@ -274,7 +274,7 @@
274274

275275
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/');
276276
$twig->addExtension(new AttributeExtension(TagNameTwigExtension::class));
277-
$twig->addFilter(new TwigFilter('repeat', fn($string, $times) => str_repeat((string) $string, $times)));
277+
$twig->addFilter(new TwigFilter('repeat', fn($string, $times): string => str_repeat((string) $string, $times)));
278278
$twigTemplate = $twig->loadTemplate('./search.twig');
279279

280280
$pageHeader = ($tagSearch ? Translation::get('msgTagSearch') : Translation::get('msgAdvancedSearch'));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ private function getBaseTemplateVars(): array
754754
'ad_entry_restricted_groups' => Translation::get('ad_entry_restricted_groups'),
755755
'restricted_groups' => ($this->configuration->get('security.permLevel') === 'medium') ?
756756
$this->currentUser->perm->getAllGroupsOptions([], $this->currentUser) : '',
757+
'buttonCancel' => Translation::get('ad_gen_cancel'),
757758
];
758759
}
759760
}

phpmyfaq/src/phpMyFAQ/Database.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ public static function errorPage(string $method): void
103103
<head>
104104
<meta charset="utf-8">
105105
<title>Fatal phpMyFAQ Error</title>
106-
<link href="assets/dist/styles.css" rel="stylesheet">
107-
<script src="assets/dist/frontend.js"></script>
106+
<link href="assets/public/styles.css" rel="stylesheet">
107+
<script src="assets/public/frontend.js"></script>
108108
</head>
109109
<body>
110-
<div class="container mt-5">
111-
<p class="alert alert-danger">The connection to the database server could not be established.</p>
112-
<p class="alert alert-danger">The error message of the database server: ' . $method . '</p>
110+
<div class="container">
111+
<h1 class="pt-5">Fatal phpMyFAQ Error</h1>
112+
<p class="alert alert-danger mt-5">The connection to the database server could not be established.</p>
113+
<p class="alert alert-info p-2">The error message of the database server: ' . $method . '</p>
113114
</div>
114115
</body>
115116
</html>';

phpmyfaq/src/phpMyFAQ/Export/Pdf/Wrapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ public function convertExternalImagesToBase64(string $html): string
637637
if ($allowedHost === '') {
638638
continue;
639639
}
640+
640641
if ($allowedHost === '0') {
641642
continue;
642643
}

phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function cleanUpContent(string $content): string
179179
return preg_replace_callback(
180180
'/style\s*=\s*"([^"]*)"/i',
181181
function (array $matches): string {
182-
$styles = explode(';', (string) $matches[1]);
182+
$styles = explode(';', $matches[1]);
183183
$filteredStyles = array_filter($styles, function (string $style): bool {
184184
return stripos(trim($style), 'overflow:') !== 0; // Exclude 'overflow' properties
185185
});

tests/phpMyFAQ/DatabaseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public function testErrorPage(): void
6969
$output
7070
);
7171
$this->assertStringContainsString(
72-
'<p class="alert alert-danger">The connection to the database server could not be established.</p>',
72+
'<p class="alert alert-danger mt-5">The connection to the database server could not be established.</p>',
7373
$output
7474
);
7575
$this->assertStringContainsString(
76-
'<p class="alert alert-danger">The error message of the database server: Error message</p>',
76+
'<p class="alert alert-info p-2">The error message of the database server: Error message</p>',
7777
$output
7878
);
7979
}

0 commit comments

Comments
 (0)