Revision: 2148
Author: olavmrk
Date: Thu Jan 28 01:29:55 2010
Log: Template: Add compatibility with old dictionary format.
Fixes issue 263.
http://code.google.com/p/simplesamlphp/source/detail?r=2148
Modified:
/trunk/lib/SimpleSAML/XHTML/Template.php
=======================================
--- /trunk/lib/SimpleSAML/XHTML/Template.php Tue Jan 12 03:56:33 2010
+++ /trunk/lib/SimpleSAML/XHTML/Template.php Thu Jan 28 01:29:55 2010
@@ -434,49 +434,83 @@
/**
- * Read a dictionary file.
+ * Read a dictionary file in json format.
*
- * @param $filename The absolute path to the dictionary file.
- * @return The translation array which was found in the dictionary file.
+ * @param string $filename The absolute path to the dictionary file,
minus the .definition.json ending.
+ * @return array The translation array from the file.
*/
- private function readDictionaryFile($filename) {
- assert('is_string($filename)');
-
+ private function readDictionaryJSON($filename) {
$definitionFile = $filename . '.definition.json';
- $translationFile = $filename . '.translation.json';
-
- 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();
- }
-
+ assert('file_exists($definitionFile)');
+
$fileContent = file_get_contents($definitionFile);
- $fileArray = json_decode($fileContent, TRUE);
-
- if (empty($fileArray)) {
+ $lang = json_decode($fileContent, TRUE);
+
+ if (empty($lang)) {
SimpleSAML_Logger::error('Invalid dictionary definition file [' .
$definitionFile . ']');
return array();
}
-
- $lang = json_decode($fileContent, TRUE);
-
- $moreTrans = NULL;
+
+ $translationFile = $filename . '.translation.json';
if (file_exists($translationFile)) {
$fileContent = file_get_contents($translationFile);
$moreTrans = json_decode($fileContent, TRUE);
-
- }
- if (!empty($moreTrans))
- $lang = self::lang_merge($lang, $moreTrans);
-
- // echo '<pre>'; print_r($lang); exit;
-
- return $lang;
- }
-
+ 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;
+ }
+
+ return array();
+ }
+
+
+ /**
+ * 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.
public static function lang_merge($def, $lang) {
foreach($def AS $key => $value) {
--
You received this message because you are subscribed to the Google Groups
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simplesamlphp-commits?hl=en.