/** * Display Attachments in Review Window */ function display_review_attachments($post_id, $switch_attachment, $is_auth) { // Begin PNphpBB2 Module // global $attach_config, $attachments; global $attach_config, $attachments, $phpbb_root_path; // End PNphpBB2 Module if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']) || !($is_auth['auth_download'] && $is_auth['auth_view']) || intval($attach_config['attachment_topic_review']) == 0) { return; } @reset($attachments); $attachments['_' . $post_id] = get_attachments_from_post($post_id); if (sizeof($attachments['_' . $post_id]) == 0) { return; } display_attachments($post_id); }
function display_review_attachments($post_id, $switch_attachment, $is_auth) { global $attach_config, $attachments; if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']) || !($is_auth['auth_download'] && $is_auth['auth_view']) || intval($attach_config['attachment_topic_review']) == 0) { return; } @reset($attachments); $attachments['_' . $post_id] = get_attachments_from_post($post_id); if (count($attachments['_' . $post_id]) == 0) { return; } display_attachments($post_id); }
/** * Initializes some templating variables for displaying Attachments in Posts */ function init_display_post_attachments($switch_attachment) { global $attach_config, $is_auth, $template, $lang, $postrow, $total_posts, $attachments, $forum_row, $t_data; if (empty($t_data) && !empty($forum_row)) { $switch_attachment = $forum_row['topic_attachment']; } if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']) || !($is_auth['auth_download'] && $is_auth['auth_view'])) { init_display_template('body', '{postrow.ATTACHMENTS}', 'viewtopic_attach_guest.tpl'); return; } $post_id_array = array(); for ($i = 0; $i < $total_posts; $i++) { if ($postrow[$i]['post_attachment'] == 1) { $post_id_array[] = (int) $postrow[$i]['post_id']; } } if (sizeof($post_id_array) == 0) { return; } $rows = get_attachments_from_post($post_id_array); $num_rows = sizeof($rows); if ($num_rows == 0) { return; } @reset($attachments); for ($i = 0; $i < $num_rows; $i++) { $attachments['_' . $rows[$i]['post_id']][] = $rows[$i]; //bt if ($rows[$i]['tracker_status']) { if (defined('TORRENT_POST')) { bb_die('Multiple registered torrents in one topic<br /><br />first torrent found in post_id = ' . TORRENT_POST . '<br />current post_id = ' . $rows[$i]['post_id'] . '<br /><br />attachments info:<br /><pre style="text-align: left;">' . print_r($rows, TRUE) . '</pre>'); } define('TORRENT_POST', $rows[$i]['post_id']); } //bt end } init_display_template('body', '{postrow.ATTACHMENTS}'); init_complete_extensions_data(); }
/** * Handle all modes... (intern) * @private */ function handle_attachments($mode) { global $is_auth, $attach_config, $refresh, $HTTP_POST_VARS, $post_id, $submit, $preview, $error, $error_msg, $lang, $template, $userdata, $db; // // ok, what shall we do ;) // // Some adjustments for PM's if ($this->page == PAGE_PRIVMSGS) { global $privmsg_id; $post_id = $privmsg_id; if ($mode == 'post') { $mode = 'newtopic'; } else { if ($mode == 'edit') { $mode = 'editpost'; } } if ($userdata['user_level'] == ADMIN) { $is_auth['auth_attachments'] = 1; $max_attachments = ADMIN_MAX_ATTACHMENTS; } else { $is_auth['auth_attachments'] = intval($attach_config['allow_pm_attach']); $max_attachments = intval($attach_config['max_attachments_pm']); } } else { if ($userdata['user_level'] == ADMIN) { $max_attachments = ADMIN_MAX_ATTACHMENTS; } else { $max_attachments = intval($attach_config['max_attachments']); } } // nothing, if the user is not authorized or attachment mod disabled if (intval($attach_config['disable_mod']) || !$is_auth['auth_attachments']) { return false; } // Init Vars $attachments = array(); if (!$refresh) { $add = isset($HTTP_POST_VARS['add_attachment']) ? TRUE : FALSE; $delete = isset($HTTP_POST_VARS['del_attachment']) ? TRUE : FALSE; $edit = isset($HTTP_POST_VARS['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($HTTP_POST_VARS['update_attachment']) ? TRUE : FALSE; $del_thumbnail = isset($HTTP_POST_VARS['del_thumbnail']) ? TRUE : FALSE; $add_attachment_box = !empty($HTTP_POST_VARS['add_attachment_box']) ? TRUE : FALSE; $posted_attachments_box = !empty($HTTP_POST_VARS['posted_attachments_box']) ? TRUE : FALSE; $refresh = $add || $delete || $edit || $del_thumbnail || $update_attachment || $add_attachment_box || $posted_attachments_box; } // Get Attachments if ($this->page == PAGE_PRIVMSGS) { $attachments = get_attachments_from_pm($post_id); } else { $attachments = get_attachments_from_post($post_id); } if ($this->page == PAGE_PRIVMSGS) { if ($userdata['user_level'] == ADMIN) { $auth = TRUE; } else { $auth = intval($attach_config['allow_pm_attach']) ? TRUE : FALSE; } if (sizeof($attachments) == 1) { $template->assign_block_vars('switch_attachments', array()); $template->assign_vars(array('L_DELETE_ATTACHMENTS' => $lang['Delete_attachment'])); } else { if (sizeof($attachments) > 0) { $template->assign_block_vars('switch_attachments', array()); $template->assign_vars(array('L_DELETE_ATTACHMENTS' => $lang['Delete_attachments'])); } } } else { $auth = $is_auth['auth_edit'] || $is_auth['auth_mod'] ? TRUE : FALSE; } if (!$submit && $mode == 'editpost' && $auth) { if (!$refresh && !$preview && !$error && !isset($HTTP_POST_VARS['del_poll_option'])) { for ($i = 0; $i < sizeof($attachments); $i++) { $this->attachment_list[] = $attachments[$i]['physical_filename']; $this->attachment_comment_list[] = $attachments[$i]['comment']; $this->attachment_filename_list[] = $attachments[$i]['real_filename']; $this->attachment_extension_list[] = $attachments[$i]['extension']; $this->attachment_mimetype_list[] = $attachments[$i]['mimetype']; $this->attachment_filesize_list[] = $attachments[$i]['filesize']; $this->attachment_filetime_list[] = $attachments[$i]['filetime']; $this->attachment_id_list[] = $attachments[$i]['attach_id']; $this->attachment_thumbnail_list[] = $attachments[$i]['thumbnail']; } } } $this->num_attachments = sizeof($this->attachment_list); if ($submit && $mode != 'vote') { if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost') { if ($this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment($this->page); if (!$error && $this->post_attach) { array_unshift($this->attachment_list, $this->attach_filename); array_unshift($this->attachment_comment_list, $this->file_comment); array_unshift($this->attachment_filename_list, $this->filename); array_unshift($this->attachment_extension_list, $this->extension); array_unshift($this->attachment_mimetype_list, $this->type); array_unshift($this->attachment_filesize_list, $this->filesize); array_unshift($this->attachment_filetime_list, $this->filetime); array_unshift($this->attachment_id_list, '0'); array_unshift($this->attachment_thumbnail_list, $this->thumbnail); $this->file_comment = ''; // This Variable is set to FALSE here, because the Attachment Mod enter Attachments into the // Database in two modes, one if the id_list is 0 and the second one if post_attach is true // Since post_attach is automatically switched to true if an Attachment got added to the filesystem, // but we are assigning an id of 0 here, we have to reset the post_attach variable to FALSE. // // This is very relevant, because it could happen that the post got not submitted, but we do not // know this circumstance here. We could be at the posting page or we could be redirected to the entered // post. :) $this->post_attach = FALSE; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['Too_many_attachments'], intval($max_attachments)); } } } } if ($preview || $refresh || $error) { $delete_attachment = isset($HTTP_POST_VARS['del_attachment']) ? TRUE : FALSE; $delete_thumbnail = isset($HTTP_POST_VARS['del_thumbnail']) ? TRUE : FALSE; $add_attachment = isset($HTTP_POST_VARS['add_attachment']) ? TRUE : FALSE; $edit_attachment = isset($HTTP_POST_VARS['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($HTTP_POST_VARS['update_attachment']) ? TRUE : FALSE; // Perform actions on temporary attachments if ($delete_attachment || $delete_thumbnail) { // store old values $actual_id_list = get_var('attach_id_list', array(0)); $actual_comment_list = get_var('comment_list', array(''), true); $actual_filename_list = get_var('filename_list', array('')); $actual_extension_list = get_var('extension_list', array('')); $actual_mimetype_list = get_var('mimetype_list', array('')); $actual_filesize_list = get_var('filesize_list', array(0)); $actual_filetime_list = get_var('filetime_list', array(0)); $actual_list = get_var('attachment_list', array('')); $actual_thumbnail_list = get_var('attach_thumbnail_list', array(0)); // clean values $this->attachment_list = array(); $this->attachment_comment_list = array(); $this->attachment_filename_list = array(); $this->attachment_extension_list = array(); $this->attachment_mimetype_list = array(); $this->attachment_filesize_list = array(); $this->attachment_filetime_list = array(); $this->attachment_id_list = array(); $this->attachment_thumbnail_list = array(); // restore values :) if (isset($HTTP_POST_VARS['attachment_list'])) { for ($i = 0; $i < sizeof($actual_list); $i++) { $restore = FALSE; $del_thumb = FALSE; if ($delete_thumbnail) { if (!isset($HTTP_POST_VARS['del_thumbnail'][$actual_list[$i]])) { $restore = TRUE; } else { $del_thumb = TRUE; } } if ($delete_attachment) { if (!isset($HTTP_POST_VARS['del_attachment'][$actual_list[$i]])) { $restore = TRUE; } } if ($restore) { $this->attachment_list[] = $actual_list[$i]; $this->attachment_comment_list[] = $actual_comment_list[$i]; $this->attachment_filename_list[] = $actual_filename_list[$i]; $this->attachment_extension_list[] = $actual_extension_list[$i]; $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; $this->attachment_filesize_list[] = $actual_filesize_list[$i]; $this->attachment_filetime_list[] = $actual_filetime_list[$i]; $this->attachment_id_list[] = $actual_id_list[$i]; $this->attachment_thumbnail_list[] = $actual_thumbnail_list[$i]; } else { if (!$del_thumb) { // delete selected attachment if ($actual_id_list[$i] == '0') { unlink_attach($actual_list[$i]); if ($actual_thumbnail_list[$i] == 1) { unlink_attach($actual_list[$i], MODE_THUMBNAIL); } } else { delete_attachment($post_id, $actual_id_list[$i], $this->page); } } else { if ($del_thumb) { // delete selected thumbnail $this->attachment_list[] = $actual_list[$i]; $this->attachment_comment_list[] = $actual_comment_list[$i]; $this->attachment_filename_list[] = $actual_filename_list[$i]; $this->attachment_extension_list[] = $actual_extension_list[$i]; $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; $this->attachment_filesize_list[] = $actual_filesize_list[$i]; $this->attachment_filetime_list[] = $actual_filetime_list[$i]; $this->attachment_id_list[] = $actual_id_list[$i]; $this->attachment_thumbnail_list[] = 0; if ($actual_id_list[$i] == 0) { unlink_attach($actual_list[$i], MODE_THUMBNAIL); } else { $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET thumbnail = 0 WHERE attach_id = ' . (int) $actual_id_list[$i]; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Unable to update ' . ATTACHMENTS_DESC_TABLE . ' Table.', '', __LINE__, __FILE__, $sql); } } } } } } } } else { if ($edit_attachment || $update_attachment || $add_attachment || $preview) { if ($edit_attachment) { $actual_comment_list = get_var('comment_list', array(''), true); $this->attachment_comment_list = array(); for ($i = 0; $i < sizeof($this->attachment_list); $i++) { $this->attachment_comment_list[$i] = $actual_comment_list[$i]; } } if ($update_attachment) { if ($this->filename == '') { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['Error_empty_add_attachbox']; } $this->upload_attachment($this->page); if (!$error) { $actual_list = get_var('attachment_list', array('')); $actual_id_list = get_var('attach_id_list', array(0)); $attachment_id = 0; $actual_element = 0; for ($i = 0; $i < sizeof($actual_id_list); $i++) { if (isset($HTTP_POST_VARS['update_attachment'][$actual_id_list[$i]])) { $attachment_id = intval($actual_id_list[$i]); $actual_element = $i; } } // Get current informations to delete the Old Attachment $sql = 'SELECT physical_filename, comment, thumbnail FROM ' . ATTACHMENTS_DESC_TABLE . ' WHERE attach_id = ' . (int) $attachment_id; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Unable to select old Attachment Entry.', '', __LINE__, __FILE__, $sql); } if ($db->sql_numrows($result) != 1) { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['Error_missing_old_entry']; } $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $comment = trim($this->file_comment) == '' ? trim($row['comment']) : trim($this->file_comment); // Update Entry $sql_ary = array('physical_filename' => (string) basename($this->attach_filename), 'real_filename' => (string) basename($this->filename), 'comment' => (string) $comment, 'extension' => (string) strtolower($this->extension), 'mimetype' => (string) strtolower($this->type), 'filesize' => (int) $this->filesize, 'filetime' => (int) $this->filetime, 'thumbnail' => (int) $this->thumbnail); $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' WHERE attach_id = ' . (int) $attachment_id; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Unable to update the Attachment.', '', __LINE__, __FILE__, $sql); } // Delete the Old Attachment unlink_attach($row['physical_filename']); if (intval($row['thumbnail']) == 1) { unlink_attach($row['physical_filename'], MODE_THUMBNAIL); } // Make sure it is displayed $this->attachment_list[$actual_element] = $this->attach_filename; $this->attachment_comment_list[$actual_element] = $comment; $this->attachment_filename_list[$actual_element] = $this->filename; $this->attachment_extension_list[$actual_element] = $this->extension; $this->attachment_mimetype_list[$actual_element] = $this->type; $this->attachment_filesize_list[$actual_element] = $this->filesize; $this->attachment_filetime_list[$actual_element] = $this->filetime; $this->attachment_id_list[$actual_element] = $actual_id_list[$actual_element]; $this->attachment_thumbnail_list[$actual_element] = $this->thumbnail; $this->file_comment = ''; } } if (($add_attachment || $preview) && $this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment($this->page); if (!$error) { array_unshift($this->attachment_list, $this->attach_filename); array_unshift($this->attachment_comment_list, $this->file_comment); array_unshift($this->attachment_filename_list, $this->filename); array_unshift($this->attachment_extension_list, $this->extension); array_unshift($this->attachment_mimetype_list, $this->type); array_unshift($this->attachment_filesize_list, $this->filesize); array_unshift($this->attachment_filetime_list, $this->filetime); array_unshift($this->attachment_id_list, '0'); array_unshift($this->attachment_thumbnail_list, $this->thumbnail); $this->file_comment = ''; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['Too_many_attachments'], intval($max_attachments)); } } } } } return TRUE; }
function handle_attachments($mode) { global $is_auth, $attach_config, $refresh, $HTTP_POST_VARS, $post_id, $submit, $preview, $error, $error_msg, $lang, $template, $userdata; // // ok, what shall we do ;) // // // Some adjustments for PM's // if ($userdata['user_level'] == ADMIN) { $max_attachments = ADMIN_MAX_ATTACHMENTS; } else { $max_attachments = intval($attach_config['max_attachments_pm']); } // // nothing, if the user is not authorized or attachment mod disabled // if (intval($attach_config['disable_mod']) || !$is_auth['auth_attachments']) { return false; } // // Init Vars // $attachments = array(); if (!$refresh) { $add = isset($HTTP_POST_VARS['add_attachment']) ? TRUE : FALSE; $delete = isset($HTTP_POST_VARS['del_attachment']) ? TRUE : FALSE; $edit = isset($HTTP_POST_VARS['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($HTTP_POST_VARS['update_attachment']) ? TRUE : FALSE; $del_thumbnail = isset($HTTP_POST_VARS['del_thumbnail']) ? TRUE : FALSE; $add_attachment_box = !empty($HTTP_POST_VARS['add_attachment_box']) ? TRUE : FALSE; $posted_attachments_box = !empty($HTTP_POST_VARS['posted_attachments_box']) ? TRUE : FALSE; $refresh = $add || $delete || $edit || $del_thumbnail || $update_attachment || $add_attachment_box || $posted_attachments_box; } // // Get Attachments // $attachments = get_attachments_from_post($post_id); $auth = $is_auth['auth_edit'] || $is_auth['auth_mod'] ? TRUE : FALSE; if (!$submit && $mode == 'editpost' && $auth) { if (!$refresh && !$preview && !$error && !isset($HTTP_POST_VARS['del_poll_option'])) { for ($i = 0; $i < count($attachments); $i++) { $this->attachment_list[] = $attachments[$i]['physical_filename']; $this->attachment_comment_list[] = $attachments[$i]['comment']; $this->attachment_filename_list[] = $attachments[$i]['real_filename']; $this->attachment_extension_list[] = $attachments[$i]['extension']; $this->attachment_mimetype_list[] = $attachments[$i]['mimetype']; $this->attachment_filesize_list[] = $attachments[$i]['filesize']; $this->attachment_filetime_list[] = $attachments[$i]['filetime']; $this->attachment_id_list[] = $attachments[$i]['attach_id']; $this->attachment_thumbnail_list[] = $attachments[$i]['thumbnail']; } } } $this->num_attachments = count($this->attachment_list); if ($submit && $mode != 'vote') { if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost') { if ($this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment($this->page); if (!$error && $this->post_attach) { array_unshift($this->attachment_list, $this->attach_filename); array_unshift($this->attachment_comment_list, $this->file_comment); array_unshift($this->attachment_filename_list, $this->filename); array_unshift($this->attachment_extension_list, $this->extension); array_unshift($this->attachment_mimetype_list, $this->type); array_unshift($this->attachment_filesize_list, $this->filesize); array_unshift($this->attachment_filetime_list, $this->filetime); array_unshift($this->attachment_id_list, '0'); array_unshift($this->attachment_thumbnail_list, $this->thumbnail); $this->file_comment = ''; // This Variable is set to FALSE here, because the Attachment Mod enter Attachments into the // Database in two modes, one if the id_list is 0 and the second one if post_attach is true // Since post_attach is automatically switched to true if an Attachment got added to the filesystem, // but we are assigning an id of 0 here, we have to reset the post_attach variable to FALSE. // // This is very relevant, because it could happen that the post got not submitted, but we do not // know this circumstance here. We could be at the posting page or we could be redirected to the entered // post. :) $this->post_attach = FALSE; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['Too_many_attachments'], intval($max_attachments)); } } } } if ($preview || $refresh || $error) { $delete_attachment = isset($HTTP_POST_VARS['del_attachment']) ? TRUE : FALSE; $delete_thumbnail = isset($HTTP_POST_VARS['del_thumbnail']) ? TRUE : FALSE; $add_attachment = isset($HTTP_POST_VARS['add_attachment']) ? TRUE : FALSE; $edit_attachment = isset($HTTP_POST_VARS['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($HTTP_POST_VARS['update_attachment']) ? TRUE : FALSE; // // Perform actions on temporary attachments // if ($delete_attachment || $delete_thumbnail) { // store old values $actual_list = isset($HTTP_POST_VARS['attachment_list']) ? $HTTP_POST_VARS['attachment_list'] : array(); $actual_comment_list = isset($HTTP_POST_VARS['comment_list']) ? $HTTP_POST_VARS['comment_list'] : array(); $actual_filename_list = isset($HTTP_POST_VARS['filename_list']) ? $HTTP_POST_VARS['filename_list'] : array(); $actual_extension_list = isset($HTTP_POST_VARS['extension_list']) ? $HTTP_POST_VARS['extension_list'] : array(); $actual_mimetype_list = isset($HTTP_POST_VARS['mimetype_list']) ? $HTTP_POST_VARS['mimetype_list'] : array(); $actual_filesize_list = isset($HTTP_POST_VARS['filesize_list']) ? $HTTP_POST_VARS['filesize_list'] : array(); $actual_filetime_list = isset($HTTP_POST_VARS['filetime_list']) ? $HTTP_POST_VARS['filetime_list'] : array(); $actual_id_list = isset($HTTP_POST_VARS['attach_id_list']) ? $HTTP_POST_VARS['attach_id_list'] : array(); $actual_thumbnail_list = isset($HTTP_POST_VARS['attach_thumbnail_list']) ? $HTTP_POST_VARS['attach_thumbnail_list'] : array(); // clean values $this->attachment_list = array(); $this->attachment_comment_list = array(); $this->attachment_filename_list = array(); $this->attachment_extension_list = array(); $this->attachment_mimetype_list = array(); $this->attachment_filesize_list = array(); $this->attachment_filetime_list = array(); $this->attachment_id_list = array(); $this->attachment_thumbnail_list = array(); // restore values :) if (isset($HTTP_POST_VARS['attachment_list'])) { for ($i = 0; $i < count($actual_list); $i++) { $restore = FALSE; $del_thumb = FALSE; if ($delete_thumbnail) { if (!isset($HTTP_POST_VARS['del_thumbnail'][$actual_list[$i]])) { $restore = TRUE; } else { $del_thumb = TRUE; } } if ($delete_attachment) { if (!isset($HTTP_POST_VARS['del_attachment'][$actual_list[$i]])) { $restore = TRUE; } } if ($restore) { $this->attachment_list[] = $actual_list[$i]; $this->attachment_comment_list[] = $actual_comment_list[$i]; $this->attachment_filename_list[] = $actual_filename_list[$i]; $this->attachment_extension_list[] = $actual_extension_list[$i]; $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; $this->attachment_filesize_list[] = $actual_filesize_list[$i]; $this->attachment_filetime_list[] = $actual_filetime_list[$i]; $this->attachment_id_list[] = $actual_id_list[$i]; $this->attachment_thumbnail_list[] = $actual_thumbnail_list[$i]; } else { if (!$del_thumb) { // // delete selected attachment // if ($actual_id_list[$i] == '0') { unlink_attach($actual_list[$i]); if ($actual_thumbnail_list[$i] == 1) { unlink_attach($actual_list[$i], MODE_THUMBNAIL); } } else { delete_attachment($post_id, $actual_id_list[$i], $this->page); } } else { if ($del_thumb) { // // delete selected thumbnail // $this->attachment_list[] = $actual_list[$i]; $this->attachment_comment_list[] = $actual_comment_list[$i]; $this->attachment_filename_list[] = $actual_filename_list[$i]; $this->attachment_extension_list[] = $actual_extension_list[$i]; $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; $this->attachment_filesize_list[] = $actual_filesize_list[$i]; $this->attachment_filetime_list[] = $actual_filetime_list[$i]; $this->attachment_id_list[] = $actual_id_list[$i]; $this->attachment_thumbnail_list[] = 0; if ($actual_id_list[$i] == '0') { unlink_attach($actual_list[$i], MODE_THUMBNAIL); } else { $sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . "\n\t\t\t\t\t\t\t\tSET thumbnail = 0\n\t\t\t\t\t\t\t\tWHERE attach_id = " . $actual_id_list[$i]; if (!DB()->sql_query($sql)) { message_die(GENERAL_ERROR, 'Unable to update ' . ATTACHMENTS_DESC_TABLE . ' Table.', '', __LINE__, __FILE__, $sql); } } } } } } } } else { if ($edit_attachment || $update_attachment || $add_attachment || $preview) { if ($edit_attachment) { $actual_comment_list = isset($HTTP_POST_VARS['comment_list']) ? $HTTP_POST_VARS['comment_list'] : ''; $this->attachment_comment_list = array(); for ($i = 0; $i < count($this->attachment_list); $i++) { $this->attachment_comment_list[$i] = $actual_comment_list[$i]; } } if ($update_attachment) { if ($this->filename == '') { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['Error_empty_add_attachbox']; } $this->upload_attachment($this->page); if (!$error) { $actual_list = isset($HTTP_POST_VARS['attachment_list']) ? $HTTP_POST_VARS['attachment_list'] : array(); $actual_id_list = isset($HTTP_POST_VARS['attach_id_list']) ? $HTTP_POST_VARS['attach_id_list'] : array(); $attachment_id = 0; $actual_element = 0; for ($i = 0; $i < count($actual_id_list); $i++) { if (isset($HTTP_POST_VARS['update_attachment'][$actual_id_list[$i]])) { $attachment_id = intval($actual_id_list[$i]); $actual_element = $i; } } // Get current informations to delete the Old Attachment $sql = "SELECT physical_filename, comment, thumbnail FROM " . ATTACHMENTS_DESC_TABLE . "\n\t\t\t\t\t\tWHERE attach_id = " . $attachment_id; if (!($result = DB()->sql_query($sql))) { message_die(GENERAL_ERROR, 'Unable to select old Attachment Entry.', '', __LINE__, __FILE__, $sql); } if (DB()->num_rows($result) != 1) { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['Error_missing_old_entry']; } $row = DB()->sql_fetchrow($result); $comment = trim($this->file_comment) == '' ? trim($row['comment']) : trim($this->file_comment); $comment = addslashes($comment); // Update Entry $sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . "\n\t\t\t\t\t\tSET physical_filename = '" . str_replace("'", "''", basename($this->attach_filename)) . "', real_filename = '" . str_replace("'", "''", basename($this->filename)) . "', comment = '" . str_replace("'", "''", $comment) . "', extension = '" . str_replace("'", "''", $this->extension) . "', mimetype = '" . str_replace("'", "''", $this->type) . "', filesize = " . $this->filesize . ", filetime = " . $this->filetime . ", thumbnail = " . $this->thumbnail . "\n\t\t\t\t\t\tWHERE attach_id = " . (int) $attachment_id; if (!DB()->sql_query($sql)) { message_die(GENERAL_ERROR, 'Unable to update the Attachment.', '', __LINE__, __FILE__, $sql); } // Delete the Old Attachment unlink_attach($row['physical_filename']); if (intval($row['thumbnail']) == 1) { unlink_attach($row['physical_filename'], MODE_THUMBNAIL); } //bt if ($this->attachment_extension_list[$actual_element] === TORRENT_EXT && $attachments[$actual_element]['tracker_status']) { include_once FT_ROOT . 'includes/functions_torrent.php'; tracker_unregister($attachment_id); } //bt end // // Make sure it is displayed // $this->attachment_list[$actual_element] = $this->attach_filename; $this->attachment_comment_list[$actual_element] = $comment; $this->attachment_filename_list[$actual_element] = $this->filename; $this->attachment_extension_list[$actual_element] = $this->extension; $this->attachment_mimetype_list[$actual_element] = $this->type; $this->attachment_filesize_list[$actual_element] = $this->filesize; $this->attachment_filetime_list[$actual_element] = $this->filetime; $this->attachment_id_list[$actual_element] = $actual_id_list[$actual_element]; $this->attachment_thumbnail_list[$actual_element] = $this->thumbnail; $this->file_comment = ''; } } if (($add_attachment || $preview) && $this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment($this->page); if (!$error) { array_unshift($this->attachment_list, $this->attach_filename); array_unshift($this->attachment_comment_list, $this->file_comment); array_unshift($this->attachment_filename_list, $this->filename); array_unshift($this->attachment_extension_list, $this->extension); array_unshift($this->attachment_mimetype_list, $this->type); array_unshift($this->attachment_filesize_list, $this->filesize); array_unshift($this->attachment_filetime_list, $this->filetime); array_unshift($this->attachment_id_list, '0'); array_unshift($this->attachment_thumbnail_list, $this->thumbnail); $this->file_comment = ''; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['Too_many_attachments'], intval($max_attachments)); } } } } } return TRUE; }
protected function handle_attachments($mode) { global $is_auth, $attach_config, $refresh, $post_id, $submit, $preview, $error, $error_msg, $lang, $template, $userdata, $db; global $CPG_SESS; $max_attachments = $userdata['user_level'] == ADMIN ? ADMIN_MAX_ATTACHMENTS : intval($attach_config['max_attachments']); // // nothing, if the user is not authorized or attachment mod disabled // if (intval($attach_config['disable_mod']) || !$is_auth['auth_attachments']) { return FALSE; } // // Init Vars // if (!$refresh) { $add = isset($_POST['add_attachment']) ? TRUE : FALSE; $delete = isset($_POST['del_attachment']) ? TRUE : FALSE; $edit = isset($_POST['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($_POST['update_attachment']) ? TRUE : FALSE; $del_thumbnail = isset($_POST['del_thumbnail']) ? TRUE : FALSE; $add_attachment_box = !empty($_POST['add_attachment_box']) ? TRUE : FALSE; $posted_attachments_box = !empty($_POST['posted_attachments_box']) ? TRUE : FALSE; $refresh = $add || $delete || $edit || $del_thumbnail || $update_attachment || $add_attachment_box; } // // Get Attachments // $auth = $is_auth['auth_edit'] || $is_auth['auth_mod'] ? TRUE : FALSE; if (!$submit && $mode == 'editpost' && $auth) { if (!$refresh && !$preview && !$error && !isset($_POST['del_poll_option'])) { $this->attachments = get_attachments_from_post($post_id); } } $this->num_attachments = count($this->attachments); if ($submit && $mode != 'vote') { if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost') { if ($this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment(); if (!$error && $this->post_attach) { array_unshift($this->attachments, array('physical_filename' => $this->attach_filename, 'real_filename' => $this->filename, 'extension' => $this->extension, 'mimetype' => $this->type, 'filesize' => $this->filesize, 'filetime' => $this->filetime, 'attach_id' => 0, 'thumbnail' => $this->thumbnail, 'comment' => $this->file_comment)); $this->file_comment = ''; // This Variable is set to FALSE here, because the Attachment Mod enter Attachments into the // Database in two modes, one if the id_list is -1 and the second one if post_attach is true // Since post_attach is automatically switched to true if an Attachment got added to the filesystem, // but we are assigning an id of -1 here, we have to reset the post_attach variable to FALSE. // // This is very relevant, because it could happen that the post got not submitted, but we do not // know this circumstance here. We could be at the posting page or we could be redirected to the entered // post. :) $this->post_attach = FALSE; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['Too_many_attachments'], intval($max_attachments)); } } } } if ($preview || $refresh || $error) { $delete_attachment = isset($_POST['del_attachment']) ? TRUE : FALSE; $delete_thumbnail = isset($_POST['del_thumbnail']) ? TRUE : FALSE; $add_attachment = isset($_POST['add_attachment']) ? TRUE : FALSE; $edit_comment = isset($_POST['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($_POST['update_attachment']) ? TRUE : FALSE; // // Perform actions on temporary attachments // $actual_list = isset($CPG_SESS['bb_attachments']) ? $CPG_SESS['bb_attachments'] : array(); if ($delete_attachment || $delete_thumbnail) { // clean values $this->attachments = array(); // restore values :) if (!empty($actual_list)) { for ($i = 0; $i < count($actual_list); $i++) { $attachment = $actual_list[$i]; $restore = FALSE; $del_thumb = FALSE; if ($delete_thumbnail) { if (!isset($_POST['del_thumbnail'][$attachment['physical_filename']])) { $restore = TRUE; } else { $del_thumb = TRUE; } } if ($delete_attachment) { if (!isset($_POST['del_attachment'][$attachment['physical_filename']])) { $restore = TRUE; } } if ($restore) { $this->attachments[] = $attachment; } else { if (!$del_thumb) { // delete selected attachment if ($attachment['attach_id'] < 1) { unlink_attach($attachment['physical_filename']); if ($attachment['thumbnail'] == 1) { unlink_attach($attachment['physical_filename'], MODE_THUMBNAIL); } } else { delete_attachment($post_id, $attachment['attach_id'], $this->page); } } else { if ($del_thumb) { // delete selected thumbnail $attachment['thumbnail'] = 0; $this->attachments[] = $attachment; if ($attachment['attach_id'] < 1) { unlink_attach($attachment['physical_filename'], MODE_THUMBNAIL); } else { $db->sql_query("UPDATE " . ATTACHMENTS_DESC_TABLE . " SET thumbnail = 0\n\t\t\t\t\t\t\t\tWHERE attach_id = " . $attachment['attach_id']); } } } } } } } else { if ($edit_comment || $update_attachment || $add_attachment || $preview) { if ($edit_comment) { $actual_comment_list = isset($_POST['comment_list']) ? $_POST['comment_list'] : ''; for ($i = 0; $i < count($this->attachments); $i++) { $this->attachments[$i]['comment'] = $actual_comment_list[$i]; } } if ($update_attachment) { if ($this->filename == '') { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['Error_empty_add_attachbox']; } $this->upload_attachment(); if (!$error) { $attachment_id = 0; $actual_element = 0; for ($i = 0; $i < count($actual_list); $i++) { if (isset($_POST['update_attachment'][$actual_list[$i]['attach_id']])) { $attachment_id = intval($actual_list[$i]['attach_id']); $actual_element = $i; break; } } // Get current informations to delete the Old Attachment $sql = "SELECT physical_filename, comment, thumbnail FROM " . ATTACHMENTS_DESC_TABLE . "\n\t\t\t\t\t\tWHERE attach_id = " . $attachment_id; $result = $db->sql_query($sql); if ($db->sql_numrows($result) != 1) { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['Error_missing_old_entry']; } $row = $db->sql_fetchrow($result); $comment = trim($this->file_comment) == '' ? trim($row['comment']) : trim($this->file_comment); // Update Entry $sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . " \n\t\t\t\t\t\tSET physical_filename = '" . $this->attach_filename . "', real_filename = '" . $this->filename . "', comment = '" . Fix_Quotes($comment) . "', extension = '" . $this->extension . "', mimetype = '" . $this->type . "', filesize = " . $this->filesize . ", filetime = " . $this->filetime . ", thumbnail = " . $this->thumbnail . "\n\t\t\t\t\t\tWHERE attach_id = " . $attachment_id; $db->sql_query($sql); // Delete the Old Attachment unlink_attach($row['physical_filename']); if (intval($row['thumbnail']) == 1) { unlink_attach($row['physical_filename'], MODE_THUMBNAIL); } // // Make sure it is displayed // $this->attachments[$actual_element] = array('physical_filename' => $this->attach_filename, 'real_filename' => $this->filename, 'extension' => $this->extension, 'mimetype' => $this->type, 'filesize' => $this->filesize, 'filetime' => $this->filetime, 'attach_id' => $actual_list[$actual_element]['attach_id'], 'thumbnail' => $this->thumbnail, 'comment' => $comment); $this->file_comment = ''; } } if (($add_attachment || $preview) && $this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment(); if (!$error) { array_unshift($this->attachments, array('physical_filename' => $this->attach_filename, 'real_filename' => $this->filename, 'extension' => $this->extension, 'mimetype' => $this->type, 'filesize' => $this->filesize, 'filetime' => $this->filetime, 'attach_id' => 0, 'thumbnail' => $this->thumbnail, 'comment' => $this->file_comment)); $this->file_comment = ''; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['Too_many_attachments'], intval($max_attachments)); } } } } } $CPG_SESS['bb_attachments'] = $this->attachments; return TRUE; }
} $template->assign_var('S_HAS_POLL', is_array($vote_info)); } else { $template->assign_var('S_HAS_POLL', 0); } # Initializes some templating variables for displaying Attachments in Posts $switch_attachment = empty($forum_topic_data) && !empty($forum_row) ? $forum_row['topic_attachment'] : $forum_topic_data['topic_attachment']; if (intval($switch_attachment) != 0 && !intval($attach_config['disable_mod']) && $is_auth['auth_download'] && $is_auth['auth_view']) { $post_id_array = array(); for ($i = 0; $i < $total_posts; $i++) { if ($postrow[$i]['post_attachment'] == 1) { $post_id_array[] = $postrow[$i]['post_id']; } } if (count($post_id_array) > 0) { $rows = get_attachments_from_post($post_id_array); $num_rows = count($rows); if ($num_rows > 0) { reset($attachments); for ($i = 0; $i < $num_rows; $i++) { $attachments['_' . $rows[$i]['post_id']][] = $rows[$i]; } init_complete_extensions_data(); $template->assign_vars(array('L_POSTED_ATTACHMENTS' => $lang['Posted_attachments'], 'L_KILOBYTE' => $lang['KB'])); } } } # Update the topic view counter $db->sql_query("UPDATE " . TOPICS_TABLE . " SET topic_views = topic_views + 1 WHERE topic_id = {$topic_id}"); if (is_active('coppermine')) { list($ugall, $ugalldir) = $db->sql_ufetchrow("SELECT prefix, dirname FROM " . $prefix . "_cpg_installs");
/** * Handle all modes... (intern) * @private */ function handle_attachments($mode) { global $is_auth, $attach_config, $refresh, $post_id, $submit, $preview, $error, $error_msg, $lang; // // ok, what shall we do ;) // if (IS_ADMIN) { $max_attachments = ADMIN_MAX_ATTACHMENTS; } else { $max_attachments = intval($attach_config['max_attachments']); } $sql_id = 'post_id'; // nothing, if the user is not authorized or attachment mod disabled if (intval($attach_config['disable_mod']) || !$is_auth['auth_attachments']) { return false; } // Init Vars $attachments = array(); if (!$refresh) { $add = isset($_POST['add_attachment']) ? TRUE : FALSE; $delete = isset($_POST['del_attachment']) ? TRUE : FALSE; $edit = isset($_POST['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($_POST['update_attachment']) ? TRUE : FALSE; $del_thumbnail = isset($_POST['del_thumbnail']) ? TRUE : FALSE; $add_attachment_box = !empty($_POST['add_attachment_box']) ? TRUE : FALSE; $posted_attachments_box = !empty($_POST['posted_attachments_box']) ? TRUE : FALSE; $refresh = $add || $delete || $edit || $del_thumbnail || $update_attachment || $add_attachment_box || $posted_attachments_box; } // Get Attachments $attachments = get_attachments_from_post($post_id); $auth = $is_auth['auth_edit'] || $is_auth['auth_mod'] ? TRUE : FALSE; if (!$submit && $mode == 'editpost' && $auth) { if (!$refresh && !$preview && !$error) { for ($i = 0; $i < sizeof($attachments); $i++) { $this->attachment_list[] = $attachments[$i]['physical_filename']; $this->attachment_comment_list[] = $attachments[$i]['comment']; $this->attachment_filename_list[] = $attachments[$i]['real_filename']; $this->attachment_extension_list[] = $attachments[$i]['extension']; $this->attachment_mimetype_list[] = $attachments[$i]['mimetype']; $this->attachment_filesize_list[] = $attachments[$i]['filesize']; $this->attachment_filetime_list[] = $attachments[$i]['filetime']; $this->attachment_id_list[] = $attachments[$i]['attach_id']; $this->attachment_thumbnail_list[] = $attachments[$i]['thumbnail']; } } } $this->num_attachments = sizeof($this->attachment_list); if ($submit) { if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost') { if ($this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment($this->page); if (!$error && $this->post_attach) { array_unshift($this->attachment_list, $this->attach_filename); array_unshift($this->attachment_comment_list, $this->file_comment); array_unshift($this->attachment_filename_list, $this->filename); array_unshift($this->attachment_extension_list, $this->extension); array_unshift($this->attachment_mimetype_list, $this->type); array_unshift($this->attachment_filesize_list, $this->filesize); array_unshift($this->attachment_filetime_list, $this->filetime); array_unshift($this->attachment_id_list, '0'); array_unshift($this->attachment_thumbnail_list, $this->thumbnail); $this->file_comment = ''; $this->post_attach = FALSE; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['TOO_MANY_ATTACHMENTS'], intval($max_attachments)); } } } } if ($preview || $refresh || $error) { $delete_attachment = isset($_POST['del_attachment']) ? TRUE : FALSE; $delete_thumbnail = isset($_POST['del_thumbnail']) ? TRUE : FALSE; $add_attachment = isset($_POST['add_attachment']) ? TRUE : FALSE; $edit_attachment = isset($_POST['edit_comment']) ? TRUE : FALSE; $update_attachment = isset($_POST['update_attachment']) ? TRUE : FALSE; // Perform actions on temporary attachments if ($delete_attachment || $delete_thumbnail) { // store old values $actual_id_list = get_var('attach_id_list', array(0)); $actual_comment_list = get_var('comment_list', array('')); $actual_filename_list = get_var('filename_list', array('')); $actual_extension_list = get_var('extension_list', array('')); $actual_mimetype_list = get_var('mimetype_list', array('')); $actual_filesize_list = get_var('filesize_list', array(0)); $actual_filetime_list = get_var('filetime_list', array(0)); $actual_list = get_var('attachment_list', array('')); $actual_thumbnail_list = get_var('attach_thumbnail_list', array(0)); // clean values $this->attachment_list = array(); $this->attachment_comment_list = array(); $this->attachment_filename_list = array(); $this->attachment_extension_list = array(); $this->attachment_mimetype_list = array(); $this->attachment_filesize_list = array(); $this->attachment_filetime_list = array(); $this->attachment_id_list = array(); $this->attachment_thumbnail_list = array(); // restore values :) if (isset($_POST['attachment_list'])) { for ($i = 0; $i < sizeof($actual_list); $i++) { $restore = FALSE; $del_thumb = FALSE; if ($delete_thumbnail) { if (!isset($_POST['del_thumbnail'][$actual_list[$i]])) { $restore = TRUE; } else { $del_thumb = TRUE; } } if ($delete_attachment) { if (!isset($_POST['del_attachment'][$actual_list[$i]])) { $restore = TRUE; } } if ($restore) { $this->attachment_list[] = $actual_list[$i]; $this->attachment_comment_list[] = $actual_comment_list[$i]; $this->attachment_filename_list[] = $actual_filename_list[$i]; $this->attachment_extension_list[] = $actual_extension_list[$i]; $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; $this->attachment_filesize_list[] = $actual_filesize_list[$i]; $this->attachment_filetime_list[] = $actual_filetime_list[$i]; $this->attachment_id_list[] = $actual_id_list[$i]; $this->attachment_thumbnail_list[] = $actual_thumbnail_list[$i]; } else { if (!$del_thumb) { // delete selected attachment if ($actual_id_list[$i] == '0') { unlink_attach($actual_list[$i]); if ($actual_thumbnail_list[$i] == 1) { unlink_attach($actual_list[$i], MODE_THUMBNAIL); } } else { delete_attachment($post_id, $actual_id_list[$i], $this->page); } } else { if ($del_thumb) { // delete selected thumbnail $this->attachment_list[] = $actual_list[$i]; $this->attachment_comment_list[] = $actual_comment_list[$i]; $this->attachment_filename_list[] = $actual_filename_list[$i]; $this->attachment_extension_list[] = $actual_extension_list[$i]; $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; $this->attachment_filesize_list[] = $actual_filesize_list[$i]; $this->attachment_filetime_list[] = $actual_filetime_list[$i]; $this->attachment_id_list[] = $actual_id_list[$i]; $this->attachment_thumbnail_list[] = 0; if ($actual_id_list[$i] == 0) { unlink_attach($actual_list[$i], MODE_THUMBNAIL); } else { $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET thumbnail = 0 WHERE attach_id = ' . (int) $actual_id_list[$i]; if (!DB()->sql_query($sql)) { bb_die('Unable to update ' . BB_ATTACHMENTS_DESC); } } } } } } } } else { if ($edit_attachment || $update_attachment || $add_attachment || $preview) { if ($edit_attachment) { $actual_comment_list = get_var('comment_list', array('')); $this->attachment_comment_list = array(); for ($i = 0; $i < sizeof($this->attachment_list); $i++) { $this->attachment_comment_list[$i] = $actual_comment_list[$i]; } } if ($update_attachment) { if ($this->filename == '') { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['ERROR_EMPTY_ADD_ATTACHBOX']; } $this->upload_attachment($this->page); if (!$error) { $actual_list = get_var('attachment_list', array('')); $actual_id_list = get_var('attach_id_list', array(0)); $attachment_id = 0; $actual_element = 0; for ($i = 0; $i < sizeof($actual_id_list); $i++) { if (isset($_POST['update_attachment'][$actual_id_list[$i]])) { $attachment_id = intval($actual_id_list[$i]); $actual_element = $i; } } // Get current informations to delete the Old Attachment $sql = 'SELECT physical_filename, comment, thumbnail FROM ' . BB_ATTACHMENTS_DESC . ' WHERE attach_id = ' . (int) $attachment_id; if (!($result = DB()->sql_query($sql))) { bb_die('Unable to select old attachment entry'); } if (DB()->num_rows($result) != 1) { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= $lang['ERROR_MISSING_OLD_ENTRY']; } $row = DB()->sql_fetchrow($result); DB()->sql_freeresult($result); $comment = trim($this->file_comment) == '' ? trim($row['comment']) : trim($this->file_comment); // Update Entry $sql_ary = array('physical_filename' => (string) basename($this->attach_filename), 'real_filename' => (string) basename($this->filename), 'comment' => (string) $comment, 'extension' => (string) strtolower($this->extension), 'mimetype' => (string) strtolower($this->type), 'filesize' => (int) $this->filesize, 'filetime' => (int) $this->filetime, 'thumbnail' => (int) $this->thumbnail); $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' WHERE attach_id = ' . (int) $attachment_id; if (!DB()->sql_query($sql)) { bb_die('Unable to update the attachment'); } // Delete the Old Attachment unlink_attach($row['physical_filename']); if (intval($row['thumbnail']) == 1) { unlink_attach($row['physical_filename'], MODE_THUMBNAIL); } //bt if ($this->attachment_extension_list[$actual_element] === TORRENT_EXT && $attachments[$actual_element]['tracker_status']) { include INC_DIR . 'functions_torrent.php'; tracker_unregister($attachment_id); } //bt end // Make sure it is displayed $this->attachment_list[$actual_element] = $this->attach_filename; $this->attachment_comment_list[$actual_element] = $comment; $this->attachment_filename_list[$actual_element] = $this->filename; $this->attachment_extension_list[$actual_element] = $this->extension; $this->attachment_mimetype_list[$actual_element] = $this->type; $this->attachment_filesize_list[$actual_element] = $this->filesize; $this->attachment_filetime_list[$actual_element] = $this->filetime; $this->attachment_id_list[$actual_element] = $actual_id_list[$actual_element]; $this->attachment_thumbnail_list[$actual_element] = $this->thumbnail; $this->file_comment = ''; } } if (($add_attachment || $preview) && $this->filename != '') { if ($this->num_attachments < intval($max_attachments)) { $this->upload_attachment($this->page); if (!$error) { array_unshift($this->attachment_list, $this->attach_filename); array_unshift($this->attachment_comment_list, $this->file_comment); array_unshift($this->attachment_filename_list, $this->filename); array_unshift($this->attachment_extension_list, $this->extension); array_unshift($this->attachment_mimetype_list, $this->type); array_unshift($this->attachment_filesize_list, $this->filesize); array_unshift($this->attachment_filetime_list, $this->filetime); array_unshift($this->attachment_id_list, '0'); array_unshift($this->attachment_thumbnail_list, $this->thumbnail); $this->file_comment = ''; } } else { $error = TRUE; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf($lang['TOO_MANY_ATTACHMENTS'], intval($max_attachments)); } } } } } return TRUE; }