-
Notifications
You must be signed in to change notification settings - Fork 1k
create no-embbed option for exporting issues #4799
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
base: stable-3_3_0
Are you sure you want to change the base?
Changes from all commits
74051f0
8ff8475
f704bb7
641f11a
95c5b87
60b8ccc
662e491
c45081d
b70b4e7
8afb136
c7f3bcc
cd25f3b
27e866b
c0b3605
b62d6d3
35dcf45
129fe93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,9 +81,26 @@ function createPublicationCoversNode($filter, $doc, $object) { | |
| $coverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image', htmlspecialchars($coverImageName, ENT_COMPAT, 'UTF-8'))); | ||
| $coverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image_alt_text', htmlspecialchars($coverImage['altText'], ENT_COMPAT, 'UTF-8'))); | ||
|
|
||
| $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); | ||
| $embedNode->setAttribute('encoding', 'base64'); | ||
| $coverNode->appendChild($embedNode); | ||
| if (!empty($filter->opts['use-file-urls'])) { | ||
| import('classes.file.PublicFileManager'); | ||
| $publicFileManager = new PublicFileManager(); | ||
| $request = Application::get()->getRequest(); | ||
|
|
||
| if (!empty($filter->opts['use-absolute-urls'])) { | ||
| $fileUrl = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($object->getJournalId()) . '/' . $coverImageName; | ||
| } else { | ||
| $fileUrl = $request->getBasePath() . '/' . $publicFileManager->getContextFilesPath($object->getJournalId()) . '/' . $coverImageName; | ||
| } | ||
|
|
||
| $hrefNode = $doc->createElementNS($deployment->getNamespace(), 'href'); | ||
| $hrefNode->setAttribute('src', htmlspecialchars($fileUrl, ENT_COMPAT, 'UTF-8')); | ||
| $hrefNode->setAttribute('mime_type', PKPString::mime_content_type($coverImageName)); | ||
| $coverNode->appendChild($hrefNode); | ||
| } else if (empty($filter->opts['no-embed'])) { | ||
| $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); | ||
| $embedNode->setAttribute('encoding', 'base64'); | ||
| $coverNode->appendChild($embedNode); | ||
| } | ||
| $coversNode->appendChild($coverNode); | ||
| } | ||
| } | ||
|
|
@@ -116,9 +133,32 @@ function createIssueCoversNode($filter, $doc, $object) { | |
| $coverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image', htmlspecialchars($coverImage, ENT_COMPAT, 'UTF-8'))); | ||
| $coverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image_alt_text', htmlspecialchars($object->getCoverImageAltText($locale), ENT_COMPAT, 'UTF-8'))); | ||
|
|
||
| $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); | ||
| $embedNode->setAttribute('encoding', 'base64'); | ||
| $coverNode->appendChild($embedNode); | ||
| import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter'); | ||
| if ($filter->opts['serializationMode'] !== NativeExportFilter::SERIALIZATION_MODE_EMBED) { | ||
| import('classes.file.PublicFileManager'); | ||
| $publicFileManager = new PublicFileManager(); | ||
| $request = Application::get()->getRequest(); | ||
|
|
||
| $fileUrl = ($filter->opts['serializationMode'] === NativeExportFilter::SERIALIZATION_MODE_URL) | ||
| ? $filePath | ||
| : "{$request->getBasePath()}/{$coverImage}"; | ||
|
|
||
| $fileUrl = ($filter->opts['serializationMode'] === NativeExportFilter::SERIALIZATION_MODE_URL) | ||
| ? $request->url(null, 'issue', 'view', array($object->getId(), $coverImage)) | ||
| : $request->getBasePath() . '/' . $publicFileManager->getContextFilesPath($object->getJournalId()) . '/' . $coverImage; | ||
|
|
||
|
|
||
| $hrefNode = $doc->createElementNS($deployment->getNamespace(), 'href'); | ||
| $hrefNode->setAttribute('src', htmlspecialchars($fileUrl, ENT_COMPAT, 'UTF-8')); | ||
| import('lib.pkp.classes.core.PKPString'); | ||
| $mimeType = PKPString::mime_content_type($filePath); | ||
| $hrefNode->setAttribute('mime_type', $mimeType); | ||
| $coverNode->appendChild($hrefNode); | ||
| } else { | ||
| $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); | ||
| $embedNode->setAttribute('encoding', 'base64'); | ||
| $coverNode->appendChild($embedNode); | ||
| } | ||
| $coversNode->appendChild($coverNode); | ||
| } | ||
| } | ||
|
|
@@ -207,22 +247,43 @@ function parsePublicationCover($filter, $node, $object) { | |
| case 'cover_image_alt_text': | ||
| $coverImage['altText'] = $n->textContent; | ||
| break; | ||
| case 'href': | ||
| case 'embed': | ||
| if (!isset($coverImage['uploadName'])) { | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.coverImageNameUnspecified')); | ||
| break; | ||
| } | ||
|
|
||
| import('classes.file.PublicFileManager'); | ||
| $publicFileManager = new PublicFileManager(); | ||
| $filePath = $publicFileManager->getContextFilesPath($context->getId()) . '/' . $coverImage['uploadName']; | ||
| $allowedFileTypes = ['gif', 'jpg', 'png', 'webp']; | ||
| $extension = pathinfo(strtolower($filePath), PATHINFO_EXTENSION); | ||
|
|
||
| if (!in_array($extension, $allowedFileTypes)) { | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.invalidFileExtension')); | ||
| break; | ||
| } | ||
|
|
||
| file_put_contents($filePath, base64_decode($n->textContent)); | ||
| if ($n->tagName === 'embed') { | ||
| file_put_contents($filePath, base64_decode($n->textContent)); | ||
| break; | ||
| } | ||
|
|
||
| // If it falls through to here, it's a href mode. | ||
| $imageUrl = $n->getAttribute('src'); | ||
| if (empty($imageUrl)) { | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.missingHref')); | ||
| break; | ||
| } | ||
|
|
||
| $fileContents = file_get_contents($imageUrl); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loading HTTP content through this function isn't reliable, it depends on a configuration which some hosts disable, take a look at how the Notice the existing code already covers URLs, relative and absolute paths, it will just be needed to keep the |
||
| if ($fileContents === false) { | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.failedDownloadingFile', array('url' => $imageUrl))); | ||
| break; | ||
| } | ||
|
|
||
| file_put_contents($filePath, $fileContents); | ||
| break; | ||
| default: | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.unknownElement', array('param' => $n->tagName))); | ||
|
|
@@ -267,6 +328,7 @@ function parseIssueCover($filter, $node, $object) { | |
| break; | ||
| case 'cover_image_alt_text': $object->setCoverImageAltText($n->textContent, $locale); break; | ||
| case 'embed': | ||
| case 'href': | ||
| if (!$object->getCoverImage($locale)) { | ||
| $deployment->addWarning(ASSOC_TYPE_ISSUE, $object->getId(), __('plugins.importexport.common.error.coverImageNameUnspecified')); | ||
| break; | ||
|
|
@@ -282,13 +344,60 @@ function parseIssueCover($filter, $node, $object) { | |
| break; | ||
| } | ||
|
|
||
| file_put_contents($filePath, base64_decode($n->textContent)); | ||
| if ($n->tagName === 'embed') { | ||
| file_put_contents($filePath, base64_decode($n->textContent)); | ||
| break; | ||
| } | ||
|
|
||
| // If it falls through to here, it's a href mode. | ||
| $imageUrl = $n->getAttribute('src'); | ||
| if (empty($imageUrl)) { | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.missingHref')); | ||
| break; | ||
| } | ||
|
|
||
| $fileContents = file_get_contents($imageUrl); | ||
| if ($fileContents === false) { | ||
| $deployment->addWarning(ASSOC_TYPE_PUBLICATION, $object->getId(), __('plugins.importexport.common.error.failedDownloadingFile', array('url' => $imageUrl))); | ||
| break; | ||
| } | ||
|
|
||
| file_put_contents($filePath, $fileContents); | ||
| break; | ||
| case 'file_url': | ||
| if (!$object->getCoverImage($locale)) { | ||
| $deployment->addWarning(ASSOC_TYPE_ISSUE, $object->getId(), __('plugins.importexport.common.error.coverImageNameUnspecified')); | ||
| break; | ||
| } | ||
|
|
||
| import('classes.file.PublicFileManager'); | ||
| $publicFileManager = new PublicFileManager(); | ||
| $filePath = $publicFileManager->getContextFilesPath($context->getId()) . '/' . $object->getCoverImage($locale); | ||
| $allowedFileTypes = ['gif', 'jpg', 'png', 'webp']; | ||
| $extension = pathinfo(strtolower($filePath), PATHINFO_EXTENSION); | ||
| if (!in_array($extension, $allowedFileTypes)) { | ||
| $deployment->addWarning(ASSOC_TYPE_ISSUE, $object->getId(), __('plugins.importexport.common.error.invalidFileExtension')); | ||
| break; | ||
| } | ||
|
|
||
| $imageUrl = $n->textContent; | ||
| if (empty($imageUrl)) { | ||
| $deployment->addWarning(ASSOC_TYPE_ISSUE, $object->getId(), __('plugins.importexport.common.error.missingFileUrl')); | ||
| break; | ||
| } | ||
|
|
||
| $fileContents = file_get_contents($imageUrl); | ||
| if ($fileContents === false) { | ||
| $deployment->addWarning(ASSOC_TYPE_ISSUE, $object->getId(), __('plugins.importexport.common.error.failedDownloadingFile', array('url' => $imageUrl))); | ||
| break; | ||
| } | ||
|
|
||
| file_put_contents($filePath, $fileContents); | ||
| break; | ||
| default: | ||
| $deployment->addWarning(ASSOC_TYPE_ISSUE, $object->getId(), __('plugins.importexport.common.error.unknownElement', array('param' => $n->tagName))); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess all the notes I've left above can be applied here and on the next modified block (around the lines 136-155).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I'll take a look and update these as well.