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
00320 $aLangData = array();
00321 $aLangIds = $this->getLanguageIds();
00322
00323 $sSourceDir = $myConfig->getAppDir() . 'views/admin/';
00324 foreach ( glob( $sSourceDir."*", GLOB_ONLYDIR ) as $sDir ) {
00325 $sFilePath = "{$sDir}/lang.php";
00326 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
00327 $sLangName = "";
00328 $sAbbr = strtolower( basename( $sDir ) );
00329 if ( !in_array( $sAbbr, $aLangIds ) ) {
00330 include $sFilePath;
00331 $aLangData[$sAbbr] = new stdClass();
00332 $aLangData[$sAbbr]->name = $sLangName;
00333 $aLangData[$sAbbr]->abbr = $sAbbr;
00334 }
00335 }
00336 }
00337
00338 $this->_aAdminTplLanguageArray = $this->getLanguageArray();
00339 if ( count( $aLangData ) ) {
00340
00341
00342 ksort( $aLangData );
00343 $iSort = max( array_keys( $this->_aAdminTplLanguageArray ) );
00344
00345
00346 foreach ( $aLangData as $oLang ) {
00347 $oLang->id = $oLang->sort = ++$iSort;
00348 $oLang->selected = 0;
00349 $oLang->active = 0;
00350 $this->_aAdminTplLanguageArray[$iSort] = $oLang;
00351 }
00352 }
00353 }
00354
00355
00356 reset( $this->_aAdminTplLanguageArray );
00357 return $this->_aAdminTplLanguageArray;
00358 }
00359
00367 public function getLanguageAbbr( $iLanguage = null )
00368 {
00369 if ( $this->_aLangAbbr === null ) {
00370 $this->_aLangAbbr = array();
00371 if ( $this->isAdmin() ) {
00372 foreach ( $this->getAdminTplLanguageArray() as $oLang ) {
00373 $this->_aLangAbbr[$oLang->id] = $oLang->abbr;
00374 }
00375 } else {
00376 $this->_aLangAbbr = $this->getLanguageIds();
00377 }
00378 }
00379
00380 $iLanguage = isset( $iLanguage ) ? (int) $iLanguage : $this->getBaseLanguage();
00381 if ( isset( $this->_aLangAbbr[$iLanguage] ) ) {
00382 $iLanguage = $this->_aLangAbbr[$iLanguage];
00383 }
00384
00385 return $iLanguage;
00386 }
00387
00394 public function getLanguageNames()
00395 {
00396 $aConfLanguages = $this->getConfig()->getConfigParam( 'aLanguages' );
00397 $aLangIds = $this->getLanguageIds();
00398 $aLanguages = array();
00399 foreach ( $aLangIds as $iId => $sValue ) {
00400 $aLanguages[$iId] = $aConfLanguages[$sValue];
00401 }
00402 return $aLanguages;
00403 }
00404
00410 public function getLanguageIds()
00411 {
00412 $myConfig = $this->getConfig();
00413 $aIds = array();
00414
00415
00416 $aLangParams = $myConfig->getConfigParam( 'aLanguageParams' );
00417 if ( is_array( $aLangParams ) ) {
00418 foreach ( $aLangParams as $sAbbr => $aValue ) {
00419 $iBaseId = (int) $aValue['baseId'];
00420 $aIds[$iBaseId] = $sAbbr;
00421 }
00422 } else {
00423 $aIds = array_keys( $myConfig->getConfigParam( 'aLanguages' ) );
00424 }
00425
00426 return $aIds;
00427 }
00428
00441 public function translateString( $sStringToTranslate, $iLang = null, $blAdminMode = null )
00442 {
00443
00444 $aLang = $this->_getLangTranslationArray( $iLang, $blAdminMode );
00445 if ( isset( $aLang[$sStringToTranslate] ) ) {
00446 return $aLang[$sStringToTranslate];
00447 }
00448
00449
00450 $aMap = $this->_getLanguageMap( $iLang, $blAdminMode );
00451 if ( isset( $aLang[$aMap[$sStringToTranslate]] ) ) {
00452 return $aLang[$aMap[$sStringToTranslate]];
00453 }
00454
00455
00456 if (count($this->_aAdditionalLangFiles)) {
00457 $aLang = $this->_getLangTranslationArray( $iLang, $blAdminMode, $this->_aAdditionalLangFiles);
00458 if (isset( $aLang[$sStringToTranslate] )) {
00459 return $aLang[$sStringToTranslate];
00460 }
00461 }
00462
00463 return $sStringToTranslate;
00464 }
00465
00476 protected function _collectSimilar( $aData, $sKey, $aCollection = array() )
00477 {
00478 foreach ( $aData as $sValKey => $sValue ) {
00479 if ( strpos( $sValKey, $sKey ) === 0 ) {
00480 $aCollection[$sValKey] = $sValue;
00481 }
00482 }
00483
00484 return $aCollection;
00485 }
00486
00497 public function getSimilarByKey( $sKey, $iLang = null, $blAdmin = null )
00498 {
00499 startProfile("getSimilarByKey");
00500
00501 $iLang = isset( $iLang ) ? $iLang : $this->getTplLanguage();
00502 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00503
00504
00505 $aLang = $this->_getLangTranslationArray( $iLang, $blAdmin );
00506 $aSimilarConst = $this->_collectSimilar( $aLang, $sKey );
00507
00508
00509 $aMap = $this->_getLanguageMap( $iLang, $blAdminMode );
00510 $aSimilarConst = $this->_collectSimilar( $aMap, $sKey, $aSimilarConst );
00511
00512
00513 if ( count( $this->_aAdditionalLangFiles ) ) {
00514 $aLang = $this->_getLangTranslationArray( $iLang, $blAdminMode, $this->_aAdditionalLangFiles);
00515 $aSimilarConst = $this->_collectSimilar( $aLang, $sKey, $aSimilarConst );
00516 }
00517
00518 stopProfile("getSimilarByKey");
00519
00520 return $aSimilarConst;
00521 }
00522
00531 public function formatCurrency( $dValue, $oActCur = null )
00532 {
00533 if ( !$oActCur ) {
00534 $oActCur = $this->getConfig()->getActShopCurrencyObject();
00535 }
00536 $sValue = oxRegistry::getUtils()->fRound( $dValue, $oActCur );
00537 return number_format( (double)$sValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand );
00538 }
00539
00548 public function formatVat( $dValue, $oActCur = null )
00549 {
00550 $iDecPos = 0;
00551 $sValue = ( string ) $dValue;
00552 $oStr = getStr();
00553 if ( ( $iDotPos = $oStr->strpos( $sValue, '.' ) ) !== false ) {
00554 $iDecPos = $oStr->strlen( $oStr->substr( $sValue, $iDotPos + 1 ) );
00555 }
00556
00557 $oActCur = $oActCur ? $oActCur : $this->getConfig()->getActShopCurrencyObject();
00558 $iDecPos = ( $iDecPos < $oActCur->decimal ) ? $iDecPos : $oActCur->decimal;
00559 return number_format( (double)$dValue, $iDecPos, $oActCur->dec, $oActCur->thousand );
00560 }
00561
00569 public function getLanguageTag( $iLanguage = null)
00570 {
00571 if ( !isset( $iLanguage ) ) {
00572 $iLanguage = $this->getBaseLanguage();
00573 }
00574
00575 $iLanguage = (int) $iLanguage;
00576
00577 return ( ( $iLanguage )?"_$iLanguage":"" );
00578 }
00579
00587 public function validateLanguage( $iLang = null )
00588 {
00589 $iLang = (int) $iLang;
00590
00591
00592 $aLanguages = $this->getLanguageArray( null, !$this->isAdmin() );
00593 if ( !isset( $aLanguages[$iLang] ) && is_array( $aLanguages ) ) {
00594 $oLang = current( $aLanguages );
00595 if (isset($oLang->id)) {
00596 $iLang = $oLang->id;
00597 }
00598 }
00599
00600 return $iLang;
00601 }
00602
00610 public function setBaseLanguage( $iLang = null )
00611 {
00612 if ( is_null($iLang) ) {
00613 $iLang = $this->getBaseLanguage();
00614 } else {
00615 $this->_iBaseLanguageId = (int) $iLang;
00616 }
00617
00618 if ( defined( 'OXID_PHP_UNIT' ) ) {
00619 modSession::getInstance();
00620 }
00621
00622 oxSession::setVar( 'language', $iLang );
00623 }
00624
00632 public function setTplLanguage( $iLang = null )
00633 {
00634 $this->_iTplLanguageId = isset( $iLang ) ? (int) $iLang : $this->getBaseLanguage();
00635 if ( $this->isAdmin() ) {
00636 $aLanguages = $this->getAdminTplLanguageArray();
00637 if ( !isset( $aLanguages[$this->_iTplLanguageId] ) ) {
00638 $this->_iTplLanguageId = key( $aLanguages );
00639 }
00640 }
00641
00642 if ( defined( 'OXID_PHP_UNIT' ) ) {
00643 modSession::getInstance();
00644 }
00645
00646 oxSession::setVar( 'tpllanguage', $this->_iTplLanguageId );
00647 return $this->_iTplLanguageId;
00648 }
00649
00659 protected function _recodeLangArray( $aLangArray, $sCharset, $blRecodeKeys = false )
00660 {
00661 $aLangs = array();
00662 foreach ( $aLangArray as $sKey => $sValue ) {
00663 $sItemKey = $sKey;
00664 if ($blRecodeKeys === true) {
00665 $sItemKey = iconv($sCharset, 'UTF-8', $sItemKey);
00666 }
00667
00668 $aLangs[$sItemKey] = iconv( $sCharset, 'UTF-8', $sValue );
00669 unset($aLangArray[$sKey]);
00670 }
00671
00672 return $aLangs;
00673 }
00674
00682 protected function _getLangFilesPathArray( $iLang )
00683 {
00684 $oConfig = $this->getConfig();
00685 $aLangFiles = array();
00686
00687
00688 $sAppDir = $oConfig->getAppDir();
00689 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00690 $sTheme = $oConfig->getConfigParam( "sTheme" );
00691 $sCustomTheme = $oConfig->getConfigParam( "sCustomTheme" );
00692 $sShopId = $oConfig->getShopId();
00693 $aModuleInfo = $this->_getActiveModuleInfo();
00694
00695
00696 $sGenericPath = $sAppDir . 'translations/' . $sLang;
00697 if ( $sGenericPath ) {
00698 $aLangFiles[] = $sGenericPath . "/lang.php";
00699 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sGenericPath );
00700 }
00701
00702
00703 if ( $sTheme ) {
00704 $sThemePath = $sAppDir . 'views/' . $sTheme .'/' . $sLang;
00705 $aLangFiles[] = $sThemePath . "/lang.php";
00706 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sThemePath );
00707 }
00708
00709
00710 if ( $sCustomTheme ) {
00711 $sCustPath = $sAppDir . 'views/' . $sCustomTheme .'/' . $sLang;
00712 $aLangFiles[] = $sCustPath . "/lang.php";
00713 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sCustPath );
00714
00715
00716 if ( $sCustomTheme ) {
00717 $sShopPath = $sAppDir . 'views/'. $sCustomTheme .'/' . $sShopId . '/' . $sLang;
00718 $aLangFiles[] = $sShopPath . "/lang.php";
00719 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sShopPath );
00720 }
00721 } else {
00722
00723 if ( $sTheme ) {
00724 $sShopPath = $sAppDir . 'views/'. $sTheme .'/' . $sShopId . '/' . $sLang;
00725 $aLangFiles[] = $sShopPath . "/lang.php";
00726 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sShopPath );
00727 }
00728 }
00729
00730
00731 if ( is_array( $aModuleInfo ) ) {
00732 foreach ( $aModuleInfo as $sPath ) {
00733 $sFullPath = $oConfig->getModulesDir() . $sPath . '/translations/' . $sLang;
00734
00735 if ( !is_dir($sFullPath) ) {
00736 $sFullPath = $oConfig->getModulesDir() . $sPath . '/out/lang/' . $sLang;
00737 }
00738 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sFullPath );
00739 }
00740 }
00741
00742 return count( $aLangFiles ) ? $aLangFiles : false;
00743 }
00744
00752 protected function _getAdminLangFilesPathArray( $iLang )
00753 {
00754 $oConfig = $this->getConfig();
00755 $aLangFiles = array();
00756
00757
00758 $sAppDir = $oConfig->getAppDir();
00759 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00760
00761 $aActiveModuleInfo = $this->_getActiveModuleInfo();
00762 $aDisabledModuleInfo = $this->_getDisabledModuleInfo();
00763
00764
00765
00766 $sAdminPath = $sAppDir . 'views/admin/' . $sLang;
00767 $aLangFiles[] = $sAdminPath . "/lang.php";
00768 $aLangFiles[] = $sAppDir . 'translations/' . $sLang . '/translit_lang.php';
00769 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sAdminPath );
00770
00771
00772 $sThemePath = $sAppDir . 'views/*/' . $sLang;
00773
00774 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sThemePath, "options" );
00775
00776
00777 if ( is_array( $aActiveModuleInfo ) ) {
00778 foreach ( $aActiveModuleInfo as $sPath ) {
00779 $sFullPath = $oConfig->getModulesDir() . $sPath . '/views/admin/' . $sLang;
00780
00781 if ( !is_dir($sFullPath) ) {
00782 $sFullPath = $oConfig->getModulesDir() . $sPath . '/out/admin/' . $sLang;
00783 }
00784 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sFullPath );
00785
00786 $aLangFiles[] = $sFullPath . '/module_options.php';
00787 }
00788 }
00789
00790
00791 if ( is_array( $aDisabledModuleInfo ) ) {
00792 foreach ( $aDisabledModuleInfo as $sPath ) {
00793 $sFullPath = $oConfig->getModulesDir() . $sPath . '/views/admin/' . $sLang;
00794
00795 if ( !is_dir($sFullPath) ) {
00796 $sFullPath = $oConfig->getModulesDir() . $sPath . '/out/admin/' . $sLang;
00797 }
00798 $aLangFiles[] = $sFullPath . '/module_options.php';
00799 }
00800 }
00801
00802 return count( $aLangFiles ) ? $aLangFiles : false;
00803 }
00804
00814 protected function _appendLangFile( $aLangFiles, $sFullPath, $sFilePattern = "lang" )
00815 {
00816 $aModuleFiles = glob( $sFullPath . "/*_{$sFilePattern}.php" );
00817 if ( is_array( $aModuleFiles ) && count( $aModuleFiles ) ) {
00818 $aLangFiles = array_merge( $aLangFiles, $aModuleFiles );
00819 }
00820 return $aLangFiles;
00821 }
00822
00832 protected function _getLangFileCacheName( $blAdmin, $iLang, $aLangFiles = null )
00833 {
00834 $myConfig = $this->getConfig();
00835 $sLangFilesIdent = '_default';
00836 if (is_array($aLangFiles) && $aLangFiles) {
00837 $sLangFilesIdent = '_'.md5(implode('+', $aLangFiles));
00838 }
00839 return "langcache_" . ( (int) $blAdmin ) . "_{$iLang}_" . $myConfig->getShopId() . "_" . $myConfig->getConfigParam( 'sTheme' ).$sLangFilesIdent;
00840 }
00841
00851 protected function _getLanguageFileData( $blAdmin = false, $iLang = 0, $aLangFiles = null )
00852 {
00853 $myConfig = $this->getConfig();
00854 $myUtils = oxRegistry::getUtils();
00855
00856 $sCacheName = $this->_getLangFileCacheName( $blAdmin, $iLang, $aLangFiles );
00857 $aLangCache = $myUtils->getLangCache( $sCacheName );
00858 if ( !$aLangCache && $aLangFiles === null ) {
00859 if ( $blAdmin ) {
00860 $aLangFiles = $this->_getAdminLangFilesPathArray( $iLang );
00861 } else {
00862 $aLangFiles = $this->_getLangFilesPathArray( $iLang );
00863 }
00864 }
00865 if ( !$aLangCache && $aLangFiles ) {
00866 $aLangCache = array();
00867 $sBaseCharset = false;
00868 $aLang = array();
00869 $aLangSeoReplaceChars = array();
00870 foreach ( $aLangFiles as $sLangFile ) {
00871
00872 if ( file_exists( $sLangFile ) && is_readable( $sLangFile ) ) {
00873 $aSeoReplaceChars = array();
00874 include $sLangFile;
00875
00876
00877 if ( isset( $aLang['charset'] ) ) {
00878
00879
00880 if ( $myConfig->isUtf() ) {
00881 $aLang = $this->_recodeLangArray( $aLang, $aLang['charset'] );
00882
00883 if (isset($aSeoReplaceChars) && is_array($aSeoReplaceChars)) {
00884 $aSeoReplaceChars = $this->_recodeLangArray( $aSeoReplaceChars, $aLang['charset'], true );
00885 }
00886
00887
00888 $aLang['charset'] = 'UTF-8';
00889 }
00890
00891 if (isset($aSeoReplaceChars) && is_array($aSeoReplaceChars)) {
00892 $aLangSeoReplaceChars = array_merge($aLangSeoReplaceChars, $aSeoReplaceChars);
00893 }
00894
00895 if ( !$sBaseCharset ) {
00896 $sBaseCharset = $aLang['charset'];
00897 }
00898
00899 $aLangCache = array_merge( $aLangCache, $aLang );
00900 }
00901 }
00902 }
00903
00904
00905 if ( $sBaseCharset ) {
00906 $aLangCache['charset'] = $sBaseCharset;
00907 }
00908
00909
00910 $aLangCache['_aSeoReplaceChars'] = $aLangSeoReplaceChars;
00911
00912
00913 $myUtils->setLangCache( $sCacheName, $aLangCache );
00914 }
00915
00916 return $aLangCache;
00917 }
00918
00927 protected function _getLanguageMap( $iLang, $blAdmin = null )
00928 {
00929 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00930 $sKey = $iLang . ( (int) $blAdmin );
00931 if ( !isset( $this->_aLangMap[$sKey] ) ) {
00932 $this->_aLangMap[$sKey] = array();
00933 $myConfig = $this->getConfig();
00934 $sMapFile = $myConfig->getAppDir() . '/views/' . ( $blAdmin ? 'admin' : $myConfig->getConfigParam( "sTheme" ) ) .'/' . oxRegistry::getLang()->getLanguageAbbr( $iLang ) . '/map.php';
00935 if ( $sMapFile ) {
00936 if ( file_exists( $sMapFile ) && is_readable( $sMapFile ) ) {
00937 include $sMapFile;
00938 $this->_aLangMap[$sKey] = $aMap;
00939 }
00940 }
00941 }
00942
00943 return $this->_aLangMap[$sKey];
00944 }
00945
00954 protected function _getCacheLanguageId( $blAdmin, $iLang = null )
00955 {
00956 $iLang = ( $iLang === null && $blAdmin ) ? $this->getTplLanguage() : $iLang;
00957 if ( !isset( $iLang ) ) {
00958 $iLang = $this->getBaseLanguage();
00959 if ( !isset( $iLang ) ) {
00960 $iLang = 0;
00961 }
00962 }
00963
00964 return (int) $iLang;
00965 }
00966
00976 protected function _getLangTranslationArray( $iLang = null, $blAdmin = null, $aLangFiles = null )
00977 {
00978 startProfile("_getLangTranslationArray");
00979
00980 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00981 $iLang = $this->_getCacheLanguageId( $blAdmin, $iLang );
00982 $sCacheName = $this->_getLangFileCacheName( $blAdmin, $iLang, $aLangFiles );
00983
00984 if ( !isset( $this->_aLangCache[$sCacheName] ) ) {
00985 $this->_aLangCache[$sCacheName] = array();
00986 }
00987 if ( !isset( $this->_aLangCache[$sCacheName][$iLang] ) ) {
00988
00989 $this->_aLangCache[$sCacheName][$iLang] = $this->_getLanguageFileData( $blAdmin, $iLang, $aLangFiles );
00990 }
00991
00992 stopProfile("_getLangTranslationArray");
00993
00994
00995 return ( isset( $this->_aLangCache[$sCacheName][$iLang] ) ? $this->_aLangCache[$sCacheName][$iLang] : array() );
00996 }
00997
01006 protected function _sortLanguagesCallback( $a1, $a2 )
01007 {
01008 return ($a1->sort > $a2->sort);
01009 }
01010
01016 public function getName()
01017 {
01018 return $this->_sName;
01019 }
01020
01026 public function getFormLang()
01027 {
01028 $sLang = null;
01029 if ( !$this->isAdmin()) {
01030 $sLang = "<input type=\"hidden\" name=\"".$this->getName()."\" value=\"". $this->getBaseLanguage() . "\">";
01031 }
01032 return $sLang;
01033 }
01034
01042 public function getUrlLang( $iLang = null )
01043 {
01044 $sLang = null;
01045 if ( !$this->isAdmin()) {
01046 $iLang = isset( $iLang ) ? $iLang : $this->getBaseLanguage();
01047 $sLang = $this->getName()."=". $iLang;
01048 }
01049 return $sLang;
01050 }
01051
01064 public function processUrl( $sUrl, $iLang = null )
01065 {
01066 $iLang = isset( $iLang ) ? $iLang : $this->getBaseLanguage();
01067 $oStr = getStr();
01068
01069 if ( !$this->isAdmin() ) {
01070 $sParam = $this->getUrlLang( $iLang );
01071 if ( !$oStr->preg_match('/(\?|&(amp;)?)lang=[0-9]+/', $sUrl) && ($iLang != oxRegistry::getConfig()->getConfigParam( 'sDefaultLang' ))) {
01072 if ( $sUrl ) {
01073 if ($oStr->strpos( $sUrl, '?') === false) {
01074 $sUrl .= "?";
01075 } elseif ( !$oStr->preg_match('/(\?|&(amp;)?)$/', $sUrl ) ) {
01076 $sUrl .= "&";
01077 }
01078 }
01079 $sUrl .= $sParam."&";
01080 } else {
01081 $sUrl = getStr()->preg_replace('/(\?|&(amp;)?)lang=[0-9]+/', '\1'.$sParam, $sUrl);
01082 }
01083 }
01084
01085 return $sUrl;
01086 }
01087
01094 public function detectLanguageByBrowser()
01095 {
01096 $sBrowserLang = strtolower( substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ) );
01097
01098 if ( !$sBrowserLang ) {
01099 return;
01100 }
01101
01102 $aLangs = $this->getLanguageArray(null, true );
01103
01104 foreach ( $aLangs as $oLang ) {
01105 if ( $oLang->abbr == $sBrowserLang ) {
01106 return (int) $oLang->id;
01107 }
01108 }
01109 }
01110
01116 public function getMultiLangTables()
01117 {
01118 $aTables = array( "oxarticles", "oxartextends", "oxattribute",
01119 "oxcategories", "oxcontents", "oxcountry",
01120 "oxdelivery", "oxdiscount", "oxgroups",
01121 "oxlinks", "oxnews", "oxobject2attribute",
01122 "oxpayments", "oxselectlist", "oxshops",
01123 "oxactions", "oxwrapping", "oxdeliveryset",
01124 "oxvendor", "oxmanufacturers", "oxmediaurls",
01125 "oxstates" );
01126
01127
01128 $aMultiLangTables = $this->getConfig()->getConfigParam( 'aMultiLangTables' );
01129
01130 if ( is_array( $aMultiLangTables ) ) {
01131 $aTables = array_merge($aTables, $aMultiLangTables);
01132 }
01133
01134 return $aTables;
01135 }
01136
01144 public function getSeoReplaceChars($iLang)
01145 {
01146
01147 $aSeoReplaceChars = $this->translateString('_aSeoReplaceChars', $iLang);
01148 if (!is_array($aSeoReplaceChars)) {
01149 $aSeoReplaceChars = array();
01150 }
01151
01152 return $aSeoReplaceChars;
01153 }
01154
01160 protected function _getActiveModuleInfo()
01161 {
01162 if ($this->_aActiveModuleInfo === null) {
01163 $oModulelist = oxNew('oxmodulelist');
01164 $this->_aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
01165 }
01166 return $this->_aActiveModuleInfo;
01167 }
01168
01174 protected function _getDisabledModuleInfo()
01175 {
01176 if ($this->_aDisabledModuleInfo === null) {
01177 $oModulelist = oxNew('oxmodulelist');
01178 $this->_aDisabledModuleInfo = $oModulelist->getDisabledModuleInfo();
01179 }
01180 return $this->_aDisabledModuleInfo;
01181 }
01182
01183 }