Ticket #545: template_virtuel.diff
| File template_virtuel.diff, 5.7 kB (added by Lipki, 9 months ago) |
|---|
-
lib/jelix/core/jIncluder.class.php
old new 98 98 $mustCompile = $gJConfig->compilation['force'] || !file_exists($cachefile); 99 99 $sourcefile = $aSelector->getPath(); 100 100 101 if( $sourcefile == '' || !file_exists($sourcefile)){101 if( ( $sourcefile == '' || !file_exists($sourcefile) ) && !$aSelector->_dyn ){ 102 102 throw new jException('jelix~errors.includer.source.missing',array( $aSelector->toString(true))); 103 103 } 104 104 -
lib/jelix/core/jSelector.class.php
old new 104 104 protected $_cachePath; 105 105 protected $_compiler = null; 106 106 protected $_compilerPath; 107 protected $_dyn = false; 107 108 protected $_useMultiSourceCompiler=false; 108 109 109 110 function __construct($sel){ … … 709 710 } 710 711 } 711 712 713 714 715 class jSelectorVTpl extends jSelectorModule { 716 protected $type = 'tpl'; 717 protected $_dirname = 'classes/'; 718 protected $_suffix = '.tpl'; 719 protected $_where; 720 public $outputType=''; 721 public $trusted=true; 722 public $_dyn = true; 723 function __construct($sel, $outputtype='', $trusted=true) { 724 if($outputtype == ''){ 725 if($GLOBALS['gJCoord']->response) 726 $this->outputType = $GLOBALS['gJCoord']->response->getFormatType(); 727 else 728 $this->outputType = $GLOBALS['gJCoord']->request->defaultResponseType; 729 } else 730 $this->outputType = $outputtype; 731 $this->trusted = $trusted; 732 $this->_compiler='jVTplCompiler'; 733 $this->_compilerPath=JELIX_LIB_PATH.'tpl/jTplCompiler.class.php'; 734 parent::__construct($sel); 735 } 736 protected function _createPath(){ 737 global $gJConfig; 738 if(!isset($gJConfig->_modulesPathList[$this->module])){ 739 throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 740 } 741 $path = $this->module.'/'.$this->resource; 742 // pas d'overload via themes/ 743 // pas de local 744 $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.'dynTpl.class.php'; 745 if(is_readable($this->_path)){ 746 $this->_where = 'modules/'.$path; 747 return; 748 } 749 throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "dyn template")); 750 } 751 protected function _createCachePath(){ 752 $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/templates/'.$this->_where.'_'.$this->outputType.($this->trusted?'_t':'').$this->_cacheSuffix; 753 } 754 } 755 756 757 712 758 /** 713 759 * Zone selector 714 760 * -
lib/jelix/tpl/jTpl.class.php
old new 242 242 * @param boolean $callMeta false if meta should not be called 243 243 * @return string the generated content 244 244 */ 245 public function fetch ($tpl, $outputtype='', $trusted = true, $callMeta=true ){245 public function fetch ($tpl, $outputtype='', $trusted = true, $callMeta=true, $dyn=false){ 246 246 $content = ''; 247 247 ob_start (); 248 248 try{ 249 249 #ifnot JTPL_STANDALONE 250 $sel = new jSelectorTpl($tpl, $outputtype, $trusted); 250 if( $dyn ) 251 sel = new jSelectorVTpl($tpl, $outputtype, $trusted); 252 else $sel = new jSelectorTpl($tpl, $outputtype, $trusted); 251 253 jIncluder::inc($sel); 252 254 $md = md5($sel->module.'_'.$sel->resource.'_'.$sel->outputType.($trusted?'_t':'')); 253 255 #else … … 283 285 } 284 286 return $content; 285 287 } 288 289 public function dynFetch($tpl, $outputtype='', $trusted = true, $callMeta=true){ 290 return $this->fetch($tpl, $outputtype, $trusted, $callMeta, true); 291 } 286 292 287 293 /** 288 294 * deprecated function: optimized version of meta() + fetch(). -
lib/jelix/tpl/jTplCompiler.class.php
old new 592 592 593 593 } 594 594 595 class jVTplCompiler extends jTplCompiler { 596 private $_pluginPath=array(); 597 private $_metaBody = ''; 598 599 public function compile($selector){ 600 601 $this->dynFile = $selector->getPath(); 602 $cachefile = $selector->getCompiledFilePath(); 603 $this->outputType = $selector->outputType; 604 $this->trusted = $selector->trusted; 605 jContext::push($selector->module); 606 607 require_once($this->dynFile); 608 $dyn = new dynTpl(); 609 if( !is_callable(array($dyn, $selector->resource)) ) { 610 $this->doError0('errors.tpl.not.found'); 611 } 612 613 $result = $this->compileContent($dyn->{$selector->resource}()); 614 615 $header ="<?php \n"; 616 foreach($this->_pluginPath as $path=>$ok){ 617 $header.=' require_once(\''.$path."');\n"; 618 } 619 $header.='function template_meta_'.md5($selector->module.'_'.$selector->resource.'_'.$this->outputType.($this->trusted?'_t':'')).'($t){'; 620 $header .="\n".$this->_metaBody."\n}\n"; 621 $header.='function template_'.md5($selector->module.'_'.$selector->resource.'_'.$this->outputType.($this->trusted?'_t':'')).'($t){'."\n?>"; 622 $result = $header.$result."<?php \n}\n?>"; 623 jFile::write($cachefile, $result); 624 jContext::pop(); 625 return true; 626 } 627 } 628 595 629 ?>
