oxfunctions.php

Go to the documentation of this file.
00001 <?php
00002 
00010 function __autoload( $sClass )
00011 {
00012     $sClass = basename( $sClass );
00013 
00014     static $sBasePath  = null;
00015     static $aClassDirs = null;
00016 
00017     // preventing infinite loop
00018     static $aTriedClasses = array();
00019 
00020     // initializing paths
00021     if ( $aClassDirs == null ) {
00022         $sBasePath = getShopBasePath();
00023         $aClassDirs = array( $sBasePath . 'core/',
00024                              $sBasePath . 'views/',
00025                              $sBasePath . 'core/exception/',
00026                              $sBasePath . 'admin/reports/',
00027                              $sBasePath . 'admin/',
00028                              $sBasePath . 'modules/',
00029                              $sBasePath
00030                             );
00031     }
00032 
00033     foreach ( $aClassDirs as $sDir ) {
00034         $sFilename = $sDir . strtolower( $sClass ) . '.php';
00035         if ( file_exists( $sFilename ) ) {
00036             require_once $sFilename;
00037             return;
00038         }
00039     }
00040 
00041     // in case module parent class (*_parent) is required
00042     $sClass = preg_replace( '/_parent$/i', '', $sClass );
00043 
00044     // special case
00045     if ( !in_array( $sClass, $aTriedClasses ) && is_array( $aModules = oxConfig::getInstance()->getConfigParam( 'aModules' ) ) ) {
00046 
00047         foreach ( $aModules as $sParentName => $sModuleName ) {
00048             // looking for module parent class
00049             if ( stripos( $sModuleName, $sClass ) !== false ) {
00050                 oxUtilsObject::getInstance()->getClassName( $sParentName );
00051                 break;
00052             }
00053         }
00054         $aTriedClasses[] = $sClass;
00055     }
00056 }
00057 
00058 if ( !function_exists( 'error_404_handler' ) ) {
00066     function error_404_handler($sUrl = '') 
00067     {
00068         header("HTTP/1.0 404 Not Found");
00069         echo "Page not found.";
00070         exit(0);
00071     }
00072 }
00073 
00085 function warningHandler($iErrorNr, $sErrorText)
00086 {
00087     echo "<div class='error_box'>".oxLang::getInstance()->translateString('userError')."<code>[$iErrorNr] $sErrorText</code></div>";
00088 }
00089 
00098 function dumpVar( $mVar, $blToFile = false )
00099 {
00100     $myConfig = oxConfig::getInstance();
00101     if ( $blToFile ) {
00102         $out = var_export( $mVar, true );
00103         $f = fopen( $myConfig->getConfigParam( 'sCompileDir' )."/vardump.txt", "a" );
00104         fwrite( $f, $out );
00105         fclose( $f );
00106     } else {
00107         echo '<pre>';
00108         print_r( $mVar );
00109         echo '</pre>';
00110     }
00111 }
00112 
00113 if ( !function_exists( 'isAdmin' ) ) {
00121     function isAdmin()
00122     {
00123         //additionally checking maybe oxConfig::blAdmin is already set
00124         if ( class_exists( 'oxConfig', false ) ) {
00125             $blAdmin = oxConfig::getInstance()->getConfigParam( 'blAdmin' );
00126             if ( isset( $blAdmin ) ) {
00127                 stopProfile('isAdmin');
00128                 return $blAdmin;
00129             }
00130         }
00131         return false;
00132     }
00133 }
00134 
00135 if ( !function_exists( 'isSearchEngineUrl' ) ) {
00136 
00142     function isSearchEngineUrl()
00143     {
00144         return false;
00145     }
00146 }
00147 
00155 function debug( $mVar )
00156 {
00157     $f = fopen( 'out.txt', 'a' );
00158     $sString = var_export( $mVar, true );
00159     fputs( $f, $sString."\n---------------------------------------------\n" );
00160     fclose( $f );
00161 }
00162 
00171 function cmpart( $a, $b )
00172 {
00173     // sorting for crossselling
00174     if ( $a->cnt == $b->cnt )
00175         return 0;
00176     return ( $a->cnt < $b->cnt ) ? -1 : 1;
00177 }
00178 
00186 function startProfile( $sProfileName )
00187 {
00188     global $aStartTimes;
00189     global $aExecutionCounts;
00190     if (!isset($aExecutionCounts[$sProfileName])) {
00191         $aExecutionCounts[$sProfileName] = 0;
00192     }
00193     if (!isset($aStartTimes[$sProfileName])) {
00194         $aStartTimes[$sProfileName] = 0;
00195     }
00196     $aExecutionCounts[$sProfileName]++;
00197     $aStartTimes[$sProfileName] = microtime(true);
00198 }
00199 
00207 function stopProfile( $sProfileName )
00208 {
00209     global $aProfileTimes;
00210     global $aStartTimes;
00211     if (!isset($aProfileTimes[$sProfileName])) {
00212         $aProfileTimes[$sProfileName] = 0;
00213     }
00214     $aProfileTimes[$sProfileName] += microtime( true ) - $aStartTimes[$sProfileName];
00215 }
00216 
00228 function oxNew( $sClassName, $sParams = null )
00229 {
00230     startProfile( 'oxNew' );
00231     $oRes = oxUtilsObject::getInstance()->oxNew( $sClassName, $sParams );
00232     stopProfile( 'oxNew' );
00233     return $oRes;
00234 }
00235 
00243 function oxNewArticle( $sArtId )
00244 {
00245     return oxUtilsObject::getInstance()->oxNewArticle( $sArtId );
00246 }
00247 
00257 function ox_get_template( $sTplName, &$sTplSource, $oSmarty )
00258 {
00259     $sTplSource = $oSmarty->oxidcache->value;
00260     if ( oxConfig::getInstance()->isDemoShop() ) {
00261         $oSmarty->security = true;
00262     }
00263 
00264     return true;
00265 }
00266 
00276 function ox_get_timestamp( $sTplName, &$iTplTimestamp, $oSmarty )
00277 {
00278     if ( isset( $oSmarty->oxidtimecache->value ) ) {
00279         // use stored timestamp
00280         $iTplTimestamp = $oSmarty->oxidtimecache->value;
00281     } else {
00282         // always compile
00283         $iTplTimestamp = time();
00284     }
00285 
00286     return true;
00287 }
00288 
00297 function ox_get_secure( $sTplName, $oSmarty )
00298 {
00299     // assume all templates are secure
00300     return true;
00301 }
00302 
00311 function ox_get_trusted( $sTplName, $oSmarty )
00312 {
00313     // not used for templates
00314 }
00315 
00329 function smarty_modifier_oxtruncate( $sString, $iLength = 80, $sEtc = '...', $blBreakWords = false)
00330 {
00331     if ( $iLength == 0 ) {
00332         $sString = '';
00333     } elseif ( $iLength > 0 && strlen( $sString ) > $iLength ) {
00334 
00335         $iLength -= strlen( $sEtc );
00336 
00337         $sString = str_replace( array('&#039;', '&quot;'), array( "'",'"' ), $sString );
00338 
00339         if ( !$blBreakWords ) {
00340             $sString = preg_replace( '/\s+?(\S+)?$/', '', substr( $sString, 0, $iLength + 1 ) );
00341         }
00342 
00343         $sString = substr( $sString, 0, $iLength ).$sEtc;
00344 
00345         return str_replace( array( "'",'"' ), array('&#039;', '&quot;'), $sString );
00346     }
00347 
00348     return $sString;
00349 }
00350 
00351 if ( !function_exists( 'getViewName' ) ) {
00352 
00361     function getViewName( $sTable, $sShopId = null )
00362     {
00363 
00364         return $sTable;
00365     }
00366 }
00367 
00368 if ( !function_exists( 'getRequestUrl' ) ) {
00377     function getRequestUrl( $sParams = '', $blReturnUrl = false )
00378     {
00379         if ($_SERVER["REQUEST_METHOD"] != "POST" ) {
00380 
00381             if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] ) {
00382                 $sRequest = $_SERVER['REQUEST_URI'];
00383             } else {    // try something else
00384                 $sRequest = $_SERVER['SCRIPT_URI'];
00385             }
00386 
00387             // trying to resolve controller file name
00388             if ( $sRequest && ( $iPos = stripos( $sRequest, '?' ) ) !== false ) {
00389 
00390                 // formatting request url
00391                 $sRequest = 'index.php' . substr( $sRequest, $iPos );
00392 
00393                 // removing possible session id
00394                 $sRequest = preg_replace( '/((\&)?sid=[^&]*(&)?)/', '', $sRequest );
00395                 return str_replace( '&', '&amp;', $sRequest );
00396             }
00397         }
00398     }
00399 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5