Changeset 3998 for branches/2.0
- Timestamp:
- Oct 9, 2009, 3:00:33 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/include/template.class.php
r3208 r3998 47 47 var $extents = array(); 48 48 49 // Templates prefilter from external sources (plugins) 50 var $external_filters = array(); 51 49 52 // used by html_head smarty block to add content before </head> 50 53 var $html_head_elements = array(); … … 291 294 ((is_adviser()) ? 'disabled="disabled" onclick="return false;"' : '')); 292 295 296 $save_compile_id = $this->smarty->compile_id; 297 $this->load_external_filters($handle); 298 293 299 global $conf, $lang_info; 294 300 if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) ) 295 301 { 296 $save_compile_id = $this->smarty->compile_id;297 302 $this->smarty->compile_id .= '.'.$lang_info['code']; 298 303 } … … 300 305 $v = $this->smarty->fetch($this->files[$handle], null, null, false); 301 306 302 if (isset ($save_compile_id) ) 303 { 304 $this->smarty->compile_id = $save_compile_id; 305 } 307 $this->smarty->compile_id = $save_compile_id; 308 $this->unload_external_filters($handle); 306 309 307 310 if ($return) … … 334 337 $this->html_head_elements = array(); 335 338 } 339 336 340 echo $this->output; 337 341 $this->output=''; … … 420 424 } 421 425 426 /** 427 * This function allows to declare a Smarty prefilter from a plugin, thus allowing 428 * it to modify template source before compilation and without changing core files 429 * They will be processed by weight ascending. 430 * http://www.smarty.net/manual/en/advanced.features.prefilters.php 431 */ 432 function set_prefilter($handle, $callback, $weight=50) 433 { 434 $this->external_filters[$handle][$weight][] = array('prefilter', $callback); 435 ksort($this->external_filters[$handle]); 436 } 437 438 function set_postfilter($handle, $callback, $weight=50) 439 { 440 $this->external_filters[$handle][$weight][] = array('postfilter', $callback); 441 ksort($this->external_filters[$handle]); 442 } 443 444 function set_outputfilter($handle, $callback, $weight=50) 445 { 446 $this->external_filters[$handle][$weight][] = array('outputfilter', $callback); 447 ksort($this->external_filters[$handle]); 448 } 449 450 /** 451 * This function actually triggers the filters on the tpl files. 452 * Called in the parse method. 453 * http://www.smarty.net/manual/en/advanced.features.prefilters.php 454 */ 455 function load_external_filters($handle) 456 { 457 if (isset($this->external_filters[$handle])) 458 { 459 $compile_id = ''; 460 foreach ($this->external_filters[$handle] as $filters) 461 { 462 foreach ($filters as $filter) 463 { 464 list($type, $callback) = $filter; 465 $compile_id .= $type.( is_array($callback) ? implode('', $callback) : $callback ); 466 call_user_func(array($this->smarty, 'register_'.$type), $callback); 467 } 468 } 469 $this->smarty->compile_id .= '.'.base_convert(crc32($compile_id), 10, 36); 470 } 471 } 472 473 function unload_external_filters($handle) 474 { 475 if (isset($this->external_filters[$handle])) 476 { 477 foreach ($this->external_filters[$handle] as $filters) 478 { 479 foreach ($filters as $filter) 480 { 481 list($type, $callback) = $filter; 482 call_user_func(array($this->smarty, 'unregister_'.$type), $callback); 483 } 484 } 485 } 486 } 487 422 488 static function prefilter_white_space($source, &$smarty) 423 489 { … … 465 531 } 466 532 } 533 467 534 468 535 /**
Note: See TracChangeset
for help on using the changeset viewer.