Changeset 3928


Ignore:
Timestamp:
Sep 28, 2009, 1:40:38 AM (11 years ago)
Author:
patdenice
Message:

Improve template prefilter functions

File:
1 edited

Legend:

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

    r3927 r3928  
    294294      ((is_adviser()) ? 'disabled="disabled" onclick="return false;"' : ''));
    295295
    296     $this->load_external_filters();
     296    $save_compile_id = $this->smarty->compile_id;
     297    $this->load_external_filters($handle);
    297298
    298299    global $conf, $lang_info;
    299300    if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) )
    300301    {
    301       $save_compile_id = $this->smarty->compile_id;
    302302      $this->smarty->compile_id .= '.'.$lang_info['code'];
    303303    }
     
    305305    $v = $this->smarty->fetch($this->files[$handle], null, null, false);
    306306
    307     if (isset ($save_compile_id) )
    308     {
    309       $this->smarty->compile_id = $save_compile_id;
    310     }
     307    $this->smarty->compile_id = $save_compile_id;
     308    $this->unload_external_filters($handle);
    311309
    312310    if ($return)
     
    432430   * http://www.smarty.net/manual/en/advanced.features.prefilters.php
    433431   */
    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);
     432  function set_external_filter($handle, $callback, $weight=50)
     433  {
     434    if (isset($this->external_filters[$handle][$weight]))
     435    {
     436      foreach($this->external_filters[$handle][$weight] as $func)
     437      {
     438        if ($func == $callback)
     439        {
     440          return false;
     441        }
     442      }
     443    }
     444    $this->external_filters[$handle][$weight][] = $callback;
     445    ksort($this->external_filters[$handle]);
     446    return true;
    440447  }
    441448 
     
    445452   * http://www.smarty.net/manual/en/advanced.features.prefilters.php
    446453   */
    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  
     454  function load_external_filters($handle)
     455  {
     456    if (isset($this->external_filters[$handle]))
     457    {
     458      $compile_id = $this->smarty->compile_id;
     459      foreach ($this->external_filters[$handle] as $callbacks)
     460      {
     461        foreach ($callbacks as $callback)
     462        {
     463          $compile_id .= $callback;
     464          $this->smarty->register_prefilter($callback);
     465        }
     466      }
     467      $this->smarty->compile_id = base_convert(crc32($compile_id), 10, 36);
     468    }
     469  }
     470
     471  function unload_external_filters($handle)
     472  {
     473    if (isset($this->external_filters[$handle]))
     474    {
     475      foreach ($this->external_filters[$handle] as $callbacks)
     476      {
     477        foreach ($callbacks as $callback)
     478        {
     479          $this->smarty->unregister_prefilter($callback);
     480        }
     481      }
     482    }
     483  }
     484
    459485  static function prefilter_white_space($source, &$smarty)
    460486  {
Note: See TracChangeset for help on using the changeset viewer.