Skip to content

Commit abad32f

Browse files
committed
v1.2.0-beta
- Added don't show inline image in attatment box - Added don't show inline image editors preview attatment box - Fixed typo in language var
1 parent d637e96 commit abad32f

File tree

10 files changed

+139
-12
lines changed

10 files changed

+139
-12
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ This extension can change the image size and/or the image file size. It rotate i
1010
- No settings.
1111

1212
#### Settings in Administration Control Panel
13+
- Create thumbnail
1314
- Thumbnail compression quality.
14-
- Image compression quality.
15-
- Maximum image width.
15+
- Insert full size image in post
16+
- Maximum image width (Displayed in post)
17+
- Image compression quality.
18+
- Maximum image width. (Store on Server)
1619
- Maximum image heigth.
1720
- Maximum image file size.
1821
- Remove EXIF data
@@ -51,7 +54,7 @@ For full functionality "Maximum avatar file size" in "ACP" > "Board configuratio
5154

5255
## Changelog
5356

54-
### v1.2.0-alpha (09-04-2023)
57+
### v1.2.0-beta (10-04-2023)
5558
- Changed sql query for allowed image extensions
5659
- Changed compression method for png images
5760
- Added possibility to insert the attachment as an fullsize image in the post message

imcger/imgupload/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ This extension can change the image size and/or the image file size. It rotate i
1010
- No settings.
1111

1212
#### Settings in Administration Control Panel
13+
- Create thumbnail
1314
- Thumbnail compression quality.
14-
- Image compression quality.
15-
- Maximum image width.
15+
- Insert full size image in post
16+
- Maximum image width (Displayed in post)
17+
- Image compression quality.
18+
- Maximum image width. (Store on Server)
1619
- Maximum image heigth.
1720
- Maximum image file size.
1821
- Remove EXIF data
@@ -51,7 +54,7 @@ For full functionality "Maximum avatar file size" in "ACP" > "Board configuratio
5154

5255
## Changelog
5356

54-
### v1.2.0-alpha (09-04-2023)
57+
### v1.2.0-beta (10-04-2023)
5558
- Changed sql query for allowed image extensions
5659
- Changed compression method for png images
5760
- Added possibility to insert the attachment as an fullsize image in the post message

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.2.0-alpha",
7-
"time": "2023-04-09",
6+
"version": "1.2.0-beta",
7+
"time": "2023-04-10",
88
"license": "GPL-2.0-only",
99
"authors": [{
1010
"name": "Thorsten Ahlers",

imcger/imgupload/event/main_listener.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public static function getSubscribedEvents()
7272
'core.thumbnail_create_before' => 'imcger_create_tumbnail',
7373
'core.modify_uploaded_file' => 'imcger_modify_uploaded_file',
7474
'core.avatar_driver_upload_move_file_before' => 'imcger_modify_uploaded_avatar',
75+
'core.viewtopic_modify_post_row' => 'imcger_viewtopic_modify_post_row',
76+
'core.posting_modify_template_vars' => 'imcger_posting_modify_template_vars',
7577
];
7678
}
7779

@@ -351,6 +353,87 @@ function imcger_modify_uploaded_avatar($event)
351353
}
352354
}
353355

356+
/**
357+
* Modify post data
358+
* Don't display attachments when shown as image in post message
359+
*
360+
* @param \phpbb\event\data $event Event object
361+
*/
362+
function imcger_viewtopic_modify_post_row($event)
363+
{
364+
$row = $event['row'];
365+
$post_attachments = $event['attachments'];
366+
367+
// Do nothing when no attachment
368+
if (!count($post_attachments))
369+
{
370+
return;
371+
}
372+
373+
// Post message text
374+
preg_match_all('#\[img\][\w\<\>\/\.?=&;]*[^\[](id=\d+)\<e\>\[\/img\]#', $row['post_text'], $matches);
375+
376+
foreach ($matches[1] as $image)
377+
{
378+
foreach ($post_attachments[$row['post_id']] as $key => $attachment)
379+
{
380+
if (strpos($attachment, $image))
381+
{
382+
unset($post_attachments[$row['post_id']][$key]);
383+
}
384+
}
385+
}
386+
387+
if (count($post_attachments[$row['post_id']]))
388+
{
389+
$event['attachments'] = $post_attachments;
390+
}
391+
else
392+
{
393+
$post_row = $event['post_row'];
394+
$post_row['S_HAS_ATTACHMENTS'] = false;
395+
$post_row['S_MULTIPLE_ATTACHMENTS'] = false;
396+
$event['post_row'] = $post_row;
397+
398+
$event['attachments'] = $post_attachments;
399+
}
400+
}
401+
402+
/**
403+
* Modify post data for post editor preview
404+
* Don't display attachments when shown as image in post message
405+
*
406+
* @param \phpbb\event\data $event Event object
407+
*/
408+
function imcger_posting_modify_template_vars($event)
409+
{
410+
// Get message text and attachment data
411+
$message_parser = $event['message_parser'];
412+
$message = $message_parser->message;
413+
$attachment_data = $message_parser->attachment_data;
414+
415+
// Create array with attachment id that insert in post message
416+
preg_match_all('#\[img\][\w\<\>\/\.?=&;]*[^\[]id=(\d+)\[\/img\]#', $message, $matches);
417+
$matches[1] = array_unique($matches[1]);
418+
419+
// Check if all attachments insert in post message
420+
$display_attachmentbox = false;
421+
foreach ($attachment_data as $attachment)
422+
{
423+
if (!in_array($attachment['attach_id'], $matches[1]))
424+
{
425+
$display_attachmentbox = true;
426+
break;
427+
}
428+
}
429+
430+
// Set variable for JS to hide attachment in post editors preview
431+
$this->template->assign_vars([
432+
'IUL_NOT_DISPLAYED_ATTACHMENTS' => json_encode($matches[1]),
433+
'IUL_NOT_DISPLAY_ATTACHMENTBOX' => (int) !$display_attachmentbox,
434+
]);
435+
}
436+
354437
/**
355438
* resize image if image to large
356439
*

imcger/imgupload/language/de/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// Language pack author
4141
'ACP_IMCGER_LANG_DESC' => 'Deutsch (Du)',
42-
'ACP_IMCGER_LANG_EXT_VER' => '1.2.0-alpha',
42+
'ACP_IMCGER_LANG_EXT_VER' => '1.2.0-beta',
4343
'ACP_IMCGER_LANG_AUTHOR' => 'IMC-Ger',
4444

4545
// Messages

imcger/imgupload/language/de_x_sie/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// language pack author
4141
'ACP_IMCGER_LANG_DESC' => 'Deutsch (Sie)',
42-
'ACP_IMCGER_LANG_EXT_VER' => '1.2.0-alpha',
42+
'ACP_IMCGER_LANG_EXT_VER' => '1.2.0-beta',
4343
'ACP_IMCGER_LANG_AUTHOR' => 'IMC-Ger',
4444

4545
// Messages

imcger/imgupload/language/en/attachment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@
3838
$lang = array_merge($lang, [
3939
// Post editor settings
4040
'PLACE_INLINE' => 'Place thumbnail inline',
41-
'IMAGE_PLACE_INLINE' => 'Place images inline',
41+
'IMAGE_PLACE_INLINE' => 'Place image inline',
4242
]);

imcger/imgupload/language/en/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// language pack author
4141
'ACP_IMCGER_LANG_DESC' => 'British English',
42-
'ACP_IMCGER_LANG_EXT_VER' => '1.2.0-alpha',
42+
'ACP_IMCGER_LANG_EXT_VER' => '1.2.0-beta',
4343
'ACP_IMCGER_LANG_AUTHOR' => 'IMC-Ger',
4444

4545
// Messages

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010
document.forms[form_name].elements[text_name].focus();
1111
}
1212

13+
/**
14+
* Remove attachment in preview when insert as img BBcode in message
15+
* AddOn for editor.js
16+
*
17+
* @var array notDisplayedAttachments Attachments that insert in the message
18+
* @var array notDisplayAttachmentBox Don't show any attachment
19+
*/
20+
function imcgerShowAttachImage() {
21+
// Return when no attachments present
22+
if (typeof notDisplayAttachmentBox == 'undefined' || notDisplayAttachmentBox && !notDisplayedAttachments.length) {
23+
return;
24+
}
25+
26+
if (notDisplayAttachmentBox) {
27+
document.getElementsByClassName('attachbox')[0].style.display = 'none';
28+
} else {
29+
let attachments = document.querySelectorAll(".attachbox .thumbnail");
30+
31+
attachments.forEach((attachment) => {
32+
let link = attachment.getElementsByTagName('a')[0].getAttribute("href");
33+
if (notDisplayedAttachments.includes(link.match('id=([0-9]+)')[1])) {
34+
attachment.parentElement.style.display = 'none';
35+
}
36+
});
37+
}
38+
}
39+
// When load the document, update AttatmentBox in preview
40+
document.addEventListener ("DOMContentLoaded", () => {imcgerShowAttachImage();});
41+
1342
(function($) { // Avoid conflicts with other libraries
1443

1544
'use strict';
@@ -181,6 +210,11 @@
181210
*/
182211
const imcgerImgUpload = {
183212
initialImage: function() {
213+
// Return if no content is displayed
214+
if (!document.getElementsByClassName("content").length) {
215+
return;
216+
}
217+
184218
let postImageArray = document.querySelectorAll(".content img.postimage"),
185219
postbodyWidth = window.getComputedStyle(document.getElementsByClassName("content")[0]).width;
186220

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
var notDisplayedAttachments = {{ IUL_NOT_DISPLAYED_ATTACHMENTS }},
3+
notDisplayAttachmentBox = {{ IUL_NOT_DISPLAY_ATTACHMENTBOX }};
4+
</script>

0 commit comments

Comments
 (0)