[Mapbender-commits] r2595 - in branches/testbaudson_dev: conf core http/classes http/frames lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jul 7 10:32:52 EDT 2008


Author: christoph
Date: 2008-07-07 10:32:51 -0400 (Mon, 07 Jul 2008)
New Revision: 2595

Added:
   branches/testbaudson_dev/lib/locale.php
Modified:
   branches/testbaudson_dev/conf/mapbender.conf-dist
   branches/testbaudson_dev/core/globalSettings.php
   branches/testbaudson_dev/http/classes/class_locale.php
   branches/testbaudson_dev/http/frames/index.php
Log:
moved class locale to ../lib

moved database wrappers from conf to globalSettings.php

added correct data for gettext 

Modified: branches/testbaudson_dev/conf/mapbender.conf-dist
===================================================================
--- branches/testbaudson_dev/conf/mapbender.conf-dist	2008-07-07 13:57:02 UTC (rev 2594)
+++ branches/testbaudson_dev/conf/mapbender.conf-dist	2008-07-07 14:32:51 UTC (rev 2595)
@@ -23,8 +23,6 @@
 	define("OWNER", "<owner>");
 	define("PW", "<password>");
 	
-	include_once(dirname(__FILE__) . "/../lib/database-mysql.php"); 
-	
 	# --------------------------------------------
 	# database with geos functions
 	# --------------------------------------------
@@ -42,8 +40,6 @@
 	define("DB", "<database>");
 	define("OWNER", "<owner>");
 	define("PW", "<password>");
-	
-	include_once(dirname(__FILE__) . "/../lib/database-pgsql.php"); 
 }
 
 # --------------------------------------------

Modified: branches/testbaudson_dev/core/globalSettings.php
===================================================================
--- branches/testbaudson_dev/core/globalSettings.php	2008-07-07 13:57:02 UTC (rev 2594)
+++ branches/testbaudson_dev/core/globalSettings.php	2008-07-07 14:32:51 UTC (rev 2595)
@@ -20,15 +20,28 @@
 require_once(dirname(__FILE__)."/../conf/mapbender.conf");
 
 //
+// database wrapper
+//
+if(SYS_DBTYPE=="mysql") {
+	require_once(dirname(__FILE__) . "/../lib/database-mysql.php"); 
+}
+else {
+	require_once(dirname(__FILE__) . "/../lib/database-pgsql.php"); 
+}
+
+
+//
 // class for error handling
 //
 require_once(dirname(__FILE__)."/../lib/exception.php");
 
 //
-// I18n wrapper function
+// I18n wrapper function, gettext
 //
 require_once(dirname(__FILE__) . "/../core/i18n.php");
+$localeObj = new Mb_locale($_SESSION["mb_lang"]);
 
+
 //
 // establish database connection
 //

Modified: branches/testbaudson_dev/http/classes/class_locale.php
===================================================================
--- branches/testbaudson_dev/http/classes/class_locale.php	2008-07-07 13:57:02 UTC (rev 2594)
+++ branches/testbaudson_dev/http/classes/class_locale.php	2008-07-07 14:32:51 UTC (rev 2595)
@@ -1,215 +1,3 @@
 <?php
-# $Id$
-# http://www.mapbender.org/index.php/class_locale.php
-# Copyright (C) 2002 CCGIS 
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-
-include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
-require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
-
-/**
- * sets the locale, depending on various settings:
- * 1) a language ID passed to the constructor
- * 2) the browser settings $_SERVER["HTTP_ACCEPT_LANGUAGE"]
- * 3) a default language ID
- * 
- */
-class Mb_locale {
-	var $knownLanguages = null;
-	var $systemLocales = null;
-	var $browserLanguages = null;
-	var $os = null;
-	var $name = null;
-	var $defaultLanguage = "en";
-	var $status = "No locale set.";
-	
-	function Mb_locale($languageId) {
-		if (!$languageId) {
-			$languageId = LANGUAGE;
-		}
-  		$e = new Mb_notice("class_locale: setting locale to " . $languageId);
-		if (USE_I18N) {
-			if (!$this->setCurrentLocale($languageId)) {
-				$e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
-			}
-		}
-		else {
-			$this->setCurrentLocale($this->defaultLanguage);
-		}
-	}
-
-	/**
-	 * Get the current locale, evaluating GET/POST variables, browser languages
-	 * and a default locale (in that preference)
-	 *
-	 * @returns current locale
-	 */
-	function setCurrentLocale($languageId) {
-
-	  	// try to set the locale to $languageId
-		if ($this->checkAndSetLocale($languageId)) {
-			return true;
-	  	}
-	  	else {
-	  		$e = new Mb_notice("class_locale: no input parameter specified.");
-	  	}
-
-		// determine the browser setting and try to set locale according to that
-		if ($this->browserLanguage == null) {
-			$this->setBrowserLanguages();
-		}		
-		foreach ($this->browserLanguages as $lang) {
-			$e = new Mb_notice("trying browser setting " . $lang);
-			if ($this->checkAndSetLocale($lang)) {
-				return true;
-			}
-		}	
-		
-		// set to default language
-		$e = new Mb_notice("trying default language " . $this->defaultLanguage);
-		return $this->checkAndSetLocale($this->defaultLanguage);
-	}
-	
-	/**
-	 * checks if a locale is available; if yes, it is set via setlocale
-	 * 
-	 * @returns true if the the locale is set successfully; otherwise false
-	 */
-	function checkAndSetLocale($languageId) {
-		if ($this->os == null) {
-			$this->os = $this->guessHostOS();
-		}
-		
-		if (!USE_I18N || ($this->os != null && isset($languageId))) {
-			if ($this->isKnownLanguage($languageId)) {
-				
-				if ($this->systemLocales == null) {
-					$this->setSystemLocales();					
-				}
-				
-				$locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];				
-				bindtextdomain(LOCALE_DOMAIN, LOCALE_DIR);
-				textdomain(LOCALE_DOMAIN);
-				if (setlocale(LC_ALL, $locale)) {
-					$this->name = $locale;
-					$_SESSION["mb_lang"] = $languageId;
-					$_SESSION["mb_locale"] = $this->name;
-					$e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
-					return true;
-				}
-				$e = new Mb_notice("locale " . $locale . " not found.");
-
-			}
-		}
-		return false;
-	}
-	
-	/**
-	 * Guess the operating system which on which this code is running
-	 * multiple methods are tested for reliably guessing the os
-	 * 
-	 * @private
-	 * @returns string with os name
-	 */
-	function guessHostOS(){
-	  if (strncasecmp(php_uname(), 'Windows', 7) == 0)
-	    return 'windows';
-	  else if (strncasecmp(php_uname(), 'Linux', 5) == 0)
-	    return 'linux';
-	  else if (strncasecmp(php_uname(), 'OpenBSD', 7) == 0)
-	    return 'bsd';
-	  else if (strncasecmp(php_uname(), 'FreeBSD', 7) == 0)
-	    return 'bsd';  
-	  else {
-	    throw new Mb_exception('unknown platform: could not interpret uname. php_uname() returned '. php_uname().'. Please report to MB developers');
-	    return null;
-	  }
-	}
-
-	/**
-	 * checks if a language is supported
-	 * 
-	 * @returns true if the language is supported; otherwise false
-	 */
-	function isKnownLanguage($languageId) {
-		if ($this->knownLocales == null) {
-			$this->setKnownLanguages();
-		}
-		if (array_key_exists($languageId, $this->knownLanguages)) {
-			return true;
-		}
-		else {
-			$e = new Mb_notice("language " . $languageId . " not supported.");
-		}	
-		return false; 
-	}
-	
-
-
-	/**
-	 * determines the available Locales on this system
-	 */
-	function setSystemLocales() {
-		$this->systemLocales['it_IT'] = array('linux' => 'it_IT.utf8',
-	                                'windows' => 'Italian_Italy.1252',
-	                                'bsd' => 'it_IT',
-	                                'posix' => 'it_IT');
-		$this->systemLocales['de_DE'] = array('linux' => 'de_DE.utf8',
-	                                'windows' => 'German_Germany.1252',
-	                                'bsd' => 'de_DE',
-	                                'posix' => 'it_IT');
-		$this->systemLocales['en_US'] = array('linux' => 'en_US.utf8',
-	                                'windows' => 'English_United States.1252',
-	                                'bsd' => 'en_US',
-	                                'posix' => 'it_IT');
-	}
-	
-	/**
-	 * set the known languages
-	 */
-	function setKnownLanguages() {
-		$this->knownLanguages = array('en_US' => 'en_US',
-                      'en' => 'en_US',
-                      'de_DE' => 'de_DE',
-                      'de' => 'de_DE',
-                      'bg_BG' => 'bg_BG',
-                      'bg' => 'bg_BG',
-                      'es_ES' => 'es_ES',
-                      'es' => 'es_ES',  
-                      'nl_NL' => 'nl_NL',
-                      'nl' => 'nl_NL',                                                                
-                      'gr_GR' => 'gr_GR',
-                      'gr' => 'gr_GR',
-                      'it_IT' => 'it_IT',
-                      'it' => 'it_IT');
-	}
-	
-	/**
-	 * sets the languages accepted by the client browser
-	 */
-	function setBrowserLanguages () {
-		$this->browserLanguages = array();
-		
-	    $bLangs = split(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
-	    foreach ($bLangs as $lang) {
-			if (strpos($lang, ';') === false)
-				array_push($this->browserLanguages, $lang);
-			else
-				array_push($this->browserLanguages, substr($lang, 0, strpos($lang, ';')));
-	    }		
-	}
-}
+include_once(dirname(__FILE__)."/../../lib/locale.php");
 ?>
\ No newline at end of file

Modified: branches/testbaudson_dev/http/frames/index.php
===================================================================
--- branches/testbaudson_dev/http/frames/index.php	2008-07-07 13:57:02 UTC (rev 2594)
+++ branches/testbaudson_dev/http/frames/index.php	2008-07-07 14:32:51 UTC (rev 2595)
@@ -18,13 +18,11 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-mb_internal_encoding("UTF-8");
 require("../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_locale.php");
 require_once(dirname(__FILE__)."/../classes/class_gui.php");
 
 $_SESSION["mb_user_gui"] = $gui_id;
-$localeObj = new Mb_locale($_SESSION["mb_lang"]);
 
 //
 // check if user is allowed to access current GUI; 

Added: branches/testbaudson_dev/lib/locale.php
===================================================================
--- branches/testbaudson_dev/lib/locale.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/locale.php	2008-07-07 14:32:51 UTC (rev 2595)
@@ -0,0 +1,214 @@
+<?php
+# $Id: class_locale.php 2406 2008-04-23 15:59:31Z christoph $
+# http://www.mapbender.org/index.php/class_locale.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+require_once(dirname(__FILE__)."/../core/globalSettings.php");
+
+/**
+ * sets the locale, depending on various settings:
+ * 1) a language ID passed to the constructor
+ * 2) the browser settings $_SERVER["HTTP_ACCEPT_LANGUAGE"]
+ * 3) a default language ID
+ * 
+ */
+class Mb_locale {
+	var $knownLanguages = null;
+	var $systemLocales = null;
+	var $browserLanguages = null;
+	var $os = null;
+	var $name = null;
+	var $defaultLanguage = "en";
+	var $status = "No locale set.";
+	
+	function Mb_locale($languageId) {
+		if (!$languageId) {
+			$languageId = LANGUAGE;
+		}
+  		$e = new Mb_notice("class_locale: setting locale to " . $languageId);
+		if (USE_I18N) {
+			if (!$this->setCurrentLocale($languageId)) {
+				$e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
+			}
+		}
+		else {
+			$this->setCurrentLocale($this->defaultLanguage);
+		}
+	}
+
+	/**
+	 * Get the current locale, evaluating GET/POST variables, browser languages
+	 * and a default locale (in that preference)
+	 *
+	 * @returns current locale
+	 */
+	function setCurrentLocale($languageId) {
+
+	  	// try to set the locale to $languageId
+		if ($this->checkAndSetLocale($languageId)) {
+			return true;
+	  	}
+	  	else {
+	  		$e = new Mb_notice("class_locale: no input parameter specified.");
+	  	}
+
+		// determine the browser setting and try to set locale according to that
+		if ($this->browserLanguage == null) {
+			$this->setBrowserLanguages();
+		}		
+		foreach ($this->browserLanguages as $lang) {
+			$e = new Mb_notice("trying browser setting " . $lang);
+			if ($this->checkAndSetLocale($lang)) {
+				return true;
+			}
+		}	
+		
+		// set to default language
+		$e = new Mb_notice("trying default language " . $this->defaultLanguage);
+		return $this->checkAndSetLocale($this->defaultLanguage);
+	}
+	
+	/**
+	 * checks if a locale is available; if yes, it is set via setlocale
+	 * 
+	 * @returns true if the the locale is set successfully; otherwise false
+	 */
+	function checkAndSetLocale($languageId) {
+		if ($this->os == null) {
+			$this->os = $this->guessHostOS();
+		}
+		
+		if (!USE_I18N || ($this->os != null && isset($languageId))) {
+			if ($this->isKnownLanguage($languageId)) {
+				
+				if ($this->systemLocales == null) {
+					$this->setSystemLocales();					
+				}
+				
+				$locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];				
+				if (setlocale(LC_ALL, $locale)) {
+					$this->name = $locale;
+					$_SESSION["mb_lang"] = $languageId;
+					$_SESSION["mb_locale"] = $this->name;
+					$e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
+					// from http://de3.php.net/manual/de/function.gettext.php
+					bindtextdomain("Mapbender", dirname(__FILE__)."/../resources/locale/");
+					textdomain("Mapbender");
+					return true;
+				}
+			}
+		}
+		$e = new Mb_notice("locale " . $locale . " not found.");
+		return false;
+	}
+	
+	/**
+	 * Guess the operating system which on which this code is running
+	 * multiple methods are tested for reliably guessing the os
+	 * 
+	 * @private
+	 * @returns string with os name
+	 */
+	function guessHostOS(){
+	  if (strncasecmp(php_uname(), 'Windows', 7) == 0)
+	    return 'windows';
+	  else if (strncasecmp(php_uname(), 'Linux', 5) == 0)
+	    return 'linux';
+	  else if (strncasecmp(php_uname(), 'OpenBSD', 7) == 0)
+	    return 'bsd';
+	  else if (strncasecmp(php_uname(), 'FreeBSD', 7) == 0)
+	    return 'bsd';  
+	  else {
+	    throw new Mb_exception('unknown platform: could not interpret uname. php_uname() returned '. php_uname().'. Please report to MB developers');
+	    return null;
+	  }
+	}
+
+	/**
+	 * checks if a language is supported
+	 * 
+	 * @returns true if the language is supported; otherwise false
+	 */
+	function isKnownLanguage($languageId) {
+		if ($this->knownLocales == null) {
+			$this->setKnownLanguages();
+		}
+		if (array_key_exists($languageId, $this->knownLanguages)) {
+			return true;
+		}
+		else {
+			$e = new Mb_notice("language " . $languageId . " not supported.");
+		}	
+		return false; 
+	}
+	
+
+
+	/**
+	 * determines the available Locales on this system
+	 */
+	function setSystemLocales() {
+		$this->systemLocales['it_IT'] = array('linux' => 'it_IT.utf8',
+	                                'windows' => 'Italian_Italy.1252',
+	                                'bsd' => 'it_IT',
+	                                'posix' => 'it_IT');
+		$this->systemLocales['de_DE'] = array('linux' => 'de_DE.utf8',
+	                                'windows' => 'German_Germany.1252',
+	                                'bsd' => 'de_DE',
+	                                'posix' => 'it_IT');
+		$this->systemLocales['en_US'] = array('linux' => 'en_US.utf8',
+	                                'windows' => 'English_United States.1252',
+	                                'bsd' => 'en_US',
+	                                'posix' => 'it_IT');
+	}
+	
+	/**
+	 * set the known languages
+	 */
+	function setKnownLanguages() {
+		$this->knownLanguages = array('en_US' => 'en_US',
+                      'en' => 'en_US',
+                      'de_DE' => 'de_DE',
+                      'de' => 'de_DE',
+                      'bg_BG' => 'bg_BG',
+                      'bg' => 'bg_BG',
+                      'es_ES' => 'es_ES',
+                      'es' => 'es_ES',  
+                      'nl_NL' => 'nl_NL',
+                      'nl' => 'nl_NL',                                                                
+                      'gr_GR' => 'gr_GR',
+                      'gr' => 'gr_GR',
+                      'it_IT' => 'it_IT',
+                      'it' => 'it_IT');
+	}
+	
+	/**
+	 * sets the languages accepted by the client browser
+	 */
+	function setBrowserLanguages () {
+		$this->browserLanguages = array();
+		
+	    $bLangs = split(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
+	    foreach ($bLangs as $lang) {
+			if (strpos($lang, ';') === false)
+				array_push($this->browserLanguages, $lang);
+			else
+				array_push($this->browserLanguages, substr($lang, 0, strpos($lang, ';')));
+	    }		
+	}
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list