Plugin Directory

Changeset 2882593


Ignore:
Timestamp:
03/18/2023 02:30:06 PM (3 years ago)
Author:
RAD_
Message:

v1.0.0

Location:
simple-lazy-load-videos/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • simple-lazy-load-videos/trunk/includes/class-actions.php

    r2874846 r2882593  
    1616         */
    1717        public static function activate( $network_wide ) {
    18             $oembed_cache = new SLLV_Oembed_Cache();
    19             $oembed_cache->flush_all();
     18
    2019        }
    2120
     
    2726         */
    2827        public static function deactivate() {
    29             $oembed_cache = new SLLV_Oembed_Cache();
    30             $oembed_cache->flush_all();
     28
    3129        }
    3230
  • simple-lazy-load-videos/trunk/includes/class-functions.php

    r2874846 r2882593  
    1717         * @return object             Remote API as object
    1818         */
    19         public function remote_api_get( $api_url, $expiration = HOUR_IN_SECONDS ) {
     19        public function remote_api_get( $api_url, $expiration = DAY_IN_SECONDS ) {
    2020            $api_url_hash = 'sllv_cache_' . md5( $api_url );
    2121            $cache = get_transient( $api_url_hash );
     
    9696         *
    9797         * @param  string $video_id Vimeo video ID
    98          * @param  string $size     Thumbnail size: thumbnail_small / thumbnail_medium / thumbnail_large
     98         * @param  string $size     Thumbnail size: 640 / 1280
    9999         * @return string           Thumbnail URL
    100100         */
    101         public function get_vimeo_thumb( $video_id, $size = 'thumbnail_large' ) {
     101        public function get_vimeo_thumb( $video_id, $size = '640' ) {
    102102            $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 );
    104104
    105105            return $thumbnail_url;
  • simple-lazy-load-videos/trunk/includes/class-main.php

    r2874846 r2882593  
    3636            new SLLV_Options();
    3737
     38            // Plugin version check & update
    3839            $this->check_version();
     40
     41            // Create plugin options if not exist
    3942            $this->check_options();
    4043
    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 );
    4446
    4547            // Add shortcodes
     
    5153         * Get option name for settings
    5254         *
    53          * @since X.X.X
     55         * @since 0.9.0
    5456         *
    5557         * @return string Option name for settings
     
    6870            $version = get_option( 'sllv_version' );
    6971
     72            // If version changed
    7073            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', '<=' ) ) {
    7179                $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();
    7581            }
    7682        }
     
    8793            }
    8894
     95            // Delete all plugin options (before v0.7.2)
    8996            if ( get_option( 'sllv' ) ) {
    9097                delete_option( 'sllv' );
     
    113120
    114121        /**
    115          * Change video oEmbed
     122         * Change video oEmbed HTML
    116123         *
    117          * @since 0.6.0
     124         * @since 1.0.0
    118125         *
    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
    123131         */
    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();
    126134
    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                }
    131149            }
    132150
    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;
    172152        }
    173153
     
    186166
    187167            ), $atts );
    188             $output = $content;
    189168
    190             $template  = new SLLV_Template();
    191             $functions = new SLLV_Functions();
     169            $template = new SLLV_Template();
    192170
    193             $video_url = $content;
     171            // Get oEmbed HTML from URL
     172            $html = $template->get_html_from_url( array(
     173                'url' => $content,
     174            ) );
    194175
    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;
    214181            }
    215182
  • simple-lazy-load-videos/trunk/includes/class-oembed-cache.php

    r2874846 r2882593  
    99
    1010        /**
    11          * Flush all oembed caches
     11         * Flush all old oembed caches
    1212         *
    13          * @since 0.2.0
     13         * Used if plugin version is 0.9.0 or older
     14         *
     15         * @since 1.0.0
    1416         */
    15         public function flush_all() {
     17        public function flush_old_cache() {
    1618            global $wpdb;
    1719
    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|_%%";
    2023
     24            // Flush common cache
    2125            $wpdb->query(
    2226                $query = $wpdb->prepare(
     
    2832                )
    2933            );
    30         }
    3134
    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
    4336            $wpdb->query(
    4437                $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
    5441                )
    5542            );
  • simple-lazy-load-videos/trunk/includes/class-options.php

    r2874846 r2882593  
    189189            global $sllv;
    190190
    191             $oembed_cache    = new SLLV_Oembed_Cache();
    192             $plugin_settings = $sllv->get_settings();
    193 
    194191            if ( $options ) {
    195192                foreach ( $options as $name => & $value ) {
     
    198195                    }
    199196                }
    200 
    201                 // Flush oembed cache if thumbnails size change
    202                 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                 }
    205197            }
    206198
  • simple-lazy-load-videos/trunk/includes/class-resources.php

    r2874846 r2882593  
    1818            add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
    1919            add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
    20             add_action( 'after_setup_theme', array( $this, 'editor_style' ) );
    2120        }
    2221
     
    5554        }
    5655
    57 
    58         /**
    59          * Editor CSS
    60          *
    61          * @since 0.5.0
    62          */
    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         }
    6856    }
    6957}
  • simple-lazy-load-videos/trunk/includes/class-template.php

    r2874846 r2882593  
    3535         * Get YouTube button
    3636         *
    37          * @since X.X.X
     37         * @since 0.9.0
    3838         *
    3939         * @return string YouTube button SVG
     
    4747         * Get Vimeo button
    4848         *
    49          * @since X.X.X
     49         * @since 0.9.0
    5050         *
    5151         * @return string Vimeo button SVG
     
    5353        public function get_vimeo_button() {
    5454            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;
    55103        }
    56104
  • simple-lazy-load-videos/trunk/readme.txt

    r2880077 r2882593  
    44Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V5Q9SBB54LMDC&source=url
    55Requires at least: 4.9
    6 Tested up to: 6.1.1
     6Tested up to: 6.2
    77Requires PHP: 5.6
    8 Stable tag: 0.9.0
     8Stable tag: 1.0.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141
    4242== 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
    4349= 0.9.0 =
    4450* Stop all other video or HTML media if new video starts playing
  • simple-lazy-load-videos/trunk/simple-lazy-load-videos.php

    r2874846 r2882593  
    44 * Plugin URI:        https://github.com/radkill/simple-lazy-load-videos
    55 * Description:       Simple Lazy Load for embedded video from Youtube and Vimeo
    6  * Version:           0.9.0
    7  * Requires at least: 5.0
     6 * Version:           1.0.0
     7 * Requires at least: 4.9
    88 * Requires PHP:      5.6
    99 * Author:            Valerii Bohdanov
Note: See TracChangeset for help on using the changeset viewer.