<?php /* * SPEEDYCACHE * https://speedycache.com/ * (c) SpeedyCache Team */ namespace SpeedyCache; if(!defined('ABSPATH')){ die('Hacking Attempt!'); } class CommonCss{ static function get_endpoint($is_unusedcss = false){ global $speedycache; $endpoints = get_transient('speedycache_ccss_endpoint'); $target_file = empty($is_unusedcss) ? 'index.php' : 'ucss.php'; $mirror = 'https://s4.softaculous.com/a/speedycache/critical-css/' . $target_file; $license = strpos($speedycache->license['license'], 'SPDFY') !== 0 ? '' : $speedycache->license['license']; if(empty($endpoints)){ $res = wp_remote_get(SPEEDYCACHE_API.'license.php?license='.$license.'&url='.rawurlencode(site_url())); // Did we get a response ? if(!is_array($res)){ return $mirror; } if(empty($res['body'])){ return $mirror; } $body = json_decode($res['body'], true); if(empty($body['fast_mirrors'])){ return $mirror; } $endpoints = $body['fast_mirrors']; if(empty($endpoints) || !is_array($endpoints)){ return $mirror; } } $index = floor(rand(0, count($endpoints) - 1)); if(empty($endpoints[$index])){ return $mirror; } set_transient('speedycache_ccss_endpoint', $endpoints, 180); $mirror = str_replace('a/softaculous', 'a/speedycache/critical-css/'.$target_file, $endpoints[$index]); return $mirror; } static function schedule($schedule_name, $urls){ $scheduled = self::get_schedule(array($schedule_name)); $time = time(); if(!empty($scheduled) && isset(end($scheduled)['time'])){ // getting the last index to get the last scheduled event $time = end($scheduled)['time'] + 10; } $final_schd_time = $time; if(!wp_next_scheduled($schedule_name, array('urls' => $urls))){ wp_schedule_single_event($final_schd_time, $schedule_name, array('urls' => $urls)); } } // Returns an array of cron event "speedycache_unused_css" static function get_schedule($event_name){ $cron = _get_cron_array(); if(empty($cron)){ return false; } $scheduled = array(); foreach($cron as $key => $crn){ foreach($crn as $e_key => $event){ if(!in_array($e_key, $event_name)){ continue; } $args = []; foreach($event as $evt){ if(!empty($evt['args'][0])){ $args = $evt['args'][0]; } } array_push($scheduled, array('name' => get_the_title($args), 'time' => $key)); } } return $scheduled; } // Adds the Critical CSS to the cache file static function update_cached($file, $css){ global $speedycache; if(!file_exists($file)){ return; } $content = file_get_contents($file); if(empty($content)){ return; } $content = static::update_content($content, $css); // Updates the .html.gz file if(!empty($speedycache->options['gzip'])){ self::update_gzip($file, $content); } // Updates the .html file file_put_contents($file, $content); } static function update_gzip($file, $content){ $gz_file = str_replace('.html', '.html.gz', $file); if(file_exists($gz_file)){ unlink($gz_file); } $content = gzencode($content, 6); if(!empty($content)){ file_put_contents($gz_file, $content); } } static function log($log_name, $message, $url = '-'){ $ccss_logs = get_option($log_name, []); if(count($ccss_logs) > 10){ array_shift($ccss_logs); } $ccss_logs[$url] = array('time' => date('h:i:s'), 'message' => $message); update_option($log_name, $ccss_logs); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
admin.php | File | 7.37 KB | 0644 |
|
bloat.php | File | 10.14 KB | 0644 |
|
cli.php | File | 1.63 KB | 0644 |
|
commoncss.php | File | 3.61 KB | 0644 |
|
criticalcss.php | File | 9.25 KB | 0644 |
|
db.php | File | 1.99 KB | 0644 |
|
enhanced.php | File | 45.29 KB | 0644 |
|
googlefonts.php | File | 5.57 KB | 0644 |
|
image.php | File | 70.58 KB | 0644 |
|
index.html | File | 91 B | 0644 |
|
lazyload.php | File | 14.7 KB | 0644 |
|
license.php | File | 4.04 KB | 0644 |
|
logs.php | File | 7.42 KB | 0644 |
|
metaboxpro.php | File | 1.97 KB | 0644 |
|
mobile.php | File | 1.57 KB | 0644 |
|
object-cache-lib.php | File | 10.86 KB | 0644 |
|
objectcache.php | File | 7.95 KB | 0644 |
|
plugin-update-checker.php | File | 52.86 KB | 0644 |
|
premium.php | File | 390 B | 0644 |
|
prooptimizations.php | File | 2.1 KB | 0644 |
|
renderblocking.php | File | 36.64 KB | 0644 |
|
settingspage.php | File | 33.3 KB | 0644 |
|
statistics.php | File | 4.28 KB | 0644 |
|
unusedcss.php | File | 7.45 KB | 0644 |
|
youtube.html | File | 2.29 KB | 0644 |
|