MyBB Community Forums

Full Version: Warnings on newreply or newthread for guests writing in preview mode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If guests are allowed to write, there are some warnings under PHP8(.3) when the preview function is used

five pieces for you:

Warning [2] Undefined array key "userusername" - Line: 121 - File: inc/functions_post.php PHP 8.3.6 (Linux)

Warning [2] Undefined array key "userusername" - Line: 131 - File: inc/functions_post.php PHP 8.3.6 (Linux)

Warning [2] Undefined array key "uid" - Line: 182 - File: inc/functions_post.php PHP 8.3.6 (Linux)

Warning [2] Undefined array key "usergroup" - Line: 186 - File: inc/functions_post.php PHP 8.3.6 (Linux)

Warning [2] Undefined array key "usergroup" - Line: 200 - File: inc/functions_post.php PHP 8.3.6 (Linux)


two more, if guests can open a new thread

Warning [2] Undefined variable $pollbox - Line: 37 - File: newthread.php(1171) : eval()'d code PHP 8.3.6 (Linux)

Warning [2] Undefined array key "attachments" - Line: 163 - File: newthread.php PHP 8.3.6 (Linux)
If you know the fix, let me know, we can push to GitHub... or I will check later myself
Pushed:
https://github.com/mybb/mybb/issues/4826

Thanks for the report.
(2024-05-04, 08:47 AM)bv64 Wrote: [ -> ]two more, if guests can open a new thread

Warning [2] Undefined variable $pollbox - Line: 37 - File: newthread.php(1171) : eval()'d code PHP 8.3.6 (Linux)

Warning [2] Undefined array key "attachments" - Line: 163 - File: newthread.php PHP 8.3.6 (Linux)

The first specifically applies to any usergroup (not just guest) that do not have permissions to create a poll. It occurs when starting a new thread and anytime after when Preview Thread is clicked.

In newthread.php, initialize at 1092
$pollbox='';
This fixes the warning and does not prevent a member with canpostpolls permission to do so.

The second occurs when usergroup permissions do not permit attachments and Preview Thread and Save to Drafts is clicked.

Line 163 is a very awkward-to-read multiple if condition that does not evaluate whether there are attachments. The referenced key is null.
This replacement is easier to read and fixes the warnings without preventing attachments when permitted.
Replace
if($mybb->settings['enableattachments'] == 1 && ($mybb->get_input('newattachment') || $mybb->get_input('updateattachment') || ((($mybb->input['action'] == "do_newthread" && $mybb->get_input('submit')) || ($mybb->input['action'] == "newthread" && isset($mybb->input['previewpost'])) || isset($mybb->input['savedraft'])) && $_FILES['attachments'])))
with
if($mybb->settings['enableattachments'] == 1 && 
	($mybb->get_input('newattachment') || $mybb->get_input('updateattachment') || 
	((($mybb->input['action'] == "do_newthread" && $mybb->get_input('submit')) || 
	($mybb->input['action'] == "newthread" && isset($mybb->input['previewpost'])) || 
	isset($mybb->input['savedraft'])) && (isset($_FILES['attachments'])?$_FILES['attachments']:false))))
PR pushed, please check it