From be6b26745a9317b045b424f4d8ab33b8668bc85e Mon Sep 17 00:00:00 2001 From: Erik Hanson Date: Fri, 15 Nov 2024 10:01:37 -0800 Subject: [PATCH] pkp/jatsTemplate#59 PDFs not prioritized for full body text --- JatsTemplatePlugin.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/JatsTemplatePlugin.php b/JatsTemplatePlugin.php index 33795fd..52b0608 100644 --- a/JatsTemplatePlugin.php +++ b/JatsTemplatePlugin.php @@ -20,6 +20,7 @@ use HTMLPurifier_Config; use PKP\core\PKPString; use PKP\db\DAORegistry; +use PKP\galley\Galley; use PKP\plugins\GenericPlugin; use PKP\plugins\Hook; use PKP\plugins\PluginRegistry; @@ -325,11 +326,24 @@ function toXml(&$record, $format = null) { $text = ''; $galleys = $article->getGalleys(); - // Give precedence to HTML galleys, as they're quickest to parse - usort($galleys, function($a, $b) { - return $a->getFileType() == 'text/html'?-1:1; - }); - + // Get HTML galleys for top of list, as they're quickest to parse + // PDFs have second-highest priority over other file types + $items = array_reduce($galleys, function(array $carry, Galley $galley) { + $fileType = $galley->getFileType(); + + switch ($fileType) { + case 'text/html': + $carry['html'][] = $galley; + break; + case 'application/pdf': + $carry['pdf'][] = $galley; + break; + default: + $carry['other'][] = $galley; + } + return $carry; + }, ['html' => [], 'pdf' => [], 'other' => []]); + $galleys = array_merge($items['html'], $items['pdf'], $items['other']); // Provide the full-text. $fileService = Services::get('file'); foreach ($galleys as $galley) {