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 . 'core/jpgraph/',
00132 $sBasePath . 'admin/reports/',
00133 $sBasePath . 'admin/',
00134 $sBasePath . 'modules/',
00135 $sBasePath
00136 );
00137 return $aClassDirs;
00138 }
00139
00140
00141 if ( !function_exists( 'getShopBasePath' ) ) {
00147 function getShopBasePath()
00148 {
00149 return OX_BASE_PATH;
00150 }
00151 }
00152
00158 function isAdmin()
00159 {
00160 if (defined('OX_IS_ADMIN')) {
00161 return OX_IS_ADMIN;
00162 }
00163
00164 return false;
00165 }
00166
00172 function setPhpIniParams()
00173 {
00174
00175 ini_set('session.name', 'sid');
00176 ini_set('session.use_cookies', 0);
00177 ini_set('session.use_trans_sid', 0);
00178 ini_set('url_rewriter.tags', '');
00179 ini_set('magic_quotes_runtime', 0);
00180 }
00181
00187 function stripGpcMagicQuotes()
00188 {
00189 if (!get_magic_quotes_gpc()) {
00190 return;
00191 }
00192 $_REQUEST = _stripMagicQuotes($_REQUEST);
00193 $_POST = _stripMagicQuotes($_POST);
00194 $_GET = _stripMagicQuotes($_GET);
00195 $_COOKIE = _stripMagicQuotes($_COOKIE);
00196 }
00197
00205 function _stripMagicQuotes($mInput)
00206 {
00207 return is_array($mInput) ? array_map( '_stripMagicQuotes', $mInput ) : stripslashes( $mInput );
00208 }
00209
00210 if ( !function_exists( 'error_404_handler' ) ) {
00218 function error_404_handler($sUrl = '')
00219 {
00220 oxRegistry::getUtils()->handlePageNotFoundError($sUrl);
00221 }
00222 }
00223
00235 function warningHandler($iErrorNr, $sErrorText)
00236 {
00237 echo "<div class='error_box'>".oxRegistry::getLang()->translateString('userError')."<code>[$iErrorNr] $sErrorText</code></div>";
00238 }
00239
00248 function dumpVar( $mVar, $blToFile = false )
00249 {
00250 $myConfig = oxRegistry::getConfig();
00251 if ( $blToFile ) {
00252 $out = var_export( $mVar, true );
00253 $f = fopen( $myConfig->getConfigParam( 'sCompileDir' )."/vardump.txt", "a" );
00254 fwrite( $f, $out );
00255 fclose( $f );
00256 } else {
00257 echo '<pre>';
00258 var_export( $mVar );
00259 echo '</pre>';
00260 }
00261 }
00262
00263 if ( !function_exists( 'isSearchEngineUrl' ) ) {
00264
00270 function isSearchEngineUrl()
00271 {
00272 return false;
00273 }
00274 }
00275
00283 function debug( $mVar )
00284 {
00285 $f = fopen( 'out.txt', 'a' );
00286 $sString = var_export( $mVar, true );
00287 fputs( $f, $sString."\n---------------------------------------------\n" );
00288 fclose( $f );
00289 }
00290
00299 function cmpart( $a, $b )
00300 {
00301
00302 if ( $a->cnt == $b->cnt )
00303 return 0;
00304 return ( $a->cnt < $b->cnt ) ? -1 : 1;
00305 }
00306
00307 if ( !function_exists( 'startProfile' ) ) {
00315 function startProfile( $sProfileName )
00316 {
00317 global $aStartTimes;
00318 global $aExecutionCounts;
00319 if (!isset($aExecutionCounts[$sProfileName])) {
00320 $aExecutionCounts[$sProfileName] = 0;
00321 }
00322 if (!isset($aStartTimes[$sProfileName])) {
00323 $aStartTimes[$sProfileName] = 0;
00324 }
00325 $aExecutionCounts[$sProfileName]++;
00326 $aStartTimes[$sProfileName] = microtime(true);
00327 }
00328 }
00329
00330 if ( !function_exists( 'stopProfile' ) ) {
00338 function stopProfile( $sProfileName )
00339 {
00340 global $aProfileTimes;
00341 global $aStartTimes;
00342 if (!isset($aProfileTimes[$sProfileName])) {
00343 $aProfileTimes[$sProfileName] = 0;
00344 }
00345 $aProfileTimes[$sProfileName] += microtime( true ) - $aStartTimes[$sProfileName];
00346 }
00347 }
00348
00359 function oxNew( $sClassName )
00360 {
00361 startProfile( 'oxNew' );
00362 $aArgs = func_get_args();
00363 $oRes = call_user_func_array( array( oxUtilsObject::getInstance(), "oxNew" ), $aArgs );
00364 stopProfile( 'oxNew' );
00365 return $oRes;
00366 }
00367
00375 function oxNewArticle( $sArtId )
00376 {
00377 return oxUtilsObject::getInstance()->oxNewArticle( $sArtId );
00378 }
00379
00387 function getDb($blAssoc = true)
00388 {
00389 return oxDb::getDb($blAssoc);
00390 }
00391
00397 function getStr()
00398 {
00399 return oxStr::getStr();
00400 }
00401
00411 function ox_get_template( $sTplName, &$sTplSource, $oSmarty )
00412 {
00413 $sTplSource = $oSmarty->oxidcache->value;
00414 if ( oxRegistry::getConfig()->isDemoShop() ) {
00415 $oSmarty->security = true;
00416 }
00417
00418 return true;
00419 }
00420
00430 function ox_get_timestamp( $sTplName, &$iTplTimestamp, $oSmarty )
00431 {
00432 if ( isset( $oSmarty->oxidtimecache->value ) ) {
00433
00434 $iTplTimestamp = $oSmarty->oxidtimecache->value;
00435 } else {
00436
00437 $iTplTimestamp = time();
00438 }
00439
00440 return true;
00441 }
00442
00451 function ox_get_secure( $sTplName, $oSmarty )
00452 {
00453
00454 return true;
00455 }
00456
00465 function ox_get_trusted( $sTplName, $oSmarty )
00466 {
00467
00468 }
00469
00470
00471 if ( !function_exists( 'getLangTableIdx' ) ) {
00472
00480 function getLangTableIdx( $iLangId )
00481 {
00482 $iLangPerTable = oxRegistry::getConfig()->getConfigParam( "iLangPerTable" );
00483
00484 $iLangPerTable = ( $iLangPerTable > 1 ) ? $iLangPerTable : 8;
00485
00486 $iTableIdx = (int) ( $iLangId / $iLangPerTable );
00487 return $iTableIdx;
00488 }
00489 }
00490
00491 if ( !function_exists( 'getLangTableName' ) ) {
00492
00501 function getLangTableName( $sTable, $iLangId )
00502 {
00503 $iTableIdx = getLangTableIdx( $iLangId );
00504 if ( $iTableIdx && in_array($sTable, oxRegistry::getLang()->getMultiLangTables())) {
00505 $sLangTableSuffix = oxRegistry::getConfig()->getConfigParam( "sLangTableSuffix" );
00506 $sLangTableSuffix = $sLangTableSuffix ? $sLangTableSuffix : "_set";
00507
00508 $sTable .= $sLangTableSuffix . $iTableIdx;
00509 }
00510
00511 return $sTable;
00512 }
00513 }
00514
00515 if ( !function_exists( 'getViewName' ) ) {
00516
00526 function getViewName( $sTable, $iLangId = null, $sShopId = null )
00527 {
00528 $myConfig = oxRegistry::getConfig();
00529 if ( !$myConfig->getConfigParam( 'blSkipViewUsage' ) ) {
00530 $sViewSfx = '';
00531
00532
00533 $blIsMultiLang = in_array( $sTable, oxRegistry::getLang()->getMultiLangTables() );
00534 if ( $iLangId != -1 && $blIsMultiLang ) {
00535 $oLang = oxRegistry::getLang();
00536 $iLangId = $iLangId !== null ? $iLangId : oxRegistry::getLang()->getBaseLanguage();
00537 $sAbbr = $oLang->getLanguageAbbr( $iLangId );
00538 $sViewSfx .= "_{$sAbbr}";
00539 }
00540
00541 if ( $sViewSfx || (($iLangId == -1 || $sShopId == -1 ) && $blIsMultiLang)) {
00542 return "oxv_{$sTable}{$sViewSfx}";
00543 }
00544
00545 }
00546
00547 return $sTable;
00548 }
00549 }
00550
00551 if ( !function_exists( 'getRequestUrl' ) ) {
00560 function getRequestUrl( $sParams = '', $blReturnUrl = false )
00561 {
00562 if ($_SERVER["REQUEST_METHOD"] != "POST" ) {
00563
00564 if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] ) {
00565 $sRequest = $_SERVER['REQUEST_URI'];
00566 } else {
00567
00568 $sRequest = $_SERVER['SCRIPT_URI'];
00569 }
00570
00571
00572 if ( $sRequest && ( $iPos = stripos( $sRequest, '?' ) ) !== false ) {
00573
00574 $oStr = getStr();
00575
00576 $sRequest = 'index.php' . $oStr->substr( $sRequest, $iPos );
00577
00578
00579 $sRequest = $oStr->preg_replace( '/(&|\?)(force_)?(admin_)?sid=[^&]*&?/', '$1', $sRequest );
00580 $sRequest = $oStr->preg_replace( '/(&|\?)stoken=[^&]*&?/', '$1', $sRequest );
00581 $sRequest = $oStr->preg_replace( '/&$/', '', $sRequest );
00582 return str_replace( '&', '&', $sRequest );
00583 }
00584 }
00585 }
00586 }
00587
00588
00589 spl_autoload_register("oxAutoload");