?? GreyFile — Mystic File Browser

Current path: home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Helpers/



?? Go up: /home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server

?? Viewing: VBUtils.php

<?php

namespace KS_PAC_DCFH\Helpers;

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

class VBUtils
{
    private static $_instance;

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

        return self::$_instance;
    }

    public static function get_all_pages(): array
    {
        $pages = wp_list_pluck(get_posts(['post_type' => 'page', 'numberposts' => -1]), 'post_title', 'ID');
        $pages = array_replace(['-1' => __('Please Select A Page', 'divi-contact-form-helper')], $pages);

        return array_map(static function ($page_title) {
            return [
                'label' => $page_title
            ];
        }, $pages);
    }

    public static function get_lanuages(): array
    {
        $langaues = [
            'en' => esc_html('English'),
            'en-GB' => esc_html('English (British)'),
            'ar' => esc_html('Arabic'),
            'az' => esc_html('Azerbaijanian (Azeri)'),
            'bg' => esc_html('Bulgarian'),
            'bs' => esc_html('Bosanski'),
            'ca' => esc_html('Català'),
            'ch' => esc_html('Simplified Chinese'),
            'cs' => esc_html('Čeština'),
            'da' => esc_html('Dansk'),
            'de' => esc_html('German'),
            'el' => esc_html('Ελληνικά'),
            'es' => esc_html('Spanish'),
            'et' => esc_html('Eesti'),
            'eu' => esc_html('Euskara'),
            'fa' => esc_html('Persian'),
            'fi' => esc_html('Finnish (Suomi)'),
            'fr' => esc_html('French'),
            'gl' => esc_html('Galego'),
            'he' => esc_html('Hebrew (עברית)'),
            'hr' => esc_html('Hrvatski'),
            'hu' => esc_html('Hungarian'),
            'id' => esc_html('Indonesian'),
            'it' => esc_html('Italian'),
            'ja' => esc_html('Japanese'),
            'ko' => esc_html('Korean (한국어)'),
            'kr' => esc_html('Korean'),
            'lt' => esc_html('Lithuanian (lietuvių)'),
            'lv' => esc_html('Latvian (Latviešu)'),
            'mk' => esc_html('Macedonian (Македонски)'),
            'mn' => esc_html('Mongolian (Монгол)'),
            'nl' => esc_html('Dutch'),
            'no' => esc_html('Norwegian'),
            'pl' => esc_html('Polish'),
            'pt' => esc_html('Portuguese'),
            'pt-BR' => esc_html('Português(Brasil)'),
            'ro' => esc_html('Romanian'),
            'ru' => esc_html('Russian'),
            'se' => esc_html('Swedish'),
            'sk' => esc_html('Slovenčina'),
            'sl' => esc_html('Slovenščina'),
            'sq' => esc_html('Albanian (Shqip)'),
            'sr' => esc_html('Serbian Cyrillic (Српски)'),
            'sr-YU' => esc_html('Serbian (Srpski)'),
            'sv' => esc_html('Svenska'),
            'th' => esc_html('Thai'),
            'tr' => esc_html('Turkish'),
            'uk' => esc_html('Ukrainian'),
            'vi' => esc_html('Vietnamese'),
            'zh' => esc_html('Simplified Chinese (简体中文)'),
            'zh-TW' => esc_html('Traditional Chinese (繁體中文)'),
        ];

        return array_map(static function ($value) {
            return [
                'label' => $value
            ];
        }, $langaues);
    }

    public static function get_datetime_formats(): array
    {
        $formats = [
            'Y/m/d h:i' => __('Y/m/d h:i (12-Hours Format)', 'divi-contact-form-helper'),
            'Y/m/d h:ia' => __('Y/m/d h:ia (12-Hours Format am or pm)', 'divi-contact-form-helper'),
            'Y-m-d h:i' => __('Y-m-d h:i (12-Hours Format)', 'divi-contact-form-helper'),
            'Y-m-d h:ia' => __('Y-m-d h:ia (12-Hours Format am or pm)', 'divi-contact-form-helper'),
            'Y/m/d H:i' => __('Y/m/d H:i (24-Hours Format)', 'divi-contact-form-helper'),
            'Y/m/d H:ia' => __('Y/m/d H:ia (24-Hours Format am or pm)', 'divi-contact-form-helper'),
            'Y-m-d H:i' => __('Y-m-d H:i (24-Hours Format)', 'divi-contact-form-helper'),
            'Y-m-d H:ia' => __('Y-m-d H:ia (24-Hours Format am or pm)', 'divi-contact-form-helper'),
            'F j, Y h:i' => __('F j, Y h:i (12-Hours Format)', 'divi-contact-form-helper'),
            'F j, Y h:ia' => __('F j, Y h:ia (12-Hours Format am or pm)', 'divi-contact-form-helper'),
            'F j, Y H:i' => __('F j, Y H:i (24-Hours Format)', 'divi-contact-form-helper'),
            'F j, Y H:ia' => __('F j, Y H:ia (24-Hours Format am or pm)', 'divi-contact-form-helper'),
        ];

        return array_map(static function ($value) {
            return [
                'label' => $value
            ];
        }, $formats);
    }

    public static function get_date_formats(): array
    {
        $formats = [
            'Y-m-d' => esc_html('Y-m-d'),
            'Y/m/d' => esc_html('Y/m/d'),
            'F j, Y' => esc_html('F j, Y'),
        ];

        return array_map(static function ($value) {
            return [
                'label' => $value
            ];
        }, $formats);
    }

    public static function get_time_formats(): array
    {
        $formats = [
            'h:i' => __('h:i (12-Hours Format)', 'divi-contact-form-helper'),
            'h:ia' => __('h:ia (12-Hours Format am or pm)', 'divi-contact-form-helper'),
            'H:i' => __('H:i (24-Hours Format)', 'divi-contact-form-helper'),
            'H:ia' => __('H:ia (24-Hours Format am or pm)', 'divi-contact-form-helper'),
        ];

        return array_map(static function ($value) {
            return [
                'label' => $value
            ];
        }, $formats);
    }

    public static function get_week_days($type = 'select'): array
    {
        $days = [
            'sunday' => __('Sunday', 'divi-contact-form-helper'),
            'monday' => __('Monday', 'divi-contact-form-helper'),
            'tuesday' => __('Tuesday', 'divi-contact-form-helper'),
            'wednesday' => __('Wednesday', 'divi-contact-form-helper'),
            'thursday' => __('Thursday', 'divi-contact-form-helper'),
            'friday' => __('Friday', 'divi-contact-form-helper'),
            'saturday' => __('Saturday', 'divi-contact-form-helper'),
        ];
        if ($type === 'select') {
            return array_map(static function ($value) {
                return [
                    'label' => $value
                ];
            }, $days);
        }
        foreach ($days as $key => $value) {
            $options[] = [
                'value' => $key,
                'label' => $value,
            ];
        }

        return $options;
    }

    public static function get_allowed_mimes_types(): array
    {
        $mimes = ks_pac_dcfh_app()->file_utils()::get_wp_allowed_mime_types();
        $customLabels = self::custom_mime_labels();
        $options = [];
        $seen = [];
        foreach ($mimes as /*$extensions => */ $mime) {
            if (in_array($mime, $seen, true)) {
                continue;
            }
            $seen[] = $mime;
            $label = $customLabels[$mime] ?? self::generate_label_from_mime($mime);
            $options[] = [
                'value' => $mime,
                'label' => $label,
            ];
        }

        return $options;

    }

    private static function custom_mime_labels(): array
    {
        return [
            // Images
            'image/jpeg' => 'JPEG Image',
            'image/gif' => 'GIF Image',
            'image/png' => 'PNG Image',
            'image/bmp' => 'Bitmap Image',
            'image/tiff' => 'TIFF Image',
            'image/webp' => 'WebP Image',
            'image/avif' => 'AVIF Image',
            'image/x-icon' => 'Icon File',
            'image/heic' => 'HEIC Image',
            'image/heif' => 'HEIF Image',
            'image/heic-sequence' => 'HEIC Image Sequence',
            'image/heif-sequence' => 'HEIF Image Sequence',
            // Video
            'video/x-ms-asf' => 'ASF Video',
            'video/x-ms-wmv' => 'Windows Media Video (WMV)',
            'video/x-ms-wmx' => 'WMX Video',
            'video/x-ms-wm' => 'WM Video',
            'video/avi' => 'AVI Video',
            'video/divx' => 'DivX Video',
            'video/x-flv' => 'Flash Video (FLV)',
            'video/quicktime' => 'QuickTime Video (MOV)',
            'video/mpeg' => 'MPEG Video',
            'video/mp4' => 'MP4 Video',
            'video/ogg' => 'Ogg Video',
            'video/webm' => 'WebM Video',
            'video/x-matroska' => 'Matroska Video (MKV)',
            'video/3gpp' => '3GPP Video',
            'video/3gpp2' => '3GPP2 Video',
            // Text
            'text/plain' => 'Plain Text File',
            'text/csv' => 'CSV (Comma-separated Values)',
            'text/tab-separated-values' => 'TSV (Tab-separated Values)',
            'text/calendar' => 'iCalendar File',
            'text/richtext' => 'Rich Text File',
            'text/css' => 'Cascading Style Sheet (CSS)',
            'text/html' => 'HTML Document',
            'text/vtt' => 'WebVTT Subtitle File',
            'application/ttaf+xml' => 'DFXP Subtitle File',
            // Audio
            'audio/mpeg' => 'MP3 Audio',
            'audio/aac' => 'AAC Audio',
            'audio/x-realaudio' => 'RealAudio File',
            'audio/wav' => 'WAV Audio',
            'audio/ogg' => 'Ogg Audio',
            'audio/flac' => 'FLAC Audio',
            'audio/midi' => 'MIDI File',
            'audio/x-ms-wma' => 'Windows Media Audio (WMA)',
            'audio/x-ms-wax' => 'WAX Audio',
            'audio/x-matroska' => 'Matroska Audio (MKA)',
            // Documents
            'application/rtf' => 'Rich Text Format (RTF)',
            'application/javascript' => 'JavaScript File',
            'application/pdf' => 'PDF Document',
            'application/java' => 'Java Class File',
            // Archives
            'application/x-tar' => 'TAR Archive',
            'application/zip' => 'ZIP Archive',
            'application/x-gzip' => 'GZIP Archive',
            'application/rar' => 'RAR Archive',
            'application/x-7z-compressed' => '7-Zip Archive',
            // Graphics
            'application/octet-stream' => 'Binary File (e.g., PSD, XCF)',
            // Microsoft formats
            'application/msword' => 'Microsoft Word Document',
            'application/vnd.ms-powerpoint' => 'Microsoft PowerPoint Document',
            'application/vnd.ms-write' => 'Microsoft Write Document',
            'application/vnd.ms-excel' => 'Microsoft Excel Spreadsheet',
            'application/vnd.ms-access' => 'Microsoft Access Database',
            'application/vnd.ms-project' => 'Microsoft Project File',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'Microsoft Word Document (DOCX)',
            'application/vnd.ms-word.document.macroEnabled.12' => 'Microsoft Word Macro-Enabled Document',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'Microsoft Word Template (DOTX)',
            'application/vnd.ms-word.template.macroEnabled.12' => 'Microsoft Word Macro-Enabled Template',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'Microsoft Excel Spreadsheet (XLSX)',
            'application/vnd.ms-excel.sheet.macroEnabled.12' => 'Microsoft Excel Macro-Enabled Spreadsheet',
            'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'Microsoft Excel Binary Spreadsheet',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'Microsoft Excel Template (XLTX)',
            'application/vnd.ms-excel.template.macroEnabled.12' => 'Microsoft Excel Macro-Enabled Template',
            'application/vnd.ms-excel.addin.macroEnabled.12' => 'Microsoft Excel Add-in',
            'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'Microsoft PowerPoint Presentation (PPTX)',
            'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'Microsoft PowerPoint Macro-Enabled Presentation',
            'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'Microsoft PowerPoint Slideshow (PPSX)',
            'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'Microsoft PowerPoint Macro-Enabled Slideshow',
            'application/vnd.openxmlformats-officedocument.presentationml.template' => 'Microsoft PowerPoint Template (POTX)',
            'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'Microsoft PowerPoint Macro-Enabled Template',
            'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'Microsoft PowerPoint Add-in',
            'application/vnd.openxmlformats-officedocument.presentationml.slide' => 'Microsoft PowerPoint Slide (SLDX)',
            'application/vnd.ms-powerpoint.slide.macroEnabled.12' => 'Microsoft PowerPoint Macro-Enabled Slide',
            // OneNote, XPS, etc.
            'application/onenote' => 'Microsoft OneNote Document',
            'application/oxps' => 'OpenXPS Document',
            'application/vnd.ms-xpsdocument' => 'Microsoft XPS Document',
            // OpenDocument formats
            'application/vnd.oasis.opendocument.text' => 'OpenDocument Text (ODT)',
            'application/vnd.oasis.opendocument.presentation' => 'OpenDocument Presentation (ODP)',
            'application/vnd.oasis.opendocument.spreadsheet' => 'OpenDocument Spreadsheet (ODS)',
            'application/vnd.oasis.opendocument.graphics' => 'OpenDocument Drawing (ODG)',
            'application/vnd.oasis.opendocument.chart' => 'OpenDocument Chart (ODC)',
            'application/vnd.oasis.opendocument.database' => 'OpenDocument Database (ODB)',
            'application/vnd.oasis.opendocument.formula' => 'OpenDocument Formula (ODF)',
            // Other document formats
            'application/wordperfect' => 'WordPerfect Document',
            'application/vnd.apple.keynote' => 'Apple Keynote Presentation',
            'application/vnd.apple.numbers' => 'Apple Numbers Spreadsheet',
            'application/vnd.apple.pages' => 'Apple Pages Document',
        ];
    }

    private static function generate_label_from_mime(string $mime): string
    {
        [$type, $subtype] = explode('/', $mime);
        $subtype = preg_replace('/^x-/', '', $subtype); // remove 'x-' prefix
        $subtype = str_replace(['-', '+'], [' ', ' '], $subtype);
        $subtype = ucwords($subtype);

        return strtoupper($subtype)." ".ucfirst($type);
    }
}



??

??