<?php
class WpFastestCacheImageOptimisation{
public $uploadDir;
private $id = false;
private $metadata = array();
private $name = "";
private $path = "";
private $url = "";
private $images = array();
private $images_clone = array();
private $location = "";
public function __construct(){
if(isset($_GET["id"]) && $_GET["id"]){
$this->id = intval($_GET["id"]);
}
$this->create_api_key();
$this->uploadDir = wp_upload_dir();
}
public function create_api_key(){
if(!get_option("WpFc_api_key")){
update_option("WpFc_api_key", md5(microtime(true)));
}
}
public function get_template_path($file_name){
return WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/templates/".$file_name;
}
public function get_total_reduction_image_number(){
global $wpdb;
$query = "SELECT sum(`meta_value`) as total FROM `".$wpdb->prefix."postmeta` WHERE `meta_key`= 'wpfc_optimisation_reduction'";
$result = $wpdb->get_row( $query );
if($result->total){
return ($result->total && $result->total > 0) ? $result->total : 0;
}else{
return 0;
}
}
public function get_total_optimized_image_number(){
$query_images_args = array();
$query_images_args['post_type'] = 'attachment';
$query_images_args['post_mime_type'] = array('image/jpeg', 'image/png');
$query_images_args['post_status'] = 'inherit';
$query_images_args['posts_per_page'] = -1;
$query_images_args['meta_query'] = array(
array(
'key' => 'wpfc_optimisation',
'compare' => 'EXISTS'
),
array(
'key' => 'wpfc_optimisation',
'value' => base64_encode('"destination_path"'),
'compare' => 'LIKE'
)
);
return $this->get_count_only($query_images_args);
}
public function get_total_image_error_number(){
$query_images_args = array();
$query_images_args['post_type'] = 'attachment';
$query_images_args['post_mime_type'] = array('image/jpeg', 'image/png');
$query_images_args['post_status'] = 'inherit';
$query_images_args['posts_per_page'] = -1;
$query_images_args['meta_query'] = array(
array(
'key' => 'wpfc_optimisation',
'compare' => 'EXISTS'
),
array(
'key' => 'wpfc_optimisation',
'value' => base64_encode('"error_code"'),
'compare' => 'LIKE'
)
);
return $this->get_count_only($query_images_args);
}
public function null_posts_groupby(){
return "";
}
public function count_posts_fields(){
return "COUNT(*) as post_count_wpfc";
}
public function get_count_only($query_images_args){
add_filter( 'posts_fields', array($this,'count_posts_fields'));
add_filter( 'posts_groupby', array($this, 'null_posts_groupby'));
unset($query_images_args["offset"]);
unset($query_images_args["order"]);
unset($query_images_args["orderby"]);
$query_images_args['posts_per_page'] = -1;
$query_image = new WP_Query( $query_images_args );
return $query_image->posts[0]->post_count_wpfc;
}
public function get_total_image_number(){
$query_images_args = array();
$query_images_args['post_type'] = 'attachment';
$query_images_args['post_mime_type'] = array('image/jpeg', 'image/png');
$query_images_args['post_status'] = 'inherit';
$query_images_args['posts_per_page'] = -1;
$query_images_args['meta_query'] = array(
array(
'key' => '_wp_attachment_metadata',
'compare' => 'EXISTS'
)
);
return $this->get_count_only($query_images_args);
}
public function get_total_pending_image_number(){
$query_images_args = array();
$query_images_args['post_type'] = 'attachment';
$query_images_args['post_mime_type'] = array('image/jpeg', 'image/png');
$query_images_args['post_status'] = 'inherit';
$query_images_args['posts_per_page'] = -1;
$query_images_args['meta_query'] = array(
array(
'key' => '_wp_attachment_metadata',
'compare' => 'EXISTS'
),
array(
'key' => 'wpfc_optimisation',
'compare' => 'NOT EXISTS'
)
);
return $this->get_count_only($query_images_args);
}
public function hook(){
add_action('wp_ajax_wpfc_revert_image_ajax_request', array($this, "wpfc_revert_image_ajax_request"));
add_action('wp_ajax_wpfc_statics_ajax_request', array($this, "wpfc_statics_ajax_request"));
add_action('wp_ajax_wpfc_optimize_image_ajax_request', array($this, "wpfc_optimize_image_ajax_request"));
add_action('wp_ajax_wpfc_update_image_list_ajax_request', array($this, "wpfc_update_image_list_ajax_request"));
}
public function get_not_optimized_before(){
$tmp_image = array();
$valueJson = get_post_meta($this->id, 'wpfc_optimisation', true);
$tmpvalueJson = base64_decode($valueJson);
if($tmpvalueJson){
$std = json_decode($tmpvalueJson);
$metaOptimized = $this->object_to_array($std);
$percentage = count($metaOptimized)*100/count($this->images);
}else{
$percentage = 100/count($this->images);
return array("metaOptimized" => array(), "images" => array_slice($this->images, 0, 1), "total_reduction" => 0, "percentage" => $percentage);
}
foreach ($this->images as $key => $value) {
$exist = false;
foreach ($metaOptimized as $meta_key => $meta_value) {
if($value["file"] == $meta_value["file"]){
$exist = true;
//break;
}
}
if(!$exist){
array_push($tmp_image, $value);
}
}
//START: total reduction
$total_reduction = 0;
foreach ($metaOptimized as $m_key => $m_value) {
$m_value["reduction"] = isset($m_value["reduction"]) ? $m_value["reduction"] : 0;
$total_reduction += $m_value["reduction"];
}
//END: total reduction
if(count($tmp_image) > 0){
if(isset($_GET["last"])){
if(preg_match("/last-(\d+)/", $_GET["last"], $last_number)){
if(count($tmp_image) > 5){
$tmp_image = array_slice($tmp_image, $last_number[1]*-1, 1);
}
}
}
return array("metaOptimized" => $metaOptimized, "images" => array_slice($tmp_image, 0, 1), "total_reduction" => $total_reduction, "percentage" => $percentage);
}else{
return array("metaOptimized" => array(), "images" => array(), "total_reduction" => 0);
}
}
public function object_to_array($obj) {
if(is_object($obj)) $obj = (array) $obj;
if(is_array($obj)) {
$new = array();
foreach($obj as $key => $val) {
$new[$key] = $this->object_to_array($val);
}
}
else $new = $obj;
return $new;
}
public function re_order_by_dimensions(){
$tmp = $this->images;
foreach ($tmp as $key => $value) {
$width_list[$key] = $value['width'];
}
array_multisort($width_list, SORT_DESC, $tmp);
return $tmp;
}
public function optimizeFirstImage(){
return array("", "unlock this");
$this->setId();
$this->setMetaData();
$this->set_server_location();
if(!$this->id){
return array("finish", "success");
}else if(!isset($this->metadata["file"]) && $this->id){
$metaOptimized = array();
$metaOptimized[0]["time"] = time();
$metaOptimized[0]["id"] = $this->id;
$metaOptimized[0]["error_code"] = 17;
update_post_meta($this->id, 'wpfc_optimisation_reduction', 0);
update_post_meta($this->id, 'wpfc_optimisation', base64_encode(json_encode($metaOptimized)));
return array("Image has been optimizedxx", "success", $this->id, 100);
}else{
$this->setName();
$this->setPath();
$this->setUrl();
$this->setImages();
}
if($this->id && count($this->images) == 0){
$metaOptimized = array();
$metaOptimized[0]["time"] = time();
$metaOptimized[0]["id"] = $this->id;
$metaOptimized[0]["error_code"] = 18;
update_post_meta($this->id, 'wpfc_optimisation_reduction', 0);
没有合适的资源?快使用搜索试试~ 我知道了~
WP Fastest Cache Premium -WP最快的缓存 v1.6.4
共38个文件
php:16个
html:10个
png:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 11 浏览量
2022-06-24
14:34:43
上传
评论
收藏 72KB ZIP 举报
温馨提示
WP Fastest Cache 是一个多功能缓存插件,通过创建HTML文件来帮助减少您网站的页面加载时间,由于 WordPress 网站是通过 PHP 和 MySQL数据库呈现的,因此每次从服务器请求页面时都需要使用 RAM 和 CPU,会减慢加载时间,并在用户的计算机或设备以及数据库上投入更多精力。但是,使用缓存系统,页面会呈现一次,然后存储为静态 HTML 文件,从而减少每个新访问者的加载时间。
资源推荐
资源详情
资源评论
收起资源包目录
wp-fastest-cache-premium-1_.6.4.zip_2.zip (38个子文件)
wp-fastest-cache-premium-1_.6.4
pro
images
de.png 461B
nl.png 427B
sg.png 547B
pl.png 380B
blank.gif 43B
hk.png 890B
bg.png 427B
gb.png 1KB
us.png 571B
templates
cache-statics.html 2KB
empty_image_line.html 99B
lazy-load.php 12KB
image_line_first.html 903B
image-statics.php 7KB
index.html 18B
paging.html 2KB
image_line.html 732B
youtube.html 2KB
mobile_theme.php 3KB
buy_credit.php 3KB
library
update.php 6KB
logs.php 7KB
lazy-load.php 15KB
index.html 18B
db.php 2KB
admin.php 3KB
render-blocking.php 37KB
widget-cache.php 5KB
statics.php 1KB
mobile-cache.php 1KB
image.php 44KB
powerful-html.php 37KB
index.html 18B
js
statics.js 21KB
lazy-load-new.js 5KB
lazy-load.js 1KB
wpFastestCachePremium.php 7KB
index.html 18B
共 38 条
- 1
资源评论
一路有你网络科技工作室
- 粉丝: 3
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功