00001 <?php
00002
00006 class oxLang extends oxSuperCfg
00007 {
00013 private static $_instance = null;
00014
00020 protected $_sName = 'lang';
00021
00027 protected $_iBaseLanguageId = null;
00028
00034 protected $_iTplLanguageId = null;
00035
00041 protected $_iEditLanguageId = null;
00042
00048 protected $_aLangCache = array();
00049
00055 protected $_aAdminTplLanguageArray = null;
00056
00062 protected $_aLangAbbr = null;
00063
00069 protected $_aAdditionalLangFiles = array();
00070
00076 protected $_aLangMap = array();
00077
00083 protected $_aActiveModuleInfo = null;
00084
00090 protected $_aDisabledModuleInfo = null;
00091
00099 public static function getInstance()
00100 {
00101 return oxRegistry::getLang();
00102 }
00103
00110 public function resetBaseLanguage()
00111 {
00112 $this->_iBaseLanguageId = null;
00113 }
00114
00120 public function getBaseLanguage()
00121 {
00122 if ( $this->_iBaseLanguageId === null ) {
00123
00124 $myConfig = $this->getConfig();
00125 $blAdmin = $this->isAdmin();
00126
00127
00128 if ( $blAdmin && ( ( $iSeLang = oxConfig::getParameter( 'changelang' ) ) !== null ) ) {
00129 $this->_iBaseLanguageId = $iSeLang;
00130 }
00131
00132 if ( is_null( $this->_iBaseLanguageId ) ) {
00133 $this->_iBaseLanguageId = oxConfig::getParameter( 'lang' );
00134 }
00135
00136
00137 $aLanguageUrls = $myConfig->getConfigParam( 'aLanguageURLs' );
00138
00139 if ( !$blAdmin && is_array( $aLanguageUrls ) ) {
00140 foreach ( $aLanguageUrls as $iId => $sUrl ) {
00141 if ( $sUrl && $myConfig->isCurrentUrl( $sUrl ) ) {
00142 $this->_iBaseLanguageId = $iId;
00143 break;
00144 }
00145 }
00146 }
00147
00148 if ( is_null( $this->_iBaseLanguageId ) ) {
00149 $this->_iBaseLanguageId = oxConfig::getParameter( 'language' );
00150 if (!isset($this->_iBaseLanguageId)) {
00151 $this->_iBaseLanguageId = oxSession::getVar('language');
00152 }
00153 }
00154
00155
00156
00157 if ( is_null( $this->_iBaseLanguageId ) && !$blAdmin && !oxRegistry::getUtils()->isSearchEngine() ) {
00158
00159
00160 $this->_iBaseLanguageId = oxRegistry::get("oxUtilsServer")->getOxCookie( 'language' );
00161
00162
00163 if ( is_null( $this->_iBaseLanguageId ) ) {
00164 $this->_iBaseLanguageId = $this->detectLanguageByBrowser();
00165 }
00166 }
00167
00168 if ( is_null( $this->_iBaseLanguageId ) ) {
00169 $this->_iBaseLanguageId = $myConfig->getConfigParam( 'sDefaultLang' );
00170 }
00171
00172 $this->_iBaseLanguageId = (int) $this->_iBaseLanguageId;
00173
00174
00175 $this->_iBaseLanguageId = $this->validateLanguage( $this->_iBaseLanguageId );
00176
00177 oxRegistry::get("oxUtilsServer")->setOxCookie( 'language', $this->_iBaseLanguageId );
00178 }
00179
00180 return $this->_iBaseLanguageId;
00181 }
00182
00188 public function getObjectTplLanguage()
00189 {
00190 if ( $this->_iObjectTplLanguageId === null ) {
00191 $this->_iObjectTplLanguageId = $this->getTplLanguage();
00192 $aLanguages = $this->getAdminTplLanguageArray();
00193 if ( !isset( $aLanguages[$this->_iObjectTplLanguageId] ) ||
00194 $aLanguages[$this->_iObjectTplLanguageId]->active == 0 ) {
00195 $this->_iObjectTplLanguageId = key( $aLanguages );
00196 }
00197 }
00198 return $this->_iObjectTplLanguageId;
00199 }
00200
00208 public function getTplLanguage()
00209 {
00210 if ( $this->_iTplLanguageId === null ) {
00211 $iSessLang = oxSession::getVar( 'tpllanguage' );
00212 $this->_iTplLanguageId = $this->isAdmin() ? $this->setTplLanguage( $iSessLang ) : $this->getBaseLanguage();
00213 }
00214 return $this->_iTplLanguageId;
00215 }
00216
00222 public function getEditLanguage()
00223 {
00224 if ( $this->_iEditLanguageId === null ) {
00225
00226 if ( !$this->isAdmin() ) {
00227 $this->_iEditLanguageId = $this->getBaseLanguage();
00228 } else {
00229
00230 $iLang = null;
00231
00232
00233 if ( "saveinnlang" == $this->getConfig()->getActiveView()->getFncName() ) {
00234 $iLang = oxConfig::getParameter( "new_lang");
00235 }
00236 $iLang = ( $iLang === null ) ? oxConfig::getParameter( 'editlanguage' ) : $iLang;
00237 $iLang = ( $iLang === null ) ? oxSession::getVar( 'editlanguage' ) : $iLang;
00238 $iLang = ( $iLang === null ) ? $this->getBaseLanguage() : $iLang;
00239
00240
00241 $this->_iEditLanguageId = $this->validateLanguage( $iLang );
00242
00243
00244 oxSession::setVar( 'editlanguage', $this->_iEditLanguageId );
00245 }
00246 }
00247 return $this->_iEditLanguageId;
00248 }
00249
00259 public function getLanguageArray( $iLanguage = null, $blOnlyActive = false, $blSort = false )
00260 {
00261 $myConfig = $this->getConfig();
00262
00263 if ( is_null($iLanguage) ) {
00264 $iLanguage = $this->_iBaseLanguageId;
00265 }
00266
00267 $aLanguages = array();
00268 $aConfLanguages = $myConfig->getConfigParam( 'aLanguages' );
00269 $aLangParams = $myConfig->getConfigParam( 'aLanguageParams' );
00270
00271 if ( is_array( $aConfLanguages ) ) {
00272 $i = 0;
00273 reset( $aConfLanguages );
00274 while ( list( $key, $val ) = each( $aConfLanguages ) ) {
00275
00276 if ( $blOnlyActive && is_array($aLangParams) ) {
00277
00278 if ( !$aLangParams[$key]['active'] ) {
00279 $i++;
00280 continue;
00281 }
00282 }
00283
00284 if ( $val ) {
00285 $oLang = new stdClass();
00286 $oLang->id = isset($aLangParams[$key]['baseId']) ? $aLangParams[$key]['baseId'] : $i;
00287 $oLang->oxid = $key;
00288 $oLang->abbr = $key;
00289 $oLang->name = $val;
00290
00291 if ( is_array( $aLangParams ) ) {
00292 $oLang->active = $aLangParams[$key]['active'];
00293 $oLang->sort = $aLangParams[$key]['sort'];
00294 }
00295
00296 $oLang->selected = ( isset( $iLanguage ) && $oLang->id == $iLanguage ) ? 1 : 0;
00297 $aLanguages[$oLang->id] = $oLang;
00298 }
00299 ++$i;
00300 }
00301 }
00302
00303 if ( $blSort && is_array($aLangParams) ) {
00304 uasort( $aLanguages, array($this, '_sortLanguagesCallback') );
00305 }
00306 return $aLanguages;
00307 }
00308
00314 public function getAdminTplLanguageArray()
00315 {
00316 if ( $this->_aAdminTplLanguageArray === null ) {
00317 $myConfig = $this->getConfig();
00318
00319 $aLangArray = $this->getLanguageArray();
00320 $this->_aAdminTplLanguageArray = array();
00321
00322 $sSourceDir = $myConfig->getAppDir() . 'views/admin/';
00323 foreach ( $aLangArray as $iLangKey => $oLang ) {
00324 $sFilePath = "{$sSourceDir}{$oLang->abbr}/lang.php";
00325 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
00326 $this->_aAdminTplLanguageArray[$iLangKey] = $oLang;
00327 }
00328 }
00329 }
00330
00331
00332 reset( $this->_aAdminTplLanguageArray );
00333 return $this->_aAdminTplLanguageArray;
00334 }
00335
00343 public function getLanguageAbbr( $iLanguage = null )
00344 {
00345 if ( $this->_aLangAbbr === null ) {
00346 $this->_aLangAbbr = $this->getLanguageIds();
00347 }
00348
00349 $iLanguage = isset( $iLanguage ) ? (int) $iLanguage : $this->getBaseLanguage();
00350 if ( isset( $this->_aLangAbbr[$iLanguage] ) ) {
00351 $iLanguage = $this->_aLangAbbr[$iLanguage];
00352 }
00353
00354 return $iLanguage;
00355 }
00356
00363 public function getLanguageNames()
00364 {
00365 $aConfLanguages = $this->getConfig()->getConfigParam( 'aLanguages' );
00366 $aLangIds = $this->getLanguageIds();
00367 $aLanguages = array();
00368 foreach ( $aLangIds as $iId => $sValue ) {
00369 $aLanguages[$iId] = $aConfLanguages[$sValue];
00370 }
00371 return $aLanguages;
00372 }
00373
00379 public function getLanguageIds()
00380 {
00381 $myConfig = $this->getConfig();
00382 $aIds = array();
00383
00384
00385 $aLangParams = $myConfig->getConfigParam( 'aLanguageParams' );
00386 if ( is_array( $aLangParams ) ) {
00387 foreach ( $aLangParams as $sAbbr => $aValue ) {
00388 $iBaseId = (int) $aValue['baseId'];
00389 $aIds[$iBaseId] = $sAbbr;
00390 }
00391 } else {
00392 $aIds = array_keys( $myConfig->getConfigParam( 'aLanguages' ) );
00393 }
00394
00395 return $aIds;
00396 }
00397
00410 public function translateString( $sStringToTranslate, $iLang = null, $blAdminMode = null )
00411 {
00412
00413 $aLang = $this->_getLangTranslationArray( $iLang, $blAdminMode );
00414 if ( isset( $aLang[$sStringToTranslate] ) ) {
00415 return $aLang[$sStringToTranslate];
00416 }
00417
00418
00419 $aMap = $this->_getLanguageMap( $iLang, $blAdminMode );
00420 if ( isset( $aLang[$aMap[$sStringToTranslate]] ) ) {
00421 return $aLang[$aMap[$sStringToTranslate]];
00422 }
00423
00424
00425 if (count($this->_aAdditionalLangFiles)) {
00426 $aLang = $this->_getLangTranslationArray( $iLang, $blAdminMode, $this->_aAdditionalLangFiles);
00427 if (isset( $aLang[$sStringToTranslate] )) {
00428 return $aLang[$sStringToTranslate];
00429 }
00430 }
00431
00432 return $sStringToTranslate;
00433 }
00434
00445 protected function _collectSimilar( $aData, $sKey, $aCollection = array() )
00446 {
00447 foreach ( $aData as $sValKey => $sValue ) {
00448 if ( strpos( $sValKey, $sKey ) === 0 ) {
00449 $aCollection[$sValKey] = $sValue;
00450 }
00451 }
00452
00453 return $aCollection;
00454 }
00455
00466 public function getSimilarByKey( $sKey, $iLang = null, $blAdmin = null )
00467 {
00468 startProfile("getSimilarByKey");
00469
00470 $iLang = isset( $iLang ) ? $iLang : $this->getTplLanguage();
00471 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00472
00473
00474 $aLang = $this->_getLangTranslationArray( $iLang, $blAdmin );
00475 $aSimilarConst = $this->_collectSimilar( $aLang, $sKey );
00476
00477
00478 $aMap = $this->_getLanguageMap( $iLang, $blAdminMode );
00479 $aSimilarConst = $this->_collectSimilar( $aMap, $sKey, $aSimilarConst );
00480
00481
00482 if ( count( $this->_aAdditionalLangFiles ) ) {
00483 $aLang = $this->_getLangTranslationArray( $iLang, $blAdminMode, $this->_aAdditionalLangFiles);
00484 $aSimilarConst = $this->_collectSimilar( $aLang, $sKey, $aSimilarConst );
00485 }
00486
00487 stopProfile("getSimilarByKey");
00488
00489 return $aSimilarConst;
00490 }
00491
00500 public function formatCurrency( $dValue, $oActCur = null )
00501 {
00502 if ( !$oActCur ) {
00503 $oActCur = $this->getConfig()->getActShopCurrencyObject();
00504 }
00505 $sValue = oxRegistry::getUtils()->fRound( $dValue, $oActCur );
00506 return number_format( (double)$sValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand );
00507 }
00508
00517 public function formatVat( $dValue, $oActCur = null )
00518 {
00519 $iDecPos = 0;
00520 $sValue = ( string ) $dValue;
00521 $oStr = getStr();
00522 if ( ( $iDotPos = $oStr->strpos( $sValue, '.' ) ) !== false ) {
00523 $iDecPos = $oStr->strlen( $oStr->substr( $sValue, $iDotPos + 1 ) );
00524 }
00525
00526 $oActCur = $oActCur ? $oActCur : $this->getConfig()->getActShopCurrencyObject();
00527 $iDecPos = ( $iDecPos < $oActCur->decimal ) ? $iDecPos : $oActCur->decimal;
00528 return number_format( (double)$dValue, $iDecPos, $oActCur->dec, $oActCur->thousand );
00529 }
00530
00538 public function getLanguageTag( $iLanguage = null)
00539 {
00540 if ( !isset( $iLanguage ) ) {
00541 $iLanguage = $this->getBaseLanguage();
00542 }
00543
00544 $iLanguage = (int) $iLanguage;
00545
00546 return ( ( $iLanguage )?"_$iLanguage":"" );
00547 }
00548
00556 public function validateLanguage( $iLang = null )
00557 {
00558 $iLang = (int) $iLang;
00559
00560
00561 $aLanguages = $this->getLanguageArray( null, !$this->isAdmin() );
00562 if ( !isset( $aLanguages[$iLang] ) && is_array( $aLanguages ) ) {
00563 $oLang = current( $aLanguages );
00564 if (isset($oLang->id)) {
00565 $iLang = $oLang->id;
00566 }
00567 }
00568
00569 return $iLang;
00570 }
00571
00579 public function setBaseLanguage( $iLang = null )
00580 {
00581 if ( is_null($iLang) ) {
00582 $iLang = $this->getBaseLanguage();
00583 } else {
00584 $this->_iBaseLanguageId = (int) $iLang;
00585 }
00586
00587 if ( defined( 'OXID_PHP_UNIT' ) ) {
00588 modSession::getInstance();
00589 }
00590
00591 oxSession::setVar( 'language', $iLang );
00592 }
00593
00601 public function setTplLanguage( $iLang = null )
00602 {
00603 $this->_iTplLanguageId = isset( $iLang ) ? (int) $iLang : $this->getBaseLanguage();
00604 if ( $this->isAdmin() ) {
00605 $aLanguages = $this->getAdminTplLanguageArray();
00606 if ( !isset( $aLanguages[$this->_iTplLanguageId] ) ) {
00607 $this->_iTplLanguageId = key( $aLanguages );
00608 }
00609 }
00610
00611 if ( defined( 'OXID_PHP_UNIT' ) ) {
00612 modSession::getInstance();
00613 }
00614
00615 oxSession::setVar( 'tpllanguage', $this->_iTplLanguageId );
00616 return $this->_iTplLanguageId;
00617 }
00618
00628 protected function _recodeLangArray( $aLangArray, $sCharset, $blRecodeKeys = false )
00629 {
00630 $aLangs = array();
00631 foreach ( $aLangArray as $sKey => $sValue ) {
00632 $sItemKey = $sKey;
00633 if ($blRecodeKeys === true) {
00634 $sItemKey = iconv($sCharset, 'UTF-8', $sItemKey);
00635 }
00636
00637 $aLangs[$sItemKey] = iconv( $sCharset, 'UTF-8', $sValue );
00638 unset($aLangArray[$sKey]);
00639 }
00640
00641 return $aLangs;
00642 }
00643
00651 protected function _getLangFilesPathArray( $iLang )
00652 {
00653 $oConfig = $this->getConfig();
00654 $aLangFiles = array();
00655
00656 $sAppDir = $oConfig->getAppDir();
00657 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00658 $sTheme = $oConfig->getConfigParam( "sTheme" );
00659 $sCustomTheme = $oConfig->getConfigParam( "sCustomTheme" );
00660 $sShopId = $oConfig->getShopId();
00661 $aModulePaths = $this->_getActiveModuleInfo();
00662
00663
00664 $sGenericPath = $sAppDir . 'translations/' . $sLang;
00665 if ( $sGenericPath ) {
00666 $aLangFiles[] = $sGenericPath . "/lang.php";
00667 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sGenericPath );
00668 }
00669
00670
00671 if ( $sTheme ) {
00672 $sThemePath = $sAppDir . 'views/' . $sTheme .'/' . $sLang;
00673 $aLangFiles[] = $sThemePath . "/lang.php";
00674 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sThemePath );
00675 }
00676
00677
00678 if ( $sCustomTheme ) {
00679 $sCustPath = $sAppDir . 'views/' . $sCustomTheme .'/' . $sLang;
00680 $aLangFiles[] = $sCustPath . "/lang.php";
00681 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sCustPath );
00682 }
00683
00684
00685
00686
00687
00688 $aLangFiles = $this->_appendModuleLangFiles( $aLangFiles, $aModulePaths, $sLang );
00689
00690
00691 $aLangFiles = $this->_appendCustomLangFiles( $aLangFiles, $sLang );
00692
00693 return count( $aLangFiles ) ? $aLangFiles : false;
00694 }
00695
00703 protected function _getAdminLangFilesPathArray( $iLang )
00704 {
00705 $oConfig = $this->getConfig();
00706 $aLangFiles = array();
00707
00708 $sAppDir = $oConfig->getAppDir();
00709 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00710
00711 $aModulePaths = array();
00712 $aModulePaths = array_merge( $aModulePaths, $this->_getActiveModuleInfo() );
00713 $aModulePaths = array_merge( $aModulePaths, $this->_getDisabledModuleInfo() );
00714
00715
00716 $sAdminPath = $sAppDir . 'views/admin/' . $sLang;
00717 $aLangFiles[] = $sAdminPath . "/lang.php";
00718 $aLangFiles[] = $sAppDir . 'translations/' . $sLang . '/translit_lang.php';
00719 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sAdminPath );
00720
00721
00722 $sThemePath = $sAppDir . 'views/*/' . $sLang;
00723 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sThemePath, "options" );
00724
00725
00726 $aLangFiles = $this->_appendModuleLangFiles( $aLangFiles, $aModulePaths, $sLang, true );
00727
00728
00729 $aLangFiles = $this->_appendCustomLangFiles( $aLangFiles, $sLang, true );
00730
00731 return count( $aLangFiles ) ? $aLangFiles : false;
00732 }
00733
00743 protected function _appendLangFile( $aLangFiles, $sFullPath, $sFilePattern = "lang" )
00744 {
00745 $aFiles = glob( $sFullPath . "/*_{$sFilePattern}.php" );
00746 if ( is_array( $aFiles ) && count( $aFiles ) ) {
00747 foreach ( $aFiles as $sFile ) {
00748 if ( !strpos( $sFile, 'cust_lang.php' ) ) {
00749 $aLangFiles[] = $sFile;
00750 }
00751 }
00752 }
00753 return $aLangFiles;
00754 }
00755
00765 protected function _appendCustomLangFiles( $aLangFiles, $sLang, $blForAdmin = false )
00766 {
00767 $oConfig = $this->getConfig();
00768 $sAppDir = $oConfig->getAppDir();
00769 $sTheme = $oConfig->getConfigParam( "sTheme" );
00770 $sCustomTheme = $oConfig->getConfigParam( "sCustomTheme" );
00771
00772 if ( $blForAdmin ) {
00773 $aLangFiles[] = $sAppDir . 'views/admin/' . $sLang . '/cust_lang.php';
00774 } else {
00775 if ( $sTheme ) {
00776 $aLangFiles[] = $sAppDir . 'views/' . $sTheme . '/' . $sLang . '/cust_lang.php';
00777 }
00778 if ( $sCustomTheme ) {
00779 $aLangFiles[] = $sAppDir . 'views/' . $sCustomTheme . '/' . $sLang . '/cust_lang.php';
00780 }
00781 }
00782
00783 return $aLangFiles;
00784 }
00785
00796 protected function _appendModuleLangFiles( $aLangFiles, $aModulePaths, $sLang, $blForAdmin = false )
00797 {
00798 if ( is_array( $aModulePaths ) ) {
00799
00800 $oConfig = $this->getConfig();
00801
00802 foreach ( $aModulePaths as $sPath ) {
00803 $sFullPath = $oConfig->getModulesDir() . $sPath;
00804 $sFullPath .= ($blForAdmin) ? '/views/admin/' : '/translations/';
00805 $sFullPath .= $sLang;
00806
00807 if ( !is_dir( $sFullPath ) ) {
00808 $sFullPath = $oConfig->getModulesDir() . $sPath;
00809 $sFullPath .= ($blForAdmin) ? '/out/admin/' : '/out/lang/';
00810 $sFullPath .= $sLang;
00811 }
00812
00813 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sFullPath );
00814
00815 if ( $blForAdmin ) {
00816 $aLangFiles[] = $sFullPath . '/module_options.php';
00817 }
00818 }
00819 }
00820
00821 return $aLangFiles;
00822 }
00823
00833 protected function _getLangFileCacheName( $blAdmin, $iLang, $aLangFiles = null )
00834 {
00835 $myConfig = $this->getConfig();
00836 $sLangFilesIdent = '_default';
00837 if (is_array($aLangFiles) && $aLangFiles) {
00838 $sLangFilesIdent = '_'.md5(implode('+', $aLangFiles));
00839 }
00840 return "langcache_" . ( (int) $blAdmin ) . "_{$iLang}_" . $myConfig->getShopId() . "_" . $myConfig->getConfigParam( 'sTheme' ).$sLangFilesIdent;
00841 }
00842
00852 protected function _getLanguageFileData( $blAdmin = false, $iLang = 0, $aLangFiles = null )
00853 {
00854 $myConfig = $this->getConfig();
00855 $myUtils = oxRegistry::getUtils();
00856
00857 $sCacheName = $this->_getLangFileCacheName( $blAdmin, $iLang, $aLangFiles );
00858 $aLangCache = $myUtils->getLangCache( $sCacheName );
00859 if ( !$aLangCache && $aLangFiles === null ) {
00860 if ( $blAdmin ) {
00861 $aLangFiles = $this->_getAdminLangFilesPathArray( $iLang );
00862 } else {
00863 $aLangFiles = $this->_getLangFilesPathArray( $iLang );
00864 }
00865 }
00866 if ( !$aLangCache && $aLangFiles ) {
00867 $aLangCache = array();
00868 $sBaseCharset = false;
00869 $aLang = array();
00870 $aLangSeoReplaceChars = array();
00871 foreach ( $aLangFiles as $sLangFile ) {
00872
00873 if ( file_exists( $sLangFile ) && is_readable( $sLangFile ) ) {
00874 $aSeoReplaceChars = array();
00875 include $sLangFile;
00876
00877
00878 if ( isset( $aLang['charset'] ) ) {
00879
00880
00881 if ( $myConfig->isUtf() ) {
00882 $aLang = $this->_recodeLangArray( $aLang, $aLang['charset'] );
00883
00884 if (isset($aSeoReplaceChars) && is_array($aSeoReplaceChars)) {
00885 $aSeoReplaceChars = $this->_recodeLangArray( $aSeoReplaceChars, $aLang['charset'], true );
00886 }
00887
00888
00889 $aLang['charset'] = 'UTF-8';
00890 }
00891
00892 if (isset($aSeoReplaceChars) && is_array($aSeoReplaceChars)) {
00893 $aLangSeoReplaceChars = array_merge($aLangSeoReplaceChars, $aSeoReplaceChars);
00894 }
00895
00896 if ( !$sBaseCharset ) {
00897 $sBaseCharset = $aLang['charset'];
00898 }
00899
00900 $aLangCache = array_merge( $aLangCache, $aLang );
00901 }
00902 }
00903 }
00904
00905
00906 if ( $sBaseCharset ) {
00907 $aLangCache['charset'] = $sBaseCharset;
00908 }
00909
00910
00911 $aLangCache['_aSeoReplaceChars'] = $aLangSeoReplaceChars;
00912
00913
00914 $myUtils->setLangCache( $sCacheName, $aLangCache );
00915 }
00916
00917 return $aLangCache;
00918 }
00919
00928 protected function _getLanguageMap( $iLang, $blAdmin = null )
00929 {
00930 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00931 $sKey = $iLang . ( (int) $blAdmin );
00932 if ( !isset( $this->_aLangMap[$sKey] ) ) {
00933 $this->_aLangMap[$sKey] = array();
00934 $myConfig = $this->getConfig();
00935 $sMapFile = $myConfig->getAppDir() . '/views/' . ( $blAdmin ? 'admin' : $myConfig->getConfigParam( "sTheme" ) ) .'/' . oxRegistry::getLang()->getLanguageAbbr( $iLang ) . '/map.php';
00936 if ( $sMapFile ) {
00937 if ( file_exists( $sMapFile ) && is_readable( $sMapFile ) ) {
00938 include $sMapFile;
00939 $this->_aLangMap[$sKey] = $aMap;
00940 }
00941 }
00942 }
00943
00944 return $this->_aLangMap[$sKey];
00945 }
00946
00955 protected function _getCacheLanguageId( $blAdmin, $iLang = null )
00956 {
00957 $iLang = ( $iLang === null && $blAdmin ) ? $this->getTplLanguage() : $iLang;
00958 if ( !isset( $iLang ) ) {
00959 $iLang = $this->getBaseLanguage();
00960 if ( !isset( $iLang ) ) {
00961 $iLang = 0;
00962 }
00963 }
00964
00965 return (int) $iLang;
00966 }
00967
00977 protected function _getLangTranslationArray( $iLang = null, $blAdmin = null, $aLangFiles = null )
00978 {
00979 startProfile("_getLangTranslationArray");
00980
00981 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00982 $iLang = $this->_getCacheLanguageId( $blAdmin, $iLang );
00983 $sCacheName = $this->_getLangFileCacheName( $blAdmin, $iLang, $aLangFiles );
00984
00985 if ( !isset( $this->_aLangCache[$sCacheName] ) ) {
00986 $this->_aLangCache[$sCacheName] = array();
00987 }
00988 if ( !isset( $this->_aLangCache[$sCacheName][$iLang] ) ) {
00989
00990 $this->_aLangCache[$sCacheName][$iLang] = $this->_getLanguageFileData( $blAdmin, $iLang, $aLangFiles );
00991 }
00992
00993 stopProfile("_getLangTranslationArray");
00994
00995
00996 return ( isset( $this->_aLangCache[$sCacheName][$iLang] ) ? $this->_aLangCache[$sCacheName][$iLang] : array() );
00997 }
00998
01007 protected function _sortLanguagesCallback( $a1, $a2 )
01008 {
01009 return ($a1->sort > $a2->sort);
01010 }
01011
01017 public function getName()
01018 {
01019 return $this->_sName;
01020 }
01021
01027 public function getFormLang()
01028 {
01029 $sLang = null;
01030 if ( !$this->isAdmin()) {
01031 $sLang = "<input type=\"hidden\" name=\"".$this->getName()."\" value=\"". $this->getBaseLanguage() . "\" />";
01032 }
01033 return $sLang;
01034 }
01035
01043 public function getUrlLang( $iLang = null )
01044 {
01045 $sLang = null;
01046 if ( !$this->isAdmin()) {
01047 $iLang = isset( $iLang ) ? $iLang : $this->getBaseLanguage();
01048 $sLang = $this->getName()."=". $iLang;
01049 }
01050 return $sLang;
01051 }
01052
01065 public function processUrl( $sUrl, $iLang = null )
01066 {
01067 $iLang = isset( $iLang ) ? $iLang : $this->getBaseLanguage();
01068 $oStr = getStr();
01069
01070 if ( !$this->isAdmin() ) {
01071 $sParam = $this->getUrlLang( $iLang );
01072 if ( !$oStr->preg_match('/(\?|&(amp;)?)lang=[0-9]+/', $sUrl) && ($iLang != oxRegistry::getConfig()->getConfigParam( 'sDefaultLang' ))) {
01073 if ( $sUrl ) {
01074 if ($oStr->strpos( $sUrl, '?') === false) {
01075 $sUrl .= "?";
01076 } elseif ( !$oStr->preg_match('/(\?|&(amp;)?)$/', $sUrl ) ) {
01077 $sUrl .= "&";
01078 }
01079 }
01080 $sUrl .= $sParam."&";
01081 } else {
01082 $sUrl = getStr()->preg_replace('/(\?|&(amp;)?)lang=[0-9]+/', '\1'.$sParam, $sUrl);
01083 }
01084 }
01085
01086 return $sUrl;
01087 }
01088
01095 public function detectLanguageByBrowser()
01096 {
01097 $sBrowserLang = strtolower( substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ) );
01098
01099 if ( !$sBrowserLang ) {
01100 return;
01101 }
01102
01103 $aLangs = $this->getLanguageArray(null, true );
01104
01105 foreach ( $aLangs as $oLang ) {
01106 if ( $oLang->abbr == $sBrowserLang ) {
01107 return (int) $oLang->id;
01108 }
01109 }
01110 }
01111
01117 public function getMultiLangTables()
01118 {
01119 $aTables = array( "oxarticles", "oxartextends", "oxattribute",
01120 "oxcategories", "oxcontents", "oxcountry",
01121 "oxdelivery", "oxdiscount", "oxgroups",
01122 "oxlinks", "oxnews", "oxobject2attribute",
01123 "oxpayments", "oxselectlist", "oxshops",
01124 "oxactions", "oxwrapping", "oxdeliveryset",
01125 "oxvendor", "oxmanufacturers", "oxmediaurls",
01126 "oxstates" );
01127
01128
01129 $aMultiLangTables = $this->getConfig()->getConfigParam( 'aMultiLangTables' );
01130
01131 if ( is_array( $aMultiLangTables ) ) {
01132 $aTables = array_merge($aTables, $aMultiLangTables);
01133 }
01134
01135 return $aTables;
01136 }
01137
01145 public function getSeoReplaceChars($iLang)
01146 {
01147
01148 $aSeoReplaceChars = $this->translateString('_aSeoReplaceChars', $iLang);
01149 if (!is_array($aSeoReplaceChars)) {
01150 $aSeoReplaceChars = array();
01151 }
01152
01153 return $aSeoReplaceChars;
01154 }
01155
01161 protected function _getActiveModuleInfo()
01162 {
01163 if ($this->_aActiveModuleInfo === null) {
01164 $oModuleList = oxNew('oxModuleList');
01165 $this->_aActiveModuleInfo = $oModuleList->getActiveModuleInfo();
01166 }
01167 return $this->_aActiveModuleInfo;
01168 }
01169
01175 protected function _getDisabledModuleInfo()
01176 {
01177 if ($this->_aDisabledModuleInfo === null) {
01178 $oModuleList = oxNew('oxModuleList');
01179 $this->_aDisabledModuleInfo = $oModuleList->getDisabledModuleInfo();
01180 }
01181 return $this->_aDisabledModuleInfo;
01182 }
01183
01184 }