oxshopcontrol.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxShopControl extends oxSuperCfg
00009 {
00020     public function start()
00021     {
00022         $myConfig = $this->getConfig();
00023 
00024         //perform tasks once per session
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                 // first start of the shop
00035                 // check wether we have to display mall startscreen or not
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                         // no class specified so we need to change back to baseshop
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         // baseshop always active if there is no mall
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             //possible reason: class does not exist etc. --> just redirect to start page
00066             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00067             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=start' );
00068         } catch ( oxCookieException $oEx ) {
00069             // redirect to start page and display the error
00070             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00071             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=start' );
00072         } catch ( oxAccessRightException $oEx) {
00073             // R&R handling -> redirect to error msg, also, can call _process again, specifying error handler view class
00074             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=content&tpl=err_accessdenied.tpl' );
00075         }
00076     }
00077 
00087     protected function _log( $sClass, $sFnc )
00088     {
00089         $sShopID    = oxSession::getVar( 'actshop' );
00090         $sTime      = date( 'Y-m-d H:i:s' );
00091         $sSid       = $this->getSession()->getId();
00092         $sUserID    = oxSession::getVar( 'usr' );
00093         $sCnid      = oxConfig::getParameter( 'cnid' );
00094         $sAnid      = oxConfig::getParameter( 'aid' )?oxConfig::getParameter( 'aid' ):oxConfig::getParameter( 'anid' );
00095         $sParameter = '';
00096 
00097         if ( $sClass == 'info' ) {
00098             $sParameter = str_replace( '.tpl', '', oxConfig::getParameter('tpl') );
00099         } elseif ( $sClass == 'search' ) {
00100             $sParameter = oxConfig::getParameter( 'searchparam' );
00101         }
00102 
00103         oxDb::getDb()->Execute( "insert into oxlogs (oxtime, oxshopid, oxuserid, oxsessid, oxclass, oxfnc, oxcnid, oxanid, oxparameter)
00104                                  values('$sTime','$sShopID','$sUserID','$sSid','$sClass','$sFnc','$sCnid','$sAnid', '$sParameter')" );
00105     }
00106 
00107     // OXID : add timing
00113     protected function _startMonitor()
00114     {
00115         if ( !$this->isAdmin() && $this->getConfig()->getConfigParam( 'iDebug' ) ) {
00116             list ( $sUsec, $sSec ) = explode( ' ', microtime() );
00117             $this->dTimeStart = ( ( float ) $sUsec + ( float ) $sSec );
00118         }
00119     }
00120 
00131     protected function _stopMonitor( $blIsCache = false, $blIsCached = false, $sViewID = null, $aViewData = array() )
00132     {
00133         $myConfig = $this->getConfig();
00134         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'iDebug' ) != 0 ) {
00135             echo '<div align="left">';
00136 
00137             // outputting template params
00138             if ( $myConfig->getConfigParam( 'iDebug' ) == 4 ) {
00139 
00140                 reset( $aViewData );
00141                 while ( list( $sViewName, $oViewData ) =each( $aViewData ) ) {
00142                     // show debbuging information
00143                         echo( "TemplateData[$sViewName] : <br />\n");
00144                         print_r( $oViewData );
00145                 }
00146             }
00147 
00148             // output timing
00149             list( $sUsec, $sSec ) = explode( ' ', microtime() );
00150             $this->dTimeEnd = ( ( float ) $sUsec + ( float ) $sSec );
00151             $dTimeSpent = $this->dTimeEnd - $this->dTimeStart;
00152 
00153             echo 'Execution time :'.$dTimeSpent.'<br />';
00154 
00155             // memory usage info
00156             if ( function_exists( 'memory_get_usage' ) ) {
00157                 $iKb = ( int ) ( memory_get_usage() / 1024 );
00158                 $iMb = round($iKb / 1024, 3);
00159                 echo 'Memory usage: '.$iMb.' MB';
00160 
00161                 if ( function_exists( 'memory_get_peak_usage' ) ) {
00162                     $iPeakKb = ( int ) ( memory_get_peak_usage() / 1024 );
00163                     $iPeakMb = round($iPeakKb / 1024, 3);
00164                     echo ' (peak: '.$iPeakMb.' MB)';
00165                 }
00166                 echo '<br />';
00167 
00168                 if ( version_compare( PHP_VERSION, '5.2.0', '>=' ) ) {
00169                     $iKb = ( int ) ( memory_get_usage( true ) / 1024 );
00170                     $iMb = round($iKb / 1024, 3);
00171                     echo 'System memory usage: '.$iMb.' MB';
00172 
00173                     if ( function_exists( 'memory_get_peak_usage' ) ) {
00174                         $iPeakKb = ( int ) ( memory_get_peak_usage( true ) / 1024 );
00175                         $iPeakMb = round($iPeakKb / 1024, 3);
00176                         echo ' (peak: '.$iPeakMb.' MB)';
00177                     }
00178                     echo '<br />';
00179                 }
00180             }
00181 
00182             echo '</div>';
00183         }
00184 
00185     }
00186 
00202     protected function _process( $sClass, $sFunction )
00203     {
00204         $myConfig = $this->getConfig();
00205 
00206         if ( !oxUtils::getInstance()->isSearchEngine() &&
00207              !( $this->isAdmin() || !$myConfig->getConfigParam( 'blLogging' ) ) ) {
00208             $this->_log( $sClass, $sFunction );
00209         }
00210 
00211         // starting resource monitor
00212         $this->_startMonitor();
00213 
00214         // creating current view object
00215         $oViewObject = oxNew( $sClass );
00216 
00217         // store this call
00218         $oViewObject->setClassName( $sClass );
00219         $oViewObject->setFncName( $sFunction );
00220 
00221         $myConfig->setActiveView( $oViewObject );
00222 
00223         // caching params ...
00224         $sOutput      = null;
00225         $blIsCached   = false;
00226         $blIsCachable = false;
00227 
00228 
00229         // init class
00230         $oViewObject->init();
00231 
00232         // executing user defined function
00233         $oViewObject->executeFunction( $oViewObject->getFncName() );
00234 
00235 
00236         // get Smarty is important here as it sets template directory correct
00237         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00238 
00239         // if no cache was stored before we should generate it
00240         if ( !$blIsCached ) {
00241 
00242             // render it
00243             $sTemplateName = $oViewObject->render();
00244 
00245             // check if template dir exists
00246             $sTemplateFile = $myConfig->getTemplatePath( $sTemplateName, $this->isAdmin() ) ;
00247             if ( !file_exists( $sTemplateFile)) {
00248                 $oEx = oxNew( 'oxSystemComponentException' );
00249                 $oLang = oxLang::getInstance();
00250                 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_SYSTEMCOMPONENT_TEMPLATENOTFOUND', $oLang->getBaseLanguage() ), $sTemplateFile) );
00251                 $oEx->setComponent( $sTemplateName );
00252                 throw $oEx;
00253             }
00254             $aViewData = $oViewObject->getViewData();
00255 
00256             //Output processing. This is useful for modules. As sometimes you may want to process output manually.
00257             $oOutput = oxNew( 'oxoutput' );
00258             $aViewData = $oOutput->processViewArray( $aViewData, $oViewObject->getClassName() );
00259             $oViewObject->setViewData( $aViewData );
00260 
00261             //add all exceptions to display
00262             if ( ( $aErrors = oxSession::getVar( 'Errors' ) ) ) {
00263                 oxUtilsView::getInstance()->passAllErrorsToView( $aViewData, $aErrors );
00264 
00265                 // resetting errors after displaying them
00266                 oxSession::setVar( 'Errors', array() );
00267             }
00268 
00269             foreach ( array_keys( $aViewData ) as $sViewName ) {
00270                 $oSmarty->assign_by_ref( $sViewName, $aViewData[$sViewName] );
00271             }
00272 
00273             // passing current view object to smarty
00274             $oSmarty->oxobject = $oViewObject;
00275 
00276 
00277             $sOutput = $oSmarty->fetch( $sTemplateName, $oViewObject->getViewId() );
00278 
00279             //Output processing - useful for modules as sometimes you may want to process output manually.
00280             $sOutput = $oOutput->process( $sOutput, $oViewObject->getClassName() );
00281             $sOutput = $oOutput->addVersionTags( $sOutput );
00282         }
00283 
00284 
00285         // show output
00286         //ob_Start("gzip");
00287         echo ( $sOutput );
00288 
00289         $myConfig->pageClose();
00290 
00291         // stopping resource monitor
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             // A. is it the right place for this code ?
00309             // productive mode ?
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                 // disable error logging if server is misconfigured
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             // perform stuff - check if setup is still there
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 }

Generated on Wed May 13 13:25:55 2009 for OXID eShop CE by  doxygen 1.5.5