oxfunctions.php

Go to the documentation of this file.
00001 <?php
00002 
00010 function __autoload( $sClass )
00011 {
00012 
00013     $sClass = basename( $sClass );
00014 
00015     static $sBasePath  = null;
00016     static $aClassDirs = null;
00017 
00018     // preventing infinite loop
00019     static $aTriedClasses = array();
00020 
00021     // initializing paths
00022     if ( $aClassDirs == null ) {
00023         $sBasePath = getShopBasePath();
00024         $aClassDirs = array( $sBasePath . 'core/',
00025                              $sBasePath . 'views/',
00026                              $sBasePath . 'core/exception/',
00027                              $sBasePath . 'core/interface/',
00028                              $sBasePath . 'admin/reports/',
00029                              $sBasePath . 'admin/',
00030                              $sBasePath . 'modules/',
00031                              $sBasePath
00032                             );
00033     }
00034 
00035     foreach ( $aClassDirs as $sDir ) {
00036         $sFilename = $sDir . strtolower( $sClass ) . '.php';
00037         if ( file_exists( $sFilename ) ) {
00038             require_once $sFilename;
00039             return;
00040         }
00041     }
00042 
00043     // in case module parent class (*_parent) is required
00044     $sClass = preg_replace( '/_parent$/i', '', $sClass );
00045 
00046     // special case
00047     if ( !in_array( $sClass, $aTriedClasses ) && is_array( $aModules = oxConfig::getInstance()->getConfigParam( 'aModules' ) ) ) {
00048 
00049         $myUtilsObject = oxUtilsObject::getInstance();
00050         foreach ( $aModules as $sParentName => $sModuleName ) {
00051             // looking for module parent class
00052             if ( stripos( $sModuleName, $sClass ) !== false ) {
00053                 $myUtilsObject->getClassName( $sParentName );
00054                 break;
00055             }
00056         }
00057         $aTriedClasses[] = $sClass;
00058     }
00059 }
00060 
00061 if ( !function_exists( 'error_404_handler' ) ) {
00069     function error_404_handler($sUrl = '')
00070     {
00071         $oUtils = oxUtils::getInstance();
00072         $oUtils->setHeader("HTTP/1.0 404 Not Found");
00073         $sReturn = "Page not found.";
00074         try {
00075             $oView = oxNew('oxubase');
00076             $oView->init();
00077             $oView->render();
00078             $oView->addTplParam('sUrl', $sUrl);
00079             if ($sRet = oxUtilsView::getInstance()->getTemplateOutput('err_404.tpl', $oView)) {
00080                 $sReturn = $sRet;
00081             }
00082         } catch (Exception $e) {
00083         }
00084         $oUtils->showMessageAndExit( $sReturn );
00085     }
00086 }
00087 
00099 function warningHandler($iErrorNr, $sErrorText)
00100 {
00101     echo "<div class='error_box'>".oxLang::getInstance()->translateString('userError')."<code>[$iErrorNr] $sErrorText</code></div>";
00102 }
00103 
00112 function dumpVar( $mVar, $blToFile = false )
00113 {
00114     $myConfig = oxConfig::getInstance();
00115     if ( $blToFile ) {
00116         $out = var_export( $mVar, true );
00117         $f = fopen( $myConfig->getConfigParam( 'sCompileDir' )."/vardump.txt", "a" );
00118         fwrite( $f, $out );
00119         fclose( $f );
00120     } else {
00121         echo '<pre>';
00122         print_r( $mVar );
00123         echo '</pre>';
00124     }
00125 }
00126 
00127 if ( !function_exists( 'isAdmin' ) ) {
00135     function isAdmin()
00136     {
00137         //additionally checking maybe oxConfig::blAdmin is already set
00138         if ( class_exists( 'oxConfig', false ) ) {
00139             $blAdmin = oxConfig::getInstance()->getConfigParam( 'blAdmin' );
00140             if ( isset( $blAdmin ) ) {
00141                 stopProfile('isAdmin');
00142                 return $blAdmin;
00143             }
00144         }
00145         return false;
00146     }
00147 }
00148 
00149 if ( !function_exists( 'isSearchEngineUrl' ) ) {
00150 
00156     function isSearchEngineUrl()
00157     {
00158         return false;
00159     }
00160 }
00161 
00169 function debug( $mVar )
00170 {
00171     $f = fopen( 'out.txt', 'a' );
00172     $sString = var_export( $mVar, true );
00173     fputs( $f, $sString."\n---------------------------------------------\n" );
00174     fclose( $f );
00175 }
00176 
00185 function cmpart( $a, $b )
00186 {
00187     // sorting for crossselling
00188     if ( $a->cnt == $b->cnt )
00189         return 0;
00190     return ( $a->cnt < $b->cnt ) ? -1 : 1;
00191 }
00192 
00200 function startProfile( $sProfileName )
00201 {
00202     global $aStartTimes;
00203     global $aExecutionCounts;
00204     if (!isset($aExecutionCounts[$sProfileName])) {
00205         $aExecutionCounts[$sProfileName] = 0;
00206     }
00207     if (!isset($aStartTimes[$sProfileName])) {
00208         $aStartTimes[$sProfileName] = 0;
00209     }
00210     $aExecutionCounts[$sProfileName]++;
00211     $aStartTimes[$sProfileName] = microtime(true);
00212 }
00213 
00221 function stopProfile( $sProfileName )
00222 {
00223     global $aProfileTimes;
00224     global $aStartTimes;
00225     if (!isset($aProfileTimes[$sProfileName])) {
00226         $aProfileTimes[$sProfileName] = 0;
00227     }
00228     $aProfileTimes[$sProfileName] += microtime( true ) - $aStartTimes[$sProfileName];
00229 }
00230 
00242 function oxNew( $sClassName, $sParams = null )
00243 {
00244     startProfile( 'oxNew' );
00245     $oRes = oxUtilsObject::getInstance()->oxNew( $sClassName, $sParams );
00246     stopProfile( 'oxNew' );
00247     return $oRes;
00248 }
00249 
00257 function oxNewArticle( $sArtId )
00258 {
00259     return oxUtilsObject::getInstance()->oxNewArticle( $sArtId );
00260 }
00261 
00269 function getDb($blAssoc = true)
00270 {
00271     return oxDb::getDb($blAssoc);
00272 }
00273 
00279 function getStr()
00280 {
00281     return oxStr::getStr();
00282 }
00283 
00293 function ox_get_template( $sTplName, &$sTplSource, $oSmarty )
00294 {
00295     $sTplSource = $oSmarty->oxidcache->value;
00296     if ( oxConfig::getInstance()->isDemoShop() ) {
00297         $oSmarty->security = true;
00298     }
00299 
00300     return true;
00301 }
00302 
00312 function ox_get_timestamp( $sTplName, &$iTplTimestamp, $oSmarty )
00313 {
00314     if ( isset( $oSmarty->oxidtimecache->value ) ) {
00315         // use stored timestamp
00316         $iTplTimestamp = $oSmarty->oxidtimecache->value;
00317     } else {
00318         // always compile
00319         $iTplTimestamp = time();
00320     }
00321 
00322     return true;
00323 }
00324 
00333 function ox_get_secure( $sTplName, $oSmarty )
00334 {
00335     // assume all templates are secure
00336     return true;
00337 }
00338 
00347 function ox_get_trusted( $sTplName, $oSmarty )
00348 {
00349     // not used for templates
00350 }
00351 
00352 if ( !function_exists( 'getViewName' ) ) {
00353 
00362     function getViewName( $sTable, $sShopId = null )
00363     {
00364 
00365         return $sTable;
00366     }
00367 }
00368 
00369 if ( !function_exists( 'getRequestUrl' ) ) {
00378     function getRequestUrl( $sParams = '', $blReturnUrl = false )
00379     {
00380         if ($_SERVER["REQUEST_METHOD"] != "POST" ) {
00381 
00382             if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] ) {
00383                 $sRequest = $_SERVER['REQUEST_URI'];
00384             } else {    // try something else
00385                 $sRequest = $_SERVER['SCRIPT_URI'];
00386             }
00387 
00388             // trying to resolve controller file name
00389             if ( $sRequest && ( $iPos = stripos( $sRequest, '?' ) ) !== false ) {
00390 
00391                 // formatting request url
00392                 $sRequest = 'index.php' . getStr()->substr( $sRequest, $iPos );
00393 
00394                 // removing possible session id
00395                 $sRequest = preg_replace( '/(&|\?){1}sid=[^&]*&?/', '$1', $sRequest );
00396                 $sRequest = preg_replace( '/&$/', '', $sRequest );
00397                 return str_replace( '&', '&amp;', $sRequest );
00398             }
00399         }
00400     }
00401 }
00402 
00403 //strips magics quote if any
00404 oxUtils::getInstance()->stripGpcMagicQuotes();

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5