1: <?php
 2: 
 3: /**
 4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
 5:  */
 6: class Quform_Filter_Regex extends Quform_Filter_Abstract
 7: {
 8:     /**
 9:      * Filter any characters matched by the set regular expression pattern
10:      *
11:      * If the value provided is not a string, the value will remain unfiltered
12:      *
13:      * @param   string  $value  The value to filter
14:      * @return  string          The filtered value
15:      */
16:     public function filter($value)
17:     {
18:         if ( ! is_string($value)) {
19:             return $value;
20:         }
21: 
22:         if (Quform::isNonEmptyString($this->config('pattern'))) {
23:             $value = preg_replace($this->config('pattern'), '', $value);
24:         }
25: 
26:         return $value;
27:     }
28: 
29:     /**
30:      * Get the default config for this filter
31:      *
32:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
33:      * @return  array
34:      */
35:     public static function getDefaultConfig($key = null)
36:     {
37:         $config = apply_filters('quform_default_config_filter_regex', array(
38:             'pattern' => ''
39:         ));
40: 
41:         $config['type'] = 'regex';
42: 
43:         if (Quform::isNonEmptyString($key)) {
44:             return Quform::get($config, $key);
45:         }
46: 
47:         return $config;
48:     }
49: }
50: