Changeset 3426:3dde74bd36ee for inc/public
- Timestamp:
- 11/30/16 09:40:32 (9 years ago)
- Branch:
- Template tags filters
- Location:
- inc/public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/public/class.dc.template.php
r3424 r3426 273 273 } 274 274 275 public function getFilters($attr) 276 { 277 $p[0] = '0'; # encode_xml 278 $p[1] = '0'; # remove_html 279 $p[2] = '0'; # cut_string 280 $p[3] = '0'; # lower_case 281 $p[4] = '0'; # upper_case or capitalize 282 $p[5] = '0'; # encode_url 283 284 $p[0] = (integer) (!empty($attr['encode_xml']) || !empty($attr['encode_html'])); 285 $p[1] = (integer) !empty($attr['remove_html']); 286 287 if (!empty($attr['cut_string']) && (integer) $attr['cut_string'] > 0) { 288 $p[2] = (integer) $attr['cut_string']; 289 } 290 291 $p[3] = (integer) !empty($attr['lower_case']); 292 $p[4] = (integer) !empty($attr['upper_case']); 293 $p[4] = (!empty($attr['capitalize']) ? 2 : $p[4]); 294 $p[5] = (integer) !empty($attr['encode_url']); 295 296 return "context::global_filter(%s,".implode(",",$p).",'".addslashes($this->current_tag)."')"; 275 public function getFilters($attr,$default=array()) 276 { 277 if (!is_array($attr) && !($attr instanceof arrayObject)) { 278 $attr = array(); 279 } 280 281 $p = array_merge( 282 array( 283 0 => null, 284 'encode_xml' => 0, 285 'encode_html' => 0, 286 'cut_string' => 0, 287 'lower_case' => 0, 288 'upper_case' => 0, 289 'encode_url' => 0, 290 'remove_html' => 0, 291 'capitalize' => 0, 292 'strip_tags' => 0 293 ), 294 $default 295 ); 296 297 foreach($attr as $k => $v) { 298 // attributes names must follow this rule 299 $k = preg_filter('/[a-zA-Z0-9_]/','$0',$k); 300 if ($k) { 301 // addslashes protect var_export, str_replace protect sprintf; 302 $p[$k] = str_replace('%','%%',addslashes($v)); 303 } 304 } 305 306 return "context::global_filters(%s,".var_export($p,true).",'".addslashes($this->current_tag)."')"; 297 307 } 298 308 -
inc/public/lib.tpl.context.php
r2863 r3426 103 103 } 104 104 105 # Static methods 105 /** 106 @deprecated since version 2.11 , use tpl_context::global_filters instead 107 */ 106 108 public static function global_filter($str, 107 109 $encode_xml, $remove_html, $cut_string, $lower_case, $upper_case ,$encode_url ,$tag='') 108 110 { 109 $args = func_get_args(); 110 array_pop($args); 111 return $str; 112 } 113 114 public static function global_filters($str,$args,$tag='') 115 { 111 116 $args[0] =& $str; 112 117 … … 114 119 $res = $GLOBALS['core']->callBehavior('publicBeforeContentFilter',$GLOBALS['core'],$tag,$args); 115 120 116 if ($remove_html) { 121 if ($args['strip_tags']) { 122 $str = self::strip_tags($str); 123 } 124 elseif ($args['remove_html']) { 117 125 $str = self::remove_html($str); 118 126 $str = preg_replace('/\s+/',' ',$str); 119 127 } 120 121 if ($encode_xml) { 128 elseif ($args['encode_xml'] || $args['encode_html']) { 122 129 $str = self::encode_xml($str); 123 130 } 124 131 125 if ($ cut_string) {126 $str = self::cut_string($str,(integer) $ cut_string);127 } 128 129 if ($ lower_case) {132 if ($args['cut_string'] > 0) { 133 $str = self::cut_string($str,(integer) $args['cut_string']); 134 } 135 136 if ($args['lower_case']) { 130 137 $str = self::lower_case($str); 131 } elseif ($upper_case) { 132 if ($upper_case == 2) { 133 $str = self::capitalize($str); 134 } else { 135 $str = self::upper_case($str); 136 } 137 } 138 if ($encode_url) { 138 } elseif ($args['capitalize']) { 139 $str = self::capitalize($str); 140 } elseif ($args['upper_case']) { 141 $str = self::upper_case($str); 142 } 143 144 if ($args['encode_url']) { 139 145 $str = self::encode_url($str); 140 146 } … … 164 170 { 165 171 return html::decodeEntities(html::clean($str)); 172 } 173 174 public static function strip_tags($str) 175 { 176 return trim(preg_replace('/ {2,}/',' ',str_replace(array("\r","\n","\t"),' ',html::clean($str)))); 166 177 } 167 178
Note: See TracChangeset
for help on using the changeset viewer.