@@ -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 *
0 commit comments