00001 <?php
00002
00008 class oxShopControl extends oxSuperCfg
00009 {
00020 public function start()
00021 {
00022 $myConfig = $this->getConfig();
00023
00024
00025 $this->_runOnce();
00026
00027 $sClass = oxConfig::getParameter( 'cl' );
00028 $sFunction = oxConfig::getParameter( 'fnc' );
00029
00030 if ( !$sClass ) {
00031
00032 if ( !$this->isAdmin() ) {
00033
00034
00035
00036 if ( $myConfig->isMall() ) {
00037
00038 $iShopCount = oxDb::getDb()->getOne( 'select count(*) from oxshops where oxactive = 1' );
00039
00040 $sMallShopURL = $myConfig->getConfigParam( 'sMallShopURL' );
00041 if ( $iShopCount && $iShopCount > 1 && $myConfig->getConfigParam( 'iMallMode' ) != 0 && !$sMallShopURL ) {
00042
00043 $sClass = 'mallstart';
00044 }
00045 }
00046
00047 if ( !$sClass ) {
00048 $sClass = 'start';
00049 }
00050 } else {
00051 $sClass = 'login';
00052 }
00053
00054 oxSession::setVar( 'cl', $sClass );
00055 }
00056
00057
00058 if ( !oxSession::getVar( 'actshop' ) ) {
00059 oxSession::setVar( 'actshop', $myConfig->getShopId() );
00060 }
00061
00062 try {
00063 $this->_process( $sClass, $sFunction );
00064 } catch( oxSystemComponentException $oEx ) {
00065
00066 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00067 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=start' );
00068 } catch ( oxCookieException $oEx ) {
00069
00070 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00071 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=start' );
00072 }
00073 }
00074
00084 protected function _log( $sClass, $sFnc )
00085 {
00086 $oDb = oxDb::getDb();
00087 $sShopID = oxSession::getVar( 'actshop' );
00088 $sTime = date( 'Y-m-d H:i:s' );
00089 $sSidQuoted = $oDb->quote( $this->getSession()->getId() );
00090 $sUserIDQuoted = $oDb->quote( oxSession::getVar( 'usr' ) );
00091 $sCnid = oxConfig::getParameter( 'cnid' );
00092 $sAnid = oxConfig::getParameter( 'aid' )?oxConfig::getParameter( 'aid' ):oxConfig::getParameter( 'anid' );
00093 $sParameter = '';
00094
00095 if ( $sClass == 'info' ) {
00096 $sParameter = str_replace( '.tpl', '', oxConfig::getParameter('tpl') );
00097 } elseif ( $sClass == 'search' ) {
00098 $sParameter = oxConfig::getParameter( 'searchparam' );
00099 }
00100
00101 $sFncQuoted = $oDb->quote( $sFnc );
00102 $sClassQuoted = $oDb->quote( $sClass );
00103 $sParameterQuoted = $oDb->quote( $sParameter );
00104
00105 $oDb->execute( "insert into oxlogs (oxtime, oxshopid, oxuserid, oxsessid, oxclass, oxfnc, oxcnid, oxanid, oxparameter)
00106 values( '$sTime', '$sShopID', $sUserIDQuoted, $sSidQuoted, $sClassQuoted, $sFncQuoted, '$sCnid', '$sAnid', $sParameterQuoted )" );
00107 }
00108
00109
00115 protected function _startMonitor()
00116 {
00117 if ( !$this->isAdmin() && $this->getConfig()->getConfigParam( 'iDebug' ) ) {
00118 list ( $sUsec, $sSec ) = explode( ' ', microtime() );
00119 $this->dTimeStart = ( ( float ) $sUsec + ( float ) $sSec );
00120 }
00121 }
00122
00133 protected function _stopMonitor( $blIsCache = false, $blIsCached = false, $sViewID = null, $aViewData = array() )
00134 {
00135 $myConfig = $this->getConfig();
00136 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'iDebug' ) != 0 ) {
00137 echo '<div align="left">';
00138
00139
00140 if ( $myConfig->getConfigParam( 'iDebug' ) == 4 ) {
00141
00142 reset( $aViewData );
00143 while ( list( $sViewName, $oViewData ) =each( $aViewData ) ) {
00144
00145 echo( "TemplateData[$sViewName] : <br />\n");
00146 print_r( $oViewData );
00147 }
00148 }
00149
00150
00151 list( $sUsec, $sSec ) = explode( ' ', microtime() );
00152 $this->dTimeEnd = ( ( float ) $sUsec + ( float ) $sSec );
00153 $dTimeSpent = $this->dTimeEnd - $this->dTimeStart;
00154
00155 echo 'Execution time :'.$dTimeSpent.'<br />';
00156
00157
00158 if ( function_exists( 'memory_get_usage' ) ) {
00159 $iKb = ( int ) ( memory_get_usage() / 1024 );
00160 $iMb = round($iKb / 1024, 3);
00161 echo 'Memory usage: '.$iMb.' MB';
00162
00163 if ( function_exists( 'memory_get_peak_usage' ) ) {
00164 $iPeakKb = ( int ) ( memory_get_peak_usage() / 1024 );
00165 $iPeakMb = round($iPeakKb / 1024, 3);
00166 echo ' (peak: '.$iPeakMb.' MB)';
00167 }
00168 echo '<br />';
00169
00170 if ( version_compare( PHP_VERSION, '5.2.0', '>=' ) ) {
00171 $iKb = ( int ) ( memory_get_usage( true ) / 1024 );
00172 $iMb = round($iKb / 1024, 3);
00173 echo 'System memory usage: '.$iMb.' MB';
00174
00175 if ( function_exists( 'memory_get_peak_usage' ) ) {
00176 $iPeakKb = ( int ) ( memory_get_peak_usage( true ) / 1024 );
00177 $iPeakMb = round($iPeakKb / 1024, 3);
00178 echo ' (peak: '.$iPeakMb.' MB)';
00179 }
00180 echo '<br />';
00181 }
00182 }
00183
00184 echo '</div>';
00185 }
00186
00187 }
00188
00204 protected function _process( $sClass, $sFunction )
00205 {
00206 $myConfig = $this->getConfig();
00207
00208 if ( !oxUtils::getInstance()->isSearchEngine() &&
00209 !( $this->isAdmin() || !$myConfig->getConfigParam( 'blLogging' ) ) ) {
00210 $this->_log( $sClass, $sFunction );
00211 }
00212
00213
00214 $this->_startMonitor();
00215
00216
00217 $oViewObject = oxNew( $sClass );
00218
00219
00220 $oViewObject->setClassName( $sClass );
00221 $oViewObject->setFncName( $sFunction );
00222
00223 $myConfig->setActiveView( $oViewObject );
00224
00225
00226 $sOutput = null;
00227 $blIsCached = false;
00228 $blIsCachable = false;
00229
00230
00231
00232 $oViewObject->init();
00233
00234
00235 $oViewObject->executeFunction( $oViewObject->getFncName() );
00236
00237
00238
00239 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00240
00241
00242 if ( !$blIsCached ) {
00243
00244
00245 $sTemplateName = $oViewObject->render();
00246
00247
00248 $sTemplateFile = $myConfig->getTemplatePath( $sTemplateName, $this->isAdmin() ) ;
00249 if ( !file_exists( $sTemplateFile)) {
00250 $oEx = oxNew( 'oxSystemComponentException' );
00251 $oLang = oxLang::getInstance();
00252 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_SYSTEMCOMPONENT_TEMPLATENOTFOUND', $oLang->getBaseLanguage() ), $sTemplateFile) );
00253 $oEx->setComponent( $sTemplateName );
00254 throw $oEx;
00255 }
00256 $aViewData = $oViewObject->getViewData();
00257
00258
00259 $oOutput = oxNew( 'oxoutput' );
00260 $aViewData = $oOutput->processViewArray( $aViewData, $oViewObject->getClassName() );
00261 $oViewObject->setViewData( $aViewData );
00262
00263
00264 if ( ( $aErrors = oxSession::getVar( 'Errors' ) ) ) {
00265 oxUtilsView::getInstance()->passAllErrorsToView( $aViewData, $aErrors );
00266
00267
00268 oxSession::setVar( 'Errors', array() );
00269 }
00270
00271 foreach ( array_keys( $aViewData ) as $sViewName ) {
00272 $oSmarty->assign_by_ref( $sViewName, $aViewData[$sViewName] );
00273 }
00274
00275
00276 $oSmarty->oxobject = $oViewObject;
00277
00278
00279 $sOutput = $oSmarty->fetch( $sTemplateName, $oViewObject->getViewId() );
00280
00281
00282 $sOutput = $oOutput->process( $sOutput, $oViewObject->getClassName() );
00283 $sOutput = $oOutput->addVersionTags( $sOutput );
00284 }
00285
00286
00287
00288
00289
00290
00291 header("Content-Type: text/html; charset=".oxLang::getInstance()->translateString( 'charset' ));
00292 echo ( $sOutput );
00293
00294 $myConfig->pageClose();
00295
00296
00297 $this->_stopMonitor( $blIsCachable, $blIsCached, $sViewID, $oViewObject->getViewData() );
00298 }
00299
00306 protected function _runOnce()
00307 {
00308 $myConfig = $this->getConfig();
00309 $blRunOnceExecuted = oxSession::getVar( 'blRunOnceExecuted' );
00310 $blProductive = true;
00311
00312
00313
00314
00315 if ( ! ( $blProductive = $myConfig->isProductiveMode() ) ) {
00316 if ( is_null($myConfig->getConfigParam( 'iDebug' )) ) {
00317 $myConfig->setConfigParam( 'iDebug', -1 );
00318 }
00319
00320 error_reporting( E_ALL ^ E_NOTICE );
00321 } else {
00322
00323
00324 if ( !ini_get( 'log_errors' ) ) {
00325 error_reporting( E_NONE );
00326 } else {
00327 error_reporting( E_ALL ^ E_NOTICE );
00328 }
00329 }
00330
00331
00332
00333 if ( !$blRunOnceExecuted && !$this->isAdmin() && $blProductive ) {
00334
00335
00336 if ( file_exists( $myConfig->getConfigParam( 'sShopDir' ) . '/setup/index.php' ) ) {
00337 $oActView = oxNew( 'oxubase' );
00338 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00339 $oSmarty->assign('oView', $oActView);
00340 $oSmarty->assign('oViewConf', $oActView->getViewConfig());
00341 oxUtils::getInstance()->showMessageAndExit( $oSmarty->fetch( 'err_setup.tpl' ) );
00342 }
00343
00344 oxSession::setVar( 'blRunOnceExecuted', true );
00345 }
00346 }
00347 }