mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-29 21:10:31 +02:00
okie, using array_merge. :D
fixed: admin_prune added: prune topics last viewed at... (only admin_prune ATM) moved: delete_attachments to functions_admin git-svn-id: file:///svn/phpbb/trunk@4482 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -193,215 +193,6 @@ function update_last_post_information($type, $id, &$parent_sql)
|
||||
return $update_sql;
|
||||
}
|
||||
|
||||
// Delete Attachment
|
||||
function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = 'post', $user_id = -1)
|
||||
{
|
||||
global $db;
|
||||
|
||||
if ($post_id_array == -1 && $attach_id_array == -1 && $page == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate Array, if it's not an array
|
||||
if ($post_id_array == -1 && $attach_id_array != -1)
|
||||
{
|
||||
$post_id_array = array();
|
||||
|
||||
if (!is_array($attach_id_array))
|
||||
{
|
||||
$attach_id_array = (strstr($attach_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array);
|
||||
}
|
||||
|
||||
// Get the post_ids to fill the array
|
||||
$sql = 'SELECT ' . (($page == 'privmsgs') ? 'privmsgs_id' : 'post_id') . ' as id
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE attach_id IN (' . implode(', ', $attach_id_array) . ')
|
||||
GROUP BY id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if (!($row = $db->sql_fetchrow($result)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
$post_id_array[] = $row['id'];
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if (!is_array($post_id_array))
|
||||
{
|
||||
if (trim($post_id_array) == '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $post_id_array);
|
||||
}
|
||||
|
||||
if (!count($post_id_array))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// First of all, determine the post id and attach_id
|
||||
if ($attach_id_array == -1)
|
||||
{
|
||||
$attach_id_array = array();
|
||||
|
||||
// Get the attach_ids to fill the array
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE ' . (($page == 'privmsgs') ? 'privmsgs_id' : 'post_id') . ' IN (' . implode(', ', $post_id_array) . ')
|
||||
GROUP BY attach_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if (!($row = $db->sql_fetchrow($result)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
$attach_id_array[] = $row['attach_id'];
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if (!is_array($attach_id_array))
|
||||
{
|
||||
$attach_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array);
|
||||
}
|
||||
|
||||
if (!count($attach_id_array))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE attach_id IN (' . implode(', ', $attach_id_array) . ')
|
||||
AND post_id IN (' . implode(', ', $post_id_array) . ')';
|
||||
$db->sql_query($sql);
|
||||
|
||||
foreach ($attach_id_array as $attach_id)
|
||||
{
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . "
|
||||
WHERE attach_id = $attach_id";
|
||||
$select_result = $db->sql_query($sql);
|
||||
|
||||
if (!is_array($db->sql_fetchrow($select_result)))
|
||||
{
|
||||
$sql = 'SELECT attach_id, physical_filename, thumbnail
|
||||
FROM ' . ATTACHMENTS_DESC_TABLE . "
|
||||
WHERE attach_id = $attach_id";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
// delete attachments
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
phpbb_unlink($row['physical_filename'], 'file', $config['use_ftp_upload']);
|
||||
if ($row['thumbnail'])
|
||||
{
|
||||
phpbb_unlink($row['physical_filename'], 'thumbnail', $config['use_ftp_upload']);
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM ' . ATTACHMENTS_DESC_TABLE . '
|
||||
WHERE attach_id = ' . $row['attach_id'];
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
$db->sql_freeresult($select_result);
|
||||
}
|
||||
|
||||
// Now Sync the Topic/PM
|
||||
if ($page == 'privmsgs')
|
||||
{
|
||||
foreach ($post_id_array as $privmsgs_id)
|
||||
{
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE privmsgs_id = ' . $privmsgs_id;
|
||||
$select_result = $db->sql_query($sql);
|
||||
|
||||
if (!is_array($db->sql_fetchrow($select_result)))
|
||||
{
|
||||
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
|
||||
SET privmsgs_attachment = 0
|
||||
WHERE privmsgs_id = ' . $privmsgs_id;
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
$db->sql_freeresult($select_result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT topic_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_id IN (' . implode(', ', $post_id_array) . ')
|
||||
GROUP BY topic_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$topic_id = $row['topic_id'];
|
||||
|
||||
$sql = 'SELECT post_id
|
||||
FROM ' . POSTS_TABLE . "
|
||||
WHERE topic_id = $topic_id
|
||||
GROUP BY post_id";
|
||||
$result2 = $db->sql_query($sql);
|
||||
|
||||
$post_ids = array();
|
||||
|
||||
while ($post_row = $db->sql_fetchrow($result2))
|
||||
{
|
||||
$post_ids[] = $post_row['post_id'];
|
||||
}
|
||||
$db->sql_freeresult($result2);
|
||||
|
||||
if (count($post_ids))
|
||||
{
|
||||
$post_id_sql = implode(', ', $post_ids);
|
||||
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . "
|
||||
WHERE post_id IN ($post_id_sql)";
|
||||
$select_result = $db->sql_query_limit($sql, 1);
|
||||
$set_id = (!is_array($db->sql_fetchrow($select_result))) ? 0 : 1;
|
||||
$db->sql_freeresult($select_result);
|
||||
|
||||
$sql = 'UPDATE ' . TOPICS_TABLE . "
|
||||
SET topic_attachment = $set_id
|
||||
WHERE topic_id = $topic_id";
|
||||
$db->sql_query($sql);
|
||||
|
||||
foreach ($post_ids as $post_id)
|
||||
{
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . "
|
||||
WHERE post_id = $post_id";
|
||||
$select_result = $db->sql_query_limit($sql, 1);
|
||||
$set_id = (!is_array($db->sql_fetchrow($select_result))) ? 0 : 1;
|
||||
$db->sql_freeresult($select_result);
|
||||
|
||||
$sql = 'UPDATE ' . POSTS_TABLE . "
|
||||
SET post_attachment = $set_id
|
||||
WHERE post_id = $post_id";
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
|
||||
// Upload Attachment - filedata is generated here
|
||||
function upload_attachment($filename)
|
||||
{
|
||||
|
Reference in New Issue
Block a user