From 927eb4d85bc26bd4037ca4f1c4cca1426ce35242 Mon Sep 17 00:00:00 2001 From: Milind More Date: Mon, 14 Oct 2024 22:48:01 +0530 Subject: [PATCH 1/2] Refactor CSS for AMP support and fix Vimeo thumbnail fetching - Refactored the CSS in youtubefancybox-amp.css to support AMP pages. Made changes to the background color, box shadow, and border radius of the lightbox. Also added a close button with hover effect. - Updated the Vimeo thumbnail fetching in class-vimeo.php to handle errors. If there is an error in fetching the thumbnail, an error message is displayed instead. - Updated the version number in youtubefancybox.php to 2.6.3 and added support for PHP 8.1. --- css/youtubefancybox-amp.css | 42 ++++++++++++++++++++++++++++++++++++- lib/class-vimeo.php | 26 ++++++++++++++++------- lib/class-youtube.php | 12 ++++++----- youtubefancybox.php | 8 +++---- 4 files changed, 71 insertions(+), 17 deletions(-) diff --git a/css/youtubefancybox-amp.css b/css/youtubefancybox-amp.css index 6001779..1f22cc1 100644 --- a/css/youtubefancybox-amp.css +++ b/css/youtubefancybox-amp.css @@ -2,7 +2,7 @@ * The File contains AMP specific CSS */ .youtubefancybox-amp-lightbox { - background: rgba(0,0,0,0.8); + background: #fff; width: 80%; height: 80%; position: fixed; @@ -11,4 +11,44 @@ justify-content: center; left: 10%; top:10%; + box-shadow: 0 0 10px rgba(0,0,0,0.5); + border-radius: 2px; +} +.youtubefancybox-amp-lightbox-close{ + position: absolute; + bottom: 0; + right: 0; + background: url(images/controls.png) no-repeat -25px 0; + width: 25px; + height: 25px; + text-indent: -9999px; + z-index: 100; + cursor: pointer; +} + +.youtubefancybox-amp-lightbox-close:hover{ + background-color: #bbb; +} + +html[amp] amp-lightbox.ytfancybox-lightbox{ + max-width: 100%; + padding: 0; + margin: 0; + position: relative; + display: inline-block; + width: 100%; + background-color: #070707; + opacity: 1; + background: repeating-linear-gradient( -45deg, #161616, #161616 2px, #070707 2px, #070707 10px ); +} + +@media (min-width: 700px) { + .entry-content > amp-lightbox.alignfull:not(.wp-block-group.has-background) { + margin: 0; + } +} + +amp-youtube, amp-vimeo{ + margin: 25px 10px; + background: #fff; } diff --git a/lib/class-vimeo.php b/lib/class-vimeo.php index 587d002..c630fd1 100644 --- a/lib/class-vimeo.php +++ b/lib/class-vimeo.php @@ -152,7 +152,16 @@ public function vimeofancybox_url( $attr ) { /** * Get thumbnail for vimeo video. */ - $response = wp_remote_get( $embed_image_url ); + $response = wp_remote_get( $embed_image_url ); + + if ( \is_wp_error( $response ) ) { + // Return error messages. + if ( ! empty( $response ) ) { + return '
' . $response->get_error_message() . ''; + } + return '
' . esc_html__( 'Error in fetching Vimeo Video Thumbnail', 'ytubebox' ) . ''; + } + $response_body = wp_remote_retrieve_body( $response ); $obj = json_decode( $response_body ); @@ -163,25 +172,28 @@ public function vimeofancybox_url( $attr ) { } ob_start(); - if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { + if ( function_exists( 'amp_is_request' ) && amp_is_request() ) { $light_box_id = wp_unique_id( 'youtubefancybox-vimeo-lightbox-' ); ?> - +
+ X >
- + - - - +
+ + + +
- +
+ X >
- + +
- + version = '2.6.2'; + $this->version = '2.6.3'; /** * If You are admin you will get admin settings @@ -102,7 +102,7 @@ public function youtubefancybox_adminjs_file( $hook ) { public function youtubefancybox_js_file() { // Iif it's AMP page then We will be using AMP components instead. - if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { + if ( function_exists( 'amp_is_request' ) && amp_is_request() ) { wp_enqueue_style( 'youtubefancybox-amp', plugins_url( 'css/youtubefancybox-amp.css', __FILE__ ), '', $this->version ); return; } From 9d749c4a87b8f916ad3840dab1b11ea65827f590 Mon Sep 17 00:00:00 2001 From: Milind More Date: Mon, 14 Oct 2024 22:48:48 +0530 Subject: [PATCH 2/2] Update version to 2.7.0 --- youtubefancybox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtubefancybox.php b/youtubefancybox.php index 66b5e9c..36368e1 100644 --- a/youtubefancybox.php +++ b/youtubefancybox.php @@ -33,7 +33,7 @@ class Youtubefanybox { */ public function __construct() { - $this->version = '2.6.3'; + $this->version = '2.7.0'; /** * If You are admin you will get admin settings