Skip to content

Commit

Permalink
#2564 Appempting to add HTML tag support for native import/export, fa…
Browse files Browse the repository at this point in the history
…iled so far
  • Loading branch information
touhidurabir authored and asmecher committed Feb 16, 2023
1 parent fc87dd1 commit b391330
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
19 changes: 19 additions & 0 deletions classes/publication/PKPPublication.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ public function getTitles(string $format = 'text')
return $return;
}

/**
* Return all the sub titles
*
* @param string $format Define the return data format as text or html
* @return array
*/
public function getSubTitles(string $format = 'text')
{
$allSubTitles = $this->getData('subtitle');
$return = [];
foreach ($allSubTitles as $locale => $subTitle) {
if (!$subTitle) {
continue;
}
$return[$locale] = $this->getLocalizedSubTitle($locale, $format);
}
return $return;
}

/**
* Combine author names and roles into a string
*
Expand Down
21 changes: 17 additions & 4 deletions plugins/importexport/native/filter/NativeExportFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,29 @@ public function supports(&$input, &$output)
* @param string $name Node name
* @param array $values Array of locale key => value mappings
*/
public function createLocalizedNodes($doc, $parentNode, $name, $values)
public function createLocalizedNodes($doc, $parentNode, $name, $values, $format = 'text')
{
$format = strtolower($format);
$deployment = $this->getDeployment();
if (is_array($values)) {
foreach ($values as $locale => $value) {
if ($value === '') {
if ($value === '') { // Skip empty values
continue;
} // Skip empty values
$parentNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), $name, htmlspecialchars($value, ENT_COMPAT, 'UTF-8')));
}

$node = $doc->createElementNS(
$deployment->getNamespace(),
$name,
$format === 'html' ? $value : htmlspecialchars($value, ENT_COMPAT, 'UTF-8')
);

$parentNode->appendChild($node);

$node->setAttribute('locale', $locale);

// if ( $format === 'html' ) {
// $node->setAttribute('type', 'text/html');
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ public function addPubIdentifier($doc, $entityNode, $entity, $pubIdType)
public function addMetadata($doc, $entityNode, $entity)
{
$deployment = $this->getDeployment();
$this->createLocalizedNodes($doc, $entityNode, 'title', $entity->getData('title'));
$this->createLocalizedNodes($doc, $entityNode, 'title', $entity->getTitles('html'), 'html');
$this->createLocalizedNodes($doc, $entityNode, 'prefix', $entity->getData('prefix'));
$this->createLocalizedNodes($doc, $entityNode, 'subtitle', $entity->getData('subtitle'));
$this->createLocalizedNodes($doc, $entityNode, 'subtitle', $entity->getSubTitles('html'), 'html');
$this->createLocalizedNodes($doc, $entityNode, 'abstract', $entity->getData('abstract'));
$this->createLocalizedNodes($doc, $entityNode, 'coverage', $entity->getData('coverage'));
$this->createLocalizedNodes($doc, $entityNode, 'type', $entity->getData('type'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function addPublications($doc, $submissionNode, $submission)
$deployment = $this->getDeployment();
$deployment->addError(ASSOC_TYPE_SUBMISSION, $submission->getId(), __('plugins.importexport.publication.exportFailed'));

throw new Exception(__('plugins.importexport.publication.exportFailed'));
throw new \Exception(__('plugins.importexport.publication.exportFailed'));
}
}
}
Expand Down

0 comments on commit b391330

Please sign in to comment.