Changeset 2080878
- Timestamp:
- 05/05/2019 02:35:18 PM (7 years ago)
- Location:
- simple-youtube-gdpr
- Files:
-
- 35 added
- 4 deleted
- 10 edited
-
tags/0.5/.gitattributes (deleted)
-
tags/0.5/.idea (deleted)
-
tags/0.6 (added)
-
tags/0.6/.gitattributes (added)
-
tags/0.6/LICENSE.txt (added)
-
tags/0.6/README.txt (added)
-
tags/0.6/includes (added)
-
tags/0.6/includes/class-simple-youtube-gdpr-activator.php (added)
-
tags/0.6/includes/class-simple-youtube-gdpr-deactivator.php (added)
-
tags/0.6/includes/class-simple-youtube-gdpr-i18n.php (added)
-
tags/0.6/includes/class-simple-youtube-gdpr-loader.php (added)
-
tags/0.6/includes/class-simple-youtube-gdpr.php (added)
-
tags/0.6/includes/index.php (added)
-
tags/0.6/includes/simple_html_dom.php (added)
-
tags/0.6/index.php (added)
-
tags/0.6/languages (added)
-
tags/0.6/languages/simple-youtube-gdpr-de_DE.mo (added)
-
tags/0.6/languages/simple-youtube-gdpr-de_DE.po (added)
-
tags/0.6/languages/simple-youtube-gdpr-en_US.mo (added)
-
tags/0.6/languages/simple-youtube-gdpr-en_US.po (added)
-
tags/0.6/languages/simple-youtube-gdpr-ru_RU.mo (added)
-
tags/0.6/languages/simple-youtube-gdpr-ru_RU.po (added)
-
tags/0.6/languages/simple-youtube-gdpr.pot (added)
-
tags/0.6/public (added)
-
tags/0.6/public/class-simple-youtube-gdpr-public.php (added)
-
tags/0.6/public/css (added)
-
tags/0.6/public/css/simple-youtube-gdpr-public.css (added)
-
tags/0.6/public/img (added)
-
tags/0.6/public/img/youtube.png (added)
-
tags/0.6/public/index.php (added)
-
tags/0.6/public/js (added)
-
tags/0.6/public/js/simple-youtube-gdpr-public.js (added)
-
tags/0.6/public/partials (added)
-
tags/0.6/public/partials/simple-youtube-gdpr-public-display.php (added)
-
tags/0.6/simple-youtube-gdpr.php (added)
-
tags/0.6/uninstall.php (added)
-
trunk/.gitattributes (deleted)
-
trunk/.idea (deleted)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/includes/class-simple-youtube-gdpr-activator.php (modified) (3 diffs)
-
trunk/includes/class-simple-youtube-gdpr-deactivator.php (modified) (3 diffs)
-
trunk/includes/class-simple-youtube-gdpr-i18n.php (modified) (3 diffs)
-
trunk/includes/class-simple-youtube-gdpr-loader.php (modified) (8 diffs)
-
trunk/includes/class-simple-youtube-gdpr.php (modified) (16 diffs)
-
trunk/includes/simple_html_dom.php (added)
-
trunk/public/class-simple-youtube-gdpr-public.php (modified) (10 diffs)
-
trunk/public/partials/simple-youtube-gdpr-public-display.php (modified) (1 diff)
-
trunk/simple-youtube-gdpr.php (modified) (4 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
simple-youtube-gdpr/trunk/README.txt
r2072368 r2080878 5 5 Requires at least: 5.0.1 6 6 Tested up to: 5.1.1 7 Stable tag: 0. 57 Stable tag: 0.6 8 8 Requires PHP: 5.2.4 9 9 License: GPLv2 or later … … 64 64 1. Replace an iframe with a picture 65 65 1. Apply scripts so that if user clicks iframe appears 66 67 == Changelog == 68 69 = 0.6 = 70 * Added Simple HTML DOM lib to run through DOM easily 71 * Removed lot's of code afterwards 72 * Now the whole figure is replaced with div with image (not just iframe. It caused troubles) 73 74 == Upgrade Notice == 75 76 = 0.6 = 77 Twenty Nineteen theme bug fixed. It replace the whole WordPress <figure> tag with an image. -
simple-youtube-gdpr/trunk/includes/class-simple-youtube-gdpr-activator.php
r2072368 r2080878 5 5 * 6 6 * @link https://alexeyvolkov.com/ 7 * @since 0. 5.07 * @since 0.6 8 8 * 9 9 * @package Simple_Youtube_Gdpr … … 16 16 * This class defines all code necessary to run during the plugin's activation. 17 17 * 18 * @since 0. 5.018 * @since 0.6 19 19 * @package Simple_Youtube_Gdpr 20 20 * @subpackage Simple_Youtube_Gdpr/includes … … 28 28 * Long Description. 29 29 * 30 * @since 0. 5.030 * @since 0.6 31 31 */ 32 32 public static function activate() { -
simple-youtube-gdpr/trunk/includes/class-simple-youtube-gdpr-deactivator.php
r2072368 r2080878 5 5 * 6 6 * @link https://alexeyvolkov.com/ 7 * @since 0. 5.07 * @since 0.6 8 8 * 9 9 * @package Simple_Youtube_Gdpr … … 16 16 * This class defines all code necessary to run during the plugin's deactivation. 17 17 * 18 * @since 0. 5.018 * @since 0.6 19 19 * @package Simple_Youtube_Gdpr 20 20 * @subpackage Simple_Youtube_Gdpr/includes … … 28 28 * Long Description. 29 29 * 30 * @since 0. 5.030 * @since 0.6 31 31 */ 32 32 public static function deactivate() { -
simple-youtube-gdpr/trunk/includes/class-simple-youtube-gdpr-i18n.php
r2072368 r2080878 8 8 * 9 9 * @link https://alexeyvolkov.com/ 10 * @since 0. 5.010 * @since 0.6 11 11 * 12 12 * @package Simple_Youtube_Gdpr … … 20 20 * so that it is ready for translation. 21 21 * 22 * @since 0. 5.022 * @since 0.6 23 23 * @package Simple_Youtube_Gdpr 24 24 * @subpackage Simple_Youtube_Gdpr/includes … … 31 31 * Load the plugin text domain for translation. 32 32 * 33 * @since 0. 5.033 * @since 0.6 34 34 */ 35 35 public function load_plugin_textdomain() { -
simple-youtube-gdpr/trunk/includes/class-simple-youtube-gdpr-loader.php
r2072368 r2080878 5 5 * 6 6 * @link https://alexeyvolkov.com/ 7 * @since 0. 5.07 * @since 0.6 8 8 * 9 9 * @package Simple_Youtube_Gdpr … … 27 27 * The array of actions registered with WordPress. 28 28 * 29 * @since 0. 5.029 * @since 0.6 30 30 * @access protected 31 31 * @var array $actions The actions registered with WordPress to fire when the plugin loads. … … 36 36 * The array of filters registered with WordPress. 37 37 * 38 * @since 0. 5.038 * @since 0.6 39 39 * @access protected 40 40 * @var array $filters The filters registered with WordPress to fire when the plugin loads. … … 45 45 * Initialize the collections used to maintain the actions and filters. 46 46 * 47 * @since 0. 5.047 * @since 0.6 48 48 */ 49 49 public function __construct() { … … 57 57 * Add a new action to the collection to be registered with WordPress. 58 58 * 59 * @since 0. 5.059 * @since 0.6 60 60 * @param string $hook The name of the WordPress action that is being registered. 61 61 * @param object $component A reference to the instance of the object on which the action is defined. … … 71 71 * Add a new filter to the collection to be registered with WordPress. 72 72 * 73 * @since 0. 5.073 * @since 0.6 74 74 * @param string $hook The name of the WordPress filter that is being registered. 75 75 * @param object $component A reference to the instance of the object on which the filter is defined. … … 86 86 * collection. 87 87 * 88 * @since 0. 5.088 * @since 0.6 89 89 * @access private 90 90 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). … … 113 113 * Register the filters and actions with WordPress. 114 114 * 115 * @since 0. 5.0115 * @since 0.6 116 116 */ 117 117 public function run() { -
simple-youtube-gdpr/trunk/includes/class-simple-youtube-gdpr.php
r2072368 r2080878 8 8 * 9 9 * @link https://alexeyvolkov.com/ 10 * @since 0. 5.010 * @since 0.6 11 11 * 12 12 * @package Simple_Youtube_Gdpr … … 23 23 * version of the plugin. 24 24 * 25 * @since 0. 5.025 * @since 0.6 26 26 * @package Simple_Youtube_Gdpr 27 27 * @subpackage Simple_Youtube_Gdpr/includes … … 34 34 * the plugin. 35 35 * 36 * @since 0. 5.036 * @since 0.6 37 37 * @access protected 38 * @var Simple_Youtube_Gdpr_Loader $loaderMaintains and registers all hooks for the plugin.38 * @var Simple_Youtube_Gdpr_Loader $loader Maintains and registers all hooks for the plugin. 39 39 */ 40 40 protected $loader; … … 43 43 * The unique identifier of this plugin. 44 44 * 45 * @since 0. 5.045 * @since 0.6 46 46 * @access protected 47 * @var string $plugin_nameThe string used to uniquely identify this plugin.47 * @var string $plugin_name The string used to uniquely identify this plugin. 48 48 */ 49 49 protected $plugin_name; … … 52 52 * The current version of the plugin. 53 53 * 54 * @since 0. 5.054 * @since 0.6 55 55 * @access protected 56 * @var string $versionThe current version of the plugin.56 * @var string $version The current version of the plugin. 57 57 */ 58 58 protected $version; … … 65 65 * the public-facing side of the site. 66 66 * 67 * @since 0. 5.067 * @since 0.6 68 68 */ 69 69 public function __construct() { … … 71 71 $this->version = SIMPLE_YOUTUBE_GDPR_VERSION; 72 72 } else { 73 $this->version = '0. 5.0';73 $this->version = '0.6'; 74 74 } 75 75 $this->plugin_name = 'simple-youtube-gdpr'; … … 95 95 * with WordPress. 96 96 * 97 * @since 0. 5.097 * @since 0.6 98 98 * @access private 99 99 */ … … 123 123 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-simple-youtube-gdpr-public.php'; 124 124 125 /** 126 * The file responsible for DOM search. 127 */ 128 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/simple_html_dom.php'; 129 125 130 $this->loader = new Simple_Youtube_Gdpr_Loader(); 126 131 … … 133 138 * with WordPress. 134 139 * 135 * @since 0. 5.0140 * @since 0.6 136 141 * @access private 137 142 */ … … 148 153 * of the plugin. 149 154 * 150 * @since 0. 5.0155 * @since 0.6 151 156 * @access private 152 157 */ … … 164 169 * of the plugin. 165 170 * 166 * @since 0. 5.0171 * @since 0.6 167 172 * @access private 168 173 */ … … 180 185 * Run the loader to execute all of the hooks with WordPress. 181 186 * 182 * @since 0. 5.0187 * @since 0.6 183 188 */ 184 189 public function run() { … … 190 195 * WordPress and to define internationalization functionality. 191 196 * 192 * @since 0. 5.0197 * @since 0.6 193 198 * @return string The name of the plugin. 194 199 */ … … 200 205 * The reference to the class that orchestrates the hooks with the plugin. 201 206 * 202 * @since 0. 5.0207 * @since 0.6 203 208 * @return Simple_Youtube_Gdpr_Loader Orchestrates the hooks of the plugin. 204 209 */ … … 210 215 * Retrieve the version number of the plugin. 211 216 * 212 * @since 0. 5.0217 * @since 0.6 213 218 * @return string The version number of the plugin. 214 219 */ -
simple-youtube-gdpr/trunk/public/class-simple-youtube-gdpr-public.php
r2072368 r2080878 5 5 * 6 6 * @link https://alexeyvolkov.com/ 7 * @since 0. 5.07 * @since 0.6 8 8 * 9 9 * @package Simple_Youtube_Gdpr … … 26 26 * The ID of this plugin. 27 27 * 28 * @since 0. 5.028 * @since 0.6 29 29 * @access private 30 30 * @var string $plugin_name The ID of this plugin. … … 35 35 * The version of this plugin. 36 36 * 37 * @since 0. 5.037 * @since 0.6 38 38 * @access private 39 39 * @var string $version The current version of this plugin. … … 44 44 * Initialize the class and set its properties. 45 45 * 46 * @since 0. 5.046 * @since 0.6 47 47 * 48 48 * @param string $plugin_name The name of the plugin. … … 59 59 * Register the stylesheets for the public-facing side of the site. 60 60 * 61 * @since 0. 5.061 * @since 0.6 62 62 */ 63 63 public function enqueue_styles() { … … 89 89 * Register the JavaScript for the public-facing side of the site. 90 90 * 91 * @since 0. 5.091 * @since 0.6 92 92 */ 93 93 public function enqueue_scripts() { … … 121 121 if ( is_single() || is_page() ) { 122 122 $content = $this->lazyloadIframes( $content ); 123 124 123 } 125 124 … … 134 133 * @return string 135 134 */ 136 private function lazyloadIframes( $html, $args = [] ) { 137 138 $buffer = $this->ignoreScripts( $html ); 139 $buffer = $this->ignoreNoscripts( $buffer ); 140 141 $defaults = [ 142 'youtube' => true, 143 ]; 144 145 $args = wp_parse_args( $args, $defaults ); 146 147 if ( ! preg_match_all( '@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $buffer, $iframes, PREG_SET_ORDER ) ) { 148 return $html; 149 } 150 151 $iframes = array_unique( $iframes, SORT_REGULAR ); 152 153 foreach ( $iframes as $iframe ) { 154 // Given the previous regex pattern, $iframe['atts'] starts with a whitespace character. 155 if ( ! preg_match( '@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $iframe['atts'], $atts ) ) { 135 private function lazyloadIframes( $html, $container = 'figure.wp-block-embed-youtube' ) { 136 $html = str_get_html( $html ); 137 foreach ( $html->find( $container ) as $figure ) { 138 if ( '' === trim( $figure->innertext ) ) {// if empty -> next item 156 139 continue; 157 140 } 158 141 159 $iframe['src'] = esc_html( trim( $atts['src'] ) ); 160 161 if ( '' === $iframe['src'] ) { 162 continue; 163 } 164 165 if ( $args['youtube'] ) { 166 $iframe_lazyload = $this->replaceYoutubeThumbnail( $iframe ); 167 } 168 169 $html = str_replace( $iframe[0], $iframe_lazyload, $html ); 170 171 unset( $iframe_lazyload ); 172 } 173 174 return $html; 142 foreach ( $figure->find( 'iframe' ) as $iframe ) { 143 if ( '' === trim( $iframe->src ) ) {// if empty -> next item 144 continue; 145 } 146 $imgHTML = $this->getThumbnail( $iframe->outertext );// send <iframe> and get <div.youtube_lazyload> <img> </div> 147 $imgDiv = str_get_html( $imgHTML );// from raw HTML to Node Object 148 $iframe = $imgDiv->find( 'div.youtube_lazyload' )[0];// Find the only one(first) div.youtube_lazyload 149 } 150 151 // Replace <figure> with <img> 152 if ( ! $iframe->class ) {// if no class -> create 153 $iframe->class = ''; 154 } 155 $iframe->class = $iframe->class . ' ' . $figure->class; 156 $figure->outertext = $iframe->outertext; 157 } 158 159 return $html->outertext; 175 160 } 176 161 … … 182 167 * @return bool|string 183 168 */ 184 private function replaceYoutubeThumbnail( $iframe ) { 185 $youtube_id = esc_html( $this->getYoutubeIDFromURL( $iframe['src'] ) ); 169 private function getThumbnail( $iframeHTML ) { 170 $iframeHTML = str_get_html( $iframeHTML ); 171 $iframe = $iframeHTML->find( 'iframe' )[0];// Find the only one(first) iframe 172 $youtube_id = esc_html( $this->getYoutubeIDFromURL( $iframe->src ) );// get YouTube ID (fM6JWeQFnNk) 186 173 187 174 if ( ! $youtube_id ) { … … 283 270 file_put_contents( $file, $image_data ); 284 271 } 285 286 /**287 * Remove inline scripts from the HTML to parse288 *289 * @param string $html HTML content.290 *291 * @return string292 */293 private function ignoreScripts( $html ) {294 return preg_replace( '/<script\b(?:[^>]*)>(?:.+)?<\/script>/Umsi', '', $html );295 }296 297 /**298 * Remove noscript tags from the HTML to parse299 *300 * @param string $html HTML content.301 *302 * @return string303 */304 private function ignoreNoscripts( $html ) {305 return preg_replace( '#<noscript>(?:.+)</noscript>#Umsi', '', $html );306 }307 272 } -
simple-youtube-gdpr/trunk/public/partials/simple-youtube-gdpr-public-display.php
r2072368 r2080878 7 7 * 8 8 * @link https://alexeyvolkov.com/ 9 * @since 0. 5.09 * @since 0.6 10 10 * 11 11 * @package Simple_Youtube_Gdpr -
simple-youtube-gdpr/trunk/simple-youtube-gdpr.php
r2072368 r2080878 10 10 * 11 11 * @link https://alexeyvolkov.com/ 12 * @since 0. 5.012 * @since 0.6 13 13 * @package Simple_Youtube_Gdpr 14 14 * … … 17 17 * Plugin URI: https://alexeyvolkov.com/blog/simple-youtube-gdpr 18 18 * Description: Replaces all YouTube video iframes with a local image and loads a no cookie verion of video. 19 * Version: 0. 5.019 * Version: 0.6 20 20 * Author: Alexey Volkov 21 21 * Author URI: https://alexeyvolkov.com/ … … 33 33 /** 34 34 * Currently plugin version. 35 * Start at version 0. 5.0and use SemVer - https://semver.org35 * Start at version 0.6 and use SemVer - https://semver.org 36 36 * Rename this for your plugin and update it as you release new versions. 37 37 */ 38 define( 'SIMPLE_YOUTUBE_GDPR_VERSION', '0. 5.0' );38 define( 'SIMPLE_YOUTUBE_GDPR_VERSION', '0.6' ); 39 39 40 40 /** … … 72 72 * not affect the page life cycle. 73 73 * 74 * @since 0. 5.074 * @since 0.6 75 75 */ 76 76 function run_simple_youtube_gdpr() { -
simple-youtube-gdpr/trunk/uninstall.php
r2072368 r2080878 21 21 * 22 22 * @link https://alexeyvolkov.com/ 23 * @since 0. 5.023 * @since 0.6 24 24 * 25 25 * @package Simple_Youtube_Gdpr
Note: See TracChangeset
for help on using the changeset viewer.