Changeset 998
- Timestamp:
- 06/21/08 17:08:23 (2 months ago)
- Files:
-
- trunk/lib/jelix/core/jSelector.class.php (modified) (1 diff)
- trunk/lib/jelix/tpl/jTpl.class.php (modified) (4 diffs)
- trunk/lib/jelix/tpl/jTplCompiler.class.php (modified) (5 diffs)
- trunk/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php (modified) (3 diffs)
- trunk/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jelix/core/jSelector.class.php
r939 r998 644 644 public $outputType=''; 645 645 public $trusted=true; 646 public $userModifiers = array(); 647 public $userFunctions = array(); 648 646 649 647 650 /** trunk/lib/jelix/tpl/jTpl.class.php
r873 r998 5 5 * @author Laurent Jouanneau 6 6 * @contributor Dominique Papin 7 * @copyright 2005-200 6Laurent Jouanneau, 2007 Dominique Papin7 * @copyright 2005-2008 Laurent Jouanneau, 2007 Dominique Papin 8 8 * @link http://www.jelix.org 9 9 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 207 207 #ifnot JTPL_STANDALONE 208 208 $sel = new jSelectorTpl($tpl,$outputtype,$trusted); 209 $sel->userModifiers = $this->userModifiers; 210 $sel->userFunctions = $this->userFunctions; 209 211 jIncluder::inc($sel); 210 212 $fct = $fctname.md5($sel->module.'_'.$sel->resource.'_'.$sel->outputType.($trusted?'_t':'')); … … 225 227 226 228 $compiler = new jTplCompiler(); 229 $compiler->setUserPlugins( $this->userModifiers, $this->userFunctions); 227 230 $compiler->compile($tpl,$outputtype, $trusted); 228 231 } … … 297 300 298 301 302 protected $userModifiers = array(); 303 304 /** 305 * register a user modifier. The function should accept at least a 306 * string as first parameter, and should return this string 307 * which can be modified. 308 * @param string $name the name of the modifier in a template 309 * @param string $functionName the corresponding PHP function 310 * @since jelix 1.1 311 */ 312 public function registerModifier($name, $functionName) { 313 $this->userModifiers[$name] = $functionName; 314 } 315 316 protected $userFunctions = array(); 317 318 /** 319 * register a user function. The function should accept a jTpl object 320 * as first parameter. 321 * @param string $name the name of the modifier in a template 322 * @param string $functionName the corresponding PHP function 323 * @since jelix 1.1 324 */ 325 public function registerFunction($name, $functionName) { 326 $this->userFunctions[$name] = $functionName; 327 } 328 299 329 /** 300 330 * return the current encoding trunk/lib/jelix/tpl/jTplCompiler.class.php
r997 r998 57 57 private $_metaBody = ''; 58 58 59 pr ivate$_modifier = array('upper'=>'strtoupper', 'lower'=>'strtolower',59 protected $_modifier = array('upper'=>'strtoupper', 'lower'=>'strtolower', 60 60 'escxml'=>'htmlspecialchars', 'eschtml'=>'htmlspecialchars', 'strip_tags'=>'strip_tags', 'escurl'=>'rawurlencode', 61 61 'capitalize'=>'ucwords', 'stripslashes'=>'stripslashes' … … 68 68 public $outputType=''; 69 69 public $trusted=true; 70 71 protected $_userFunctions = array(); 70 72 71 73 /** … … 93 95 * @return boolean true if ok 94 96 */ 95 public function compile($tplFile, $outputtype, $trusted ){97 public function compile($tplFile, $outputtype, $trusted, $userModifiers = array(), $userFunctions = array()){ 96 98 $this->_sourceFile = $tplFile; 97 99 $this->outputType = ($outputtype==''?'html':$outputtype); 98 100 $cachefile = JTPL_CACHE_PATH .$this->outputType.($trusted?'_t':'').'_'. basename($tplFile); 99 101 $this->trusted = $trusted; 102 $this->_modifier = array_merge($this->_modifier, $userModifiers); 103 $this->_userFunctions = $userFunctions; 104 100 105 #else 101 106 /** … … 111 116 $this->outputType = $selector->outputType; 112 117 $this->trusted = $selector->trusted; 118 $this->_modifier = array_merge($this->_modifier, $selector->userModifiers); 119 $this->_userFunctions = $selector->userFunctions; 120 113 121 jContext::push($selector->module); 114 122 #endif … … 393 401 $res = $path[1].'( $t'.(trim($argfct)!=''?','.$argfct:'').');'; 394 402 $this->_pluginPath[$path[0]] = true; 403 404 } else if ( isset($this->_userFunctions[$name])) { 405 $argfct=$this->_parseFinal($args,$this->_allowedAssign); 406 $res = $this->_userFunctions[$name].'( $t'.(trim($argfct)!=''?','.$argfct:'').');'; 395 407 396 408 } else { trunk/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php
r958 r998 14 14 class testJtplContentCompiler extends jTplCompiler { 15 15 16 public function compileContent2($content){ 16 public function setUserPlugins($userModifiers, $userFunctions) { 17 $this->_modifier = array_merge($this->_modifier, $userModifiers); 18 $this->_userFunctions = $userFunctions; 19 } 20 21 public function compileContent2($content){ 17 22 return $this->compileContent($content); 18 } 19 } 20 21 23 } 24 } 25 26 function testjtplcontentUserFunction($t,$a,$b) { 27 28 } 22 29 23 30 … … 119 126 '<p>ok<?php if(($t->_vars[\'foo\'] || $t->_vars[\'bar\']) && $t->_vars[\'baz\']):?> <?php endif;?></p>', 120 127 ), 128 19=>array( 129 '<p>ok{bla $foo, $params}</p>', 130 '<p>ok<?php testjtplcontentUserFunction( $t,$t->_vars[\'foo\'], $t->_vars[\'params\']);?></p>', 131 ), 121 132 ); 122 133 … … 125 136 $compil->outputType = 'html'; 126 137 $compil->trusted = true; 127 138 $compil->setUserPlugins(array(), array('bla'=>'testjtplcontentUserFunction')); 128 139 foreach($this->content as $k=>$t){ 129 140 try{ trunk/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php
r997 r998 14 14 class testJtplCompiler extends jTplCompiler { 15 15 16 public function setUserPlugins($userModifiers, $userFunctions) { 17 $this->_modifier = array_merge($this->_modifier, $userModifiers); 18 $this->_userFunctions = $userFunctions; 19 } 20 21 16 22 public function testParseExpr($string, $allowed=array(), $exceptchar=array(';'), $splitArgIntoArray=false){ 17 23 return $this->_parseFinal($string, $allowed, $exceptchar, $splitArgIntoArray); … … 44 50 } 45 51 46 52 function testjtplcontentUserModifier($s){} 47 53 48 54 … … 262 268 '$aaa|jdatetime:\'db_date\',\'lang_date\'' => 'jtpl_modifier_common_jdatetime($t->_vars[\'aaa\'],\'db_date\',\'lang_date\')', 263 269 '$aaa|jdatetime:\'db_:date\',\'lang_date\'' => 'jtpl_modifier_common_jdatetime($t->_vars[\'aaa\'],\'db_:date\',\'lang_date\')', 270 '$aaa|bla'=>'testjtplcontentUserModifier($t->_vars[\'aaa\'])', 264 271 ); 265 272 … … 268 275 $compil = new testJtplCompiler(); 269 276 $compil->trusted = true; 277 $compil->setUserPlugins(array('bla'=>'testjtplcontentUserModifier'),array()); 278 270 279 foreach($this->varTag as $k=>$t){ 271 280 try{
