Skip to content

Commit 440e27a

Browse files
authored
Merge pull request #2 from IMC-GER/revise-javascript
Revise javascript
2 parents 4a9d6b2 + 0da23f6 commit 440e27a

31 files changed

+520
-379
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ This extension can change the image size and/or the image file size. It rotate i
2727
- [Post - upload attachments](https://raw.githubusercontent.com/IMC-GER/images/main/screenshots/imgupload/en/imgupload_upload_en.jpg)
2828

2929
## Requirements
30-
- phpBB 3.2.4 or higher
31-
- php 7.1 or higher
30+
- phpBB 3.3.0 or higher
31+
- php 7.2 or higher
3232
- php ImageMagick library installed
3333

3434
## Compatible with
@@ -54,6 +54,16 @@ For full functionality "Maximum avatar file size" in "ACP" > "Board configuratio
5454

5555
## Changelog
5656

57+
### v1.4.0 (14-01-2024)
58+
- Revised JS code
59+
- Fixed JS code in ACP don't work with radio buttons
60+
- Fixed if the attachment thumbnail is too small, it will not be centered
61+
- Added security measures for Ajax request
62+
- Added updating the image file size in the row after uploading or rotating
63+
- Changed error handling for missing thumbnail file to a warning message
64+
- Changed compression method for png files
65+
- Changed phpBB min. version to 3.3.0
66+
5767
### v1.3.2 (13-12-2023)
5868
- Fixed error when upload none image file
5969
- Fixed upload aborts sporadically with large files

imcger/imgupload/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ This extension can change the image size and/or the image file size. It rotate i
2727
- [Post - upload attachments](https://raw.githubusercontent.com/IMC-GER/images/main/screenshots/imgupload/en/imgupload_upload_en.jpg)
2828

2929
## Requirements
30-
- phpBB 3.2.4 or higher
31-
- php 7.1 or higher
30+
- phpBB 3.3.0 or higher
31+
- php 7.2 or higher
3232
- php ImageMagick library installed
3333

3434
## Compatible with
@@ -54,6 +54,16 @@ For full functionality "Maximum avatar file size" in "ACP" > "Board configuratio
5454

5555
## Changelog
5656

57+
### v1.4.0 (14-01-2024)
58+
- Revised JS code
59+
- Fixed JS code in ACP don't work with radio buttons
60+
- Fixed if the attachment thumbnail is too small, it will not be centered
61+
- Added security measures for Ajax request
62+
- Added updating the image file size in the row after uploading or rotating
63+
- Changed error handling for missing thumbnail file to a warning message
64+
- Changed compression method for png files
65+
- Changed phpBB min. version to 3.3.0
66+
5767
### v1.3.2 (13-12-2023)
5868
- Fixed error when upload none image file
5969
- Fixed upload aborts sporadically with large files

imcger/imgupload/acp/main_info.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Image upload use ImageMagick
54
* An extension for the phpBB Forum Software package.
65
*

imcger/imgupload/acp/main_module.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Images upload use ImageMagick
54
* An extension for the phpBB Forum Software package.
65
*
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
/*
2-
Image upload use ImageMagick
3-
------------------------------------- */
1+
/**
2+
* Image upload use ImageMagick
3+
* An extension for the phpBB Forum Software package.
4+
*
5+
* @copyright (c) 2022, Thorsten Ahlers
6+
* @license GNU General Public License, version 2 (GPL-2.0)
7+
*
8+
*/
49

5-
function imcgerImgInlineDisabled() {
6-
if (document.getElementById('img_create_thumbnail').checked) {
7-
document.getElementById('imcger_imgupload_image_inline').disabled = false;
10+
$('input[name=img_create_thumbnail]').on('change', function () {
11+
if ($('input[name=img_create_thumbnail]:checked').last().val() == 1) {
12+
$('input[name=imcger_imgupload_image_inline]').prop('disabled', false);
813
} else {
9-
document.getElementById('imcger_imgupload_image_inline').checked = false;
10-
setTimeout(document.getElementById('imcger_imgupload_image_inline').disabled = true, 1000);
14+
$('input[name=imcger_imgupload_image_inline]').attr('type') == 'radio' ?
15+
$('input[name=imcger_imgupload_image_inline]').last().click() : $('input[name=imcger_imgupload_image_inline]').prop('checked', false);
16+
$('input[name=imcger_imgupload_image_inline]').prop('disabled', true);
1117
}
12-
}
18+
});
1319

14-
document.getElementById('img_create_thumbnail').addEventListener('click', imcgerImgInlineDisabled);
15-
imcgerImgInlineDisabled();
20+
$('input[name=imcger_imgupload_image_inline]').trigger('change');

imcger/imgupload/adm/style/acp_imgupload_body.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ <h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
1010
<fieldset>
1111
<legend>{{ lang('ACP_ATTACHMENT_SETTINGS') }}</legend>
1212
<dl>
13-
<dt><label for="img_create_thumbnail">{{ lang('CREATE_THUMBNAIL') ~ lang('COLON') }}</label><br/><span>{{ lang('CREATE_THUMBNAIL_EXPLAIN') }}</span></dt>
13+
<dt><label for="img_create_thumbnail">{{ lang('CREATE_THUMBNAIL') ~ lang('COLON') }}</label><br><span>{{ lang('CREATE_THUMBNAIL_EXPLAIN') }}</span></dt>
1414
<dd>
1515
{{ _self.switch('img_create_thumbnail', CREATE_THUMBNAIL, switch_type) }}
1616
</dd>
1717
</dl>
1818
<dl>
19-
<dt><label for="imcger_imgupload_tum_quality">{{ lang('ACP_IMCGER_THUMB_QUALITY') ~ lang('COLON') }}</label><br/><span>{{ lang('ACP_IMCGER_THUMB_QUALITY_DESC') }}</span></dt>
19+
<dt><label for="imcger_imgupload_tum_quality">{{ lang('ACP_IMCGER_THUMB_QUALITY') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_THUMB_QUALITY_DESC') }}</span></dt>
2020
<dd>
2121
{{ _self.number('imcger_imgupload_tum_quality', IMCGER_TUM_QUALITY, 50, 90) }}
2222
</dd>
2323
</dl>
2424
<dl>
25-
<dt><label for="imcger_imgupload_image_inline">{{ lang('ACP_IMCGER_IMAGE_INLINE') ~ lang('COLON') }}</label><br/><span>{{ lang('ACP_IMCGER_IMAGE_INLINE_DESC') }}</span></dt>
25+
<dt><label for="imcger_imgupload_image_inline">{{ lang('ACP_IMCGER_IMAGE_INLINE') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_IMAGE_INLINE_DESC') }}</span></dt>
2626
<dd>
2727
{{ _self.switch('imcger_imgupload_image_inline', IMCGER_IMGUPLOAD_IMAGE_INLINE, switch_type) }}
2828
</dd>
2929
</dl>
3030
<dl>
31-
<dt><label for="imcger_imgupload_img_max_thumb_width">{{ lang('ACP_IMCGER_IMG_MAX_THUMB_WIDTH') ~ lang('COLON') }}</label><br/><span>{{ lang('ACP_IMCGER_IMG_MAX_THUMB_WIDTH_DESC') }}</span></dt>
31+
<dt><label for="imcger_imgupload_img_max_thumb_width">{{ lang('ACP_IMCGER_IMG_MAX_THUMB_WIDTH') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_IMG_MAX_THUMB_WIDTH_DESC') }}</span></dt>
3232
<dd>
3333
{{ _self.number('imcger_imgupload_img_max_thumb_width', IMCGER_IMG_MAX_THUMB_WIDTH, 0, 99999) }}
3434
</dd>
@@ -38,23 +38,23 @@ <h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
3838
<fieldset>
3939
<legend>{{ lang('ACP_IMCGER_SETTINGS_IMAGE') }}</legend>
4040
<dl>
41-
<dt><label for="imcger_imgupload_img_quality">{{ lang('ACP_IMCGER_IMAGE_QUALITY') ~ lang('COLON') }}</label><br/><span>{{ lang('ACP_IMCGER_IMAGE_QUALITY_DESC') }}</span></dt>
41+
<dt><label for="imcger_imgupload_img_quality">{{ lang('ACP_IMCGER_IMAGE_QUALITY') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_IMAGE_QUALITY_DESC') }}</span></dt>
4242
<dd>
4343
{{ _self.number('imcger_imgupload_img_quality', IMCGER_IMG_QUALITY, 50, 90) }}
4444
</dd>
4545
</dl>
4646

4747
<dl>
48-
<dt><label for="imcger_imgupload_max_width">{{ lang('ACP_IMCGER_MAX_SIZE') ~ lang('COLON') }}</label><br/><span>{{ lang('ACP_IMCGER_MAX_SIZE_DESC') }}</span></dt>
48+
<dt><label for="imcger_imgupload_max_width">{{ lang('ACP_IMCGER_MAX_SIZE') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_MAX_SIZE_DESC') }}</span></dt>
4949
<dd>
5050
{{ _self.number('imcger_imgupload_max_width', IMCGER_MAX_WIDTH, 0, 99999) }} x {{ _self.number('imcger_imgupload_max_height', IMCGER_MAX_HEIGHT, 0, 99999) }}
5151
</dd>
5252
</dl>
5353

5454
<dl>
55-
<dt><label for="imcger_imgupload_max_filesize">{{ lang('ACP_IMCGER_MAX_FILESIZE') ~ lang('COLON') }}</label><br/><span>{{ lang('ACP_IMCGER_MAX_FILESIZE_DESC') }}</span></dt>
55+
<dt><label for="imcger_imgupload_max_filesize">{{ lang('ACP_IMCGER_MAX_FILESIZE') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_MAX_FILESIZE_DESC') }}</span></dt>
5656
<dd>
57-
{{ _self.number('imcger_imgupload_max_filesize', IMCGER_MAX_FILESIZE, 0, 9999999999) }} <select name="size_select"><option value="b" {% if IMCGER_UNIT == 'b' %} selected="selected"{% endif %}>Bytes</option><option value="kb" {% if IMCGER_UNIT == 'kb' %} selected="selected"{% endif %}>KiB</option><option value="mb" {% if IMCGER_UNIT == 'mb' %} selected="selected"{% endif %}>MiB</option></select>
57+
{{ _self.number('imcger_imgupload_max_filesize', IMCGER_MAX_FILESIZE, 0, 9999999999) }} <select name="size_select"><option value="b" {% if IMCGER_UNIT == 'b' %} selected{% endif %}>Bytes</option><option value="kb" {% if IMCGER_UNIT == 'kb' %} selected{% endif %}>KiB</option><option value="mb" {% if IMCGER_UNIT == 'mb' %} selected{% endif %}>MiB</option></select>
5858
</dd>
5959
</dl>
6060

imcger/imgupload/composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"type": "phpbb-extension",
44
"description": "Using ImageMagick php librarie for resize image attachments and creating thumbnails.",
55
"homepage": "https://github.com/IMC-GER/phpBB-Image-upload-use-ImageMagick/tags",
6-
"version": "1.3.2",
7-
"time": "2023-12-13",
6+
"version": "1.4.0",
7+
"time": "2024-01-14",
88
"license": "GPL-2.0-only",
99
"authors": [
1010
{
@@ -20,14 +20,14 @@
2020
],
2121
"require": {
2222
"php": ">=7.1.0",
23-
"phpbb/phpbb": "^3.2.4",
23+
"phpbb/phpbb": "^3.3.0",
2424
"composer/installers": "~1.0",
2525
"ext-imagick": "*"
2626
},
2727
"extra": {
2828
"display-name": "Image upload use ImageMagick",
2929
"soft-require": {
30-
"phpbb/phpbb": "^3.2.4"
30+
"phpbb/phpbb": "^3.3.0"
3131
},
3232
"version-check": {
3333
"host": "raw.githubusercontent.com",

imcger/imgupload/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
- '@auth'
1919
- '@language'
2020
- '@ext.manager'
21+
- '@filesystem'
2122
- '%core.root_path%'
2223
- '%core.php_ext%'
2324

imcger/imgupload/controller/admin_controller.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Image upload use ImageMagick
54
* An extension for the phpBB Forum Software package.
65
*
@@ -11,6 +10,9 @@
1110

1211
namespace imcger\imgupload\controller;
1312

13+
/**
14+
* ACP Controller
15+
*/
1416
class admin_controller
1517
{
1618
/** @var config */

imcger/imgupload/controller/save_rotated_img_controller.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
*
66
* @copyright (c) 2022, Thorsten Ahlers
77
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
89
*/
910

1011
namespace imcger\imgupload\controller;
1112

1213
/**
13-
* @ignore
14-
*/
15-
16-
/**
17-
* Main controller
14+
* Ajax main controller
1815
*/
1916
class save_rotated_img_controller
2017
{
@@ -39,20 +36,26 @@ class save_rotated_img_controller
3936
/** @var \phpbb\extension\manager */
4037
protected $ext_manager;
4138

39+
/** @var \phpbb\filesystem\filesystem */
40+
protected $filesystem;
41+
4242
/** @var string phpBB root path */
4343
protected $root_path;
4444

4545
/** @var string phpEx */
4646
protected $php_ext;
4747

4848
/**
49+
* Constructor for ajax controller
50+
*
4951
* @param \phpbb\config\config $config
5052
* @param \phpbb\user $user
5153
* @param \phpbb\request\request $request
5254
* @param \phpbb\db\driver\driver_interface $db
5355
* @param \phpbb\auth\auth $auth
5456
* @param \phpbb\language\language $language
5557
* @param \phpbb\extension\manager $ext_manager
58+
* @param \phpbb\filesystem\filesystem $filesystem
5659
* @param string $root_path
5760
* @param string $php_ext
5861
*/
@@ -64,6 +67,7 @@ public function __construct(
6467
\phpbb\auth\auth $auth,
6568
\phpbb\language\language $language,
6669
\phpbb\extension\manager $ext_manager,
70+
\phpbb\filesystem\filesystem $filesystem,
6771
$root_path,
6872
$php_ext
6973
)
@@ -75,6 +79,7 @@ public function __construct(
7579
$this->auth = $auth;
7680
$this->language = $language;
7781
$this->ext_manager = $ext_manager;
82+
$this->filesystem = $filesystem;
7883
$this->root_path = $root_path;
7984
$this->php_ext = $php_ext;
8085

@@ -85,9 +90,12 @@ public function __construct(
8590
/**
8691
* Rotate Image with ImageMagick
8792
*
88-
* @var string $data String contain attach id and rotate degree
93+
* @var int attach_id contain attach id
94+
* @var int img_rotate_deg contain rotate degree
95+
* @var int creation_time creation time of token
96+
* @var string form_token form token
8997
*
90-
* @return array Json arry with old and new attach id or error message
98+
* @return array Json arry with status, old and new attach id, new file size or error message
9199
*/
92100
public function save_image()
93101
{
@@ -103,14 +111,21 @@ public function save_image()
103111
$this->json_response(3);
104112
}
105113

106-
$img_attach_id = $this->request->variable('attach_id', '');
107-
$img_rotate_deg = $this->request->variable('img_rotate_deg', '');
108-
109114
// Get name of the extension
110115
$metadata_manager = $this->ext_manager->create_extension_metadata_manager('imcger/imgupload');
111116
$ext_display_name = $metadata_manager->get_metadata('display-name');
112117

113-
if (!$img_attach_id || !$img_rotate_deg)
118+
// Check form token
119+
if (!check_form_key('posting'))
120+
{
121+
$this->json_response(5, $ext_display_name, $this->language->lang('FORM_INVALID'));
122+
}
123+
124+
// Get variable, accept only integer
125+
$img_attach_id = intval($this->request->variable('attach_id', ''));
126+
$img_rotate_deg = intval($this->request->variable('img_rotate_deg', ''));
127+
128+
if (!$img_attach_id || $img_rotate_deg < 1 || $img_rotate_deg > 360)
114129
{
115130
$this->json_response(5, $ext_display_name, $this->language->lang('IUL_WRONG_PARAM'));
116131
}
@@ -135,7 +150,7 @@ public function save_image()
135150
$image_file_path = $this->root_path . trim($this->config['upload_path'], '/') . '/' . $img_data['physical_filename'];
136151
$thumb_file_path = $this->root_path . trim($this->config['upload_path'], '/') . '/' . 'thumb_' . $img_data['physical_filename'];
137152

138-
if (file_exists($image_file_path))
153+
if ($this->filesystem->exists($image_file_path))
139154
{
140155
$img_data['filesize'] = $this->rotate_image($image_file_path, $img_rotate_deg);
141156
}
@@ -144,13 +159,14 @@ public function save_image()
144159
$this->json_response(4, $ext_display_name, $this->language->lang('IUL_IMG_NOT_EXIST'));
145160
}
146161

147-
if ($img_data['thumbnail'] && file_exists($thumb_file_path))
162+
if ($img_data['thumbnail'] && $this->filesystem->exists($thumb_file_path))
148163
{
149164
$this->rotate_image($thumb_file_path, $img_rotate_deg);
150165
}
151166
else if ($img_data['thumbnail'])
152167
{
153-
$this->json_response(4, $ext_display_name, $this->language->lang('IUL_THUMB_NOT_EXIST'));
168+
$img_data['thumbnail'] = 0;
169+
$alert_msg = $this->language->lang('IUL_THUMB_NOT_EXIST');
154170
}
155171

156172
// Update DataBase
@@ -166,7 +182,7 @@ public function save_image()
166182
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $img_attach_id;
167183
$this->db->sql_query($sql);
168184

169-
$this->json_response(0, $ext_display_name, '', $img_attach_id, $new_attach_id);
185+
$this->json_response(0, $ext_display_name, $alert_msg ?? '', $img_attach_id, $new_attach_id, $img_data['filesize']);
170186
}
171187
else
172188
{
@@ -201,10 +217,11 @@ private function rotate_image($path, $deg)
201217
* @param string $message Messagebox message
202218
* @param int $old_attach_id Previous attachment id
203219
* @param int $new_attach_id New attachment id
220+
* @param int $file_size New file size
204221
*
205222
* @return string $json
206223
*/
207-
private function json_response($status, $title = '', $message = '', $old_attach_id = 0, $new_attach_id = 0)
224+
private function json_response($status, $title = '', $message = '', $old_attach_id = 0, $new_attach_id = 0, $file_size = 0)
208225
{
209226
$json_response = new \phpbb\json_response;
210227
$json_response->send([
@@ -213,6 +230,7 @@ private function json_response($status, $title = '', $message = '', $old_attach_
213230
'message' => $message,
214231
'oldAttachId' => (int) $old_attach_id,
215232
'newAttachId' => (int) $new_attach_id,
233+
'fileSize' => (int) $file_size,
216234
]);
217235
}
218236
}

0 commit comments

Comments
 (0)