Revision 1864
Added by darkviper over 12 years ago
| branches/2.8.x/CHANGELOG | ||
|---|---|---|
| 11 | 11 |
! = Update/Change |
| 12 | 12 |
=============================================================================== |
| 13 | 13 |
|
| 14 |
19 Feb-2013 Build 1864 Werner v.d.Decken(DarkViper) |
|
| 15 |
! update classes Translate, TranslateTable, TranslateAdaptorWbOldStyle |
|
| 16 |
+ added interface TranslateAdaptorInterface |
|
| 17 |
+ added Klasse_Translate_de.pdf |
|
| 18 |
! update class WbAdaptor |
|
| 19 |
! update /framework/initialize.php |
|
| 20 |
19 Feb-2013 Build 1863 Werner v.d.Decken(DarkViper) |
|
| 21 |
! updated Twig template engine to stable version 1.12.2 |
|
| 14 | 22 |
19 Feb-2013 Build 1862 Werner v.d.Decken(DarkViper) |
| 15 | 23 |
! updated Twig template engine to stable version 1.12.2 |
| 16 | 24 |
18 Feb-2013 Build 1861 Werner v.d.Decken(DarkViper) |
| branches/2.8.x/wb/admin/interface/version.php | ||
|---|---|---|
| 51 | 51 |
|
| 52 | 52 |
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled) |
| 53 | 53 |
if(!defined('VERSION')) define('VERSION', '2.8.3');
|
| 54 |
if(!defined('REVISION')) define('REVISION', '1862');
|
|
| 54 |
if(!defined('REVISION')) define('REVISION', '1864');
|
|
| 55 | 55 |
if(!defined('SP')) define('SP', '');
|
| branches/2.8.x/wb/framework/TranslateAdaptorInterface.php | ||
|---|---|---|
| 1 |
<?php |
|
| 2 |
|
|
| 3 |
/** |
|
| 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
| 5 |
* |
|
| 6 |
* This program is free software: you can redistribute it and/or modify |
|
| 7 |
* it under the terms of the GNU General Public License as published by |
|
| 8 |
* the Free Software Foundation, either version 3 of the License, or |
|
| 9 |
* (at your option) any later version. |
|
| 10 |
* |
|
| 11 |
* This program is distributed in the hope that it will be useful, |
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
* GNU General Public License for more details. |
|
| 15 |
* |
|
| 16 |
* You should have received a copy of the GNU General Public License |
|
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
*/ |
|
| 19 |
|
|
| 20 |
/** |
|
| 21 |
* TranslateAdaptorInterface.php |
|
| 22 |
* |
|
| 23 |
* @category Core |
|
| 24 |
* @package Core_Translation |
|
| 25 |
* @author Werner v.d.Decken <wkl@isteam.de> |
|
| 26 |
* @copyright Werner v.d.Decken <wkl@isteam.de> |
|
| 27 |
* @license http://www.gnu.org/licenses/gpl.html GPL License |
|
| 28 |
* @version 0.0.1 |
|
| 29 |
* @revision $Revision$ |
|
| 30 |
* @link $HeadURL$ |
|
| 31 |
* @lastmodified $Date$ |
|
| 32 |
* @since File available since 06.02.2013 |
|
| 33 |
* @description definitions for all TranslateAdaptorXxxxx |
|
| 34 |
*/ |
|
| 35 |
interface TranslateAdaptorInterface {
|
|
| 36 |
|
|
| 37 |
public function __construct($sAddon = ''); |
|
| 38 |
public function loadLanguage($sLangCode); |
|
| 39 |
public function findFirstLanguage(); |
|
| 40 |
|
|
| 41 |
} // end of interface TranslateAdaptorInterface |
|
| 42 |
|
|
| 0 | 43 | |
| branches/2.8.x/wb/framework/Translate.php | ||
|---|---|---|
| 35 | 35 |
class Translate {
|
| 36 | 36 |
|
| 37 | 37 |
// @object hold the Singleton instance |
| 38 |
private static $_oInstance = null; |
|
| 38 |
private static $_oInstance = null;
|
|
| 39 | 39 |
|
| 40 |
protected $_sAdaptor = 'WbOldStyle'; |
|
| 41 |
protected $_sDefaultLanguage = 'en'; |
|
| 42 |
protected $_sUserLanguage = 'en'; |
|
| 43 |
protected $_aAddons = array(); |
|
| 44 |
protected $_aTranslations = array(); |
|
| 40 |
protected $sAdaptor = 'WbOldStyle'; |
|
| 41 |
protected $sSystemLanguage = 'en'; |
|
| 42 |
protected $sDefaultLanguage = 'en'; |
|
| 43 |
protected $sUserLanguage = 'en'; |
|
| 44 |
protected $bUseCache = true; |
|
| 45 |
/** TranslationTable objects of all loaded addons */ |
|
| 46 |
protected $aLoadedAddons = array(); |
|
| 47 |
/** TranslationTable object of the core and additional one activated addon */ |
|
| 48 |
protected $aActiveTranslations = array(); |
|
| 49 |
|
|
| 50 |
const CACHE_ENABLED = true; |
|
| 51 |
const CACHE_DISABLED = false; |
|
| 45 | 52 |
|
| 46 | 53 |
/** prevent class from public instancing and get an object to hold extensions */ |
| 47 | 54 |
protected function __construct() {}
|
| ... | ... | |
| 64 | 71 |
* @param string UserLanguage code ('de' || 'de_CH' || 'de_CH_uri')
|
| 65 | 72 |
* @throws TranslationException |
| 66 | 73 |
*/ |
| 67 |
public function initialize($sDefaultLanguage, $sUserLanguage = '', $sAdaptor = 'WbOldStyle') |
|
| 74 |
public function initialize($sSystemLanguage, $sDefaultLanguage, $sUserLanguage = '', |
|
| 75 |
$sAdaptor = 'WbOldStyle', $bUseCache = self::CACHE_ENABLED) |
|
| 68 | 76 |
{
|
| 69 | 77 |
if(!class_exists('TranslateAdaptor'.$sAdaptor)) {
|
| 70 | 78 |
throw new TranslationException('unable to load adaptor: '.$sAdaptor);
|
| 71 | 79 |
} |
| 72 |
$this->_sAdaptor = $sAdaptor; |
|
| 73 |
$this->_sDefaultLanguage = $sDefaultLanguage; |
|
| 80 |
$this->bUseCache = $bUseCache; |
|
| 81 |
$this->sAdaptor = 'TranslateAdaptor'.$sAdaptor; |
|
| 82 |
// if no system language is set then use language 'en' |
|
| 83 |
$this->sSystemLanguage = (trim($sSystemLanguage) == '' ? 'en' : $sSystemLanguage); |
|
| 84 |
// if no default language is set then use system language |
|
| 85 |
$this->sDefaultLanguage = (trim($sDefaultLanguage) == '' |
|
| 86 |
? $this->sSystemLanguage |
|
| 87 |
: $sDefaultLanguage); |
|
| 74 | 88 |
// if no user language is set then use default language |
| 75 |
$this->_sUserLanguage = ($sUserLanguage == '' ? $sDefaultLanguage : $sUserLanguage); |
|
| 89 |
$this->sUserLanguage = (trim($sUserLanguage) == '' |
|
| 90 |
? $this->sDefaultLanguage |
|
| 91 |
: $sUserLanguage); |
|
| 76 | 92 |
$sPattern = '/^[a-z]{2,3}(?:(?:\_[a-z]{2})?(?:\_[a-z0-9]{2,4})?)$/siU';
|
| 77 | 93 |
// validate language codes |
| 78 |
if(preg_match($sPattern, $this->_sDefaultLanguage) && |
|
| 79 |
preg_match($sPattern, $this->_sUserLanguage)) |
|
| 94 |
if(preg_match($sPattern, $this->sSystemLanguage) && |
|
| 95 |
preg_match($sPattern, $this->sDefaultLanguage) && |
|
| 96 |
preg_match($sPattern, $this->sUserLanguage)) |
|
| 80 | 97 |
{
|
| 81 | 98 |
// load core translations and activate it |
| 82 |
$oTmp = new TranslationTable('', $this->_sDefaultLanguage, $this->_sUserLanguage);
|
|
| 83 |
$this->_aAddons['core'] = $oTmp->load($this->_sAdaptor); |
|
| 84 |
$this->_aTranslations[0] = $this->_aAddons['core']; |
|
| 85 |
if(sizeof($this->_aAddons['core']) == 0) {
|
|
| 99 |
$oTmp = new TranslationTable('',
|
|
| 100 |
$this->sSystemLanguage, |
|
| 101 |
$this->sDefaultLanguage, |
|
| 102 |
$this->sUserLanguage, |
|
| 103 |
$this->bUseCache); |
|
| 104 |
$this->aLoadedAddons['core'] = $oTmp->load($this->sAdaptor); |
|
| 105 |
$this->aActiveTranslations[0] = $this->aLoadedAddons['core']; |
|
| 106 |
if(sizeof($this->aLoadedAddons['core']) == 0) {
|
|
| 86 | 107 |
// throw an exception for missing translations |
| 87 | 108 |
throw new TranslationException('missing core translations');
|
| 88 | 109 |
} |
| 89 | 110 |
}else {
|
| 90 | 111 |
// throw an exception for invalid or missing language codes |
| 91 |
$sMsg = 'Invalid language codes: ['.$this->_sDefaultLanguage.'] ['.$this->_sUserLanguage.']'; |
|
| 112 |
$sMsg = 'Invalid language codes: ['.$this->sSystemLanguage.'] or [' |
|
| 113 |
. $this->sDefaultLanguage.'] or ['.$this->sUserLanguage.']'; |
|
| 92 | 114 |
throw new TranslationException($sMsg); |
| 93 | 115 |
} |
| 94 | 116 |
} |
| ... | ... | |
| 99 | 121 |
*/ |
| 100 | 122 |
public function addAddon($sAddon) |
| 101 | 123 |
{
|
| 102 |
if(!(strtolower($sAddon) == 'core' || $sAddon == '' || isset($this->_aAddons[$sAddon]))) {
|
|
| 124 |
if(!(strtolower($sAddon) == 'core' || $sAddon == '' || isset($this->aLoadedAddons[$sAddon]))) {
|
|
| 103 | 125 |
// load requested addon translations if needed and possible |
| 104 |
$oTmp = new TranslationTable($sAddon, $this->_sDefaultLanguage, $this->_sUserLanguage); |
|
| 105 |
$this->_aAddons[$sAddon] = $oTmp->load($this->_sAdaptor); |
|
| 126 |
$oTmp = new TranslationTable($sAddon, |
|
| 127 |
$this->sSystemLanguage, |
|
| 128 |
$this->sDefaultLanguage, |
|
| 129 |
$this->sUserLanguage, |
|
| 130 |
$this->bUseCache); |
|
| 131 |
$this->aLoadedAddons[$sAddon] = $oTmp->load($this->sAdaptor); |
|
| 106 | 132 |
} |
| 107 | 133 |
} |
| 108 | 134 |
/** |
| ... | ... | |
| 112 | 138 |
public function enableAddon($sAddon) |
| 113 | 139 |
{
|
| 114 | 140 |
if(!(strtolower($sAddon) == 'core' || $sAddon == '')) {
|
| 115 |
if(!isset($this->_aAddons[$sAddon])) {
|
|
| 141 |
if(!isset($this->aLoadedAddons[$sAddon])) {
|
|
| 116 | 142 |
$this->addAddon($sAddon); |
| 117 | 143 |
} |
| 118 |
$this->_aTranslations[1] = $this->_aAddons[$sAddon];
|
|
| 144 |
$this->aActiveTranslations[1] = $this->aLoadedAddons[$sAddon];
|
|
| 119 | 145 |
} |
| 120 | 146 |
|
| 121 | 147 |
} |
| 122 |
|
|
| 148 |
/** |
|
| 149 |
* Dissable active addon |
|
| 150 |
*/ |
|
| 123 | 151 |
public function disableAddon() |
| 124 | 152 |
{
|
| 125 |
if(isset($this->_aTranslations[1])) {
|
|
| 126 |
unset($this->_aTranslations[1]);
|
|
| 153 |
if(isset($this->aActiveTranslations[1])) {
|
|
| 154 |
unset($this->aActiveTranslations[1]);
|
|
| 127 | 155 |
} |
| 128 | 156 |
} |
| 129 | 157 |
|
| ... | ... | |
| 134 | 162 |
*/ |
| 135 | 163 |
public function __isset($sKey) |
| 136 | 164 |
{
|
| 137 |
foreach($this->_aTranslations as $oAddon) {
|
|
| 165 |
foreach($this->aActiveTranslations as $oAddon) {
|
|
| 138 | 166 |
if(isset($oAddon->$sKey)) {
|
| 139 | 167 |
// is true if at least one translation is found |
| 140 | 168 |
return true; |
| ... | ... | |
| 150 | 178 |
public function __get($sKey) |
| 151 | 179 |
{
|
| 152 | 180 |
$sRetval = ''; |
| 153 |
foreach($this->_aTranslations as $oAddon) {
|
|
| 181 |
foreach($this->aActiveTranslations as $oAddon) {
|
|
| 154 | 182 |
if(isset($oAddon->$sKey)) {
|
| 155 | 183 |
// search the last matching translation (Core -> Addon) |
| 156 | 184 |
$sRetval = $oAddon->$sKey; |
| ... | ... | |
| 165 | 193 |
*/ |
| 166 | 194 |
public function getLangArray() |
| 167 | 195 |
{
|
| 168 |
$aTranslations = array(); |
|
| 169 |
foreach($this->_aTranslations as $aTranslation) {
|
|
| 170 |
$aTranslations = array_merge($aTranslations, $aTranslation); |
|
| 196 |
$aSumTranslations = array(); |
|
| 197 |
foreach($this->aActiveTranslations as $oTranslationTable) {
|
|
| 198 |
if(get_class($oTranslationTable) == 'TranslationTable') {
|
|
| 199 |
$aSumTranslations = array_merge($aSumTranslations, $oTranslationTable->getArray()); |
|
| 200 |
} |
|
| 171 | 201 |
} |
| 172 |
return $aTranslations; |
|
| 202 |
return $aSumTranslations;
|
|
| 173 | 203 |
} |
| 174 | 204 |
|
| 175 | 205 |
} // end of class Translate |
| branches/2.8.x/wb/framework/initialize.php | ||
|---|---|---|
| 1 | 1 |
<?php |
| 2 | 2 |
/** |
| 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
| 3 | 4 |
* |
| 4 |
* @category framework |
|
| 5 |
* @package initialize |
|
| 6 |
* @author Ryan Djurovich, WebsiteBaker Project |
|
| 7 |
* @copyright 2009-2012, WebsiteBaker Org. e.V. |
|
| 8 |
* @link http://www.websitebaker2.org/ |
|
| 9 |
* @license http://www.gnu.org/licenses/gpl.html |
|
| 10 |
* @platform WebsiteBaker 2.8.x |
|
| 11 |
* @requirements PHP 5.2.2 and higher |
|
| 12 |
* @version $Id$ |
|
| 13 |
* @filesource $HeadURL$ |
|
| 14 |
* @lastmodified $Date$ |
|
| 5 |
* This program is free software: you can redistribute it and/or modify |
|
| 6 |
* it under the terms of the GNU General Public License as published by |
|
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
* (at your option) any later version. |
|
| 15 | 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
|
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
* GNU General Public License for more details. |
|
| 14 |
* |
|
| 15 |
* You should have received a copy of the GNU General Public License |
|
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 16 | 17 |
*/ |
| 17 | 18 |
|
| 18 |
/* -------------------------------------------------------- */ |
|
| 19 |
// Must include code to stop this file being accessed directly |
|
| 20 |
require_once(dirname(__FILE__).'/globalExceptionHandler.php'); |
|
| 21 |
if(!defined('WB_URL')) { throw new IllegalFileException(); }
|
|
| 22 |
/* -------------------------------------------------------- */ |
|
| 23 | 19 |
/** |
| 20 |
* initialize.php |
|
| 21 |
* |
|
| 22 |
* @category Core |
|
| 23 |
* @package Core_Environment |
|
| 24 |
* @author Werner v.d.Decken <wkl@isteam.de> |
|
| 25 |
* @copyright Werner v.d.Decken <wkl@isteam.de> |
|
| 26 |
* @license http://www.gnu.org/licenses/gpl.html GPL License |
|
| 27 |
* @version 0.0.1 |
|
| 28 |
* @revision $Revision$ |
|
| 29 |
* @link $HeadURL$ |
|
| 30 |
* @lastmodified $Date$ |
|
| 31 |
* @since File replaced since 05.02.2013 |
|
| 32 |
* @description set the basic environment to run WebsiteBaker |
|
| 33 |
*/ |
|
| 34 |
|
|
| 35 |
/* *** define some helper functions *** */ |
|
| 36 |
/** |
|
| 24 | 37 |
* sanitize $_SERVER['HTTP_REFERER'] |
| 25 | 38 |
* @param string $sWbUrl qualified startup URL of current application |
| 26 | 39 |
*/ |
| ... | ... | |
| 48 | 61 |
} |
| 49 | 62 |
$_SERVER['HTTP_REFERER'] = $sTmpReferer; |
| 50 | 63 |
} |
| 51 |
/* -------------------------------------------------------- */ |
|
| 64 |
/** |
|
| 65 |
* Set constants for system/install values |
|
| 66 |
* @throws RuntimeException |
|
| 67 |
*/ |
|
| 52 | 68 |
function SetInstallPathConstants() {
|
| 53 |
if(!defined('DEBUG')){ define('DEBUG', false); }// Include config file
|
|
| 69 |
if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in config file
|
|
| 54 | 70 |
if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
|
| 55 | 71 |
if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
|
| 56 | 72 |
throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
|
| ... | ... | |
| 62 | 78 |
$x1 = parse_url(WB_URL); |
| 63 | 79 |
define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
|
| 64 | 80 |
} |
| 81 |
define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY);
|
|
| 65 | 82 |
if(!defined('DOCUMENT_ROOT')) {
|
| 83 |
|
|
| 66 | 84 |
define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(WB_REL, '/').'$/', '', WB_PATH));
|
| 67 | 85 |
} |
| 86 |
define('TMP_PATH', WB_PATH.'/temp');
|
|
| 68 | 87 |
} |
| 69 |
/* -------------------------------------------------------- */ |
|
| 88 |
/** |
|
| 89 |
* Read DB settings from configuration file |
|
| 90 |
* @return string |
|
| 91 |
* @throws RuntimeException |
|
| 92 |
* |
|
| 93 |
*/ |
|
| 94 |
function readConfiguration($sRetvalType = 'url') {
|
|
| 95 |
$x = debug_backtrace(); |
|
| 96 |
if(sizeof($x) != 0) { throw new RuntimeException('illegal function request!'); }
|
|
| 97 |
$aRetval = array(); |
|
| 98 |
$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php'; |
|
| 99 |
if(is_readable($sSetupFile)) {
|
|
| 100 |
$aCfg = parse_ini_file($sSetupFile, true); |
|
| 101 |
foreach($aCfg['Constants'] as $key=>$value) {
|
|
| 102 |
if($key == 'debug') { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); }
|
|
| 103 |
if(!defined(strtoupper($key))) { define(strtoupper($key), $value); }
|
|
| 104 |
} |
|
| 105 |
$db = $aCfg['DataBase']; |
|
| 106 |
$db['type'] = isset($db['type']) ? $db['type'] : 'mysql'; |
|
| 107 |
$db['user'] = isset($db['user']) ? $db['user'] : 'foo'; |
|
| 108 |
$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar'; |
|
| 109 |
$db['host'] = isset($db['host']) ? $db['host'] : 'localhost'; |
|
| 110 |
$db['port'] = isset($db['port']) ? $db['port'] : '3306'; |
|
| 111 |
$db['port'] = ($db['port'] != '3306') ? $db['port'] : ''; |
|
| 112 |
$db['name'] = isset($db['name']) ? $db['name'] : 'dummy'; |
|
| 113 |
$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8'; |
|
| 114 |
$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : ''); |
|
| 115 |
define('TABLE_PREFIX', $db['table_prefix']);
|
|
| 116 |
if($sRetvalType == 'dsn') {
|
|
| 117 |
$aRetval[0] = $db['type'].':dbname='.$db['name'].';host='.$db['host'].';' |
|
| 118 |
. ($db['port'] != '' ? 'port='.(int)$db['port'].';' : ''); |
|
| 119 |
$aRetval[1] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
|
|
| 120 |
$aRetval[2] = array( 'user' => $db['user'], 'pass' => $db['pass']); |
|
| 121 |
}else { // $sRetvalType == 'url'
|
|
| 122 |
$aRetval[0] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@' |
|
| 123 |
. $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']; |
|
| 124 |
} |
|
| 125 |
unset($db, $aCfg); |
|
| 126 |
return $sRetval; |
|
| 127 |
} |
|
| 128 |
throw new RuntimeException('unable to read setup.ini.php');
|
|
| 129 |
} |
|
| 130 |
/* *************************************************************************************** |
|
| 131 |
* Start initialization * |
|
| 132 |
****************************************************************************************/ |
|
| 133 |
// initialize debug evaluation values --- |
|
| 134 |
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn' |
|
| 70 | 135 |
$starttime = array_sum(explode(" ",microtime()));
|
| 71 |
$iPhpDeclaredClasses = sizeof(get_declared_classes()); |
|
| 136 |
$iPhpDeclaredClasses = sizeof(get_declared_classes()); |
|
| 137 |
// disable all kind of magic_quotes in PHP versions before 5.4 --- |
|
| 138 |
if(version_compare(PHP_VERSION, '5.4.0', '<')) {
|
|
| 139 |
if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
|
|
| 140 |
@ini_set('magic_quotes_sybase', 0);
|
|
| 141 |
@ini_set('magic_quotes_gpc', 0);
|
|
| 142 |
@ini_set('magic_quotes_runtime', 0);
|
|
| 143 |
} |
|
| 144 |
} |
|
| 145 |
// define constant systemenvironment settings --- |
|
| 72 | 146 |
SetInstallPathConstants(); |
| 73 |
SanitizeHttpReferer(WB_URL); // sanitize $_SERVER['HTTP_REFERER'] |
|
| 74 |
if(!class_exists('WbAutoloader', false)){ include(dirname(__FILE__).'/WbAutoloader.php'); }
|
|
| 147 |
date_default_timezone_set('UTC');
|
|
| 148 |
if(!defined('MAX_TIME')) { define('MAX_TIME', (pow(2, 31)-1)); } // 32-Bit Timestamp of 19 Jan 2038 03:14:07 GMT
|
|
| 149 |
if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT']))); }
|
|
| 150 |
// register WB basic autoloader --- |
|
| 151 |
$sTmp = dirname(__FILE__).'/WbAutoloader.php'; |
|
| 152 |
if(!class_exists('WbAutoloader', false)){ include($sTmp); }
|
|
| 75 | 153 |
WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m')); |
| 76 |
require_once dirname(dirname(__FILE__)).'/include/Twig/Autoloader.php'; |
|
| 154 |
// register TWIG autoloader --- |
|
| 155 |
// $sTmp = dirname(dirname(__FILE__)).'/include/Sensio/Twig/lib/Twig/Autoloader.php'; |
|
| 156 |
$sTmp = dirname(dirname(__FILE__)).'/include/Twig/Autoloader.php'; |
|
| 157 |
if(!class_exists('Twig_Autoloader', false)){ include($sTmp); }
|
|
| 77 | 158 |
Twig_Autoloader::register(); |
| 78 |
date_default_timezone_set('UTC');
|
|
| 79 |
// Create database class |
|
| 80 |
$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME; |
|
| 159 |
// aktivate exceptionhandler --- |
|
| 160 |
if(!function_exists('globalExceptionHandler')) {
|
|
| 161 |
include(dirname(__FILE__).'/globalExceptionHandler.php'); |
|
| 162 |
} |
|
| 163 |
// load db configuration --- |
|
| 164 |
if(defined('DB_TYPE')) {
|
|
| 165 |
$aSqlData = array( 0 => DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME); |
|
| 166 |
}else {
|
|
| 167 |
$aSqlData = readConfiguration($sDbConnectType); |
|
| 168 |
} |
|
| 169 |
// sanitize $_SERVER['HTTP_REFERER'] --- |
|
| 170 |
SanitizeHttpReferer(WB_URL); |
|
| 171 |
// --------------------------- |
|
| 172 |
// Create global database instance --- |
|
| 81 | 173 |
$database = WbDatabase::getInstance(); |
| 82 |
$database->doConnect($sSqlUrl); |
|
| 83 |
// disable all kind of magic_quotes |
|
| 84 |
if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
|
|
| 85 |
@ini_set('magic_quotes_sybase', 0);
|
|
| 86 |
@ini_set('magic_quotes_gpc', 0);
|
|
| 87 |
@ini_set('magic_quotes_runtime', 0);
|
|
| 174 |
if($sDbConnectType == 'dsn') {
|
|
| 175 |
$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]); |
|
| 176 |
}else {
|
|
| 177 |
$database->doConnect($aSqlData[0], TABLE_PREFIX); |
|
| 88 | 178 |
} |
| 89 |
// Get website settings (title, keywords, description, header, and footer) |
|
| 90 |
$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings"; |
|
| 91 |
$get_settings = $database->query($query_settings); |
|
| 92 |
if($database->is_error()) { die($database->get_error()); }
|
|
| 93 |
if($get_settings->numRows() == 0) { die("Settings not found"); }
|
|
| 94 |
while($setting = $get_settings->fetchRow()) {
|
|
| 95 |
$setting_name=strtoupper($setting['name']); |
|
| 96 |
$setting_value=$setting['value']; |
|
| 97 |
// if ($setting_value=='') {$setting_value=false;}
|
|
| 98 |
if ($setting_value=='false'){$setting_value=false;}
|
|
| 99 |
if ($setting_value=='true'){$setting_value=true;}
|
|
| 100 |
@define($setting_name,$setting_value); |
|
| 101 |
} |
|
| 102 |
@define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
|
|
| 103 |
$string_file_mode = STRING_FILE_MODE; |
|
| 179 |
unset($aSqlData); |
|
| 180 |
// load global settings from database and define global consts from --- |
|
| 181 |
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`'; |
|
| 182 |
if(($oSettings = $database->query($sql))) {
|
|
| 183 |
if(!$oSettings->numRows()) { throw new AppException('no settings found'); }
|
|
| 184 |
while($aSetting = $oSettings->fetchRow(MYSQL_ASSOC)) {
|
|
| 185 |
//sanitize true/false values |
|
| 186 |
$aSetting['value'] = ($aSetting['value'] == 'true' |
|
| 187 |
? true |
|
| 188 |
: ($aSetting['value'] == 'false' |
|
| 189 |
? false |
|
| 190 |
: $aSetting['value']) |
|
| 191 |
); |
|
| 192 |
// make global const from setting |
|
| 193 |
@define(strtoupper($aSetting['name']), $aSetting['value']); |
|
| 194 |
} |
|
| 195 |
}else { throw new AppException($database->get_error()); }
|
|
| 196 |
// get/set users timezone --- |
|
| 197 |
define('TIMEZONE', (isset($_SESSION['TIMEZONE']) ? $_SESSION['TIMEZONE'] : DEFAULT_TIMEZONE));
|
|
| 198 |
define('DATE_FORMAT', (isset($_SESSION['DATE_FORMAT']) ? $_SESSION['DATE_FORMAT'] : DEFAULT_DATE_FORMAT));
|
|
| 199 |
define('TIME_FORMAT', (isset($_SESSION['TIME_FORMAT']) ? $_SESSION['TIME_FORMAT'] : DEFAULT_TIME_FORMAT));
|
|
| 200 |
// set Theme directory --- |
|
| 201 |
define('THEME_URL', WB_URL.'/templates/'.DEFAULT_THEME);
|
|
| 202 |
define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);
|
|
| 203 |
define('THEME_REL', WB_REL.'/templates/'.DEFAULT_THEME);
|
|
| 204 |
// extended wb editor settings |
|
| 205 |
define('EDIT_ONE_SECTION', false);
|
|
| 206 |
define('EDITOR_WIDTH', 0);
|
|
| 207 |
// define numeric, octal values for chmod operations --- |
|
| 208 |
$string_file_mode = STRING_FILE_MODE; // STRING_FILE_MODE is set deprecated |
|
| 104 | 209 |
define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
|
| 105 |
$string_dir_mode = STRING_DIR_MODE; |
|
| 210 |
$string_dir_mode = STRING_DIR_MODE; // STRING_DIR_MODE is set deprecated
|
|
| 106 | 211 |
define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
|
| 212 |
// define form security class and preload it --- |
|
| 107 | 213 |
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
| 108 | 214 |
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php'; |
| 109 | 215 |
require_once($sSecMod); |
| 110 |
if (!defined("WB_INSTALL_PROCESS")) {
|
|
| 111 |
// get CAPTCHA and ASP settings |
|
| 112 |
$table = TABLE_PREFIX.'mod_captcha_control'; |
|
| 113 |
if( ($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) ) {
|
|
| 114 |
if($get_settings->numRows() == 0) { die("CAPTCHA-Settings not found"); }
|
|
| 115 |
$setting = $get_settings->fetchRow(); |
|
| 116 |
if($setting['enabled_captcha'] == '1') define('ENABLED_CAPTCHA', true);
|
|
| 117 |
else define('ENABLED_CAPTCHA', false);
|
|
| 118 |
if($setting['enabled_asp'] == '1') define('ENABLED_ASP', true);
|
|
| 119 |
else define('ENABLED_ASP', false);
|
|
| 120 |
define('CAPTCHA_TYPE', $setting['captcha_type']);
|
|
| 121 |
define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
|
|
| 122 |
define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
|
|
| 123 |
define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
|
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
// set error-reporting |
|
| 128 |
if(intval(ER_LEVEL) > 0 ) |
|
| 129 |
{
|
|
| 216 |
// set error-reporting from loaded settings --- |
|
| 217 |
if(intval(ER_LEVEL) > 0 ) {
|
|
| 130 | 218 |
error_reporting(ER_LEVEL); |
| 131 |
if( intval(ini_get ( 'display_errors' )) == 0 ) |
|
| 132 |
{
|
|
| 219 |
if( intval(ini_get ( 'display_errors' )) == 0 ) {
|
|
| 133 | 220 |
ini_set('display_errors', 1);
|
| 134 | 221 |
} |
| 135 | 222 |
} |
| 136 |
// Start a session
|
|
| 223 |
// Start a session ---
|
|
| 137 | 224 |
if(!defined('SESSION_STARTED')) {
|
| 138 | 225 |
session_name(APP_NAME.'_session_id'); |
| 139 | 226 |
@session_start(); |
| 140 | 227 |
define('SESSION_STARTED', true);
|
| 141 | 228 |
} |
| 142 |
if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started']))
|
|
| 229 |
// *** begin deprecated part ************************************************************* |
|
| 230 |
// load settings for use in Captch and ASP module |
|
| 231 |
if (!defined("WB_INSTALL_PROCESS")) {
|
|
| 232 |
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_captcha_control`'; |
|
| 233 |
// request settings from database |
|
| 234 |
if(($oSettings = $database->query($sql))) {
|
|
| 235 |
if(($aSetting = $oSettings->fetchRow(MYSQL_ASSOC))) {
|
|
| 236 |
define('ENABLED_CAPTCHA', ($aSetting['enabled_captcha'] == '1'));
|
|
| 237 |
define('ENABLED_ASP', ($aSetting['enabled_asp'] == '1'));
|
|
| 238 |
define('CAPTCHA_TYPE', $aSetting['captcha_type']);
|
|
| 239 |
define('ASP_SESSION_MIN_AGE', (int)$aSetting['asp_session_min_age']);
|
|
| 240 |
define('ASP_VIEW_MIN_AGE', (int)$aSetting['asp_view_min_age']);
|
|
| 241 |
define('ASP_INPUT_MIN_AGE', (int)$aSetting['asp_input_min_age']);
|
|
| 242 |
} |
|
| 243 |
} |
|
| 244 |
} |
|
| 245 |
if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started'])) {
|
|
| 143 | 246 |
$_SESSION['session_started'] = time(); |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
// Get users language |
|
| 148 |
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']); |
|
| 149 |
$language = (intval(isset(${$requestMethod}['lang'])) ? ${$requestMethod}['lang'] : null);
|
|
| 150 |
if(isset($language) AND $language != '' AND !is_numeric($language) AND strlen($language) == 2) {
|
|
| 151 |
define('LANGUAGE', strtoupper($language));
|
|
| 247 |
} |
|
| 248 |
// *** end of deprecated part ************************************************************ |
|
| 249 |
// get user language --- |
|
| 250 |
$sRequestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']); |
|
| 251 |
// check if get/post value is available |
|
| 252 |
$sTempLanguage = (isset(${$sRequestMethod}['lang']) ? ${$sRequestMethod}['lang'] : '');
|
|
| 253 |
// validate language code |
|
| 254 |
if(preg_match('/^[a-z]{2}$/si', $sTempLanguage)) {
|
|
| 255 |
// if there's valid get/post |
|
| 256 |
define('LANGUAGE', strtoupper($sTempLanguage));
|
|
| 152 | 257 |
$_SESSION['LANGUAGE']=LANGUAGE; |
| 153 |
} else {
|
|
| 154 |
if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
|
|
| 258 |
}else {
|
|
| 259 |
if(isset($_SESSION['LANGUAGE']) && $_SESSION['LANGUAGE']) {
|
|
| 260 |
// if there's valid session value |
|
| 155 | 261 |
define('LANGUAGE', $_SESSION['LANGUAGE']);
|
| 156 |
} else {
|
|
| 262 |
}else {
|
|
| 263 |
// otherwise set to default |
|
| 157 | 264 |
define('LANGUAGE', DEFAULT_LANGUAGE);
|
| 158 | 265 |
} |
| 159 | 266 |
} |
| 160 |
|
|
| 161 |
// Load Language file |
|
| 162 |
if(!defined('LANGUAGE_LOADED')) {
|
|
| 163 |
if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
|
|
| 164 |
exit('Error loading language file '.LANGUAGE.', please check configuration');
|
|
| 165 |
} else {
|
|
| 166 |
require_once(WB_PATH.'/languages/'.LANGUAGE.'.php'); |
|
| 167 |
} |
|
| 168 |
} |
|
| 169 |
|
|
| 170 |
// Get users timezone |
|
| 171 |
if(isset($_SESSION['TIMEZONE'])) {
|
|
| 172 |
define('TIMEZONE', $_SESSION['TIMEZONE']);
|
|
| 267 |
// activate translations / load language definitions |
|
| 268 |
/** begin of deprecated part || will be replaced by class Translate **/ |
|
| 269 |
// Load Language file |
|
| 270 |
if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
|
|
| 271 |
$sMsg = 'Error loading language file '.LANGUAGE.', please check configuration'; |
|
| 272 |
throw new AppException($sMsg); |
|
| 173 | 273 |
} else {
|
| 174 |
define('TIMEZONE', DEFAULT_TIMEZONE);
|
|
| 274 |
// include language file |
|
| 275 |
require_once(WB_PATH.'/languages/'.LANGUAGE.'.php'); |
|
| 175 | 276 |
} |
| 176 |
// Get users date format |
|
| 177 |
if(isset($_SESSION['DATE_FORMAT'])) {
|
|
| 178 |
define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
|
|
| 179 |
} else {
|
|
| 180 |
define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
|
|
| 277 |
/** end of deprecated part **/ |
|
| 278 |
// instantiate and initialize adaptor for temporary registry replacement --- |
|
| 279 |
if(class_exists('WbAdaptor')) {
|
|
| 280 |
WbAdaptor::getInstance()->getWbConstants(); |
|
| 181 | 281 |
} |
| 182 |
// Get users time format |
|
| 183 |
if(isset($_SESSION['TIME_FORMAT'])) {
|
|
| 184 |
define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
|
|
| 185 |
} else {
|
|
| 186 |
define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
|
|
| 187 |
} |
|
| 188 |
|
|
| 189 |
// Set Theme dir |
|
| 190 |
define('THEME_URL', WB_URL.'/templates/'.DEFAULT_THEME);
|
|
| 191 |
define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);
|
|
| 192 |
|
|
| 193 |
// extended wb_settings |
|
| 194 |
define('EDIT_ONE_SECTION', false);
|
|
| 195 |
|
|
| 196 |
define('EDITOR_WIDTH', 0);
|
|
| 282 |
// load and activate new global translation table |
|
| 283 |
Translate::getInstance()->initialize('en',
|
|
| 284 |
(defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''),
|
|
| 285 |
(defined('LANGUAGE') ? LANGUAGE : ''),
|
|
| 286 |
'WbOldStyle'); |
|
| 287 |
// *** END OF FILE *********************************************************************** |
|
| 288 |
|
|
| branches/2.8.x/wb/framework/TranslationTable.php | ||
|---|---|---|
| 33 | 33 |
*/ |
| 34 | 34 |
class TranslationTable {
|
| 35 | 35 |
|
| 36 |
private $_aTranslations = array(); |
|
| 37 |
private $_sSystemLang = 'en'; |
|
| 38 |
private $_sDefaultLang = 'en'; |
|
| 39 |
private $_sUserLang = 'en'; |
|
| 40 |
private $_sAddon = ''; |
|
| 41 |
|
|
| 36 |
protected $aTranslations = array(); |
|
| 37 |
protected $aLanguages = array(); |
|
| 38 |
protected $sSystemLang = 'en'; |
|
| 39 |
protected $sDefaultLang = 'en'; |
|
| 40 |
protected $sUserLang = 'en'; |
|
| 41 |
protected $sAddon = ''; |
|
| 42 |
protected $oReg = null; |
|
| 43 |
protected $sTempPath = ''; |
|
| 44 |
protected $iDirMode = 0777; |
|
| 42 | 45 |
/** |
| 43 | 46 |
* Constructor |
| 44 | 47 |
* @param string relative pathname of the Addon (i.e. '' || 'modules/myAddon/') |
| 45 |
* @param string Default language code ( 2ALPHA[[_2ALPHA]_2*4ALNUM] ) |
|
| 46 |
* @param string User language code ( 2ALPHA[[_2ALPHA]_2*4ALNUM] ) |
|
| 48 |
* @param string System language code ( 2*3ALPHA[[_2ALPHA]_2*4ALNUM] ) |
|
| 49 |
* @param string Default language code ( 2*3ALPHA[[_2ALPHA]_2*4ALNUM] ) |
|
| 50 |
* @param string User language code ( 2*3ALPHA[[_2ALPHA]_2*4ALNUM] ) |
|
| 47 | 51 |
*/ |
| 48 |
public function __construct($sAddon, $sDefaultLanguage, $sUserLanguage = '') |
|
| 52 |
public function __construct($sAddon, |
|
| 53 |
$sSystemLanguage, $sDefaultLanguage, $sUserLanguage, |
|
| 54 |
$bUseCache = Translate::CACHE_ENABLED) |
|
| 49 | 55 |
{
|
| 50 |
$this->_sDefaultLang = $sDefaultLanguage; |
|
| 51 |
$this->_sUserLang = ($sUserLanguage == '' ? $sDefaultLanguage : $sUserLanguage); |
|
| 52 |
$this->_sAddon = $sAddon; |
|
| 56 |
$this->bUseCache = $bUseCache; |
|
| 57 |
$this->sSystemLang = $sSystemLanguage; |
|
| 58 |
$this->sDefaultLang = $sDefaultLanguage; |
|
| 59 |
$this->sUserLang = $sUserLanguage; |
|
| 60 |
$this->sAddon = $sAddon; |
|
| 61 |
if(class_exists('WbAdaptor')) {
|
|
| 62 |
$this->sTempPath = WbAdaptor::getInstance()->TempPath; |
|
| 63 |
$this->iDirMode = WbAdaptor::getInstance()->OctalDirMode; |
|
| 64 |
}else {
|
|
| 65 |
$this->sTempPath = dirname(dirname(__FILE__)).'/temp/'; |
|
| 66 |
} |
|
| 67 |
$this->aLanguages['system'] = array(); |
|
| 68 |
$this->aLanguages['default'] = array(); |
|
| 69 |
$this->aLanguages['user'] = array(); |
|
| 53 | 70 |
} |
| 54 | 71 |
/** |
| 55 | 72 |
* Load language definitions |
| ... | ... | |
| 58 | 75 |
*/ |
| 59 | 76 |
public function load($sAdaptor) |
| 60 | 77 |
{
|
| 61 |
$c = 'TranslateAdaptor'.$sAdaptor; |
|
| 62 |
$oTmp = new $c($this->_sAddon); |
|
| 63 |
// load default language first |
|
| 64 |
if( ($aResult = $oTmp->loadLanguage($this->_sDefaultLang)) !== false ) {
|
|
| 65 |
$this->_aTranslations = $aResult; |
|
| 66 |
} |
|
| 67 |
if($this->_sUserLang != $this->_sDefaultLang) {
|
|
| 68 |
// load user language if its not equal default language |
|
| 69 |
if( ($aResult = $oTmp->loadLanguage($this->_sUserLang)) !== false ) {
|
|
| 70 |
$this->_aTranslations = array_merge($this->_aTranslations, $aResult); |
|
| 78 |
$sCachePath = $this->getCachePath(); |
|
| 79 |
$sCacheFile = $sCachePath.md5($this->sAddon.$this->sSystemLang. |
|
| 80 |
$this->sDefaultLang.$this->sUserLang).'.php'; |
|
| 81 |
if($this->bUseCache && is_readable($sCacheFile)) {
|
|
| 82 |
$this->aTranslations = $this->loadCacheFile($sCacheFile); |
|
| 83 |
}else {
|
|
| 84 |
$bLanguageFound = false; |
|
| 85 |
$oAdaptor= new $sAdaptor($this->sAddon); |
|
| 86 |
if(!$oAdaptor instanceof TranslatorAdaptorInterface) {
|
|
| 87 |
$sMsg = 'Class ['.$sAdaptor.'] does not implement the ' |
|
| 88 |
. 'interface [TranslateAdaptorInterface]'; |
|
| 89 |
throw new TranslationException($sMsg); |
|
| 71 | 90 |
} |
| 72 |
} |
|
| 73 |
if(($this->_sSystemLang != $this->_sUserLang) && |
|
| 74 |
($this->_sSystemLang != $this->_sDefaultLang)) {
|
|
| 75 |
// load system language if its not already loaded |
|
| 76 |
if( ($aResult = $oTmp->loadLanguage($this->_sSystemLang)) !== false ) {
|
|
| 77 |
$this->_aTranslations = array_merge($this->_aTranslations, $aResult); |
|
| 91 |
// load system language first |
|
| 92 |
if(($aResult = $this->loadLanguageSegments($this->sSystemLang, $oAdaptor)) !== false) {
|
|
| 93 |
// load system language |
|
| 94 |
$this->aLanguages['system'] = $aResult; |
|
| 95 |
$bLanguageFound = true; |
|
| 78 | 96 |
} |
| 79 |
} |
|
| 80 |
if(sizeof($this->_aTranslations) == 0) {
|
|
| 81 |
// if absolutely no requested language found, simply get the first available |
|
| 82 |
$sFirstLanguage = $oTmp->findFirstLanguage(); |
|
| 83 |
// load first found language if its not already loaded |
|
| 84 |
if( ($aResult = $oTmp->loadLanguage($sFirstLanguage)) !== false ) {
|
|
| 85 |
$this->_aTranslations = array_merge($this->_aTranslations, $aResult); |
|
| 97 |
if($this->sDefaultLang != $this->sSystemLang) {
|
|
| 98 |
// load default language if it's not equal system language |
|
| 99 |
if(($aResult = $this->loadLanguageSegments($this->sDefaultLang, $oAdaptor)) !== false) {
|
|
| 100 |
$this->aLanguages['default'] = $aResult; |
|
| 101 |
$bLanguageFound = true; |
|
| 102 |
} |
|
| 103 |
}else {
|
|
| 104 |
// copy system language |
|
| 105 |
$this->aLanguages['default'] = $this->aLanguages['system']; |
|
| 86 | 106 |
} |
| 107 |
if($this->sUserLang != $this->sDefaultLang |
|
| 108 |
&& $this->sUserLang != $this->sSystemLang) {
|
|
| 109 |
// load user language if it's not equal default language or system language |
|
| 110 |
if(($aResult = $this->loadLanguageSegments($this->sUserLang, $oAdaptor)) !== false) {
|
|
| 111 |
$this->aLanguages['user'] = $aResult; |
|
| 112 |
$bLanguageFound = true; |
|
| 113 |
} |
|
| 114 |
}elseif($this->sUserLang == $this->sDefaultLang) {
|
|
| 115 |
// copy default language |
|
| 116 |
$this->aLanguages['user'] = $this->aLanguages['default']; |
|
| 117 |
}elseif($this->sUserLang == $this->sSystemLang) {
|
|
| 118 |
// copy system language |
|
| 119 |
$this->aLanguages['user'] = $this->aLanguages['system']; |
|
| 120 |
} |
|
| 121 |
if($bLanguageFound) {
|
|
| 122 |
// copy user into default if default is missing |
|
| 123 |
if(sizeof($this->aLanguages['user']) && !sizeof($this->aLanguages['default'])) {
|
|
| 124 |
$this->aLanguages['default'] = $this->aLanguages['user']; |
|
| 125 |
} |
|
| 126 |
// copy default into system if system is missing |
|
| 127 |
if(sizeof($this->aLanguages['default']) && !sizeof($this->aLanguages['system'])) {
|
|
| 128 |
$this->aLanguages['system'] = $this->aLanguages['default']; |
|
| 129 |
} |
|
| 130 |
} |
|
| 131 |
// if absolutely no requested language found, simply get the first available language |
|
| 132 |
if(!$bLanguageFound) {
|
|
| 133 |
$sFirstLanguage = $oAdaptor->findFirstLanguage(); |
|
| 134 |
// load first found language if its not already loaded |
|
| 135 |
if(($aResult = $this->loadLanguageSegments($sFirstLanguage, $oAdaptor)) !== false) {
|
|
| 136 |
$this->aLanguages['system'] = $aResult; |
|
| 137 |
$bLanguageFound = true; |
|
| 138 |
} |
|
| 139 |
} |
|
| 140 |
if($bLanguageFound) {
|
|
| 141 |
$this->aTranslations = array_merge($this->aTranslations, |
|
| 142 |
$this->aLanguages['system'], |
|
| 143 |
$this->aLanguages['default'], |
|
| 144 |
$this->aLanguages['user']); |
|
| 145 |
if($this->bUseCache) {
|
|
| 146 |
$this->writeCacheFile($sCacheFile); |
|
| 147 |
} |
|
| 148 |
} |
|
| 87 | 149 |
} |
| 88 | 150 |
return $this; |
| 89 | 151 |
} |
| ... | ... | |
| 94 | 156 |
*/ |
| 95 | 157 |
public function __isset($sKey) |
| 96 | 158 |
{
|
| 97 |
return isset($this->_aTranslations[$sKey]);
|
|
| 159 |
return isset($this->aTranslations[$sKey]); |
|
| 98 | 160 |
} |
| 99 | 161 |
/** |
| 100 | 162 |
* Get translation text |
| ... | ... | |
| 103 | 165 |
*/ |
| 104 | 166 |
public function __get($sKey) |
| 105 | 167 |
{
|
| 106 |
if(isset($this->_aTranslations[$sKey])) {
|
|
| 107 |
return $this->_aTranslations[$sKey];
|
|
| 168 |
if(isset($this->aTranslations[$sKey])) {
|
|
| 169 |
return $this->aTranslations[$sKey]; |
|
| 108 | 170 |
}else {
|
| 109 | 171 |
return ''; |
| 110 | 172 |
} |
| ... | ... | |
| 116 | 178 |
*/ |
| 117 | 179 |
public function getArray() |
| 118 | 180 |
{
|
| 119 |
return $this->_aTranslations; |
|
| 181 |
$aRetval = (is_array($this->aTranslations) ? $this->aTranslations : array()); |
|
| 182 |
return $aRetval; |
|
| 120 | 183 |
} |
| 184 |
/** |
|
| 185 |
* Load Language |
|
| 186 |
* @param string Language Code |
|
| 187 |
* @param object Adaptor object |
|
| 188 |
* @return bool|array |
|
| 189 |
*/ |
|
| 190 |
protected function loadLanguageSegments($sLangCode, $oAdaptor) |
|
| 191 |
{
|
|
| 192 |
$aTranslations = array(); |
|
| 193 |
// sanitize the language code |
|
| 194 |
$aLangCode = explode('_', preg_replace('/[^a-z0-9]/i', '_', strtolower($sLangCode)));
|
|
| 195 |
$sConcatedLang = ''; |
|
| 196 |
foreach($aLangCode as $sLang) |
|
| 197 |
{ // iterate all segments of the language code
|
|
| 198 |
if( ($aResult = $oAdaptor->loadLanguage($sConcatedLang.$sLang)) !== false ) {
|
|
| 199 |
$aTranslations = array_merge($aTranslations, $aResult); |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
return (sizeof($aTranslations) > 0 ? $aTranslations : false); |
|
| 203 |
} |
|
| 204 |
/** |
|
| 205 |
* getCachePath |
|
| 206 |
* @return string a valid path for caching or null on error |
|
| 207 |
*/ |
|
| 208 |
protected function getCachePath() |
|
| 209 |
{
|
|
| 210 |
$sCachePath = $this->sTempPath.__CLASS__.'/cache/'; |
|
| 211 |
if(!file_exists($sCachePath) && is_writeable($this->sTempPath)) {
|
|
| 212 |
$iOldUmask = umask(0); |
|
| 213 |
mkdir($sCachePath, $this->iDirMode, true); |
|
| 214 |
umask($iOldUmask); |
|
| 215 |
} |
|
| 216 |
if(is_writable($sCachePath)) {
|
|
| 217 |
return $sCachePath; |
|
| 218 |
}else {
|
|
| 219 |
return null; |
|
| 220 |
} |
|
| 221 |
} |
|
| 222 |
/** |
|
| 223 |
* load cached translation table |
|
| 224 |
* @param string path/name of the cachefile |
|
| 225 |
* @return array list of translations |
|
| 226 |
*/ |
|
| 227 |
protected function loadCacheFile($sCacheFile) |
|
| 228 |
{
|
|
| 229 |
$aTranslation = array(); |
|
| 230 |
include($sCacheFile); |
|
| 231 |
return $aTranslation; |
|
| 232 |
} |
|
| 233 |
/** |
|
| 234 |
* Write cache from translation |
|
| 235 |
* @param string path/name of the cachefile |
|
| 236 |
*/ |
|
| 237 |
protected function writeCacheFile($sCacheFile) |
|
| 238 |
{
|
|
| 239 |
$sOutput = '<?php'."\n".'/* autogenerated cachefile */'."\n"; |
|
| 240 |
while (list($key, $value) = each($this->aTranslations)) {
|
|
| 241 |
$sOutput .= '$aTranslation[\''.$key.'\'] = \''.addslashes($value).'\';'."\n"; |
|
| 242 |
} |
|
| 243 |
file_put_contents($sCacheFile, $sOutput, LOCK_EX); |
|
| 244 |
} |
|
| 121 | 245 |
} // end of class TranslationTable |
| branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php | ||
|---|---|---|
| 33 | 33 |
* @description Loads translation table from old languagefiles before WB-2.9.0. |
| 34 | 34 |
* Can handle Languagecodes like 'de_DE_BAY' (2ALPHA_2ALPHA_2-4ALNUM) |
| 35 | 35 |
*/ |
| 36 |
class TranslateAdaptorWbOldStyle {
|
|
| 36 |
class TranslateAdaptorWbOldStyle implements TranslateAdaptorInterface {
|
|
| 37 | 37 |
|
| 38 |
protected $sAppPath = ''; |
|
| 39 | 38 |
protected $sAddon = ''; |
| 40 |
protected $aLangTable = array(); |
|
| 41 | 39 |
protected $sFilePath = ''; |
| 42 | 40 |
/** |
| 43 | 41 |
* Constructor |
| ... | ... | |
| 46 | 44 |
public function __construct($sAddon = '') |
| 47 | 45 |
{
|
| 48 | 46 |
$this->sAddon = $sAddon; |
| 49 |
$this->sAppPath = dirname(dirname(__FILE__)).'/'; |
|
| 50 |
$this->sFilePath = $this->sAppPath |
|
| 51 |
. trim(str_replace('\\', '/', $sAddon), '/').'/languages/';
|
|
| 47 |
$this->sFilePath = str_replace('\\', '/', dirname(dirname(__FILE__))).'/'.$sAddon;
|
|
| 48 |
$this->sFilePath = rtrim(str_replace('\\', '/', $this->sFilePath), '/').'/languages/';
|
|
| 52 | 49 |
} |
| 53 | 50 |
/** |
| 54 | 51 |
* Load languagefile |
| ... | ... | |
| 58 | 55 |
public function loadLanguage($sLangCode) |
| 59 | 56 |
{
|
| 60 | 57 |
$aTranslations = array(); |
| 61 |
// sanitize the language code |
|
| 62 |
$aLangCode = explode('_', preg_replace('/[^a-z0-9]/i', '_', strtolower($sLangCode)));
|
|
| 63 |
$sConcatedLang = ''; |
|
| 64 |
foreach($aLangCode as $sLang) |
|
| 65 |
{ // iterate all segments of the language code
|
|
| 66 |
$sLangFile = ''; |
|
| 67 |
$sLang = strtolower($sLang); |
|
| 68 |
// seek lowerchars file |
|
| 69 |
if(is_readable($this->sFilePath.$sConcatedLang.$sLang.'.php')) {
|
|
| 70 |
$sLangFile = $this->sFilePath.$sConcatedLang.$sLang.'.php'; |
|
| 71 |
}else {
|
|
| 72 |
// seek upperchars file |
|
| 73 |
$sLang = strtoupper($sLang); |
|
| 74 |
if(is_readable($this->sFilePath.$sConcatedLang.$sLang.'.php')) {
|
|
| 75 |
$sLangFile = $this->sFilePath.$sConcatedLang.$sLang.'.php'; |
|
| 58 |
$sLangFile = strtolower($sLangCode.'.php'); |
|
| 59 |
if( ($aDirContent = scandir($this->sFilePath)) !== false) {
|
|
| 60 |
foreach($aDirContent as $sFile) {
|
|
| 61 |
if($sLangFile === strtolower($sFile)) {
|
|
| 62 |
$sLangFile = $this->sFilePath.$sFile; |
|
| 63 |
if(is_readable($sLangFile)) {
|
|
| 64 |
$aTmp = $this->_importArrays($sLangFile); |
|
| 65 |
$aTranslations = array_merge($aTranslations, $aTmp); |
|
| 66 |
break; |
|
| 67 |
} |
|
| 76 | 68 |
} |
| 77 | 69 |
} |
| 78 |
if($sLangFile) {
|
|
| 79 |
// import the fond file |
|
| 80 |
$sConcatedLang .= $sLangFile.'_'; |
|
| 81 |
$aTmp = $this->_importArrays($sLangFile); |
|
| 82 |
$aTranslations = array_merge($aTranslations, $aTmp); |
|
| 83 |
} |
|
| 84 | 70 |
} |
| 85 | 71 |
return (sizeof($aTranslations) > 0 ? $aTranslations : false); |
| 86 | 72 |
} |
| ... | ... | |
| 128 | 114 |
// walk through all arrays |
| 129 | 115 |
foreach(${$sSection} as $key => $value) {
|
| 130 | 116 |
// and import all found translations |
| 131 |
$aLanguageTable[$sSection.'_'.$key] = $value; |
|
| 117 |
if(!is_array($value)) {
|
|
| 118 |
// skip all multiarray definitions from compatibility mode |
|
| 119 |
$aLanguageTable[$sSection.'_'.$key] = $value; |
|
| 120 |
} |
|
| 132 | 121 |
} |
| 133 | 122 |
} |
| 134 | 123 |
return $aLanguageTable; |
| branches/2.8.x/wb/framework/WbAdaptor.php | ||
|---|---|---|
| 41 | 41 |
/** constructor */ |
| 42 | 42 |
protected function __construct() |
| 43 | 43 |
{
|
| 44 |
$this->_aSys = array('Sys' => array(), 'Req' => array());
|
|
| 44 |
$this->_aSys = array('System' => array(), 'Request' => array());
|
|
| 45 | 45 |
} |
| 46 | 46 |
/** |
| 47 | 47 |
* Get active instance |
| ... | ... | |
| 49 | 49 |
*/ |
| 50 | 50 |
public static function getInstance() |
| 51 | 51 |
{
|
| 52 |
if(self::$_oInstance === null) {
|
|
| 52 |
if(self::$_oInstance == null) {
|
|
| 53 | 53 |
$c = __CLASS__; |
| 54 | 54 |
self::$_oInstance = new $c(); |
| 55 | 55 |
|
| ... | ... | |
| 90 | 90 |
*/ |
| 91 | 91 |
public function getWbConstants() |
| 92 | 92 |
{
|
| 93 |
$this->_aSys = array('Sys' => array(), 'Req' => array());
|
|
| 93 |
$this->_aSys = array('System' => array(), 'Request' => array());
|
|
| 94 | 94 |
$aConsts = get_defined_constants(true); |
| 95 | 95 |
foreach($aConsts['user'] as $sKey=>$sVal) |
| 96 | 96 |
{
|
Also available in: Unified diff
update classes Translate, TranslateTable, TranslateAdaptorWbOldStyle
added interface TranslateAdaptorInterface
added Klasse_Translate_de.pdf
update class WbAdaptor
update /framework/initialize.php