Changeset 23688 for trunk


Ignore:
Timestamp:
Jun 30, 2013, 7:34:55 AM (11 years ago)
Author:
rvelices
Message:

replace the language_prefilter with a postfilter (now that smarty has modifiercompiler feature, there is no need for prefilter)

File:
1 edited

Legend:

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

    r23588 r23688  
    108108    if ( $conf['compiled_template_cache_language'] )
    109109    {
    110       $this->smarty->registerFilter('pre', array('Template', 'prefilter_language') );
     110      $this->smarty->registerFilter('post', array('Template', 'postfilter_language') );
    111111    }
    112112
     
    529529      else
    530530      {
    531         $ret .= '('.$params[0].')>1';
     531        $ret .= '($tmp=('.$params[0].'))>1';
    532532      }
    533533      $ret .= '?';
     
    535535      $ret .= ':';
    536536      $ret .= self::modcompiler_translate( array($params[1]) );
    537       $ret .= ','.$params[0];
     537      $ret .= ',$tmp';
    538538      $ret .= ')';
    539539      return $ret;
     
    844844
    845845  /**
    846    * Smarty prefilter to allow caching (whenever possible) language strings
    847    * from templates.
    848    */
    849   static function prefilter_language($source, $smarty)
    850   {
    851     global $lang;
    852     $ldq = preg_quote($smarty->left_delimiter, '~');
    853     $rdq = preg_quote($smarty->right_delimiter, '~');
    854 
    855     $regex = "~$ldq\'([^'$]+)\'\|@translate *$rdq~";
    856     $source = preg_replace_callback( $regex, create_function('$m', 'global $lang; return isset($lang[$m[1]]) ? $lang[$m[1]] : $m[0];'), $source);
    857 
     846   * Smarty postfilter
     847   */
     848  static function postfilter_language($source, $smarty)
     849  {
     850    // replaces echo PHP_STRING_LITERAL; with the string literal value
     851    $source = preg_replace_callback(
     852      '/\\<\\?php echo ((?:\'(?:(?:\\\\.)|[^\'])*\')|(?:"(?:(?:\\\\.)|[^"])*"));\\?\\>\\n/',
     853      create_function('$matches', 'eval(\'$tmp=\'.$matches[1].\';\');return $tmp;'),
     854      $source);
    858855    return $source;
    859856  }
Note: See TracChangeset for help on using the changeset viewer.