Actually, I copied from the previous version 1.8 26 in which full edit of the post, new reply and New Thread works fine. Because this bankpipe related code doesn't add after upgradation to the core file.
Also, I Checked on a fresh mybb and bankpipe copy, but the issue is also present there.
But after upgrading to 1.8.29 full edit of the post and creation of a new thread did not work after adding that variable.
Below is 1.8.29 function_upload.php file one code portion. where full edit, new reply and post new thread gives error.
**
* Process adding attachment(s) when the "Add Attachment" button is pressed.
*
* @param int $pid The ID of the post.
* @param array $forumpermission The permissions for the forum.
* @param string $attachwhere Search string "pid='$pid'" or "posthash='".$db->escape_string($mybb->get_input('posthash'))."'"
* @param string $action Where called from: "newthread", "newreply", or "editpost"
*
* @return array Array of errors if any, empty array otherwise
*/
function add_attachments($pid, $forumpermissions, $attachwhere, $action=false)
{
global $db, $mybb, $editdraftpid, $lang;
$ret = array();
if($forumpermissions['canpostattachments'])
{
$attachments = array();
$fields = array ('name', 'type', 'tmp_name', 'error', 'size');
$aid = array();
$total = isset($_FILES['attachments']['name']) ? count($_FILES['attachments']['name']) : 0;
$filenames = "";
$delim = "";
for($i=0; $i<$total; ++$i)
{
foreach($fields as $field)
{
$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
}
$FILE = $attachments[$i];
if(!empty($FILE['name']) && !empty($FILE['type']) && $FILE['size'] > 0)
{
$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
$delim = ",";
}
}
if ($filenames != '')
{
$query = $db->simple_select("attachments", "filename", "{$attachwhere} AND filename IN (".$filenames.")");
while ($row = $db->fetch_array($query))
{
$aid[$row['filename']] = true;
}
}
foreach($attachments as $FILE)
{
if($err = check_parse_php_upload_err($FILE))
{
$ret['errors'][] = $err;
$mybb->input['action'] = $action;
}
else if(!empty($FILE['name']) && !empty($FILE['type']))
{
if($FILE['size'] > 0)
{
$filename = $db->escape_string($FILE['name']);
$exists = !empty($aid[$filename]);
$update_attachment = false;
if($action == "editpost")
{
if($exists && $mybb->get_input('updateattachment') && ($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']))
{
$update_attachment = true;
}
}
else
{
if($exists && $mybb->get_input('updateattachment'))
{
$update_attachment = true;
}
}
if(!$exists && $mybb->get_input('updateattachment') && $mybb->get_input('updateconfirmed', MyBB::INPUT_INT) != 1)
{
$ret['errors'][] = $lang->sprintf($lang->error_updatefailed, $filename);
}
else
{
$attachedfile = upload_attachment($FILE, $update_attachment);
if(!empty($attachedfile['error']))
{
$ret['errors'][] = $attachedfile['error'];
$mybb->input['action'] = $action;
}
/* + PL:bankpipe + */ else
/* + PL:bankpipe + */ {
/* + PL:bankpipe + */ $args = ['attachedfile' => $attachedfile];
/* + PL:bankpipe + */ $GLOBALS['plugins']->run_hooks('bankpipe_core_add_attachment', $args);
/* + PL:bankpipe + */ }
else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
$ret['success'][] = array($attachedfile['aid'], get_attachment_icon(get_extension($filename)), $filename, get_friendly_size($FILE['size']));
}
}
}
else
{
$ret['errors'][] = $lang->sprintf($lang->error_uploadempty, htmlspecialchars_uni($FILE['name']));
$mybb->input['action'] = $action;
}
}
}
}
return $ret;
}
If I remove, 'else' from the below 1.8.29 function_upload.php code, then there is no any post edit, reply, and new thread creation related issue. working fine.
I don't know whether the removal of code 'else' will create an issue or not on board.
else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
$ret['success'][] = array($attachedfile['aid'], get_attachment_icon(get_extension($filename)), $filename, get_friendly_size($FILE['size']));
}
Below is 1.8.26 function_upload.php code in which full edit, new reply, and post new thread working fine.
**
* Process adding attachment(s) when the "Add Attachment" button is pressed.
*
* @param int $pid The ID of the post.
* @param array $forumpermission The permissions for the forum.
* @param string $attachwhere Search string "pid='$pid'" or "posthash='".$db->escape_string($mybb->get_input('posthash'))."'"
* @param string $action Where called from: "newthread", "newreply", or "editpost"
*
* @return array Array of errors if any, empty array otherwise
*/
function add_attachments($pid, $forumpermissions, $attachwhere, $action=false)
{
global $db, $mybb, $editdraftpid, $lang;
$ret = array();
if($forumpermissions['canpostattachments'])
{
$attachments = array();
$fields = array ('name', 'type', 'tmp_name', 'error', 'size');
$aid = array();
$total = isset($_FILES['attachments']['name']) ? count($_FILES['attachments']['name']) : 0;
$filenames = "";
$delim = "";
for($i=0; $i<$total; ++$i)
{
foreach($fields as $field)
{
$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
}
$FILE = $attachments[$i];
if(!empty($FILE['name']) && !empty($FILE['type']) && $FILE['size'] > 0)
{
$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
$delim = ",";
}
}
if ($filenames != '')
{
$query = $db->simple_select("attachments", "filename", "{$attachwhere} AND filename IN (".$filenames.")");
while ($row = $db->fetch_array($query))
{
$aid[$row['filename']] = true;
}
}
foreach($attachments as $FILE)
{
if($err = check_parse_php_upload_err($FILE))
{
$ret['errors'][] = $err;
$mybb->input['action'] = $action;
}
else if(!empty($FILE['name']) && !empty($FILE['type']))
{
if($FILE['size'] > 0)
{
$filename = $db->escape_string($FILE['name']);
$exists = $aid[$filename];
$update_attachment = false;
if($action == "editpost")
{
if($exists && $mybb->get_input('updateattachment') && ($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']))
{
$update_attachment = true;
}
}
else
{
if($exists && $mybb->get_input('updateattachment'))
{
$update_attachment = true;
}
}
$attachedfile = upload_attachment($FILE, $update_attachment);
if(!empty($attachedfile['error']))
{
$ret['errors'][] = $attachedfile['error'];
$mybb->input['action'] = $action;
}
/* + PL:bankpipe + */ else
/* + PL:bankpipe + */ {
/* + PL:bankpipe + */ $args = ['attachedfile' => $attachedfile];
/* + PL:bankpipe + */ $GLOBALS['plugins']->run_hooks('bankpipe_core_add_attachment', $args);
/* + PL:bankpipe + */ }
}
else
{
$ret['errors'][] = $lang->sprintf($lang->error_uploadempty, htmlspecialchars_uni($FILE['name']));
$mybb->input['action'] = $action;
}
}
}
}
return $ret;
}
Please guide.
Thank you.