From 166000955a34533e416210f7c9b5676f47fedb68 Mon Sep 17 00:00:00 2001 From: Mai Tan Date: Mon, 25 Nov 2019 13:42:48 +0900 Subject: [PATCH 1/6] Removed external resources --- README.txt | 4 ++- VERSION | 2 +- admin/class-defer-js-admin.php | 23 ------------ admin/partials/defer-js-admin-display.php | 9 ++--- defer-wordpress.php | 44 +++++++++++++++-------- public/js/defer.js | 1 + public/js/polyfill.js | 1 + 7 files changed, 39 insertions(+), 45 deletions(-) create mode 100644 public/js/defer.js create mode 100644 public/js/polyfill.js diff --git a/README.txt b/README.txt index 2846100..b34f2ed 100755 --- a/README.txt +++ b/README.txt @@ -103,7 +103,9 @@ Lazy loading content on web page can help reduce resource contention and improve == Changelog == -1.1.10+3 Bug fixes and improvements +1.1.10+4 Removed external resources + +1.1.10 Bug fixes and improvements 1.1.9 Fixed wrong encoding when using mb_detect_encoding() function diff --git a/VERSION b/VERSION index 11f91de..3543547 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.10+3 \ No newline at end of file +1.1.10+4 \ No newline at end of file diff --git a/admin/class-defer-js-admin.php b/admin/class-defer-js-admin.php index be4c75d..4f521dd 100755 --- a/admin/class-defer-js-admin.php +++ b/admin/class-defer-js-admin.php @@ -93,28 +93,6 @@ public function register_menu_plugin_options($links) public function options_page() { - if (!defined('DEFER_JS_SPONSORS_HTML')) { - if (class_exists('shinsenter\DeferCache')) { - $cache = new \shinsenter\DeferCache(DEFER_JS_CACHE_DIR, 1); - $html = $cache->get('sponsors' . DEFER_JS_CACHE_SUFFIX); - - if (empty($html)) { - $html = @file_get_contents(DEFER_JS_SPONSORS . '?t=' . time()); - $cache->put('sponsors' . DEFER_JS_CACHE_SUFFIX, $html, DEFER_JS_CACHE_EXP); - } - - define('DEFER_JS_SPONSORS_HTML', $html); - } else { - if (!file_exists(DEFER_JS_CACHE_DIR) || time() - filectime(DEFER_JS_CACHE_DIR) >= DEFER_JS_CACHE_EXP) { - $source = @file_get_contents(DEFER_JS_SPONSORS . '?t=' . time()); - $template = "reset_settings(); } @@ -170,7 +148,6 @@ public function enqueue_scripts() * class. */ - wp_enqueue_script('defer.js', 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js/dist/defer.min.js', array(), $this->version, false); wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/defer-js-admin.js', array(), $this->version, false); } diff --git a/admin/partials/defer-js-admin-display.php b/admin/partials/defer-js-admin-display.php index b136212..a860b70 100755 --- a/admin/partials/defer-js-admin-display.php +++ b/admin/partials/defer-js-admin-display.php @@ -381,6 +381,7 @@ +

Add defer.js library

@@ -404,7 +405,7 @@ - @@ -430,6 +430,7 @@

+ */ ?> @@ -473,9 +474,5 @@

From Vietnam 🇻🇳 with love.

- - \ No newline at end of file diff --git a/defer-wordpress.php b/defer-wordpress.php index 4d4f5af..8b0b1a1 100755 --- a/defer-wordpress.php +++ b/defer-wordpress.php @@ -20,16 +20,15 @@ * Currently plugin version. * Rename this for your plugin and update it as you release new versions. */ -define('DEFER_WORDPRESS_PLUGIN_VERSION', '1.1.10+2'); +define('DEFER_WORDPRESS_PLUGIN_VERSION', '1.1.10+4'); define('DEFER_JS_PREFIX', 'shinsenter_deferjs_'); -define('DEFER_GA_SCRIPT', '!function(n,a){n[a]=n[a]||[],n[a].push(["js",new Date],["config","UA-34520609-2"])}(window,"dataLayer")'); /* * @wordpress-plugin * Plugin Name: An efficient lazy loader (defer.js) * Plugin URI: https://wordpress.org/plugins/shins-pageload-magic/ * Description: ⚡️ A native, blazing fast lazy loader. ✅ Legacy browsers support (IE9+). 💯 SEO friendly. 🧩 Lazy load almost anything. - * Version: 1.1.10+3 + * Version: 1.1.10+4 * Author: Mai Nhut Tan * Author URI: https://code.shin.company/ * License: GPL-2.0+ @@ -41,10 +40,9 @@ /* * defer.js library version */ -if (!defined('DEFER_JS_VERSION')) { - define('DEFER_JS_VERSION', '1.1.10'); - define('DEFER_JS_RELEASED_URL', 'https://raw.githubusercontent.com/shinsenter/defer-wordpress/master/VERSION'); -} +// if (!defined('DEFER_JS_VERSION')) { +// define('DEFER_JS_VERSION', '1.1.10'); +// } if (!defined('DEFER_JS_PLUGIN_NAME')) { require_once __DIR__ . '/vendor/autoload.php'; @@ -54,7 +52,6 @@ if (!defined('DEFER_JS_PLUGIN_HOOK')) { define('DEFER_JS_PLUGIN_HOOK', 'plugin_action_links_' . plugin_basename(__FILE__)); define('DEFER_JS_HOMEPAGE', 'https://github.com/shinsenter/defer.js'); - define('DEFER_JS_SPONSORS', 'https://raw.githubusercontent.com/shinsenter/defer.php/footprint/sponsors.html'); define('DEFER_JS_PAYPAL', 'https://www.paypal.me/shinsenter'); define('DEFER_JS_PATREON', 'https://www.patreon.com/appseeds'); define('DEFER_JS_RATING', 'https://wordpress.org/support/plugin/shins-pageload-magic/reviews/?filter=5#new-post'); @@ -83,12 +80,31 @@ function shinsenter_deferjs_ob($buffer) $defer->{$key} = get_option(DEFER_JS_PREFIX . $key, $value); } - $loader_scripts = $defer->loader_scripts; - $loader_scripts[] = DEFER_GA_SCRIPT; - - $defer->loader_scripts = $loader_scripts; - $defer->debug_mode = false; - $defer->hide_warnings = true; + /* + * 20191125 Fix security errors in accordance with WordPress guidelines + */ + $defer->manually_add_deferjs = true; + $defer->append_defer_js = true; + + // all files have been downloaded and served locally + // https://github.com/shinsenter/defer.js/tree/master/dist + $polyfill = file_get_contents(__DIR__ . '/public/js/polyfill.js'); + $deferjs = file_get_contents(__DIR__ . '/public/js/defer.js'); + + // Append polyfill.js and defer_plus.min.js + static::$helpers = $polyfill . $deferjs; + + // Remove copyright (omit external requests) + static::$fingerprint = ' + ┌┬┐┌─┐┌─┐┌─┐┬─┐ ┬┌─┐ + ││├┤ ├┤ ├┤ ├┬┘ │└─┐ + ─┴┘└─┘└ └─┘┴└─o└┘└─┘ +This page was optimized with defer.js +WordPress: https://wordpress.org/plugins/shins-pageload-magic/ +'; + + $defer->debug_mode = false; + $defer->hide_warnings = true; $optimized = $defer->fromHtml($buffer)->toHtml(); } catch (\Exception $e) { diff --git a/public/js/defer.js b/public/js/defer.js new file mode 100644 index 0000000..badcb34 --- /dev/null +++ b/public/js/defer.js @@ -0,0 +1 @@ +!function(t,o,e,n,i,r){function c(t,e){r?n(t,e||32):i.push(t,e)}function f(t,e,n,i){return e&&o.getElementById(e)||(i=o.createElement(t||'SCRIPT'),e&&(i.id=e),n&&(i.onload=n),o.head.appendChild(i)),i||{}}r=/p/.test(o.readyState),t.addEventListener('on'+e in t?e:'load',function(){for(r=1;i[0];)c(i.shift(),i.shift())}),c._=f,t.defer=c,t.deferscript=function(t,e,n,i){c(function(){f('',e,i).src=t},n)}}(this,document,'pageshow',setTimeout,[]),function(u,n){var a='IntersectionObserver',d='src',l='lazied',h='data-',p=h+l,y='load',m='forEach',b='getAttribute',g=Function(),v=u.defer||g,c=v._||g;function I(t,e){return[].slice.call((e||n).querySelectorAll(t))}function t(s){return function(t,e,o,r,c,f){v(function(n,e){function i(n){!1!==(r||g).call(n,n)&&((f||['srcset',d,'style'])[m](function(t,e){(e=n[b](h+t))&&(n[t]=e)}),I('SOURCE',n)[m](i),y in n&&n[y]()),n.className+=' '+(o||l)}e=a in u?(n=new u[a](function(t){t[m](function(t,e){t.isIntersecting&&(e=t.target)&&(n.unobserve(e),i(e))})},c)).observe.bind(n):i,I(t||s+'['+h+d+']:not(['+p+'])')[m](function(t){t[b](p)||(t.setAttribute(p,s),e(t))})},e)}}function e(){v(function(e,n,i,o,r){e=I((i='script[type=deferjs]')+':not('+(o='[async]')+')').concat(I(i+o)),function t(){if(0!=e){for(o in(i=e.shift()).parentNode.removeChild(i),i.removeAttribute('type'),n=c(),i)'string'==typeof(r=i[o])&&n[o]!=r&&(n[o]=r);n[d]&&!n.hasAttribute('async')?n.onload=n.onerror=t:v(t,.1)}}()},4)}e(),u.deferstyle=function(e,n,t,i){v(function(t){(t=c('LINK',n,i)).rel='stylesheet',t.href=e},t)},u.deferimg=t('IMG'),u.deferiframe=t('IFRAME'),v.all=e}(this,document); \ No newline at end of file diff --git a/public/js/polyfill.js b/public/js/polyfill.js new file mode 100644 index 0000000..7bc6670 --- /dev/null +++ b/public/js/polyfill.js @@ -0,0 +1 @@ +!function(){'use strict';if('object'==typeof window)if('IntersectionObserver'in window&&'IntersectionObserverEntry'in window&&'intersectionRatio'in window.IntersectionObserverEntry.prototype)'isIntersecting'in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,'isIntersecting',{get:function(){return 0 Date: Tue, 26 Nov 2019 15:05:33 +0900 Subject: [PATCH 2/6] Fixed namespaces --- defer-wordpress.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/defer-wordpress.php b/defer-wordpress.php index 8b0b1a1..a334704 100755 --- a/defer-wordpress.php +++ b/defer-wordpress.php @@ -92,10 +92,10 @@ function shinsenter_deferjs_ob($buffer) $deferjs = file_get_contents(__DIR__ . '/public/js/defer.js'); // Append polyfill.js and defer_plus.min.js - static::$helpers = $polyfill . $deferjs; + \shinsenter\Defer::$helpers = $polyfill . $deferjs; // Remove copyright (omit external requests) - static::$fingerprint = ' + \shinsenter\Defer::$fingerprint = ' ┌┬┐┌─┐┌─┐┌─┐┬─┐ ┬┌─┐ ││├┤ ├┤ ├┤ ├┬┘ │└─┐ ─┴┘└─┘└ └─┘┴└─o└┘└─┘ From 0aa01a3e411ff74f9e753b6adc696ea2d7d3037f Mon Sep 17 00:00:00 2001 From: Mai Tan Date: Tue, 26 Nov 2019 15:12:14 +0900 Subject: [PATCH 3/6] Updated composer --- composer.json | 2 +- composer.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b762e6c..ea3923c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "require": { "php": ">=5.6", "symfony/http-foundation": "3.3.18", - "shinsenter/defer.php": "^1.0" + "shinsenter/defer.php": "^1.0.0" }, "config": { "preferred-install": "dist", diff --git a/composer.lock b/composer.lock index 6cda183..0f3e805 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "77b4f7853eb883a5021e2e178d29776d", + "content-hash": "e258c52588909028a03cdfef4ab2e1db", "packages": [ { "name": "shinsenter/defer.php", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/shinsenter/defer.php.git", - "reference": "7d3a3a68016fb58348b1c597a25cb599e2d92ba5" + "reference": "ba5d15f6b8cd48a6fc7f23088df8fa4f7188449a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/shinsenter/defer.php/zipball/7d3a3a68016fb58348b1c597a25cb599e2d92ba5", - "reference": "7d3a3a68016fb58348b1c597a25cb599e2d92ba5", + "url": "https://api.github.com/repos/shinsenter/defer.php/zipball/ba5d15f6b8cd48a6fc7f23088df8fa4f7188449a", + "reference": "ba5d15f6b8cd48a6fc7f23088df8fa4f7188449a", "shasum": "" }, "require": { From 90479d41c9698f33103922d75bfdffcf2059ec38 Mon Sep 17 00:00:00 2001 From: Mai Tan Date: Tue, 26 Nov 2019 15:23:52 +0900 Subject: [PATCH 4/6] Remove relative paths --- _dist_/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_dist_/deploy.sh b/_dist_/deploy.sh index 2106310..0e5b5fa 100755 --- a/_dist_/deploy.sh +++ b/_dist_/deploy.sh @@ -32,8 +32,8 @@ fi cd $plugin_dir svn rm trunk/* --force -rsync -aHxW --delete --exclude-from=$base_dir/_dist_/blacklist.txt $base_dir/ $plugin_dir/trunk/ -mv trunk/defer-wordpress.php $plugin_dir/trunk/$plugin_name.php +rsync -aHxW --delete --exclude-from=$base_dir/_dist_/blacklist.txt $base_dir/ trunk/ +mv trunk/defer-wordpress.php trunk/$plugin_name.php svn add trunk/* --force svn stat From a2268d93244a5805d7a47fd16bf2ad767ef2d2c8 Mon Sep 17 00:00:00 2001 From: Mai Tan Date: Mon, 2 Dec 2019 16:15:06 +0900 Subject: [PATCH 5/6] Improved scripts --- defer-wordpress.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/defer-wordpress.php b/defer-wordpress.php index a334704..e56d9c1 100755 --- a/defer-wordpress.php +++ b/defer-wordpress.php @@ -88,11 +88,15 @@ function shinsenter_deferjs_ob($buffer) // all files have been downloaded and served locally // https://github.com/shinsenter/defer.js/tree/master/dist - $polyfill = file_get_contents(__DIR__ . '/public/js/polyfill.js'); - $deferjs = file_get_contents(__DIR__ . '/public/js/defer.js'); + $polyfill = '"IntersectionObserver"in window||deferscript("' + . plugin_dir_url(__FILE__) + . 'public/js/polyfill.js","polyfill-js",1);'; + $deferjs = file_get_contents(__DIR__ . '/public/js/defer.js'); + $helpers = file_get_contents(\shinsenter\Defer::HELPERS_URL); // Append polyfill.js and defer_plus.min.js - \shinsenter\Defer::$helpers = $polyfill . $deferjs; + \shinsenter\Defer::$helpers = $polyfill . $deferjs . $helpers; + // Remove copyright (omit external requests) \shinsenter\Defer::$fingerprint = ' From cb849fea3309aefe734da359b2d77e2776bdad2a Mon Sep 17 00:00:00 2001 From: Mai Tan Date: Tue, 3 Dec 2019 10:21:23 +0900 Subject: [PATCH 6/6] Update composer --- composer.json | 2 +- composer.lock | 139 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 125 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index ea3923c..abf8d8c 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "require": { "php": ">=5.6", - "symfony/http-foundation": "3.3.18", + "symfony/http-foundation": "3.4.36", "shinsenter/defer.php": "^1.0.0" }, "config": { diff --git a/composer.lock b/composer.lock index 0f3e805..9e8bf2c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,57 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e258c52588909028a03cdfef4ab2e1db", + "content-hash": "f87a7e7ae75ff280f466b5e66911f252", "packages": [ + { + "name": "paragonie/random_compat", + "version": "v2.0.18", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "0a58ef6e3146256cc3dc7cc393927bcc7d1b72db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/0a58ef6e3146256cc3dc7cc393927bcc7d1b72db", + "reference": "0a58ef6e3146256cc3dc7cc393927bcc7d1b72db", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "time": "2019-01-03T20:59:08+00:00" + }, { "name": "shinsenter/defer.php", "version": "1.0.17", @@ -75,29 +124,30 @@ }, { "name": "symfony/http-foundation", - "version": "v3.3.18", + "version": "v3.4.36", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "88506c8c623d861d4733194efe9c0c317b593ad6" + "reference": "d2d0cfe8e319d9df44c4cca570710fcf221d4593" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/88506c8c623d861d4733194efe9c0c317b593ad6", - "reference": "88506c8c623d861d4733194efe9c0c317b593ad6", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/d2d0cfe8e319d9df44c4cca570710fcf221d4593", + "reference": "d2d0cfe8e319d9df44c4cca570710fcf221d4593", "shasum": "" }, "require": { "php": "^5.5.9|>=7.0.8", - "symfony/polyfill-mbstring": "~1.1" + "symfony/polyfill-mbstring": "~1.1", + "symfony/polyfill-php70": "~1.6" }, "require-dev": { - "symfony/expression-language": "~2.8|~3.0" + "symfony/expression-language": "~2.8|~3.0|~4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -124,20 +174,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2018-08-01T12:50:04+00:00" + "time": "2019-11-28T12:52:59+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.12.0", + "version": "v1.13.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" + "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", - "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7b4aab9743c30be783b73de055d24a39cf4b954f", + "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f", "shasum": "" }, "require": { @@ -149,7 +199,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.13-dev" } }, "autoload": { @@ -183,7 +233,66 @@ "portable", "shim" ], - "time": "2019-08-06T08:03:45+00:00" + "time": "2019-11-27T14:18:11+00:00" + }, + { + "name": "symfony/polyfill-php70", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "af23c7bb26a73b850840823662dda371484926c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/af23c7bb26a73b850840823662dda371484926c4", + "reference": "af23c7bb26a73b850840823662dda371484926c4", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0|~2.0|~9.99", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-11-27T13:56:44+00:00" } ], "packages-dev": [],