diff --git a/JatsTemplatePlugin.php b/JatsTemplatePlugin.php index b613609..debc0e5 100755 --- a/JatsTemplatePlugin.php +++ b/JatsTemplatePlugin.php @@ -60,8 +60,10 @@ public function callbackFindJats($hookName, $args) { $doc =& $args[3]; if (!$doc && empty($candidateFiles)) { + $request = Application::get()->getRequest(); + $doc = new Article(); - $doc->convertOAIToXml($record); + $doc->convertOAIToXml($record, $request); } return false; diff --git a/classes/ArticleBody.php b/classes/ArticleBody.php index 27b38ae..4aa4697 100644 --- a/classes/ArticleBody.php +++ b/classes/ArticleBody.php @@ -16,6 +16,7 @@ use APP\submission\Submission; use PKP\config\Config; use PKP\core\PKPString; +use PKP\galley\Galley; use PKP\search\SearchFileParser; class ArticleBody extends \DOMDocument @@ -32,10 +33,24 @@ public function create(Submission $submission):\DOMNode $text = ''; $galleys = $submission->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 = app()->get('file'); @@ -55,7 +70,7 @@ public function create(Submission $submission):\DOMNode } // Remove non-paragraph content $text = $purifier->purify(file_get_contents(Config::getVar('files', 'files_dir') . '/' . $filepath)); - + // Remove empty paragraphs } else { $parser = SearchFileParser::fromFile($galleyFile);