Skip to content

Commit

Permalink
feat: removed configuration for enabling rewrite rules
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 29, 2023
1 parent d209bce commit bb85ab7
Show file tree
Hide file tree
Showing 35 changed files with 202 additions and 382 deletions.
106 changes: 34 additions & 72 deletions phpmyfaq/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,78 +603,40 @@
);
}

if ($faqConfig->get('main.enableRewriteRules')) {
$tplNavigation = [
'backToHome' => '<a class="nav-link" href="./index.html">' . Translation::get('msgHome') . '</a>',
'allCategories' => '<a class="nav-link px-2 text-white" href="./show-categories.html">' .
Translation::get('msgShowAllCategories') . '</a>',
'msgAddContent' => '<a class="nav-link px-2 text-white" href="./addcontent.html">' .
Translation::get('msgAddContent') . '</a>',
'msgQuestion' => $faqConfig->get('main.enableAskQuestions')
?
'<a class="nav-link px-2 text-white" href="./ask.html">' . Translation::get('msgQuestion') . '</a>'
:
'',
'msgOpenQuestions' => $faqConfig->get('main.enableAskQuestions')
?
'<a class="nav-link px-2 text-white" href="./open-questions.html">' .
Translation::get('msgOpenQuestions') . '</a>'
:
'',
'msgSearch' => '<a class="nav-link" href="./search.html">' . Translation::get('msgAdvancedSearch') . '</a>',
'msgContact' => '<a class="nav-link px-2 link-light" href="./contact.html">' . Translation::get('msgContact') .
'</a>',
'msgGlossary' => '<a class="nav-link px-2 link-light" href="./glossary.html">' .
Translation::get('ad_menu_glossary') . '</a>',
'privacyLink' => sprintf(
'<a class="nav-link px-2 link-light" target="_blank" href="%s">%s</a>',
Strings::htmlentities($faqConfig->get('main.privacyURL')),
Translation::get('msgPrivacyNote')
),
'faqOverview' => '<a class="nav-link px-2 link-light" href="./overview.html">' .
Translation::get('faqOverview') . '</a>',
'showSitemap' => '<a class="nav-link px-2 link-light" href="./sitemap/A/' . $faqLangCode . '.html">' .
Translation::get('msgSitemap') . '</a>',
'breadcrumbHome' => '<a href="./index.html">' . Translation::get('msgHome') . '</a>',
];
} else {
$tplNavigation = [
'backToHome' => '<a href="index.php?' . $sids . '">' . Translation::get('msgHome') . '</a>',
'allCategories' => '<a class="nav-link" href="index.php?' . $sids . 'action=show">' .
Translation::get('msgShowAllCategories') . '</a>',
'msgAddContent' => '<a class="nav-link" href="index.php?' . $sids . 'action=add&cat=' . $cat . '">' .
Translation::get('msgAddContent') . '</a>',
'msgQuestion' => $faqConfig->get('main.enableAskQuestions')
?
'<a class="nav-link" href="index.php?' . $sids . 'action=ask&category_id=' . $cat . '">' .
Translation::get('msgQuestion') . '</a>'
:
'',
'msgOpenQuestions' => $faqConfig->get('main.enableAskQuestions')
?
'<a class="nav-link" href="index.php?' . $sids . 'action=open-questions">' .
Translation::get('msgOpenQuestions') . '</a>'
:
'',
'msgSearch' => '<a class="nav-link" href="index.php?' . $sids . 'action=search">' .
Translation::get('msgAdvancedSearch') . '</a>',
'msgContact' => '<a class="nav-link px-2 link-light" href="index.php?' . $sids . 'action=contact">' .
Translation::get('msgContact') . '</a>',
'msgGlossary' => '<a class="nav-link px-2 link-light" href="index.php?' . $sids . 'action=glossary">' .
Translation::get('ad_menu_glossary') . '</a>',
'privacyLink' => sprintf(
'<a class="nav-link px-2 link-light" target="_blank" href="%s">%s</a>',
Strings::htmlentities($faqConfig->get('main.privacyURL')),
Translation::get('msgPrivacyNote')
),
'faqOverview' => '<a class="nav-link px-2 link-light" href="index.php?' . $sids . 'action=overview">' .
Translation::get('faqOverview') . '</a>',
'showSitemap' => '<a class="nav-link px-2 link-light" href="index.php?' . $sids . 'action=sitemap&amp;lang=' .
$faqLangCode . '">' .
Translation::get('msgSitemap') . '</a>',
'breadcrumbHome' => '<a href="index.php?' . $sids . '">' . Translation::get('msgHome') . '</a>',
];
}
$tplNavigation = [
'backToHome' => '<a class="nav-link" href="./index.html">' . Translation::get('msgHome') . '</a>',
'allCategories' => '<a class="nav-link px-2 text-white" href="./show-categories.html">' .
Translation::get('msgShowAllCategories') . '</a>',
'msgAddContent' => '<a class="nav-link px-2 text-white" href="./addcontent.html">' .
Translation::get('msgAddContent') . '</a>',
'msgQuestion' => $faqConfig->get('main.enableAskQuestions')
?
'<a class="nav-link px-2 text-white" href="./ask.html">' . Translation::get('msgQuestion') . '</a>'
:
'',
'msgOpenQuestions' => $faqConfig->get('main.enableAskQuestions')
?
'<a class="nav-link px-2 text-white" href="./open-questions.html">' .
Translation::get('msgOpenQuestions') . '</a>'
:
'',
'msgSearch' => '<a class="nav-link" href="./search.html">' . Translation::get('msgAdvancedSearch') . '</a>',
'msgContact' => '<a class="nav-link px-2 link-light" href="./contact.html">' . Translation::get('msgContact') .
'</a>',
'msgGlossary' => '<a class="nav-link px-2 link-light" href="./glossary.html">' .
Translation::get('ad_menu_glossary') . '</a>',
'privacyLink' => sprintf(
'<a class="nav-link px-2 link-light" target="_blank" href="%s">%s</a>',
Strings::htmlentities($faqConfig->get('main.privacyURL')),
Translation::get('msgPrivacyNote')
),
'faqOverview' => '<a class="nav-link px-2 link-light" href="./overview.html">' .
Translation::get('faqOverview') . '</a>',
'showSitemap' => '<a class="nav-link px-2 link-light" href="./sitemap/A/' . $faqLangCode . '.html">' .
Translation::get('msgSitemap') . '</a>',
'breadcrumbHome' => '<a href="./index.html">' . Translation::get('msgHome') . '</a>',
];


$tplNavigation['faqHome'] = Strings::htmlentities($faqConfig->getDefaultUrl());
$tplNavigation['activeSearch'] = ('search' == $action) ? 'active' : '';
Expand Down
34 changes: 9 additions & 25 deletions phpmyfaq/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,7 @@
) && $faqConfig->get('search.searchForSolutionId')
) {
$response = new Response();
if ($faqConfig->get('main.enableRewriteRules')) {
$response->isRedirect($faqConfig->getDefaultUrl() . 'solution_id_' . $inputSearchTerm . '.html');
} else {
$response->isRedirect($faqConfig->getDefaultUrl() . 'index.php?solution_id=' . $inputSearchTerm);
}
$response->isRedirect($faqConfig->getDefaultUrl() . 'solution_id_' . $inputSearchTerm . '.html');
$response->send();
exit();
}
Expand All @@ -216,26 +212,14 @@
$mostPopularSearchData = $faqSearch->getMostPopularSearches($faqConfig->get('search.numberSearchTerms'));

// Set base URL scheme
if ($faqConfig->get('main.enableRewriteRules')) {
$baseUrl = sprintf(
'%ssearch.html?search=%s&amp;seite=%d%s&amp;pmf-search-category=%d',
$faqConfig->getDefaultUrl(),
urlencode($inputSearchTerm),
$page,
$languages,
$inputCategory
);
} else {
$baseUrl = sprintf(
'%s?%saction=search&amp;search=%s&amp;seite=%d%s&amp;pmf-search-category=%d',
$faqConfig->getDefaultUrl(),
empty($sids) ? '' : 'sids=' . $sids . '&amp;',
urlencode($inputSearchTerm),
$page,
$languages,
$inputCategory
);
}
$baseUrl = sprintf(
'%ssearch.html?search=%s&amp;seite=%d%s&amp;pmf-search-category=%d',
$faqConfig->getDefaultUrl(),
urlencode($inputSearchTerm),
$page,
$languages,
$inputCategory
);

// Pagination options
$options = [
Expand Down
3 changes: 3 additions & 0 deletions phpmyfaq/setup/migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@
$faqConfig->add('upgrade.releaseEnvironment', 'development');
$faqConfig->add('upgrade.dateLastChecked', '');

// Rewrite rules are now mandatory
$faqConfig->delete('main.enableRewriteRules');

// Bookmarks support
$query[] = match ($dbConfig->getType()) {
'mysqli' => 'CREATE TABLE ' . $prefix . 'faqbookmarks (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class AutoCompleteController
{
#[Route('api/autocomplete')]
public function search(Request $request): JsonResponse
{
$response = new JsonResponse();
Expand Down
49 changes: 0 additions & 49 deletions phpmyfaq/src/phpMyFAQ/Core/Controller.php

This file was deleted.

23 changes: 9 additions & 14 deletions phpmyfaq/src/phpMyFAQ/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,15 @@ public function renderRecordsByCategoryId(int $categoryId, string $orderBy = 'id
}

if ($pages > 1) {
// Set rewrite URL, if needed
if ($this->config->get('main.enableRewriteRules')) {
$link = new Link($this->config->getDefaultUrl(), $this->config);
$useRewrite = true;
$rewriteUrl = sprintf(
'%scategory/%d/%%d/%s.html',
$this->config->getDefaultUrl(),
$categoryId,
$link->getSEOItemTitle($title)
);
} else {
$useRewrite = false;
$rewriteUrl = '';
}
$link = new Link($this->config->getDefaultUrl(), $this->config);
$useRewrite = true;
$rewriteUrl = sprintf(
'%scategory/%d/%%d/%s.html',
$this->config->getDefaultUrl(),
$categoryId,
$link->getSEOItemTitle($title)
);

$baseUrl = sprintf(
'%sindex.php?%saction=show&amp;cat=%d&amp;seite=%d',
$this->config->getDefaultUrl(),
Expand Down
Loading

0 comments on commit bb85ab7

Please sign in to comment.