?? GreyFile — Mystic File Browser

Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Helpers/



?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app

?? Viewing: Module_Helpers.php

<?php

namespace KS_PAC_DCFH\Helpers;

if (!defined('ABSPATH')) {
    exit;
}

class Module_Helpers
{
    private static $_instance;

    public static function instance(): self
    {
        if (self::$_instance === null) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public static function get_shadow_presets_values($preset = null): array
    {
        $presets = [
            'none' => [
                'horizontal' => '',
                'vertical' => '',
                'blur' => '',
                'spread' => '',
                'position' => '',
            ],
            'preset1' => [
                'horizontal' => '0px',
                'vertical' => '2px',
                'blur' => '18px',
                'spread' => '0px',
                'position' => '',
            ],
            'preset2' => [
                'horizontal' => '6px',
                'vertical' => '6px',
                'blur' => '18px',
                'spread' => '0px',
                'position' => '',
            ],
            'preset3' => [
                'horizontal' => '0px',
                'vertical' => '12px',
                'blur' => '18px',
                'spread' => '-6px',
                'position' => '',
            ],
            'preset4' => [
                'horizontal' => '10px',
                'vertical' => '10px',
                'blur' => '0px',
                'spread' => '0px',
                'position' => '',
            ],
            'preset5' => [
                'horizontal' => '0px',
                'vertical' => '6px',
                'blur' => '0px',
                'spread' => '10px',
                'position' => '',
            ],
            'preset6' => [
                'horizontal' => '0px',
                'vertical' => '0px',
                'blur' => '18px',
                'spread' => '0px',
                'position' => 'inset',
            ],
            'preset7' => [
                'horizontal' => '10px',
                'vertical' => '10px',
                'blur' => '0px',
                'spread' => '0px',
                'position' => 'inset',
            ],
        ];
        if (!empty($preset) && isset($presets[$preset])) {
            return $presets[$preset];
        }

        return $presets;
    }

    public static function get_shadow_presets($prefix): array
    {
        $options = [];
        foreach (self::get_shadow_presets_values() as $key => $value) {
            if ('none' === $key) {
                $options[] = [
                    'value' => $key,
                    'icon' => $key,
                    'fields' => [
                        $prefix.'_shadow_horizontal' => '0',
                        $prefix.'_shadow_vertical' => '0',
                        $prefix.'_shadow_blur' => '0',
                        $prefix.'_shadow_spread' => '0',
                        $prefix.'_shadow_position' => '',
                    ]
                ];
            } else {
                $options[] = [
                    'value' => $key,
                    'content' => sprintf('<span class="preset %1$s"></span>', esc_attr($key)),
                    'fields' => [
                        $prefix.'_shadow_horizontal' => $value["horizontal"],
                        $prefix.'_shadow_vertical' => $value["vertical"],
                        $prefix.'_shadow_blur' => $value["blur"],
                        $prefix.'_shadow_spread' => $value["spread"],
                        $prefix.'_shadow_position' => $value["position"],
                    ]
                ];
            }
        }

        return $options;
    }

    public static function get_responsive_margin_padding_border_props($props, $top = '0', $right = '0', $bottom = '0', $left = '0'): array
    {
        $responsive_props = ['desktop' => '', 'tablet' => '', 'phone' => ''];
        $default_values = [0 => $top, 1 => $right, 2 => $bottom, 3 => $left];
        foreach ($props as $device => $prop) {
            if (!empty($prop)) {
                $prop_array = explode('|', $prop);
                foreach ($prop_array as $key => $value) {
                    if (!in_array($value, ['true', 'false', 'on', 'off'])) {
                        $prop_array[$key] = !empty($value) ? $value : ($default_values[$key] ?? 0);
                    } else {
                        unset($prop_array[$key]);
                    }
                }
                $responsive_props[$device] = implode(' ', $prop_array);
            } else {
                $responsive_props[$device] = '';
            }
        }

        return $responsive_props;
    }

    public static function get_responsive_props($props, $slug, $default = '', $copy = false)
    {
        $responsive_prop = [];
        $responsive_enabled = isset($props["{$slug}_last_edited"]) && et_pb_get_responsive_status($props["{$slug}_last_edited"]);
        if (!isset($props[$slug]) || '' === $props[$slug]) {
            $responsive_prop['desktop'] = $default;
        } else {
            $responsive_prop['desktop'] = $props[$slug];
        }
        if (!$responsive_enabled || !isset($props["{$slug}_tablet"]) || '' === $props["{$slug}_tablet"]) {
            $responsive_prop['tablet'] = $copy ? $responsive_prop['desktop'] : $default;
        } else {
            $responsive_prop['tablet'] = $props["{$slug}_tablet"];
        }
        if (!$responsive_enabled || !isset($props["{$slug}_phone"]) || '' === $props["{$slug}_phone"]) {
            $responsive_prop['phone'] = $copy ? $responsive_prop['tablet'] : $default;
        } else {
            $responsive_prop['phone'] = $props["{$slug}_phone"];
        }

        return str_replace(['|', 'on|', 'off|'], '', $responsive_prop);
    }

    public static function process_multiple_mimes_checkboxes_value($data): array
    {
        $allowed_mime_types = ks_pac_dcfh_wp_helper()::get_wp_allowed_mime_types();
        $mimes = array_keys($allowed_mime_types);
        $mime_values = [];
        $mime_keys = [];
        $data = explode('|', $data);
        foreach ($data as $key => $val) {
            if (isset($mimes[$key], $allowed_mime_types[$mimes[$key]]) && 'on' === strtolower($val)) {
                // array_push($mime_values, ' '.str_replace("|", ', ', $mimes[$key]));
                // array_push($mime_keys, $allowed_mime_types[$mimes[$key]]);
                $mime_values[] = ' '.str_replace("|", ', ', $mimes[$key]);
                $mime_keys[] = $allowed_mime_types[$mimes[$key]];
            }
        }

        return ['keys' => implode(',', $mime_keys), 'values' => implode(',', $mime_values)];
    }

    public static function process_multiple_checkboxes_value($checkboxes, $array_to_match): string
    {
        $processed_data = [];
        $checkboxes = explode('|', $checkboxes);
        foreach ($checkboxes as $key => $val) {
            if (isset($array_to_match[$key]) && 'on' === strtolower($val)) {
                $processed_data[] = $array_to_match[$key];
            }
        }

        return implode(',', $processed_data);
    }

    public static function get_mimes_with_ext(): array
    {
        $allowed_mime_types = ks_pac_dcfh_wp_helper()::get_wp_allowed_mime_types();
        $mimes = array_combine(
            array_map(static function ($key) {
                return '.'.$key;
            }, array_keys($allowed_mime_types)),
            $allowed_mime_types
        );

        return array_keys($mimes);
    }

    public static function get_week_day_names(): array
    {
        return [
            0 => __('Sunday', 'divi-contact-form-helper'),
            1 => __('Monday', 'divi-contact-form-helper'),
            2 => __('Tuesday', 'divi-contact-form-helper'),
            3 => __('Wednesday', 'divi-contact-form-helper'),
            4 => __('Thursday', 'divi-contact-form-helper'),
            5 => __('Friday', 'divi-contact-form-helper'),
            6 => __('Saturday', 'divi-contact-form-helper'),
        ];
    }

    public static function get_flex_alignment($alignment): array
    {
        $default = '';

        return array_map(
            static function ($v) use (&$default) {
                if (empty($v)) {
                    $v = $default;
                }
                $default = $v;
                if ($v === 'center') {
                    $v = 'center';
                } elseif ($v === 'right') {
                    $v = 'flex-end';
                } else {
                    $v = 'flex-start';
                }

                return $v;
            },
            $alignment
        );
    }

    public static function get_flex_column($column): array
    {
        return array_map(static function ($v) {
            $v = (int)$v;
            switch ($v) {
                case 2:
                    return '50%';
                case 3:
                    return '33%';
                case 4:
                    return '25%';
                default:
                    return '100%';
            }
        }, $column);
    }

    public static function max_number_files_allowed()
    {
        return ini_get('max_file_uploads');
    }

    public static function justified_to_justify($array): array
    {
        return array_map(static function ($value) {
            if ('justified' === strtolower($value)) {
                return 'justify';
            }

            return $value;
        }, $array);
    }

    public static function get_global_color($devices): array
    {
        $global_colors = [];
        foreach ($devices as $device => $value) {
            if (!empty($value)) {
                if (strpos($value, 'gcid-') !== false) {
                    $global_color_info = et_builder_get_global_color_info($value);
                    $global_colors[$device] = esc_attr($global_color_info['color']);
                } else {
                    $global_colors[$device] = $value;
                }
            }

        }

        return $global_colors;
    }
}


??

??