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 $sShopID = oxSession::getVar( 'actshop' );
00087 $sTime = date( 'Y-m-d H:i:s' );
00088 $sSid = $this->getSession()->getId();
00089 $sUserID = oxSession::getVar( 'usr' );
00090 $sCnid = oxConfig::getParameter( 'cnid' );
00091 $sAnid = oxConfig::getParameter( 'aid' )?oxConfig::getParameter( 'aid' ):oxConfig::getParameter( 'anid' );
00092 $sParameter = '';
00093
00094 if ( $sClass == 'info' ) {
00095 $sParameter = str_replace( '.tpl', '', oxConfig::getParameter('tpl') );
00096 } elseif ( $sClass == 'search' ) {
00097 $sParameter = oxConfig::getParameter( 'searchparam' );
00098 }
00099
00100 oxDb::getDb()->Execute( "insert into oxlogs (oxtime, oxshopid, oxuserid, oxsessid, oxclass, oxfnc, oxcnid, oxanid, oxparameter)
00101 values('$sTime','$sShopID','$sUserID','$sSid','$sClass','$sFnc','$sCnid','$sAnid', '$sParameter')" );
00102 }
00103
00104
00110 protected function _startMonitor()
00111 {
00112 if ( !$this->isAdmin() && $this->getConfig()->getConfigParam( 'iDebug' ) ) {
00113 list ( $sUsec, $sSec ) = explode( ' ', microtime() );
00114 $this->dTimeStart = ( ( float ) $sUsec + ( float ) $sSec );
00115 }
00116 }
00117
00128 protected function _stopMonitor( $blIsCache = false, $blIsCached = false, $sViewID = null, $aViewData = array() )
00129 {
00130 $myConfig = $this->getConfig();
00131 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'iDebug' ) != 0 ) {
00132 echo '<div align="left">';
00133
00134
00135 if ( $myConfig->getConfigParam( 'iDebug' ) == 4 ) {
00136
00137 reset( $aViewData );
00138 while ( list( $sViewName, $oViewData ) =each( $aViewData ) ) {
00139
00140 echo( "TemplateData[$sViewName] : <br />\n");
00141 print_r( $oViewData );
00142 }
00143 }
00144
00145
00146 list( $sUsec, $sSec ) = explode( ' ', microtime() );
00147 $this->dTimeEnd = ( ( float ) $sUsec + ( float ) $sSec );
00148 $dTimeSpent = $this->dTimeEnd - $this->dTimeStart;
00149
00150 echo 'Execution time :'.$dTimeSpent.'<br />';
00151
00152
00153 if ( function_exists( 'memory_get_usage' ) ) {
00154 $iKb = ( int ) ( memory_get_usage() / 1024 );
00155 $iMb = round($iKb / 1024, 3);
00156 echo 'Memory usage: '.$iMb.' MB';
00157
00158 if ( function_exists( 'memory_get_peak_usage' ) ) {
00159 $iPeakKb = ( int ) ( memory_get_peak_usage() / 1024 );
00160 $iPeakMb = round($iPeakKb / 1024, 3);
00161 echo ' (peak: '.$iPeakMb.' MB)';
00162 }
00163 echo '<br />';
00164
00165 if ( version_compare( PHP_VERSION, '5.2.0', '>=' ) ) {
00166 $iKb = ( int ) ( memory_get_usage( true ) / 1024 );
00167 $iMb = round($iKb / 1024, 3);
00168 echo 'System memory usage: '.$iMb.' MB';
00169
00170 if ( function_exists( 'memory_get_peak_usage' ) ) {
00171 $iPeakKb = ( int ) ( memory_get_peak_usage( true ) / 1024 );
00172 $iPeakMb = round($iPeakKb / 1024, 3);
00173 echo ' (peak: '.$iPeakMb.' MB)';
00174 }
00175 echo '<br />';
00176 }
00177 }
00178
00179 echo '</div>';
00180 }
00181
00182 }
00183
00199 protected function _process( $sClass, $sFunction )
00200 {
00201 $myConfig = $this->getConfig();
00202
00203 if ( !oxUtils::getInstance()->isSearchEngine() &&
00204 !( $this->isAdmin() || !$myConfig->getConfigParam( 'blLogging' ) ) ) {
00205 $this->_log( $sClass, $sFunction );
00206 }
00207
00208
00209 $this->_startMonitor();
00210
00211
00212 $oViewObject = oxNew( $sClass );
00213
00214
00215 $oViewObject->setClassName( $sClass );
00216 $oViewObject->setFncName( $sFunction );
00217
00218 $myConfig->setActiveView( $oViewObject );
00219
00220
00221 $sOutput = null;
00222 $blIsCached = false;
00223 $blIsCachable = false;
00224
00225
00226
00227 $oViewObject->init();
00228
00229
00230 $oViewObject->executeFunction( $oViewObject->getFncName() );
00231
00232
00233
00234 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00235
00236
00237 if ( !$blIsCached ) {
00238
00239
00240 $sTemplateName = $oViewObject->render();
00241
00242
00243 $sTemplateFile = $myConfig->getTemplatePath( $sTemplateName, $this->isAdmin() ) ;
00244 if ( !file_exists( $sTemplateFile)) {
00245 $oEx = oxNew( 'oxSystemComponentException' );
00246 $oLang = oxLang::getInstance();
00247 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_SYSTEMCOMPONENT_TEMPLATENOTFOUND', $oLang->getBaseLanguage() ), $sTemplateFile) );
00248 $oEx->setComponent( $sTemplateName );
00249 throw $oEx;
00250 }
00251 $aViewData = $oViewObject->getViewData();
00252
00253
00254 $oOutput = oxNew( 'oxoutput' );
00255 $aViewData = $oOutput->processViewArray( $aViewData, $oViewObject->getClassName() );
00256 $oViewObject->setViewData( $aViewData );
00257
00258
00259 if ( ( $aErrors = oxSession::getVar( 'Errors' ) ) ) {
00260 oxUtilsView::getInstance()->passAllErrorsToView( $aViewData, $aErrors );
00261
00262
00263 oxSession::setVar( 'Errors', array() );
00264 }
00265
00266 foreach ( array_keys( $aViewData ) as $sViewName ) {
00267 $oSmarty->assign_by_ref( $sViewName, $aViewData[$sViewName] );
00268 }
00269
00270
00271 $oSmarty->oxobject = $oViewObject;
00272
00273
00274 $sOutput = $oSmarty->fetch( $sTemplateName, $oViewObject->getViewId() );
00275
00276
00277 $sOutput = $oOutput->process( $sOutput, $oViewObject->getClassName() );
00278 $sOutput = $oOutput->addVersionTags( $sOutput );
00279 }
00280
00281
00282
00283
00284
00285
00286 header("Content-Type: text/html; charset=".oxLang::getInstance()->translateString( 'charset' ));
00287 echo ( $sOutput );
00288
00289 $myConfig->pageClose();
00290
00291
00292 $this->_stopMonitor( $blIsCachable, $blIsCached, $sViewID, $oViewObject->getViewData() );
00293 }
00294
00301 protected function _runOnce()
00302 {
00303 $myConfig = $this->getConfig();
00304 $blRunOnceExecuted = oxSession::getVar( 'blRunOnceExecuted' );
00305 $blProductive = true;
00306
00307
00308
00309
00310 if ( ! ( $blProductive = $myConfig->isProductiveMode() ) ) {
00311 if ( is_null($myConfig->getConfigParam( 'iDebug' )) ) {
00312 $myConfig->setConfigParam( 'iDebug', -1 );
00313 }
00314
00315 error_reporting( E_ALL ^ E_NOTICE );
00316 } else {
00317
00318
00319 if ( !ini_get( 'log_errors' ) ) {
00320 error_reporting( E_NONE );
00321 } else {
00322 error_reporting( E_ALL ^ E_NOTICE );
00323 }
00324 }
00325
00326
00327
00328 if ( !$blRunOnceExecuted && !$this->isAdmin() && $blProductive ) {
00329
00330
00331 if ( file_exists( $myConfig->getConfigParam( 'sShopDir' ) . '/setup/index.php' ) ) {
00332 $oActView = oxNew( 'oxubase' );
00333 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00334 $oSmarty->assign('oView', $oActView);
00335 $oSmarty->assign('oViewConf', $oActView->getViewConfig());
00336 oxUtils::getInstance()->showMessageAndExit( $oSmarty->fetch( 'err_setup.tpl' ) );
00337 }
00338
00339 oxSession::setVar( 'blRunOnceExecuted', true );
00340 }
00341 }
00342 }