This repository was archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomLocaleHandler.inc.php
More file actions
102 lines (78 loc) · 3.05 KB
/
CustomLocaleHandler.inc.php
File metadata and controls
102 lines (78 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @file plugins/generic/customLocale/CustomLocaleHandler.inc.php
*
* Copyright (c) 2016 Language Science Press
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class CustomLocaleHandler
*/
import('classes.handler.Handler');
class CustomLocaleHandler extends Handler {
function CustomLocaleHandler() {
parent::Handler();
}
function printCustomLocaleChanges($args, $request) {
$press = Request::getPress();
$pressId = $press->getId();
$publicFilesDir = Config::getVar('files', 'public_files_dir');
$customLocaleDir = $publicFilesDir . DIRECTORY_SEPARATOR . 'presses' . DIRECTORY_SEPARATOR . $pressId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR;
$absolutePath = dirname(__FILE__);
$ompPath = str_replace('/plugins/generic/customLocale','',$absolutePath);
$customLocalePath = $ompPath.DIRECTORY_SEPARATOR .$customLocaleDir;
// get all xml-files in the custom locale directory
$directory = new RecursiveDirectoryIterator($customLocalePath);
$iterator = new RecursiveIteratorIterator($directory);
$regex = new RegexIterator($iterator, '/^.+\.xml$/i', RecursiveRegexIterator::GET_MATCH);
$files = iterator_to_array($regex);
$fileKeys = array_keys($files);
import('lib.pkp.classes.file.FileManager');
import('lib.pkp.classes.file.EditableLocaleFile');
$output = "";
// iterate through all customized files
for ($i=0; $i<sizeof($fileKeys);$i++) {
$pathToFile = $fileKeys[$i];
$posLib = strpos($pathToFile,'lib');
$posLocale = strpos($pathToFile,'locale');
$posPlugins = strpos($pathToFile,'plugins');
$ompFile = '';
if (!$posLib===false) {
$ompFile = substr($pathToFile,$posLib);
} else if (!$posPlugins===false) {
$ompFile = substr($pathToFile,$posPlugins);
}
else {
$ompFile = substr($pathToFile,$posLocale);
}
$fileManagerCustomized = new FileManager();
$localeContentsCustomized = null;
if ($fileManagerCustomized->fileExists($fileKeys[$i])) {
$localeContentsCustomized = EditableLocaleFile::load($fileKeys[$i]);
}
$fileManager = new FileManager();
$localeContents = null;
if ($fileManager->fileExists($ompFile)) {
$localeContents = EditableLocaleFile::load($ompFile);
}
$localeKeys = array_keys($localeContentsCustomized);
if (sizeof($localeKeys)>0) {
$output = $output . "\nFile: " . $ompFile;
}
for ($ii=0; $ii<sizeof($localeKeys);$ii++) {
$pos = $ii+1;
$output = $output . "\n\n" . $pos .". locale key: " . $localeKeys[$ii];
$output = $output . "\n\n original content: " . $localeContents[$localeKeys[$ii]];
$output = $output . "\n customized content: " . $localeContentsCustomized[$localeKeys[$ii]];
}
if (sizeof($localeKeys)>0) {
$output = $output . "\n\n__________________________________________________________________________________\n\n";
}
}
$filename = 'customLocale_changes.txt';
header("Content-Type: text/plain");
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Length: " . strlen($output));
echo $output;
}
}
?>