Skip to content

Commit

Permalink
refactor: improved translation key
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Nov 24, 2024
1 parent 546bb8e commit 5b4d031
Show file tree
Hide file tree
Showing 66 changed files with 138 additions and 144 deletions.
2 changes: 1 addition & 1 deletion phpmyfaq/admin/media.browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
$templateVars = [
'metaLanguage' => Translation::get('metaLanguage'),
'notAuthenticated' => !$user->isLoggedIn(),
'msgNotAuthenticated' => Translation::get('err_NotAuth'),
'msgNotAuthenticated' => Translation::get('msgNoPermission'),
'msgMediaSearch' => Translation::get('ad_media_name_search'),
'isImageDirectoryMissing' => !is_dir(PMF_CONTENT_DIR . '/user/images'),
'msgImageDirectoryMissing' => sprintf(Translation::get('ad_dir_missing'), '/images'),
Expand Down
8 changes: 1 addition & 7 deletions phpmyfaq/admin/no-permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
*/

use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$template = $twig->loadTemplate('@admin/no-permission.twig');

echo $template->render(
[
'adminHeaderNoPermission' => Translation::get('ad_entryins_fail'),
'msgNoPermission' => Translation::get('err_NotAuth')
]
);
echo $template->render();
4 changes: 2 additions & 2 deletions phpmyfaq/assets/templates/admin/no-permission.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<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-exclamation-triangle"></i>
{{ adminHeaderNoPermission }}
{{ 'msgErrorOccurred' | translate }}
</h1>
</div>

<p class="alert alert-danger">
{{ msgNoPermission }}
{{ 'msgNoPermission' | translate }}
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function delete(Request $request): JsonResponse
!Token::getInstance($this->container->get('session'))
->verifyToken('delete-attachment', $deleteData->csrf)
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$attachment = AttachmentFactory::create($deleteData->attId);
Expand Down Expand Up @@ -75,7 +75,7 @@ public function refresh(Request $request): JsonResponse
!Token::getInstance($this->container->get('session'))
->verifyToken('refresh-attachment', $dataToCheck->csrf)
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$attachment = AttachmentFactory::create($dataToCheck->attId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function delete(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance($this->container->get('session'))->verifyToken('category', $data->csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

[ $currentAdminUser, $currentAdminGroups ] = CurrentUser::getCurrentUserGroupId($currentUser);
Expand Down Expand Up @@ -151,7 +151,7 @@ public function updateOrder(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance($this->container->get('session'))->verifyToken('category', $data->csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$user = CurrentUser::getCurrentUser($this->configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function delete(Request $request): JsonResponse
!Token::getInstance($this->container->get('session'))
->verifyToken('delete-comment', $data->data->{'pmf-csrf-token'})
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$comments = new Comments($this->configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function sendTestMail(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance($this->container->get('session'))->verifyToken('configuration', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function save(Request $request): JsonResponse
$oldConfigurationData = $this->configuration->getAll();

if (!Token::getInstance($this->container->get('session'))->verifyToken('configuration', $csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
} else {
// Set the new values
$newConfigValues = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function exportReport(Request $request): Response
!Token::getInstance($this->container->get('session'))
->verifyToken('create-report', $data->{'pmf-csrf-token'})
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$text = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function create(Request $request): JsonResponse
$data = json_decode($request->getContent())->data;

if (!Token::getInstance($this->container->get('session'))->verifyToken('edit-faq', $data->{'pmf-csrf-token'})) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

// Collect FAQ data
Expand Down Expand Up @@ -279,7 +279,7 @@ public function update(Request $request): JsonResponse
$data = json_decode($request->getContent())->data;

if (!Token::getInstance()->verifyToken('edit-faq', $data->{'pmf-csrf-token'})) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

// Collect FAQ data
Expand Down Expand Up @@ -505,7 +505,7 @@ public function activate(Request $request): JsonResponse
$checked = Filter::filterVar($data->checked, FILTER_VALIDATE_BOOLEAN);

if (!Token::getInstance()->verifyToken('faq-overview', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

if (!($faqIds === false || $faqIds === [] || $faqIds === null)) {
Expand Down Expand Up @@ -543,7 +543,7 @@ public function sticky(Request $request): JsonResponse
$checked = Filter::filterVar($data->checked, FILTER_VALIDATE_BOOLEAN);

if (!Token::getInstance()->verifyToken('faq-overview', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

if (!($faqIds === false || $faqIds === [] || $faqIds === null)) {
Expand Down Expand Up @@ -583,7 +583,7 @@ public function delete(Request $request): JsonResponse
$faqLanguage = Filter::filterVar($data->faqLanguage, FILTER_SANITIZE_SPECIAL_CHARS);

if (!Token::getInstance()->verifyToken('faq-overview', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$adminLog = new AdminLog($this->configuration);
Expand Down Expand Up @@ -611,7 +611,7 @@ public function search(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance()->verifyToken('edit-faq', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$faqPermission = new FaqPermission($this->configuration);
Expand Down Expand Up @@ -649,7 +649,7 @@ public function saveOrderOfStickyFaqs(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance()->verifyToken('order-stickyfaqs', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$faq = new Faq($this->configuration);
Expand All @@ -672,7 +672,7 @@ public function import(Request $request): JsonResponse
}

if (!Token::getInstance()->verifyToken('importfaqs', $request->request->get('csrf'))) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$faqImport = new Import($this->configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function activateInput(Request $request)

$forms = new Forms($this->configuration);
if (!Token::getInstance($this->container->get('session'))->verifyToken('activate-input', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

try {
Expand All @@ -64,7 +64,7 @@ public function setInputAsRequired(Request $request)

$forms = new Forms($this->configuration);
if (!Token::getInstance($this->container->get('session'))->verifyToken('require-input', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

try {
Expand All @@ -87,7 +87,7 @@ public function editTranslation(Request $request)

$forms = new Forms($this->configuration);
if (!Token::getInstance($this->container->get('session'))->verifyToken('edit-translation', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

try {
Expand All @@ -109,7 +109,7 @@ public function deleteTranslation(Request $request)

$forms = new Forms($this->configuration);
if (!Token::getInstance($this->container->get('session'))->verifyToken('delete-translation', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

try {
Expand Down Expand Up @@ -140,7 +140,7 @@ public function addTranslation(Request $request): JsonResponse

$forms = new Forms($this->configuration);
if (!Token::getInstance($this->container->get('session'))->verifyToken('add-translation', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function delete(Request $request): JsonResponse
$glossaryLanguage = Filter::filterVar($data->lang, FILTER_SANITIZE_SPECIAL_CHARS);

if (!Token::getInstance($this->container->get('session'))->verifyToken('delete-glossary', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$glossary = new Glossary($this->configuration);
Expand Down Expand Up @@ -90,7 +90,7 @@ public function create(Request $request): JsonResponse
$glossaryDefinition = Filter::filterVar($data->definition, FILTER_SANITIZE_SPECIAL_CHARS);

if (!Token::getInstance($this->container->get('session'))->verifyToken('add-glossary', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$glossary = new Glossary($this->configuration);
Expand Down Expand Up @@ -119,7 +119,7 @@ public function update(Request $request): JsonResponse
$glossaryDefinition = Filter::filterVar($data->definition, FILTER_SANITIZE_SPECIAL_CHARS);

if (!Token::getInstance($this->container->get('session'))->verifyToken('update-glossary', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$glossary = new Glossary($this->configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function upload(Request $request): JsonResponse
!Token::getInstance($this->container->get('session'))
->verifyToken('edit-faq', $request->query->get('csrf'))
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$file = $request->files->get('file');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function add(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance($this->container->get('session'))->verifyToken('add-instance', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$url = Filter::filterVar($data->url, FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down Expand Up @@ -160,7 +160,7 @@ public function delete(Request $request): JsonResponse
$data = json_decode($request->getContent());

if (!Token::getInstance($this->container->get('session'))->verifyToken('delete-instance', $data->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$instanceId = Filter::filterVar($data->instanceId, FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function create(Request $request): JsonResponse
$news = new News($this->configuration);

if (!Token::getInstance($this->container->get('session'))->verifyToken('save-news', $data->csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$header = Filter::filterVar($data->newsHeader, FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down Expand Up @@ -94,7 +94,7 @@ public function delete(Request $request): JsonResponse
$news = new News($this->configuration);

if (!Token::getInstance($this->container->get('session'))->verifyToken('delete-news', $data->csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$deleteId = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
Expand All @@ -119,7 +119,7 @@ public function update(Request $request): JsonResponse
$news = new News($this->configuration);

if (!Token::getInstance($this->container->get('session'))->verifyToken('update-news', $data->csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$newsId = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
Expand Down Expand Up @@ -168,7 +168,7 @@ public function activate(Request $request): JsonResponse
$news = new News($this->configuration);

if (!Token::getInstance($this->container->get('session'))->verifyToken('activate-news', $data->csrfToken)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$newsId = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function delete(Request $request): JsonResponse
!Token::getInstance($this->container->get('session'))
->verifyToken('delete-questions', $data->data->{'pmf-csrf-token'})
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$questionIds = $data->data->{'questions[]'};
Expand All @@ -60,7 +60,7 @@ public function delete(Request $request): JsonResponse

return $this->json(['success' => Translation::get('ad_open_question_deleted')], Response::HTTP_OK);
} else {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function deleteTerm(Request $request): JsonResponse
!Token::getInstance($this->container->get('session'))
->verifyToken('delete-searchterm', $deleteData->csrf)
) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$searchId = Filter::filterVar($deleteData->searchTermId, FILTER_VALIDATE_INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function export(Request $request): BinaryFileResponse|JsonResponse
$requestData = json_decode($request->getContent());

if (!Token::getInstance($this->container->get('session'))->verifyToken('export-sessions', $requestData->csrf)) {
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
return $this->json(['error' => Translation::get('msgNoPermission')], Response::HTTP_UNAUTHORIZED);
}

$session = $this->container->get('phpmyfaq.admin.session');
Expand Down
Loading

0 comments on commit 5b4d031

Please sign in to comment.