Skip to content

Commit 1bbe7b7

Browse files
committed
Change updating function for the image file size
1 parent a388450 commit 1bbe7b7

File tree

6 files changed

+69
-34
lines changed

6 files changed

+69
-34
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ For full functionality "Maximum avatar file size" in "ACP" > "Board configuratio
5858
- Revised JS code
5959
- Fixed JS code in ACP don't work with radio buttons
6060
- Added security measures for Ajax request
61+
- Added updating the image file size in the line after uploading or rotating
6162
- Changed error handling for missing thumbnail file to a warning message
63+
- Changed compression method for png files
6264

6365
### v1.3.2 (13-12-2023)
6466
- Fixed error when upload none image file

imcger/imgupload/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ For full functionality "Maximum avatar file size" in "ACP" > "Board configuratio
5858
- Revised JS code
5959
- Fixed JS code in ACP don't work with radio buttons
6060
- Added security measures for Ajax request
61+
- Added updating the image file size in the line after uploading or rotating
6162
- Changed error handling for missing thumbnail file to a warning message
63+
- Changed compression method for png files
6264

6365
### v1.3.2 (13-12-2023)
6466
- Fixed error when upload none image file

imcger/imgupload/controller/admin_controller.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
namespace imcger\imgupload\controller;
1212

13-
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14-
1513
/**
16-
* ACP Event Listener
14+
* ACP Controller
1715
*/
18-
class admin_controller implements EventSubscriberInterface
16+
class admin_controller
1917
{
2018
/** @var config */
2119
protected $config;

imcger/imgupload/controller/save_rotated_img_controller.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function save_image()
180180
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $img_attach_id;
181181
$this->db->sql_query($sql);
182182

183-
$this->json_response(0, $ext_display_name, $alert_msg ?? '', $img_attach_id, $new_attach_id);
183+
$this->json_response(0, $ext_display_name, $alert_msg ?? '', $img_attach_id, $new_attach_id, $img_data['filesize']);
184184
}
185185
else
186186
{
@@ -218,7 +218,7 @@ private function rotate_image($path, $deg)
218218
*
219219
* @return string $json
220220
*/
221-
private function json_response($status, $title = '', $message = '', $old_attach_id = 0, $new_attach_id = 0)
221+
private function json_response($status, $title = '', $message = '', $old_attach_id = 0, $new_attach_id = 0, $file_size = 0)
222222
{
223223
$json_response = new \phpbb\json_response;
224224
$json_response->send([
@@ -227,6 +227,7 @@ private function json_response($status, $title = '', $message = '', $old_attach_
227227
'message' => $message,
228228
'oldAttachId' => (int) $old_attach_id,
229229
'newAttachId' => (int) $new_attach_id,
230+
'fileSize' => (int) $file_size,
230231
]);
231232
}
232233
}

imcger/imgupload/styles/all/template/event/overall_footer_body_after.html

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@
140140
});
141141
},
142142

143+
/**
144+
* Subroutine for converting the file size into a string
145+
*
146+
* @param int fileSize file size in byte
147+
*
148+
* @return string strFileSize file size as byte, KiB or MiB
149+
*/
150+
sizeToString: function(fileSize) {
151+
let strFileSize = '';
152+
153+
fileSize = parseInt(fileSize);
154+
155+
if (fileSize < 1024) {
156+
strFileSize = fileSize + ' {{ lang("BYTES_SHORT")|e("js") }}';
157+
} else if (fileSize < 1048576) {
158+
strFileSize = Math.round(fileSize / 10.24) / 100 + ' {{ lang("KIB")|e("js") }}';
159+
} else {
160+
strFileSize = Math.round(fileSize / 10485.76) / 100 + ' {{ lang("MIB")|e("js") }}';
161+
}
162+
163+
return(strFileSize);
164+
},
165+
143166
/**
144167
* Rotate the image clockwiese
145168
*
@@ -232,24 +255,38 @@
232255
beforeSend: function(xhr, settings) {
233256
$(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw');
234257
$('.imcger-iupl-button button').prop('disabled', true).css('cursor','not-allowed');
258+
$('.attach-row[data-attach-id="' + attach_id + '"]') .find('.file-status').removeClass('file-uploaded ').addClass('file-working');
259+
235260
},
236261
});
237262

238263
// Code to run if the request succeeds (is done);
239-
ajaxReq.done(function(json) {
240-
if (json.status < 3) {
241-
imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId);
264+
ajaxReq.done(function(response) {
265+
if (typeof response !== 'object') {
266+
return;
267+
}
268+
269+
if (response.status < 3) {
270+
imcger.imgUpload.updateAttId(response.oldAttachId, response.newAttachId);
242271
imcger.imgUpload.image.imgOrientationValue[index] = 0;
243-
imcger.imgUpload.image.setImgSize(json.newAttachId);
272+
273+
// Update row with new image size
274+
if (response.fileSize) {
275+
let strFileSize = imcger.imgUpload.image.sizeToString(response.fileSize);
276+
277+
if (strFileSize) {
278+
$('.attach-row[data-attach-id="' + response.newAttachId + '"] .file-size').html(strFileSize);
279+
}
280+
}
244281

245282
// Display a message when a warning occurs
246-
if (json.message) {
247-
phpbb.alert(json.title, json.message);
283+
if (response.message) {
284+
phpbb.alert(response.title, response.message);
248285
}
249-
} else if (json.status == 3) {
286+
} else if (response.status == 3) {
250287
window.location.assign(window.location.href.replace(window.location.hash, ''));
251288
} else {
252-
phpbb.alert(json.title, json.message);
289+
phpbb.alert(response.title, response.message);
253290
}
254291
});
255292

@@ -263,43 +300,35 @@
263300
ajaxReq.always(function(xhr, status) {
264301
$(button).find('>:first-child').attr('class', 'icon fa-save fa-fw');
265302
$('.imcger-iupl-button button').prop('disabled', false).css('cursor','pointer');
303+
$('.attach-row[data-attach-id="' + xhr.newAttachId + '"]') .find('.file-status').removeClass('file-working').addClass('file-uploaded');
266304
});
267305
},
268306

269307
/**
270-
* Send a request to the Server to get the image filesize
271-
* and update the row with it
308+
* Sends a request to the server to get the file size
309+
* of the image and update the row with it
272310
*
273311
* @param int attach_id attach id from attach image
274312
*/
275313
setImgSize: function(attach_id) {
276-
let imgURL = $('#img-' + attach_id).attr('src').replace('&t=1', ''),
277-
ajaxReq = $.ajax({
314+
const imgURL = $('#img-' + attach_id).attr('src').replace('&t=1', '');
315+
316+
let ajaxReq = $.ajax({
278317
url: imgURL,
279318
data: null,
280-
async: false,
281319
type: 'HEAD',
282320
dataType: "json",
283321
timeout: 5000,
284322
});
285323

286-
ajaxReq.done(function(json) {
287-
let fileSize = ajaxReq.getResponseHeader('Content-Length'),
288-
strFileSize = '';
289-
290-
if (fileSize < 1024) {
291-
strFileSize = fileSize + ' {{ lang("BYTES_SHORT")|e("js") }}';
292-
} else if (fileSize < 1048576) {
293-
strFileSize = Math.round(fileSize / 10.24) / 100 + ' {{ lang("KIB")|e("js") }}';
294-
} else {
295-
strFileSize = Math.round(fileSize / 10485.76) / 100 + ' {{ lang("MIB")|e("js") }}';
296-
}
324+
ajaxReq.done(function(response, status, xhr) {
325+
let strFileSize = imcger.imgUpload.image.sizeToString(xhr.getResponseHeader('Content-Length'));
297326

298327
if (strFileSize) {
299328
$('.attach-row[data-attach-id="' + attach_id + '"] .file-size').html(strFileSize);
300329
}
301330
});
302-
}
331+
},
303332
}
304333

305334
/**
@@ -477,6 +506,7 @@
477506
} else {
478507
// Do nothing wenn click on image
479508
$link.attr('onclick', 'return false;');
509+
$link.css('cursor','default');
480510
}
481511

482512
// Hack for vertically centered image
@@ -553,6 +583,7 @@
553583
} else {
554584
// Do nothing wenn click on image
555585
$link.attr('onclick', 'return false;');
586+
$link.css('cursor','default');
556587
}
557588

558589
// Add thumnail and buttons to rotate it
@@ -573,9 +604,10 @@
573604
}
574605

575606
$(this).css('margin-top', ((maxImgHeight - parseInt(imgHeight)) / 2));
576-
577-
imcger.imgUpload.image.setImgSize(attach.attach_id);
578607
});
608+
609+
// Update row with the image file size
610+
imcger.imgUpload.image.setImgSize(attach.attach_id);
579611
} else {
580612
$link.attr('href', url).html(attach.real_filename);
581613
$row.find('.file-name').html($link);

imgupload_version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stable": {
33
"1.0": {
4-
"current": "1.3.2",
4+
"current": "1.4.0",
55
"announcement": "https://www.phpbb.de/community/viewtopic.php?t=246009",
66
"download": "https://github.com/IMC-GER/phpBB-Image-upload-use-ImageMagick/tags",
77
"eol": null,

0 commit comments

Comments
 (0)