HEX
Server: LiteSpeed
System: Linux s1.hostssdserver.com 4.18.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User: dreamlan (1220)
PHP: 8.3.32
Disabled: exec,system,passthru,shell_exec,proc_open,popen,apache_child_terminate
Upload Files
File: /home/dreamlan/public_html/wp-content/plugins/html5-video-player/inc/Helper/Block.php
<?php

namespace H5VP\Helper;

if (!defined('ABSPATH'))
    exit; // Exit if accessed directly

class Block
{

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

    public function classic_to_gutenberg_block($id)
    {
        $provider = $this->get_post_meta($id, 'h5vp_video_source', 'self-hosted');
        $block_name = in_array($provider, ['amazons3', 'self-hosted', 'library']) ? 'video' : $provider;
        $width = $this->get_post_meta($id, 'h5vp_player_width_playerio') ? $this->get_post_meta($id, 'h5vp_player_width_playerio') . 'px' : '100%';
        $source = $this->get_post_meta($id, 'h5vp_video_link');
        $option = h5vp_get_option('h5vp_option', []);

        $chapters = $this->get_post_meta($id, 'h5vp_chapters', []);

        if (count($chapters) > 0) {
            foreach ($chapters as $key => $chapter) {
                $chapters[$key]['label'] = $chapter['name'];
                $chapters[$key]['time'] = (int) $chapter['time'];
            }
        }

        if (in_array($provider, ['vimeo', 'youtube'])) {
            $source = $this->get_post_meta($id, 'h5vp_video_link_youtube_vimeo', '');
        }

        return [
            'blockName' => "html5-player/$block_name",
            'attrs' => [
                "provider" => $provider === 'library' ? 'self-hosted' : $provider,
                "imported" => false,
                "clientId" => "",
                "uniqueId" => wp_unique_id('h5vp'),
                "source" => $source,
                "poster" => $this->get_post_meta($id, 'h5vp_video_thumbnails', ''),
                "options" => [
                    "controls" => $this->get_post_meta($id, 'h5vp_controls', ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen']),
                    "settings" => ["captions", "quality", "speed", "loop"],
                    "loadSprite" => true,
                    "autoplay" => $this->get_post_meta($id, 'h5vp_auto_play_playerio', false, true),
                    "playsinline" => true,
                    "seekTime" => (int) $this->get_post_meta($id, 'h5vp_seek_time_playerio', 10),
                    "volume" => 1,
                    "muted" => $this->get_post_meta($id, 'h5vp_muted_playerio', false, true),
                    "hideControls" => $this->get_post_meta($id, 'h5vp_auto_hide_control_playerio', false, true),
                    "resetOnEnd" => $this->get_post_meta($id, 'h5vp_reset_on_end_playerio', false, true),
                    "tooltips" => [
                        "controls" => true,
                        "seek" => true
                    ],
                    "captions" => [
                        "active" => $this->get_post_meta($id, 'h5vp_enable_caption', false, true),
                        "language" => "auto",
                        "update" => true
                    ],
                    "ratio" => $this->get_post_meta($id, 'h5vp_ratio', null),
                    "storage" => [
                        "enabled" => true,
                        "key" => "plyr"
                    ],
                    "speed" => [
                        "options" => explode(',', $option('h5vp_speed', '0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4'))
                    ],
                    "loop" => [
                        "active" => $this->get_post_meta($id, 'h5vp_repeat_playerio', false) === 'loop',
                    ],
                    "ads" => [
                        "enabled" => true,
                        "tagUrl" => $this->get_post_meta($id, 'h5vp_ad_tagUrl'),
                    ],
                    "urls" => [
                        "enabled" => $this->get_post_meta($id, 'isCDURL', false, true),
                        "download" => $this->get_post_meta($id, 'CDURL', null),
                    ],
                    "markers" => [
                        "enabled" => count($chapters) > 0,
                        "points" => $chapters,
                    ],
                    "preload" => $this->get_post_meta($id, 'h5vp_preload_playerio', 'metadata'),
                ],
                "features" => [
                    "popup" => [
                        "enabled" => $this->get_post_meta($id, 'h5vp_popup', false, true),
                        "selector" => null,
                        "hasBtn" => false,
                        "type" => "poster",
                        "btnText" => "Watch Video",
                        "align" => "center",
                        "btnStyle" => [
                            "color" => "#fff",
                            "backgroundColor" => "#006BA1",
                            "fontSize" => "16px",
                            "padding" => [
                                "top" => "10px",
                                "right" => "20px",
                                "bottom" => "10px",
                                "left" => "20px"
                            ]
                        ]
                    ],
                    "overlay" => [
                        "enabled" => $this->get_post_meta($id, 'h5vp_enable_overlay', false, true),
                        "items" => [
                            [
                                "color" => $this->get_post_meta($id, 'h5vp_overlay_text_color', '#ffffff'), // -,
                                "backgroundColor" => $this->get_post_meta($id, 'h5vp_overlay_background', '#333'),
                                "fontSize" => "16px",
                                "link" => $this->get_post_meta($id, 'h5vp_overlay_url', ''),
                                "logo" => $this->get_post_meta($id, 'h5vp_overlay_logo', [])['url'] ?? null, // image url or base64 image pat
                                "text" => $this->get_post_meta($id, 'h5vp_overlay_text', ''),
                                "position" => $this->get_post_meta($id, 'overlay_position', 'top_right'),
                                "type" => $this->get_post_meta($id, 'h5vp_overlay_type', '0', true) ? 'text' : 'logo',
                                "opacity" => $this->get_post_meta($id, 'overlay_opacity', 0.7),
                            ]
                        ]
                    ],
                    "endScreen" => [
                        "enabled" => $this->get_post_meta($id, 'h5vp_endscreen_enable', false, true),
                        "text" => $this->get_post_meta($id, 'h5vp_endscreen_text', 'End Screen Text'),
                        "btnText" => $this->get_post_meta($id, 'endscreen_btn_text', 'Visit'),
                        "btnLink" => $this->get_post_meta($id, 'endscreen_btn_link', ''),
                        "btnStyle" => []
                    ],
                    "thumbInPause" => [
                        "enabled" => $this->get_post_meta($id, 'h5vp_poster_when_pause', false, true),
                        "type" => "default"
                    ],
                    "watermark" => [
                        "enabled" => false,
                        "type" => "email",
                        "text" => "",
                        "color" => "#f00"
                    ],
                    "passwordProtected" => [
                        "enabled" => $this->get_post_meta($id, 'h5vp_password_protected', false, true),
                        "errorMessage" => "Password didn't matched",
                        "heading" => $this->get_post_meta($id, 'h5vp_protected_password_text', "Please Entire the password to access the video"),
                        'key' => "propagans_$id",
                        "button" => [
                            "text" => "Access",
                            "color" => "#222",
                            "backgroundColor" => "#ffffffe3"
                        ]
                    ],
                    "sticky" => [
                        "enabled" => $this->get_post_meta($id, 'h5vp_sticky_mode', false, true),
                        "position" => "top_right"
                    ],
                    "playWhenVisible" => false,
                    "disablePause" => $this->get_post_meta($id, 'h5vp_disable_pause', false, true),
                    "hideYoutubeUI" => $this->get_post_meta($id, 'hideYoutubeUI', false, true),
                    "startTime" => $this->get_post_meta($id, 'h5vp_start_time', 0),
                    "hideLoadingPlaceholder" => false,
                    'customPlayButtonSelector' => $this->get_post_meta($id, 'h5vp_custom_play_button_css_selector', ''),
                ],
                'onlyLoggedIn' => [
                    'whoCanSeeThisVideo' => $this->get_post_meta($id, 'whoo_can_see_this_video', 'everyone'),
                    'allowedRoles' => $this->get_post_meta($id, 'h5vp_allowed_user_roles', []),
                    'message' => $this->get_post_meta($id, 'h5vp_loggedin_user_text', 'This video is only for registered users. Please login to view the video.')
                ],
                'seo' => [
                    'name' => $this->get_post_meta($id, 'h5vp_seo_name', ''),
                    'description' => $this->get_post_meta($id, 'h5vp_seo_description', ''),
                    'duration' => $this->get_post_meta($id, 'h5vp_seo_duration', 0),
                ],
                "quality" => $this->get_post_meta($id, 'h5vp_quality_playerio'),
                "subtitle" => $this->get_post_meta($id, 'h5vp_subtitle_playerio'),
                "thumbInPause" => false,
                "hideYoutubeUI" => $this->get_post_meta($id, 'hideYoutubeUI', false, true),
                "additionalCSS" => "",
                "additionalID" => "",
                "autoplayWhenVisible" => false,
                "styles" => [
                    "plyr_wrapper" => [
                        "width" => $width,
                        "borderRadius" => "0px",
                        "overflow" => "hidden"
                    ]
                ],
                "CSS" => "",
                "ratio" => null,
                "isCDURL" => false,
                "CDURL" => "",
                "posterTime" => 20,
                "brandColor" => "#00B3FF",
                "radius" => [
                    "number" => 0,
                    "unit" => "px"
                ],
                "protected" => false,
                "password" => "",
                "protectedText" => "Please enter password to wath the video",
                "seekTime" => 10,
                "startTime" => 0,
                "preload" => $this->get_post_meta($id, 'h5vp_preload_playerio', 'metadata'),
                "streaming" => false,
                "streamingType" => "hls",
                "captionEnabled" => false,
                "vastTag" => "",
                "saveState" => true
            ],
            "innerBlocks" => [],
            "innerHTML" => "",
            "innerContent" => [],
        ];
    }

    public function video_player_to_gutenberg_block($attrs)
    {

        $quick = h5vp_get_option('h5vp_quick');
        $option = h5vp_get_option('h5vp_option');
        $get_attr = $this->get_attr($attrs);

        $hideYoutubeUI = $get_attr('hide_youtube_ui', $quick('h5vp_hide_youtube_ui', '0'), true);
        $block_name = $get_attr('source', 'library') == 'library' ? 'video' : $get_attr('source', 'library');
        $width = $get_attr('width', $quick('h5vp_player_width_quick') . 'px');

        $code_controls = isset($attrs['controls']) ? explode(',', $get_attr('controls', '')) : null;
        $final_controls = [];

        if (is_array($code_controls)) {
            foreach ($code_controls as $control) {
                array_push($final_controls, trim($control));
            }
        }

        $controls = $final_controls ? $final_controls : Functions::getOptionDeep('h5vp_quick', 'controls', ['play-large', 'play', 'progress', 'duration', 'current-time', 'mute', 'volume', 'settings', 'fullscreen']);

        return [
            'blockName' => "html5-player/$block_name",
            'attrs' => [
                "provider" => $get_attr('source'),
                "uniqueId" => wp_unique_id('h5vp'),
                "source" => $get_attr('file', $get_attr('src', $get_attr('mp4'))),
                "poster" => $get_attr('poster'),
                "options" => [
                    "controls" => $controls,
                    "settings" => ["captions", "quality", "speed", "loop"],
                    "loadSprite" => true,
                    "autoplay" => $get_attr('autoplay', 'false', true),
                    "playsinline" => $get_attr('playsinline', 'true', true),
                    "seekTime" => (int) $get_attr('seek_time', $quick('h5vp_seek_time_quick', 10)),
                    "volume" => 1,
                    "muted" => (bool) $get_attr('muted', $quick('h5vp_muted_quick', '0'), true),
                    "hideControls" => $get_attr('hide_controls', $quick('h5vp_auto_hide_control_quick', '1'), true),
                    "resetOnEnd" => $get_attr('reset_on_end', $quick('h5vp_reset_on_end_quick', '1'), true),
                    "tooltips" => [
                        "controls" => true,
                        "seek" => true
                    ],
                    "captions" => [
                        "active" => false,
                        "language" => "auto",
                        "update" => true
                    ],
                    "ratio" => $attrs['aspect_ratio'] ?? null, // here is the isssue
                    "storage" => [
                        "enabled" => true,
                        "key" => "plyr"
                    ],
                    "speed" => [
                        "options" => explode(',', $option('h5vp_speed', '0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4'))
                    ],
                    "loop" => [
                        "active" => $get_attr('repeat', $quick('h5vp_repeat_quick', '0'), true),
                    ],
                    "ads" => [
                        "enabled" => false,
                        "tagUrl" => '',
                    ],
                    "preload" => $get_attr('preload', $quick('h5vp_preload_quick', 'metadata')),
                    'markers' => [
                        'enabled' => false,
                        'points' => []
                    ],
                    'urls' => [
                        'enabled' => false,
                    ],
                ],
                "features" => [
                    "popup" => [
                        "enabled" => $get_attr('popup', false, true),
                        "type" => $get_attr('popup_type', 'button'),
                        "btnText" => $get_attr('popup_btn_text', 'Watch Video'),
                        "btnStyle" => [
                            "color" => $get_attr('popup_btn_color', '#fff'),
                            "backgroundColor" => $get_attr('popup_btn_bg_color', '#f00'),
                            "padding" => [
                                "top" => '7px',
                                "right" => '10px',
                                "bottom" => '7px',
                                "left" => '10px',
                            ]
                        ]
                    ],
                    "overlay" => [
                        "enabled" => false,
                        "items" => []
                    ],
                    "endScreen" => [
                        "enabled" => false
                    ],
                    "thumbInPause" => [
                        "enabled" => $get_attr('thumb_in_pause', false, true),
                        "type" => "default"
                    ],
                    "watermark" => [
                        "enabled" => $get_attr('watermark', false, true),
                        "type" => $get_attr('watermark_type', 'email'),
                        "text" => $get_attr('watermark_text', 'watermark text'),
                        "color" => $get_attr('watermark_color', '#f00')
                    ],
                    "passwordProtected" => [
                        "enabled" => false,
                    ],
                    "sticky" => [
                        "enabled" => $get_attr('sticky', false, true),
                        "position" => $get_attr('sticky_position', 'top_right')
                    ],
                    "playWhenVisible" => $get_attr('play_when_visible', false, true),
                    "disablePause" => $get_attr('disable_pause', false, true),
                    "hideYoutubeUI" => $hideYoutubeUI,
                    "startTime" => $get_attr('start_time'),
                    "hideLoadingPlaceholder" => $get_attr('hide_loading_placeholder', false, true),
                ],
                'onlyLoggedIn' => [
                    'whoCanSeeThisVideo' => $get_attr('who_can_see_this_video', 'everyone'),
                    'allowedRoles' => explode(',', $get_attr('allowed_roles', '')),
                    'message' => $get_attr('logged_out_user_text', 'This video is only for registered users. Please login to view the video.')
                ],
                "hideYoutubeUI" => $hideYoutubeUI,
                "additionalCSS" => "",
                "additionalID" => $get_attr('additional_id', ''),
                "autoplayWhenVisible" => false,
                "styles" => [
                    "plyr_wrapper" => [
                        'width' => $width ? $width : '100%',
                        "borderRadius" => "0px",
                        "overflow" => "hidden"
                    ]
                ],

            ],

            "innerBlocks" => [],
            "innerHTML" => "",
            "innerContent" => [],
        ];
    }

    function get_post_meta($id, $key, $default = null, $is_boolean = false)
    {
        $meta = get_post_meta($id, $key, true);

        if ($is_boolean) {
            $meta = $meta == '1' ? true : false;
        }
        if ($meta == '') {
            $meta = $default;
        }
        return $meta;
    }

    function get_attr($attrs)
    {
        return function ($key, $default = false, $is_boolean = false) use ($attrs) {
            $value = $attrs[$key] ?? $default;
            if ($is_boolean) {
                // $value can be true or 1 or false or 0
                $value = $value === 'true' || $value === '1' ? true : false;
            }
            return $value;
        };
    }
}