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
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
00082 $aViewData = $oObject->getViewData();
00083 if ( is_array( $aViewData ) ) {
00084 foreach ( array_keys( $aViewData ) as $sViewName ) {
00085
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
00132 $sDestination = oxConfig::getParameter( 'CustomError' );
00133 if ( $sCustomDestination != '' ) {
00134 $sDestination = $sCustomDestination;
00135 }
00136 } else {
00137
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
00152 $sTmp = $oEr;
00153 $oEr = oxNew( 'oxDisplayError' );
00154 $oEr->setMessage( $sTmp );
00155 } elseif ( $oEr instanceof oxDisplayErrorInterface ) {
00156
00157 } else {
00158 $oEr = null;
00159 }
00160
00161 if ( $oEr ) {
00162 $aEx[$sDestination][] = serialize( $oEr );
00163 oxSession::setVar( 'Errors', $aEx );
00164 }
00165 }
00166
00175 public function parseThroughSmarty( $sDesc, $sOxid )
00176 {
00177
00178 $sOxid .= oxLang::getInstance()->getTplLanguage();
00179
00180 $oSmarty = clone $this->getSmarty();
00181
00182 $oActView = oxNew( 'oxubase' );
00183 $oActView->addGlobalParams();
00184
00185
00186 $sTplVars = $oSmarty->_tpl_vars;
00187
00188 $aViewData = $oActView->getViewData();
00189 $aActiveViewData = $this->getConfig()->getActiveView()->getViewData();
00190 foreach ( array_keys( $aViewData ) as $sViewName ) {
00191 if ( isset( $aActiveViewData[$sViewName] ) ) {
00192 $oSmarty->assign_by_ref( $sViewName, $aActiveViewData[$sViewName] );
00193 }
00194 }
00195
00196 $oSmarty->oxidcache = new oxField($sDesc, oxField::T_RAW);
00197 $sRes = $oSmarty->fetch( "ox:$sOxid" );
00198
00199
00200 $oSmarty->_tpl_vars = $sTplVars;
00201
00202 return $sRes;
00203 }
00204
00212 protected function _fillCommonSmartyProperties( $oSmarty )
00213 {
00214 $myConfig = $this->getConfig();
00215
00216 $oSmarty->php_handling = SMARTY_PHP_REMOVE;
00217 $oSmarty->security = $myConfig->isDemoShop()? true : false;
00218
00219 $oSmarty->left_delimiter = '[{';
00220 $oSmarty->right_delimiter = '}]';
00221
00222 $oSmarty->register_resource( 'ox', array( 'ox_get_template',
00223 'ox_get_timestamp',
00224 'ox_get_secure',
00225 'ox_get_trusted' ) );
00226
00227 $oSmarty->register_modifier( 'truncate', 'smarty_modifier_oxtruncate' );
00228
00229
00230 $oSmarty->caching = false;
00231 $oSmarty->compile_dir = $myConfig->getConfigParam( 'sCompileDir' );
00232 $oSmarty->cache_dir = $myConfig->getConfigParam( 'sCompileDir' );
00233 $oSmarty->template_dir = $myConfig->getTemplateDir( $this->isAdmin() );
00234 $oSmarty->compile_id = md5( $oSmarty->template_dir );
00235
00236 $iDebug = $myConfig->getConfigParam( 'iDebug' );
00237 if ( $iDebug == 1 || $iDebug == 3 || $iDebug == 4 ) {
00238 $oSmarty->debugging = true;
00239 }
00240 }
00241
00249 protected function _smartyCompileCheck( $oSmarty )
00250 {
00251 $myConfig = $this->getConfig();
00252 $oSmarty->compile_check = $myConfig->getConfigParam( 'blCheckTemplates' );
00253
00254 }
00255 }