Skip to content

Commit 4d1a61b

Browse files
committed
Revised template variables
1 parent abad32f commit 4d1a61b

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

imcger/imgupload/event/main_listener.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ public function set_template_vars()
102102
$this->language->add_lang('attachment','imcger/imgupload');
103103
}
104104

105-
$allowed_images = '';
105+
$allowed_images = [];
106106
$img_maxwidth = $this->config['imcger_imgupload_image_inline_maxwidth'];
107107

108108
$sql = 'SELECT extension FROM ' . EXTENSIONS_TABLE . ' WHERE group_id = (SELECT group_id FROM ' . EXTENSION_GROUPS_TABLE . ' WHERE group_name = "IMAGES")';
109109
$result = $this->db->sql_query($sql);
110110

111111
while ($row = $this->db->sql_fetchrow($result))
112112
{
113-
$allowed_images .= '"' . $row['extension'] . '", ';
113+
$allowed_images[] = $row['extension'];
114114
}
115115
$this->db-> sql_freeresult();
116116

117117
$this->template->assign_vars([
118-
'IUL_ALLOWED_IMAGES' => $allowed_images,
118+
'IUL_ALLOWED_IMAGES' => json_encode($allowed_images),
119119
'IUL_IMG_SET_INLINE' => $this->config['imcger_imgupload_image_inline'],
120120
'IUL_IMG_MAXWIDTH' => $img_maxwidth ? $img_maxwidth . 'px' : 'none',
121121
]);
@@ -370,9 +370,10 @@ function imcger_viewtopic_modify_post_row($event)
370370
return;
371371
}
372372

373-
// Post message text
373+
// Create array with image id that insert in post message
374374
preg_match_all('#\[img\][\w\<\>\/\.?=&;]*[^\[](id=\d+)\<e\>\[\/img\]#', $row['post_text'], $matches);
375375

376+
// Find image in attachment, delete atachment
376377
foreach ($matches[1] as $image)
377378
{
378379
foreach ($post_attachments[$row['post_id']] as $key => $attachment)
@@ -384,19 +385,20 @@ function imcger_viewtopic_modify_post_row($event)
384385
}
385386
}
386387

387-
if (count($post_attachments[$row['post_id']]))
388+
$post_row = $event['post_row'];
389+
390+
// Set template vars
391+
if (!empty($post_attachments[$row['post_id']]) && count($post_attachments[$row['post_id']]))
388392
{
389-
$event['attachments'] = $post_attachments;
393+
$post_row['S_MULTIPLE_ATTACHMENTS'] = (bool) (count($post_attachments[$row['post_id']]) > 1);
390394
}
391395
else
392396
{
393-
$post_row = $event['post_row'];
394397
$post_row['S_HAS_ATTACHMENTS'] = false;
395398
$post_row['S_MULTIPLE_ATTACHMENTS'] = false;
396-
$event['post_row'] = $post_row;
397-
398-
$event['attachments'] = $post_attachments;
399399
}
400+
$event['post_row'] = $post_row;
401+
$event['attachments'] = $post_attachments;
400402
}
401403

402404
/**

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/**
55
* Add inline attachment at position as image
66
* AddOn for editor.js
7+
*
8+
* @param string fileUrl Image file URL
79
*/
810
function imcgerAttachImage(fileUrl) {
911
insert_text('[img]' + fileUrl + '[/img]');
@@ -14,29 +16,34 @@
1416
* Remove attachment in preview when insert as img BBcode in message
1517
* AddOn for editor.js
1618
*
17-
* @var array notDisplayedAttachments Attachments that insert in the message
18-
* @var array notDisplayAttachmentBox Don't show any attachment
19+
* @var array notDisplayedAttachments Attachments that insert in the message
20+
* @var bool notDisplayAttachmentBox Don't show any attachment
1921
*/
2022
function imcgerShowAttachImage() {
23+
const notDisplayedAttachments = {{ IUL_NOT_DISPLAYED_ATTACHMENTS }},
24+
notDisplayAttachmentBox = {{ IUL_NOT_DISPLAY_ATTACHMENTBOX }};
25+
2126
// Return when no attachments present
2227
if (typeof notDisplayAttachmentBox == 'undefined' || notDisplayAttachmentBox && !notDisplayedAttachments.length) {
2328
return;
2429
}
2530

2631
if (notDisplayAttachmentBox) {
32+
// Hide attachment box
2733
document.getElementsByClassName('attachbox')[0].style.display = 'none';
2834
} else {
2935
let attachments = document.querySelectorAll(".attachbox .thumbnail");
30-
36+
// Hide attachments that present in array
3137
attachments.forEach((attachment) => {
3238
let link = attachment.getElementsByTagName('a')[0].getAttribute("href");
39+
3340
if (notDisplayedAttachments.includes(link.match('id=([0-9]+)')[1])) {
3441
attachment.parentElement.style.display = 'none';
3542
}
3643
});
3744
}
3845
}
39-
// When load the document, update AttatmentBox in preview
46+
// When load the document, update AttachmentBox in preview
4047
document.addEventListener ("DOMContentLoaded", () => {imcgerShowAttachImage();});
4148

4249
(function($) { // Avoid conflicts with other libraries
@@ -93,7 +100,7 @@
93100
*/
94101
phpbb.plupload.imcgerUpdateRow = function() {
95102
$('.file-name.ellipsis-text a').each(function() {
96-
const allowedExt = [{{ IUL_ALLOWED_IMAGES }}];
103+
const allowedExt = {{ IUL_ALLOWED_IMAGES }};
97104
let link = $(this),
98105
imgUrl = $(this).attr('href'),
99106
real_filename = $(this).html(),
@@ -136,11 +143,11 @@
136143
/**
137144
* Update the relevant elements and hidden data for an attachment.
138145
*
139-
* @param {int} index The index from phpbb.plupload.ids of the attachment to edit.
140-
* @param {array} downloadUrl Optional array of download urls to update.
146+
* @param int index The index from phpbb.plupload.ids of the attachment to edit.
147+
* @param array downloadUrl Optional array of download urls to update.
141148
*/
142149
phpbb.plupload.updateRow = function(index, downloadUrl) {
143-
const allowedExt = [{{ IUL_ALLOWED_IMAGES }}];
150+
const allowedExt = {{ IUL_ALLOWED_IMAGES }};
144151
let attach = phpbb.plupload.data[index],
145152
row = $('[data-attach-id="' + attach.attach_id + '"]'),
146153
filenameArray = attach.real_filename.split('.'),

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)