oxutilsview.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsView extends oxSuperCfg
00007 {
00013     private static $_instance = null;
00014 
00020     protected static $_oSmarty = null;
00021 
00027     public static function getInstance()
00028     {
00029         // disable caching for test modules
00030         if ( defined( 'OXID_PHP_UNIT' ) ) {
00031             static $inst = array();
00032             self::$_instance = $inst[oxClassCacheKey()];
00033         }
00034 
00035         if ( !self::$_instance instanceof oxUtilsView ) {
00036 
00037 
00038             self::$_instance = oxNew( 'oxUtilsView' );
00039 
00040             if ( defined( 'OXID_PHP_UNIT' ) ) {
00041                 $inst[oxClassCacheKey()] = self::$_instance;
00042             }
00043         }
00044         return self::$_instance;
00045     }
00046 
00056     public function getSmarty( $blReload = false )
00057     {
00058         if ( !self::$_oSmarty || $blReload ) {
00059             self::$_oSmarty = new Smarty;
00060             $this->_fillCommonSmartyProperties( self::$_oSmarty );
00061             $this->_smartyCompileCheck( self::$_oSmarty );
00062         }
00063 
00064         return self::$_oSmarty;
00065     }
00066 
00076     public function getTemplateOutput( $sTemplate, $oObject )
00077     {
00078         $oSmarty = $this->getSmarty();
00079         $iDebug  = $this->getConfig()->getConfigParam( 'iDebug' );
00080 
00081         // assign
00082         $aViewData = $oObject->getViewData();
00083         if ( is_array( $aViewData ) ) {
00084             foreach ( array_keys( $aViewData ) as $sViewName ) {
00085                 // show debbuging information
00086                 if ( $iDebug == 4 ) {
00087                     echo( "TemplateData[$sViewName] : \n");
00088                     print_r( $aViewData[$sViewName] );
00089                 }
00090                 $oSmarty->assign_by_ref( $sViewName, $aViewData[$sViewName] );
00091             }
00092         }
00093 
00094         return $oSmarty->fetch( $sTemplate );
00095     }
00096 
00105     public function passAllErrorsToView( &$aView, $aErrors )
00106     {
00107         if ( count( $aErrors ) > 0 ) {
00108             foreach ( $aErrors as $sLocation => $aEx2 ) {
00109                 foreach ( $aEx2 as $sKey => $oEr ) {
00110                     $aView['Errors'][$sLocation][$sKey] = unserialize( $oEr );
00111                 }
00112             }
00113         }
00114     }
00115 
00128     public function addErrorToDisplay( $oEr, $blFull = false, $blCustomDestination = false, $sCustomDestination = "" )
00129     {
00130         if ( $blCustomDestination && ( oxConfig::getParameter( 'CustomError' ) || $sCustomDestination!= '' ) ) {
00131             // check if the current request wants do display exceptions on its own
00132             $sDestination = oxConfig::getParameter( 'CustomError' );
00133             if ( $sCustomDestination != '' ) {
00134                 $sDestination = $sCustomDestination;
00135             }
00136         } else {
00137             //default
00138             $sDestination = 'default';
00139         }
00140 
00141         $aEx = oxSession::getVar( 'Errors' );
00142         if ( $oEr instanceof oxException ) {
00143              $oEx = oxNew( 'oxExceptionToDisplay' );
00144              $oEx->setMessage( $oEr->getMessage() );
00145              $oEx->setExceptionType( get_class( $oEr ) );
00146              $oEx->setValues( $oEr->getValues() );
00147              $oEx->setStackTrace( $oEr->getTraceAsString() );
00148              $oEx->setDebug( $blFull );
00149              $oEr = $oEx;
00150         } elseif ( $oEr && ! ( $oEr instanceof oxDisplayErrorInterface ) ) {
00151             // assuming that a string was given
00152             $sTmp = $oEr;
00153             $oEr = oxNew( 'oxDisplayError' );
00154             $oEr->setMessage( $sTmp );
00155         } elseif ( $oEr instanceof oxDisplayErrorInterface ) {
00156             // take the object
00157         } else {
00158             $oEr = null;
00159         }
00160 
00161         if ( $oEr ) {
00162             $aEx[$sDestination][] = serialize( $oEr );
00163             oxSession::setVar( 'Errors', $aEx );
00164         }
00165     }
00166 
00179     public function parseThroughSmarty( $sDesc, $sOxid = null, $oActView = null, $blRecompile = false )
00180     {
00181         $iLang = oxLang::getInstance()->getTplLanguage();
00182 
00183         // now parse it through smarty
00184         $oSmarty = clone $this->getSmarty();
00185 
00186         // save old tpl data
00187         $sTplVars = $oSmarty->_tpl_vars;
00188         $blForceRecompile = $oSmarty->force_compile;
00189 
00190         $oSmarty->force_compile = $blRecompile;
00191 
00192         if ( !$oActView ) {
00193             $oActView = oxNew( 'oxubase' );
00194             $oActView->addGlobalParams();
00195         }
00196 
00197         $aViewData = $oActView->getViewData();
00198         foreach ( array_keys( $aViewData ) as $sName ) {
00199             $oSmarty->assign_by_ref( $sName, $aViewData[$sName] );
00200         }
00201 
00202         if ( is_array( $sDesc ) ) {
00203             foreach ( $sDesc as $sName => $aData ) {
00204                 $oSmarty->oxidcache = new oxField( $aData[1], oxField::T_RAW );
00205                 $sRes[$sName] = $oSmarty->fetch( "ox:".$aData[0].$iLang );
00206             }
00207         } else {
00208             $oSmarty->oxidcache = new oxField($sDesc, oxField::T_RAW);
00209             $sRes = $oSmarty->fetch( "ox:{$sOxid}{$iLang}" );
00210         }
00211 
00212         // restore tpl vars for continuing smarty processing if it is in one
00213         $oSmarty->_tpl_vars = $sTplVars;
00214         $oSmarty->force_compile = $blForceRecompile;
00215 
00216         return $sRes;
00217     }
00218 
00226     protected function _fillCommonSmartyProperties( $oSmarty )
00227     {
00228         $myConfig = $this->getConfig();
00229 
00230         if ( !$myConfig->isDemoShop() ) {
00231             $oSmarty->php_handling = (int) $myConfig->getConfigParam( 'iSmartyPhpHandling' );
00232             $oSmarty->security     = false;
00233         } else {
00234             $oSmarty->php_handling = SMARTY_PHP_REMOVE;
00235             $oSmarty->security     = true;
00236         }
00237 
00238         $oSmarty->left_delimiter  = '[{';
00239         $oSmarty->right_delimiter = '}]';
00240 
00241         $oSmarty->register_resource( 'ox', array( 'ox_get_template',
00242                                                   'ox_get_timestamp',
00243                                                   'ox_get_secure',
00244                                                   'ox_get_trusted' ) );
00245 
00246 
00247         // $myConfig->blTemplateCaching; // DODGER #655 : permanently switched off as it doesnt work good enough
00248         $oSmarty->caching      = false;
00249         $oSmarty->compile_dir  = $myConfig->getConfigParam( 'sCompileDir' );
00250         $oSmarty->cache_dir    = $myConfig->getConfigParam( 'sCompileDir' );
00251         $oSmarty->template_dir = $myConfig->getTemplateDir( $this->isAdmin() );
00252         $oSmarty->compile_id   = md5( $oSmarty->template_dir );
00253 
00254         $iDebug = $myConfig->getConfigParam( 'iDebug' );
00255         if (  $iDebug == 1 || $iDebug == 3 || $iDebug == 4 ) {
00256             $oSmarty->debugging = true;
00257         }
00258     }
00259 
00267     protected function _smartyCompileCheck( $oSmarty )
00268     {
00269         $myConfig = $this->getConfig();
00270         $oSmarty->compile_check  = $myConfig->getConfigParam( 'blCheckTemplates' );
00271 
00272     }
00273 }

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