Dotclear


Ignore:
Timestamp:
08/30/18 11:03:20 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Revamp global_filters() function to take care of 3rd party filters (via new behavior publicContentFilter)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/public/lib.tpl.context.php

    r3830 r3832  
    116116    } 
    117117 
     118    private static function default_filters($filter, $str, $arg) 
     119    { 
     120        switch ($filter) { 
     121            case 'strip_tags': 
     122                return self::strip_tags($str); 
     123 
     124            case 'remove_html': 
     125                return preg_replace('/\s+/', ' ', self::remove_html($str)); 
     126 
     127            case 'encode_xml': 
     128            case 'encode_html': 
     129                return self::encode_xml($str); 
     130 
     131            case 'cut_string': 
     132                return self::cut_string($str, (integer) $arg); 
     133 
     134            case 'lower_case': 
     135                return self::lower_case($str); 
     136 
     137            case 'capitalize': 
     138                return self::capitalize($str); 
     139 
     140            case 'upper_case': 
     141                return self::upper_case($str); 
     142 
     143            case 'encode_url': 
     144                return self::encode_url($str); 
     145        } 
     146        return $str; 
     147    } 
     148 
    118149    public static function global_filters($str, $args, $tag = '') 
    119150    { 
     151        $filters = array( 
     152            'strip_tags',                             // Removes HTML tags (mono line) 
     153            'remove_html',                            // Removes HTML tags 
     154            'encode_xml', 'encode_html',              // Encode HTML entities 
     155            'cut_string',                             // Cut string (length in $args['cut_string']) 
     156            'lower_case', 'capitalize', 'upper_case', // Case transformations 
     157            'encode_url'                             // URL encode (as for insert in query string) 
     158        ); 
     159 
    120160        $args[0] = &$str; 
    121161 
     
    124164        $str = $args[0]; 
    125165 
    126         if ($args['strip_tags']) { 
    127             $str = self::strip_tags($str); 
    128         } 
    129         if ($args['remove_html']) { 
    130             $str = self::remove_html($str); 
    131             $str = preg_replace('/\s+/', ' ', $str); 
    132         } 
    133         if ($args['encode_xml'] || $args['encode_html']) { 
    134             $str = self::encode_xml($str); 
    135         } 
    136  
    137         if ($args['cut_string'] > 0) { 
    138             $str = self::cut_string($str, (integer) $args['cut_string']); 
    139         } 
    140  
    141         if ($args['lower_case']) { 
    142             $str = self::lower_case($str); 
    143         } elseif ($args['capitalize']) { 
    144             $str = self::capitalize($str); 
    145         } elseif ($args['upper_case']) { 
    146             $str = self::upper_case($str); 
    147         } 
    148  
    149         if ($args['encode_url']) { 
    150             $str = self::encode_url($str); 
     166        foreach ($filters as $filter) { 
     167            # --BEHAVIOR-- publicContentFilter 
     168            switch ($GLOBALS['core']->callBehavior('publicContentFilter', $GLOBALS['core'], $tag, $args, $filter)) { 
     169                case '1': 
     170                    // 3rd party filter applied and must stop 
     171                    break; 
     172                case '0': 
     173                default: 
     174                    // 3rd party filter applied and should continue 
     175                    // Apply default filter 
     176                    if ($args[$filter]) { 
     177                        $str = self::default_filters($filter, $str, $args[$filter]); 
     178                    } 
     179            } 
    151180        } 
    152181 
Note: See TracChangeset for help on using the changeset viewer.

Sites map