'star',
'label' => __('Star', 'fluentform'),
],
[
'value' => 'heart',
'label' => __('Heart', 'fluentform'),
],
[
'value' => 'thumb',
'label' => __('Thumb', 'fluentform'),
],
[
'value' => 'smile',
'label' => __('Smile', 'fluentform'),
],
[
'value' => 'bolt',
'label' => __('Bolt', 'fluentform'),
],
];
}
public static function getPresetSvgs()
{
return [
'star' => '',
'heart' => '',
'thumb' => '',
'smile' => '',
'bolt' => '',
];
}
public static function resolveSettings($field)
{
$settings = ArrayHelper::get($field, 'settings');
if (!is_array($settings)) {
$settings = ArrayHelper::get($field, 'raw.settings', []);
}
if (!is_array($settings)) {
$settings = is_array($field) ? $field : [];
}
return [
'icon_source' => static::normalizeIconSource(ArrayHelper::get($settings, 'icon_source')),
'icon_type' => static::normalizeIconType(ArrayHelper::get($settings, 'icon_type')),
'custom_icon_svg' => static::sanitizeCustomSvg(ArrayHelper::get($settings, 'custom_icon_svg')),
'inactive_color' => static::sanitizeColor(ArrayHelper::get($settings, 'inactive_color'), static::DEFAULT_INACTIVE_COLOR),
'active_color' => static::sanitizeColor(ArrayHelper::get($settings, 'active_color'), static::DEFAULT_ACTIVE_COLOR),
];
}
public static function sanitizeColor($color, $fallback = '')
{
$sanitized = sanitize_hex_color((string) $color);
if ($sanitized) {
return $sanitized;
}
return $fallback ? sanitize_hex_color($fallback) : '';
}
public static function normalizeIconSource($iconSource)
{
return sanitize_key($iconSource) === 'custom_svg' ? 'custom_svg' : 'preset';
}
public static function normalizeIconType($iconType)
{
$iconType = sanitize_key($iconType);
$presetSvgs = static::getPresetSvgs();
return isset($presetSvgs[$iconType]) ? $iconType : static::DEFAULT_ICON;
}
public static function sanitizeCustomSvg($svg)
{
if (!is_string($svg)) {
return '';
}
$svg = trim(preg_replace('/<\?xml.*?\?>/i', '', $svg));
if (!$svg || stripos($svg, '