Ignore:
Timestamp:
09/27/09 22:47:24 (10 years ago)
Author:
mathiasm
Message:

Add Smarty's prefilter capability. see topic:16219 (FR).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/template.class.php

    r3282 r3927  
    4747  var $extents = array(); 
    4848 
     49  // Templates prefilter from external sources (plugins) 
     50  var $external_filters = array(); 
     51   
    4952  // used by html_head smarty block to add content before </head> 
    5053  var $html_head_elements = array(); 
     
    291294      ((is_adviser()) ? 'disabled="disabled" onclick="return false;"' : '')); 
    292295 
     296    $this->load_external_filters(); 
     297 
    293298    global $conf, $lang_info; 
    294299    if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) ) 
     
    334339      $this->html_head_elements = array(); 
    335340    } 
     341 
    336342    echo $this->output; 
    337343    $this->output=''; 
     
    420426  } 
    421427 
     428 /** 
     429   * This function allows to declare a Smarty prefilter from a plugin, thus allowing 
     430   * it to modify template source before compilation and without changing core files 
     431   * They will be processed by weight ascending. 
     432   * http://www.smarty.net/manual/en/advanced.features.prefilters.php 
     433   */ 
     434  function set_external_filter($weight, $callback)  
     435  { 
     436   
     437    if (! is_integer($weight)) return false; 
     438    $this->external_filters[$weight] = $callback; 
     439    return ksort($this->external_filters); 
     440  } 
     441   
     442 /** 
     443   * This function actually triggers the filters on the tpl files. 
     444   * Called in the parse method. 
     445   * http://www.smarty.net/manual/en/advanced.features.prefilters.php 
     446   */ 
     447  function load_external_filters()  
     448  { 
     449    if (! isset($this->external_filters) || ! count($this->external_filters)) return;   
     450    print_r($this->external_filters ); 
     451    $test= array(1,2,3); 
     452    print_r($test); 
     453    foreach ($this->external_filters as $filter)  
     454    { 
     455      $this->smarty->register_prefilter( $filter );      
     456    } 
     457  } 
     458   
    422459  static function prefilter_white_space($source, &$smarty) 
    423460  { 
     
    465502  } 
    466503} 
     504 
    467505 
    468506/** 
Note: See TracChangeset for help on using the changeset viewer.