WP Retina 2x - Version 5.2.8

Version Description

  • Fix: Security update.
  • Update: Lazysizes 4.0.3.
Download this release

Release Info

Developer TigrouMeow
Plugin Icon 128x128 WP Retina 2x
Version 5.2.8
Comparing to
See all releases

Code changes from version 5.2.7 to 5.2.8

Files changed (5) hide show
  1. ajax.php +47 -324
  2. core.php +26 -2
  3. js/admin.js +320 -0
  4. readme.txt +2 -2
  5. wp-retina-2x.php +2 -2
ajax.php CHANGED
@@ -13,326 +13,38 @@ class Meow_WR2X_Ajax {
13
  add_action( 'wp_ajax_wr2x_replace', array( $this, 'wp_ajax_wr2x_replace' ) );
14
  add_action( 'wp_ajax_wr2x_upload', array( $this, 'wp_ajax_wr2x_upload' ) );
15
  add_action( 'wp_ajax_wr2x_retina_details', array( $this, 'wp_ajax_wr2x_retina_details' ) );
16
- add_action( 'admin_head', array( $this, 'admin_head' ) );
17
  }
18
 
19
- function admin_head() {
20
- ?>
21
- <script type="text/javascript" >
22
-
23
- /* GENERATE RETINA IMAGES ACTION */
24
-
25
- var current;
26
- var maxPhpSize = <?php echo $this->core->get_max_filesize(); ?>;
27
- var ids = [];
28
- var errors = 0;
29
- var ajax_action = "generate"; // generate | delete
30
-
31
- function wr2x_display_please_refresh() {
32
- wr2x_refresh_progress_status();
33
- jQuery('#wr2x_progression').html(jQuery('#wr2x_progression').html() + " - <?php echo _e( "<a href='?page=wp-retina-2x&view=issues&refresh=true'>Refresh</a> this page.", 'wp-retina-2x' ); ?>");
34
- }
35
-
36
- function wr2x_refresh_progress_status() {
37
- var errortext = "";
38
- if ( errors > 0 ) {
39
- errortext = ' - ' + errors + ' error(s)';
40
- }
41
- jQuery('#wr2x_progression').text(current + "/" + ids.length +
42
- " (" + Math.round(current / ids.length * 100) + "%)" + errortext);
43
- }
44
-
45
- function wr2x_do_next () {
46
- var data = { action: 'wr2x_' + ajax_action, attachmentId: ids[current - 1] };
47
- wr2x_refresh_progress_status();
48
- jQuery.post(ajaxurl, data, function (response) {
49
- try {
50
- reply = jQuery.parseJSON(response);
51
- }
52
- catch (e) {
53
- reply = null;
54
- }
55
- if ( !reply || !reply.success )
56
- errors++;
57
- else {
58
- wr2x_refresh_media_sizes(reply.results);
59
- if (reply.results_full)
60
- wr2x_refresh_full(reply.results_full);
61
- }
62
- if (++current <= ids.length)
63
- wr2x_do_next();
64
- else {
65
- current--;
66
- wr2x_display_please_refresh();
67
- }
68
- }).fail(function () {
69
- errors++;
70
- if (++current <= ids.length)
71
- wr2x_do_next();
72
- else {
73
- current--;
74
- wr2x_display_please_refresh();
75
- }
76
- });
77
- }
78
-
79
- function wr2x_do_all () {
80
- current = 1;
81
- ids = [];
82
- errors = 0;
83
- var data = { action: 'wr2x_list_all', issuesOnly: 0 };
84
- jQuery('#wr2x_progression').text("<?php _e( "Wait...", 'wp-retina-2x' ); ?>");
85
- jQuery.post(ajaxurl, data, function (response) {
86
- reply = jQuery.parseJSON(response);
87
- if (reply.success = false) {
88
- alert('Error: ' + reply.message);
89
- return;
90
- }
91
- if (reply.total == 0) {
92
- jQuery('#wr2x_progression').html("<?php _e( "Nothing to do ;)", 'wp-retina-2x' ); ?>");
93
- return;
94
- }
95
- ids = reply.ids;
96
- jQuery('#wr2x_progression').text(current + "/" + ids.length + " (" + Math.round(current / ids.length * 100) + "%)");
97
- wr2x_do_next();
98
- });
99
- }
100
-
101
- function wr2x_delete_all () {
102
- ajax_action = 'delete';
103
- wr2x_do_all();
104
- }
105
-
106
- function wr2x_generate_all () {
107
- ajax_action = 'generate';
108
- wr2x_do_all();
109
- }
110
-
111
- // Refresh the dashboard retina full with the results from the Ajax operation (Upload)
112
- function wr2x_refresh_full (results) {
113
- jQuery.each(results, function (id, html) {
114
- jQuery('#wr2x-info-full-' + id).html(html);
115
- jQuery('#wr2x-info-full-' + id + ' img').attr('src', jQuery('#wr2x-info-full-' + id + ' img').attr('src')+'?'+ Math.random());
116
- jQuery('#wr2x-info-full-' + id + ' img').on('click', function (evt) {
117
- wr2x_delete_full( jQuery(evt.target).parents('.wr2x-file-row').attr('postid') );
118
- });
119
- });
120
- }
121
-
122
- // Refresh the dashboard media sizes with the results from the Ajax operation (Replace or Generate)
123
- function wr2x_refresh_media_sizes (results) {
124
- jQuery.each(results, function (id, html) {
125
- jQuery('#wr2x-info-' + id).html(html);
126
- });
127
- }
128
-
129
- function wr2x_generate (attachmentId, retinaDashboard) {
130
- var data = { action: 'wr2x_generate', attachmentId: attachmentId };
131
- jQuery('#wr2x_generate_button_' + attachmentId).text("<?php echo __( "Wait...", 'wp-retina-2x' ); ?>");
132
- jQuery.post(ajaxurl, data, function (response) {
133
- var reply = jQuery.parseJSON(response);
134
- if (!reply.success) {
135
- alert(reply.message);
136
- return;
137
- }
138
- jQuery('#wr2x_generate_button_' + attachmentId).html("<?php echo __( "GENERATE", 'wp-retina-2x' ); ?>");
139
- wr2x_refresh_media_sizes(reply.results);
140
- });
141
- }
142
-
143
- /* REPLACE FUNCTION */
144
-
145
- function wr2x_stop_propagation(evt) {
146
- evt.stopPropagation();
147
- evt.preventDefault();
148
- }
149
-
150
- function wr2x_delete_full(attachmentId) {
151
- var data = {
152
- action: 'wr2x_delete_full',
153
- isAjax: true,
154
- attachmentId: attachmentId
155
- };
156
-
157
- jQuery.post(ajaxurl, data, function (response) {
158
- var data = jQuery.parseJSON(response);
159
- if (data.success === false) {
160
- alert(data.message);
161
- }
162
- else {
163
- wr2x_refresh_full(data.results);
164
- wr2x_display_please_refresh();
165
- }
166
- });
167
- }
168
-
169
- function wr2x_load_details(attachmentId) {
170
- var data = {
171
- action: 'wr2x_retina_details',
172
- isAjax: true,
173
- attachmentId: attachmentId
174
- };
175
-
176
- jQuery.post(ajaxurl, data, function (response) {
177
- var data = jQuery.parseJSON(response);
178
- if (data.success === false) {
179
- alert(data.message);
180
- }
181
- else {
182
- jQuery('#meow-modal-info .loading').css('display', 'none');
183
- jQuery('#meow-modal-info .content').html(data.result);
184
- }
185
- });
186
- }
187
-
188
- function wr2x_filedropped (evt) {
189
- wr2x_stop_propagation(evt);
190
- var files = evt.dataTransfer.files;
191
- var count = files.length;
192
- if (count < 0) {
193
- return;
194
- }
195
-
196
- var wr2x_replace = jQuery(evt.target).parent().hasClass('wr2x-fullsize-replace');
197
- var wr2x_upload = jQuery(evt.target).parent().hasClass('wr2x-fullsize-retina-upload');
198
-
199
- function wr2x_handleprogress(prg) {
200
- console.debug("Upload of " + prg.srcElement.filename + ": " + prg.loaded / prg.total * 100 + "%");
201
- }
202
-
203
- function wr2x_uploadFile(file, attachmentId, filename) {
204
- var action = "";
205
- if (wr2x_replace) {
206
- action = 'wr2x_replace';
207
- }
208
- else if (wr2x_upload) {
209
- action = 'wr2x_upload';
210
- }
211
- else {
212
- alert("Unknown command. Contact the developer.");
213
- }
214
- var data = new FormData();
215
- data.append('file', file);
216
- data.append('action', action);
217
- data.append('attachmentId', attachmentId);
218
- data.append('isAjax', true);
219
- data.append('filename', filename);
220
- // var data = {
221
- // action: action,
222
- // isAjax: true,
223
- // filename: evt.target.filename,
224
- // data: form_data,
225
- // attachmentId: attachmentId
226
- // };
227
-
228
- jQuery.ajax({
229
- type: 'POST',
230
- url: ajaxurl,
231
- contentType: false,
232
- processData: false,
233
- data: data,
234
- success: function (response) {
235
- jQuery('[postid=' + attachmentId + '] td').removeClass('wr2x-loading-file');
236
- jQuery('[postid=' + attachmentId + '] .wr2x-dragdrop').removeClass('wr2x-hover-drop');
237
- try {
238
- var data = jQuery.parseJSON(response);
239
- }
240
- catch (e) {
241
- alert("The server-side returned an abnormal response. Check your PHP error logs and also your browser console (WP Retina 2x will try to display it there).");
242
- console.debug(response);
243
- return;
244
- }
245
- if (wr2x_replace) {
246
- var imgSelector = '[postid=' + attachmentId + '] .wr2x-info-thumbnail img';
247
- jQuery(imgSelector).attr('src', jQuery(imgSelector).attr('src')+'?'+ Math.random());
248
- }
249
- if (wr2x_upload) {
250
- var imgSelector = '[postid=' + attachmentId + '] .wr2x-info-full img';
251
- jQuery(imgSelector).attr('src', jQuery(imgSelector).attr('src')+'?'+ Math.random());
252
- }
253
- if (data.success === false) {
254
- alert(data.message);
255
- }
256
- else {
257
- if ( wr2x_replace ) {
258
- wr2x_refresh_media_sizes(data.results);
259
- }
260
- else if ( wr2x_upload ) {
261
- wr2x_refresh_full(data.results);
262
- }
263
- }
264
- },
265
- error: function(XMLHttpRequest, textStatus, errorThrown) {
266
- jQuery('[postid=' + attachmentId + '] td').removeClass('wr2x-loading-file');
267
- jQuery('[postid=' + attachmentId + '] .wr2x-dragdrop').removeClass('wr2x-hover-drop');
268
- alert("An error occurred on the server-side. Please check your PHP error logs.");
269
- }
270
- });
271
- }
272
- var file = files[0];
273
- if (file.size > maxPhpSize) {
274
- jQuery(this).removeClass('wr2x-hover-drop');
275
- alert( "Your PHP configuration only allows file upload of a maximum of " + (maxPhpSize / 1000000) + "MB." );
276
- return;
277
- }
278
- var postId = jQuery(evt.target).parents('.wr2x-file-row').attr('postid');
279
- jQuery(evt.target).parents('td').addClass('wr2x-loading-file');
280
- wr2x_uploadFile(file, postId, file.name);
281
- }
282
 
283
- jQuery(document).ready(function () {
284
- jQuery('.wr2x-dragdrop').on('dragenter', function (evt) {
285
- wr2x_stop_propagation(evt);
286
- jQuery(this).addClass('wr2x-hover-drop');
287
- });
288
-
289
- jQuery('.wr2x-dragdrop').on('dragover', function (evt) {
290
- wr2x_stop_propagation(evt);
291
- jQuery(this).addClass('wr2x-hover-drop');
292
- });
293
-
294
- jQuery('.wr2x-dragdrop').on('dragleave', function (evt) {
295
- wr2x_stop_propagation(evt);
296
- jQuery(this).removeClass('wr2x-hover-drop');
297
- });
298
-
299
- jQuery('.wr2x-dragdrop').on('dragexit', wr2x_stop_propagation);
300
-
301
- jQuery('.wr2x-dragdrop').each(function (index, elem) {
302
- this.addEventListener('drop', wr2x_filedropped);
303
- });
304
-
305
- jQuery('.wr2x-info, .wr2x-button-view').on('click', function (evt) {
306
- jQuery('#meow-modal-info-backdrop').css('display', 'block');
307
- jQuery('#meow-modal-info .content').html("");
308
- jQuery('#meow-modal-info .loading').css('display', 'block');
309
- jQuery('#meow-modal-info').css('display', 'block');
310
- jQuery('#meow-modal-info').focus();
311
- var postid = jQuery(evt.target).parents('.wr2x-info').attr('postid');
312
- if (!postid)
313
- postid = jQuery(evt.target).parents('.wr2x-file-row').attr('postid');
314
- wr2x_load_details(postid);
315
- });
316
-
317
- jQuery('#meow-modal-info .close, #meow-modal-info-backdrop').on('click', function (evt) {
318
- jQuery('#meow-modal-info').css('display', 'none');
319
- jQuery('#meow-modal-info-backdrop').css('display', 'none');
320
- });
321
-
322
- jQuery('.wr2x-info-full img').on('click', function (evt) {
323
- wr2x_delete_full( jQuery(evt.target).parents('.wr2x-file-row').attr('postid') );
324
- });
325
-
326
- jQuery('#meow-modal-info').bind('keydown', function (evt) {
327
- if (evt.keyCode === 27) {
328
- jQuery('#meow-modal-info').css('display', 'none');
329
- jQuery('#meow-modal-info-backdrop').css('display', 'none');
330
- }
331
- });
332
- });
333
-
334
- </script>
335
- <?php
336
  }
337
 
338
  /**
@@ -343,6 +55,9 @@ class Meow_WR2X_Ajax {
343
 
344
  // Using issuesOnly, only the IDs with a PENDING status will be processed
345
  function wp_ajax_wr2x_list_all( $issuesOnly ) {
 
 
 
346
  $issuesOnly = intval( $_POST['issuesOnly'] );
347
  if ( $issuesOnly == 1 ) {
348
  $ids = $this->core->get_issues();
@@ -395,6 +110,8 @@ class Meow_WR2X_Ajax {
395
  }
396
 
397
  function wp_ajax_wr2x_delete_full( $pleaseReturn = false ) {
 
 
398
 
399
  if ( !isset( $_POST['attachmentId'] ) ) {
400
  echo json_encode(
@@ -431,6 +148,8 @@ class Meow_WR2X_Ajax {
431
  }
432
 
433
  function wp_ajax_wr2x_delete() {
 
 
434
 
435
  if ( !isset( $_POST['attachmentId'] ) ) {
436
  echo json_encode(
@@ -465,6 +184,9 @@ class Meow_WR2X_Ajax {
465
  }
466
 
467
  function wp_ajax_wr2x_retina_details() {
 
 
 
468
  if ( !isset( $_POST['attachmentId'] ) ) {
469
  echo json_encode(
470
  array(
@@ -488,6 +210,9 @@ class Meow_WR2X_Ajax {
488
  }
489
 
490
  function wp_ajax_wr2x_generate() {
 
 
 
491
  if ( !isset( $_POST['attachmentId'] ) ) {
492
  echo json_encode(
493
  array(
@@ -524,13 +249,7 @@ class Meow_WR2X_Ajax {
524
  }
525
 
526
  function check_get_ajax_uploaded_file() {
527
- if ( !current_user_can('upload_files') ) {
528
- echo json_encode( array(
529
- 'success' => false,
530
- 'message' => __( "You do not have permission to upload files.", 'wp-retina-2x' )
531
- ));
532
- die();
533
- }
534
 
535
  $tmpfname = $_FILES['file']['tmp_name'];
536
 
@@ -562,6 +281,8 @@ class Meow_WR2X_Ajax {
562
  }
563
 
564
  function wp_ajax_wr2x_upload() {
 
 
565
  try {
566
  $tmpfname = $this->check_get_ajax_uploaded_file();
567
  $attachmentId = (int) $_POST['attachmentId'];
@@ -610,6 +331,8 @@ class Meow_WR2X_Ajax {
610
  }
611
 
612
  function wp_ajax_wr2x_replace() {
 
 
613
  $tmpfname = $this->check_get_ajax_uploaded_file();
614
  $attachmentId = (int) $_POST['attachmentId'];
615
  $meta = wp_get_attachment_metadata( $attachmentId );
13
  add_action( 'wp_ajax_wr2x_replace', array( $this, 'wp_ajax_wr2x_replace' ) );
14
  add_action( 'wp_ajax_wr2x_upload', array( $this, 'wp_ajax_wr2x_upload' ) );
15
  add_action( 'wp_ajax_wr2x_retina_details', array( $this, 'wp_ajax_wr2x_retina_details' ) );
 
16
  }
17
 
18
+ /**
19
+ * Checks nonce for the specified action
20
+ * @param string $action
21
+ */
22
+ function check_nonce( $action ) {
23
+ if ( !wp_verify_nonce( $_POST['nonce'], $action ) ) {
24
+ echo json_encode(
25
+ array (
26
+ 'success' => false,
27
+ 'message' => __( "Invalid API request.", 'wp-retina-2x' )
28
+ )
29
+ );
30
+ die();
31
+ }
32
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ /**
35
+ * Checks if the current user has sufficient permissions to perform the Ajax actions
36
+ */
37
+ function check_capability() {
38
+ $cap = 'upload_files';
39
+ if ( !current_user_can( $cap ) ) {
40
+ echo json_encode(
41
+ array (
42
+ 'success' => false,
43
+ 'message' => __( "You do not have permission to upload files.", 'wp-retina-2x' )
44
+ )
45
+ );
46
+ die();
47
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  }
49
 
50
  /**
55
 
56
  // Using issuesOnly, only the IDs with a PENDING status will be processed
57
  function wp_ajax_wr2x_list_all( $issuesOnly ) {
58
+ $this->check_nonce( 'wr2x_list_all' );
59
+ $this->check_capability();
60
+
61
  $issuesOnly = intval( $_POST['issuesOnly'] );
62
  if ( $issuesOnly == 1 ) {
63
  $ids = $this->core->get_issues();
110
  }
111
 
112
  function wp_ajax_wr2x_delete_full( $pleaseReturn = false ) {
113
+ if ( !$pleaseReturn ) $this->check_nonce( 'wr2x_delete_full' );
114
+ $this->check_capability();
115
 
116
  if ( !isset( $_POST['attachmentId'] ) ) {
117
  echo json_encode(
148
  }
149
 
150
  function wp_ajax_wr2x_delete() {
151
+ $this->check_nonce( 'wr2x_delete' );
152
+ $this->check_capability();
153
 
154
  if ( !isset( $_POST['attachmentId'] ) ) {
155
  echo json_encode(
184
  }
185
 
186
  function wp_ajax_wr2x_retina_details() {
187
+ $this->check_nonce( 'wr2x_retina_details' );
188
+ $this->check_capability();
189
+
190
  if ( !isset( $_POST['attachmentId'] ) ) {
191
  echo json_encode(
192
  array(
210
  }
211
 
212
  function wp_ajax_wr2x_generate() {
213
+ $this->check_nonce( 'wr2x_generate' );
214
+ $this->check_capability();
215
+
216
  if ( !isset( $_POST['attachmentId'] ) ) {
217
  echo json_encode(
218
  array(
249
  }
250
 
251
  function check_get_ajax_uploaded_file() {
252
+ $this->check_capability();
 
 
 
 
 
 
253
 
254
  $tmpfname = $_FILES['file']['tmp_name'];
255
 
281
  }
282
 
283
  function wp_ajax_wr2x_upload() {
284
+ $this->check_nonce( 'wr2x_upload' );
285
+
286
  try {
287
  $tmpfname = $this->check_get_ajax_uploaded_file();
288
  $attachmentId = (int) $_POST['attachmentId'];
331
  }
332
 
333
  function wp_ajax_wr2x_replace() {
334
+ $this->check_nonce( 'wr2x_replace' );
335
+
336
  $tmpfname = $this->check_get_ajax_uploaded_file();
337
  $attachmentId = (int) $_POST['attachmentId'];
338
  $meta = wp_get_attachment_metadata( $attachmentId );
core.php CHANGED
@@ -1141,8 +1141,32 @@ class Meow_WR2X_Core {
1141
  global $wr2x_version, $wr2x_retinajs, $wr2x_retina_image, $wr2x_picturefill, $wr2x_lazysizes;
1142
  $method = get_option( "wr2x_method" );
1143
 
1144
- if ( is_admin() && !get_option( "wr2x_retina_admin" ) )
1145
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1146
 
1147
  // Picturefill
1148
  if ( $method == "Picturefill" ) {
1141
  global $wr2x_version, $wr2x_retinajs, $wr2x_retina_image, $wr2x_picturefill, $wr2x_lazysizes;
1142
  $method = get_option( "wr2x_method" );
1143
 
1144
+ if ( is_admin() && !get_option( "wr2x_retina_admin" ) ) {
1145
+ wp_enqueue_script( 'wr2x-admin', plugins_url( '/js/admin.js', __FILE__ ), array(), $wr2x_version, false );
1146
+
1147
+ $nonce = array (
1148
+ 'wr2x_generate' => null,
1149
+ 'wr2x_delete' => null,
1150
+ 'wr2x_delete_full' => null,
1151
+ 'wr2x_list_all' => null,
1152
+ 'wr2x_replace' => null,
1153
+ 'wr2x_upload' => null,
1154
+ 'wr2x_retina_details' => null
1155
+ );
1156
+ foreach ( array_keys( $nonce ) as $action )
1157
+ $nonce[$action] = wp_create_nonce( $action );
1158
+
1159
+ wp_localize_script( 'wr2x-admin', 'wr2x_admin_server', array (
1160
+ 'maxFileSize' => $this->get_max_filesize(),
1161
+ 'nonce' => $nonce,
1162
+ 'i18n' => array (
1163
+ 'Refresh' => __( "<a href='?page=wp-retina-2x&view=issues&refresh=true'>Refresh</a> this page.", 'wp-retina-2x' ),
1164
+ 'Wait' => __( "Wait...", 'wp-retina-2x' ),
1165
+ 'Nothing_to_do' => __( "Nothing to do ;)", 'wp-retina-2x' ),
1166
+ 'Generate' => __( "GENERATE", 'wp-retina-2x' )
1167
+ )
1168
+ ) );
1169
+ }
1170
 
1171
  // Picturefill
1172
  if ( $method == "Picturefill" ) {
js/admin.js ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* GENERATE RETINA IMAGES ACTION */
2
+
3
+ var current;
4
+ var maxPhpSize = wr2x_admin_server.maxFileSize;
5
+ var ids = [];
6
+ var errors = 0;
7
+ var ajax_action = "generate"; // generate | delete
8
+
9
+ function wr2x_display_please_refresh() {
10
+ wr2x_refresh_progress_status();
11
+ jQuery('#wr2x_progression').html(jQuery('#wr2x_progression').html() + " - " + wr2x_admin_server.i18n.Refresh);
12
+ }
13
+
14
+ function wr2x_refresh_progress_status() {
15
+ var errortext = "";
16
+ if ( errors > 0 ) {
17
+ errortext = ' - ' + errors + ' error(s)';
18
+ }
19
+ jQuery('#wr2x_progression').text(current + "/" + ids.length +
20
+ " (" + Math.round(current / ids.length * 100) + "%)" + errortext);
21
+ }
22
+
23
+ function wr2x_do_next () {
24
+ var data = { action: 'wr2x_' + ajax_action, attachmentId: ids[current - 1] };
25
+ data.nonce = wr2x_admin_server.nonce[data.action];
26
+
27
+ wr2x_refresh_progress_status();
28
+ jQuery.post(ajaxurl, data, function (response) {
29
+ try {
30
+ reply = jQuery.parseJSON(response);
31
+ }
32
+ catch (e) {
33
+ reply = null;
34
+ }
35
+ if ( !reply || !reply.success )
36
+ errors++;
37
+ else {
38
+ wr2x_refresh_media_sizes(reply.results);
39
+ if (reply.results_full)
40
+ wr2x_refresh_full(reply.results_full);
41
+ }
42
+ if (++current <= ids.length)
43
+ wr2x_do_next();
44
+ else {
45
+ current--;
46
+ wr2x_display_please_refresh();
47
+ }
48
+ }).fail(function () {
49
+ errors++;
50
+ if (++current <= ids.length)
51
+ wr2x_do_next();
52
+ else {
53
+ current--;
54
+ wr2x_display_please_refresh();
55
+ }
56
+ });
57
+ }
58
+
59
+ function wr2x_do_all () {
60
+ current = 1;
61
+ ids = [];
62
+ errors = 0;
63
+ var data = { action: 'wr2x_list_all', issuesOnly: 0 };
64
+ data.nonce = wr2x_admin_server.nonce[data.action];
65
+
66
+ jQuery('#wr2x_progression').text(wr2x_admin_server.i18n.Wait);
67
+ jQuery.post(ajaxurl, data, function (response) {
68
+ reply = jQuery.parseJSON(response);
69
+ if (reply.success = false) {
70
+ alert('Error: ' + reply.message);
71
+ return;
72
+ }
73
+ if (reply.total == 0) {
74
+ jQuery('#wr2x_progression').html(wr2x_admin_server.i18n.Nothing_to_do);
75
+ return;
76
+ }
77
+ ids = reply.ids;
78
+ jQuery('#wr2x_progression').text(current + "/" + ids.length + " (" + Math.round(current / ids.length * 100) + "%)");
79
+ wr2x_do_next();
80
+ });
81
+ }
82
+
83
+ function wr2x_delete_all () {
84
+ ajax_action = 'delete';
85
+ wr2x_do_all();
86
+ }
87
+
88
+ function wr2x_generate_all () {
89
+ ajax_action = 'generate';
90
+ wr2x_do_all();
91
+ }
92
+
93
+ // Refresh the dashboard retina full with the results from the Ajax operation (Upload)
94
+ function wr2x_refresh_full (results) {
95
+ jQuery.each(results, function (id, html) {
96
+ jQuery('#wr2x-info-full-' + id).html(html);
97
+ jQuery('#wr2x-info-full-' + id + ' img').attr('src', jQuery('#wr2x-info-full-' + id + ' img').attr('src')+'?'+ Math.random());
98
+ jQuery('#wr2x-info-full-' + id + ' img').on('click', function (evt) {
99
+ wr2x_delete_full( jQuery(evt.target).parents('.wr2x-file-row').attr('postid') );
100
+ });
101
+ });
102
+ }
103
+
104
+ // Refresh the dashboard media sizes with the results from the Ajax operation (Replace or Generate)
105
+ function wr2x_refresh_media_sizes (results) {
106
+ jQuery.each(results, function (id, html) {
107
+ jQuery('#wr2x-info-' + id).html(html);
108
+ });
109
+ }
110
+
111
+ function wr2x_generate (attachmentId, retinaDashboard) {
112
+ var data = { action: 'wr2x_generate', attachmentId: attachmentId };
113
+ data.nonce = wr2x_admin_server.nonce[data.action];
114
+
115
+ jQuery('#wr2x_generate_button_' + attachmentId).text(wr2x_admin_server.i18n.Wait);
116
+ jQuery.post(ajaxurl, data, function (response) {
117
+ var reply = jQuery.parseJSON(response);
118
+ if (!reply.success) {
119
+ alert(reply.message);
120
+ return;
121
+ }
122
+ jQuery('#wr2x_generate_button_' + attachmentId).html(wr2x_admin_server.i18n.Generate);
123
+ wr2x_refresh_media_sizes(reply.results);
124
+ });
125
+ }
126
+
127
+ /* REPLACE FUNCTION */
128
+
129
+ function wr2x_stop_propagation(evt) {
130
+ evt.stopPropagation();
131
+ evt.preventDefault();
132
+ }
133
+
134
+ function wr2x_delete_full(attachmentId) {
135
+ var data = {
136
+ action: 'wr2x_delete_full',
137
+ isAjax: true,
138
+ attachmentId: attachmentId
139
+ };
140
+ data.nonce = wr2x_admin_server.nonce[data.action];
141
+
142
+ jQuery.post(ajaxurl, data, function (response) {
143
+ var data = jQuery.parseJSON(response);
144
+ if (data.success === false) {
145
+ alert(data.message);
146
+ }
147
+ else {
148
+ wr2x_refresh_full(data.results);
149
+ wr2x_display_please_refresh();
150
+ }
151
+ });
152
+ }
153
+
154
+ function wr2x_load_details(attachmentId) {
155
+ var data = {
156
+ action: 'wr2x_retina_details',
157
+ isAjax: true,
158
+ attachmentId: attachmentId
159
+ };
160
+ data.nonce = wr2x_admin_server.nonce[data.action];
161
+
162
+ jQuery.post(ajaxurl, data, function (response) {
163
+ var data = jQuery.parseJSON(response);
164
+ if (data.success === false) {
165
+ alert(data.message);
166
+ }
167
+ else {
168
+ jQuery('#meow-modal-info .loading').css('display', 'none');
169
+ jQuery('#meow-modal-info .content').html(data.result);
170
+ }
171
+ });
172
+ }
173
+
174
+ function wr2x_filedropped (evt) {
175
+ wr2x_stop_propagation(evt);
176
+ var files = evt.dataTransfer.files;
177
+ var count = files.length;
178
+ if (count < 0) {
179
+ return;
180
+ }
181
+
182
+ var wr2x_replace = jQuery(evt.target).parent().hasClass('wr2x-fullsize-replace');
183
+ var wr2x_upload = jQuery(evt.target).parent().hasClass('wr2x-fullsize-retina-upload');
184
+
185
+ function wr2x_handleprogress(prg) {
186
+ console.debug("Upload of " + prg.srcElement.filename + ": " + prg.loaded / prg.total * 100 + "%");
187
+ }
188
+
189
+ function wr2x_uploadFile(file, attachmentId, filename) {
190
+ var action = "";
191
+ if (wr2x_replace) {
192
+ action = 'wr2x_replace';
193
+ }
194
+ else if (wr2x_upload) {
195
+ action = 'wr2x_upload';
196
+ }
197
+ else {
198
+ alert("Unknown command. Contact the developer.");
199
+ }
200
+ var data = new FormData();
201
+ data.append('file', file);
202
+ data.append('action', action);
203
+ data.append('attachmentId', attachmentId);
204
+ data.append('isAjax', true);
205
+ data.append('filename', filename);
206
+ data.append('nonce', wr2x_admin_server.nonce[action]);
207
+
208
+ // var data = {
209
+ // action: action,
210
+ // isAjax: true,
211
+ // filename: evt.target.filename,
212
+ // data: form_data,
213
+ // attachmentId: attachmentId
214
+ // };
215
+
216
+ jQuery.ajax({
217
+ type: 'POST',
218
+ url: ajaxurl,
219
+ contentType: false,
220
+ processData: false,
221
+ data: data,
222
+ success: function (response) {
223
+ jQuery('[postid=' + attachmentId + '] td').removeClass('wr2x-loading-file');
224
+ jQuery('[postid=' + attachmentId + '] .wr2x-dragdrop').removeClass('wr2x-hover-drop');
225
+ try {
226
+ var data = jQuery.parseJSON(response);
227
+ }
228
+ catch (e) {
229
+ alert("The server-side returned an abnormal response. Check your PHP error logs and also your browser console (WP Retina 2x will try to display it there).");
230
+ console.debug(response);
231
+ return;
232
+ }
233
+ if (wr2x_replace) {
234
+ var imgSelector = '[postid=' + attachmentId + '] .wr2x-info-thumbnail img';
235
+ jQuery(imgSelector).attr('src', jQuery(imgSelector).attr('src')+'?'+ Math.random());
236
+ }
237
+ if (wr2x_upload) {
238
+ var imgSelector = '[postid=' + attachmentId + '] .wr2x-info-full img';
239
+ jQuery(imgSelector).attr('src', jQuery(imgSelector).attr('src')+'?'+ Math.random());
240
+ }
241
+ if (data.success === false) {
242
+ alert(data.message);
243
+ }
244
+ else {
245
+ if ( wr2x_replace ) {
246
+ wr2x_refresh_media_sizes(data.results);
247
+ }
248
+ else if ( wr2x_upload ) {
249
+ wr2x_refresh_full(data.results);
250
+ }
251
+ }
252
+ },
253
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
254
+ jQuery('[postid=' + attachmentId + '] td').removeClass('wr2x-loading-file');
255
+ jQuery('[postid=' + attachmentId + '] .wr2x-dragdrop').removeClass('wr2x-hover-drop');
256
+ alert("An error occurred on the server-side. Please check your PHP error logs.");
257
+ }
258
+ });
259
+ }
260
+ var file = files[0];
261
+ if (file.size > maxPhpSize) {
262
+ jQuery(this).removeClass('wr2x-hover-drop');
263
+ alert( "Your PHP configuration only allows file upload of a maximum of " + (maxPhpSize / 1000000) + "MB." );
264
+ return;
265
+ }
266
+ var postId = jQuery(evt.target).parents('.wr2x-file-row').attr('postid');
267
+ jQuery(evt.target).parents('td').addClass('wr2x-loading-file');
268
+ wr2x_uploadFile(file, postId, file.name);
269
+ }
270
+
271
+ jQuery(document).ready(function () {
272
+ jQuery('.wr2x-dragdrop').on('dragenter', function (evt) {
273
+ wr2x_stop_propagation(evt);
274
+ jQuery(this).addClass('wr2x-hover-drop');
275
+ });
276
+
277
+ jQuery('.wr2x-dragdrop').on('dragover', function (evt) {
278
+ wr2x_stop_propagation(evt);
279
+ jQuery(this).addClass('wr2x-hover-drop');
280
+ });
281
+
282
+ jQuery('.wr2x-dragdrop').on('dragleave', function (evt) {
283
+ wr2x_stop_propagation(evt);
284
+ jQuery(this).removeClass('wr2x-hover-drop');
285
+ });
286
+
287
+ jQuery('.wr2x-dragdrop').on('dragexit', wr2x_stop_propagation);
288
+
289
+ jQuery('.wr2x-dragdrop').each(function (index, elem) {
290
+ this.addEventListener('drop', wr2x_filedropped);
291
+ });
292
+
293
+ jQuery('.wr2x-info, .wr2x-button-view').on('click', function (evt) {
294
+ jQuery('#meow-modal-info-backdrop').css('display', 'block');
295
+ jQuery('#meow-modal-info .content').html("");
296
+ jQuery('#meow-modal-info .loading').css('display', 'block');
297
+ jQuery('#meow-modal-info').css('display', 'block');
298
+ jQuery('#meow-modal-info').focus();
299
+ var postid = jQuery(evt.target).parents('.wr2x-info').attr('postid');
300
+ if (!postid)
301
+ postid = jQuery(evt.target).parents('.wr2x-file-row').attr('postid');
302
+ wr2x_load_details(postid);
303
+ });
304
+
305
+ jQuery('#meow-modal-info .close, #meow-modal-info-backdrop').on('click', function (evt) {
306
+ jQuery('#meow-modal-info').css('display', 'none');
307
+ jQuery('#meow-modal-info-backdrop').css('display', 'none');
308
+ });
309
+
310
+ jQuery('.wr2x-info-full img').on('click', function (evt) {
311
+ wr2x_delete_full( jQuery(evt.target).parents('.wr2x-file-row').attr('postid') );
312
+ });
313
+
314
+ jQuery('#meow-modal-info').bind('keydown', function (evt) {
315
+ if (evt.keyCode === 27) {
316
+ jQuery('#meow-modal-info').css('display', 'none');
317
+ jQuery('#meow-modal-info-backdrop').css('display', 'none');
318
+ }
319
+ });
320
+ });
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: TigrouMeow
3
  Tags: retina, images, image, responsive, lazysizes, lazy, attachment, media, files, iphone, ipad, high-dpi
4
  Requires at least: 3.5
5
  Tested up to: 4.9
6
- Stable tag: 5.2.7
7
 
8
  Make your website look beautiful and crisp on modern displays by creating and displaying retina images. WP 4.4+ is also supported and enhanced.
9
 
@@ -33,7 +33,7 @@ More information and tutorial available one https://meowapps.com/wp-retina-2x/.
33
 
34
  == Changelog ==
35
 
36
- = 5.2.7 =
37
  * Fix: Security update.
38
  * Update: Lazysizes 4.0.3.
39
 
3
  Tags: retina, images, image, responsive, lazysizes, lazy, attachment, media, files, iphone, ipad, high-dpi
4
  Requires at least: 3.5
5
  Tested up to: 4.9
6
+ Stable tag: 5.2.8
7
 
8
  Make your website look beautiful and crisp on modern displays by creating and displaying retina images. WP 4.4+ is also supported and enhanced.
9
 
33
 
34
  == Changelog ==
35
 
36
+ = 5.2.8 =
37
  * Fix: Security update.
38
  * Update: Lazysizes 4.0.3.
39
 
wp-retina-2x.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Retina 2x
4
  Plugin URI: https://meowapps.com
5
  Description: Make your website look beautiful and crisp on modern displays by creating + displaying retina images.
6
- Version: 5.2.7
7
  Author: Jordy Meow
8
  Author URI: https://meowapps.com
9
  Text Domain: wp-retina-2x
@@ -29,7 +29,7 @@ if ( class_exists( 'Meow_WR2X_Core' ) ) {
29
  global $wr2x_picturefill, $wr2x_retinajs, $wr2x_lazysizes,
30
  $wr2x_retina_image, $wr2x_core;
31
 
32
- $wr2x_version = '5.2.7';
33
  $wr2x_retinajs = '2.0.0';
34
  $wr2x_picturefill = '3.0.2';
35
  $wr2x_lazysizes = '4.0.1';
3
  Plugin Name: WP Retina 2x
4
  Plugin URI: https://meowapps.com
5
  Description: Make your website look beautiful and crisp on modern displays by creating + displaying retina images.
6
+ Version: 5.2.8
7
  Author: Jordy Meow
8
  Author URI: https://meowapps.com
9
  Text Domain: wp-retina-2x
29
  global $wr2x_picturefill, $wr2x_retinajs, $wr2x_lazysizes,
30
  $wr2x_retina_image, $wr2x_core;
31
 
32
+ $wr2x_version = '5.2.8';
33
  $wr2x_retinajs = '2.0.0';
34
  $wr2x_picturefill = '3.0.2';
35
  $wr2x_lazysizes = '4.0.1';