library/smarty/libs/plugins/shared.escape_special_chars.php
changeset 46 f11c31f7fa3e
parent 45 a56e7f9a0463
child 47 03388ec805b4
equal deleted inserted replaced
45:a56e7f9a0463 46:f11c31f7fa3e
     1 <?php
       
     2 /**
       
     3  * Smarty shared plugin
       
     4  *
       
     5  * @package    Smarty
       
     6  * @subpackage PluginsShared
       
     7  */
       
     8 
       
     9 if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
       
    10     /**
       
    11      * escape_special_chars core function
       
    12      * Function: smarty_function_escape_special_chars<br>
       
    13      * Purpose:  used by other smarty functions to escape
       
    14      *           special chars except for already escaped ones
       
    15      *
       
    16      * @author   Monte Ohrt <monte at ohrt dot com>
       
    17      *
       
    18      * @param  string $string text that should by escaped
       
    19      *
       
    20      * @return string
       
    21      */
       
    22     function smarty_function_escape_special_chars($string) {
       
    23         if (!is_array($string)) {
       
    24             $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
       
    25         }
       
    26 
       
    27         return $string;
       
    28     }
       
    29 } else {
       
    30     /**
       
    31      * escape_special_chars core function
       
    32      * Function: smarty_function_escape_special_chars<br>
       
    33      * Purpose:  used by other smarty functions to escape
       
    34      *           special chars except for already escaped ones
       
    35      *
       
    36      * @author   Monte Ohrt <monte at ohrt dot com>
       
    37      *
       
    38      * @param  string $string text that should by escaped
       
    39      *
       
    40      * @return string
       
    41      */
       
    42     function smarty_function_escape_special_chars($string) {
       
    43         if (!is_array($string)) {
       
    44             $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
       
    45             $string = htmlspecialchars($string);
       
    46             $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
       
    47         }
       
    48 
       
    49         return $string;
       
    50     }
       
    51 }