Version Description
- updated Smush.it endpoint URL
Download this release
Release Info
Developer | alexdunae |
Plugin | Smush Image Compression and Optimization |
Version | 1.2.5 |
Comparing to | |
See all releases |
Code changes from version 1.2.4 to 1.2.5
- readme.txt +6 -3
- theme.php +144 -161
- wp-smushit.php +33 -68
readme.txt
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
=== WP Smush.it ===
|
2 |
Plugin Name: WP Smush.it
|
3 |
-
Version: 1.2.
|
4 |
Author: Dialect
|
5 |
Author URI: http://dialect.ca/?wp_smush_it
|
6 |
Contributors: alexdunae
|
7 |
Tags: images, image, attachments, attachment
|
8 |
Requires at least: 2.5
|
9 |
-
Tested up to: 2.8.
|
10 |
-
Stable tag: 1.2.
|
11 |
|
12 |
Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
13 |
|
@@ -48,6 +48,9 @@ Plugin updates are announced on [http://www.twitter.com/TheCHANGELOG](http://www
|
|
48 |
1. Done!
|
49 |
|
50 |
== Changelog ==
|
|
|
|
|
|
|
51 |
= 1.2.4 =
|
52 |
* removed debugging code that was interfering with the Flash uploader
|
53 |
|
1 |
=== WP Smush.it ===
|
2 |
Plugin Name: WP Smush.it
|
3 |
+
Version: 1.2.5
|
4 |
Author: Dialect
|
5 |
Author URI: http://dialect.ca/?wp_smush_it
|
6 |
Contributors: alexdunae
|
7 |
Tags: images, image, attachments, attachment
|
8 |
Requires at least: 2.5
|
9 |
+
Tested up to: 2.8.5
|
10 |
+
Stable tag: 1.2.5
|
11 |
|
12 |
Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
13 |
|
48 |
1. Done!
|
49 |
|
50 |
== Changelog ==
|
51 |
+
= 1.2.5 =
|
52 |
+
* updated Smush.it endpoint URL
|
53 |
+
|
54 |
= 1.2.4 =
|
55 |
* removed debugging code that was interfering with the Flash uploader
|
56 |
|
theme.php
CHANGED
@@ -1,161 +1,144 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Admin page for smushing all the images in a given WordPress theme.
|
4 |
-
*
|
5 |
-
* Expects a `theme` in the query string.
|
6 |
-
*
|
7 |
-
* @version 1.3
|
8 |
-
* @package WP_SmushIt
|
9 |
-
*/
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
<
|
91 |
-
|
92 |
-
<
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
?>
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
<?php
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
?>
|
142 |
-
</ul>
|
143 |
-
<?php endif; ?>
|
144 |
-
</div>
|
145 |
-
|
146 |
-
<?php
|
147 |
-
|
148 |
-
exit;
|
149 |
-
|
150 |
-
|
151 |
-
/*
|
152 |
-
|
153 |
-
div class="wrap"> <div id="icon-plugins" class="icon32"><br /></div>
|
154 |
-
<h2>Installing Plugin: Google XML Sitemaps 3.1.4</h2><p>Downloading install package from <span class="code">http://downloads.wordpress.org/plugin/google-sitemap-generator.3.1.4.zip</span>.</p>
|
155 |
-
<p>Unpacking the package.</p>
|
156 |
-
|
157 |
-
<p>Installing the plugin.</p>
|
158 |
-
<p>Successfully installed the plugin <strong>Google XML Sitemaps 3.1.4</strong>.</p>
|
159 |
-
<p><strong>Actions:</strong> <a href="plugins.php?action=activate&plugin=google-sitemap-generator%2Fsitemap.php&_wpnonce=2b4ca1722c" title="Activate this plugin" target="_parent">Activate Plugin</a> | <a href="http://localhost/wp28/wp-admin/plugin-install.php" title="Return to Plugin Installer" target="_parent">Return to Plugin Installer</a></p>
|
160 |
-
</div>
|
161 |
-
**/
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Admin page for smushing all the images in a given WordPress theme.
|
4 |
+
*
|
5 |
+
* Expects a `theme` in the query string.
|
6 |
+
*
|
7 |
+
* @version 1.3
|
8 |
+
* @package WP_SmushIt
|
9 |
+
*/
|
10 |
+
|
11 |
+
if ( FALSE == is_admin() ) {
|
12 |
+
wp_die(__('You are not logged in to the dashboard.', WP_SMUSHIT_DOMAIN));
|
13 |
+
}
|
14 |
+
|
15 |
+
if ( FALSE === current_user_can('edit_themes') ) {
|
16 |
+
wp_die(__('You don\'t have permission to work with themes.', WP_SMUSHIT_DOMAIN));
|
17 |
+
}
|
18 |
+
|
19 |
+
ob_start();
|
20 |
+
|
21 |
+
$theme = null;
|
22 |
+
$theme_path = null;
|
23 |
+
$theme_url = null;
|
24 |
+
|
25 |
+
|
26 |
+
if ( isset($_GET['theme']) && !empty($_GET['theme']) ) {
|
27 |
+
|
28 |
+
$theme = attribute_escape($_GET['theme']);
|
29 |
+
$theme_path = get_theme_root() . '/' . $theme;
|
30 |
+
$theme_url = get_theme_root_uri() . '/' . $theme;
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
+
?>
|
35 |
+
<div class="wrap">
|
36 |
+
<div id="icon-plugins" class="icon32"><br /></div><h2>WP Smush.it: Smush Theme Assets</h2>
|
37 |
+
|
38 |
+
<?php
|
39 |
+
// Smush files
|
40 |
+
if (isset($_POST['action']) && $_POST['action'] == 'smush_theme' ):
|
41 |
+
|
42 |
+
if ( function_exists('check_admin_referer') ) check_admin_referer('wp-smushit_smush-theme' . $theme);
|
43 |
+
|
44 |
+
|
45 |
+
?>
|
46 |
+
|
47 |
+
<p>Processing files in the <strong><?php echo $theme; ?></strong> theme.</p>
|
48 |
+
|
49 |
+
<?php
|
50 |
+
|
51 |
+
foreach($_POST['smushitlink'] as $l) {
|
52 |
+
// decode and sanitize the file path
|
53 |
+
$asset_url = base64_decode($l);
|
54 |
+
$asset_path = str_replace($theme_url, $theme_path, $asset_url);
|
55 |
+
|
56 |
+
print "<p>Smushing <span class='code'>$asset_url</span><br/>";
|
57 |
+
|
58 |
+
list($processed_path, $msg) = wp_smushit($asset_path);
|
59 |
+
|
60 |
+
echo "<em>– $msg</em>.</p>\n";
|
61 |
+
ob_flush();
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
?>
|
66 |
+
|
67 |
+
<p>Finished processing all the files in the <strong><?php echo $theme; ?></strong> theme.</p>
|
68 |
+
|
69 |
+
<p><strong>Actions:</strong>
|
70 |
+
<a href="themes.php?page=<?php echo basename(dirname(__FILE__)) . '/theme.php&theme=' . $theme; ?>" title="<?php _e('Smush other files in this theme', WP_SMUSHIT_DOMAIN); ?>" target="_parent"><?php _e('Smush other files in this theme', WP_SMUSHIT_DOMAIN); ?></a> |
|
71 |
+
|
72 |
+
<a href="<?php echo '?page=' . basename(dirname(__FILE__)) . '/theme.php'; ?>" title="<?php _e('Work with a different theme', WP_SMUSHIT_DOMAIN); ?>" target="_parent"><?php _e('Work with a different theme', WP_SMUSHIT_DOMAIN); ?></a>
|
73 |
+
</p>
|
74 |
+
|
75 |
+
|
76 |
+
<?php
|
77 |
+
// Select files to smush
|
78 |
+
elseif( $theme ):
|
79 |
+
$td = get_theme_data($theme_path . '/style.css');
|
80 |
+
|
81 |
+
?>
|
82 |
+
|
83 |
+
<form method="post" action="">
|
84 |
+
<input type="hidden" name="action" value="smush_theme"/>
|
85 |
+
<?php
|
86 |
+
if ( function_exists('wp_nonce_field') ) wp_nonce_field('wp-smushit_smush-theme' . $theme);
|
87 |
+
?>
|
88 |
+
|
89 |
+
<table class="widefat fixed" cellspacing="0">
|
90 |
+
<thead>
|
91 |
+
<tr>
|
92 |
+
<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
|
93 |
+
<th scope="col" id="name" class="manage-column column-name" style="">File name</th>
|
94 |
+
</tr>
|
95 |
+
<tbody>
|
96 |
+
<?php
|
97 |
+
|
98 |
+
$theme_files = list_files($theme_path, 5);
|
99 |
+
|
100 |
+
foreach($theme_files as $file) {
|
101 |
+
|
102 |
+
if ( preg_match('/\.(jpg|jpeg|png|gif)$/i', $file) < 1 ) {
|
103 |
+
continue;
|
104 |
+
}
|
105 |
+
|
106 |
+
$file = str_replace(TEMPLATEPATH, '', $file);
|
107 |
+
|
108 |
+
$file_url = $theme_url . $file;
|
109 |
+
|
110 |
+
|
111 |
+
?>
|
112 |
+
<tr valign="middle">
|
113 |
+
<th scope="row" class="check-column"><input type="checkbox" name="smushitlink[]" value="<?php echo attribute_escape(base64_encode($file_url)); ?>" /></th>
|
114 |
+
<td class="column-name"><strong><a class='row-title' href='<?php echo $file_url; ?>'><?php echo $file_url; ?></a></strong></td>
|
115 |
+
</tr>
|
116 |
+
<?php
|
117 |
+
|
118 |
+
}
|
119 |
+
// closedir($handle);
|
120 |
+
?>
|
121 |
+
</table>
|
122 |
+
|
123 |
+
<input type="submit">
|
124 |
+
</form>
|
125 |
+
|
126 |
+
|
127 |
+
<?php else: ?>
|
128 |
+
|
129 |
+
|
130 |
+
<p>Select a theme.</p>
|
131 |
+
<ul>
|
132 |
+
<?php
|
133 |
+
$themes = get_themes();
|
134 |
+
|
135 |
+
foreach($themes as $t) {
|
136 |
+
printf("\t<li><a href=\"?page=%s&theme=%s\">%s</a></li>\n",
|
137 |
+
basename(dirname(__FILE__)) . '/theme.php',
|
138 |
+
$t['Template'],
|
139 |
+
$t['Name']);
|
140 |
+
}
|
141 |
+
?>
|
142 |
+
</ul>
|
143 |
+
<?php endif; ?>
|
144 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wp-smushit.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Integrate the Smush.it API into WordPress.
|
4 |
-
* @version 1.2.
|
5 |
* @package WP_SmushIt
|
6 |
*/
|
7 |
/*
|
@@ -9,7 +9,7 @@ Plugin Name: WP Smush.it
|
|
9 |
Plugin URI: http://dialect.ca/code/wp-smushit/
|
10 |
Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
11 |
Author: Dialect
|
12 |
-
Version: 1.2.
|
13 |
Author URI: http://dialect.ca/?wp_smush_it
|
14 |
*/
|
15 |
|
@@ -22,13 +22,16 @@ if ( !class_exists('Services_JSON') ) {
|
|
22 |
* Constants
|
23 |
*/
|
24 |
|
25 |
-
define('SMUSHIT_REQ_URL', 'http://smushit.com/ws.php?img=%s');
|
|
|
|
|
26 |
|
27 |
define('SMUSHIT_BASE_URL', 'http://smushit.com/');
|
28 |
|
|
|
29 |
define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
|
30 |
|
31 |
-
define('WP_SMUSHIT_UA', 'WP Smush.it/1.
|
32 |
|
33 |
define('WP_SMUSHIT_GIF_TO_PNG', intval(get_option('wp_smushit_gif_to_png')));
|
34 |
|
@@ -53,7 +56,7 @@ add_action('manage_media_custom_column', 'wp_smushit_custom_column', 10, 2);
|
|
53 |
add_action('admin_menu', 'wp_smushit_add_pages');
|
54 |
add_action('admin_init', 'wp_smushit_init');
|
55 |
add_action('admin_action_wp_smushit_manual', 'wp_smushit_manual');
|
56 |
-
|
57 |
|
58 |
|
59 |
/**
|
@@ -70,7 +73,7 @@ function wp_smushit_init() {
|
|
70 |
}
|
71 |
|
72 |
function wp_smushit_add_pages() {
|
73 |
-
|
74 |
add_options_page(__('WP Smush.it Options', WP_SMUSHIT_OPTIONS), 'WP Smush.it', 8, dirname(__FILE__) . '/options.php');
|
75 |
add_filter( 'plugin_action_links', 'wp_smushit_filter_plugin_actions', 10, 2 );
|
76 |
}
|
@@ -91,8 +94,7 @@ function wp_smushit_options() {
|
|
91 |
* Process all the images from a given theme
|
92 |
*/
|
93 |
function wp_smushit_theme() {
|
94 |
-
|
95 |
-
exit(0);
|
96 |
}
|
97 |
|
98 |
|
@@ -193,10 +195,16 @@ function wp_smushit($file) {
|
|
193 |
$processed_url = SMUSHIT_BASE_URL . $processed_url;
|
194 |
}
|
195 |
|
196 |
-
$temp_file =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
-
if ( false === $temp_file )
|
199 |
-
return array($file, __('Error updating file', WP_SMUSHIT_DOMAIN) );
|
200 |
|
201 |
// check if Smush.it converted a GIF to a PNG
|
202 |
if( 1 == WP_SMUSHIT_GIF_TO_PNG && wp_smushit_did_gif_to_png($file, $data->dest) ) {
|
@@ -302,56 +310,6 @@ function wp_smushit_did_gif_to_png($orig, $new) {
|
|
302 |
|
303 |
}
|
304 |
|
305 |
-
/**
|
306 |
-
* Download a remote file to a temp file.
|
307 |
-
*
|
308 |
-
* Used to download a processed image from Smush.it.
|
309 |
-
*
|
310 |
-
* @param string $remote_file URL of the file to download
|
311 |
-
* @return string|boolean Returns the temp file path on success or else FALSE
|
312 |
-
*/
|
313 |
-
function wp_smushit_download($remote_file) {
|
314 |
-
$temp_file = tempnam( WP_CONTENT_DIR, '___' );
|
315 |
-
|
316 |
-
if ( function_exists('wp_remote_get') ) {
|
317 |
-
// try using WordPress's built-in HTTP class
|
318 |
-
$response = wp_remote_get($remote_file, array('user-agent' => WP_SMUSHIT_UA));
|
319 |
-
|
320 |
-
if ( 200 != wp_remote_retrieve_response_code($response) )
|
321 |
-
return false;
|
322 |
-
|
323 |
-
$data = wp_remote_retrieve_body($response);
|
324 |
-
|
325 |
-
if ( function_exists('file_put_contents') ) {
|
326 |
-
if ( false === file_put_contents($temp_file, $data) )
|
327 |
-
return false;
|
328 |
-
|
329 |
-
} else { // PHP < 5
|
330 |
-
$fh = @fopen($temp_file, 'w');
|
331 |
-
|
332 |
-
if ( FALSE === $fh )
|
333 |
-
return false;
|
334 |
-
|
335 |
-
if ( FALSE === fwrite($fh, $data) )
|
336 |
-
return false;
|
337 |
-
|
338 |
-
fclose($fh);
|
339 |
-
}
|
340 |
-
|
341 |
-
} else {
|
342 |
-
wp_smushit_check_url_fopen();
|
343 |
-
|
344 |
-
// try using 'fopen' via 'copy'
|
345 |
-
if( FALSE === @copy( $remote_file, $temp_file ) )
|
346 |
-
return false;
|
347 |
-
}
|
348 |
-
|
349 |
-
chmod( $temp_file, 0644 );
|
350 |
-
|
351 |
-
return $temp_file;
|
352 |
-
}
|
353 |
-
|
354 |
-
|
355 |
/**
|
356 |
* Post an image to Smush.it.
|
357 |
*
|
@@ -363,13 +321,14 @@ function wp_smushit_post($file_url) {
|
|
363 |
|
364 |
$data = false;
|
365 |
|
366 |
-
if (
|
367 |
$response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA));
|
368 |
|
369 |
-
if ( 200 != wp_remote_retrieve_response_code($response) )
|
370 |
return false;
|
|
|
371 |
|
372 |
-
$data =
|
373 |
} else {
|
374 |
wp_smushit_check_url_fopen();
|
375 |
|
@@ -397,14 +356,20 @@ function wp_smushit_post($file_url) {
|
|
397 |
* Calls `wp_die()` if not, otherwise returns true.
|
398 |
*/
|
399 |
function wp_smushit_check_url_fopen() {
|
400 |
-
|
401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
$err = __('Remote fopen is not enabled (<a href="http://dialect.ca/code/wp-smushit/#fopen_note" target="_blank">more info</a>)', WP_SMUSHIT_DOMAIN);
|
403 |
wp_die($err);
|
404 |
-
return false;
|
405 |
}
|
406 |
|
407 |
-
return
|
408 |
}
|
409 |
|
410 |
/**
|
1 |
<?php
|
2 |
/**
|
3 |
* Integrate the Smush.it API into WordPress.
|
4 |
+
* @version 1.2.5
|
5 |
* @package WP_SmushIt
|
6 |
*/
|
7 |
/*
|
9 |
Plugin URI: http://dialect.ca/code/wp-smushit/
|
10 |
Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
11 |
Author: Dialect
|
12 |
+
Version: 1.2.5
|
13 |
Author URI: http://dialect.ca/?wp_smush_it
|
14 |
*/
|
15 |
|
22 |
* Constants
|
23 |
*/
|
24 |
|
25 |
+
//define('SMUSHIT_REQ_URL', 'http://smushit.com/ws.php?img=%s');
|
26 |
+
//define('SMUSHIT_REQ_URL', 'http://smushit.com/ysmush.it/ws.php?img=%s');
|
27 |
+
define('SMUSHIT_REQ_URL', 'http://ws1.adq.ac4.yahoo.com/ysmush.it/ws.php?img=%s');
|
28 |
|
29 |
define('SMUSHIT_BASE_URL', 'http://smushit.com/');
|
30 |
|
31 |
+
|
32 |
define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
|
33 |
|
34 |
+
define('WP_SMUSHIT_UA', 'WP Smush.it/1.2.5 (+http://dialect.ca/code/wp-smushit)');
|
35 |
|
36 |
define('WP_SMUSHIT_GIF_TO_PNG', intval(get_option('wp_smushit_gif_to_png')));
|
37 |
|
56 |
add_action('admin_menu', 'wp_smushit_add_pages');
|
57 |
add_action('admin_init', 'wp_smushit_init');
|
58 |
add_action('admin_action_wp_smushit_manual', 'wp_smushit_manual');
|
59 |
+
add_action('admin_action_wp_smushit_theme', 'wp_smushit_theme');
|
60 |
|
61 |
|
62 |
/**
|
73 |
}
|
74 |
|
75 |
function wp_smushit_add_pages() {
|
76 |
+
add_submenu_page('themes.php', 'Smush.it', 'WP Smush.it', 8, dirname(__FILE__) . '/theme.php');
|
77 |
add_options_page(__('WP Smush.it Options', WP_SMUSHIT_OPTIONS), 'WP Smush.it', 8, dirname(__FILE__) . '/options.php');
|
78 |
add_filter( 'plugin_action_links', 'wp_smushit_filter_plugin_actions', 10, 2 );
|
79 |
}
|
94 |
* Process all the images from a given theme
|
95 |
*/
|
96 |
function wp_smushit_theme() {
|
97 |
+
require_once('theme.php');
|
|
|
98 |
}
|
99 |
|
100 |
|
195 |
$processed_url = SMUSHIT_BASE_URL . $processed_url;
|
196 |
}
|
197 |
|
198 |
+
$temp_file = download_url($processed_url);
|
199 |
+
|
200 |
+
if ( is_wp_error($temp_file) ) {
|
201 |
+
@unlink($tmp);
|
202 |
+
$results_msg = sprintf(__("Error downloading file (%s)", WP_SMUSHIT_DOMAIN),
|
203 |
+
$temp_file->get_error_message());
|
204 |
+
return array($file, $results_msg );
|
205 |
+
}
|
206 |
+
|
207 |
|
|
|
|
|
208 |
|
209 |
// check if Smush.it converted a GIF to a PNG
|
210 |
if( 1 == WP_SMUSHIT_GIF_TO_PNG && wp_smushit_did_gif_to_png($file, $data->dest) ) {
|
310 |
|
311 |
}
|
312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
/**
|
314 |
* Post an image to Smush.it.
|
315 |
*
|
321 |
|
322 |
$data = false;
|
323 |
|
324 |
+
if ( function_exists('wp_remote_get') ) {
|
325 |
$response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA));
|
326 |
|
327 |
+
if ( 200 != wp_remote_retrieve_response_code($response) ) {
|
328 |
return false;
|
329 |
+
}
|
330 |
|
331 |
+
$data = wp_remote_retrieve_body($response);
|
332 |
} else {
|
333 |
wp_smushit_check_url_fopen();
|
334 |
|
356 |
* Calls `wp_die()` if not, otherwise returns true.
|
357 |
*/
|
358 |
function wp_smushit_check_url_fopen() {
|
359 |
+
$use_fopen = false;
|
360 |
+
|
361 |
+
if ( class_exists('WP_Http_Fopen') ) {
|
362 |
+
$use_fopen = WP_Http_Fopen::test();
|
363 |
+
} else {
|
364 |
+
$use_fopen = ( function_exists('fopen') && ini_get('allow_url_fopen') == true );
|
365 |
+
}
|
366 |
+
|
367 |
+
if ( !$use_fopen ) {
|
368 |
$err = __('Remote fopen is not enabled (<a href="http://dialect.ca/code/wp-smushit/#fopen_note" target="_blank">more info</a>)', WP_SMUSHIT_DOMAIN);
|
369 |
wp_die($err);
|
|
|
370 |
}
|
371 |
|
372 |
+
return $use_fopen;
|
373 |
}
|
374 |
|
375 |
/**
|