| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Helpers; |
| 4 |
|
| 5 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 6 |
|
| 7 |
class Helper |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Sanitize form inputs recursively. |
| 11 |
* |
| 12 |
* @param $input |
| 13 |
* |
| 14 |
* @return string $input |
| 15 |
*/ |
| 16 |
public static function sanitizer($input, $attribute = null, $fields = []) |
| 17 |
{ |
| 18 |
if (is_string($input)) { |
| 19 |
if (ArrayHelper::get($fields, $attribute.'.element') === 'textarea') { |
| 20 |
$input = sanitize_textarea_field($input); |
| 21 |
} else { |
| 22 |
$input = sanitize_text_field($input); |
| 23 |
} |
| 24 |
} elseif (is_array($input)) { |
| 25 |
foreach ($input as $key => &$value) { |
| 26 |
$attribute = $attribute ? $attribute.'['.$key.']' : $key; |
| 27 |
|
| 28 |
$value = Helper::sanitizer($value, $attribute, $fields); |
| 29 |
|
| 30 |
$attribute = null; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
return $input; |
| 35 |
} |
| 36 |
|
| 37 |
public static function makeMenuUrl($page = 'fluent_forms_settings', $component = null) |
| 38 |
{ |
| 39 |
$baseUrl = admin_url('admin.php?page='.$page); |
| 40 |
|
| 41 |
return $component ? $baseUrl.'#'.ArrayHelper::get($component, 'hash', '') : $baseUrl; |
| 42 |
} |
| 43 |
|
| 44 |
public static function getHtmlElementClass($value1, $value2, $class = 'active', $default = '') |
| 45 |
{ |
| 46 |
return $value1 === $value2 ? $class : $default; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Determines if the given string is a valid json. |
| 51 |
* |
| 52 |
* @param $string |
| 53 |
* |
| 54 |
* @return bool |
| 55 |
*/ |
| 56 |
public static function isJson($string) |
| 57 |
{ |
| 58 |
json_decode($string); |
| 59 |
|
| 60 |
|
| 61 |
return json_last_error() === JSON_ERROR_NONE; |
| 62 |
} |
| 63 |
} |