Changeset 2882593
- Timestamp:
- 03/18/2023 02:30:06 PM (3 years ago)
- Location:
- simple-lazy-load-videos/trunk
- Files:
-
- 9 edited
-
includes/class-actions.php (modified) (2 diffs)
-
includes/class-functions.php (modified) (2 diffs)
-
includes/class-main.php (modified) (6 diffs)
-
includes/class-oembed-cache.php (modified) (2 diffs)
-
includes/class-options.php (modified) (2 diffs)
-
includes/class-resources.php (modified) (2 diffs)
-
includes/class-template.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
simple-lazy-load-videos.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
simple-lazy-load-videos/trunk/includes/class-actions.php
r2874846 r2882593 16 16 */ 17 17 public static function activate( $network_wide ) { 18 $oembed_cache = new SLLV_Oembed_Cache(); 19 $oembed_cache->flush_all(); 18 20 19 } 21 20 … … 27 26 */ 28 27 public static function deactivate() { 29 $oembed_cache = new SLLV_Oembed_Cache(); 30 $oembed_cache->flush_all(); 28 31 29 } 32 30 -
simple-lazy-load-videos/trunk/includes/class-functions.php
r2874846 r2882593 17 17 * @return object Remote API as object 18 18 */ 19 public function remote_api_get( $api_url, $expiration = HOUR_IN_SECONDS ) {19 public function remote_api_get( $api_url, $expiration = DAY_IN_SECONDS ) { 20 20 $api_url_hash = 'sllv_cache_' . md5( $api_url ); 21 21 $cache = get_transient( $api_url_hash ); … … 96 96 * 97 97 * @param string $video_id Vimeo video ID 98 * @param string $size Thumbnail size: thumbnail_small / thumbnail_medium / thumbnail_large98 * @param string $size Thumbnail size: 640 / 1280 99 99 * @return string Thumbnail URL 100 100 */ 101 public function get_vimeo_thumb( $video_id, $size = ' thumbnail_large' ) {101 public function get_vimeo_thumb( $video_id, $size = '640' ) { 102 102 $data = $this->remote_api_get( 'https://vimeo.com/api/v2/video/' . $video_id . '.json' ); 103 $thumbnail_url = str_replace( ' http://', 'https://', $data[0]->$size );103 $thumbnail_url = str_replace( '-d_640', '-d_' . $size, $data[0]->thumbnail_large ); 104 104 105 105 return $thumbnail_url; -
simple-lazy-load-videos/trunk/includes/class-main.php
r2874846 r2882593 36 36 new SLLV_Options(); 37 37 38 // Plugin version check & update 38 39 $this->check_version(); 40 41 // Create plugin options if not exist 39 42 $this->check_options(); 40 43 41 // Register hooks 42 add_filter( 'oembed_dataparse', array( $this, 'change_oembed' ), 10, 3 ); 43 add_action( 'save_post', array( $this, 'flush_oembed_cache' ), 10, 3 ); 44 // Change oEmbed HTML after cache by `embed_oembed_html` 45 add_filter( 'embed_oembed_html', array( $this, 'change_oembed_html' ), 10, 4 ); 44 46 45 47 // Add shortcodes … … 51 53 * Get option name for settings 52 54 * 53 * @since X.X.X55 * @since 0.9.0 54 56 * 55 57 * @return string Option name for settings … … 68 70 $version = get_option( 'sllv_version' ); 69 71 72 // If version changed 70 73 if ( ! $version || version_compare( $version, SLLV_VERSION, '!=' ) ) { 74 update_option( 'sllv_version', SLLV_VERSION ); 75 } 76 77 // Flush oEmbed cache if plugin update from version 0.9.0 or older 78 if ( ! $version || version_compare( $version, '0.9.0', '<=' ) ) { 71 79 $oembed_cache = new SLLV_Oembed_Cache(); 72 $oembed_cache->flush_all(); 73 74 update_option( 'sllv_version', SLLV_VERSION ); 80 $oembed_cache->flush_old_cache(); 75 81 } 76 82 } … … 87 93 } 88 94 95 // Delete all plugin options (before v0.7.2) 89 96 if ( get_option( 'sllv' ) ) { 90 97 delete_option( 'sllv' ); … … 113 120 114 121 /** 115 * Change video oEmbed 122 * Change video oEmbed HTML 116 123 * 117 * @since 0.6.0124 * @since 1.0.0 118 125 * 119 * @param string $return The returned oEmbed HTML. 120 * @param object $data A data object result from an oEmbed provider. 121 * @param string $url The URL of the content to be embedded. 122 * @return string The returned oEmbed HTML 126 * @param string|false $cache The cached HTML result, stored in post meta. 127 * @param string $url The attempted embed URL. 128 * @param array $attr An array of shortcode attributes. 129 * @param int $post_ID Post ID. 130 * @return string The returned oEmbed HTML 123 131 */ 124 public function change_oembed ( $return, $data, $url) {125 $template = new SLLV_Template();132 public function change_oembed_html( $cache, $url, $attr, $post_ID ) { 133 $template = new SLLV_Template(); 126 134 127 if ( isset( $data->title ) ) { 128 $video_title = $data->title; 129 } else { 130 $video_title = __( 'Video', 'simple-lazy-load-videos' ); 135 // do replacement only on frontend 136 if ( ! is_admin() ) { 137 // Just some video for test 138 // $url = 'https://youtu.be/D5LF3WChRrA'; 139 140 // Get oEmbed HTML from URL 141 $html = $template->get_html_from_url( array( 142 'url' => $url, 143 ) ); 144 145 // replace default HTML by custom if exist 146 if ( $html ) { 147 $cache = $html; 148 } 131 149 } 132 150 133 if ( 'YouTube' === $data->provider_name ) { 134 preg_match( "/embed\/([-\w]+)/", $data->html, $matches ); 135 $video_id = $matches[1]; 136 137 $return = $template->video( array( 138 'provider' => 'youtube', 139 'title' => $video_title, 140 'id' => $video_id, 141 'url' => 'https://youtu.be/' . $video_id, 142 'thumbnail' => 'https://i.ytimg.com/vi/' . $video_id . '/' . $this->get_settings( 'youtube_thumbnail_size' ) . '.jpg', 143 'play' => $template->get_youtube_button(), 144 ) ); 145 } elseif ( 'Vimeo' === $data->provider_name ) { 146 $return = $template->video( array( 147 'provider' => 'vimeo', 148 'title' => $video_title, 149 'id' => $data->video_id, 150 'url' => 'https://vimeo.com/' . $data->video_id, 151 'thumbnail' => substr( $data->thumbnail_url, 0, -3 ) . $this->get_settings( 'vimeo_thumbnail_size' ), 152 'play' => $template->get_vimeo_button(), 153 ) ); 154 } 155 156 return $return; 157 } 158 159 160 /** 161 * Flush oembed cache 162 * 163 * @since 0.6.0 164 * 165 * @param int $post_ID Post ID. 166 * @param WP_Post $post Post object. 167 * @param bool $update Whether this is an existing post being updated. 168 */ 169 public function flush_oembed_cache( $post_ID, $post, $update ) { 170 $oembed_cache = new SLLV_Oembed_Cache(); 171 $oembed_cache->flush( $post_ID ); 151 return $cache; 172 152 } 173 153 … … 186 166 187 167 ), $atts ); 188 $output = $content;189 168 190 $template = new SLLV_Template(); 191 $functions = new SLLV_Functions(); 169 $template = new SLLV_Template(); 192 170 193 $video_url = $content; 171 // Get oEmbed HTML from URL 172 $html = $template->get_html_from_url( array( 173 'url' => $content, 174 ) ); 194 175 195 $determine_video = $functions->determine_video_url( $video_url ); 196 197 if ( $determine_video['type'] ) { 198 if ( 'youtube' === $determine_video['type'] ) { 199 $thumbnail = $functions->get_youtube_thumb( $determine_video['id'], $this->get_settings( 'youtube_thumbnail_size' ) ); 200 $play = $template->get_youtube_button(); 201 } elseif ( 'vimeo' === $determine_video['type'] ) { 202 $thumbnail = $functions->get_vimeo_thumb( $determine_video['id'] ); 203 $play = $template->get_vimeo_button(); 204 } 205 206 $output = $template->video( array( 207 'provider' => $determine_video['type'], 208 'title' => __( 'Video', 'simple-lazy-load-videos' ), 209 'id' => $determine_video['id'], 210 'url' => $video_url, 211 'thumbnail' => $thumbnail, 212 'play' => $play, 213 ) ); 176 // if oEmbed HTML not exist then show shortcode content 177 if ( $html ) { 178 $output = $html; 179 } else { 180 $output = $content; 214 181 } 215 182 -
simple-lazy-load-videos/trunk/includes/class-oembed-cache.php
r2874846 r2882593 9 9 10 10 /** 11 * Flush all o embed caches11 * Flush all old oembed caches 12 12 * 13 * @since 0.2.0 13 * Used if plugin version is 0.9.0 or older 14 * 15 * @since 1.0.0 14 16 */ 15 public function flush_ all() {17 public function flush_old_cache() { 16 18 global $wpdb; 17 19 18 $meta_key_1 = "|_oembed|_%%"; 19 $meta_key_2 = "|_oembed|_time|_%%"; 20 $meta_key_1 = "|_oembed|_%%"; 21 $meta_key_2 = "|_oembed|_time|_%%"; 22 $option_name = "|_transient_oembed|_%%"; 20 23 24 // Flush common cache 21 25 $wpdb->query( 22 26 $query = $wpdb->prepare( … … 28 32 ) 29 33 ); 30 }31 34 32 /** 33 * Flush oembed cache for single post 34 * 35 * @since 0.2.0 36 */ 37 public function flush( $post_id ) { 38 global $wpdb; 39 40 $meta_key_1 = "|_oembed|_%%"; 41 $meta_key_2 = "|_oembed|_time|_%%"; 42 35 // Flush Gutenberg cache 43 36 $wpdb->query( 44 37 $query = $wpdb->prepare( 45 "DELETE FROM `" . $wpdb->postmeta . "` 46 WHERE post_id = %d 47 AND ( 48 `meta_key` LIKE %s ESCAPE '|' 49 OR `meta_key` LIKE %s ESCAPE '|' 50 )", 51 $post_id, 52 $meta_key_1, 53 $meta_key_2 38 "DELETE FROM `" . $wpdb->options . "` 39 WHERE `option_name` LIKE %s ESCAPE '|'", 40 $option_name 54 41 ) 55 42 ); -
simple-lazy-load-videos/trunk/includes/class-options.php
r2874846 r2882593 189 189 global $sllv; 190 190 191 $oembed_cache = new SLLV_Oembed_Cache();192 $plugin_settings = $sllv->get_settings();193 194 191 if ( $options ) { 195 192 foreach ( $options as $name => & $value ) { … … 198 195 } 199 196 } 200 201 // Flush oembed cache if thumbnails size change202 if ( $options['youtube_thumbnail_size'] != $plugin_settings['youtube_thumbnail_size'] || $options['vimeo_thumbnail_size'] != $plugin_settings['vimeo_thumbnail_size'] ) {203 $oembed_cache->flush_all();204 }205 197 } 206 198 -
simple-lazy-load-videos/trunk/includes/class-resources.php
r2874846 r2882593 18 18 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 19 19 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 20 add_action( 'after_setup_theme', array( $this, 'editor_style' ) );21 20 } 22 21 … … 55 54 } 56 55 57 58 /**59 * Editor CSS60 *61 * @since 0.5.062 */63 public function editor_style() {64 if ( file_exists( SLLV_PATH . 'assets/css/main.min.css' ) ) {65 add_editor_style( SLLV_URL . 'assets/css/main.min.css' );66 }67 }68 56 } 69 57 } -
simple-lazy-load-videos/trunk/includes/class-template.php
r2874846 r2882593 35 35 * Get YouTube button 36 36 * 37 * @since X.X.X37 * @since 0.9.0 38 38 * 39 39 * @return string YouTube button SVG … … 47 47 * Get Vimeo button 48 48 * 49 * @since X.X.X49 * @since 0.9.0 50 50 * 51 51 * @return string Vimeo button SVG … … 53 53 public function get_vimeo_button() { 54 54 return $this->vimeo; 55 } 56 57 58 /** 59 * Get oEmbed HTML from URL 60 * 61 * @since 1.0.0 62 * 63 * @param array $args Arguments 64 * @return string Returned video HTML 65 */ 66 public function get_html_from_url( $args = array() ) { 67 global $sllv; 68 69 $args = wp_parse_args( $args, array( 70 'url' => '', 71 ) ); 72 73 $functions = new SLLV_Functions(); 74 75 $output = false; 76 77 if ( $args['url'] ) { 78 // Determine video from URL 79 $determine_video = $functions->determine_video_url( $args['url'] ); 80 81 // Build HTML if URL is video 82 if ( $determine_video['type'] ) { 83 if ( 'youtube' === $determine_video['type'] ) { 84 $thumbnail = $functions->get_youtube_thumb( $determine_video['id'], $sllv->get_settings( 'youtube_thumbnail_size' ) ); 85 $play = $this->get_youtube_button(); 86 } elseif ( 'vimeo' === $determine_video['type'] ) { 87 $thumbnail = $functions->get_vimeo_thumb( $determine_video['id'], $sllv->get_settings( 'vimeo_thumbnail_size' ) ); 88 $play = $this->get_vimeo_button(); 89 } 90 91 $output = $this->video( array( 92 'provider' => $determine_video['type'], 93 'title' => __( 'Video', 'simple-lazy-load-videos' ), 94 'id' => $determine_video['id'], 95 'url' => $args['url'], 96 'thumbnail' => $thumbnail, 97 'play' => $play, 98 ) ); 99 } 100 } 101 102 return $output; 55 103 } 56 104 -
simple-lazy-load-videos/trunk/readme.txt
r2880077 r2882593 4 4 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V5Q9SBB54LMDC&source=url 5 5 Requires at least: 4.9 6 Tested up to: 6. 1.16 Tested up to: 6.2 7 7 Requires PHP: 5.6 8 Stable tag: 0.9.08 Stable tag: 1.0.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 41 41 42 42 == Changelog == 43 = 1.0.0 = 44 * Add Gutenberg support 45 * New oEmbed template logic 46 * Do template replacement only on frontend 47 * Fix Vimeo thumbnail 48 43 49 = 0.9.0 = 44 50 * Stop all other video or HTML media if new video starts playing -
simple-lazy-load-videos/trunk/simple-lazy-load-videos.php
r2874846 r2882593 4 4 * Plugin URI: https://github.com/radkill/simple-lazy-load-videos 5 5 * Description: Simple Lazy Load for embedded video from Youtube and Vimeo 6 * Version: 0.9.07 * Requires at least: 5.06 * Version: 1.0.0 7 * Requires at least: 4.9 8 8 * Requires PHP: 5.6 9 9 * Author: Valerii Bohdanov
Note: See TracChangeset
for help on using the changeset viewer.