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 
00129     public function addErrorToDisplay( $oEr, $blFull = false, $blCustomDestination = false, $sCustomDestination = "" )
00130     {
00131         if ( $blCustomDestination && ( oxConfig::getParameter( 'CustomError' ) || $sCustomDestination!= '' ) ) {
00132             // check if the current request wants do display exceptions on its own
00133             $sDestination = oxConfig::getParameter( 'CustomError' );
00134             if ( $sCustomDestination != '' ) {
00135                 $sDestination = $sCustomDestination;
00136             }
00137         } else {
00138             //default
00139             $sDestination = 'default';
00140         }
00141 
00142         $aEx = oxSession::getVar( 'Errors' );
00143         if ( $oEr instanceof oxException ) {
00144              $oEx = oxNew( 'oxExceptionToDisplay' );
00145              $oEx->setMessage( $oEr->getMessage() );
00146              $oEx->setExceptionType( get_class( $oEr ) );
00147              $oEx->setValues( $oEr->getValues() );
00148              $oEx->setStackTrace( $oEr->getTraceAsString() );
00149              $oEx->setDebug( $blFull );
00150              $oEr=$oEx;
00151         } elseif ( ! ( $oEr instanceof oxDisplayErrorInterface ) ) {
00152             // assuming that a string was given
00153             $sTmp = $oEr;
00154             $oEr = oxNew( 'oxDisplayError' );
00155             $oEr->setMessage( $sTmp );
00156         } elseif ( $oEr instanceof oxDisplayErrorInterface ) {
00157             // take the object
00158             continue;
00159         } else {
00160             $oEr = null;
00161         }
00162 
00163         $aEx[$sDestination][] = serialize( $oEr );
00164 
00165         oxSession::setVar( 'Errors', $aEx );
00166     }
00167 
00176     public function parseThroughSmarty( $sDesc, $sOxid )
00177     {
00178 
00179         $sOxid .= oxLang::getInstance()->getTplLanguage();
00180         // now parse it through smarty
00181         $oSmarty = clone $this->getSmarty();
00182 
00183         $oActView = oxNew( 'oxubase' );
00184         $oActView->addGlobalParams();
00185 
00186         // save old tpl data
00187         $sTplVars = $oSmarty->_tpl_vars;
00188 
00189         $aViewData = $oActView->getViewData();
00190         $aActiveViewData = $this->getConfig()->getActiveView()->getViewData();
00191         foreach ( array_keys( $aViewData ) as $sViewName ) {
00192             if ( isset( $aActiveViewData[$sViewName] ) ) {
00193                 $oSmarty->assign_by_ref( $sViewName, $aActiveViewData[$sViewName] );
00194             }
00195         }
00196 
00197         $oSmarty->oxidcache = new oxField($sDesc, oxField::T_RAW);
00198         $sRes = $oSmarty->fetch( "ox:$sOxid" );
00199 
00200         // restore tpl vars for continuing smarty processing if it is in one
00201         $oSmarty->_tpl_vars = $sTplVars;
00202 
00203         return $sRes;
00204     }
00205 
00213     protected function _fillCommonSmartyProperties( $oSmarty )
00214     {
00215         $myConfig = $this->getConfig();
00216 
00217         $oSmarty->php_handling = SMARTY_PHP_REMOVE;
00218         $oSmarty->security = false;
00219 
00220         // Additional demoshop behaviour
00221         if ( $myConfig->isDemoShop() ) {
00222             $oSmarty->security     = true;
00223             $oSmarty->php_handling =  SMARTY_PHP_REMOVE;
00224         }
00225 
00226         $oSmarty->left_delimiter  = '[{';
00227         $oSmarty->right_delimiter = '}]';
00228 
00229         $oSmarty->register_resource( 'ox', array( 'ox_get_template',
00230                                                   'ox_get_timestamp',
00231                                                   'ox_get_secure',
00232                                                   'ox_get_trusted' ) );
00233 
00234         $oSmarty->register_modifier( 'truncate', 'smarty_modifier_oxtruncate' );
00235 
00236         // $myConfig->blTemplateCaching; // DODGER #655 : permanently switched off as it doesnt work good enough
00237         $oSmarty->caching      = false;
00238         $oSmarty->compile_dir  = $myConfig->getConfigParam( 'sCompileDir' );
00239         $oSmarty->cache_dir    = $myConfig->getConfigParam( 'sCompileDir' );
00240         $oSmarty->template_dir = $myConfig->getTemplateDir( $this->isAdmin() );
00241 
00242         $sShopId = 'admin';
00243         if ( !$this->isAdmin() ) {
00244             $sShopId = $myConfig->getShopId();
00245         }
00246 
00247         $oSmarty->compile_id = md5($oSmarty->template_dir);
00248 
00249         $iDebug = $myConfig->getConfigParam( 'iDebug' );
00250         if (  $iDebug == 1 || $iDebug == 3 || $iDebug == 4 ) {
00251             $oSmarty->debugging = true;
00252         }
00253     }
00254 
00262     protected function _smartyCompileCheck( $oSmarty )
00263     {
00264         $myConfig = $this->getConfig();
00265         $oSmarty->compile_check  = $myConfig->getConfigParam( 'blCheckTemplates' );
00266 
00267     }
00268 }

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