Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1689)
+++ branches/2.8.x/CHANGELOG	(revision 1690)
@@ -11,6 +11,10 @@
 ! = Update/Change
 ===============================================================================
 
+31 May-2012 Build 1690 Werner v.d.Decken(DarkViper)
+! ModLanguage modified for auto fallback to DEFAULT_LANGUAGE
+! globalExceptionHandler added AppException, SecurityException, SecDirectoryTraversalException
+! Errormessage for old class.database modified
 08 May-2012 Build 1689 Werner v.d.Decken(DarkViper)
 # fixed Errorhandling for old class.database
 08 May-2012 Build 1688 Dietmar Woellbrink (Luisehahne)
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1689)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1690)
@@ -51,5 +51,5 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.3');
-if(!defined('REVISION')) define('REVISION', '1689');
+if(!defined('REVISION')) define('REVISION', '1690');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/framework/class.database.php
===================================================================
--- branches/2.8.x/wb/framework/class.database.php	(revision 1689)
+++ branches/2.8.x/wb/framework/class.database.php	(revision 1690)
@@ -18,19 +18,25 @@
 	private function showError() {
 		
 		$y = debug_backtrace();
-		$msg  = '<div style="margin: 100px auto; width: 70%">';
+		$msg  = '<div style="margin: 100px auto; width: 70%; background-color: #ffcccc; padding: 10px;">';
 		$msg .= '<p style="color: #dd0000; font-weight: bold;">Runtime Error !!</p>';
 		$msg .= '<p>Ouups...  there is a invalid statement found!!</p>';
-		$msg .= '<p>In File: <b>'.$y[0]['file'].'</b> Line: <b>'.$y[0]['line'].'</b><br />tried to create an invalid <b>'.$y[0]['class'].'</b> - object</p>';
-		$msg .= '<p>Please contact the module author to solve this problem.</p>';
+		$msg .= '<p>In File: <b>'.$y[1]['file'].'</b> Line: <b>'.$y[1]['line'].'</b><br />';
+		$msg .= 'tried to create an invalid <b>'.$y[1]['class'].'</b> - object</p>';
+		$msg .= '<p>Please replace <span style="color:#dd0000; font-weight:bold;">';
+		$msg .= '$database = new database();</span> by <span style="color:#00bb00; font-weight:bold;">';
+		$msg .= '$database = WbDatabase::getInstance();</span>.</p>';
 		$msg .= '<p>Also you can get information and help from the ';
 		$msg .= '<a href="http://www.websitebaker2.org/forum/index.php/board,2.0.html">WebsiteBaker Forum</a></p>';
 		$msg .= '<hr />';
 		$msg .= '<p style="color: #dd0000; font-weight: bold;">Runtime Error !!</p>';
 		$msg .= '<p>Ouups...  hier wurde ein ung&uuml;ltiges Kommando gefunden!!</p>';
-		$msg .= '<p>In Datei: <b>'.$y[0]['file'].'</b> - Zeile: <b>'.$y[0]['line'].'</b><br />es wurde versucht, ein ung&uuml;ltiges <b>'.$y[0]['class'].'</b> - Objekt zu erstellen.</p>';
-		$msg .= '<p>Bitte kontaktieren Sie den Modulautor um dieses Problem zu l&ouml;sen.</p>';
-		$msg .= '<p>Ebenso k&ouml;nnen sie auch Informationen und Hilfe im ';
+		$msg .= '<p>In der Datei: <b>'.$y[1]['file'].'</b> - Zeile: <b>'.$y[1]['line'].'</b><br />';
+		$msg .= 'wurde versucht, ein ung&uuml;ltiges <b>'.$y[1]['class'].'</b> - Objekt zu erstellen.</p>';
+		$msg .= '<p>Bitte ersetzen Sie <span style="color:#dd0000; font-weight:bold;">';
+		$msg .= '$database = new database();</span> durch <span style="color:#00bb00; font-weight:bold;">';
+		$msg .= '$database = WbDatabase::getInstance();</span>.</p>';
+		$msg .= '<p>Auch k&ouml;nnen sie auch Informationen und Hilfe im ';
 		$msg .= '<a href="http://www.websitebaker2.org/forum/index.php/board,31.0.html">WebsiteBaker Forum</a> finden.</p>';
 		$msg .= '</div>';
 		die($msg);
Index: branches/2.8.x/wb/framework/globalExceptionHandler.php
===================================================================
--- branches/2.8.x/wb/framework/globalExceptionHandler.php	(revision 1689)
+++ branches/2.8.x/wb/framework/globalExceptionHandler.php	(revision 1690)
@@ -32,6 +32,9 @@
 				if(mysql_errno()) {
 					$result .= mysql_errno().': '.mysql_error().'<br />'."\n";
 				}
+				$result .= '<pre>'."\n";
+				$result .= print_r($trace, true)."\n";
+				$result .= '</pre>'."\n";
 			}else {
 				$result = 'Exception: "'.$this->getMessage().'" in ['.$file.']<br />'."\n";
 			}
@@ -56,7 +59,9 @@
 
 	class SecDirectoryTraversalException extends SecurityException {
 		public function __toString() {
-			return 'possible directory traversal attack';
+			$out  = 'possible directory traversal attack<br />'."\n";
+			$out .= '\''.$e->getMessage().'\'<br />'."\n";
+			return $out;
 		}
 	}
 /* ------------------------------------------------------------------------------------ */
@@ -77,6 +82,8 @@
 			$out .= $trace[0]['function'].'();<br />';
 			$out .= 'in "'.$file.'"'."\n";
 			echo $out;
+		}elseif ($e instanceof AppException) {
+			echo (string)$e;
 		}elseif ($e instanceof IllegalFileException) {
 			$sResponse  = $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden';
 			header($sResponse);
Index: branches/2.8.x/wb/framework/ModLanguage.php
===================================================================
--- branches/2.8.x/wb/framework/ModLanguage.php	(revision 1689)
+++ branches/2.8.x/wb/framework/ModLanguage.php	(revision 1690)
@@ -7,24 +7,38 @@
  * @license      http://www.gnu.org/licenses/gpl.html
  * @version      $Id$
  * @filesource   $HeadURL$
- * @since        Datei vorhanden seit Release 2.8.2
+ * @since        Datei vorhanden seit Release 2.8.4
  * @lastmodified $Date$
  */
 class ModLanguage {
 
+// @var string 2 upercase chars for hardcoded system default language
+	private $_sSystemLanguage    = 'EN';
+// @var string 2 upercase chars for default fallback language
+	private $_sDefaultLanguage   = '';
+// @var string 2 upercase chars for current active language
 	private $_sCurrentLanguage   = '';
-	private $_sDefaultLanguage   = '';
+// @var string full directory with trailing slash to search language files in
 	private $_sLanguageDirectory = '';
-	private $_sLanguageFile      = '';
-	private $_LanguageTable      = array();
+// @array list to hold the complete resulting translation table
+	private $_aLanguageTable     = array();
+// @array list of all loaded/merged languages
+	private $_aLoadedLanguages   = array();
+
+// @boolean set to TRUE if language is successfully loaded
 	private $_bLoaded            = false;
+// @object hold the Singleton instance
+	private static $_oInstance   = null;
 
-	private static $_oInstance   = null;
-/* prevent from public instancing */
-	protected function  __construct() { }
-/* prevent from cloning */
-	private function __clone() {}
 /**
+ *  prevent class from public instancing
+ */
+	final protected function  __construct() { }
+/**
+ *  prevent from cloning existing instance
+ */
+	final private function __clone() {}
+/**
  * get a valid instance of this class
  * @return object
  */
@@ -36,108 +50,150 @@
 		return self::$_oInstance;
 	}
 /**
+ * return requested translation for a key
+ * @param string $sLanguageKey 2-uppercase letters language code
+ * @return string found translation or empty string
+ * @throws TranslationException
+ */
+	public function __get($sLanguageKey)
+	{
+		if($this->_bLoaded) {
+			$sRetval = (isset($this->_aLanguageTable[$sLanguageKey])
+						? $this->_aLanguageTable[$sLanguageKey] : '{missing: '.$sLanguageKey.'}');
+			return $sRetval;
+		}
+		$msg = 'No translation table loaded';
+		throw new TranslationException($msg);
+	}
+/**
+ * returns the whoole language array for use in templateengine
+ * @return array
+ * @throws TranslationException
+ */
+	public function getLangArray()
+	{
+		if($this->_bLoaded) {
+			return $this->_aLanguageTable;
+		}
+		$msg = 'No translation table loaded';
+		throw new TranslationException($msg);
+	}
+/**
  * set language and load needed language file
  * @param string $sDirectory full path to the language files
- * @param string $sLanguage 2-letters language code
- * @param string $sDefault 2-letters default-language code
+ * @param string $sLanguage 2 chars current active language code
+ * @param string $sDefault 2 chars default fallback language code
+ * @throws SecDirectoryTraversalException [global exception]
+ * @throws TranslationException [private exception]
  */
-	public function setLanguage($sDirectory, $sLanguage, $sDefault = 'EN')
+	public function setLanguage($sDirectory, $sCurrentLanguage, $sDefaultLanguage = 'EN')
 	{
+		// sanitize arguments
 		$sBasePath = realpath(dirname(dirname(__FILE__)));
-		$sLangDir = realpath($sDirectory);
-		if(!preg_match('/^'.preg_quote($sBasePath, '/').'/', $sLangDir)) {
-			throw new SecDirectoryTraversalException();
-		}
-		$sLangDir = str_replace('\\', '/', $sLangDir);
-		$sLangDir = rtrim($sLangDir, '/').'/';
-		$sLanguage = strtoupper($sLanguage);
-		$sLanguage = strtoupper($sDefault);
-		if($this->_sLanguageDirectory != $sLangDir ||
-		   $this->_sCurrentLanguage != $sLanguage ||
-		   $this->_sDefaultLanguage != $sDefault)
-		{
-		// only load language if not already loaded
-			$this->_sLanguageDirectory = rtrim($sLangDir, '/').'/';
-			$this->_sCurrentLanguage = $sLanguage;
-			$this->_sDefaultLanguage = $sDefault;
-
-			if(!$this->_findLanguageFile()) {
+		$sLangDir  = realpath($sDirectory);
+		if(preg_match('/^'.preg_quote($sBasePath, '/').'/', $sLangDir)) {
+			$sLangDir  = rtrim(str_replace('\\', '/', $sLangDir), '/').'/';
+			$sCurrentLanguage = strtoupper($sCurrentLanguage);
+			$sDefaultLanguage = strtoupper($sDefaultLanguage);
+			// check if the requested language is not already loaded
+			if($this->_sLanguageDirectory != $sLangDir ||
+			   $this->_sCurrentLanguage   != $sCurrentLanguage ||
+			   $this->_sDefaultLanguage   != $sDefaultLanguage)
+			{
+			// now load and merge the files in order SYSTEM - DEFAULT - CURRENT
+				$this->_aLanguageTable = array();
+				// at first search SYSTEM_LANGUAGE
+				$this->_loadLanguage($sLangDir, $this->_sSystemLanguage);
+				// at second merge DEFAULT_LANGUAGE
+				if(!in_array($sDefaultLanguage, $this->_aLoadedLanguages)) {
+					$this->_loadLanguage($sLangDir, $sDefaultLanguage);
+				}
+				// at third merge CURRENT_LANGUAGE
+				if(!in_array($sCurrentLanguage, $this->_aLoadedLanguages)) {
+					$this->_loadLanguage($sLangDir, $sCurrentLanguage);
+				}
+				// if no predefined language was fond, search for first available language
+				if(sizeof($this->_aLanguageTable) == 0) {
+					// if absolutely no language was fond, throw an exception
+					if(false !== ($sRandomLanguage = $this->_findFirstLanguage($sLangDir))) {
+						$this->_loadLanguage($sLangDir, $sRandomLanguage);
+					}
+				}
+				// remember last settings
+				$this->_sLanguageDirectory = $sLangDir;
+				$this->_sCurrentLanguage   = $sCurrentLanguage;
+				$this->_sDefaultLanguage   = $sDefaultLanguage;
+			}
+			if(!($this->_bLoaded = (sizeof($this->_aLanguageTable) != 0))) {
 				$msg  = 'unable to find valid language definition file in<br />';
 				$msg .= '"'.str_replace($sBasePath, '', $this->_sLanguageDirectory).'"';
 				throw new TranslationException($msg);
 			}
-			$this->_importArrays();
+			$this->_bLoaded = true;
+		}else {
+			throw new SecDirectoryTraversalException($sLangDir);
 		}
-		$this->_bLoaded = (sizeof($this->_LanguageTable) > 0);
 	}
 /**
- * return requested translation for a key
- * @param string $sLanguageKey 2-uppercase letters language code
- * @return string found translation or empty string 
+ * load language from given directory
+ * @param string $sLangDir
+ * @param string $sLanguage
  */
-	public function __get($sLanguageKey)
+	private function _loadLanguage($sLangDir, $sLanguage)
 	{
-		$sRetval = (isset($this->_LanguageTable[$sLanguageKey])
-		            ? $this->_LanguageTable[$sLanguageKey] : '{missing: '.$sLanguageKey.'}');
-		return $sRetval;
+		if(is_readable($sLangDir.$sLanguage.'.php')) {
+			$this->_aLanguageTable = array_merge($this->_aLanguageTable,
+			                                    $this->_importArrays($sLangDir.$sLanguage.'.php'));
+			$this->_aLoadedLanguages[] = $sLanguage;
+		}
 	}
 /**
- * returns the whoole language array for use in templateengine
- * @return array
+ * find first available language in given directory
+ * @param  string $sLangDir the directory to scan for language files
+ * @return string returns the 2 char language code or FALSE if search fails
  */
-	public function getLangArray()
+	private function _findFirstLanguage($sLangDir)
 	{
-		return $this->_LanguageTable;
-	}
-/**
- * search language file in order: LANGUAGE - DEFAULT_LANGUAGE - FIRST_FOUND
- * @return boolean
- */
-	private function _findLanguageFile()
-	{
-		$bMatch = false;
-		$dir = $this->_sLanguageDirectory;
-		if(is_readable($dir.$this->_sCurrentLanguage.'.php')) {
-		// check actual language
-			$this->_sLanguageFile = $dir.$this->_sCurrentLanguage.'.php';
-			$bMatch = true;
-		}else {
-			if(is_readable($dir.$this->_sDefaultLanguage.'.php')) {
-			// check default language
-				$this->_sLanguageFile = $dir.$this->_sDefaultLanguage.'.php';
-				$bMatch = true;
-			}else {
-			// search for first available and readable language file
-				if(is_readable($dir)) {
-					$iterator = new DirectoryIterator($dir);
-					foreach ($iterator as $fileinfo) {
-						if(!preg_match('/^[A-Z]{2}\.php$/', $fileinfo->getBasename())) { continue; }
-						$sLanguageFile = str_replace('\\', '/', $fileinfo->getPathname());
-						if(is_readable($sLanguageFile)) {
-							$this->_sLanguageFile = $sLanguageFile;
-							$bMatch = true;
-							break;
-						}
-					}
+	// search for first available and readable language file
+		$sRetval = false;
+		if(is_readable($sLangDir)) {
+			$iterator = new DirectoryIterator($sLangDir);
+			foreach ($iterator as $fileinfo) {
+				if(!preg_match('/^[A-Z]{2}\.php$/', $fileinfo->getBasename())) { continue; }
+				$sLanguageFile = $fileinfo->getPathname();
+				if(is_readable($sLanguageFile)) {
+					$sRetval = basename($sLanguageFile, '.php');
+					break;
 				}
 			}
 		}
-		return $bMatch;
+		return $sRetval;
 	}
 /**
  * import key-values from language file
+ * @param  string $sLanguageFile
+ * @return array of language definitions
  */
-	private function _importArrays()
+	private function _importArrays($sLanguageFile)
 	{
-		include($this->_sLanguageFile);
-		$aLangSections = array('HEADING', 'TEXT', 'MESSAGE', 'MENU', 'OVERVIEW', 'GENERIC');
+		include($sLanguageFile);
+		$aAllVars = get_defined_vars();
+		$aLangSections = array();
+		$aLanguageTable = array();
+		foreach($aAllVars as $key=>$value) {
+		// extract the names of arrays from language file
+			if(is_array($value)) {
+				$aLangSections[] = $key;
+			}
+		}
 		foreach($aLangSections as $sSection) {
-			if(isset(${$sSection}) && is_array(${$sSection})) {
-				foreach(${$sSection} as $key => $value) {
-					$this->_LanguageTable[$sSection.'_'.$key] = $value;
-				}
+		// walk through all arrays
+			foreach(${$sSection} as $key => $value) {
+			// and import all found translations
+				$aLanguageTable[$sSection.'_'.$key] = $value;
 			}
 		}
+		return $aLanguageTable;
 	}
 } // end class Translate
 /**
@@ -144,4 +200,3 @@
  *  Exception class for Translation
  */
 class TranslationException extends AppException {}
-
