Skip to content

Commit

Permalink
Merge pull request #31 from alexplusde/hotfix-redeclared-functions
Browse files Browse the repository at this point in the history
fix Cannot redeclare htmlEncode()
  • Loading branch information
alxndr-w committed Feb 6, 2024
2 parents 907985a + 2884972 commit a56726a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
23 changes: 5 additions & 18 deletions fragments/FAQPage.json-ld.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<?php
$jsonOptions = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK;

function htmlEncode($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8');
}

function getAuthor($question)
{
return [
'@type' => 'Person',
'name' => json_encode($question->getAuthor(), $GLOBALS['jsonOptions']),
];
}
?>

<script type="application/ld+json">
Expand All @@ -31,15 +18,15 @@ function getAuthor($question)
"name": <?= json_encode($question->getQuestion(), $jsonOptions) ?> ,
"text": <?= json_encode($question->getValue('answer'), $jsonOptions) ?> ,
"answerCount": 1,
"dateCreated": "<?= htmlEncode($question->getValue('createdate')) ?>",
"author": <?= json_encode(getAuthor($question), $jsonOptions) ?> ,
"dateCreated": "<?= qanda::htmlEncode($question->getValue('createdate')) ?>",
"author": <?= json_encode(qanda::getJsonAuthor($question), $jsonOptions) ?> ,
"acceptedAnswer": {
"@type": "Answer",
"text": <?= json_encode($question->getQuestion(), $jsonOptions) ?> ,
"upvoteCount": 0,
"url": "<?= htmlEncode($question->getUrl()) ?>",
"dateCreated": "<?= htmlEncode($question->getValue('updatedate')) ?>",
"author": <?= json_encode(getAuthor($question), $jsonOptions) ?>
"url": "<?= qanda::htmlEncode($question->getUrl()) ?>",
"dateCreated": "<?= qanda::htmlEncode($question->getValue('updatedate')) ?>",
"author": <?= json_encode(qanda::getJsonAuthor($question), $jsonOptions) ?>
}
}
<?php
Expand Down
23 changes: 5 additions & 18 deletions fragments/qanda.json-ld.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
<?php
$jsonOptions = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK;

function htmlEncode($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8');
}

function getAuthor($question)
{
return [
'@type' => 'Person',
'name' => json_encode($question->getAuthor(), $GLOBALS['jsonOptions']),
];
}

?>

<script type="application/ld+json">
Expand All @@ -23,15 +10,15 @@ function getAuthor($question)
"name": <?= json_encode($this->question->getQuestion(), $jsonOptions) ?> ,
"text": <?= json_encode($this->question->getQuestion(), $jsonOptions) ?> ,
"answerCount": 1,
"dateCreated": "<?= htmlEncode($this->question->getValue('createdate')) ?>",
"author": <?= json_encode(getAuthor($this->question), $jsonOptions) ?> ,
"dateCreated": "<?= qanda::htmlEncode($this->question->getValue('createdate')) ?>",
"author": <?= json_encode(qanda::getJsonAuthor($this->question), $jsonOptions) ?> ,
"acceptedAnswer": {
"@type": "Answer",
"text": <?= json_encode($this->question->getValue('answer'), $jsonOptions) ?> ,
"upvoteCount": 0,
"url": "<?= htmlEncode($this->question->getUrl()) ?>",
"dateCreated": "<?= htmlEncode($this->question->getValue('updatedate')) ?>",
"author": <?= json_encode(getAuthor($this->question), $jsonOptions) ?>
"url": "<?= qanda::htmlEncode($this->question->getUrl()) ?>",
"dateCreated": "<?= qanda::htmlEncode($this->question->getValue('updatedate')) ?>",
"author": <?= json_encode(qanda::getJsonAuthor($this->question), $jsonOptions) ?>
}
}
</script>
19 changes: 19 additions & 0 deletions lib/qanda.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,23 @@ public static function showFAQPage(array|rex_yform_manager_collection $questions
$fragment->setVar('questions', $questions);
return $fragment->parse('FAQPage.json-ld.php');
}


/* Hilfsklasse für JSON-LD Fragmente */
public static function htmlEncode($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8');
}

/* Hilfsklasse für JSON-LD Fragmente */
public static function getJsonAuthor($question)
{
return [
'@type' => 'Person',
'name' => json_encode($question->getAuthor(), $GLOBALS['jsonOptions']),
];
}



}

0 comments on commit a56726a

Please sign in to comment.