Changeset 23425 for trunk


Ignore:
Timestamp:
Jun 21, 2013, 7:04:57 AM (11 years ago)
Author:
rvelices
Message:

bug 2858: Smarty3 fix php warnings, concat, used modifier on array

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/template/cat_modify.tpl

    r17007 r23425  
    8484    <strong>{'Lock'|@translate}</strong>
    8585    <br>
    86     {html_radios name='visible' values='true,false'|@explode output='No,Yes'|@explode|translate selected=$CAT_VISIBLE}
     86                {html_radios name='visible' values=['true','false'] output=['No'|translate,'Yes'|translate] selected=$CAT_VISIBLE}
    8787  </p>
    8888
     
    9191    <strong>{'Comments'|@translate}</strong>
    9292    <br>
    93     {html_radios name='commentable' values='false,true'|@explode output='No,Yes'|@explode|translate selected=$CAT_COMMENTABLE}
     93                {html_radios name='commentable' values=['false','true'] output=['No'|translate,'Yes'|translate] selected=$CAT_COMMENTABLE}
    9494  </p>
    9595  {/if}
  • trunk/include/template.class.php

    r23384 r23425  
    5959    $this->smarty = new SmartyBC;
    6060    $this->smarty->debugging = $conf['debug_template'];
     61    if (!$this->smarty->debugging)
     62      $this->smarty->error_reporting = error_reporting() & ~E_NOTICE;
    6163    $this->smarty->compile_check = $conf['template_compile_check'];
    6264    $this->smarty->force_compile = $conf['template_force_compile'];
     
    8991
    9092    $this->smarty->assign( 'pwg', new PwgTemplateAdapter() );
    91     $this->smarty->register_modifier( 'translate', array('Template', 'mod_translate') );
    92     $this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') );
    93     $this->smarty->register_modifier( 'get_extent', array(&$this, 'get_extent') );
    94     $this->smarty->register_block('html_head', array(&$this, 'block_html_head') );
    95     $this->smarty->register_block('html_style', array(&$this, 'block_html_style') );
    96     $this->smarty->register_function('combine_script', array(&$this, 'func_combine_script') );
    97     $this->smarty->register_function('get_combined_scripts', array(&$this, 'func_get_combined_scripts') );
    98     $this->smarty->register_function('combine_css', array(&$this, 'func_combine_css') );
    99     $this->smarty->register_function('define_derivative', array(&$this, 'func_define_derivative') );
    100     $this->smarty->register_compiler_function('get_combined_css', array(&$this, 'func_get_combined_css') );
    101     $this->smarty->register_block('footer_script', array(&$this, 'block_footer_script') );
    102     $this->smarty->register_prefilter( array('Template', 'prefilter_white_space') );
     93    $this->smarty->registerPlugin('modifiercompiler', 'translate', array('Template', 'modcompiler_translate') );
     94    $this->smarty->registerPlugin('modifier', 'explode', array('Template', 'mod_explode') );
     95    $this->smarty->registerPlugin( 'modifier', 'get_extent', array($this, 'get_extent') );
     96    $this->smarty->registerPlugin('block', 'html_head', array($this, 'block_html_head') );
     97    $this->smarty->registerPlugin('block', 'html_style', array($this, 'block_html_style') );
     98    $this->smarty->registerPlugin('function', 'combine_script', array($this, 'func_combine_script') );
     99    $this->smarty->registerPlugin('function', 'get_combined_scripts', array($this, 'func_get_combined_scripts') );
     100    $this->smarty->registerPlugin('function', 'combine_css', array($this, 'func_combine_css') );
     101    $this->smarty->registerPlugin('function', 'define_derivative', array($this, 'func_define_derivative') );
     102    $this->smarty->registerPlugin('compiler', 'get_combined_css', array($this, 'func_get_combined_css') );
     103    $this->smarty->registerPlugin('block', 'footer_script', array($this, 'block_footer_script') );
     104    $this->smarty->registerFilter('pre', array('Template', 'prefilter_white_space') );
    103105    if ( $conf['compiled_template_cache_language'] )
    104106    {
    105       $this->smarty->register_prefilter( array('Template', 'prefilter_language') );
     107      $this->smarty->registerFilter('pre', array('Template', 'prefilter_language') );
    106108    }
    107109
     
    170172    if (!isset($this->smarty->compile_id))
    171173    {
    172       $real_dir = realpath($dir);
    173       $compile_id = crc32( $real_dir===false ? $dir : $real_dir);
    174       $this->smarty->compile_id = base_convert($compile_id, 10, 36 );
     174      $compile_id = "1";
     175      $compile_id .= ($real_dir = realpath($dir))===false ? $dir : $real_dir;
     176      $this->smarty->compile_id = base_convert(crc32($compile_id), 10, 36 );
    175177    }
    176178  }
     
    323325  function concat($tpl_var, $value)
    324326  {
    325     $old_val = & $this->smarty->get_template_vars($tpl_var);
    326     if ( isset($old_val) )
    327     {
    328       $old_val .= $value;
    329     }
    330     else
    331     {
    332       $this->assign($tpl_var, $value);
    333     }
     327    $this->assign($tpl_var,
     328      $this->smarty->getTemplateVars($tpl_var) . $value);
    334329  }
    335330
     
    490485  }
    491486
    492   /**
    493    * translate variable modifier - translates a text to the currently loaded
    494    * language
    495    */
    496   static function mod_translate($text)
    497   {
    498     return l10n($text);
     487  static function get_php_str_val($str)
     488  {
     489    if (is_string($str) && strlen($str)>1)
     490    {
     491      if ( ($str[0]=='\'' && $str[strlen($str)-1]=='\'')
     492        || ($str[0]=='"' && $str[strlen($str)-1]=='"'))
     493      {
     494        eval('$tmp='.$str.';');
     495        return $tmp;
     496      }
     497    }
     498    return null;
     499  }
     500
     501  /**
     502   * translate variable modifier - translates a text to the currently loaded language
     503   */
     504  static function modcompiler_translate($params)
     505  {
     506    global $conf, $lang;
     507    if ( $conf['compiled_template_cache_language']
     508      && ($key=self::get_php_str_val($params[0])) !== null)
     509    {
     510      if (isset($lang[$key]))
     511        return var_export($lang[$key], true);
     512    }
     513    return 'l10n('.$params[0].')';
    499514  }
    500515
     
    810825    $rdq = preg_quote($smarty->right_delimiter, '~');
    811826
    812     $regex = "~$ldq *\'([^'$]+)\'\|@translate *$rdq~";
     827    $regex = "~$ldq\'([^'$]+)\'\|@translate *$rdq~";
    813828    $source = preg_replace_callback( $regex, create_function('$m', 'global $lang; return isset($lang[$m[1]]) ? $lang[$m[1]] : $m[0];'), $source);
    814 
    815     $regex = "~$ldq *\'([^'$]+)\'\|@translate\|~";
    816     $source = preg_replace_callback( $regex, create_function('$m', 'global $lang; return isset($lang[$m[1]]) ? \'{\'.var_export($lang[$m[1]],true).\'|\' : $m[0];'), $source);
    817 
    818     $regex = "~($ldq *assign +var=.+ +value=)\'([^'$]+)\'\|@translate~";
    819     $source = preg_replace_callback( $regex, create_function('$m', 'global $lang; return isset($lang[$m[2]]) ? $m[1].var_export($lang[$m[2]],true) : $m[0];'), $source);
    820829
    821830    return $source;
     
    877886    {
    878887      ksort($this->picture_buttons);
    879       $this->assign('PLUGIN_PICTURE_BUTTONS', 
     888      $this->assign('PLUGIN_PICTURE_BUTTONS',
    880889          array_reduce(
    881             $this->picture_buttons, 
    882             create_function('$v,$w', 'return array_merge($v, $w);'), 
     890            $this->picture_buttons,
     891            create_function('$v,$w', 'return array_merge($v, $w);'),
    883892            array()
    884893          ));
     
    891900    {
    892901      ksort($this->index_buttons);
    893       $this->assign('PLUGIN_INDEX_BUTTONS', 
     902      $this->assign('PLUGIN_INDEX_BUTTONS',
    894903          array_reduce(
    895             $this->index_buttons, 
    896             create_function('$v,$w', 'return array_merge($v, $w);'), 
     904            $this->index_buttons,
     905            create_function('$v,$w', 'return array_merge($v, $w);'),
    897906            array()
    898907          ));
Note: See TracChangeset for help on using the changeset viewer.