Open Monograph Press  3.3.0
CustomLocaleHandler.inc.php
1 <?php
2 
12 import('classes.handler.Handler');
13 
20  function printCustomLocaleChanges($args, $request) {
21  $context = $request->getContext();
22 
23  $contextFileManager = new ContextFileManager($context->getId());
24  $customLocaleDir = $contextFileManager->getBasePath() . 'customLocale';
25  if (!file_exists($customLocaleDir) || !is_dir($customLocaleDir)) throw new Exception("Path \"$customLocaleDir\" does not exist!");
26 
27  // get all xml-files in the custom locale directory
28  $directory = new RecursiveDirectoryIterator($customLocaleDir);
29  $iterator = new RecursiveIteratorIterator($directory);
30  $regex = new RegexIterator($iterator, '/^.+\.xml$/i', RecursiveRegexIterator::GET_MATCH);
31  $files = iterator_to_array($regex);
32  $fileKeys = array_keys($files);
33 
34  $output = '';
35 
36  import('lib.pkp.classes.i18n.LocaleFile');
37  // iterate through all customized files
38  foreach ($fileKeys as $pathToFile) {
39  $posLib = strpos($pathToFile,'lib');
40  $posLocale = strpos($pathToFile,'locale');
41  $posPlugins = strpos($pathToFile,'plugins');
42 
43  $localeFile = '';
44  if (!$posLib===false) {
45  $localeFile = substr($pathToFile,$posLib);
46  } else if (!$posPlugins===false) {
47  $localeFile = substr($pathToFile,$posPlugins);
48  }
49  else {
50  $localeFile = substr($pathToFile,$posLocale);
51  }
52 
53  $localeContentsCustomized = null;
54  if ($contextFileManager->fileExists($pathToFile)) {
55  $localeContentsCustomized = LocaleFile::load($pathToFile);
56  }
57 
58  $localeContents = null;
59  if ($contextFileManager->fileExists($localeFile)) {
60  $localeContents = LocaleFile::load($localeFile);
61  }
62 
63  $localeKeys = array_keys($localeContentsCustomized);
64 
65  if (sizeof($localeKeys)>0) {
66  $output = $output . "\nFile: " . $localeFile;
67  }
68 
69  foreach ($localeKeys as $index => $localeKey) {
70  $output = $output . "\n\n" . $index+1 . '. locale key: ' . $localeKey;
71  $output = $output . "\n\n original content: " . $localeContents[$localeKey];
72  $output = $output . "\n customized content: " . $localeContentsCustomized[$localeKey];
73  }
74  if (!empty($localeKeys)) {
75  $output = $output . "\n\n__________________________________________________________________________________\n\n";
76  }
77  }
78 
79  $filename = 'customLocale_changes.txt';
80  header('Content-Type: text/plain');
81  header('Content-Disposition: attachment; filename="'.$filename.'"');
82  header('Content-Length: ' . strlen($output));
83  echo $output;
84  }
85 }
86 
CustomLocaleHandler\printCustomLocaleChanges
printCustomLocaleChanges($args, $request)
Definition: CustomLocaleHandler.inc.php:20
ContextFileManager
Class defining operations for private context file management.
Definition: ContextFileManager.inc.php:19
LocaleFile\load
static & load($filename)
Definition: LocaleFile.inc.php:129
Handler
Base request handler application class.
Definition: Handler.inc.php:18
CustomLocaleHandler
Definition: CustomLocaleHandler.inc.php:14