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 . 'admin/reports/',
00028                              $sBasePath . 'admin/',
00029                              $sBasePath . 'modules/',
00030                              $sBasePath
00031                             );
00032     }
00033 
00034     foreach ( $aClassDirs as $sDir ) {
00035         $sFilename = $sDir . strtolower( $sClass ) . '.php';
00036         if ( file_exists( $sFilename ) ) {
00037             require_once $sFilename;
00038             return;
00039         }
00040     }
00041 
00042     // in case module parent class (*_parent) is required
00043     $sClass = preg_replace( '/_parent$/i', '', $sClass );
00044 
00045     // special case
00046     if ( !in_array( $sClass, $aTriedClasses ) && is_array( $aModules = oxConfig::getInstance()->getConfigParam( 'aModules' ) ) ) {
00047 
00048         $myUtilsObject = oxUtilsObject::getInstance();
00049         foreach ( $aModules as $sParentName => $sModuleName ) {
00050             // looking for module parent class
00051             if ( stripos( $sModuleName, $sClass ) !== false ) {
00052                 $myUtilsObject->getClassName( $sParentName );
00053                 break;
00054             }
00055         }
00056         $aTriedClasses[] = $sClass;
00057     }
00058 }
00059 
00060 if ( !function_exists( 'error_404_handler' ) ) {
00068     function error_404_handler($sUrl = '')
00069     {
00070         header("HTTP/1.0 404 Not Found");
00071         echo "Page not found.";
00072         exit(0);
00073     }
00074 }
00075 
00087 function warningHandler($iErrorNr, $sErrorText)
00088 {
00089     echo "<div class='error_box'>".oxLang::getInstance()->translateString('userError')."<code>[$iErrorNr] $sErrorText</code></div>";
00090 }
00091 
00100 function dumpVar( $mVar, $blToFile = false )
00101 {
00102     $myConfig = oxConfig::getInstance();
00103     if ( $blToFile ) {
00104         $out = var_export( $mVar, true );
00105         $f = fopen( $myConfig->getConfigParam( 'sCompileDir' )."/vardump.txt", "a" );
00106         fwrite( $f, $out );
00107         fclose( $f );
00108     } else {
00109         echo '<pre>';
00110         print_r( $mVar );
00111         echo '</pre>';
00112     }
00113 }
00114 
00115 if ( !function_exists( 'isAdmin' ) ) {
00123     function isAdmin()
00124     {
00125         //additionally checking maybe oxConfig::blAdmin is already set
00126         if ( class_exists( 'oxConfig', false ) ) {
00127             $blAdmin = oxConfig::getInstance()->getConfigParam( 'blAdmin' );
00128             if ( isset( $blAdmin ) ) {
00129                 stopProfile('isAdmin');
00130                 return $blAdmin;
00131             }
00132         }
00133         return false;
00134     }
00135 }
00136 
00137 if ( !function_exists( 'isSearchEngineUrl' ) ) {
00138 
00144     function isSearchEngineUrl()
00145     {
00146         return false;
00147     }
00148 }
00149 
00157 function debug( $mVar )
00158 {
00159     $f = fopen( 'out.txt', 'a' );
00160     $sString = var_export( $mVar, true );
00161     fputs( $f, $sString."\n---------------------------------------------\n" );
00162     fclose( $f );
00163 }
00164 
00173 function cmpart( $a, $b )
00174 {
00175     // sorting for crossselling
00176     if ( $a->cnt == $b->cnt )
00177         return 0;
00178     return ( $a->cnt < $b->cnt ) ? -1 : 1;
00179 }
00180 
00188 function startProfile( $sProfileName )
00189 {
00190     global $aStartTimes;
00191     global $aExecutionCounts;
00192     if (!isset($aExecutionCounts[$sProfileName])) {
00193         $aExecutionCounts[$sProfileName] = 0;
00194     }
00195     if (!isset($aStartTimes[$sProfileName])) {
00196         $aStartTimes[$sProfileName] = 0;
00197     }
00198     $aExecutionCounts[$sProfileName]++;
00199     $aStartTimes[$sProfileName] = microtime(true);
00200 }
00201 
00209 function stopProfile( $sProfileName )
00210 {
00211     global $aProfileTimes;
00212     global $aStartTimes;
00213     if (!isset($aProfileTimes[$sProfileName])) {
00214         $aProfileTimes[$sProfileName] = 0;
00215     }
00216     $aProfileTimes[$sProfileName] += microtime( true ) - $aStartTimes[$sProfileName];
00217 }
00218 
00230 function oxNew( $sClassName, $sParams = null )
00231 {
00232     startProfile( 'oxNew' );
00233     $oRes = oxUtilsObject::getInstance()->oxNew( $sClassName, $sParams );
00234     stopProfile( 'oxNew' );
00235     return $oRes;
00236 }
00237 
00245 function oxNewArticle( $sArtId )
00246 {
00247     return oxUtilsObject::getInstance()->oxNewArticle( $sArtId );
00248 }
00249 
00257 function getDb($blAssoc = true)
00258 {
00259     return oxDb::getDb($blAssoc);
00260 }
00261 
00267 function getStr()
00268 {
00269     return oxStr::getStr();
00270 }
00271 
00281 function ox_get_template( $sTplName, &$sTplSource, $oSmarty )
00282 {
00283     $sTplSource = $oSmarty->oxidcache->value;
00284     if ( oxConfig::getInstance()->isDemoShop() ) {
00285         $oSmarty->security = true;
00286     }
00287 
00288     return true;
00289 }
00290 
00300 function ox_get_timestamp( $sTplName, &$iTplTimestamp, $oSmarty )
00301 {
00302     if ( isset( $oSmarty->oxidtimecache->value ) ) {
00303         // use stored timestamp
00304         $iTplTimestamp = $oSmarty->oxidtimecache->value;
00305     } else {
00306         // always compile
00307         $iTplTimestamp = time();
00308     }
00309 
00310     return true;
00311 }
00312 
00321 function ox_get_secure( $sTplName, $oSmarty )
00322 {
00323     // assume all templates are secure
00324     return true;
00325 }
00326 
00335 function ox_get_trusted( $sTplName, $oSmarty )
00336 {
00337     // not used for templates
00338 }
00339 
00340 if ( !function_exists( 'getViewName' ) ) {
00341 
00350     function getViewName( $sTable, $sShopId = null )
00351     {
00352 
00353         return $sTable;
00354     }
00355 }
00356 
00357 if ( !function_exists( 'getRequestUrl' ) ) {
00366     function getRequestUrl( $sParams = '', $blReturnUrl = false )
00367     {
00368         if ($_SERVER["REQUEST_METHOD"] != "POST" ) {
00369 
00370             if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] ) {
00371                 $sRequest = $_SERVER['REQUEST_URI'];
00372             } else {    // try something else
00373                 $sRequest = $_SERVER['SCRIPT_URI'];
00374             }
00375 
00376             // trying to resolve controller file name
00377             if ( $sRequest && ( $iPos = stripos( $sRequest, '?' ) ) !== false ) {
00378 
00379                 // formatting request url
00380                 $sRequest = 'index.php' . getStr()->substr( $sRequest, $iPos );
00381 
00382                 // removing possible session id
00383                 $sRequest = preg_replace( '/((\&)?sid=[^&]*(&)?)/', '', $sRequest );
00384                 return str_replace( '&', '&amp;', $sRequest );
00385             }
00386         }
00387     }
00388 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5