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 $sAppDir = $oConfig->getAppDir();
00688 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00689 $sTheme = $oConfig->getConfigParam( "sTheme" );
00690 $sCustomTheme = $oConfig->getConfigParam( "sCustomTheme" );
00691 $sShopId = $oConfig->getShopId();
00692 $aModulePaths = $this->_getActiveModuleInfo();
00693
00694
00695 $sGenericPath = $sAppDir . 'translations/' . $sLang;
00696 if ( $sGenericPath ) {
00697 $aLangFiles[] = $sGenericPath . "/lang.php";
00698 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sGenericPath );
00699 }
00700
00701
00702 if ( $sTheme ) {
00703 $sThemePath = $sAppDir . 'views/' . $sTheme .'/' . $sLang;
00704 $aLangFiles[] = $sThemePath . "/lang.php";
00705 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sThemePath );
00706 }
00707
00708
00709 if ( $sCustomTheme ) {
00710 $sCustPath = $sAppDir . 'views/' . $sCustomTheme .'/' . $sLang;
00711 $aLangFiles[] = $sCustPath . "/lang.php";
00712 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sCustPath );
00713 }
00714
00715
00716
00717
00718
00719 $aLangFiles = $this->_appendModuleLangFiles( $aLangFiles, $aModulePaths, $sLang );
00720
00721
00722 $aLangFiles = $this->_appendCustomLangFiles( $aLangFiles, $sLang );
00723
00724 return count( $aLangFiles ) ? $aLangFiles : false;
00725 }
00726
00734 protected function _getAdminLangFilesPathArray( $iLang )
00735 {
00736 $oConfig = $this->getConfig();
00737 $aLangFiles = array();
00738
00739 $sAppDir = $oConfig->getAppDir();
00740 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00741
00742 $aModulePaths = array();
00743 $aModulePaths = array_merge( $aModulePaths, $this->_getActiveModuleInfo() );
00744 $aModulePaths = array_merge( $aModulePaths, $this->_getDisabledModuleInfo() );
00745
00746
00747 $sAdminPath = $sAppDir . 'views/admin/' . $sLang;
00748 $aLangFiles[] = $sAdminPath . "/lang.php";
00749 $aLangFiles[] = $sAppDir . 'translations/' . $sLang . '/translit_lang.php';
00750 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sAdminPath );
00751
00752
00753 $sThemePath = $sAppDir . 'views/*/' . $sLang;
00754 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sThemePath, "options" );
00755
00756
00757 $aLangFiles = $this->_appendModuleLangFiles( $aLangFiles, $aModulePaths, $sLang, true );
00758
00759
00760 $aLangFiles = $this->_appendCustomLangFiles( $aLangFiles, $sLang, true );
00761
00762 return count( $aLangFiles ) ? $aLangFiles : false;
00763 }
00764
00774 protected function _appendLangFile( $aLangFiles, $sFullPath, $sFilePattern = "lang" )
00775 {
00776 $aFiles = glob( $sFullPath . "/*_{$sFilePattern}.php" );
00777 if ( is_array( $aFiles ) && count( $aFiles ) ) {
00778 foreach ( $aFiles as $sFile ) {
00779 if ( !strpos( $sFile, 'cust_lang.php' ) ) {
00780 $aLangFiles[] = $sFile;
00781 }
00782 }
00783 }
00784 return $aLangFiles;
00785 }
00786
00796 protected function _appendCustomLangFiles( $aLangFiles, $sLang, $blForAdmin = false )
00797 {
00798 $oConfig = $this->getConfig();
00799 $sAppDir = $oConfig->getAppDir();
00800 $sTheme = $oConfig->getConfigParam( "sTheme" );
00801 $sCustomTheme = $oConfig->getConfigParam( "sCustomTheme" );
00802
00803 if ( $blForAdmin ) {
00804 $aLangFiles[] = $sAppDir . 'views/admin/' . $sLang . '/cust_lang.php';
00805 } else {
00806 if ( $sTheme ) {
00807 $aLangFiles[] = $sAppDir . 'views/' . $sTheme . '/' . $sLang . '/cust_lang.php';
00808 }
00809 if ( $sCustomTheme ) {
00810 $aLangFiles[] = $sAppDir . 'views/' . $sCustomTheme . '/' . $sLang . '/cust_lang.php';
00811 }
00812 }
00813
00814 return $aLangFiles;
00815 }
00816
00827 protected function _appendModuleLangFiles( $aLangFiles, $aModulePaths, $sLang, $blForAdmin = false )
00828 {
00829 if ( is_array( $aModulePaths ) ) {
00830
00831 $oConfig = $this->getConfig();
00832
00833 foreach ( $aModulePaths as $sPath ) {
00834 $sFullPath = $oConfig->getModulesDir() . $sPath;
00835 $sFullPath .= ($blForAdmin) ? '/views/admin/' : '/translations/';
00836 $sFullPath .= $sLang;
00837
00838 if ( !is_dir( $sFullPath ) ) {
00839 $sFullPath = $oConfig->getModulesDir() . $sPath;
00840 $sFullPath .= ($blForAdmin) ? '/out/admin/' : '/out/lang/';
00841 $sFullPath .= $sLang;
00842 }
00843
00844 $aLangFiles = $this->_appendLangFile( $aLangFiles, $sFullPath );
00845
00846 if ( $blForAdmin ) {
00847 $aLangFiles[] = $sFullPath . '/module_options.php';
00848 }
00849 }
00850 }
00851
00852 return $aLangFiles;
00853 }
00854
00864 protected function _getLangFileCacheName( $blAdmin, $iLang, $aLangFiles = null )
00865 {
00866 $myConfig = $this->getConfig();
00867 $sLangFilesIdent = '_default';
00868 if (is_array($aLangFiles) && $aLangFiles) {
00869 $sLangFilesIdent = '_'.md5(implode('+', $aLangFiles));
00870 }
00871 return "langcache_" . ( (int) $blAdmin ) . "_{$iLang}_" . $myConfig->getShopId() . "_" . $myConfig->getConfigParam( 'sTheme' ).$sLangFilesIdent;
00872 }
00873
00883 protected function _getLanguageFileData( $blAdmin = false, $iLang = 0, $aLangFiles = null )
00884 {
00885 $myConfig = $this->getConfig();
00886 $myUtils = oxRegistry::getUtils();
00887
00888 $sCacheName = $this->_getLangFileCacheName( $blAdmin, $iLang, $aLangFiles );
00889 $aLangCache = $myUtils->getLangCache( $sCacheName );
00890 if ( !$aLangCache && $aLangFiles === null ) {
00891 if ( $blAdmin ) {
00892 $aLangFiles = $this->_getAdminLangFilesPathArray( $iLang );
00893 } else {
00894 $aLangFiles = $this->_getLangFilesPathArray( $iLang );
00895 }
00896 }
00897 if ( !$aLangCache && $aLangFiles ) {
00898 $aLangCache = array();
00899 $sBaseCharset = false;
00900 $aLang = array();
00901 $aLangSeoReplaceChars = array();
00902 foreach ( $aLangFiles as $sLangFile ) {
00903
00904 if ( file_exists( $sLangFile ) && is_readable( $sLangFile ) ) {
00905 $aSeoReplaceChars = array();
00906 include $sLangFile;
00907
00908
00909 if ( isset( $aLang['charset'] ) ) {
00910
00911
00912 if ( $myConfig->isUtf() ) {
00913 $aLang = $this->_recodeLangArray( $aLang, $aLang['charset'] );
00914
00915 if (isset($aSeoReplaceChars) && is_array($aSeoReplaceChars)) {
00916 $aSeoReplaceChars = $this->_recodeLangArray( $aSeoReplaceChars, $aLang['charset'], true );
00917 }
00918
00919
00920 $aLang['charset'] = 'UTF-8';
00921 }
00922
00923 if (isset($aSeoReplaceChars) && is_array($aSeoReplaceChars)) {
00924 $aLangSeoReplaceChars = array_merge($aLangSeoReplaceChars, $aSeoReplaceChars);
00925 }
00926
00927 if ( !$sBaseCharset ) {
00928 $sBaseCharset = $aLang['charset'];
00929 }
00930
00931 $aLangCache = array_merge( $aLangCache, $aLang );
00932 }
00933 }
00934 }
00935
00936
00937 if ( $sBaseCharset ) {
00938 $aLangCache['charset'] = $sBaseCharset;
00939 }
00940
00941
00942 $aLangCache['_aSeoReplaceChars'] = $aLangSeoReplaceChars;
00943
00944
00945 $myUtils->setLangCache( $sCacheName, $aLangCache );
00946 }
00947
00948 return $aLangCache;
00949 }
00950
00959 protected function _getLanguageMap( $iLang, $blAdmin = null )
00960 {
00961 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00962 $sKey = $iLang . ( (int) $blAdmin );
00963 if ( !isset( $this->_aLangMap[$sKey] ) ) {
00964 $this->_aLangMap[$sKey] = array();
00965 $myConfig = $this->getConfig();
00966 $sMapFile = $myConfig->getAppDir() . '/views/' . ( $blAdmin ? 'admin' : $myConfig->getConfigParam( "sTheme" ) ) .'/' . oxRegistry::getLang()->getLanguageAbbr( $iLang ) . '/map.php';
00967 if ( $sMapFile ) {
00968 if ( file_exists( $sMapFile ) && is_readable( $sMapFile ) ) {
00969 include $sMapFile;
00970 $this->_aLangMap[$sKey] = $aMap;
00971 }
00972 }
00973 }
00974
00975 return $this->_aLangMap[$sKey];
00976 }
00977
00986 protected function _getCacheLanguageId( $blAdmin, $iLang = null )
00987 {
00988 $iLang = ( $iLang === null && $blAdmin ) ? $this->getTplLanguage() : $iLang;
00989 if ( !isset( $iLang ) ) {
00990 $iLang = $this->getBaseLanguage();
00991 if ( !isset( $iLang ) ) {
00992 $iLang = 0;
00993 }
00994 }
00995
00996 return (int) $iLang;
00997 }
00998
01008 protected function _getLangTranslationArray( $iLang = null, $blAdmin = null, $aLangFiles = null )
01009 {
01010 startProfile("_getLangTranslationArray");
01011
01012 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
01013 $iLang = $this->_getCacheLanguageId( $blAdmin, $iLang );
01014 $sCacheName = $this->_getLangFileCacheName( $blAdmin, $iLang, $aLangFiles );
01015
01016 if ( !isset( $this->_aLangCache[$sCacheName] ) ) {
01017 $this->_aLangCache[$sCacheName] = array();
01018 }
01019 if ( !isset( $this->_aLangCache[$sCacheName][$iLang] ) ) {
01020
01021 $this->_aLangCache[$sCacheName][$iLang] = $this->_getLanguageFileData( $blAdmin, $iLang, $aLangFiles );
01022 }
01023
01024 stopProfile("_getLangTranslationArray");
01025
01026
01027 return ( isset( $this->_aLangCache[$sCacheName][$iLang] ) ? $this->_aLangCache[$sCacheName][$iLang] : array() );
01028 }
01029
01038 protected function _sortLanguagesCallback( $a1, $a2 )
01039 {
01040 return ($a1->sort > $a2->sort);
01041 }
01042
01048 public function getName()
01049 {
01050 return $this->_sName;
01051 }
01052
01058 public function getFormLang()
01059 {
01060 $sLang = null;
01061 if ( !$this->isAdmin()) {
01062 $sLang = "<input type=\"hidden\" name=\"".$this->getName()."\" value=\"". $this->getBaseLanguage() . "\" />";
01063 }
01064 return $sLang;
01065 }
01066
01074 public function getUrlLang( $iLang = null )
01075 {
01076 $sLang = null;
01077 if ( !$this->isAdmin()) {
01078 $iLang = isset( $iLang ) ? $iLang : $this->getBaseLanguage();
01079 $sLang = $this->getName()."=". $iLang;
01080 }
01081 return $sLang;
01082 }
01083
01096 public function processUrl( $sUrl, $iLang = null )
01097 {
01098 $iLang = isset( $iLang ) ? $iLang : $this->getBaseLanguage();
01099 $oStr = getStr();
01100
01101 if ( !$this->isAdmin() ) {
01102 $sParam = $this->getUrlLang( $iLang );
01103 if ( !$oStr->preg_match('/(\?|&(amp;)?)lang=[0-9]+/', $sUrl) && ($iLang != oxRegistry::getConfig()->getConfigParam( 'sDefaultLang' ))) {
01104 if ( $sUrl ) {
01105 if ($oStr->strpos( $sUrl, '?') === false) {
01106 $sUrl .= "?";
01107 } elseif ( !$oStr->preg_match('/(\?|&(amp;)?)$/', $sUrl ) ) {
01108 $sUrl .= "&";
01109 }
01110 }
01111 $sUrl .= $sParam."&";
01112 } else {
01113 $sUrl = getStr()->preg_replace('/(\?|&(amp;)?)lang=[0-9]+/', '\1'.$sParam, $sUrl);
01114 }
01115 }
01116
01117 return $sUrl;
01118 }
01119
01126 public function detectLanguageByBrowser()
01127 {
01128 $sBrowserLang = strtolower( substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ) );
01129
01130 if ( !$sBrowserLang ) {
01131 return;
01132 }
01133
01134 $aLangs = $this->getLanguageArray(null, true );
01135
01136 foreach ( $aLangs as $oLang ) {
01137 if ( $oLang->abbr == $sBrowserLang ) {
01138 return (int) $oLang->id;
01139 }
01140 }
01141 }
01142
01148 public function getMultiLangTables()
01149 {
01150 $aTables = array( "oxarticles", "oxartextends", "oxattribute",
01151 "oxcategories", "oxcontents", "oxcountry",
01152 "oxdelivery", "oxdiscount", "oxgroups",
01153 "oxlinks", "oxnews", "oxobject2attribute",
01154 "oxpayments", "oxselectlist", "oxshops",
01155 "oxactions", "oxwrapping", "oxdeliveryset",
01156 "oxvendor", "oxmanufacturers", "oxmediaurls",
01157 "oxstates" );
01158
01159
01160 $aMultiLangTables = $this->getConfig()->getConfigParam( 'aMultiLangTables' );
01161
01162 if ( is_array( $aMultiLangTables ) ) {
01163 $aTables = array_merge($aTables, $aMultiLangTables);
01164 }
01165
01166 return $aTables;
01167 }
01168
01176 public function getSeoReplaceChars($iLang)
01177 {
01178
01179 $aSeoReplaceChars = $this->translateString('_aSeoReplaceChars', $iLang);
01180 if (!is_array($aSeoReplaceChars)) {
01181 $aSeoReplaceChars = array();
01182 }
01183
01184 return $aSeoReplaceChars;
01185 }
01186
01192 protected function _getActiveModuleInfo()
01193 {
01194 if ($this->_aActiveModuleInfo === null) {
01195 $oModulelist = oxNew('oxmodulelist');
01196 $this->_aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
01197 }
01198 return $this->_aActiveModuleInfo;
01199 }
01200
01206 protected function _getDisabledModuleInfo()
01207 {
01208 if ($this->_aDisabledModuleInfo === null) {
01209 $oModulelist = oxNew('oxmodulelist');
01210 $this->_aDisabledModuleInfo = $oModulelist->getDisabledModuleInfo();
01211 }
01212 return $this->_aDisabledModuleInfo;
01213 }
01214
01215 }