From: Vincent Vanwaelscappel Date: Tue, 19 Nov 2024 14:14:11 +0000 (+0100) Subject: wip #7191 @3.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=df9e42c3d37974b171084d982cc9df724fb34f62;p=spinepro.git wip #7191 @3.5 --- diff --git a/wp-content/mu-plugins/cube/src/Elementor/Widgets/BackgroundImage.php b/wp-content/mu-plugins/cube/src/Elementor/Widgets/BackgroundImage.php index bc5d7e96..71289d95 100644 --- a/wp-content/mu-plugins/cube/src/Elementor/Widgets/BackgroundImage.php +++ b/wp-content/mu-plugins/cube/src/Elementor/Widgets/BackgroundImage.php @@ -7,22 +7,26 @@ use Elementor\Embed; use Elementor\Utils; -class BackgroundImage extends _Base { +class BackgroundImage extends _Base +{ protected $_has_template_content = false; // Tell Elementor that content is all rendered dynamically // Widget name / ID - public function get_name() { + public function get_name() + { return 'cube-bg-image'; } // Elementor widget title - public function get_title() { - return __( 'Flexible Image', 'cube' ); + public function get_title() + { + return __('Flexible Image', 'cube'); } // Elementor interface icon - public function get_icon() { + public function get_icon() + { return 'eicon-image'; } @@ -30,13 +34,15 @@ class BackgroundImage extends _Base { * List of scripts the widget depends on. * Used to set scripts dependencies required to run the widget. * + * @return array Widget scripts dependencies. * @since 1.0.0 * @access public - * @return array Widget scripts dependencies. */ - public function get_script_depends() { + public function get_script_depends() + { return []; } + /** * Register the widget controls. * Adds different input fields to allow the user to change and customize the widget settings. @@ -44,40 +50,41 @@ class BackgroundImage extends _Base { * @since 1.0.0 * @access protected */ - protected function register_controls() { + protected function register_controls() + { $this->start_controls_section( 'section_image', [ - 'label' => __( 'Flexible Background Image', 'cube' ), + 'label' => __('Flexible Background Image', 'cube'), ] ); - + $this->add_control( - 'image', - [ - 'label' => __( 'Choose Image', 'elementor' ), - 'type' => Controls_Manager::MEDIA, - 'default' => [ - 'url' => Utils::get_placeholder_image_src(), - ], - ] - ); + 'image', + [ + 'label' => __('Choose Image', 'elementor'), + 'type' => Controls_Manager::MEDIA, + 'default' => [ + 'url' => Utils::get_placeholder_image_src(), + ], + ] + ); $this->add_control( 'background_position', [ - 'label' => __( 'Background Position', 'cube' ), + 'label' => __('Background Position', 'cube'), 'type' => Controls_Manager::SELECT, 'default' => 'center', 'options' => [ - 'top left' => __( 'Top Left', 'cube' ), - 'top center' => __( 'Top Center', 'cube' ), - 'top right' => __( 'Top Right', 'cube' ), - 'center' => __( 'Center', 'cube' ), - 'bottom left' => __( 'Bottom Left', 'cube' ), - 'bottom center' => __( 'Bottom Center', 'cube' ), - 'bottom right' => __( 'Bottom Right', 'cube' ), + 'top left' => __('Top Left', 'cube'), + 'top center' => __('Top Center', 'cube'), + 'top right' => __('Top Right', 'cube'), + 'center' => __('Center', 'cube'), + 'bottom left' => __('Bottom Left', 'cube'), + 'bottom center' => __('Bottom Center', 'cube'), + 'bottom right' => __('Bottom Right', 'cube'), ], ] ); @@ -94,11 +101,12 @@ class BackgroundImage extends _Base { 'show_external' => true ] ); - + $this->end_controls_section(); $this->common_controls(); } + /** * Render the widget output on the frontend. * Written in PHP and used to generate the final HTML. @@ -106,7 +114,8 @@ class BackgroundImage extends _Base { * @since 1.0.0 * @access protected */ - protected function render() { + protected function render() + { $image = $this->get_settings('image'); $bg_position = $this->get_settings('background_position'); @@ -125,20 +134,43 @@ class BackgroundImage extends _Base { } // Handle links / video - if (!empty( $link['url'])) { + if (!empty($link['url'])) { // If the link is to a youtube video, we want this to open in a lightbox instead // For now only supporting links that start with https://www.youtube.com or https://youtu.be... - if (strpos($link['url'], 'https://www.youtube.com') === 0 || strpos($link['url'], 'https://youtu.be') === 0) { + if (stristr($link['url'], 'mp4')) { + + //{"type":"video","videoType":"hosted","url":"https:\/\/spinepro.dev2.cubedesigners.com\/wp-content\/uploads\/2024\/11\/Spine-Pro-Case-Study-Sonia_compressed1.mp4","autoplay":"","modalOptions":{"id":"elementor-lightbox-77aaa04","entranceAnimation":"","entranceAnimation_tablet":"","entranceAnimation_mobile":"","videoAspectRatio":"169"},"videoParams":{"controls":"","preload":"metadata","controlsList":"nodownload"}} + + $lightbox_options = [ + 'type' => 'video', + 'videoType' => 'hosted', + 'url' => $link['url'], + 'autoplay' => "", + 'modalOptions' => [ + 'id' => 'elementor-lightbox-' . $this->get_id(), + 'entranceAnimation' => 'zoomIn', + 'videoAspectRatio' => '169', + ], + 'videoParams' => + ["controls" => "", + "preload" => "metadata", + "controlsList" => "nodownload"], + + ]; + $attributes = ' data-elementor-lightbox="' . htmlentities(wp_json_encode($lightbox_options)) . '"'; + $attributes .= ' data-elementor-open-lightbox="yes"'; + $class = 'cursor-pointer'; + } else if (strpos($link['url'], 'https://www.youtube.com') === 0 || strpos($link['url'], 'https://youtu.be') === 0) { - $attributes = "data-elementor-lightbox='". $this->lightbox($link['url'], $this->get_id()) ."'"; + $attributes = "data-elementor-lightbox='" . $this->lightbox($link['url'], $this->get_id()) . "'"; $attributes .= ' data-elementor-open-lightbox="yes"'; $class = 'cursor-pointer'; } else { // Normal link $tag = 'a'; - $attributes = 'href="'. $link['url'] .'"'; + $attributes = 'href="' . $link['url'] . '"'; if ($link['is_external']) { $attributes .= ' target="_blank"'; @@ -151,13 +183,14 @@ class BackgroundImage extends _Base { } - echo '<'. $tag .' class="bg-image '. $class .'" '. $attributes .' style="background-image: url('. $image['url'] .'); background-position: '. $bg_position .'">
'; + echo '<' . $tag . ' class="bg-image ' . $class . '" ' . $attributes . ' style="background-image: url(' . $image['url'] . '); background-position: ' . $bg_position . '">
'; } // Generate Elementor lightbox settings - public static function lightbox($url, $element_ID) { + public static function lightbox($url, $element_ID) + { // Video settings for lightbox embed $embed_params = [ @@ -166,12 +199,12 @@ class BackgroundImage extends _Base { ]; $lightbox_options = [ - 'type' => 'video', - 'url' => Embed::get_embed_url($url, $embed_params), + 'type' => 'video', + 'url' => Embed::get_embed_url($url, $embed_params), 'modalOptions' => [ - 'id' => 'elementor-lightbox-' . $element_ID, + 'id' => 'elementor-lightbox-' . $element_ID, 'entranceAnimation' => 'zoomIn', - 'videoAspectRatio' => '169', + 'videoAspectRatio' => '169', ], ];