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

Texture crossref reference support and create galley support for OJS 3.3 #111

Merged
merged 6 commits into from
Sep 13, 2022
10 changes: 5 additions & 5 deletions TexturePlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function callbackLoadHandler($hookName, $args) {
case 'texture/media':
define('HANDLER_CLASS', 'TextureHandler');
define('TEXTURE_PLUGIN_NAME', $this->getName());
$args[2] = $this->getPluginPath() . '/' . 'TextureHandler.inc.php';
$args[2] = $this->getPluginPath() .DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR. 'TextureHandler.inc.php';
break;
}

Expand Down Expand Up @@ -137,12 +137,12 @@ public function templateFetchCallback($hookName, $params) {
if (strtolower($fileExtension) == 'text/xml') {
import('lib.pkp.classes.linkAction.request.OpenWindowAction');
$this->_editWithTextureAction($row, $dispatcher, $request, $submissionFile, $stageId);
//$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
//$this->_exportAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
#$this->_exportAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
} elseif (strtolower($fileExtension) == TEXTURE_DAR_FILE_TYPE) {
$this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_DAR_FILE_TYPE);
// $this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_DAR_FILE_TYPE);
} elseif (strtolower($fileExtension) == TEXTURE_ZIP_FILE_TYPE) {
$this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_ZIP_FILE_TYPE);
// $this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_ZIP_FILE_TYPE);
} elseif (strtolower($fileExtension) == TEXTURE_HTML_FILE_TYPE) {
import('lib.pkp.classes.linkAction.request.OpenWindowAction');
$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
Expand Down
Empty file modified classes/DAR.inc.php
100755 → 100644
Empty file.
194 changes: 194 additions & 0 deletions classes/JATS.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<?php


use DAORegistry;
use DOMDocument;
use DOMXpath;
use PKPString;

class JATS extends \DOMDocument
{

public static function getJournalMeta(DOMDocument $origDocument, $context): void
{

$xpath = new DOMXpath($origDocument);

$journalMeta = $xpath->query("//article/front/journal-meta");
foreach ($journalMeta as $journalMetaEntry) {
$origDocument->documentElement->removeChild($journalMetaEntry);
}
$articleMeta = $xpath->query("//article/front/article-meta");
if (count($articleMeta) == 1) {
if (count($journalMeta) == 0) {

$journalMeta = $origDocument->createElement('journal-meta');

$journalIdType = $origDocument->createElement('journal-id', $context->getLocalizedAcronym());
$journalIdType->setAttribute('journal-id-type', 'publisher-id');
$journalMeta->appendChild($journalIdType);
$issn = $origDocument->createElement('issn', $context->getData('onlineIssn'));
$issn->setAttribute('pub-type', 'epub');
$journalMeta->appendChild($issn);
$publisher = $origDocument->createElement('publisher');
$publisherName = $origDocument->createElement('publisher-name', $context->getData('publisherInstitution'));
$publisher->appendChild($publisherName);
$journalMeta->appendChild($publisher);

$articleMeta->item(0)->parentNode->insertBefore($journalMeta, $articleMeta->item(0));

}

}
}


public static function getArticleMetaHistory(DOMDocument $origDocument, Submission $submission, $datePublished = null): void
{

$xpath = new DOMXpath($origDocument);

$editDecisionDao = DAORegistry::getDAO('EditDecisionDAO');
$history = $xpath->query("//article/front/article-meta/history");

foreach ($history as $item) {
$item->parentNode->removeChild($item);
}
$history = $origDocument->createElement('history');
$dateReceived = $submission->getData('dateSubmitted');
if ($dateReceived) {
$dateReceived = self::getDate($origDocument, $dateReceived, 'received');
$history->appendChild($dateReceived);
}

$dateAccepted = null;
$decisions = $editDecisionDao->getEditorDecisions($submission->getId());
foreach ($decisions as $decision) {
if ($decision['stageId'] == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW && $decision['decision'] == SUBMISSION_EDITOR_DECISION_ACCEPT)
$dateAccepted = $decision['dateDecided'];
}
if ($dateAccepted) {
$history->appendChild(self::getDate($origDocument, $dateAccepted, 'accepted'));
}

if ($datePublished) {
$history->appendChild(self::getDate($origDocument, $datePublished, 'published'));
}


$articleMeta = $xpath->query("//article/front/article-meta");
if ($articleMeta)
$articleMeta->item(0)->appendChild($history);


}


public static function getJournalMetaPubDate(DOMDocument $origDocument, $context, $submission, $datePublished, $firstPage = null, $lastPage=null): void
{
$xpath = new DOMXpath($origDocument);
$timestamp = strtotime($datePublished);

$issueDao = DAORegistry::getDAO('IssueDAO');

$pubDate = $xpath->query("//article/front/article-meta/pub-date");

foreach ($pubDate as $item) {
$item->parentNode->removeChild($item);
}

$pubDate = $origDocument->createElement('pub-date');
$pubDate->setAttribute('pub-type','epub');
$day = $origDocument->createElement('day', date('d', $timestamp));
$pubDate->appendChild($day);
$month = $origDocument->createElement('month', date('m', $timestamp));
$pubDate->appendChild($month);
$year = $origDocument->createElement('year', date('Y', $timestamp));
$pubDate->appendChild($year);

$issue = $issueDao->getBySubmissionId($submission->getId(), $context->getId());
$volume = $origDocument->createElement('volume', $issue->getVolume());
$pubDate->appendChild($volume);

if ($firstPage) {
$pubDate->appendChild($origDocument->createElement('fpage',$firstPage));
}
if ($lastPage) {
$pubDate->appendChild($origDocument->createElement('lpage',$lastPage));
}
$articleMeta = $xpath->query("//article/front/article-meta");
if ($articleMeta)
$articleMeta->item(0)->appendChild($pubDate);


}


public static function getArticleMetaCCBYLicense(DOMDocument $origDocument, $context, $copyrightYear = null): void
{


$xpath = new DOMXpath($origDocument);
$permissions = $xpath->query("//article/front/article-meta/permissions");
foreach ($permissions as $permission) {
$origDocument->documentElement->removeChild($permission);
}


$articleMeta = $xpath->query("//article/front/article-meta");
$licenseUrl = $context->getData('licenseUrl');
if (count($articleMeta) > 0 and $licenseUrl) {


PKPString::regexp_match_get('/http[s]?:(www\.)?\/\/creativecommons.org\/licenses\/([a-z]+(-[a-z]+)*)\/(\d.0)\/*([a-z]*).*/i', $licenseUrl, $matches);
if (count($matches) > 5 and $matches[2] and $matches[4]) {

if (!$$copyrightYear) $copyrightYear = date('Y');

$permissionNode = $origDocument->createElement('permissions');
$copyrightStatementNode = $origDocument->createElement('copyright-statement', '© ' . $copyrightYear . ' The Author(s)');
$permissionNode->appendChild($copyrightStatementNode);
$copyrightYearNode = $origDocument->createElement('copyright-year', $copyrightYear);
$permissionNode->appendChild($copyrightYearNode);

$copyrightLicenseNode = $origDocument->createElement('copyright-license');
$copyrightLicenseNode->setAttribute('license-type', 'open-access');
$copyrightLicenseNode->setAttribute('xlink:href', $licenseUrl);
$copyrightLicenseNode->setAttribute('xml:lang', 'en');

$copyrightLicensePNode = $origDocument->createElement('license-p');

$inlineGraphicNode = $origDocument->createElement('inline-graphic');
$inlineGraphicNode->setAttribute('xlink:href', 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/' . $matches[2] . '.svg');
$copyrightLicensePNode->appendChild($inlineGraphicNode);

$countryCode = $matches[5] ? strtoupper($matches[5]) : '';
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$country = $isoCodes->getCountries()->getByAlpha2($countryCode) ? $isoCodes->getCountries()->getByAlpha2($countryCode)->getName() : '';
$licensePTextNode = $origDocument->createTextNode("This work is published under the Creative Commons {$country} License {$matches[4]} (CC BY {$matches[4]} {$countryCode}).");

$copyrightLicensePNode->appendChild($licensePTextNode);
$copyrightLicenseNode->appendChild($copyrightLicensePNode);
$permissionNode->appendChild($copyrightLicenseNode);
$articleMeta[0]->appendChild($permissionNode);
}
}

}

public static function getDate(\DOMDocument $origDocument, string $dateAndTime, $type =null): DOMElement
{
$timestamp = strtotime($dateAndTime);
$date = $origDocument->createElement('date');
if ($type) $date->setAttribute('type', $type);
$date->setAttribute('iso-8601-date', date('Y-m-d', $timestamp));
$day = $origDocument->createElement('day', date('d', $timestamp));
$date->appendChild($day);
$month = $origDocument->createElement('month', date('m', $timestamp));
$date->appendChild($month);
$year = $origDocument->createElement('year', date('Y', $timestamp));
$date->appendChild($year);
return $date;

}
}
11 changes: 7 additions & 4 deletions TextureHandler.inc.php → controllers/TextureHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function extract($args, $request) {
$user = $request->getUser();
$zipType = $request->getUserVar("zipType");
$submissionFile = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION_FILE);
$archivePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'texture-' . $zipType . '-archive' . mt_rand();
$archivePath = '';//TextureHandler . inc . 'texture-' . $zipType . '-archive' . mt_rand();
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
$html_types = array('html');

Expand All @@ -110,7 +110,7 @@ public function extract($args, $request) {
$genreDAO = DAORegistry::getDAO('GenreDAO');
$genre = $genreDAO->getByKey('SUBMISSION', $submission->getData('contextId'));
$fileStage = $submissionFile->getFileStage();
$sourceFileId = $submissionFile->getData('submissionFileId');
$sourceFileId = $submissionFile->getData('fileId');
if ($zipType == TEXTURE_DAR_FILE_TYPE) {
$manifestFileDom = new DOMDocument();
$darManifestFilePath = $archivePath . DIRECTORY_SEPARATOR . DAR_MANIFEST_FILE;
Expand Down Expand Up @@ -559,7 +559,7 @@ public function json($args, $request) {


} elseif (!empty($resources) && isset($resources[DAR_MANUSCRIPT_FILE]) && is_object($resources[DAR_MANUSCRIPT_FILE])) {
$this->_updateManuscriptFile($request, $resources, $submission, $submissionFile);
$this->updateManuscriptFile($request, $resources, $submission, $submissionFile);
} else {
return new JSONMessage(false);
}
Expand All @@ -579,7 +579,7 @@ public function json($args, $request) {
* @param $submissionFile SubmissionFile
* @return SubmissionFile
*/
protected function _updateManuscriptFile($request, $resources, $submission, $submissionFile) {
protected function updateManuscriptFile($request, $resources, $submission, $submissionFile) {

$modifiedDocument = new DOMDocument('1.0', 'utf-8');
$modifiedData = $resources[DAR_MANUSCRIPT_FILE]->data;
Expand All @@ -593,6 +593,9 @@ protected function _updateManuscriptFile($request, $resources, $submission, $sub
$origDocument = new DOMDocument('1.0', 'utf-8');
$origDocument->loadXML($manuscriptXml);




$body = $origDocument->documentElement->getElementsByTagName('body')->item(0);
$origDocument->documentElement->removeChild($body);

Expand Down
Loading