Skip to content
Snippets Groups Projects
Commit a3b2e0f6 authored by Olav Morken's avatar Olav Morken
Browse files

Template: Add compatibility with old dictionary format.

Fixes issue 263.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2148 44740490-163a-0410-bde0-09ae8108e29a
parent b4280552
No related branches found
No related tags found
No related merge requests found
...@@ -434,49 +434,83 @@ class SimpleSAML_XHTML_Template { ...@@ -434,49 +434,83 @@ class SimpleSAML_XHTML_Template {
/** /**
* Read a dictionary file. * Read a dictionary file in json format.
* *
* @param $filename The absolute path to the dictionary file. * @param string $filename The absolute path to the dictionary file, minus the .definition.json ending.
* @return The translation array which was found in the dictionary file. * @return array The translation array from the file.
*/ */
private function readDictionaryFile($filename) { private function readDictionaryJSON($filename) {
assert('is_string($filename)');
$definitionFile = $filename . '.definition.json'; $definitionFile = $filename . '.definition.json';
$translationFile = $filename . '.translation.json'; assert('file_exists($definitionFile)');
SimpleSAML_Logger::debug('Template: Reading [' . $filename . ']');
if (!file_exists($definitionFile)) {
SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $definitionFile . ']');
return array();
}
$fileContent = file_get_contents($definitionFile); $fileContent = file_get_contents($definitionFile);
$fileArray = json_decode($fileContent, TRUE); $lang = json_decode($fileContent, TRUE);
if (empty($fileArray)) { if (empty($lang)) {
SimpleSAML_Logger::error('Invalid dictionary definition file [' . $definitionFile . ']'); SimpleSAML_Logger::error('Invalid dictionary definition file [' . $definitionFile . ']');
return array(); return array();
} }
$lang = json_decode($fileContent, TRUE);
$moreTrans = NULL; $translationFile = $filename . '.translation.json';
if (file_exists($translationFile)) { if (file_exists($translationFile)) {
$fileContent = file_get_contents($translationFile); $fileContent = file_get_contents($translationFile);
$moreTrans = json_decode($fileContent, TRUE); $moreTrans = json_decode($fileContent, TRUE);
if (!empty($moreTrans)) {
$lang = self::lang_merge($lang, $moreTrans);
}
}
return $lang;
}
/**
* Read a dictionary file in PHP format.
*
* @param string $filename The absolute path to the dictionary file.
* @return array The translation array from the file.
*/
private function readDictionaryPHP($filename) {
$phpFile = $filename . '.php';
assert('file_exists($phpFile)');
$lang = NULL;
include($phpFile);
if (isset($lang)) {
return $lang;
} }
if (!empty($moreTrans))
$lang = self::lang_merge($lang, $moreTrans);
// echo '<pre>'; print_r($lang); exit; return array();
}
return $lang;
/**
* Read a dictionary file.
*
* @param $filename The absolute path to the dictionary file.
* @return The translation array which was found in the dictionary file.
*/
private function readDictionaryFile($filename) {
assert('is_string($filename)');
SimpleSAML_Logger::debug('Template: Reading [' . $filename . ']');
$jsonFile = $filename . '.definition.json';
if (file_exists($jsonFile)) {
return $this->readDictionaryJSON($filename);
}
$phpFile = $filename . '.php';
if (file_exists($phpFile)) {
return $this->readDictionaryPHP($filename);
}
SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']');
return array();
} }
// Merge two translation arrays. // Merge two translation arrays.
public static function lang_merge($def, $lang) { public static function lang_merge($def, $lang) {
foreach($def AS $key => $value) { foreach($def AS $key => $value) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment