From ca63a255506685d489c53f2e1939ad0906d45d70 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Wed, 2 Jul 2008 13:03:07 +0000 Subject: [PATCH] Template: add readDictionaryFile()-method and change includeLanguageFile() to use it. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@752 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/XHTML/Template.php | 48 ++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index 73b64eb66..ea93c0cc3 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -349,28 +349,44 @@ class SimpleSAML_XHTML_Template { $filebase = $this->configuration->getPathValue('dictionarydir'); } - - SimpleSAML_Logger::info('Template: Loading [' . $filebase . $file . ']'); - - if (!file_exists($filebase . $file)) { - SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filebase . $file . ']'); - return; + + $lang = $this->readDictionaryFile($filebase . $file); + if (is_array($this->langtext)) { + SimpleSAML_Logger::info('Template: Merging language array. Loading [' . $file . ']'); + $this->langtext = array_merge($this->langtext, $lang); + } else { + SimpleSAML_Logger::info('Template: Setting new language array. Loading [' . $file . ']'); + $this->langtext = $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::info('Template: Reading [' . $filename . ']'); + + if (!file_exists($filename)) { + SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']'); + return array(); } - include($filebase . $file); + + $lang = NULL; + include($filename); if (isset($lang)) { - if (is_array($this->langtext)) { - SimpleSAML_Logger::info('Template: Merging language array. Loading [' . $file . ']'); - $this->langtext = array_merge($this->langtext, $lang); - } else { - SimpleSAML_Logger::info('Template: Setting new language array. Loading [' . $file . ']'); - $this->langtext = $lang; - } + return $lang; } - - + return array(); } + /** * Show the template to the user. */ -- GitLab