00001 <?php
00002
00010 function oxAutoload( $sClass )
00011 {
00012 startProfile("oxAutoload");
00013 $sClass = basename( $sClass );
00014 $sClass = strtolower($sClass);
00015
00016 static $sBasePath = null;
00017 static $aClassDirs = null;
00018
00019
00020 static $aTriedClasses = array();
00021
00022
00023
00024 $sBaseClassLocation = null;
00025 $aBaseClasses = array("oxutils", "oxsupercfg", "oxutilsobject");
00026 if (in_array($sClass, $aBaseClasses)) {
00027 $sFilename = getShopBasePath() ."core/" . $sClass . ".php" ;
00028 include $sFilename;
00029 return;
00030 }
00031
00032 static $aClassPaths;
00033
00034 if (isset($aClassPaths[$sClass])) {
00035 stopProfile("oxAutoload");
00036 include $aClassPaths[$sClass];
00037 return;
00038 }
00039
00040 $sBasePath = getShopBasePath();
00041
00042
00043
00044 if ( $aClassDirs == null ) {
00045 $aClassDirs = getClassDirs ( $sBasePath );
00046 }
00047
00048 foreach ( $aClassDirs as $sDir ) {
00049 $sFilename = $sDir . $sClass . '.php';
00050 if ( file_exists( $sFilename ) ) {
00051 if (!isset($aClassPaths[$sClass])) {
00052 $aClassPaths[$sClass] = $sFilename;
00053
00054 }
00055 stopProfile("oxAutoload");
00056 include $sFilename;
00057 return;
00058 }
00059 }
00060
00061
00062
00063
00064
00065 $aModuleFiles = oxUtilsObject::getInstance()->getModuleVar( 'aModuleFiles' );
00066 if ( is_array( $aModuleFiles ) ) {
00067 $sBasePath = getShopBasePath();
00068 $oModulelist = oxNew('oxmodulelist');
00069 $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
00070 if (is_array($aActiveModuleInfo)) {
00071 foreach ($aModuleFiles as $sModuleId => $aModules) {
00072 if (isset($aModules[$sClass]) && isset($aActiveModuleInfo[$sModuleId])) {
00073 $sPath = $aModules[$sClass];
00074 $sFilename = $sBasePath. 'modules/'. $sPath;
00075 if ( file_exists( $sFilename ) ) {
00076 if (!isset($aClassPaths[$sClass])) {
00077 $aClassPaths[$sClass] = $sFilename;
00078 oxRegistry::getUtils()->toPhpFileCache("class_file_paths", $aClassPaths);
00079 }
00080 stopProfile("oxAutoload");
00081 include $sFilename;
00082 return;
00083 }
00084 }
00085 }
00086 }
00087 }
00088
00089
00090 $sClass = preg_replace( '/_parent$/i', '', $sClass );
00091
00092
00093 if ( !in_array( $sClass, $aTriedClasses ) && is_array( $aModules = oxUtilsObject::getInstance()->getModuleVar( 'aModules' ) ) ) {
00094
00095 $myUtilsObject = oxUtilsObject::getInstance();
00096 foreach ( $aModules as $sParentName => $sModuleName ) {
00097
00098 if ( preg_match('/\b'.$sClass.'($|\&)/i', $sModuleName ) ) {
00099 $myUtilsObject->getClassName( $sParentName );
00100 break;
00101 }
00102 $aTriedClasses[] = $sClass;
00103 }
00104 }
00105
00106 stopProfile("oxAutoload");
00107 }
00108
00116 function getClassDirs($sBasePath)
00117 {
00118 $aClassDirs = array( $sBasePath . 'core/',
00119 $sBasePath . 'application/components/widgets/',
00120 $sBasePath . 'application/components/',
00121 $sBasePath . 'application/models/',
00122 $sBasePath . 'application/controllers/',
00123 $sBasePath . 'application/controllers/admin/',
00124 $sBasePath . 'application/controllers/admin/reports/',
00125 $sBasePath . 'views/',
00126 $sBasePath . 'core/exception/',
00127 $sBasePath . 'core/interface/',
00128 $sBasePath . 'core/cache/',
00129 $sBasePath . 'core/cache/connectors/',
00130 $sBasePath . 'core/wysiwigpro/',
00131 $sBasePath . 'admin/reports/',
00132 $sBasePath . 'admin/',
00133 $sBasePath . 'modules/',
00134 $sBasePath
00135 );
00136 return $aClassDirs;
00137 }
00138
00139
00140 if ( !function_exists( 'getShopBasePath' ) ) {
00146 function getShopBasePath()
00147 {
00148 return OX_BASE_PATH;
00149 }
00150 }
00151
00157 function isAdmin()
00158 {
00159 if (defined('OX_IS_ADMIN')) {
00160 return OX_IS_ADMIN;
00161 }
00162
00163 return false;
00164 }
00165
00171 function setPhpIniParams()
00172 {
00173
00174 ini_set('session.name', 'sid');
00175 ini_set('session.use_cookies', 0);
00176 ini_set('session.use_trans_sid', 0);
00177 ini_set('url_rewriter.tags', '');
00178 ini_set('magic_quotes_runtime', 0);
00179 }
00180
00186 function stripGpcMagicQuotes()
00187 {
00188 if (!get_magic_quotes_gpc()) {
00189 return;
00190 }
00191 $_REQUEST = _stripMagicQuotes($_REQUEST);
00192 $_POST = _stripMagicQuotes($_POST);
00193 $_GET = _stripMagicQuotes($_GET);
00194 $_COOKIE = _stripMagicQuotes($_COOKIE);
00195 }
00196
00204 function _stripMagicQuotes($mInput)
00205 {
00206 return is_array($mInput) ? array_map( '_stripMagicQuotes', $mInput ) : stripslashes( $mInput );
00207 }
00208
00209 if ( !function_exists( 'error_404_handler' ) ) {
00217 function error_404_handler($sUrl = '')
00218 {
00219 oxRegistry::getUtils()->handlePageNotFoundError($sUrl);
00220 }
00221 }
00222
00234 function warningHandler($iErrorNr, $sErrorText)
00235 {
00236 echo "<div class='error_box'>".oxRegistry::getLang()->translateString('userError')."<code>[$iErrorNr] $sErrorText</code></div>";
00237 }
00238
00247 function dumpVar( $mVar, $blToFile = false )
00248 {
00249 $myConfig = oxRegistry::getConfig();
00250 if ( $blToFile ) {
00251 $out = var_export( $mVar, true );
00252 $f = fopen( $myConfig->getConfigParam( 'sCompileDir' )."/vardump.txt", "a" );
00253 fwrite( $f, $out );
00254 fclose( $f );
00255 } else {
00256 echo '<pre>';
00257 var_export( $mVar );
00258 echo '</pre>';
00259 }
00260 }
00261
00262 if ( !function_exists( 'isSearchEngineUrl' ) ) {
00263
00269 function isSearchEngineUrl()
00270 {
00271 return false;
00272 }
00273 }
00274
00282 function debug( $mVar )
00283 {
00284 $f = fopen( 'out.txt', 'a' );
00285 $sString = var_export( $mVar, true );
00286 fputs( $f, $sString."\n---------------------------------------------\n" );
00287 fclose( $f );
00288 }
00289
00298 function cmpart( $a, $b )
00299 {
00300
00301 if ( $a->cnt == $b->cnt )
00302 return 0;
00303 return ( $a->cnt < $b->cnt ) ? -1 : 1;
00304 }
00305
00306 if ( !function_exists( 'startProfile' ) ) {
00314 function startProfile( $sProfileName )
00315 {
00316 global $aStartTimes;
00317 global $aExecutionCounts;
00318 if (!isset($aExecutionCounts[$sProfileName])) {
00319 $aExecutionCounts[$sProfileName] = 0;
00320 }
00321 if (!isset($aStartTimes[$sProfileName])) {
00322 $aStartTimes[$sProfileName] = 0;
00323 }
00324 $aExecutionCounts[$sProfileName]++;
00325 $aStartTimes[$sProfileName] = microtime(true);
00326 }
00327 }
00328
00329 if ( !function_exists( 'stopProfile' ) ) {
00337 function stopProfile( $sProfileName )
00338 {
00339 global $aProfileTimes;
00340 global $aStartTimes;
00341 if (!isset($aProfileTimes[$sProfileName])) {
00342 $aProfileTimes[$sProfileName] = 0;
00343 }
00344 $aProfileTimes[$sProfileName] += microtime( true ) - $aStartTimes[$sProfileName];
00345 }
00346 }
00347
00358 function oxNew( $sClassName )
00359 {
00360 startProfile( 'oxNew' );
00361 $aArgs = func_get_args();
00362 $oRes = call_user_func_array( array( oxUtilsObject::getInstance(), "oxNew" ), $aArgs );
00363 stopProfile( 'oxNew' );
00364 return $oRes;
00365 }
00366
00376 function oxNewArticle( $sArtId )
00377 {
00378 return oxUtilsObject::getInstance()->oxNewArticle( $sArtId );
00379 }
00380
00388 function getDb($blAssoc = true)
00389 {
00390 return oxDb::getDb($blAssoc);
00391 }
00392
00398 function getStr()
00399 {
00400 return oxStr::getStr();
00401 }
00402
00412 function ox_get_template( $sTplName, &$sTplSource, $oSmarty )
00413 {
00414 $sTplSource = $oSmarty->oxidcache->value;
00415 if ( oxRegistry::getConfig()->isDemoShop() ) {
00416 $oSmarty->security = true;
00417 }
00418
00419 return true;
00420 }
00421
00431 function ox_get_timestamp( $sTplName, &$iTplTimestamp, $oSmarty )
00432 {
00433 if ( isset( $oSmarty->oxidtimecache->value ) ) {
00434
00435 $iTplTimestamp = $oSmarty->oxidtimecache->value;
00436 } else {
00437
00438 $iTplTimestamp = time();
00439 }
00440
00441 return true;
00442 }
00443
00452 function ox_get_secure( $sTplName, $oSmarty )
00453 {
00454
00455 return true;
00456 }
00457
00466 function ox_get_trusted( $sTplName, $oSmarty )
00467 {
00468
00469 }
00470
00471
00472 if ( !function_exists( 'getLangTableIdx' ) ) {
00473
00481 function getLangTableIdx( $iLangId )
00482 {
00483 $iLangPerTable = oxRegistry::getConfig()->getConfigParam( "iLangPerTable" );
00484
00485 $iLangPerTable = ( $iLangPerTable > 1 ) ? $iLangPerTable : 8;
00486
00487 $iTableIdx = (int) ( $iLangId / $iLangPerTable );
00488 return $iTableIdx;
00489 }
00490 }
00491
00492 if ( !function_exists( 'getLangTableName' ) ) {
00493
00502 function getLangTableName( $sTable, $iLangId )
00503 {
00504 $iTableIdx = getLangTableIdx( $iLangId );
00505 if ( $iTableIdx && in_array($sTable, oxRegistry::getLang()->getMultiLangTables())) {
00506 $sLangTableSuffix = oxRegistry::getConfig()->getConfigParam( "sLangTableSuffix" );
00507 $sLangTableSuffix = $sLangTableSuffix ? $sLangTableSuffix : "_set";
00508
00509 $sTable .= $sLangTableSuffix . $iTableIdx;
00510 }
00511
00512 return $sTable;
00513 }
00514 }
00515
00516 if ( !function_exists( 'getViewName' ) ) {
00517
00527 function getViewName( $sTable, $iLangId = null, $sShopId = null )
00528 {
00529 $myConfig = oxRegistry::getConfig();
00530 if ( !$myConfig->getConfigParam( 'blSkipViewUsage' ) ) {
00531 $sViewSfx = '';
00532
00533
00534 $blIsMultiLang = in_array( $sTable, oxRegistry::getLang()->getMultiLangTables() );
00535 if ( $iLangId != -1 && $blIsMultiLang ) {
00536 $oLang = oxRegistry::getLang();
00537 $iLangId = $iLangId !== null ? $iLangId : oxRegistry::getLang()->getBaseLanguage();
00538 $sAbbr = $oLang->getLanguageAbbr( $iLangId );
00539 $sViewSfx .= "_{$sAbbr}";
00540 }
00541
00542 if ( $sViewSfx || (($iLangId == -1 || $sShopId == -1 ) && $blIsMultiLang)) {
00543 return "oxv_{$sTable}{$sViewSfx}";
00544 }
00545
00546 }
00547
00548 return $sTable;
00549 }
00550 }
00551
00552 if ( !function_exists( 'getRequestUrl' ) ) {
00561 function getRequestUrl( $sParams = '', $blReturnUrl = false )
00562 {
00563 if ($_SERVER["REQUEST_METHOD"] != "POST" ) {
00564
00565 if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] ) {
00566 $sRequest = $_SERVER['REQUEST_URI'];
00567 } else {
00568
00569 $sRequest = $_SERVER['SCRIPT_URI'];
00570 }
00571
00572
00573 if ( $sRequest && ( $iPos = stripos( $sRequest, '?' ) ) !== false ) {
00574
00575 $oStr = getStr();
00576
00577 $sRequest = 'index.php' . $oStr->substr( $sRequest, $iPos );
00578
00579
00580 $sRequest = $oStr->preg_replace( '/(&|\?)(force_)?(admin_)?sid=[^&]*&?/', '$1', $sRequest );
00581 $sRequest = $oStr->preg_replace( '/(&|\?)stoken=[^&]*&?/', '$1', $sRequest );
00582 $sRequest = $oStr->preg_replace( '/&$/', '', $sRequest );
00583 return str_replace( '&', '&', $sRequest );
00584 }
00585 }
00586 }
00587 }
00588
00589
00590 spl_autoload_register("oxAutoload");