Skip to content

Commit

Permalink
pkp/pkp-lib#7916 revert back symfony html sanitizer and bring back ht…
Browse files Browse the repository at this point in the history
…ml purifier (#46)
  • Loading branch information
touhidurabir authored Jul 16, 2024
1 parent b162bb2 commit 2974473
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions OAIMetadataFormat_JATS.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
use APP\core\Services;
use PKP\core\PKPString;
use PKP\plugins\Hook;
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;

class OAIMetadataFormat_JATS extends OAIMetadataFormat {
/**
Expand Down Expand Up @@ -325,17 +323,21 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) {
}

// Set the article abstract.
static $sanitizer = null;
if (!$sanitizer) {
$sanitizer = new \PKP\core\PKPHtmlSanitizer('p');
static $purifier;
if (!$purifier) {
$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'p');
$config->set('Cache.SerializerPath', 'cache');
$purifier = new \HTMLPurifier($config);
}

foreach ($articleMetaNode->getElementsByTagName('abstract') as $abstractNode) $articleMetaNode->removeChild($abstractNode);
foreach ((array) $publication->getData('abstract') as $locale => $abstract) {
if (empty($abstract)) continue;
$isPrimary = $locale == $article->getLocale();
$abstractDoc = new \DOMDocument;
if (strpos($abstract, '<p>')===null) $abstract = "<p>$abstract</p>";
$abstractDoc->loadXML(($isPrimary?'<abstract>':'<trans-abstract>') . $sanitizer->sanitize($abstract) . ($isPrimary?'</abstract>':'</trans-abstract>'));
$abstractDoc->loadXML(($isPrimary?'<abstract>':'<trans-abstract>') . $purifier->purify($abstract) . ($isPrimary?'</abstract>':'</trans-abstract>'));
$abstractNode = $this->_addChildInOrder($articleMetaNode, $doc->importNode($abstractDoc->documentElement, true));
if (!$isPrimary) $abstractNode->setAttribute('xml:lang', substr($locale,0,2));
}
Expand Down

0 comments on commit 2974473

Please sign in to comment.