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
00374 function oxNewArticle( $sArtId )
00375 {
00376 return oxUtilsObject::getInstance()->oxNewArticle( $sArtId );
00377 }
00378
00386 function getDb($blAssoc = true)
00387 {
00388 return oxDb::getDb($blAssoc);
00389 }
00390
00396 function getStr()
00397 {
00398 return oxStr::getStr();
00399 }
00400
00410 function ox_get_template( $sTplName, &$sTplSource, $oSmarty )
00411 {
00412 $sTplSource = $oSmarty->oxidcache->value;
00413 if ( oxRegistry::getConfig()->isDemoShop() ) {
00414 $oSmarty->security = true;
00415 }
00416
00417 return true;
00418 }
00419
00429 function ox_get_timestamp( $sTplName, &$iTplTimestamp, $oSmarty )
00430 {
00431 if ( isset( $oSmarty->oxidtimecache->value ) ) {
00432
00433 $iTplTimestamp = $oSmarty->oxidtimecache->value;
00434 } else {
00435
00436 $iTplTimestamp = time();
00437 }
00438
00439 return true;
00440 }
00441
00450 function ox_get_secure( $sTplName, $oSmarty )
00451 {
00452
00453 return true;
00454 }
00455
00464 function ox_get_trusted( $sTplName, $oSmarty )
00465 {
00466
00467 }
00468
00469
00470 if ( !function_exists( 'getLangTableIdx' ) ) {
00471
00479 function getLangTableIdx( $iLangId )
00480 {
00481 $iLangPerTable = oxRegistry::getConfig()->getConfigParam( "iLangPerTable" );
00482
00483 $iLangPerTable = ( $iLangPerTable > 1 ) ? $iLangPerTable : 8;
00484
00485 $iTableIdx = (int) ( $iLangId / $iLangPerTable );
00486 return $iTableIdx;
00487 }
00488 }
00489
00490 if ( !function_exists( 'getLangTableName' ) ) {
00491
00500 function getLangTableName( $sTable, $iLangId )
00501 {
00502 $iTableIdx = getLangTableIdx( $iLangId );
00503 if ( $iTableIdx && in_array($sTable, oxRegistry::getLang()->getMultiLangTables())) {
00504 $sLangTableSuffix = oxRegistry::getConfig()->getConfigParam( "sLangTableSuffix" );
00505 $sLangTableSuffix = $sLangTableSuffix ? $sLangTableSuffix : "_set";
00506
00507 $sTable .= $sLangTableSuffix . $iTableIdx;
00508 }
00509
00510 return $sTable;
00511 }
00512 }
00513
00514 if ( !function_exists( 'getViewName' ) ) {
00515
00525 function getViewName( $sTable, $iLangId = null, $sShopId = null )
00526 {
00527 $myConfig = oxRegistry::getConfig();
00528 if ( !$myConfig->getConfigParam( 'blSkipViewUsage' ) ) {
00529 $sViewSfx = '';
00530
00531
00532 $blIsMultiLang = in_array( $sTable, oxRegistry::getLang()->getMultiLangTables() );
00533 if ( $iLangId != -1 && $blIsMultiLang ) {
00534 $oLang = oxRegistry::getLang();
00535 $iLangId = $iLangId !== null ? $iLangId : oxRegistry::getLang()->getBaseLanguage();
00536 $sAbbr = $oLang->getLanguageAbbr( $iLangId );
00537 $sViewSfx .= "_{$sAbbr}";
00538 }
00539
00540 if ( $sViewSfx || (($iLangId == -1 || $sShopId == -1 ) && $blIsMultiLang)) {
00541 return "oxv_{$sTable}{$sViewSfx}";
00542 }
00543
00544 }
00545
00546 return $sTable;
00547 }
00548 }
00549
00550 if ( !function_exists( 'getRequestUrl' ) ) {
00559 function getRequestUrl( $sParams = '', $blReturnUrl = false )
00560 {
00561 if ($_SERVER["REQUEST_METHOD"] != "POST" ) {
00562
00563 if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] ) {
00564 $sRequest = $_SERVER['REQUEST_URI'];
00565 } else {
00566
00567 $sRequest = $_SERVER['SCRIPT_URI'];
00568 }
00569
00570
00571 if ( $sRequest && ( $iPos = stripos( $sRequest, '?' ) ) !== false ) {
00572
00573 $oStr = getStr();
00574
00575 $sRequest = 'index.php' . $oStr->substr( $sRequest, $iPos );
00576
00577
00578 $sRequest = $oStr->preg_replace( '/(&|\?)(force_)?(admin_)?sid=[^&]*&?/', '$1', $sRequest );
00579 $sRequest = $oStr->preg_replace( '/(&|\?)stoken=[^&]*&?/', '$1', $sRequest );
00580 $sRequest = $oStr->preg_replace( '/&$/', '', $sRequest );
00581 return str_replace( '&', '&', $sRequest );
00582 }
00583 }
00584 }
00585 }
00586
00587
00588 spl_autoload_register("oxAutoload");