Orderassets/images/image-palceholder.png000064400000000221147577727020013400 0ustar00PNG  IHDR+F],sRGB, pHYs   PLTE8;tRNSnp2 IDATxc`a0FIENDB`assets/images/no-image.png000064400000003441147577727020011541 0ustar00PNG  IHDR<PES pHYs\rtEXtSoftwarewww.inkscape.org<IDATx_H?3Ifn*KR胘EB\dor7@Ԡ"{ |$10 uIt5u?s5[oۜ33sV$I׀q(yh}h69_M%I7ʗHv o'w +UXJGV:Q*tTa +UXJGhooݻPVjjjבeXQvuVZ[[岩) `0pI222_B-^jy}G<>}f9r"UUU}3gΐMOO p9/,=V˹tQQQ{Ckn޼nXfsX닢6$u: EYYr!G211Acc#& $vuu5MMMTVV իa9 n_,//AQ~? _$I"j B\r`$P($wDnǯFeeeF0"_FJDÛE bR8CDpOOaeEjLMMaٸvچHx``zA7|}o۷E>|(/7- ZQn7999h4dddݍ^իW\. ˓ݿÁd(߈a:;;װVQ)//`a+7oȷ˗/inn&--Bnܸ! cǎ򍸇?~ȇ YƨG*++9}4~X%%%c&&&XZZraZ@GGdžXȑ#vxycjdt:BnѸFc#iḭ,~z/Vd2roD#刺6)))ÇMEE(rhjjbzzS\\j9߽{8餦哓 NLL 8qqqull Ʉ`  ׇ$I{p(e.href,"high"),i=void 0},s))}function l(t){const e=t.target.closest("a");m(e)&&p(e.href,"high")}function f(t){t.relatedTarget&&t.target.closest("a")==t.relatedTarget.closest("a")||i&&(clearTimeout(i),i=void 0)}function h(t){if(performance.now()-o1||t.metaKey||t.ctrlKey)return;if(!e)return;e.addEventListener("click",function(t){1337!=t.detail&&t.preventDefault()},{capture:!0,passive:!1,once:!0});const n=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!1,detail:1337});e.dispatchEvent(n)}function m(o){if(o&&o.href&&(!n||"instant"in o.dataset)){if(o.origin!=location.origin){if(!(e||"instant"in o.dataset)||!a)return}if(["http:","https:"].includes(o.protocol)&&("http:"!=o.protocol||"https:"!=location.protocol)&&(t||!o.search||"instant"in o.dataset)&&!(o.hash&&o.pathname+o.search==location.pathname+location.search||"noInstant"in o.dataset))return!0}}function p(t,e="auto"){if(c.has(t))return;const n=document.createElement("link");n.rel="prefetch",n.href=t,n.fetchPriority=e,n.as="document",document.head.appendChild(n),c.add(t)}!function(){if(!document.createElement("link").relList.supports("prefetch"))return;const o="instantVaryAccept"in document.body.dataset||"Shopify"in window,i=navigator.userAgent.indexOf("Chrome/");i>-1&&(a=parseInt(navigator.userAgent.substring(i+"Chrome/".length)));if(o&&a&&a<110)return;const c="instantMousedownShortcut"in document.body.dataset;t="instantAllowQueryString"in document.body.dataset,e="instantAllowExternalLinks"in document.body.dataset,n="instantWhitelist"in document.body.dataset;const r={capture:!0,passive:!0};let f=!1,v=!1,g=!1;if("instantIntensity"in document.body.dataset){const t=document.body.dataset.instantIntensity;if(t.startsWith("mousedown"))f=!0,"mousedown-only"==t&&(v=!0);else if(t.startsWith("viewport")){const e=navigator.connection&&navigator.connection.saveData,n=navigator.connection&&navigator.connection.effectiveType&&navigator.connection.effectiveType.includes("2g");e||n||("viewport"==t?document.documentElement.clientWidth*document.documentElement.clientHeight<45e4&&(g=!0):"viewport-all"==t&&(g=!0))}else{const e=parseInt(t);isNaN(e)||(s=e)}}v||document.addEventListener("touchstart",d,r);f?c||document.addEventListener("mousedown",l,r):document.addEventListener("mouseover",u,r);c&&document.addEventListener("mousedown",h,r);if(g){let t=window.requestIdleCallback;t||(t=(t=>{t()})),t(function(){const t=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){const n=e.target;t.unobserve(n),p(n.href)}})});document.querySelectorAll("a").forEach(e=>{m(e)&&t.observe(e)})},{timeout:1500})}}();})();assets/js/index.html000064400000000133147577727020010476 0ustar00

Powered By SpeedyCache

Go to SpeedyCache.Comassets/js/lazy-load.js000064400000011735147577727020010745 0ustar00var speedycache_lazy_load = { sources: [], osl: 0, scroll: false, init: function(){ speedycache_lazy_load.set_source(); window.addEventListener('load', function(){ let observer = new MutationObserver((mutations) => { speedycache_lazy_load.osl = speedycache_lazy_load.sources.length; speedycache_lazy_load.set_source(); if(speedycache_lazy_load.sources.length > speedycache_lazy_load.osl){ speedycache_lazy_load.load_sources(false); } }); observer.observe(document.getElementsByTagName('html')[0], {childList: true, attributes: true, subtree: true, attributeFilter: ["src"], attributeOldValue: false, characterDataOldValue: false}); speedycache_lazy_load.load_sources(true); }); let js_events = ['scroll', 'resize', 'click']; js_events.forEach((event) => { window.addEventListener(event, function(){ speedycache_lazy_load.scroll=true; speedycache_lazy_load.load_sources(false); }); }); }, c: function(e, pageload){ var winH = document.documentElement.clientHeight || body.clientHeight; var number = 0; if(pageload){ number = 0; }else{ number = (winH > 800) ? 800 : 200; number = speedycache_lazy_load.scroll ? 800 : number; } var elemRect = e.getBoundingClientRect(); var top = 0; var parentOfE = e.parentNode ? e.parentNode : false; if(typeof parentOfE.getBoundingClientRect == 'undefined'){ var parentRect = false; }else{ var parentRect = parentOfE.getBoundingClientRect(); } if(elemRect.x == 0 && elemRect.y == 0){ for(var i = 0; i < 10; i++){ if(parentOfE){ if(parentRect.x == 0 && parentRect.y == 0){ if(parentOfE.parentNode){ parentOfE = parentOfE.parentNode; } if(typeof parentOfE.getBoundingClientRect == 'undefined'){ parentRect = false; }else{ parentRect = parentOfE.getBoundingClientRect(); } }else{ top = parentRect.top; break; } } }; }else{ top = elemRect.top; } if(winH - top + number > 0){ return true; } return false; }, r: function(e, pageload){ var self = this; var originalsrc,originalsrcset; try{ originalsrc = e.getAttribute('data-speedycache-original-src'); originalsrcset = e.getAttribute('data-speedycache-original-srcset'); originalsizes = e.getAttribute('data-speedycache-original-sizes'); if(self.c(e, pageload)){ if(originalsrc || originalsrcset){ if(e.tagName == 'DIV' || e.tagName == 'A' || e.tagName == 'SPAN'){ e.style.backgroundImage = 'url(' + originalsrc + ')'; e.removeAttribute('data-speedycache-original-src'); e.removeAttribute('data-speedycache-original-srcset'); e.removeAttribute('onload'); }else{ if(originalsrc){ e.setAttribute('src', originalsrc); } if(originalsrcset){ e.setAttribute('srcset', originalsrcset); } if(originalsizes){ e.setAttribute('sizes', originalsizes); } if(e.getAttribute('alt') && e.getAttribute('alt') == 'blank'){ e.removeAttribute('alt'); } e.removeAttribute('data-speedycache-original-src'); e.removeAttribute('data-speedycache-original-srcset'); e.removeAttribute('data-speedycache-original-sizes'); e.removeAttribute('onload'); if(e.tagName == 'IFRAME'){ var y = "https://www.youtube.com/embed/"; if(navigator.userAgent.match(/\sEdge?\/\d/i)){ e.setAttribute('src',e.getAttribute('src').replace(/.+\/main\/youtube\.html\#/, y)); } e.onload = function(){ if(typeof window.jQuery != 'undefined'){if(jQuery.fn.fitVids){jQuery(e).parent().fitVids({ customSelector: 'iframe[src]'});}} var s = e.getAttribute('src').match(/main\/youtube\.html\#(.+)/); if(s){ try{ var i = e.contentDocument || e.contentWindow; if(i.location.href == 'about:blank'){ e.setAttribute('src',y+s[1]); } }catch(err){ e.setAttribute('src',y+s[1]); } } } } } }else{ if(e.tagName == 'NOSCRIPT'){ if(e.getAttribute('data-type') == 'speedycache'){ e.removeAttribute('data-type'); e.after(e.textContent); } } } } }catch(error){ console.log(error); console.log('==>', e); } }, set_source: function(){ var i = [].slice.call(document.getElementsByTagName('img')); var f = [].slice.call(document.getElementsByTagName('iframe')); var d = [].slice.call(document.getElementsByTagName('div')); var a = [].slice.call(document.getElementsByTagName('a')); var s = [].slice.call(document.getElementsByTagName('span')); var n = [].slice.call(document.getElementsByTagName('noscript')); this.sources = i.concat(f).concat(d).concat(a).concat(s).concat(n); }, load_sources: function(pageload){ var self = this; [].forEach.call(self.sources, function(e, index) { self.r(e, pageload); }); } }; document.addEventListener('DOMContentLoaded',function(){ speedycache_lazy_load.init(); });assets/js/delayjs.min.js000064400000001206147577727020011256 0ustar00!function(){let e=["mouseover","click","keydown","wheel","touchmove","touchstart"],t=setTimeout(r,1e4);function r(){e.forEach((e=>{window.removeEventListener(e,r,{passive:!0})})),document.querySelectorAll('script[type="speedycache/javascript"]').forEach((async e=>{await new Promise((t=>function(e,t){let r=document.createElement("script");e.getAttributeNames().forEach((t=>{"type"!==t&&r.setAttribute("data-src"==t?"src":t,e.getAttribute(t))})),r.setAttribute("type","text/javascript"),r.addEventListener("load",t),e.after(r),e.remove()}(e,t)))})),null!=t&&(clearTimeout(t),t=null)}e.forEach((e=>{window.addEventListener(e,r,{passive:!0})}))}();assets/js/metabox.js000064400000001403147577727020010477 0ustar00jQuery(document).ready(function() { jQuery('#speedycache-generate-specific-cache').on('click', function(){ let ccss_disabled = jQuery('#speedycache-disable-critical-css:checked'); if(ccss_disabled.length){ alert('Critical CSS is disabled for this post'); return; } jQuery.ajax({ 'method': 'POST', 'url': speedycache_metabox.url, 'data': { 'post_id': speedycache_metabox.post_id, 'security': speedycache_metabox.nonce, 'action': 'speedycache_generate_single_ccss', }, success: function(res){ if(!res.success){ alert(res.data.message ? res.data.message : 'Something went wrong ! Unable to intitiate Critical CSS!'); return; } alert(res.data.message); } }); }); });assets/js/delayjs.js000064400000002302147577727020010472 0ustar00(function(){ let speedycache_js_events = ['mouseover','click','keydown','wheel','touchmove','touchstart'], speedycache_djs_timeout = setTimeout(speedycache_delay_event, 10000); speedycache_js_events.forEach((event) => { window.addEventListener(event, speedycache_delay_event, {passive: true}); }); function speedycache_delay_event(){ speedycache_js_events.forEach((event) => { window.removeEventListener(event, speedycache_delay_event, {passive: true}); }); document.querySelectorAll('script[type="speedycache/javascript"]').forEach(async e => { await new Promise(resolve => speedycache_load_js(e, resolve)); }); if(speedycache_djs_timeout != null){ clearTimeout(speedycache_djs_timeout); speedycache_djs_timeout = null; } } function speedycache_load_js(js, resolve){ let async_js = document.createElement('script'); let attr = js.getAttributeNames(); attr.forEach(name => { if(name === 'type'){ return; } async_js.setAttribute(name == 'data-src' ? 'src' : name, js.getAttribute(name)); }); async_js.setAttribute('type', 'text/javascript'); async_js.addEventListener('load', resolve); js.after(async_js); js.remove(); } })();main/object-cache-lib.php000064400000025556147577727020011313 0ustar00add( $key, $data, $group, (int) $expire ); } function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->add_multiple( $data, $group, $expire ); } function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); } function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->set( $key, $data, $group, (int) $expire ); } function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->set_multiple( $data, $group, $expire ); } function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { global $wp_object_cache; return $wp_object_cache->get( $key, $group, $force, $found ); } function wp_cache_get_multiple( $keys, $group = '', $force = false ) { global $wp_object_cache; return $wp_object_cache->get_multiple( $keys, $group, $force ); } function wp_cache_delete( $key, $group = '' ) { global $wp_object_cache; return $wp_object_cache->delete( $key, $group ); } function wp_cache_delete_multiple( array $keys, $group = '' ) { global $wp_object_cache; return $wp_object_cache->delete_multiple( $keys, $group ); } function wp_cache_incr( $key, $offset = 1, $group = '' ) { global $wp_object_cache; return $wp_object_cache->incr( $key, $offset, $group ); } function wp_cache_decr( $key, $offset = 1, $group = '' ) { global $wp_object_cache; return $wp_object_cache->decr( $key, $offset, $group ); } function wp_cache_flush() { global $wp_object_cache; return $wp_object_cache->flush(); } function wp_cache_flush_runtime() { return wp_cache_flush(); } function wp_cache_flush_group( $group ) { global $wp_object_cache; return $wp_object_cache->flush_group( $group ); } function wp_cache_supports( $feature ) { switch ( $feature ) { case 'add_multiple': case 'set_multiple': case 'get_multiple': case 'delete_multiple': case 'flush_runtime': case 'flush_group': return true; default: return false; } } function wp_cache_close() { return true; } function wp_cache_add_global_groups( $groups ) { global $wp_object_cache; $wp_object_cache->add_global_groups( $groups ); } function wp_cache_add_non_persistent_groups( $groups ) { // Default cache doesn't persist so nothing to do here. } function wp_cache_switch_to_blog( $blog_id ) { global $wp_object_cache; $wp_object_cache->switch_to_blog( $blog_id ); } function wp_cache_reset() { _deprecated_function( __FUNCTION__, '3.5.0', 'wp_cache_switch_to_blog()' ); global $wp_object_cache; $wp_object_cache->reset(); } #[AllowDynamicProperties] class WP_Object_Cache { private $cache = array(); public $cache_hits = 0; public $cache_misses = 0; protected $global_groups = array(); private $blog_prefix; private $multisite; public $object_cache; static $instance; public function __construct() { $this->object_cache = \SpeedyCache\ObjectCache::get_instance(); $this->multisite = is_multisite(); $this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : ''; } static function get_instance(){ if(self::$instance){ return self::$instance; } self::$instance = new self; return self::$instance; } public function __get( $name ) { return $this->$name; } public function __set( $name, $value ) { return $this->$name = $value; } public function __isset( $name ) { return isset( $this->$name ); } public function __unset( $name ) { unset( $this->$name ); } protected function is_valid_key( $key ) { if ( is_int( $key ) ) { return true; } if ( is_string( $key ) && trim( $key ) !== '' ) { return true; } $type = gettype( $key ); if ( ! function_exists( '__' ) ) { wp_load_translations_early(); } $message = is_string( $key ) ? __( 'Cache key must not be an empty string.' ) /* translators: %s: The type of the given cache key. */ : sprintf( __( 'Cache key must be integer or non-empty string, %s given.' ), $type ); _doing_it_wrong( sprintf( '%s::%s', __CLASS__, debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1]['function'] ), $message, '6.1.0' ); return false; } protected function _exists( $key, $group ) { if(!$id = $this->id($key, $group)){ return false; } return isset($this->cache[$group][$id]); } public function add( $key, $data, $group = 'default', $expire = 0 ) { if(wp_suspend_cache_addition()){ return false; } if(! $this->is_valid_key($key)){ return false; } if($this->_exists($key, $group)){ return false; } return $this->set($key, $data, $group, (int) $expire); } public function add_multiple( array $data, $group = '', $expire = 0 ) { $values = array(); foreach ( $data as $key => $value ) { $values[ $key ] = $this->add( $key, $value, $group, $expire ); } return $values; } public function replace( $key, $data, $group = 'default', $expire = 0 ) { if ( ! $this->is_valid_key( $key ) ) { return false; } if(!$id = $this->id($key, $group)){ return false; } if (!$this->_exists($key, $group)){ if(!$this->object_cache::exists($id)){ return false; } } return $this->set( $key, $data, $group, (int) $expire ); } public function set( $key, $data, $group = 'default', $expire = 0 ) { if(! $this->is_valid_key($key)){ return false; } if(is_object($data)){ $data = clone $data; } if(!$id = $this->id($key, $group)){ return false; } if(!in_array($group, $this->object_cache::$non_cache_group)){ $this->object_cache::set($id, $data, (int) $expire); } $this->cache[$group][$id] = $data; return true; } public function set_multiple( array $data, $group = '', $expire = 0 ) { $values = array(); foreach ( $data as $key => $value ) { $values[ $key ] = $this->set( $key, $value, $group, $expire ); } return $values; } public function get( $key, $group = 'default', $force = false, &$found = null ) { if ( ! $this->is_valid_key( $key ) ) { return false; } if(!$id = $this->id($key, $group)){ $found = false; $this->cache_misses += 1; return false; } // In memory cache if($this->_exists($key, $group)){ $found = true; $this->cache_hits += 1; return $this->cache[$group][$id]; } // Non Cache Group check. if(empty($this->object_cache) || in_array($group, $this->object_cache::$non_cache_group)){ $found = false; $this->cache_misses += 1; return false; } // Fetch cache from redis. if($cache = $this->object_cache::get($id)){ $found = true; $this->cache_hits += 1; if(is_serialized($cache)){ $cache = maybe_unserialize($cache); } $this->cache[$group][$id] = $cache; return $this->cache[$group][$id]; } $found = false; $this->cache_misses += 1; return false; } public function get_multiple($keys, $group = 'default', $force = false) { $values = array(); foreach($keys as $key){ $values[$key] = $this->get($key, $group, $force); } return $values; } public function delete($key, $group = 'default', $deprecated = false) { if (! $this->is_valid_key($key)){ return false; } if(!$id = $this->id($key, $group)){ return false; } if(empty($this->cache[$group]) && empty($this->cache[$group][$id]) && !$this->object_cache::exists($id)) { return false; } unset($this->cache[$group][$id]); $this->object_cache::delete($id); return true; } public function delete_multiple(array $keys, $group = ''){ $values = array(); foreach($keys as $key){ $values[$key] = $this->delete($key, $group); } return $values; } public function incr($key, $offset = 1, $group = 'default'){ return $this->incr_desr($key, $offset = 1, $group, true); } public function decr($key, $offset = 1, $group = 'default'){ return $this->incr_desr($key, $offset = 1, $group, false); } public function incr_desr($key, $offset = 1, $group = 'default', $incr = true){ if (! $this->is_valid_key($key)){ return false; } $cache_val = $this->get($key, $group); if(false === $cache_val){ return false; } if(! is_numeric( $cache_val)){ $cache_val = 0; } $offset = (int) $offset; if($incr){ $cache_val += $offset; } else { $cache_val -= $offset; } if ( $cache_val < 0 ) { $cache_val = 0; } $this->set($key, $cache_val, $group); return $cache_val; } public function flush() { $this->cache = array(); if(!empty($this->object_cache)){ $this->object_cache::flush_db(); } return true; } public function flush_group($group) { unset($this->cache[$group]); return true; } public function add_global_groups($groups){ $groups = (array) $groups; $groups = array_fill_keys($groups, true); $this->global_groups = array_merge($this->global_groups, $groups); } public function is_global($group){ return in_array($group, $this->global_groups); } public function switch_to_blog($blog_id){ $blog_id = (int) $blog_id; $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; } public function reset(){ _deprecated_function(__FUNCTION__, '3.5.0', 'WP_Object_Cache::switch_to_blog()'); // Clear out non-global caches since the blog ID has changed. foreach(array_keys($this->cache) as $group){ if(! isset( $this->global_groups[$group])){ unset($this->cache[$group]); } } } public function stats() { echo '

'; echo "Cache Hits: {$this->cache_hits}
"; echo "Cache Misses: {$this->cache_misses}
"; echo '

'; echo '
    '; foreach($this->cache as $group => $cache){ echo '
  • Group: ' . esc_html($group) . ' - ( ' . number_format(strlen(serialize($cache)) / KB_IN_BYTES, 2 ) . 'k )
  • '; } echo '
'; } public function id($key, $group){ $prefix = $this->is_global($group) ? '' : $this->blog_prefix; if(empty($group)){ $group = 'default'; } return $prefix . $group . '.' . $key; } }main/cli.php000064400000003202147577727020006767 0ustar00 * : Purges cache or minified * --- * options: * - cache * - and minified * * ## EXAMPLES * # Purge Cache * $ wp speedycache purge cache * * # Purge cache and minfied * $ wp speedycache purge cache and minified */ public function purge($args, $args_assoc){ global $speedycache; if(!isset($speedycache)){ WP_CLI::error('speedycache has not been defined!'); } if(!function_exists('speedycache_delete_cache')){ WP_CLI::error('speedycache_delete_cache() does not exist!'); } if(empty($args[0]) || $args[0] !== 'cache'){ self::wrong_usage(); } if(empty($args[1]) || empty($args[2])){ $this->delete_cache(); return; } if($args[1] == 'and' && $args[2] == 'minified'){ $this->delete_cache(true); return; } self::wrong_usage(); } private function delete_cache($minified_too = false){ if(function_exists('speedycache_delete_cache')){ WP_CLI::error('Somethinng Went Wrong: Unable to delete cache'); } WP_CLI::line('Clearing the ALL cache...'); if(defined('SPEEDYCACHE_VERSION') && version_compare(SPEEDYCACHE_VERSION, '1.2.0', '>=')){ $delete['minified'] = $minified_too; \SpeedyCache\Delete::run($delete); } else { speedycache_delete_cache($minified_too); } WP_CLI::success('The cache has been cleared!'); } } WP_CLI::add_command('speedycache', 'speedycache_cli');main/renderblocking.php000064400000111221147577727020011211 0ustar00render_blocking = array(); $speedycache->render_blocking['except'] = ''; $speedycache->render_blocking['tags'] = array(); $speedycache->render_blocking['header_start_index'] = 0; $speedycache->render_blocking['js_tags_text'] = ''; $speedycache->render_blocking['html'] = $html; self::set_header_start_index(); self::set_tags(); $speedycache->render_blocking['tags'] = self::reorder_tags($speedycache->render_blocking['tags']); } static function set_tags(){ self::set_comments(); self::set_js(); self::set_css(); } static function set_comments(){ global $speedycache; $comment_tags = self::find_tags(''); self::set_except($comment_tags); foreach($comment_tags as $key => $value){ if(preg_match("/\<\!--\s*\[if/i", $value['text'])){ if(preg_match("/data-speedycache-render\=[\"\']false[\"\']/i", $value['text'])){ continue; } array_push($speedycache->render_blocking['tags'], $value); } } } static function set_css(){ global $speedycache; $style_tags = self::find_tags(''); foreach($style_tags as $key => $value){ // if(!preg_match("/<\/script>/i", $value['text'])){ array_push($speedycache->render_blocking['tags'], $value); } } $link_tags = self::find_tags(''); foreach($link_tags as $key => $value){ if(preg_match("/href\s*\=/i", $value['text'])){ if(preg_match("/rel\s*\=\s*[\'\"]\s*stylesheet\s*[\'\"]/i", $value['text'])){ array_push($speedycache->render_blocking['tags'], $value); } } } } static function set_js(){ global $speedycache; // Creating regex to exclude js from RenderBlocking if(!empty($speedycache->options['render_blocking_excludes'])){ $exclude_script_list = array_map('preg_quote', $speedycache->options['render_blocking_excludes'], array_fill(0, count($speedycache->options['render_blocking_excludes']), '/')); $exclude_user_script = '/\b(?:' . implode('|', $exclude_script_list) . ')\b/'; } $script_tag = self::find_tags(''); foreach($script_tag as $key => $value){ if(self::exclude_scripts($value['text'])){ continue; } // Excludes the user specified scripts if(!empty($exclude_user_script) && preg_match($exclude_user_script, $value['text'])){ continue; } // Import map should always load at the same place as it is meant to be loaded before other scripts. if(preg_match("/importmap/i", $value['text'])){ continue; } // if(preg_match("/partner\.googleadservices\.com\/gampad\/google_service\.js/i", $value['text'])){ continue; } // if(preg_match("/]*>\s*GS_googleAddAdSenseService\([\"\'][^\"\']+[\"\']\)\;\s*GS_googleEnableAllServices\(\)\;\s*<\/script>/i", $value['text'])){ continue; } // if(preg_match("/]*>\s*GA_googleAddSlot\([^\)]+\)\;\s*<\/script>/i", $value['text'])){ continue; } // if(preg_match("/]*>\s*GA_googleFetchAds\(\)\;\s*<\/script>/i", $value['text'])){ continue; } // if(preg_match("/]*>\s*\(function\(i,s,o,g,r,a,m\)\{i\[\'GoogleAnalyticsObject\'\]/i", $value['text'])){ if(preg_match("/ga\(\'send\',\s*\'pageview\'\)\;\s*<\/script>/i", $value['text'])){ continue; } } // // // if(preg_match("/]+googletagmanager\.com\/gtag\/js[^\>]+>/i", $value['text'])){ continue; } if(preg_match("/^ */ if(preg_match("/data-skip-moving\=[\"\']true[\"\']/i", $value['text'])){ continue; } if(preg_match('/amzn_assoc_placement/i', $value['text'])){ // continue; } // if(preg_match("/^]*>\s*document.write\([\"\']\s*
[\"\']\)\s*<\/script>$/i", $value['text'])){ if(preg_match("/amazonjs/i", $value['text'])){ continue; } } } if(preg_match('/reklamstore/i', $value['text'])){ if(preg_match("/reklamstore_region_id/i", $value['text'])){ continue; }else if(preg_match("/reklamstore\.com\/reklamstore\.js/i", $value['text'])){ continue; } } // if(preg_match("/document\.write\s*\(/i", $value['text'])){ if(preg_match("/'+ if(preg_match("/^\/\/about\:blank/", $matches[0])){ return $matches[0]; } //""; if(preg_match("/^\/\/www\'/", $matches[0])){ return $matches[0]; } // if(URL.match( /^https?:\/\// ) ){ if(preg_match("/^\/\/\s*\)\s*\)\s*\{/", $matches[0])){ return $matches[0]; } // "string".replace(/\//,3); if(preg_match("/^\/\/\s*\,/", $matches[0])){ return $matches[0]; } // src = src.replace('https?://[^./].',''); if(preg_match("/^\/\/\[[^\]\[]+\]/", $matches[0])){ return $matches[0]; } // comments: /\/\*[^*]*\*+([^/][^*]*\*+)*\//gi, if(preg_match("/^\/\/\s*gi\s*\,/", $matches[0])){ return $matches[0]; } // var proto = document.location.protocol, host = "whatshelp.io", url = proto + "//static." + host; if(preg_match("/^\/\/static\./i", $matches[0])){ return $matches[0]; } // whatsapp://send?text= // NOTE: preg_match_replace gets only 5 chars so we check "tsapp://" instead of "whatsapp://" if(preg_match("/^tsapp\:\/\/send/", $matches[0])){ return $matches[0]; } // sms://?&body="+postTitle+" "+postUrl if(preg_match("/^\/\/\?\&/", $matches[0])){ return $matches[0]; } // viber://forward?text="+postTitle+" "+postUrl if(preg_match("/^viber\:\/\//", $matches[0])){ return $matches[0]; } //threema://compose?text="+postTitle+" "+postUrl if(preg_match("/^reema\:\/\//", $matches[0])){ return $matches[0]; } // weixin:// if(preg_match("/^eixin\:\/\//", $matches[0])){ return $matches[0]; } // fb-messenger://share? if(preg_match("/^enger\:\/\//", $matches[0])){ return $matches[0]; } // rtmp://37.77.2.234:1935/redirect/live.flv if(preg_match("/^rtmp\:\/\//", $matches[0])){ return $matches[0]; } // comgooglemaps://?q=40.956572,29.0859053&directionsmode=driving if(preg_match("/^emaps\:\/\//", $matches[0])){ return $matches[0]; } // javascript:// if(preg_match("/^cript\:\/\//", $matches[0])){ return $matches[0]; } // jsFileLocation:"//29.59.155.173/~cfo/site-data/plugins/revslider/public/assets/js/", if(preg_match("/^\/\/([0-9]{1,3}\.){3}[0-9]{1,3}\/\~/", $matches[0])){ return $matches[0]; } // var url = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi; if(preg_match("/\/\/\=\]/", $matches[0])){ return $matches[0]; } if(preg_match("/^maps\:\/\//", $matches[0])){ return $matches[0]; } // "line://msg/text/" + postTitle + "! " + postUrl if(preg_match("/^line\:\/\//", $matches[0])){ return $matches[0]; } // document.write(''); if(preg_match("/^\/\/\:\"/", $matches[0])){ return $matches[0]; } // url: "//$1/p/$2/media/?size=l" if(preg_match("/^\/\/\\$/", $matches[0])){ return $matches[0]; } if(preg_match("/^\/\/\//", $matches[0])){ return $matches[0]; } if(preg_match("/^http/", $matches[0])){ return $matches[0]; } // var xxx={"case":"\nhttp://www.google.com"}; if(preg_match("/^nhttp/", $matches[0])){ return $matches[0]; } // var currUrl = 'file://' + "something"; if(preg_match("/^file\:\/\//i", $matches[0])){ return $matches[0]; } // if(preg_match("/cript\:\/\/nop/i", $matches[0])){ return $matches[0]; } // Flash.RTMP_RE = /^rtmp[set]?:\/\//i; if(preg_match("/^\/\/i\;/", $matches[0])){ return $matches[0]; } //segs.unshift('//*[@id="' + elm.getAttribute('id') + '"]'); if(preg_match("/^\/\/\*\[/", $matches[0])){ return $matches[0]; } // e.write('') if(preg_match("/^\/\/W3C\/\/DTD\s+XHTML/i", $matches[0])){ return $matches[0]; } // var sourceURL = '\n/*\n//# sourceURL=' + (options.sourceURL || '/lodash/template/source[' + (templateCounter++) + ']') + '\n*/'; // var xxx = "} catch (e){ throw 'TemplateError: ' + e + ' (on " + name + "' + ' line ' + this.line + ')'; } " + "//@ sourceURL=" + name + "\n" // source map if(preg_match("/^\/\/(\#|\@)\s+sourceURL/i", $matches[0])){ return $matches[0]; } // options.tileLayerThem = '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; if(preg_match("/^\/\/\{[^\}]+\}\./", $matches[0])){ return $matches[0]; } // document.write("<"+"script defer src=\"//:\" id=\"__onload_ie_pixastic__\">"); if(preg_match("/^\/\/\:\\\\(\"|\')/", $matches[0])){ return $matches[0]; } // a.src='//cdn.'+w[r+'h']+'/libs/b.js'; if(preg_match("/^\/\/cdn\./", $matches[0])){ return $matches[0]; } //\x3c/script> if(preg_match("/x3c\/script>/i", $matches[0])){ return $matches[0]; } return ''; } if(preg_match("/<\/script>/", $matches[0])){ return preg_replace("/\/\/[^\<]+<\/script>/", '', $matches[0]); } return ''; } static function minify_js_in_body($exclude_rules = false){ global $speedycache; $data = $speedycache->enhanced['html']; $script_list = array(); $script_start_index = false; for($i = 0; $i < strlen( $data ); $i++){ if(isset($data[$i - 6])){ if(substr($data, $i - 6, 7) == ''){ array_push($script_list, array('start' => $script_start_index, 'end' => $i)); $script_start_index = false; } } } if(empty($script_list)){ return $speedycache->enhanced['html']; } foreach(array_reverse($script_list) as $key => $value){ $script_tag = substr($data, $value['start'], ($value['end'] - $value['start'] + 1)); if(!preg_match("/^\<]+src\=[^\>\<]+>/i", $script_tag) && preg_match("/\/speedycache\-assets\//i", $script_tag)){ continue; } preg_match("/src\=[\"\']([^\'\"]+)[\"\']/i", $script_tag, $src); $http_host = str_replace(array('http://', 'www.'), '', sanitize_text_field($_SERVER['HTTP_HOST'])); if(!isset($src[1])){ continue; } if(!preg_match('/'.preg_quote($http_host, '/').'/i', $src[1])){ continue; } if(!empty($exclude_rules)){ $is_excluded = false; foreach((array)$exclude_rules as $exclude_key => $exclude_value){ if(!empty($exclude_value['prefix']) && $exclude_value['type'] === 'js'){ if($exclude_value['prefix'] === 'contain'){ $preg_match_rule = preg_quote($exclude_value['content'], '/'); } if(preg_match('/'.$preg_match_rule.'/i', $src[1])){ $is_excluded = true; break; } } } if(!empty($is_excluded)){ continue; } } // Skip if the file is already minified. if(strpos($src[1], '.min.') !== FALSE){ continue; } if(preg_match("/alexa\.com\/site\_stats/i", $src[1])){ continue; } if(preg_match("/wp-spamshield\/js\/jscripts\.php/i", $src[1])){ continue; } //amazonjs/components/js/jquery-tmpl/jquery.tmpl.min.js?ver=1.0.0pre if(preg_match("/jquery-tmpl\/jquery\.tmpl\.min\.js/i", $src[1])){ continue; } // if(preg_match("/[\?\=].*".preg_quote($http_host, '/').'/i', $src[1])){ continue; } $js_file_name = md5($src[1]); $cache_file_path = WP_CONTENT_DIR.'/'.$speedycache->enhanced['cache_speedycache_minified'].'/'.$js_file_name; if(!defined('SPEEDYCACHE_WP_CONTENT_URL')){ $js_script = content_url().'/'.$speedycache->enhanced['cache_speedycache_minified'].'/'.$js_file_name; }else{ $js_script = SPEEDYCACHE_WP_CONTENT_URL.'/'.$speedycache->enhanced['cache_speedycache_minified'].'/'.$js_file_name; } $js_script = str_replace(array('http://', 'https://'), '//', $js_script); $args = array( 'src' => $src[1], 'cache_file_path' => $cache_file_path, 'js_script' => $js_script, 'script_tag' => $script_tag, 'value' => $value ); self::fetch_and_minify_js($args); } return $speedycache->enhanced['html']; } static function fetch_and_minify_js($args){ global $speedycache; $response = wp_remote_get(\SpeedyCache\Enhanced::fix_protocol($args['src']), array('timeout' => 10 ) ); if(empty($response) || is_wp_error($response)){ return false; } if(wp_remote_retrieve_response_code($response) != 200){ return false; } $js_content = wp_remote_retrieve_body($response); if(preg_match('/<\/\s*html\s*>\s*$/i', $js_content)){ return false; } $minified_js_content = \SpeedyCache\Enhanced::minify_js($js_content); if(!is_dir($args['cache_file_path'])){ $prefix = time(); \SpeedyCache\Cache::create_dir($args['cache_file_path'], $minified_js_content, 'js'); } if(file_exists($args['cache_file_path']) && $js_files = @scandir($args['cache_file_path'], 1)){ $new_script = str_replace($args['src'], $args['js_script'].'/'.$js_files[0], $args['script_tag']); $speedycache->enhanced['html'] = substr_replace($speedycache->enhanced['html'], $new_script, $args['value']['start'], ($args['value']['end'] - $args['value']['start'] + 1)); } } static function combine_js_in_footer($minify = false){ global $speedycache; $footer = strstr($speedycache->enhanced['html'], ''); \SpeedyCache\JS::init($footer, $minify); $tmp_footer = \SpeedyCache\JS::combine(); if(!empty($speedycache->options['render_blocking'])){ \SpeedyCache\RenderBlocking::init($tmp_footer); $tmp_footer = \SpeedyCache\RenderBlocking::action(false, true); } $speedycache->enhanced['html'] = str_replace($footer, $tmp_footer, $speedycache->enhanced['html']); return $speedycache->enhanced['html']; } /* Js Part End */ static function fix_protocol($url){ if(!preg_match('/^\/\//', $url)){ return $url; } if(preg_match('/^https:\/\//', home_url())){ return 'https:'.$url; } return 'http:'.$url; } static function set_html($html){ global $speedycache; $speedycache->enhanced['html'] = $html; self::set_head_html(); self::set_body_html(); } static function set_body_html(){ global $speedycache; preg_match("//si", $speedycache->enhanced['html'], $out); if(isset($out[0])){ $speedycache->enhanced['body_html'] = $out[0]; return; } $speedycache->enhanced['body_html'] = ''; } static function set_head_html(){ global $speedycache; preg_match("//si", $speedycache->enhanced['html'], $out); if(isset($out[0])){ $speedycache->enhanced['head_html'] = $out[0]; return; } $speedycache->enhanced['head_html'] = ''; } static function delay_js($content){ global $speedycache; // If Delay js mode is selected and the scripts are empty then return if(empty($speedycache->options['delay_js_mode']) || (!empty($speedycache->options['delay_js_mode']) && $speedycache->options['delay_js_mode'] == 'selected' && empty($speedycache->options['delay_js_scripts']))){ return $content; } $scripts = self::find_tags('', $content); if(empty($scripts)){ return $content; } foreach($scripts as $tag => $script){ // Dont process a tag without src if(strpos($script['text'], ' src') === FALSE){ continue; } // Don't delay a module. if(strpos($script['text'], 'type="module"') !== FALSE){ continue; } // Don't touch any import maps as they are meant to be loaded early. if(strpos($script['text'], 'importmap') !== FALSE){ continue; } // We dont want to delay jQuery if(preg_match('/jquery\./U', $script['text'], $match)){ continue; } // Excluding Scripts if($speedycache->options['delay_js_mode'] == 'all' && !empty($speedycache->options['delay_js_excludes'])){ $script_matched = false; foreach($speedycache->options['delay_js_excludes'] as $to_delay){ if(empty($to_delay)){ continue; } if(strpos($script['text'], $to_delay) !== FALSE){ $script_matched = true; } } if(!empty($script_matched)){ continue; } } // Delay Selected Scripts if($speedycache->options['delay_js_mode'] == 'selected' && !empty($speedycache->options['delay_js_scripts'])){ $script_found = false; foreach($speedycache->options['delay_js_scripts'] as $to_delay){ if(empty($to_delay)){ continue; } if(strpos($script['text'], $to_delay) !== FALSE){ $script_found = true; break; } } if(empty($script_found)){ continue; } } $new_tag = self::updating_tag($script['text']); if(!empty($new_tag)){ $content = str_replace($script['text'], $new_tag, $content); } } // Adds the script which loads the JS files on user interaction self::inject_js($content); return $content; } static function updating_tag($tag){ global $speedycache; if(preg_match('/src=["\'](.*)["\']/U', $tag, $src)){ return ''; } } static function inject_js(&$content){ $js = file_get_contents(SPEEDYCACHE_PRO_DIR . '/assets/js/delayjs.min.js'); $js = ''; $content = str_replace('', $js . "\n", $content); } static function find_tags($start_string, $end_string, $html = false){ global $speedycache; if(!empty($html)){ $data = $html; } $list = array(); $start_index = false; $end_index = false; for($i = 0; $i < strlen($data); $i++){ if(substr($data, $i, strlen($start_string)) == $start_string){ if(!$start_index && !$end_index){ $start_index = $i; } } if(empty($start_index) || $i < $start_index){ continue; } if(substr($data, $i, strlen($end_string)) !== $end_string){ continue; } $end_index = $i + strlen($end_string) - 1; $text = substr($data, $start_index, ($end_index - $start_index + 1)); if($html === false){ $tag = self::get_tags($start_index, $text, $end_index); if($tag !== FALSE){ array_push($list, $tag); } }else{ array_push($list, array('start' => $start_index, 'end' => $end_index, 'text' => $text)); } $start_index = false; $end_index = false; } return $list; } // Adds Image dimensions to the images where height and width is not present // It helps in reducing the Cumulative Layout shift(CLS) as the browser knows how much space to allocate for the image. static function image_dimensions($content){ if(!function_exists('getimagesize')){ return $content; } // Get Images without height and width $images_regex = '](?!height=[\'\"](?:\S+)[\'\"]))*+>|](?!width=[\'\"](?:\S+)[\'\"]))*+>'; preg_match_all('/'.$images_regex.'/Uis', $content, $image_matches); if(empty($image_matches)){ return $content; } $images = $image_matches[0]; $site_url = site_url(); foreach($images as $image){ // Get the SRC if(!preg_match( '/\s+src\s*=\s*[\'"](?[^\'"]+)/i', $image, $src_match)){ continue; } $url = $src_match['url']; // We will proccess image which is uploaded inside wp-content if(strpos($url, 'wp-content') === FALSE || strpos($url, '.svg') !== FALSE || strpos($url, $site_url) === FALSE){ continue; } $url = str_replace($site_url, '', $url); $image_path = str_replace('/wp-content', '', WP_CONTENT_DIR) . $url; if(!file_exists($image_path)){ continue; } $sizes = getimagesize($image_path); if(empty($sizes)){ continue; } preg_match('/[^\'\"\s]+)[\'\"]?.*>/i', $image, $initial_height); preg_match('/[^\'\"\s]+)[\'\"]?.*>/i', $image, $initial_width); $dimensions_attr = ''; if(empty($initial_height['height']) && empty($initial_width['width'])){ $dimensions_attr = $sizes[3]; } if(!empty($initial_height['height']) && empty($dimensions_attr)){ if(!is_numeric($initial_height['height'])){ continue; } $ratio = $initial_height['height'] / $sizes[1]; $dimensions_attr = 'width="' . (int) round($sizes[0] * $ratio) . '" height="' . $initial_height['height'] . '"'; } if(!empty($initial_width['width']) && empty($dimensions_attr)){ if(!is_numeric( $initial_width['width'])){ continue; } $ratio = $initial_width['width'] / $sizes[0]; $dimensions_attr = 'width="' . $initial_width['width'] . '" height="' . (int) round($sizes[1] * $ratio) . '"'; } $changed_image = preg_replace('/\s(height|width)=(?:[\'"]?(?:[^\'\"\s]+)*[\'"]?)?/i', '', $image); $changed_image = preg_replace('/<\s*img/i', '', '', $content); return $content; } static function preload_critical_images($content){ global $speedycache; preg_match_all('#(]+?)\/?>(?><\/picture>)?#is', $content, $images, PREG_SET_ORDER); if(empty($images)){ return $content; } $count = 0; $preload_tags = ''; foreach($images as $image){ // Break once the Critical Image Count is reached. if($count >= $speedycache->options['critical_image_count']){ break; } if(strpos($image[0], 'secure.gravatar.com') !== FALSE){ continue; } // NOTE:: Will remove this in future, firt we will just support tag if(strpos($image[0], '') !== FALSE){ continue; } // Excluding base64 image from preloading. if(strpos($image[0], ';base64') !== FALSE){ continue; } $atts_array = wp_kses_hair($image[2], wp_allowed_protocols()); $atts = []; foreach($atts_array as $name => $attr){ $atts[$name] = $attr['value']; } if(empty($atts['src'])){ continue; } // To preload unique images. if(strpos($preload_tags, $atts['src']) === FALSE){ $preload_tags .= ''; } $count++; } if(empty($preload_tags)){ return $content; } // If title tag is not there then don't add the preload. if(strpos($content, '') === FALSE){ return $content; } $content = str_replace('', '' . $preload_tags, $content); return $content; } static function pre_connect_hint($urls, $relation_type){ global $speedycache; if($relation_type !== 'preconnect'){ return $urls; } foreach($speedycache->options['pre_connect_list'] as $url) { if(empty($url) || empty($url['resource'])){ continue; } $preconnect = array('href' => $url['resource']); if(!empty($url['crossorigin'])){ $preconnect['crossorigin'] = 'crossorigin'; } $urls[] = $preconnect; } return $urls; } static function preload_resource(){ global $speedycache; if(empty($speedycache->options['preload_resource_list']) || !is_array($speedycache->options['preload_resource_list'])){ return; } foreach($speedycache->options['preload_resource_list'] as $preload_resource){ if(empty($preload_resource['resource']) || empty($preload_resource['type'])){ continue; } $crossorigin = ''; if(!empty($preload_resource['crossorigin'])){ $crossorigin = 'crossorigin'; } echo ''; } } } main/metaboxpro.php000064400000003743147577727020010412 0ustar00options['critical_css'])){ return ''; } $post_meta = get_post_meta($post_id, 'speedycache_post_meta', true); $html = '
'.esc_html__('Disable CriticalCSS', 'speedycache').'

Critical CSS

Create Crtical CSS for this page

'; return $html; } static function enqueue_scripts(){ global $speedycache, $post; if(empty($speedycache->options['critical_css'])){ return; } wp_enqueue_script('speedycache_metabox', SPEEDYCACHE_PRO_URL . '/assets/js/metabox.js', array('jquery'), SPEEDYCACHE_PRO_VERSION, true); wp_localize_script('speedycache_metabox', 'speedycache_metabox', array( 'nonce' => wp_create_nonce('speedycache_nonce'), 'post_id' => !empty($post->ID) ? $post->ID : '', 'url' => admin_url('admin-ajax.php') )); } // Filter to sets options to be saved for post meta static function options($options){ global $speedycache; if(empty($options)){ $options = []; } if(!is_array($options)){ $options = [$options]; } if(!empty($speedycache->options['critical_css'])){ $options[] = 'disable_critical_css'; } return $options; } } main/premium.php000064400000000606147577727020007703 0ustar00query("DELETE FROM `$wpdb->options` WHERE option_name LIKE '%\_transient\_%' ;"); wp_send_json(array('success' => true)); } if($type === 'expired_transient'){ $wpdb->query("DELETE FROM `$wpdb->options` WHERE option_name LIKE '_transient_timeout%' AND option_value < " . time()); wp_send_json(array('success' => true)); } if($type === 'trackback_pingback'){ $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback' ;"); wp_send_json(array('success' => true)); } if($type === 'trashed_spam_comments'){ $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_approved = 'spam' OR comment_approved = 'trash' ;"); wp_send_json(array('success' => true)); } if($type === 'trashed_contents'){ $wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_status = 'trash';"); wp_send_json(array('success' => true)); } if($type === 'post_revisions'){ $wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_type = 'revision';"); wp_send_json(array('success' => true)); } if($type === 'all_warnings'){ $wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_type = 'revision';"); $wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_status = 'trash';"); $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_approved = 'spam' OR comment_approved = 'trash' ;"); $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback' ;"); $wpdb->query("DELETE FROM `$wpdb->options` WHERE option_name LIKE '%\_transient\_%' ;"); $wpdb->query("DELETE FROM `$wpdb->options` WHERE option_name LIKE '_transient_timeout%' AND option_value < " . time()); wp_send_json(array('success' => true)); } } } main/unusedcss.php000064400000016717147577727020010253 0ustar00license['license'])){ self::log('speedycache_unused_css_logs', 'License Not found, please link your License'); return false; } foreach($urls as $url){ // Handeling php timeout here if($time < time()){ $urls = array_diff($urls, $attempted_url); self::schedule('speedycache_unused_css', $urls); return; } $url = trim($url, '/'); $license = strpos($speedycache->license['license'], 'SPDFY') !== 0 ? '' : $speedycache->license['license']; $attempted_url[] = $url; $response = wp_remote_post($api, array( 'timeout' => 30, 'body' => array( 'url' => $url, 'license' => $license, 'excludes' => !empty($speedycache->options['unused_css_exclude_stylesheets']) ? json_encode($speedycache->options['unused_css_exclude_stylesheets']) : '', 'include_selectors' => !empty($speedycache->options['speedycache_unusedcss_include_selector']) ? json_encode($speedycache->options['speedycache_unusedcss_include_selector']) : '', ), 'sslverify' => false, )); if(is_wp_error($response)){ $error = $response->get_error_message(); self::log('speedycache_unused_css_logs', $response->get_error_message(), $url); continue; } $body = json_decode(wp_remote_retrieve_body($response), true); if(empty($body)){ $error = __('The response recieved is empty.', 'speedycache'); self::log('speedycache_unused_css_logs', __('The response recieved is empty.', 'speedycache'), $url); continue; } if(empty($body['success'])){ $error = !empty($body['message']) ? wp_strip_all_tags($body['message']) : __('Unable to extract UsedCSS', 'speedycache'); self::log('speedycache_unused_css_logs', !empty($body['message']) ? wp_strip_all_tags($body['message']) : __('Unable to extract UsedCSS', 'speedycache'), $url); continue; } if(empty($body['css']) || strlen($body['css']) < 20){ $error = __('Was unable to generate Used CSS', 'speedycache'); self::log('speedycache_unused_css_logs', __('Was unable to generate Used CSS', 'speedycache'), $url); continue; } self::update_css($url, $body['css']); self::log('speedycache_unused_css_logs', 'success', $url); //Updates the log on success if(!empty($error)){ return $error; } return true; } } // Adds the generated css and asynchronyses the css includes static function update_css($url, $css){ global $speedycache; if(empty($url)){ return false; } if(empty($css)){ return false; } $css = ''; $url = parse_url($url); $uri = !empty($url['path']) ? $url['path'] : ''; $cache_loc = $uri . '/index.html'; if(empty($cache_loc)){ return; } if(!empty($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] === 'SpeedyCacheTest'){ $cache_path = speedycache_cache_path('test' . $cache_loc); } else { $cache_path = speedycache_cache_path('all' . $cache_loc); } $cache_path = rtrim($cache_path, '/'); // For Desktop \SpeedyCache\UnusedCss::update_cached($cache_path, $css); if(!empty($speedycache->options['mobile_theme']) && $_SERVER['HTTP_USER_AGENT'] !== 'SpeedyCacheTest'){ $cache_mobile = speedycache_cache_path('mobile-cache' . $cache_loc); // For Mobile Cache if(file_exists($cache_mobile)){ \SpeedyCache\UnusedCss::update_cached($cache_mobile, $css); } } } // Updates the content of the cached file static function update_content($content, $css){ global $speedycache; // Includes the Used CSS file in the head. $content = str_replace('', '' . $css, $content); $css_links = '/(?=]*\s(rel\s*=\s*[\'"]stylesheet["\']))]*\shref\s*=\s*[\'"]([^\'"]+)[\'"](.*)>/iU'; preg_match_all($css_links, $content, $matches, PREG_SET_ORDER, 0); if(empty($matches)){ return $content; } $exclude_stylesheets = array( '/widget-google-reviews/assets/css/public-main.css', '/uploads/elementor/css/post-', '/uploads/oxygen/css/', '/uploads/bb-plugin/cache/', '/et-cache/', 'woocommerce-smallscreen.css', 'dashicons.min.css', 'animations.min.css', '/uploads/generateblocks/', 'woocommerce-mobile.min.css', 'fonts.googleapis.com', ); // Mergeing user added excludes which the one we have. if(!empty($speedycache->options['unused_css_exclude_stylesheets']) && !is_array($speedycache->options['unused_css_exclude_stylesheets'])){ $exclude_stylesheets = array_merge($exclude_stylesheets, $speedycache->options['unused_css_exclude_stylesheets']); } $noscript_wrap = ''; foreach($matches as $tag){ foreach($exclude_stylesheets as $style){ if(strpos($tag[0], $style) !== FALSE){ continue 2; } } // We dont want to delay te Used CSS file if(strpos($tag[0], 'unused-css') !== FALSE){ continue; } // Removing the styles after getting unused css if(!empty($speedycache->options['unusedcss_load']) && $speedycache->options['unusedcss_load'] === 'remove'){ $content = str_replace($tag[0], '', $content); } elseif(!empty($speedycache->options['unusedcss_load']) && $speedycache->options['unusedcss_load'] === 'interaction'){ $new_tag = preg_replace('#href=([\'"]).+?\1#', 'data-spcdelay="' . $tag[2] . '"',$tag[0]); $content = str_replace($tag[0], $new_tag, $content); $noscript_wrap .= $tag[0]; } else { // Loading the Unused CSS Async $preload = str_replace('stylesheet', 'preload', $tag[1]); $onload = preg_replace('~' . preg_quote($tag[3], '~') . '~iU', ' as="style" onload="" ' . $tag[3] . '>', $tag[3]); $new_tag = str_replace($tag[3] . '>', $onload, $tag[0]); $new_tag = str_replace($tag[1], $preload, $new_tag); $new_tag = str_replace('onload=""', 'onload="this.onload=null;this.rel=\'stylesheet\'"', $new_tag); $new_tag = preg_replace('/(id\s*=\s*[\"\'](?:[^\"\']*)*[\"\'])/i', '', $new_tag); $content = str_replace($tag[0], $new_tag, $content); $noscript_wrap .= $tag[0]; } } if(!empty($noscript_wrap)){ $noscript_wrap .= ''; if(!empty($speedycache->options['unusedcss_load']) && $speedycache->options['unusedcss_load'] === 'interaction'){ $noscript_wrap .= ''; } $noscript_wrap = '