Skip to content
Snippets Groups Projects
Commit 6492ce36 authored by Hanne Moa's avatar Hanne Moa
Browse files

Fixed comments from previous pull-request

parent d2759355
No related branches found
No related tags found
No related merge requests found
......@@ -423,9 +423,9 @@ $config = array(
'language.cookie.lifetime' => (60 * 60 * 24 * 900),
/**
* Custom getLanguage function called from SimpleSAML_Locale_Language::getLanguage().
* Custom getLanguage function called from SimpleSAML\Locale\Language::getLanguage().
* Function should return language code of one of the available languages or NULL.
* See SimpleSAML_Locale_Language::getLanguage() source code for more info.
* See SimpleSAML\Locale\Language::getLanguage() source code for more info.
*
* This option can be used to implement a custom function for determining
* the default language for the user.
......
<?php
/**
* A minimalistic XHTML PHP based template system implemented for simpleSAMLphp.
* Choosing the language to localize to for our minimalistic XHTML PHP based template system.
*
* @author Andreas Åkre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @author Hanne Moa, UNINETT AS. <hanne.moa@uninett.no>
* @package SimpleSAMLphp
*/
class SimpleSAML_Locale_Language {
namespace SimpleSAML\Locale;
class Language {
/**
* This is the default language map. It is used to map languages codes from the user agent to
......@@ -32,7 +36,7 @@ class SimpleSAML_Locale_Language {
* @param $configuration Configuration object
* @param $defaultDictionary The default dictionary where tags will come from.
*/
function __construct(SimpleSAML_Configuration $configuration) {
function __construct(\SimpleSAML_Configuration $configuration) {
$this->configuration = $configuration;
$this->availableLanguages = $this->configuration->getArray('language.available', array('en'));
......@@ -55,7 +59,7 @@ class SimpleSAML_Locale_Language {
if (in_array($language, $this->availableLanguages, TRUE)) {
$this->language = $language;
if ($setLanguageCookie === TRUE) {
SimpleSAML_Locale_Language::setLanguageCookie($language);
Language::setLanguageCookie($language);
}
}
}
......@@ -85,7 +89,7 @@ class SimpleSAML_Locale_Language {
}
// Language is provided in a stored COOKIE
$languageCookie = SimpleSAML_Locale_Language::getLanguageCookie();
$languageCookie = Language::getLanguageCookie();
if ($languageCookie !== NULL) {
$this->language = $languageCookie;
return $languageCookie;
......@@ -109,7 +113,7 @@ class SimpleSAML_Locale_Language {
* languages in the header were available.
*/
private function getHTTPLanguage() {
$languageScore = SimpleSAML_Utilities::getAcceptLanguage();
$languageScore = \SimpleSAML_Utilities::getAcceptLanguage();
/* For now we only use the default language map. We may use a configurable language map
* in the future.
......@@ -185,7 +189,7 @@ class SimpleSAML_Locale_Language {
* @return string|NULL The language, or NULL if unset.
*/
public static function getLanguageCookie() {
$config = SimpleSAML_Configuration::getInstance();
$config = \SimpleSAML_Configuration::getInstance();
$availableLanguages = $config->getArray('language.available', array('en'));
$name = $config->getString('language.cookie.name', 'language');
......@@ -209,7 +213,7 @@ class SimpleSAML_Locale_Language {
assert('is_string($language)');
$language = strtolower($language);
$config = SimpleSAML_Configuration::getInstance();
$config = \SimpleSAML_Configuration::getInstance();
$availableLanguages = $config->getArray('language.available', array('en'));
if (!in_array($language, $availableLanguages, TRUE) || headers_sent()) {
......@@ -224,7 +228,7 @@ class SimpleSAML_Locale_Language {
'httponly' => FALSE,
);
SimpleSAML_Utilities::setCookie($name, $language, $params, FALSE);
\SimpleSAML_Utilities::setCookie($name, $language, $params, FALSE);
}
}
<?php
/**
* A minimalistic XHTML PHP based template system implemented for simpleSAMLphp.
* The translation-relevant bits from our original minimalistic XHTML PHP based template system.
*
* @author Andreas Åkre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @author Hanne Moa, UNINETT AS. <hanne.moa@uninett.no>
* @package SimpleSAMLphp
*/
class SimpleSAML_Locale_Translate {
namespace SimpleSAML\Locale;
class Translate {
private $configuration = null;
......@@ -31,15 +35,15 @@ class SimpleSAML_Locale_Translate {
* @param $configuration Configuration object
* @param $defaultDictionary The default dictionary where tags will come from.
*/
function __construct(SimpleSAML_Configuration $configuration, $defaultDictionary = NULL) {
function __construct(\SimpleSAML_Configuration $configuration, $defaultDictionary = NULL) {
$this->configuration = $configuration;
$this->language = new SimpleSAML_Locale_Language($configuration);
$this->language = new Language($configuration);
if($defaultDictionary !== NULL && substr($defaultDictionary, -4) === '.php') {
/* For backwards compatibility - print warning. */
$backtrace = debug_backtrace();
$where = $backtrace[0]['file'] . ':' . $backtrace[0]['line'];
SimpleSAML_Logger::warning('Deprecated use of new SimpleSAML_Locale_Translate(...) at ' . $where .
\SimpleSAML_Logger::warning('Deprecated use of new SimpleSAML\Locale\Translate(...) at ' . $where .
'. The last parameter is now a dictionary name, which should not end in ".php".');
$this->defaultDictionary = substr($defaultDictionary, 0, -4);
......@@ -66,7 +70,7 @@ class SimpleSAML_Locale_Translate {
if($sepPos !== FALSE) {
$module = substr($name, 0, $sepPos);
$fileName = substr($name, $sepPos + 1);
$dictDir = SimpleSAML_Module::getModuleDir($module) . '/dictionaries/';
$dictDir = \SimpleSAML_Module::getModuleDir($module) . '/dictionaries/';
} else {
$dictDir = $this->configuration->getPathValue('dictionarydir', 'dictionaries/');
$fileName = $name;
......@@ -212,12 +216,12 @@ class SimpleSAML_Locale_Translate {
/* Old style call to t(...). Print warning to log. */
$backtrace = debug_backtrace();
$where = $backtrace[0]['file'] . ':' . $backtrace[0]['line'];
SimpleSAML_Logger::warning('Deprecated use of SimpleSAML_Template::t(...) at ' . $where .
\SimpleSAML_Logger::warning('Deprecated use of SimpleSAML_Template::t(...) at ' . $where .
'. Please update the code to use the new style of parameters.');
/* For backwards compatibility. */
if(!$replacements && $this->getTag($tag) === NULL) {
SimpleSAML_Logger::warning('Code which uses $fallbackdefault === FALSE shouls be' .
\SimpleSAML_Logger::warning('Code which uses $fallbackdefault === FALSE shouls be' .
' updated to use the getTag-method instead.');
return NULL;
}
......@@ -231,7 +235,7 @@ class SimpleSAML_Locale_Translate {
$tagData = $this->getTag($tag);
if($tagData === NULL) {
/* Tag not found. */
SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not translated at all.');
\SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not translated at all.');
return $this->t_not_translated($tag, $fallbackdefault);
}
}
......@@ -280,7 +284,7 @@ class SimpleSAML_Locale_Translate {
throw new Exception("Inline translation should be string or array. Is " . gettype($translation) . " now!");
}
SimpleSAML_Logger::debug('Template: Adding inline language translation for tag [' . $tag . ']');
\SimpleSAML_Logger::debug('Template: Adding inline language translation for tag [' . $tag . ']');
$this->langtext[$tag] = $translation;
}
......@@ -304,7 +308,7 @@ class SimpleSAML_Locale_Translate {
$lang = $this->readDictionaryFile($filebase . $file);
SimpleSAML_Logger::debug('Template: Merging language array. Loading [' . $file . ']');
\SimpleSAML_Logger::debug('Template: Merging language array. Loading [' . $file . ']');
$this->langtext = array_merge($this->langtext, $lang);
}
......@@ -323,7 +327,7 @@ class SimpleSAML_Locale_Translate {
$lang = json_decode($fileContent, TRUE);
if (empty($lang)) {
SimpleSAML_Logger::error('Invalid dictionary definition file [' . $definitionFile . ']');
\SimpleSAML_Logger::error('Invalid dictionary definition file [' . $definitionFile . ']');
return array();
}
......@@ -369,7 +373,7 @@ class SimpleSAML_Locale_Translate {
private function readDictionaryFile($filename) {
assert('is_string($filename)');
SimpleSAML_Logger::debug('Template: Reading [' . $filename . ']');
\SimpleSAML_Logger::debug('Template: Reading [' . $filename . ']');
$jsonFile = $filename . '.definition.json';
if (file_exists($jsonFile)) {
......@@ -382,7 +386,7 @@ class SimpleSAML_Locale_Translate {
return $this->readDictionaryPHP($filename);
}
SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']');
\SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']');
return array();
}
......
......@@ -25,7 +25,7 @@ class SimpleSAML_XHTML_Template {
$this->configuration = $configuration;
$this->template = $template;
$this->data['baseurlpath'] = $this->configuration->getBaseURL();
$this->translator = new SimpleSAML_Locale_Translate($configuration, $defaultDictionary = NULL);
$this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary = NULL);
}
/**
......@@ -42,7 +42,7 @@ class SimpleSAML_XHTML_Template {
}
/**
* Wrap Translate->getTranslation
* @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Locale\Translate::getTranslation() instead.
*/
public function getTranslation($translations) {
return $this->translator->getTranslation($translations);
......
......@@ -44,7 +44,7 @@ class sspmod_core_Auth_Process_LanguageAdaptor extends SimpleSAML_Auth_Processin
if (array_key_exists($this->langattr, $attributes))
$attrlang = $attributes[$this->langattr][0];
$lang = SimpleSAML_Locale_Language::getLanguageCookie();
$lang = SimpleSAML\Locale\Language::getLanguageCookie();
if (isset($attrlang))
......@@ -55,7 +55,7 @@ class sspmod_core_Auth_Process_LanguageAdaptor extends SimpleSAML_Auth_Processin
if (isset($attrlang) && !isset($lang)) {
// Language set in attribute but not in cookie - update cookie
SimpleSAML_Locale_Language::setLanguageCookie($attrlang);
SimpleSAML\Locale\Language::setLanguageCookie($attrlang);
} elseif (!isset($attrlang) && isset($lang)) {
// Language set in cookie, but not in attribute. Update attribute
$request['Attributes'][$this->langattr] = array($lang);
......
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