Skip to content

Commit d41ef77

Browse files
committed
v1.3.2-b1
- Fixed error when upload image after upload none image file - Fixed don't change attachment id in IMG bbCode after image rotated - Changed Symfony json response tp phpBB response - Added support for Toggle Control from LukeWCS
1 parent 9a29dd5 commit d41ef77

File tree

5 files changed

+83
-51
lines changed

5 files changed

+83
-51
lines changed

imcger/imgupload/adm/style/acp_imgupload_body.html

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% INCLUDE 'overall_header.html' %}
2+
{% set switch_type = TOGGLECTRL_TYPE ?? 'toggle' %}
23

34
<h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
45

@@ -11,25 +12,25 @@ <h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
1112
<dl>
1213
<dt><label for="img_create_thumbnail">{{ lang('CREATE_THUMBNAIL') ~ lang('COLON') }}</label><br/><span>{{ lang('CREATE_THUMBNAIL_EXPLAIN') }}</span></dt>
1314
<dd>
14-
{{ _self.switch('img_create_thumbnail', CREATE_THUMBNAIL) }}
15+
{{ _self.switch('img_create_thumbnail', CREATE_THUMBNAIL, switch_type) }}
1516
</dd>
1617
</dl>
1718
<dl>
1819
<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>
1920
<dd>
20-
<input type="number" id="imcger_imgupload_tum_quality" min="50" max="90" step="any" maxlength="3" name="imcger_imgupload_tum_quality" value="{{ IMCGER_TUM_QUALITY }}">
21+
{{ _self.number('imcger_imgupload_tum_quality', IMCGER_TUM_QUALITY, 50, 90) }}
2122
</dd>
2223
</dl>
2324
<dl>
2425
<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>
2526
<dd>
26-
{{ _self.switch('imcger_imgupload_image_inline', IMCGER_IMGUPLOAD_IMAGE_INLINE) }}
27+
{{ _self.switch('imcger_imgupload_image_inline', IMCGER_IMGUPLOAD_IMAGE_INLINE, switch_type) }}
2728
</dd>
2829
</dl>
2930
<dl>
3031
<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>
3132
<dd>
32-
<input type="number" id="imcger_imgupload_img_max_thumb_width" min="0" max="99999" step="any" maxlength="3" name="imcger_imgupload_img_max_thumb_width" value="{{ IMCGER_IMG_MAX_THUMB_WIDTH }}"> px
33+
{{ _self.number('imcger_imgupload_img_max_thumb_width', IMCGER_IMG_MAX_THUMB_WIDTH, 0, 99999) }}
3334
</dd>
3435
</dl>
3536
</fieldset>
@@ -38,23 +39,29 @@ <h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
3839
<legend>{{ lang('ACP_IMCGER_SETTINGS_IMAGE') }}</legend>
3940
<dl>
4041
<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-
<dd><input type="number" id="imcger_imgupload_img_quality" min="50" max="90" step="any" maxlength="3" name="imcger_imgupload_img_quality" value="{{ IMCGER_IMG_QUALITY }}"></dd>
42+
<dd>
43+
{{ _self.number('imcger_imgupload_img_quality', IMCGER_IMG_QUALITY, 50, 90) }}
44+
</dd>
4245
</dl>
4346

4447
<dl>
4548
<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>
46-
<dd><input type="number" id="imcger_imgupload_max_width" min="0" max="9999999999" step="any" maxlength="10" name="imcger_imgupload_max_width" value="{{ IMCGER_MAX_WIDTH }}"> x <input type="number" id="imcger_imgupload_max_height" min="0" max="9999999999" step="any" maxlength="10" name="imcger_imgupload_max_height" value="{{ IMCGER_MAX_HEIGHT }}"> px</dd>
49+
<dd>
50+
{{ _self.number('imcger_imgupload_max_width', IMCGER_MAX_WIDTH, 0, 99999) }} x {{ _self.number('imcger_imgupload_max_height', IMCGER_MAX_HEIGHT, 0, 99999) }}
51+
</dd>
4752
</dl>
4853

4954
<dl>
5055
<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>
51-
<dd><input type="number" id="imcger_imgupload_max_filesize" min="0" max="9999999999" step="any" name="imcger_imgupload_max_filesize" value="{{ IMCGER_MAX_FILESIZE }}"/> <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></dd>
56+
<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>
58+
</dd>
5259
</dl>
5360

5461
<dl>
5562
<dt><label for="imcger_imgupload_del_exif">{{ lang('ACP_IMCGER_DEL_EXIF') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_DEL_EXIF_DESC') }}</span></dt>
5663
<dd>
57-
{{ _self.switch('imcger_imgupload_del_exif', IMCGER_DEL_EXIF) }}
64+
{{ _self.switch('imcger_imgupload_del_exif', IMCGER_DEL_EXIF, switch_type) }}
5865
</dd>
5966
</dl>
6067
</fieldset>
@@ -65,7 +72,7 @@ <h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
6572
<dt><label for="imcger_imgupload_avatar_resize">{{ lang('ACP_IMCGER_AVATAR_RESIZE') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_IMCGER_AVATAR_RESIZE_DESC') }}</span>
6673
{% if IMCGER_AVATAR_FILESIZE_ISSET %}<br><span style="color: red">{{ lang('ACP_IMCGER_AVATAR_FILESIZE_ISSET') }}</span>{% endif %}</dt>
6774
<dd>
68-
{{ _self.switch('imcger_imgupload_avatar_resize', IMCGER_AVATAR_RESIZE) }}
75+
{{ _self.switch('imcger_imgupload_avatar_resize', IMCGER_AVATAR_RESIZE, switch_type) }}
6976
</dd>
7077
</dl>
7178
</fieldset>
@@ -92,6 +99,32 @@ <h1>{{ lang('ACP_IMCGER_IMGUPLOAD_TITLE') }}</h1>
9299
{% INCLUDECSS '@imcger_imgupload/acp_imgupload.css' %}
93100
{% INCLUDEJS '@imcger_imgupload/acp_imgupload.js' %}
94101

95-
{% macro switch(name, checked = false) -%}
96-
<input type="checkbox" class="toggle" id="{{ name }}" name="{{ name }}" value="1"{{ checked ? ' checked' }}>
102+
{#
103+
Twig Macros
104+
@copyright (c) 2023 LukeWCS, https://github.com/LukeWCS
105+
#}
106+
107+
{% macro switch(name, checked = false, type = 'toggle') -%}
108+
{% if type == 'toggle' || type == 'checkbox' -%}
109+
<input type="checkbox"{{ type == 'toggle' ? ' class="toggle"' }} name="{{ name }}" value="1"{{ checked ? ' checked' }}>
110+
{%- elseif type == 'radio' -%}
111+
<label><input type="radio" class="radio" name="{{ name }}" value="1"{{ checked ? ' checked' }}> {{ lang('YES') }}</label>
112+
<label><input type="radio" class="radio" name="{{ name }}" value="0"{{ !checked ? ' checked' }}> {{ lang('NO') }}</label>
113+
{%- endif %}
114+
{%- endmacro %}
115+
116+
{% macro select(name, value, options) -%}
117+
<select name="{{ name }}">
118+
{% for opt_lang_var, opt_value in options %}
119+
<option value="{{ opt_value }}"{{ opt_value == value ? ' selected' }}>{{ lang(opt_lang_var) }}</option>
120+
{% endfor %}
121+
</select>
122+
{%- endmacro %}
123+
124+
{% macro number(name, value, min, max, step = 1, placeholder = '') -%}
125+
<input type="number" name="{{ name }}" value="{{ value }}" min="{{ min }}" max="{{ max }}" step="{{ step }}"{{ placeholder ? ' placeholder="' ~ placeholder ~ '"' }}>
126+
{%- endmacro %}
127+
128+
{% macro text(name, value, size = 10, placeholder = '', pattern = '') -%}
129+
<input type="text" name="{{ name }}" value="{{ value }}" size="{{ size }}"{{ placeholder ? ' placeholder="' ~ placeholder ~ '"' }}{{ pattern ? ' pattern="' ~ pattern ~ '"' }}>
97130
{%- endmacro %}

imcger/imgupload/composer.json

Lines changed: 2 additions & 2 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.1",
7-
"time": "2023-10-15",
6+
"version": "1.3.2-b1",
7+
"time": "2023-12-10",
88
"license": "GPL-2.0-only",
99
"authors": [
1010
{

imcger/imgupload/controller/admin_controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ protected function set_variable()
128128
$this->config->set('img_create_thumbnail', $this->request->variable('img_create_thumbnail', 0));
129129
$this->config->set('imcger_imgupload_image_inline', $this->request->variable('imcger_imgupload_image_inline', 0));
130130
$this->config->set('imcger_imgupload_img_max_thumb_width', $this->request->variable('imcger_imgupload_img_max_thumb_width', 0));
131+
$this->config->set('imcger_imgupload_avatar_resize', $this->request->variable('imcger_imgupload_avatar_resize', 0));
131132
}
132133

133134
/**

imcger/imgupload/controller/save_rotated_img_controller.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/**
1313
* @ignore
1414
*/
15-
use Symfony\Component\HttpFoundation\JsonResponse;
1615

1716
/**
1817
* Main controller
@@ -101,7 +100,7 @@ public function save_image()
101100
// No user logged in, redirect in js to login page
102101
if ($this->user->data['user_id'] == ANONYMOUS)
103102
{
104-
return $this->json_response(3);
103+
$this->json_response(3);
105104
}
106105

107106
$img_attach_id = $this->request->variable('attach_id', '');
@@ -113,7 +112,7 @@ public function save_image()
113112

114113
if (!$img_attach_id || !$img_rotate_deg)
115114
{
116-
return $this->json_response(5, $ext_display_name, $this->language->lang('IUL_WRONG_PARAM'));
115+
$this->json_response(5, $ext_display_name, $this->language->lang('IUL_WRONG_PARAM'));
117116
}
118117

119118
if ($this->auth->acl_gets('u_attach', 'a_attach', 'f_attach'))
@@ -129,7 +128,7 @@ public function save_image()
129128

130129
if (!isset($img_data) || $img_data == false)
131130
{
132-
return $this->json_response(4, $ext_display_name, $this->language->lang('IUL_NO_IMG_IN_DATABASE'));
131+
$this->json_response(4, $ext_display_name, $this->language->lang('IUL_NO_IMG_IN_DATABASE'));
133132
}
134133

135134
// Get image file path
@@ -142,7 +141,7 @@ public function save_image()
142141
}
143142
else
144143
{
145-
return $this->json_response(4, $ext_display_name, $this->language->lang('IUL_IMG_NOT_EXIST'));
144+
$this->json_response(4, $ext_display_name, $this->language->lang('IUL_IMG_NOT_EXIST'));
146145
}
147146

148147
if ($img_data['thumbnail'] && file_exists($thumb_file_path))
@@ -151,7 +150,7 @@ public function save_image()
151150
}
152151
else if ($img_data['thumbnail'])
153152
{
154-
return $this->json_response(4, $ext_display_name, $this->language->lang('IUL_THUMB_NOT_EXIST'));
153+
$this->json_response(4, $ext_display_name, $this->language->lang('IUL_THUMB_NOT_EXIST'));
155154
}
156155

157156
// Update DataBase
@@ -167,11 +166,11 @@ public function save_image()
167166
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $img_attach_id;
168167
$this->db->sql_query($sql);
169168

170-
return $this->json_response(0, $ext_display_name, '', $img_attach_id, $new_attach_id);
169+
$this->json_response(0, $ext_display_name, '', $img_attach_id, $new_attach_id);
171170
}
172171
else
173172
{
174-
return $this->json_response(5, $ext_display_name, $this->language->lang('IUL_DATABASE_NOT_UPDATE'));
173+
$this->json_response(5, $ext_display_name, $this->language->lang('IUL_DATABASE_NOT_UPDATE'));
175174
}
176175
}
177176

@@ -207,14 +206,13 @@ private function rotate_image($path, $deg)
207206
*/
208207
private function json_response($status, $title = '', $message = '', $old_attach_id = 0, $new_attach_id = 0)
209208
{
210-
$json = new JsonResponse([
209+
$json_response = new \phpbb\json_response;
210+
$json_response->send([
211211
'status' => (int) $status,
212212
'title' => $title,
213213
'message' => $message,
214214
'oldAttachId' => (int) $old_attach_id,
215215
'newAttachId' => (int) $new_attach_id,
216216
]);
217-
218-
return $json;
219217
}
220218
}

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script>
44
/**
55
* Update row with new attachment id
6+
* when save image after rotate
67
*
78
* @param string returnStr old and new attach id
89
*/
@@ -74,6 +75,11 @@
7475
// Replace [attachment=imc-ger] with [attachment=0]
7576
messageText = document.getElementById('message').value;
7677
messageText = messageText.replace(/\[attachment=imc-ger\]/gm, '[attachment=0]');
78+
79+
// Replace [img]oldURL[/img] with [img]newURL[/img]
80+
regex = new RegExp('view&id=' + oldAttachId + '\\[\\/img\\]', 'gm');
81+
messageText = messageText.replace(regex, 'view&id=' + newAttachId + '[/img]');
82+
7783
document.getElementById('message').value = messageText;
7884

7985
phpbb.plupload.updateRows();
@@ -153,7 +159,7 @@
153159

154160
rotate: function(attach_id, deg, clockwise) {
155161
let image = document.getElementById('img-' + attach_id),
156-
deg_start, deg_ziel;
162+
deg_start, deg_ziel;
157163

158164
if (clockwise) {
159165
deg_ziel = deg == 0 ? 360 : deg;
@@ -283,16 +289,10 @@
283289
* Delete a attached file.
284290
*/
285291
$('#file-list').on('click', '.file-delete', function(e) {
286-
var row = $(this).parents('.attach-row'),
292+
var row = $(this).parents('.attach-row'),
287293
attachId = row.attr('data-attach-id');
288294

289-
// Hack to avoid the error 503
290-
setTimeout(() => {
291-
phpbb.plupload.deleteFile(row, attachId);
292295
phpbb.plupload.imcgerDelImgBbcode(attachId);
293-
}, 1000);
294-
295-
e.preventDefault();
296296
});
297297

298298
/**
@@ -410,7 +410,6 @@
410410
'<button class="button" type="button" onclick="imcgerIupl.rotateLeft(' + attach.attach_id + ')" ><i id="fa-undo" class="icon fa-undo fa-fw" aria-hidden="true"></i></button><br>' +
411411
'<button class="button" type="button" onclick="imcgerIuplSaveImg(' + attach.attach_id + ', this)" ><i id="fa-save" class="icon fa-save fa-fw" aria-hidden="true"></i></button></span>';
412412

413-
414413
// Add the link to the file
415414
if (typeof downloadUrl !== 'undefined' && typeof downloadUrl[index] !== 'undefined') {
416415
let url = downloadUrl[index].replace('&amp;', '&'),
@@ -453,29 +452,30 @@
453452
// Do nothing wenn click on image
454453
link.attr('onclick', 'return false;');
455454
}
456-
} else {
457-
link.attr('href', url).html(attach.real_filename);
458-
}
459455

460-
// Add thumnail and buttons to rotate it
461-
row.find('.file-name').html(link);
462-
row.find('.file-name a').after(imcgerButtonsForRotate);
456+
// Add thumnail and buttons to rotate it
457+
row.find('.file-name').html(link);
458+
row.find('.file-name a').after(imcgerButtonsForRotate);
463459

464-
// Set max height to Image
465-
maxImgHeight = parseInt($('.file-name img').css('max-height').replace(/px/, ''));
466-
link.height(maxImgHeight + 'px');
460+
// Set max height to Image
461+
maxImgHeight = parseInt($('.file-name img').css('max-height').replace(/px/, ''));
462+
link.height(maxImgHeight + 'px');
467463

468-
// Hack for vertically centered image
469-
$('#img-' + attach.attach_id).on('load', function(e) {
470-
let imgHeight = maxImgHeight;
464+
// Hack for vertically centered image
465+
$('#img-' + attach.attach_id).on('load', function(e) {
466+
let imgHeight = maxImgHeight;
471467

472-
// The $(this) element work not all time
473-
if (e.target.height < e.target.width) {
474-
imgHeight = maxImgHeight / e.target.width * e.target.height;
475-
}
468+
// The $(this) element work not all time
469+
if (e.target.height < e.target.width) {
470+
imgHeight = maxImgHeight / e.target.width * e.target.height;
471+
}
476472

477-
$(this).css('margin-top', ((maxImgHeight - parseInt(imgHeight)) / 2));
478-
});
473+
$(this).css('margin-top', ((maxImgHeight - parseInt(imgHeight)) / 2));
474+
});
475+
} else {
476+
link.attr('href', url).html(attach.real_filename);
477+
row.find('.file-name').html(link);
478+
}
479479
}
480480

481481
row.find('textarea').attr('name', 'comment_list[' + index + ']');

0 commit comments

Comments
 (0)