1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-08 17:56:52 +02:00

changed attachment processing (posting), the old way was a mess. :)

git-svn-id: file:///svn/phpbb/trunk@3960 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2003-05-01 18:24:18 +00:00
parent 3a4e4374dc
commit 9def7a65e3
5 changed files with 110 additions and 178 deletions

View File

@@ -147,7 +147,7 @@ function format_display($message, $html, $bbcode, $uid, $url, $smilies, $sig)
// If we allow users to disable display of emoticons
// we'll need an appropriate check and preg_replace here
$message = (empty($smilies) || empty($config['allow_smilies'])) ? preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $message) : str_replace('<img src="{SMILE_PATH}', '<img src="' . $config['smilies_path'], $message);
$message = (empty($smilies) || empty($config['allow_smilies'])) ? preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $message) : str_replace('<img src="{SMILE_PATH}', '<img src="' . $phpbb_root_path . $config['smilies_path'], $message);
// Replace naughty words such as farty pants
if (sizeof($censors))
@@ -585,11 +585,7 @@ function upload_attachment($filename)
// Opera add the name to the mime type
$filedata['mimetype'] = ( strstr($filedata['mimetype'], '; name') ) ? str_replace(strstr($filedata['mimetype'], '; name'), '', $filedata['mimetype']) : $filedata['mimetype'];
$filedata['extension'] = strrchr(strtolower($filename), '.');
$filedata['extension'][0] = ' ';
$filedata['extension'] = strtolower(trim($filedata['extension']));
$filedata['extension'] = (is_array($filedata['extension'])) ? '' : $filedata['extension'];
$filedata['extension'] = array_pop(explode('.', strtolower($filename)));
$filedata['filesize'] = (!@filesize($file)) ? intval($_FILES['size']) : @filesize($file);
$extensions = array();
@@ -929,7 +925,7 @@ function phpbb_unlink($filename, $mode = 'file', $use_ftp = false)
// Submit Post
function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_uid, $poll, $attachment_data, $post_data)
function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_uid, $poll, $attachment_data, $filename_data, $post_data)
{
global $db, $auth, $user, $config, $phpEx, $SID, $template;
@@ -950,7 +946,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
'topic_type' => $topic_type,
'topic_approved' => ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1,
'icon_id' => $post_data['icon_id'],
'topic_attachment' => (sizeof($attachment_data['physical_filename'])) ? 1 : 0,
'topic_attachment' => (sizeof($filename_data['physical_filename'])) ? 1 : 0,
'topic_poster' => intval($user->data['user_id']),
'topic_first_poster_name' => ($username != '') ? stripslashes($username) : (($user->data['user_id'] == ANONYMOUS) ? '' : stripslashes($user->data['username']))
);
@@ -1052,32 +1048,32 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
}
// Submit Attachments
if (count($attachment_data['attach_id']) && !empty($post_data['post_id']) && ($mode == 'post' || $mode == 'reply' || $mode == 'edit'))
if (count($attachment_data) && !empty($post_data['post_id']) && ($mode == 'post' || $mode == 'reply' || $mode == 'edit'))
{
for ($i = 0; $i < count($attachment_data['attach_id']); $i++)
foreach ($attachment_data as $attach_row)
{
if ($attachment_data['attach_id'][$i] != '-1')
if ($attach_row['attach_id'] != '-1')
{
// update entry in db if attachment already stored in db and filespace
$attach_sql = array(
'comment' => trim($attachment_data['comment'][$i])
'comment' => trim($attach_row['comment'])
);
$sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' WHERE attach_id = ' . $attachment_data['attach_id'][$i];
$sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' WHERE attach_id = ' . intval($attach_row['attach_id']);
$db->sql_query($sql);
}
else
{
// insert attachment into db
$attach_sql = array(
'physical_filename' => $attachment_data['physical_filename'][$i],
'real_filename' => $attachment_data['real_filename'][$i],
'comment' => trim($attachment_data['comment'][$i]),
'extension' => $attachment_data['extension'][$i],
'mimetype' => $attachment_data['mimetype'][$i],
'filesize' => $attachment_data['filesize'][$i],
'filetime' => $attachment_data['filetime'][$i],
'thumbnail' => $attachment_data['thumbnail'][$i]
'physical_filename' => $attach_row['physical_filename'],
'real_filename' => $attach_row['real_filename'],
'comment' => trim($attach_row['comment']),
'extension' => $attach_row['extension'],
'mimetype' => $attach_row['mimetype'],
'filesize' => $attach_row['filesize'],
'filetime' => $attach_row['filetime'],
'thumbnail' => $attach_row['thumbnail']
);
$sql = 'INSERT INTO ' . ATTACHMENTS_DESC_TABLE . ' ' . $db->sql_build_array('INSERT', $attach_sql);
@@ -1096,7 +1092,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
}
}
if (count($attachment_data['attach_id']) > 0)
if (count($attachment_data))
{
$sql = "UPDATE " . POSTS_TABLE . "
SET post_attachment = 1

View File

@@ -55,6 +55,9 @@ class parse_message
var $message = '';
var $disabled_bbcodes = array();
var $attachment_data = array();
var $filename_data = array();
function parse_message($message_type)
{
$this->message_mode = $message_type;
@@ -543,26 +546,26 @@ class parse_message
return;
}
function parse_attachments($mode, $post_id, $submit, $preview, $refresh, &$attachment_data)
function parse_attachments($mode, $post_id, $submit, $preview, $refresh)
{
global $config, $_FILE, $_POST, $auth, $user;
$error = false;
$error_msg = '';
$num_attachments = count($attachment_data['attach_id']);
$attachment_data['filecomment'] = ( isset($_POST['filecomment']) ) ? trim( strip_tags($_POST['filecomment'])) : '';
$attachment_data['filename'] = ( $_FILES['fileupload']['name'] != 'none' ) ? trim($_FILES['fileupload']['name']) : '';
$num_attachments = count($this->attachment_data);
$this->filename_data['filecomment'] = ( isset($_POST['filecomment']) ) ? trim( strip_tags($_POST['filecomment'])) : '';
$this->filename_data['filename'] = ( $_FILES['fileupload']['name'] != 'none' ) ? trim($_FILES['fileupload']['name']) : '';
$add_file = ( isset($_POST['add_file']) ) ? true : false;
$delete_file = ( isset($_POST['delete_file']) ) ? true : false;
$edit_comment = ( isset($_POST['edit_comment']) ) ? true : false;
if ( $submit && ($mode == 'post' || $mode == 'reply' || $mode == 'edit') && $attachment_data['filename'] != '')
if ( $submit && ($mode == 'post' || $mode == 'reply' || $mode == 'edit') && $this->filename_data['filename'] != '')
{
if ( $num_attachments < $config['max_attachments'] ) //|| $auth->acl_gets('m_', 'a_', $forum_id) )
{
$filedata = upload_attachment($attachment_data['filename']);
$filedata = upload_attachment($this->filename_data['filename']);
if ($filedata['error'])
{
@@ -572,19 +575,22 @@ class parse_message
if (($filedata['post_attach']) && (!$error))
{
array_unshift($attachment_data['physical_filename'], $filedata['destination_filename']);
array_unshift($attachment_data['comment'], $attachment_data['filecomment']);
array_unshift($attachment_data['real_filename'], $filedata['filename']);
array_unshift($attachment_data['extension'], $filedata['extension']);
array_unshift($attachment_data['mimetype'], $filedata['mimetype']);
array_unshift($attachment_data['filesize'], $filedata['filesize']);
array_unshift($attachment_data['filetime'], $filedata['filetime']);
array_unshift($attachment_data['attach_id'], '-1');
array_unshift($attachment_data['thumbnail'], $filedata['thumbnail']);
$new_entry = array(
'physical_filename' => $filedata['destination_filename'],
'comment' => $this->filename_data['filecomment'],
'real_filename' => $filedata['filename'],
'extension' => $filedata['extension'],
'mimetype' => $filedata['mimetype'],
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'attach_id' => '-1',
'thumbnail' => $filedata['thumbnail']
);
$attachment_data['filecomment'] = '';
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->filename_data['filecomment'] = '';
// This Variable is set to FALSE here, because the Attachment Mod enter Attachments into the
// This Variable is set to FALSE here, because Attachments are entered 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.
@@ -607,94 +613,45 @@ class parse_message
// Perform actions on temporary attachments
if ($delete_file)
{
// store old values
$actual_list = ( isset($_POST['attachment_list']) ) ? $_POST['attachment_list'] : array();
$actual_comment_list = ( isset($_POST['comment_list']) ) ? $_POST['comment_list'] : array();
$actual_filename_list = ( isset($_POST['filename_list']) ) ? $_POST['filename_list'] : array();
$actual_extension_list = ( isset($_POST['extension_list']) ) ? $_POST['extension_list'] : array();
$actual_mimetype_list = ( isset($_POST['mimetype_list']) ) ? $_POST['mimetype_list'] : array();
$actual_filesize_list = ( isset($_POST['filesize_list']) ) ? $_POST['filesize_list'] : array();
$actual_filetime_list = ( isset($_POST['filetime_list']) ) ? $_POST['filetime_list'] : array();
$actual_id_list = ( isset($_POST['attach_id_list']) ) ? $_POST['attach_id_list'] : array();
$actual_thumbnail_list = ( isset($_POST['attach_thumbnail_list']) ) ? $_POST['attach_thumbnail_list'] : array();
// clean values
$attachment_data['physical_filename'] = array();
$attachment_data['comment'] = array();
$attachment_data['real_filename'] = array();
$attachment_data['extension'] = array();
$attachment_data['mimetype'] = array();
$attachment_data['filesize'] = array();
$attachment_data['filetime'] = array();
$attachment_data['attach_id'] = array();
$attachment_data['thumbnail'] = array();
// restore values :)
if( isset($_POST['attachment_list']) )
foreach ($_POST['delete_file'] as $index => $value)
{
for ($i = 0; $i < count($actual_list); $i++)
// delete selected attachment
if ($this->attachment_data[$index]['attach_id'] == '-1')
{
$restore = false;
if ($delete_file)
{
if (!isset($_POST['delete_file'][$actual_list[$i]]))
{
$restore = true;
}
}
phpbb_unlink($this->attachment_data[$index]['physical_filename'], 'file', $config['use_ftp_upload']);
if ($restore)
if ($this->attachment_data[$index]['thumbnail'] == 1)
{
$attachment_data['physical_filename'][] = $actual_list[$i];
$attachment_data['comment'][] = $actual_comment_list[$i];
$attachment_data['real_filename'][] = $actual_filename_list[$i];
$attachment_data['extension'][] = $actual_extension_list[$i];
$attachment_data['mimetype'][] = $actual_mimetype_list[$i];
$attachment_data['filesize'][] = $actual_filesize_list[$i];
$attachment_data['filetime'][] = $actual_filetime_list[$i];
$attachment_data['attach_id'][] = $actual_id_list[$i];
$attachment_data['thumbnail'][] = $actual_thumbnail_list[$i];
}
else
{
// delete selected attachment
if ($actual_id_list[$i] == '-1')
{
phpbb_unlink($actual_list[$i], 'file', $config['use_ftp_upload']);
if ($actual_thumbnail_list[$i] == 1)
{
phpbb_unlink('t_' . $actual_list[$i], 'thumbnail', $config['use_ftp_upload']);
}
}
else
{
delete_attachment($post_id, $actual_id_list[$i]);
}
phpbb_unlink('t_' . $this->attachment_data[$index]['physical_filename'], 'thumbnail', $config['use_ftp_upload']);
}
}
else
{
delete_attachment($post_id, intval($this->attachment_data[$index]['attach_id']));
}
unset($this->attachment_data[$index]);
}
// a quick way to reindex the array. :)
$this->attachment_data = array_merge($this->attachment_data);
}
else if ( ($edit_comment) || ($add_file) || ($preview) )
{
if ($edit_comment)
{
$actual_comment_list = ( isset($_POST['comment_list']) ) ? $_POST['comment_list'] : '';
$attachment_data['comment'] = array();
for ($i = 0; $i < count($attachment_data['physical_filename']); $i++)
foreach ($actual_comment_list as $index => $entry)
{
$attachment_data['comment'][$i] = $actual_comment_list[$i];
$this->attachment_data[$index]['comment'] = $entry;
}
}
if ((($add_file) || ($preview) ) && ($attachment_data['filename'] != '') )
if ((($add_file) || ($preview) ) && ($this->filename_data['filename'] != '') )
{
if ( $num_attachments < $config['max_attachments'] ) //|| $auth->acl_gets('m_', 'a_', $forum_id) )
{
$filedata = upload_attachment($attachment_data['filename']);
$filedata = upload_attachment($this->filename_data['filename']);
if ($filedata['error'])
{
@@ -704,17 +661,20 @@ class parse_message
if (!$error)
{
array_unshift($attachment_data['physical_filename'], $filedata['destination_filename']);
array_unshift($attachment_data['comment'], $attachment_data['filecomment']);
array_unshift($attachment_data['real_filename'], $filedata['filename']);
array_unshift($attachment_data['extension'], $filedata['extension']);
array_unshift($attachment_data['mimetype'], $filedata['mimetype']);
array_unshift($attachment_data['filesize'], $filedata['filesize']);
array_unshift($attachment_data['filetime'], $filedata['filetime']);
array_unshift($attachment_data['attach_id'], '-1');
array_unshift($attachment_data['thumbnail'], $filedata['thumbnail']);
$new_entry = array(
'physical_filename' => $filedata['destination_filename'],
'comment' => $this->filename_data['filecomment'],
'real_filename' => $filedata['filename'],
'extension' => $filedata['extension'],
'mimetype' => $filedata['mimetype'],
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'attach_id' => '-1',
'thumbnail' => $filedata['thumbnail']
);
$attachment_data['filecomment'] = '';
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->filename_data['filecomment'] = '';
}
}
else