Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/jatsTemplate#59 PDFs not prioritized for full body text #62

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion JatsTemplatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 20 additions & 5 deletions classes/ArticleBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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);
Expand Down