Skip to content

Commit 88812a4

Browse files
author
Jacob Middag
committed
Minor improvements for bulk compressions
1 parent 7e92739 commit 88812a4

5 files changed

Lines changed: 36 additions & 19 deletions

File tree

src/class-tiny-plugin.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public function enqueue_scripts($hook) {
7575
wp_localize_script($handle, 'tinyCompress', array(
7676
'nonce' => wp_create_nonce('tiny-compress'),
7777
'L10nAllDone' => self::translate('All images are processed'),
78-
'L10nBulkAction' => self::translate('Compress all'),
78+
'L10nBulkAction' => self::translate('Compress images'),
7979
'L10nCompressing' => self::translate('Compressing'),
80+
'L10nCompressions' => self::translate('compressions'),
8081
'L10nError' => self::translate('Error'),
8182
'L10nInternalError' => self::translate('Internal error'),
8283
'L10nOutOf' => self::translate('out of'),
@@ -143,6 +144,7 @@ public function compress_image() {
143144

144145
list($tiny_metadata, $result) = $this->compress($metadata, $id);
145146
if ($json) {
147+
$result['message'] = $tiny_metadata->get_latest_error();
146148
$result['status'] = $this->settings->get_status();
147149
$result['thumbnail'] = $tiny_metadata->get_url('thumbnail');
148150
echo json_encode($result);
@@ -206,16 +208,24 @@ private function render_compress_details($tiny_metadata) {
206208
}
207209

208210
public function bulk_compress_page() {
211+
global $wpdb;
212+
209213
echo '<div class="wrap" id="tiny-bulk-compress">';
210214
echo '<h2>' . self::translate('Compress JPEG & PNG Images') . '</h2>';
211215
if (empty($_POST['tiny-bulk-compress']) && empty($_REQUEST['ids'])) {
212-
echo '<p>' . self::translate_escape("Use this tool to compress all images via the Tiny API service") . '.</p>';
213-
echo '<p>' . self::translate_escape("To begin, just press the button below") . '.</p>';
216+
$result = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC", ARRAY_A);
217+
$count = $result[0]['count'];
218+
219+
echo '<p>' . self::translate_escape("Use this tool to compress all images in your media library") . '. ';
220+
echo self::translate_escape("Only images that have not been compressed will be compressed") . '.</p>';
221+
echo '<p>' . sprintf(self::translate_escape("We have found %d images in your media library"), $count) . '. ';
222+
echo self::translate_escape("To begin, just press the button below") . '.</p>';
214223

215224
echo '<form method="POST" action="?page=tiny-bulk-compress">';
216225
echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce('tiny-bulk-compress') . '">';
217226
echo '<input type="hidden" name="tiny-bulk-compress" value="1">';
218-
echo '<p><button class="button" type="submit">'. self::translate_escape('Compress all images') .'</p>';
227+
echo '<p><button class="button button-primary button-large" type="submit">' .
228+
self::translate_escape('Compress all images') . '</p>';
219229
echo '</form>';
220230
} else {
221231
check_admin_referer('tiny-bulk-compress');
@@ -227,7 +237,6 @@ public function bulk_compress_page() {
227237
$cond = "";
228238
}
229239

230-
global $wpdb;
231240
// Get all ids and names of the images and not the whole objects which will only fill memory
232241
$items = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' $cond ORDER BY ID DESC", ARRAY_A);
233242

@@ -239,7 +248,7 @@ public function bulk_compress_page() {
239248
echo "</p>";
240249

241250
echo '<div id="tiny-status"><p>'. self::translate_escape('Compressions this month') . sprintf(' <span>%d</span></p></div>', $this->settings->get_status());
242-
echo '<div id="tiny-progress"><p>'. self::translate_escape('Processing') . ': <span>0</span> ' . self::translate_escape('out of') . sprintf(' %d </p></div>', count($items));
251+
echo '<div id="tiny-progress"><p>'. self::translate_escape('Processing') . ' <span>0</span> ' . self::translate_escape('out of') . sprintf(' %d </p></div>', count($items));
243252
echo '<div id="tiny-images">';
244253
echo '</div>';
245254

341 Bytes
Binary file not shown.

src/languages/tiny-compress-images-nl_NL.po

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ msgstr "Compressie"
3737
msgid "Compress"
3838
msgstr "Comprimeer"
3939

40-
msgid "Compress all"
41-
msgstr "Comprimeer alles"
40+
msgid "Compress images"
41+
msgstr "Comprimeer afbeeldingen"
4242

4343
msgid "Compressed %d out of %d sizes"
4444
msgstr "%d van de %d afmetingen zijn gecomprimeerd"
@@ -143,10 +143,10 @@ msgid "Please fill in an API key to start compressing images"
143143
msgstr "Vul een API-sleutel in om te starten met comprimeren"
144144

145145
msgid "Compress all images"
146-
msgstr "Comprimeer afbeeldingen"
146+
msgstr "Comprimeer alle afbeeldingen"
147147

148148
msgid "Compress JPEG & PNG Images"
149-
msgstr "Comprimeer alle JPEG & PNG afbeeldingen"
149+
msgstr "Comprimeer JPEG & PNG afbeeldingen"
150150

151151
msgid "All images are processed"
152152
msgstr "Alle afbeeldingen zijn verwerkt"
@@ -163,11 +163,20 @@ msgstr "Wachten"
163163
msgid "Compressing"
164164
msgstr "Comprimeren"
165165

166+
msgid "compressions"
167+
msgstr "compressies"
168+
166169
msgid "out of"
167170
msgstr "van de"
168171

169-
msgid "Use this tool to compress all images via the Tiny API service"
170-
msgstr "Deze tool comprimeert alle afbeeldingen via de Tiny API-dienst"
172+
msgid "Use this tool to compress all images in your media library"
173+
msgstr "Deze tool comprimeert alle afbeeldingen in je media-bibliotheek"
174+
175+
msgid "Only images that have not been compressed will be compressed"
176+
msgstr "Dit geldt alleen voor de afbeeldingen die nog niet zijn gecomprimeerd"
177+
178+
msgid "We have found %d images in your media library"
179+
msgstr "We hebben %d afbeeldingen in de media-bibliotheek gevonden"
171180

172181
msgid "To begin, just press the button below"
173182
msgstr "Druk op de knop om te starten"

src/scripts/admin.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,19 @@
5757
if (error) {
5858
row.find('.bar').addClass('failed')
5959
row.find('.percent').html(tinyCompress.L10nInternalError)
60-
row.find('.percent').attr("title", error.toString())
60+
row.find('.progress').attr("title", error.toString())
6161
} else if (data.error) {
6262
row.find('.bar').addClass('failed')
6363
row.find('.percent').html(tinyCompress.L10nError)
64-
row.find('.percent').attr("title", data.error)
64+
row.find('.progress').attr("title", data.error)
6565
} else if (data.failed > 0) {
6666
row.find('.bar').addClass('failed')
6767
row.find('.bar').css('width', '100%')
68-
row.find('.percent').html(
69-
data.failed + " " + tinyCompress.L10nOutOf + " " + (data.success + data.failed))
68+
row.find('.percent').html(data.success + " " + tinyCompress.L10nCompressions)
69+
row.find('.progress').attr("title", data.message)
7070
} else {
7171
row.find('.bar').css('width', '100%')
72-
row.find('.percent').html(
73-
data.success + " " + tinyCompress.L10nOutOf + " " + (data.success + data.failed))
72+
row.find('.percent').html(data.success + " " + tinyCompress.L10nCompressions)
7473
}
7574
if (data.status) {
7675
jQuery('#tiny-status span').html(data.status)

test/integration/BulkCompressIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function tearDown() {
1717
public function testBulkCompressActionShouldBePresentInMedia() {
1818
$this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png');
1919
self::$driver->get(wordpress('/wp-admin/upload.php?mode=list'));
20-
$this->assertEquals('Compress all', self::$driver->findElement(
20+
$this->assertEquals('Compress images', self::$driver->findElement(
2121
WebDriverBy::cssSelector('select[name="action"] option[value="tiny_bulk_compress"]')
2222
)->getText());
2323
}

0 commit comments

Comments
 (0)