Skip to content

Commit

Permalink
fix: added handling of URL fragments, closes #1467
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Apr 21, 2020
1 parent 6064478 commit 74d305f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion phpmyfaq/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,18 @@
$faqVisits = new Visits($faqConfig);
$faqVisits->logViews($recordId);

// Add Glossary entries for answers only
$question = $faq->getRecordTitle($recordId);
if ($faqConfig->get('main.enableMarkdownEditor')) {
$answer = $markDown->text($faq->faqRecord['content']);
} else {
$answer = $faqHelper->renderMarkupContent($faq->faqRecord['content']);
}

// Rewrite URL fragments
$currentUrl = htmlspecialchars("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", ENT_QUOTES, 'UTF-8');
$answer = $faqHelper->rewriteUrlFragments($answer, $currentUrl);

// Add Glossary entries for answers only
$answer = $oGlossary->insertItemsIntoContent($answer);

// Set the path of the current category
Expand Down
13 changes: 12 additions & 1 deletion phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,25 @@ public function setSsl($ssl)
/**
* Rewrites the CSS class generated by TinyMCE for HighlightJS.
*
* @param string $answer
* @param string $answer
* @return string
*/
public function renderMarkupContent(string $answer): string
{
return str_replace('class="language-markup"', 'class="language-html"', $answer);
}

/**
* Extends URL fragments (e.g. <a href="#foo">) with the full default URL.
* @param string $answer
* @param string $currentUrl
* @return string
*/
public function rewriteUrlFragments(string $answer, string $currentUrl): string
{
return str_replace('href="#', 'href="' . $currentUrl . '#', $answer);
}

/**
* Renders a Share on Twitter link.
*
Expand Down

0 comments on commit 74d305f

Please sign in to comment.