| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\Settings; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use FluentForm\App\Models\FormMeta; |
| 7 |
use FluentForm\App\Helpers\Helper; |
| 8 |
use FluentForm\Framework\Support\Arr; |
| 9 |
|
| 10 |
class Customizer |
| 11 |
{ |
| 12 |
public function get($formId, $metaKeys = ['_custom_form_css', '_custom_form_js']) |
| 13 |
{ |
| 14 |
$result = []; |
| 15 |
|
| 16 |
foreach ($metaKeys as $metaKey) { |
| 17 |
$value = Helper::getFormMeta($formId, $metaKey, ''); |
| 18 |
|
| 19 |
// If the meta doesn't exist or is empty, skip it |
| 20 |
if ($value === '' || $value === null) { |
| 21 |
continue; |
| 22 |
} |
| 23 |
|
| 24 |
if ($metaKey === '_custom_form_css') { |
| 25 |
$result['css'] = $value; |
| 26 |
} elseif ($metaKey === '_ff_selected_style') { |
| 27 |
$result['styler_theme'] = $value; |
| 28 |
} elseif ($metaKey === '_ff_form_styles') { |
| 29 |
$result['styler_styles'] = $value; |
| 30 |
} elseif ($metaKey === '_custom_form_js') { |
| 31 |
$result['js'] = $value; |
| 32 |
} else { |
| 33 |
$result[$metaKey] = $value; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
return $result; |
| 38 |
} |
| 39 |
|
| 40 |
public function store($attributes = []) |
| 41 |
{ |
| 42 |
if (!fluentformCanUnfilteredHTML()) { |
| 43 |
throw new Exception( |
| 44 |
esc_html__('You need unfiltered_html permission to save Custom CSS & JS', 'fluentform') |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
$formId = absint(Arr::get($attributes, 'form_id')); |
| 49 |
|
| 50 |
$css = fluentformSanitizeCSS(Arr::get($attributes, 'css')); |
| 51 |
$js = fluentform_kses_js(Arr::get($attributes, 'js')); |
| 52 |
|
| 53 |
FormMeta::persist($formId, '_custom_form_css', $css); |
| 54 |
FormMeta::persist($formId, '_custom_form_js', $js); |
| 55 |
} |
| 56 |
} |
| 57 |
|