Version Description
- Optimize on upload
- Statistics
- Log services
- Interface rebuild
- News feed from feed.resmush.it
Download this release
Release Info
Developer | maecia |
Plugin | reSmush.it Image Optimizer |
Version | 0.1.1 |
Comparing to | |
See all releases |
Version 0.1.1
- classes/resmushit.class.php +244 -0
- classes/resmushitUI.class.php +279 -0
- css/resmushit.css +207 -0
- images/clock.gif +0 -0
- images/header.jpg +0 -0
- images/logo.png +0 -0
- images/maecia.png +0 -0
- images/ok.png +0 -0
- images/twitter.png +0 -0
- images/warning.png +0 -0
- js/script.js +113 -0
- readme.txt +49 -0
- resmushit.admin.php +79 -0
- resmushit.inc.php +25 -0
- resmushit.php +186 -0
- resmushit.settings.php +10 -0
classes/resmushit.class.php
ADDED
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ReSmushit
|
5 |
+
*
|
6 |
+
*
|
7 |
+
* @package Resmush.it
|
8 |
+
* @subpackage Controller
|
9 |
+
* @author Charles Bourgeaux <contact@resmush.it>
|
10 |
+
*/
|
11 |
+
Class reSmushit {
|
12 |
+
|
13 |
+
const MAX_FILESIZE = 2097152;
|
14 |
+
|
15 |
+
/**
|
16 |
+
*
|
17 |
+
* Optimize a picture according to a filepath.
|
18 |
+
*
|
19 |
+
* @param string $file_path the path to the file on the server
|
20 |
+
* @return bool TRUE if the resmush operation worked
|
21 |
+
*/
|
22 |
+
public static function getPictureQuality() {
|
23 |
+
if(get_option( 'resmushit_qlty' ))
|
24 |
+
return get_option( 'resmushit_qlty' );
|
25 |
+
else
|
26 |
+
return RESMUSHIT_QLTY;
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
*
|
31 |
+
* Optimize a picture according to a filepath.
|
32 |
+
*
|
33 |
+
* @param string $file_path the path to the file on the server
|
34 |
+
* @return bool TRUE if the resmush operation worked
|
35 |
+
*/
|
36 |
+
public static function optimize($file_path = NULL, $is_original = TRUE) {
|
37 |
+
global $wp_version;
|
38 |
+
|
39 |
+
if(filesize($file_path) > self::MAX_FILESIZE)
|
40 |
+
return false;
|
41 |
+
|
42 |
+
$ch = curl_init();
|
43 |
+
curl_setopt($ch, CURLOPT_URL, RESMUSHIT_ENDPOINT);
|
44 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
45 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, RESMUSHIT_TIMEOUT);
|
46 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
47 |
+
curl_setopt($ch, CURLOPT_USERAGENT, "Wordpress $wp_version/Resmush.it " . RESMUSHIT_VERSION );
|
48 |
+
|
49 |
+
if (!class_exists('CURLFile')) {
|
50 |
+
$arg = array('files' => '@' . $file_path);
|
51 |
+
} else {
|
52 |
+
$cfile = new CURLFile($file_path);
|
53 |
+
$arg = array(
|
54 |
+
'files' => $cfile,
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
+
$arg['qlty'] = self::getPictureQuality();
|
59 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $arg);
|
60 |
+
|
61 |
+
$data = curl_exec($ch);
|
62 |
+
curl_close($ch);
|
63 |
+
|
64 |
+
$json = json_decode($data);
|
65 |
+
if($json){
|
66 |
+
if (!isset($json->error)) {
|
67 |
+
$data = file_get_contents($json->dest);
|
68 |
+
if ($data) {
|
69 |
+
if($is_original){
|
70 |
+
$originalFile = pathinfo($file_path);
|
71 |
+
$newPath = $originalFile['dirname'] . '/' . $originalFile['filename'] . '-unsmushed.' . $originalFile['extension'];
|
72 |
+
copy($file_path, $newPath);
|
73 |
+
}
|
74 |
+
file_put_contents($file_path, $data);
|
75 |
+
rlog("Picture " . $file_path . " optimized from " . reSmushitUI::sizeFormat($json->src_size) . " to " . reSmushitUI::sizeFormat($json->dest_size));
|
76 |
+
return $json;
|
77 |
+
}
|
78 |
+
} else {
|
79 |
+
rlog("Webservice returned the following error while optimizing $file_path : Code #" . $json->error . " - " . $json->error_long);
|
80 |
+
}
|
81 |
+
} else {
|
82 |
+
rlog("Cannot establish connection with reSmush.it webservice while optimizing $file_path (timeout of " . RESMUSHIT_TIMEOUT . "sec.)");
|
83 |
+
}
|
84 |
+
return false;
|
85 |
+
}
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
/**
|
90 |
+
*
|
91 |
+
* Return optimization statistics
|
92 |
+
*
|
93 |
+
* @param none
|
94 |
+
* @return array of statistics
|
95 |
+
*/
|
96 |
+
public static function getStatistics(){
|
97 |
+
global $wpdb;
|
98 |
+
$output = array();
|
99 |
+
|
100 |
+
$query = $wpdb->prepare(
|
101 |
+
"select
|
102 |
+
$wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
|
103 |
+
from $wpdb->posts
|
104 |
+
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s",
|
105 |
+
array('resmushed_cumulated_original_sizes')
|
106 |
+
);
|
107 |
+
$original_sizes = $wpdb->get_results($query);
|
108 |
+
$total_original_size = 0;
|
109 |
+
foreach($original_sizes as $s){
|
110 |
+
$total_original_size += $s->meta_value;
|
111 |
+
}
|
112 |
+
|
113 |
+
$query = $wpdb->prepare(
|
114 |
+
"select
|
115 |
+
$wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
|
116 |
+
from $wpdb->posts
|
117 |
+
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s",
|
118 |
+
array('resmushed_cumulated_optimized_sizes')
|
119 |
+
);
|
120 |
+
$optimized_sizes = $wpdb->get_results($query);
|
121 |
+
$total_optimized_size = 0;
|
122 |
+
foreach($optimized_sizes as $s){
|
123 |
+
$total_optimized_size += $s->meta_value;
|
124 |
+
}
|
125 |
+
|
126 |
+
|
127 |
+
$output['total_original_size'] = $total_original_size;
|
128 |
+
$output['total_optimized_size'] = $total_optimized_size;
|
129 |
+
$output['total_saved_size'] = $total_original_size - $total_optimized_size;
|
130 |
+
if($total_original_size == 0)
|
131 |
+
$output['percent_reduction'] = 0;
|
132 |
+
else
|
133 |
+
$output['percent_reduction'] = 100*round(($total_original_size - $total_optimized_size)/$total_original_size,4) . ' %';
|
134 |
+
//number of thumbnails + original picture
|
135 |
+
$output['files_optimized'] = sizeof($optimized_sizes) * (sizeof(get_intermediate_image_sizes()) + 1);
|
136 |
+
$output['total_optimizations'] = get_option('resmushit_total_optimized');
|
137 |
+
$output['total_pictures'] = self::getCountAllPictures() * (sizeof(get_intermediate_image_sizes()) + 1);
|
138 |
+
|
139 |
+
return $output;
|
140 |
+
}
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
/**
|
145 |
+
*
|
146 |
+
* Get the count of all pictures
|
147 |
+
*
|
148 |
+
* @param none
|
149 |
+
* @return json of unsmushed pictures attachments ID
|
150 |
+
*/
|
151 |
+
public static function getCountAllPictures(){
|
152 |
+
global $wpdb;
|
153 |
+
|
154 |
+
$queryAllPictures = $wpdb->prepare(
|
155 |
+
"select
|
156 |
+
Count($wpdb->posts.ID) as count
|
157 |
+
from $wpdb->posts
|
158 |
+
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
|
159 |
+
where $wpdb->posts.post_type = %s
|
160 |
+
and $wpdb->posts.post_mime_type like %s
|
161 |
+
and ($wpdb->posts.post_mime_type = 'image/jpeg' OR $wpdb->posts.post_mime_type = 'image/gif' OR $wpdb->posts.post_mime_type = 'image/png')",
|
162 |
+
array('_wp_attachment_metadata','attachment', 'image%')
|
163 |
+
);
|
164 |
+
$data = $wpdb->get_results($queryAllPictures);
|
165 |
+
if(isset($data[0]))
|
166 |
+
$data = $data[0];
|
167 |
+
|
168 |
+
if(!isset($data->count))
|
169 |
+
return 0;
|
170 |
+
return $data->count;
|
171 |
+
}
|
172 |
+
|
173 |
+
|
174 |
+
|
175 |
+
|
176 |
+
|
177 |
+
/**
|
178 |
+
*
|
179 |
+
* Get a list of non optimized pictures
|
180 |
+
*
|
181 |
+
* @param none
|
182 |
+
* @return json of unsmushed pictures attachments ID
|
183 |
+
*/
|
184 |
+
public static function getNonOptimizedPictures(){
|
185 |
+
global $wpdb;
|
186 |
+
$tmp = array();
|
187 |
+
$unsmushed_images = array();
|
188 |
+
$already_optimized_images_array = array();
|
189 |
+
|
190 |
+
$queryAllPictures = $wpdb->prepare(
|
191 |
+
"select
|
192 |
+
$wpdb->posts.ID as ID,
|
193 |
+
$wpdb->posts.guid as guid,
|
194 |
+
$wpdb->postmeta.meta_value as file_meta
|
195 |
+
from $wpdb->posts
|
196 |
+
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
|
197 |
+
where $wpdb->posts.post_type = %s
|
198 |
+
and $wpdb->posts.post_mime_type like %s
|
199 |
+
and ($wpdb->posts.post_mime_type = 'image/jpeg' OR $wpdb->posts.post_mime_type = 'image/gif' OR $wpdb->posts.post_mime_type = 'image/png')",
|
200 |
+
array('_wp_attachment_metadata','attachment', 'image%')
|
201 |
+
);
|
202 |
+
|
203 |
+
$queryAlreadyOptimizedPictures = $wpdb->prepare(
|
204 |
+
"select
|
205 |
+
$wpdb->posts.ID as ID
|
206 |
+
from $wpdb->posts
|
207 |
+
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
|
208 |
+
where $wpdb->postmeta.meta_value = %s",
|
209 |
+
array('resmushed_quality', self::getPictureQuality())
|
210 |
+
);
|
211 |
+
|
212 |
+
// Get the images in the attachement table
|
213 |
+
$all_images = $wpdb->get_results($queryAllPictures);
|
214 |
+
$already_optimized_images = $wpdb->get_results($queryAlreadyOptimizedPictures);
|
215 |
+
|
216 |
+
foreach($already_optimized_images as $image)
|
217 |
+
$already_optimized_images_array[] = $image->ID;
|
218 |
+
|
219 |
+
|
220 |
+
foreach($all_images as $image){
|
221 |
+
if(!in_array($image->ID, $already_optimized_images_array)){
|
222 |
+
$tmp = array();
|
223 |
+
$tmp['ID'] = $image->ID;
|
224 |
+
$tmp['attachment_metadata'] = unserialize($image->file_meta);
|
225 |
+
$unsmushed_images[] = $tmp;
|
226 |
+
}
|
227 |
+
|
228 |
+
}
|
229 |
+
return json_encode($unsmushed_images);
|
230 |
+
}
|
231 |
+
|
232 |
+
|
233 |
+
/**
|
234 |
+
*
|
235 |
+
* Return the number of non optimized pictures
|
236 |
+
*
|
237 |
+
* @param none
|
238 |
+
* @return number of non optimized pictures to the current quality factor
|
239 |
+
*/
|
240 |
+
public static function getCountNonOptimizedPictures(){
|
241 |
+
$data = json_decode(self::getNonOptimizedPictures());
|
242 |
+
return sizeof($data) * (sizeof(get_intermediate_image_sizes()) + 1);
|
243 |
+
}
|
244 |
+
}
|
classes/resmushitUI.class.php
ADDED
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ReSmushit Admin UI class
|
5 |
+
*
|
6 |
+
*
|
7 |
+
* @package Resmush.it
|
8 |
+
* @subpackage UI
|
9 |
+
* @author Charles Bourgeaux <contact@resmush.it>
|
10 |
+
*/
|
11 |
+
Class reSmushitUI {
|
12 |
+
|
13 |
+
/**
|
14 |
+
*
|
15 |
+
* Create a new panel
|
16 |
+
*
|
17 |
+
* @param string $title Title of the pane
|
18 |
+
* @param string $html HTML content
|
19 |
+
* @param string $border Color of the border
|
20 |
+
* @return none
|
21 |
+
*/
|
22 |
+
public static function fullWidthPanel($title = null, $html = null, $border = null) {
|
23 |
+
self::fullWidthPanelWrapper($title, $html, $border);
|
24 |
+
echo $html;
|
25 |
+
self::fullWidthPanelEndWrapper();
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
/**
|
32 |
+
*
|
33 |
+
* Create a new panel wrapper (start)
|
34 |
+
*
|
35 |
+
* @param string $title Title of the pane
|
36 |
+
* @param string $html HTML content
|
37 |
+
* @param string $border Color of the border
|
38 |
+
* @return none
|
39 |
+
*/
|
40 |
+
public static function fullWidthPanelWrapper($title = null, $html = null, $border = null) {
|
41 |
+
?>
|
42 |
+
<div class='rsmt-panel w100 <?php if($border) echo 'brdr-'.$border; ?>'>
|
43 |
+
<h2><?php echo $title; ?></h2>
|
44 |
+
<?php
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
/**
|
51 |
+
*
|
52 |
+
* Create a new panel wrapper (end)
|
53 |
+
*
|
54 |
+
* @param none
|
55 |
+
* @return none
|
56 |
+
*/
|
57 |
+
public static function fullWidthPanelEndWrapper() {
|
58 |
+
?>
|
59 |
+
</div>
|
60 |
+
<?php
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
/**
|
67 |
+
*
|
68 |
+
* Generate Header panel
|
69 |
+
*
|
70 |
+
* @param none
|
71 |
+
* @return none
|
72 |
+
*/
|
73 |
+
public static function headerPanel() {
|
74 |
+
$html = "<img src='". RESMUSHIT_BASE_URL . "images/header.jpg' />";
|
75 |
+
self::fullWidthPanel($html);
|
76 |
+
}
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
/**
|
83 |
+
*
|
84 |
+
* Generate Settings panel
|
85 |
+
*
|
86 |
+
* @param none
|
87 |
+
* @return none
|
88 |
+
*/
|
89 |
+
public static function settingsPanel() {
|
90 |
+
self::fullWidthPanelWrapper('Settings', null, 'orange');
|
91 |
+
?>
|
92 |
+
<div class="rsmt-settings">
|
93 |
+
<form method="post" action="options.php" id="rsmt-options-form">
|
94 |
+
<?php settings_fields( 'resmushit-settings' ); ?>
|
95 |
+
<?php do_settings_sections( 'resmushit-settings' ); ?>
|
96 |
+
<table class="form-table">
|
97 |
+
<?php self::addSetting("text", "Image quality", "Default value is 92. The quality factor must be between 0 (very week) and 100 (best quality)", "resmushit_qlty") ?>
|
98 |
+
<?php self::addSetting("checkbox", "Optimize on upload", "All future images uploaded will be automatically optimized", "resmushit_on_upload") ?>
|
99 |
+
<?php self::addSetting("checkbox", "Enable statistics", "Create statistics about optimized pictures", "resmushit_statistics") ?>
|
100 |
+
<?php self::addSetting("checkbox", "Enable logs", "Enable file logging (for developers)", "resmushit_logs") ?>
|
101 |
+
</table>
|
102 |
+
<?php submit_button(); ?>
|
103 |
+
</form>
|
104 |
+
</div>
|
105 |
+
<?php self::fullWidthPanelEndWrapper();
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
/**
|
111 |
+
*
|
112 |
+
* Generate Bulk panel
|
113 |
+
*
|
114 |
+
* @param none
|
115 |
+
* @return none
|
116 |
+
*/
|
117 |
+
public static function bulkPanel() {
|
118 |
+
$countNonOptimizedPictures = reSmushit::getCountNonOptimizedPictures();
|
119 |
+
self::fullWidthPanelWrapper('Optimize unsmushed pictures', null, 'blue');
|
120 |
+
?>
|
121 |
+
|
122 |
+
<div class="rsmt-bulk">
|
123 |
+
<div class="non-optimized-wrapper <?php if(!$countNonOptimizedPictures) echo 'disabled' ?>">
|
124 |
+
<h3 class="icon_message warning">There is currently <em><?php echo $countNonOptimizedPictures; ?> non optimized pictures</em>.</h3>
|
125 |
+
<p>This action will resmush all pictures which have not been optimized to the good Image Quality Rate.</p>
|
126 |
+
<p class="submit" id="bulk-resize-examine-button">
|
127 |
+
<button class="button-primary" onclick="resmushit_bulk_resize('bulk_resize_image_list');">Optimize all pictures</button>
|
128 |
+
</p>
|
129 |
+
<div id='bulk_resize_image_list'></div>
|
130 |
+
</div>
|
131 |
+
|
132 |
+
<div class="optimized-wrapper <?php if($countNonOptimizedPictures) echo 'disabled' ?>">
|
133 |
+
<h3 class="icon_message ok">Congrats ! All your pictures are correctly optimized</h3>
|
134 |
+
</div>
|
135 |
+
</div>
|
136 |
+
<?php self::fullWidthPanelEndWrapper();
|
137 |
+
}
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
/**
|
143 |
+
*
|
144 |
+
* Generate Statistics panel
|
145 |
+
*
|
146 |
+
* @param none
|
147 |
+
* @return none
|
148 |
+
*/
|
149 |
+
public static function statisticsPanel() {
|
150 |
+
if(!get_option('resmushit_statistics'))
|
151 |
+
return false;
|
152 |
+
self::fullWidthPanelWrapper('Statistics', null, 'green');
|
153 |
+
?>
|
154 |
+
|
155 |
+
<div class="rsmt-statistics">
|
156 |
+
<?php $resmushit_stat = reSmushit::getStatistics();
|
157 |
+
if($resmushit_stat['files_optimized'] != 0):
|
158 |
+
?>
|
159 |
+
<p><strong>Space saved :</strong> <span id="rsmt-statistics-space-saved"><?php echo self::sizeFormat($resmushit_stat['total_saved_size'])?></span></p>
|
160 |
+
<p><strong>Total reduction :</strong> <span id="rsmt-statistics-percent-reduction"><?php echo $resmushit_stat['percent_reduction'] ?></span></p>
|
161 |
+
<p><strong>Images optimized :</strong> <span id="rsmt-statistics-files-optimized"><?php echo $resmushit_stat['files_optimized'] ?></span>/<span id="rsmt-statistics-total-pictures"><?php echo $resmushit_stat['total_pictures'] ?></span></p>
|
162 |
+
<p><strong>Total images optimized :</strong> <span id="rsmt-statistics-total-optimizations"><?php echo $resmushit_stat['total_optimizations'] ?></span></p>
|
163 |
+
<?php else: ?>
|
164 |
+
<p>No picture has been optimized yet ! Add pictures to your Wordpress Media Library.</p>
|
165 |
+
<?php endif; ?>
|
166 |
+
</div>
|
167 |
+
<?php self::fullWidthPanelEndWrapper();
|
168 |
+
}
|
169 |
+
|
170 |
+
|
171 |
+
|
172 |
+
/**
|
173 |
+
*
|
174 |
+
* Generate News panel
|
175 |
+
*
|
176 |
+
* @param none
|
177 |
+
* @return none
|
178 |
+
*/
|
179 |
+
public static function newsPanel() {
|
180 |
+
global $wp_version;
|
181 |
+
?>
|
182 |
+
<div class="rsmt-news">
|
183 |
+
|
184 |
+
<?php
|
185 |
+
self::fullWidthPanelWrapper('News', null, 'red');
|
186 |
+
$ch = curl_init();
|
187 |
+
curl_setopt($ch, CURLOPT_URL, RESMUSHIT_NEWSFEED);
|
188 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
189 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
190 |
+
$data_raw = curl_exec($ch);
|
191 |
+
curl_close($ch);
|
192 |
+
$data = json_decode($data_raw);
|
193 |
+
if($data):
|
194 |
+
foreach($data as $i=>$news):
|
195 |
+
if($i > 1)
|
196 |
+
break;
|
197 |
+
?>
|
198 |
+
<div class="news-item">
|
199 |
+
<span class="news-date"><?php echo date('d/m/Y', $news->date) ?></span>
|
200 |
+
<div class="news-img">
|
201 |
+
<a href="<?php echo $news->link ?>" target="_blank">
|
202 |
+
<img src="<?php echo $news->picture ?>" />
|
203 |
+
</a>
|
204 |
+
</div>
|
205 |
+
<h3><a href="<?php echo $news->link ?>" target="_blank"><?php echo $news->title ?></a></h3>
|
206 |
+
<div class="news-content">
|
207 |
+
<?php echo $news->content ?>
|
208 |
+
</div>
|
209 |
+
</div>
|
210 |
+
|
211 |
+
<?php endforeach; ?>
|
212 |
+
<?php endif; ?>
|
213 |
+
<div class="social">
|
214 |
+
<a class="social-maecia" title="Maecia Agency - Paris France" href="https://www.maecia.com" target="_blank">
|
215 |
+
<img src="<?php echo RESMUSHIT_BASE_URL ?>images/maecia.png" />
|
216 |
+
</a>
|
217 |
+
<a class="social-resmushit" title="Visit resmush.it for more informations" href="https://www.resmush.it" target="_blank">
|
218 |
+
<img src="<?php echo RESMUSHIT_BASE_URL ?>images/logo.png" />
|
219 |
+
</a>
|
220 |
+
<a class="social-twitter" title="Follow reSmush.it on Twitter" href="https://www.twitter.com/resmushit" target="_blank">
|
221 |
+
<img src="<?php echo RESMUSHIT_BASE_URL ?>images/twitter.png" />
|
222 |
+
</a>
|
223 |
+
</div>
|
224 |
+
</div>
|
225 |
+
<?php self::fullWidthPanelEndWrapper();
|
226 |
+
}
|
227 |
+
|
228 |
+
|
229 |
+
|
230 |
+
|
231 |
+
/**
|
232 |
+
*
|
233 |
+
* Helper to generate multiple settings fields
|
234 |
+
*
|
235 |
+
* @param string $type type of the setting
|
236 |
+
* @param string $name displayed name of the setting
|
237 |
+
* @param string $extra additionnal informations about the setting
|
238 |
+
* @param string $machine_name setting machine name
|
239 |
+
* @return none
|
240 |
+
*/
|
241 |
+
public static function addSetting($type, $name, $extra, $machine_name) {
|
242 |
+
echo "<div class='setting-row type-$type'>";
|
243 |
+
echo "<label for='$machine_name'>$name<p>$extra</p></label>";
|
244 |
+
switch($type){
|
245 |
+
case 'text':
|
246 |
+
echo "<input type='text' name='$machine_name' id='$machine_name' value='". get_option( $machine_name ) ."'/>";
|
247 |
+
break;
|
248 |
+
case 'checkbox':
|
249 |
+
$additionnal = null;
|
250 |
+
if ( 1 == get_option( $machine_name ) ) $additionnal = 'checked="checked"';
|
251 |
+
echo "<input type='checkbox' name='$machine_name' id='$machine_name' value='1' ". $additionnal ."/>";
|
252 |
+
break;
|
253 |
+
}
|
254 |
+
echo '</div>';
|
255 |
+
}
|
256 |
+
|
257 |
+
|
258 |
+
|
259 |
+
/**
|
260 |
+
*
|
261 |
+
* Helper to format size in bytes
|
262 |
+
*
|
263 |
+
* @param int $bytes filesize in bytes
|
264 |
+
* @return string rendered filesize
|
265 |
+
*/
|
266 |
+
public static function sizeFormat($bytes) {
|
267 |
+
if ($bytes > 0)
|
268 |
+
{
|
269 |
+
$unit = intval(log($bytes, 1024));
|
270 |
+
$units = array('B', 'KB', 'MB', 'GB');
|
271 |
+
|
272 |
+
if (array_key_exists($unit, $units) === true)
|
273 |
+
{
|
274 |
+
return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]);
|
275 |
+
}
|
276 |
+
}
|
277 |
+
return $bytes;
|
278 |
+
}
|
279 |
+
}
|
css/resmushit.css
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.rsmt-panels{
|
2 |
+
display: flex;
|
3 |
+
flex-direction:row;
|
4 |
+
justify-content:space-between;
|
5 |
+
margin-right: 20px;
|
6 |
+
}
|
7 |
+
.rsmt-panels .rsmt-panel{
|
8 |
+
background-color: #FFF;
|
9 |
+
box-shadow: 0 2px 0 #EAEAEA;
|
10 |
+
padding: 15px;
|
11 |
+
margin: 0 0 15px;
|
12 |
+
box-sizing:border-box;
|
13 |
+
}
|
14 |
+
.rsmt-panels .w100{
|
15 |
+
width: 100%;
|
16 |
+
}
|
17 |
+
.rsmt-panels .w66{
|
18 |
+
flex-basis: 66%;
|
19 |
+
}
|
20 |
+
.rsmt-panels .w33{
|
21 |
+
flex-basis: 33%;
|
22 |
+
}
|
23 |
+
.rsmt-panels .brdr-green{
|
24 |
+
border-left: 4px solid #277F72
|
25 |
+
}
|
26 |
+
.rsmt-panels .brdr-blue{
|
27 |
+
border-left: 4px solid #5A8BA8
|
28 |
+
}
|
29 |
+
.rsmt-panels .brdr-orange{
|
30 |
+
border-left: 4px solid #DFC02A
|
31 |
+
}
|
32 |
+
.rsmt-panels .brdr-red{
|
33 |
+
border-left: 4px solid #9E2F29
|
34 |
+
}
|
35 |
+
.rsmt-panels h2{
|
36 |
+
text-transform: uppercase;
|
37 |
+
font-family: 'Roboto Slab', serif;
|
38 |
+
font-size: 1.5em;
|
39 |
+
color:#4B4B4B;
|
40 |
+
}
|
41 |
+
.rsmt-panels img{
|
42 |
+
max-width: 100%;
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
.rsmt-settings .setting-row{
|
47 |
+
margin-bottom: 20px;
|
48 |
+
}
|
49 |
+
.rsmt-settings .setting-row.type-checkbox{
|
50 |
+
display: flex;
|
51 |
+
}
|
52 |
+
.rsmt-settings .setting-row label{
|
53 |
+
display: inline-block;
|
54 |
+
font-weight: bold;
|
55 |
+
width: 100%
|
56 |
+
}
|
57 |
+
.rsmt-settings .setting-row label p{
|
58 |
+
margin:0;
|
59 |
+
font-size: 0.8em;
|
60 |
+
font-weight: normal;
|
61 |
+
}
|
62 |
+
.rsmt-settings .setting-row input[type='text']{
|
63 |
+
width: 100%;
|
64 |
+
}
|
65 |
+
.rsmt-settings .setting-row input[type='checkbox']{
|
66 |
+
margin-top: 2px;
|
67 |
+
}
|
68 |
+
.rsmt-settings .setting-row input.form-error{
|
69 |
+
border: 1px solid #D54E21;
|
70 |
+
color: #D54E21;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
.rsmt-bulk .loader{
|
75 |
+
height: 50px;
|
76 |
+
width: 50px;
|
77 |
+
display: inline-block;
|
78 |
+
background-image: url(../images/clock.gif);
|
79 |
+
background-repeat: no-repeat;
|
80 |
+
}
|
81 |
+
.rsmt-bulk .disabled{
|
82 |
+
display: none;
|
83 |
+
}
|
84 |
+
.rsmt-bulk .icon_message{
|
85 |
+
background-repeat: no-repeat;
|
86 |
+
padding: 13px 0 0 60px;
|
87 |
+
min-height: 48px;
|
88 |
+
-webkit-box-sizing: border-box;
|
89 |
+
-moz-box-sizing: border-box;
|
90 |
+
box-sizing: border-box;
|
91 |
+
}
|
92 |
+
.rsmt-bulk .warning{
|
93 |
+
background-image: url(../images/warning.png);
|
94 |
+
}
|
95 |
+
.rsmt-bulk .ok{
|
96 |
+
background-image: url(../images/ok.png);
|
97 |
+
}
|
98 |
+
.rsmt-bulk .bulk--back-progressionbar{
|
99 |
+
background: #F1F1F1;
|
100 |
+
box-shadow: inset 0 5px 15px rgba(0, 0, 0, 0.1);
|
101 |
+
width: 100%;
|
102 |
+
height: 25px;
|
103 |
+
position: relative;
|
104 |
+
text-align: center;
|
105 |
+
}
|
106 |
+
.rsmt-bulk .resmushit--progress--bar p{
|
107 |
+
font-size: 15px;
|
108 |
+
line-height: 1.5;
|
109 |
+
color: white;
|
110 |
+
position: absolute;
|
111 |
+
left: 50%;
|
112 |
+
top: -13px;
|
113 |
+
z-index: 1;
|
114 |
+
transform: translate(-50%,0%);
|
115 |
+
}
|
116 |
+
.rsmt-bulk .resmushit--progress--bar{
|
117 |
+
background: #234C71;
|
118 |
+
position:absolute;
|
119 |
+
transition: all 1s ease-out;
|
120 |
+
height:100%;
|
121 |
+
}
|
122 |
+
.rsmt-bulk .resmushit--progress--bar:after{
|
123 |
+
content: "";
|
124 |
+
width: 100%;
|
125 |
+
position: absolute;
|
126 |
+
bottom: 0;
|
127 |
+
height: 50%;
|
128 |
+
background: rgba(0,0,0,0.2);
|
129 |
+
left: 0;
|
130 |
+
color: white;
|
131 |
+
}
|
132 |
+
.rsmt-bulk .resmush--complete{
|
133 |
+
padding: 10px;
|
134 |
+
background-color: #4862A3;
|
135 |
+
text-align: center;
|
136 |
+
color: white;
|
137 |
+
width: 200px;
|
138 |
+
text-align: center;
|
139 |
+
margin: 20px auto;
|
140 |
+
}
|
141 |
+
.rsmt-bulk .loading--bulk{
|
142 |
+
text-align: center;
|
143 |
+
}
|
144 |
+
.rsmt-bulk #bulk_resize_target{
|
145 |
+
overflow: auto;
|
146 |
+
padding: 20px 10px;
|
147 |
+
height: 100%!important;
|
148 |
+
background: white;
|
149 |
+
}
|
150 |
+
.rsmt-bulk .file--treated{
|
151 |
+
display: none;
|
152 |
+
}
|
153 |
+
|
154 |
+
|
155 |
+
.rsmt-news .news-item{
|
156 |
+
margin-bottom: 25px;
|
157 |
+
}
|
158 |
+
.rsmt-news .news-date{
|
159 |
+
background: #bbb;
|
160 |
+
color:#fff;
|
161 |
+
padding: 2px 5px;
|
162 |
+
font-size: 0.8em;
|
163 |
+
}
|
164 |
+
.rsmt-news .news-content{
|
165 |
+
font-style: italic;
|
166 |
+
}
|
167 |
+
.rsmt-news .news-img img{
|
168 |
+
width: 100%;
|
169 |
+
box-shadow: 0 2px 0 #EAEAEA;
|
170 |
+
padding: 10px 10px;
|
171 |
+
box-sizing: border-box;
|
172 |
+
background: #F4F4F4;
|
173 |
+
}
|
174 |
+
.rsmt-news h3{
|
175 |
+
margin: 5px 0 3px;
|
176 |
+
font-size: 1.2em;
|
177 |
+
}
|
178 |
+
.rsmt-news h3 a{
|
179 |
+
text-decoration: none;
|
180 |
+
}
|
181 |
+
.rsmt-news .social{
|
182 |
+
text-align: right;
|
183 |
+
}
|
184 |
+
.rsmt-news .social a{
|
185 |
+
margin-left: 10px;
|
186 |
+
}
|
187 |
+
.rsmt-news .social .social-twitter{
|
188 |
+
width: 16px;
|
189 |
+
height: 16px;
|
190 |
+
display: inline-block;
|
191 |
+
}
|
192 |
+
.rsmt-news .social a{
|
193 |
+
opacity: 0.5;
|
194 |
+
text-decoration: none;
|
195 |
+
}
|
196 |
+
.rsmt-news .social a:hover{
|
197 |
+
opacity: 0.8;
|
198 |
+
}
|
199 |
+
|
200 |
+
|
201 |
+
|
202 |
+
|
203 |
+
@media screen and (max-width: 1100px) {
|
204 |
+
.rsmt-panels{
|
205 |
+
flex-direction:column;
|
206 |
+
}
|
207 |
+
}
|
images/clock.gif
ADDED
Binary file
|
images/header.jpg
ADDED
Binary file
|
images/logo.png
ADDED
Binary file
|
images/maecia.png
ADDED
Binary file
|
images/ok.png
ADDED
Binary file
|
images/twitter.png
ADDED
Binary file
|
images/warning.png
ADDED
Binary file
|
js/script.js
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
/**
|
3 |
+
* Bulk Resize admin javascript functions
|
4 |
+
*/
|
5 |
+
var bulkCounter = 0;
|
6 |
+
var bulkTotalimages = 0;
|
7 |
+
var next_index = 0;
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Form Validators
|
12 |
+
*/
|
13 |
+
jQuery("#rsmt-options-form").submit(function(){
|
14 |
+
jQuery("#resmushit_qlty").removeClass('form-error');
|
15 |
+
var qlty = jQuery("#resmushit_qlty").val();
|
16 |
+
if(!jQuery.isNumeric(qlty) || qlty > 100 || qlty < 0){
|
17 |
+
jQuery("#resmushit_qlty").addClass('form-error');
|
18 |
+
return false;
|
19 |
+
}
|
20 |
+
});
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
/**
|
26 |
+
* recursive function for resizing images
|
27 |
+
*/
|
28 |
+
function resmushit_bulk_process(bulk, item){
|
29 |
+
jQuery.post(
|
30 |
+
ajaxurl, { // (defined by wordpress - points to admin-ajax.php)
|
31 |
+
action: 'resmushit_bulk_process_image',
|
32 |
+
data: bulk[item]
|
33 |
+
},
|
34 |
+
function(response) {
|
35 |
+
if(!flag_removed){
|
36 |
+
jQuery('#bulk_resize_target').remove();
|
37 |
+
container.append('<div id="smush_results" style="padding: 20px 5px; overflow: auto;" />');
|
38 |
+
var results_target = jQuery('#smush_results');
|
39 |
+
results_target.html('<div class="bulk--back-progressionbar"><div <div class="resmushit--progress--bar"</div></div>');
|
40 |
+
flag_removed = true;
|
41 |
+
}
|
42 |
+
|
43 |
+
var results_target = jQuery('#smush_results');
|
44 |
+
bulkCounter++;
|
45 |
+
jQuery('.resmushit--progress--bar').html('<p>'+ Math.round((bulkCounter*100/bulkTotalimages)) +'%</p>');
|
46 |
+
jQuery('.resmushit--progress--bar').animate({'width': Math.round((bulkCounter*100/bulkTotalimages))+'%'}, 0);
|
47 |
+
|
48 |
+
if(item < bulk.length)
|
49 |
+
resmushit_bulk_process(bulk, item + 1);
|
50 |
+
else{
|
51 |
+
jQuery('.non-optimized-wrapper').addClass('disabled');
|
52 |
+
jQuery('.optimized-wrapper').removeClass('disabled');
|
53 |
+
updateStatistics();
|
54 |
+
}
|
55 |
+
}
|
56 |
+
);
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
/**
|
61 |
+
* ajax post to return all images that are candidates for resizing
|
62 |
+
* @param string the id of the html element into which results will be appended
|
63 |
+
*/
|
64 |
+
function resmushit_bulk_resize(container_id) {
|
65 |
+
container = jQuery('#'+container_id);
|
66 |
+
container.html('<div id="bulk_resize_target">');
|
67 |
+
jQuery('#bulk-resize-examine-button').fadeOut(200);
|
68 |
+
var target = jQuery('#bulk_resize_target');
|
69 |
+
|
70 |
+
target.html('<div class="loading--bulk"><span class="loader"></span><br />Examining existing attachments. This may take a few moments...</div>');
|
71 |
+
|
72 |
+
target.animate(
|
73 |
+
{ height: [100,'swing'] },
|
74 |
+
500,
|
75 |
+
function() {
|
76 |
+
jQuery.post(
|
77 |
+
ajaxurl,
|
78 |
+
{ action: 'resmushit_bulk_get_images' },
|
79 |
+
function(response) {
|
80 |
+
var images = JSON.parse(response);
|
81 |
+
if (images.length > 0) {
|
82 |
+
bulkTotalimages = images.length;
|
83 |
+
|
84 |
+
|
85 |
+
flag_removed = false;
|
86 |
+
//start treating all pictures
|
87 |
+
resmushit_bulk_process(images, 0);
|
88 |
+
} else {
|
89 |
+
target.html('<div>There are no existing attachments that require Smushing.</div>');
|
90 |
+
}
|
91 |
+
}
|
92 |
+
);
|
93 |
+
});
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
/**
|
98 |
+
* ajax post to update statistics
|
99 |
+
*/
|
100 |
+
function updateStatistics() {
|
101 |
+
jQuery.post(
|
102 |
+
ajaxurl, {
|
103 |
+
action: 'resmushit_update_statistics'
|
104 |
+
},
|
105 |
+
function(response) {
|
106 |
+
statistics = JSON.parse(response);
|
107 |
+
jQuery('#rsmt-statistics-space-saved').text(statistics.total_saved_size_formatted);
|
108 |
+
jQuery('#rsmt-statistics-files-optimized').text(statistics.files_optimized);
|
109 |
+
jQuery('#rsmt-statistics-percent-reduction').text(statistics.percent_reduction);
|
110 |
+
jQuery('#rsmt-statistics-total-optimizations').text(statistics.total_optimizations);
|
111 |
+
}
|
112 |
+
);
|
113 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== reSmush.it Image Optimizer ===
|
2 |
+
Contributors: maecia
|
3 |
+
Tags: image, optimizer, image optimization, resmush.it, smush, jpg, png, gif, optimization, compression, Compress, Images, Pictures, Reduce Image Size,Smush,Smush.it
|
4 |
+
Requires at least: 4.0.0
|
5 |
+
Tested up to: 4.5.3
|
6 |
+
Stable tag: 0.1.1
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
Use reSmush.it Image Optimizer to optimize your pictures file sizes. Improve your performances by using reSmush.it, the Billion images API optimizer.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
reSmush.it Image Optimizer allow to use **free Image optimization** based on [reSmush.it API](http://www.reesmush.it/ "Image Optimization API, developped by Charles Bourgeaux"). reSmush.it provides image size reduction based on several advanced algorithms. The API accept JPG, PNG and GIF files up to **2MB**.
|
15 |
+
|
16 |
+
This plugin includes a bulk operation to optimize all your pictures in 2 clicks ! Change your image optimization level to fit your needs !
|
17 |
+
This service is used by **thousands** of websites on different CMS (Drupal, Joomla, Prestashop...).
|
18 |
+
|
19 |
+
This plugin has been developped by [Maecia Agency](http://www.maecia.com/ "Maecia Drupal & Wordpress Agency"), Paris.
|
20 |
+
|
21 |
+
== Installation ==
|
22 |
+
|
23 |
+
1. Upload `resmushit-image-optimizer` to the `/wp-content/plugins/` directory.
|
24 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
25 |
+
3. All your news pictures will be automatically optimized !
|
26 |
+
|
27 |
+
|
28 |
+
== Frequently Asked Questions ==
|
29 |
+
|
30 |
+
= Is it free ? =
|
31 |
+
|
32 |
+
Yes ! Absolutely free, the only restriction is to send images below 2MB.
|
33 |
+
|
34 |
+
== Screenshots ==
|
35 |
+
|
36 |
+
1. The simple interface
|
37 |
+
|
38 |
+
== Changelog ==
|
39 |
+
|
40 |
+
= 0.1.1 =
|
41 |
+
* Optimize on upload
|
42 |
+
* Statistics
|
43 |
+
* Log services
|
44 |
+
* Interface rebuild
|
45 |
+
* News feed from feed.resmush.it
|
46 |
+
|
47 |
+
= 0.1.0 =
|
48 |
+
* plugin base
|
49 |
+
* bulk optimizer
|
resmushit.admin.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* Create menu entries and routing
|
5 |
+
*
|
6 |
+
* @param none
|
7 |
+
* @return none
|
8 |
+
*/
|
9 |
+
function resmushit_create_menu() {
|
10 |
+
if ( is_super_admin() )
|
11 |
+
add_media_page( 'reSmush.it', 'reSmush.it', 'manage_options', 'resmushit_options', 'resmushit_settings_page');
|
12 |
+
}
|
13 |
+
add_action( 'admin_menu','resmushit_create_menu');
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
/**
|
20 |
+
*
|
21 |
+
* Declares settings entries
|
22 |
+
*
|
23 |
+
* @param none
|
24 |
+
* @return none
|
25 |
+
*/
|
26 |
+
function resmushit_settings_declare() {
|
27 |
+
register_setting( 'resmushit-settings', 'resmushit_on_upload' );
|
28 |
+
register_setting( 'resmushit-settings', 'resmushit_qlty' );
|
29 |
+
register_setting( 'resmushit-settings', 'resmushit_statistics' );
|
30 |
+
register_setting( 'resmushit-settings', 'resmushit_logs' );
|
31 |
+
}
|
32 |
+
add_action( 'admin_init', 'resmushit_settings_declare' );
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
/**
|
39 |
+
*
|
40 |
+
* Settings page builder
|
41 |
+
*
|
42 |
+
* @param none
|
43 |
+
* @return none
|
44 |
+
*/
|
45 |
+
function resmushit_settings_page() {
|
46 |
+
?>
|
47 |
+
<div class='rsmt-panels'>
|
48 |
+
<div class="rsmt-cols w66 iln-block">
|
49 |
+
<?php reSmushitUI::headerPanel();?>
|
50 |
+
<?php reSmushitUI::bulkPanel();?>
|
51 |
+
<?php reSmushitUI::statisticsPanel();?>
|
52 |
+
</div>
|
53 |
+
<div class="rsmt-cols w33 iln-block">
|
54 |
+
<?php reSmushitUI::settingsPanel();?>
|
55 |
+
<?php reSmushitUI::newsPanel();?>
|
56 |
+
</div>
|
57 |
+
</div>
|
58 |
+
<?php
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
/**
|
64 |
+
*
|
65 |
+
* Assets declaration
|
66 |
+
*
|
67 |
+
* @param none
|
68 |
+
* @return none
|
69 |
+
*/
|
70 |
+
function resmushit_register_plugin_assets(){
|
71 |
+
|
72 |
+
wp_register_style( 'resmushit-css', plugins_url( 'css/resmushit.css', __FILE__ ) );
|
73 |
+
wp_enqueue_style( 'resmushit-css' );
|
74 |
+
wp_enqueue_style( 'prefix-style', esc_url_raw( 'https://fonts.googleapis.com/css?family=Roboto+Slab:700' ), array(), null );
|
75 |
+
|
76 |
+
wp_register_script( 'resmushit-js', plugins_url( 'js/script.js', __FILE__ ) );
|
77 |
+
wp_enqueue_script( 'resmushit-js' );
|
78 |
+
}
|
79 |
+
add_action( 'admin_head', 'resmushit_register_plugin_assets' );
|
resmushit.inc.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require('resmushit.settings.php');
|
4 |
+
require('classes/resmushit.class.php');
|
5 |
+
require('classes/resmushitUI.class.php');
|
6 |
+
require('resmushit.admin.php');
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
*
|
12 |
+
* Embedded file log function
|
13 |
+
*
|
14 |
+
* @param string $str text to log in file
|
15 |
+
* @return none
|
16 |
+
*/
|
17 |
+
function rlog($str) {
|
18 |
+
if(get_option('resmushit_logs') == 0)
|
19 |
+
return false;
|
20 |
+
$str = "[".date('d-m-Y H:i:s')."] " . $str;
|
21 |
+
$str = print_r($str, true) . "\n";
|
22 |
+
$fp = fopen('../' . RESMUSHIT_LOGS_PATH, 'a+');
|
23 |
+
fwrite($fp, $str);
|
24 |
+
fclose($fp);
|
25 |
+
}
|
resmushit.php
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package resmushit
|
4 |
+
* @author Charles Bourgeaux <charles.bourgeaux@maecia.com>
|
5 |
+
* @author Tedj Ferhati <tedj.ferhati@maecia.com>
|
6 |
+
* @license GPL-2.0+
|
7 |
+
* @link http://www.resmush.it
|
8 |
+
* @copyright 2016 Resmush.it
|
9 |
+
*
|
10 |
+
* @wordpress-plugin
|
11 |
+
* Plugin Name: reSmush.it Image Optimizer
|
12 |
+
* Plugin URI: http://www.resmush.it
|
13 |
+
* Description: Image Optimization API. Provides image size optimization
|
14 |
+
* Version: 0.1.1
|
15 |
+
* Timestamp: 2016.05.13
|
16 |
+
* Author: Maecia
|
17 |
+
* Author URI: https://www.maecia.com
|
18 |
+
* Author: Charles Bourgeaux
|
19 |
+
* Author: Tedj Ferhati
|
20 |
+
* License: GPL-2.0+
|
21 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
22 |
+
*/
|
23 |
+
|
24 |
+
|
25 |
+
require('resmushit.inc.php');
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
/**
|
31 |
+
*
|
32 |
+
* Registering settings on plugin installation
|
33 |
+
*
|
34 |
+
* @param none
|
35 |
+
* @return none
|
36 |
+
*/
|
37 |
+
function resmushit_activate() {
|
38 |
+
if ( is_super_admin() ) {
|
39 |
+
if(!get_option('resmushit_qlty'))
|
40 |
+
update_option( 'resmushit_qlty', RESMUSHIT_DEFAULT_QLTY );
|
41 |
+
if(!get_option('resmushit_on_upload'))
|
42 |
+
update_option( 'resmushit_on_upload', '1' );
|
43 |
+
if(!get_option('resmushit_statistics'))
|
44 |
+
update_option( 'resmushit_statistics', '1' );
|
45 |
+
if(!get_option('resmushit_total_optimized'))
|
46 |
+
update_option( 'resmushit_total_optimized', '0' );
|
47 |
+
}
|
48 |
+
}
|
49 |
+
register_activation_hook( __FILE__, 'resmushit_activate' );
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
/**
|
56 |
+
*
|
57 |
+
* Call resmush.it optimization for attachments
|
58 |
+
*
|
59 |
+
* @param attachment object
|
60 |
+
* @param boolean preserve original file
|
61 |
+
* @return attachment object
|
62 |
+
*/
|
63 |
+
function resmushit_process_images($attachments, $force_keep_original = TRUE) {
|
64 |
+
global $attachment_id;
|
65 |
+
$cumulated_original_sizes = 0;
|
66 |
+
$cumulated_optimized_sizes = 0;
|
67 |
+
|
68 |
+
|
69 |
+
$basepath = dirname(get_attached_file( $attachment_id )) . '/';
|
70 |
+
$basefile = basename($attachments[ 'file' ]);
|
71 |
+
|
72 |
+
$statistics[] = reSmushit::optimize($basepath . $basefile, $force_keep_original );
|
73 |
+
|
74 |
+
foreach($attachments['sizes'] as $image_style)
|
75 |
+
$statistics[] = reSmushit::optimize($basepath . $image_style['file'], FALSE );
|
76 |
+
|
77 |
+
$count = 0;
|
78 |
+
foreach($statistics as $stat){
|
79 |
+
if($stat && !isset($stat->error)){
|
80 |
+
$cumulated_original_sizes += $stat->src_size;
|
81 |
+
$cumulated_optimized_sizes += $stat->dest_size;
|
82 |
+
$count++;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
$optimizations_successful_count = get_option('resmushit_total_optimized');
|
87 |
+
update_option( 'resmushit_total_optimized', $optimizations_successful_count + $count );
|
88 |
+
|
89 |
+
update_post_meta($attachment_id,'resmushed_quality', resmushit::getPictureQuality());
|
90 |
+
if(get_option('resmushit_statistics')){
|
91 |
+
update_post_meta($attachment_id,'resmushed_cumulated_original_sizes', $cumulated_original_sizes);
|
92 |
+
update_post_meta($attachment_id,'resmushed_cumulated_optimized_sizes', $cumulated_optimized_sizes);
|
93 |
+
}
|
94 |
+
return $attachments;
|
95 |
+
}
|
96 |
+
//Automatically optimize images if option is checked
|
97 |
+
if(get_option('resmushit_on_upload'))
|
98 |
+
add_filter('wp_generate_attachment_metadata', 'resmushit_process_images');
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
/**
|
105 |
+
*
|
106 |
+
* Make current attachment available
|
107 |
+
*
|
108 |
+
* @param attachment object
|
109 |
+
* @return attachment object
|
110 |
+
*/
|
111 |
+
function resmushit_get_meta_id($result){
|
112 |
+
global $attachment_id;
|
113 |
+
$attachment_id = $result;
|
114 |
+
}
|
115 |
+
//Automatically retrieve image attachment ID if option is checked
|
116 |
+
if(get_option('resmushit_on_upload'))
|
117 |
+
add_filter('add_attachment', 'resmushit_get_meta_id');
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
/**
|
124 |
+
*
|
125 |
+
* add Ajax action to fetch all unsmushed pictures
|
126 |
+
*
|
127 |
+
* @param none
|
128 |
+
* @return json object
|
129 |
+
*/
|
130 |
+
function resmushit_bulk_get_images() {
|
131 |
+
echo reSmushit::getNonOptimizedPictures();
|
132 |
+
die();
|
133 |
+
}
|
134 |
+
add_action( 'wp_ajax_resmushit_bulk_get_images', 'resmushit_bulk_get_images' );
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
/**
|
141 |
+
*
|
142 |
+
* add Ajax action to optimize a picture according to attachment ID
|
143 |
+
*
|
144 |
+
* @param none
|
145 |
+
* @return boolean
|
146 |
+
*/
|
147 |
+
function resmushit_bulk_process_image() {
|
148 |
+
global $attachment_id;
|
149 |
+
|
150 |
+
|
151 |
+
$attachment_id = $_POST['data']['ID'];
|
152 |
+
|
153 |
+
$basepath = dirname(get_attached_file( $attachment_id )) . '/';
|
154 |
+
$basefile = basename(get_attached_file( $attachment_id ));
|
155 |
+
$fileInfo = pathinfo(get_attached_file( $attachment_id ));
|
156 |
+
|
157 |
+
$originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
|
158 |
+
rlog('Bulk optimization launched for file : ' . get_attached_file( $attachment_id ));
|
159 |
+
|
160 |
+
if(file_exists($originalFile))
|
161 |
+
copy($originalFile, get_attached_file( $attachment_id ));
|
162 |
+
|
163 |
+
//Regenerate thumbnails
|
164 |
+
wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
|
165 |
+
die();
|
166 |
+
}
|
167 |
+
add_action( 'wp_ajax_resmushit_bulk_process_image', 'resmushit_bulk_process_image' );
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
|
172 |
+
|
173 |
+
/**
|
174 |
+
*
|
175 |
+
* add Ajax action to update statistics
|
176 |
+
*
|
177 |
+
* @param none
|
178 |
+
* @return json object
|
179 |
+
*/
|
180 |
+
function resmushit_update_statistics() {
|
181 |
+
$output = reSmushit::getStatistics();
|
182 |
+
$output['total_saved_size_formatted'] = reSmushitUI::sizeFormat($output['total_saved_size']);
|
183 |
+
echo json_encode($output);
|
184 |
+
die();
|
185 |
+
}
|
186 |
+
add_action( 'wp_ajax_resmushit_update_statistics', 'resmushit_update_statistics' );
|
resmushit.settings.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
|
5 |
+
define('RESMUSHIT_VERSION', '0.1.1');
|
6 |
+
define('RESMUSHIT_DEFAULT_QLTY', '92');
|
7 |
+
define('RESMUSHIT_TIMEOUT', '5');
|
8 |
+
define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
|
9 |
+
define('RESMUSHIT_NEWSFEED', 'http://feed.resmush.it/');
|
10 |
+
define('RESMUSHIT_BASE_URL', plugin_dir_url( __FILE__ ));
|