Skip to content

Commit

Permalink
Merge pull request #19 from cedis-epublishing/upgrade-ojs-3.3
Browse files Browse the repository at this point in the history
Upgrade ojs 3.3
  • Loading branch information
ajnyga authored Sep 26, 2023
2 parents dda68ee + d54e6aa commit bc35149
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Excel to OJS3 XML conversion tool

Version 1.3.1.0 supports the schema for OJS 3.2.1.
Version 1.4.0.0 supports the schema for OJS 3.3. (tested with OJS 3.3.0-14, Aug 2023)

The tool was created for "in-house use" at the Federation of Finnish Learned Societies (https://tsv.fi). *It is not pretty*. It has not been thoroughly tested, but has been used to import the archives of around 20 journals since 2017. Feel free to use and develop further.

Expand Down Expand Up @@ -45,7 +45,7 @@ Only validate by adding -v:
| title | Article title | x |
| subTitle | Article subtitle | |
| abstract| Article abstract | |
| seq | Article sequence inside an issue, first article '1' | x |
| articleSeq | Article sequence inside an issue, first article '1' | x |
| pages| For example "23-45" | |
| language| Article language "en", "fi", "sv", "de", "fr" | x |
| keywords| Word 1; Word 2; Word3 | |
Expand Down Expand Up @@ -108,6 +108,9 @@ de - German
## Licence
The conversion tool is distributed under the GNU GPL v3.

## Changes in version 1.4.0.0 (Aug 2023)
- Support OJS 3.3

## Changes in version 1.3.1.0 (Mar 2021)
- Support OJS 3.2

Expand Down
74 changes: 43 additions & 31 deletions convert.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@
}

// The default locale. For alternative locales use language field. For additional locales use locale:fieldName.
$defaultLocale = 'en_US';
$defaultLocale = 'de_DE';

// The uploader account name
$uploader = "admin";

// Default author name. If no author is given for an article, this name is used instead.
$defaultAuthor['givenname'] = "Editorial Board";

// Default user group (localized)
$defaultUserGroupRef = array(
'en_US' => 'Author',
'de_DE' => 'Autor/in',
'sv_SE' => 'Författare'
);

// Location of full text files
$filesFolder = dirname(__FILE__) . "/". $files ."/";

Expand All @@ -53,7 +60,7 @@
);

// PHPExcel settings
error_reporting(E_ALL);
// error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/Helsinki');
Expand Down Expand Up @@ -126,7 +133,6 @@
$sections[$article['issueDatepublished']][$article['sectionAbbrev']] = $article['sectionTitle'];
}


/*
* Create XML
* --------------------
Expand All @@ -135,9 +141,10 @@
echo date('H:i:s') , " Starting XML output" , EOL;
$currentIssueDatepublished = null;
$currentYear = null;
$fileId = 1;
$submission_file_id = 1;
$authorId = 1;
$submissionId = 1;
$file_id = 1;

foreach ($articles as $key => $article){

Expand Down Expand Up @@ -200,7 +207,7 @@
fwrite ($xmlfile,"\t\t<sections>\r\n");

foreach ($sections[$article['issueDatepublished']] as $sectionAbbrev => $sectionTitle){
fwrite ($xmlfile,"\t\t\t<section ref=\"".htmlentities($sectionAbbrev, ENT_XML1)."\">\r\n");
fwrite ($xmlfile,"\t\t\t<section ref=\"".htmlentities($sectionAbbrev, ENT_XML1)."\" seq=\"".htmlentities("0", ENT_XML1)."\">\r\n");
fwrite ($xmlfile,"\t\t\t\t<abbrev locale=\"".$defaultLocale."\">".htmlentities($sectionAbbrev, ENT_XML1)."</abbrev>\r\n");
fwrite ($xmlfile,"\t\t\t\t<title locale=\"".$defaultLocale."\"><![CDATA[".$sectionTitle."]]></title>\r\n");
fwrite ($xmlfile, searchLocalisations('sectionTitle', $article, 3));
Expand Down Expand Up @@ -260,49 +267,54 @@
else {
echo date('H:i:s') , " ERROR: You need to enable fileinfo or mime_magic extension.", EOL;
}
$fileExtension = pathinfo($file)['extension'];

$fileContents = file_get_contents ($file);

fwrite ($xmlfile,"\t\t\t<submission_file xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" stage=\"proof\" id=\"".$fileId."\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n");

fwrite ($xmlfile,"\t\t\t<submission_file xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" stage=\"proof\" id=\"".$submission_file_id."\" file_id=\"".$file_id."\" uploader=\"".$uploader."\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\" genre=\"".trim($article['fileGenre'.$i])."\">\r\n");
fwrite ($xmlfile,"\t\t\t\t<name locale=\"".$articleLocale."\">". trim(htmlentities($article['file'.$i], ENT_XML1)) ."</name>\r\n");
if (empty($article['fileGenre'.$i]))
$article['fileGenre'.$i] = "Article Text";

fwrite ($xmlfile,"\t\t\t\t<revision number=\"1\" genre=\"".trim($article['fileGenre'.$i])."\" filename=\"". trim(htmlentities($article['file'.$i], ENT_XML1)) . "\" filesize=\"".$fileSize."\" filetype=\"".$fileType."\" uploader=\"".$uploader."\">\r\n");
fwrite ($xmlfile,"\t\t\t\t<file id=\"".$file_id."\" filesize=\"".$fileSize."\" extension=\"".$fileExtension."\">\r\n");

fwrite ($xmlfile,"\t\t\t\t<name locale=\"".$articleLocale."\">". trim(htmlentities($article['file'.$i], ENT_XML1)) ."</name>\r\n");
fwrite ($xmlfile,"\t\t\t\t<embed encoding=\"base64\">");
fwrite ($xmlfile, base64_encode($fileContents));
fwrite ($xmlfile,"\t\t\t\t</embed>\r\n");

fwrite ($xmlfile,"\t\t\t\t</revision>\r\n");
fwrite ($xmlfile,"\t\t\t\t</file>\r\n");
fwrite ($xmlfile,"\t\t\t</submission_file>\r\n\r\n");

# save galley data
$galleys[$fileId] = "\t\t\t\t<article_galley xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$locales[trim($article['fileLocale'.$i])]."\" approved=\"false\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n";
$galleys[$fileId] .= "\t\t\t\t\t<name locale=\"".$fileLocale."\">".$article['fileLabel'.$i]."</name>\r\n";
$galleys[$submission_file_id] = "\t\t\t\t<article_galley xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$locales[trim($article['fileLocale'.$i])]."\" approved=\"false\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n";
$galleys[$submission_file_id] .= "\t\t\t\t\t<name locale=\"".$fileLocale."\">".$article['fileLabel'.$i]."</name>\r\n";

$galleys[$fileId] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name');
$galleys[$fileId] .= "\t\t\t\t\t<seq>".$fileSeq."</seq>\r\n";
$galleys[$fileId] .= "\t\t\t\t\t<submission_file_ref id=\"".$fileId."\" revision=\"1\"/>\r\n";
$galleys[$fileId] .= "\t\t\t\t</article_galley>\r\n\r\n";
$galleys[$submission_file_id] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name');
$galleys[$submission_file_id] .= "\t\t\t\t\t<seq>".$fileSeq."</seq>\r\n";
$galleys[$submission_file_id] .= "\t\t\t\t\t<submission_file_ref id=\"".$submission_file_id."\"/>\r\n";
$galleys[$submission_file_id] .= "\t\t\t\t</article_galley>\r\n\r\n";

$fileId++;
$submission_file_id++;
}
if (preg_match("@^https?://@", $article['file'.$i]) && $article['file'.$i] != "") {
# save remote galley data
$galleys[$fileId] = "\t\t\t\t<article_galley xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$locales[trim($article['fileLocale'.$i])]."\" approved=\"false\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n";
$galleys[$fileId] .= "\t\t\t\t\t<name locale=\"".$fileLocale."\">".$article['fileLabel'.$i]."</name>\r\n";
$galleys[$fileId] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name');
$galleys[$fileId] .= "\t\t\t\t\t<seq>".$fileSeq."</seq>\r\n";
$galleys[$fileId] .= "\t\t\t\t\t<remote src=\"" . trim(htmlentities($article['file'.$i], ENT_XML1)) . "\" />\r\n";
$galleys[$fileId] .= "\t\t\t\t</article_galley>\r\n\r\n";
$galleys[$submission_file_id] = "\t\t\t\t<article_galley xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$locales[trim($article['fileLocale'.$i])]."\" approved=\"false\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n";
$galleys[$submission_file_id] .= "\t\t\t\t\t<name locale=\"".$fileLocale."\">".$article['fileLabel'.$i]."</name>\r\n";
$galleys[$submission_file_id] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name');
$galleys[$submission_file_id] .= "\t\t\t\t\t<seq>".$fileSeq."</seq>\r\n";
$galleys[$submission_file_id] .= "\t\t\t\t\t<remote src=\"" . trim(htmlentities($article['file'.$i], ENT_XML1)) . "\" />\r\n";
$galleys[$submission_file_id] .= "\t\t\t\t</article_galley>\r\n\r\n";
}
$fileSeq++;
$file_id++;
}

# Publication
fwrite ($xmlfile,"\t\t\t<publication xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$articleLocale."\" version=\"1\" status=\"3\" primary_contact_id=\"".$authorId."\" url_path=\"\" seq=\"0\" date_published=\"".$article['issueDatepublished']."\" section_ref=\"".htmlentities($article['sectionAbbrev'], ENT_XML1)."\" access_status=\"0\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n\r\n");
if (array_key_exists('articleSeq', $article)) {
fwrite ($xmlfile,"\t\t\t<publication xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$articleLocale."\" version=\"1\" status=\"3\" primary_contact_id=\"".$authorId."\" url_path=\"\" seq=\"".$article['articleSeq']."\" date_published=\"".$article['issueDatepublished']."\" section_ref=\"".htmlentities($article['sectionAbbrev'], ENT_XML1)."\" access_status=\"0\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n\r\n");
} else {
fwrite ($xmlfile,"\t\t\t<publication xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" locale=\"".$articleLocale."\" version=\"1\" status=\"3\" primary_contact_id=\"".$authorId."\" url_path=\"\" date_published=\"".$article['issueDatepublished']."\" section_ref=\"".htmlentities($article['sectionAbbrev'], ENT_XML1)."\" access_status=\"0\" xsi:schemaLocation=\"http://pkp.sfu.ca native.xsd\">\r\n\r\n");
}
fwrite ($xmlfile,"\t\t\t\t<id type=\"internal\" advice=\"ignore\">".$submissionId."</id>\r\n\r\n");

# DOI
Expand Down Expand Up @@ -383,7 +395,7 @@

if ($article['authorFirstname'.$i]) {

fwrite ($xmlfile,"\t\t\t\t\t<author include_in_browse=\"true\" user_group_ref=\"Author\" seq=\"0\" id=\"".$authorId."\">\r\n");
fwrite ($xmlfile,"\t\t\t\t\t<author include_in_browse=\"true\" user_group_ref=\"".$defaultUserGroupRef[$defaultLocale]."\" seq=\"".$i."\" id=\"".$authorId."\">\r\n");

fwrite ($xmlfile,"\t\t\t\t\t\t<givenname locale=\"".$articleLocale."\"><![CDATA[".$article['authorFirstname'.$i].(!empty($article['authorMiddlename'.$i]) ? ' '.$article['authorMiddlename'.$i] : '')."]]></givenname>\r\n");
if (!empty($article['authorLastname'.$i])){
Expand Down Expand Up @@ -422,7 +434,7 @@

# If no authors are given, use default author name
if (!$article['authorFirstname1']){
fwrite ($xmlfile,"\t\t\t\t\t<author primary_contact=\"true\" user_group_ref=\"Author\" seq=\"0\" id=\"".$authorId."\">\r\n");
fwrite ($xmlfile,"\t\t\t\t\t<author primary_contact=\"true\" user_group_ref=\"".$defaultUserGroupRef[$defaultLocale]."\" seq=\"0\" id=\"".$authorId."\">\r\n");
fwrite ($xmlfile,"\t\t\t\t\t\t<givenname><![CDATA[".$defaultAuthor['givenname']."]]></givenname>\r\n");
fwrite ($xmlfile,"\t\t\t\t\t\t<email><![CDATA[]]></email>\r\n");
fwrite ($xmlfile,"\t\t\t\t\t</author>\r\n");
Expand Down Expand Up @@ -474,7 +486,7 @@ function searchLocalisations($key, $input, $intend, $tag = null, $flags = null)

$nodes = "";
$pattern = "/:".$key."/";
$values = array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input), $flags)));
$values = array_intersect_key($input, array_filter(array_flip(preg_grep($pattern, array_keys($input), $flags ?? 0))));

foreach ($values as $keyval => $value){
if ($value != ""){
Expand All @@ -490,7 +502,7 @@ function searchLocalisations($key, $input, $intend, $tag = null, $flags = null)
}

# Function for searching alternative locales for a given taxonomy field
function searchTaxonomyLocalisations($key, $key_singular, $input, $intend, $flags = null) {
function searchTaxonomyLocalisations($key, $key_singular, $input, $intend, $flags = 0) {
global $locales;

$nodes = "";
Expand Down Expand Up @@ -534,7 +546,7 @@ function createArray($sheet) {
for ($row = 2; $row <= $highestrow; $row++) {
$a = array();
for ($column = 1; $column <= $columncount; $column++) {
if (strpos($header[$column], "bstract") !== false) {
if (strpos($header[$column], "abstract") !== false) {
if ($sheet->getCellByColumnAndRow($column,$row)->getValue() instanceof \PhpOffice\PhpSpreadsheet\RichText\RichText) {
$value = $sheet->getCellByColumnAndRow($column,$row)->getValue();
$elements = $value->getRichTextElements();
Expand Down Expand Up @@ -590,7 +602,7 @@ function countMaxAuthors($sheet) {
$header = $headerRow[0];
$authorFirstnameValues = array();
foreach ($header as $headerValue) {
if (strpos($headerValue, "authorFirstname") !== false) {
if ($headerValue && strpos($headerValue, "authorFirstname") !== false) {
$authorFirstnameValues[] = (int) trim(str_replace("authorFirstname", "", $headerValue));
}
}
Expand All @@ -604,7 +616,7 @@ function countMaxFiles($sheet) {
$header = $headerRow[0];
$fileValues = array();
foreach ($header as $headerValue) {
if (strpos($headerValue, "fileLabel") !== false) {
if ($headerValue && strpos($headerValue, "fileLabel") !== false) {
$fileValues[] = (int) trim(str_replace("fileLabel", "", $headerValue));
}
}
Expand Down

0 comments on commit bc35149

Please sign in to comment.