diff --git a/README.md b/README.md index 460b2f7..63f1f6d 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 | | @@ -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 diff --git a/convert.php b/convert.php old mode 100755 new mode 100644 index 745151b..2046d2c --- a/convert.php +++ b/convert.php @@ -27,7 +27,7 @@ } // 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"; @@ -35,6 +35,13 @@ // 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 ."/"; @@ -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'); @@ -126,7 +133,6 @@ $sections[$article['issueDatepublished']][$article['sectionAbbrev']] = $article['sectionTitle']; } - /* * Create XML * -------------------- @@ -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){ @@ -200,7 +207,7 @@ fwrite ($xmlfile,"\t\t\r\n"); foreach ($sections[$article['issueDatepublished']] as $sectionAbbrev => $sectionTitle){ - fwrite ($xmlfile,"\t\t\t
\r\n"); + fwrite ($xmlfile,"\t\t\t
\r\n"); fwrite ($xmlfile,"\t\t\t\t".htmlentities($sectionAbbrev, ENT_XML1)."\r\n"); fwrite ($xmlfile,"\t\t\t\t<![CDATA[".$sectionTitle."]]>\r\n"); fwrite ($xmlfile, searchLocalisations('sectionTitle', $article, 3)); @@ -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\r\n"); - + fwrite ($xmlfile,"\t\t\t\r\n"); + fwrite ($xmlfile,"\t\t\t\t". trim(htmlentities($article['file'.$i], ENT_XML1)) ."\r\n"); if (empty($article['fileGenre'.$i])) $article['fileGenre'.$i] = "Article Text"; - fwrite ($xmlfile,"\t\t\t\t\r\n"); + fwrite ($xmlfile,"\t\t\t\t\r\n"); - fwrite ($xmlfile,"\t\t\t\t". trim(htmlentities($article['file'.$i], ENT_XML1)) ."\r\n"); fwrite ($xmlfile,"\t\t\t\t"); fwrite ($xmlfile, base64_encode($fileContents)); fwrite ($xmlfile,"\t\t\t\t\r\n"); - fwrite ($xmlfile,"\t\t\t\t\r\n"); + fwrite ($xmlfile,"\t\t\t\t\r\n"); fwrite ($xmlfile,"\t\t\t\r\n\r\n"); # save galley data - $galleys[$fileId] = "\t\t\t\t\r\n"; - $galleys[$fileId] .= "\t\t\t\t\t".$article['fileLabel'.$i]."\r\n"; + $galleys[$submission_file_id] = "\t\t\t\t\r\n"; + $galleys[$submission_file_id] .= "\t\t\t\t\t".$article['fileLabel'.$i]."\r\n"; - $galleys[$fileId] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name'); - $galleys[$fileId] .= "\t\t\t\t\t".$fileSeq."\r\n"; - $galleys[$fileId] .= "\t\t\t\t\t\r\n"; - $galleys[$fileId] .= "\t\t\t\t\r\n\r\n"; + $galleys[$submission_file_id] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name'); + $galleys[$submission_file_id] .= "\t\t\t\t\t".$fileSeq."\r\n"; + $galleys[$submission_file_id] .= "\t\t\t\t\t\r\n"; + $galleys[$submission_file_id] .= "\t\t\t\t\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\r\n"; - $galleys[$fileId] .= "\t\t\t\t\t".$article['fileLabel'.$i]."\r\n"; - $galleys[$fileId] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name'); - $galleys[$fileId] .= "\t\t\t\t\t".$fileSeq."\r\n"; - $galleys[$fileId] .= "\t\t\t\t\t\r\n"; - $galleys[$fileId] .= "\t\t\t\t\r\n\r\n"; + $galleys[$submission_file_id] = "\t\t\t\t\r\n"; + $galleys[$submission_file_id] .= "\t\t\t\t\t".$article['fileLabel'.$i]."\r\n"; + $galleys[$submission_file_id] .= searchLocalisations('fileLabel'.$i, $article, 5, 'name'); + $galleys[$submission_file_id] .= "\t\t\t\t\t".$fileSeq."\r\n"; + $galleys[$submission_file_id] .= "\t\t\t\t\t\r\n"; + $galleys[$submission_file_id] .= "\t\t\t\t\r\n\r\n"; } $fileSeq++; + $file_id++; } # Publication - fwrite ($xmlfile,"\t\t\t\r\n\r\n"); + if (array_key_exists('articleSeq', $article)) { + fwrite ($xmlfile,"\t\t\t\r\n\r\n"); + } else { + fwrite ($xmlfile,"\t\t\t\r\n\r\n"); + } fwrite ($xmlfile,"\t\t\t\t".$submissionId."\r\n\r\n"); # DOI @@ -383,7 +395,7 @@ if ($article['authorFirstname'.$i]) { - fwrite ($xmlfile,"\t\t\t\t\t\r\n"); + fwrite ($xmlfile,"\t\t\t\t\t\r\n"); fwrite ($xmlfile,"\t\t\t\t\t\t\r\n"); if (!empty($article['authorLastname'.$i])){ @@ -422,7 +434,7 @@ # If no authors are given, use default author name if (!$article['authorFirstname1']){ - fwrite ($xmlfile,"\t\t\t\t\t\r\n"); + fwrite ($xmlfile,"\t\t\t\t\t\r\n"); fwrite ($xmlfile,"\t\t\t\t\t\t\r\n"); fwrite ($xmlfile,"\t\t\t\t\t\t\r\n"); fwrite ($xmlfile,"\t\t\t\t\t\r\n"); @@ -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 != ""){ @@ -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 = ""; @@ -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(); @@ -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)); } } @@ -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)); } }