1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-18 14:48:28 +01: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:
Meik Sievertsen 2003-09-07 17:16:12 +00:00
parent 734b62cca6
commit db2a73d2f0
7 changed files with 288 additions and 255 deletions

View File

@ -1,23 +1,15 @@
<?php
/***************************************************************************
* admin_prune.php
* -------------------
* begin : Mon Jul 31, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id$
*
****************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
// -------------------------------------------------------------
//
// $Id$
//
// FILENAME : admin_prune.php
// STARTED : Mon Jul 31, 2001
// COPYRIGHT : © 2001, 2003 phpBB Group
// WWW : http://www.phpbb.com/
// LICENCE : GPL vs2.0 [ see /docs/COPYING ]
//
// -------------------------------------------------------------
if (!empty($setmodules))
{
@ -44,19 +36,23 @@ if (!$auth->acl_get('a_prune'))
}
// Get the forum ID for pruning
$forum_id = (isset($_REQUEST['f'])) ? array_map('intval', $_REQUEST['f']) : 0;
$forum_id = (isset($_REQUEST['f'])) ? array_map('intval', $_REQUEST['f']) : array();
// Check for submit to be equal to Prune. If so then proceed with the pruning.
if (isset($_POST['submit']))
{
$prunedays = (isset($_POST['prunedays'])) ? intval($_POST['prunedays']) : 0;
$prune_posted = (isset($_POST['prune_days'])) ? intval($_POST['prune_days']) : 0;
$prune_viewed = (isset($_POST['prune_vieweddays'])) ? intval($_POST['prune_vieweddays']) : 0;
$prune_all = !$prune_posted && !$prune_viewed;
$prune_flags = 0;
$prune_flags += (!empty($_POST['prune_old_polls'])) ? 2 : 0;
$prune_flags += (!empty($_POST['prune_announce'])) ? 4 : 0;
$prune_flags += (!empty($_POST['prune_sticky'])) ? 8 : 0;
// Convert days to seconds for timestamp functions...
$prunedate = time() - ($prunedays * 86400);
$prunedate_posted = time() - ($prune_posted * 86400);
$prunedate_viewed = time() - ($prune_viewed * 86400);
adm_page_header($user->lang['PRUNE']);
@ -74,7 +70,7 @@ if (isset($_POST['submit']))
</tr>
<?php
$sql_forum = ($forum_id) ? ' AND forum_id IN (' . implode(', ', $forum_id) . ')' : '';
$sql_forum = (sizeof($forum_id)) ? ' AND forum_id IN (' . implode(', ', $forum_id) . ')' : '';
// Get a list of forum's or the data for the forum that we are pruning.
$sql = 'SELECT forum_id, forum_name
@ -87,12 +83,34 @@ if (isset($_POST['submit']))
if ($row = $db->sql_fetchrow($result))
{
$prune_ids = array();
$p_result['topics'] = 0;
$p_result['posts'] = 0;
$log_data = '';
do
{
if ($auth->acl_get('f_list', $row['forum_id']))
{
$p_result = prune($row['forum_id'], $prunedate, $prune_flags, FALSE);
if ($prune_all)
{
$p_result = prune($row['forum_id'], 'posted', time(), $prune_flags, false);
}
else
{
if ($prune_posted)
{
$return = prune($row['forum_id'], 'posted', $prunedate_posted, $prune_flags, false);
$p_result['topics'] += $return['topics'];
$p_result['posts'] += $return['posts'];
}
if ($prune_viewed)
{
$return = prune($row['forum_id'], 'viewed', $prunedate_viewed, $prune_flags, false);
$p_result['topics'] += $return['topics'];
$p_result['posts'] += $return['posts'];
}
}
$prune_ids[] = $row['forum_id'];
$row_class = ($row_class == 'row1') ? 'row2' : 'row1';
@ -207,6 +225,10 @@ else
<td class="row1"><?php echo $user->lang['PRUNE_NOT_POSTED']; ?></td>
<td class="row2"><input type="text" name="prune_days" size="4" /></td>
</tr>
<tr>
<td class="row1"><?php echo $user->lang['PRUNE_NOT_VIEWED']; ?></td>
<td class="row2"><input type="text" name="prune_vieweddays" size="4" /></td>
</tr>
<tr>
<td class="row1"><?php echo $user->lang['PRUNE_OLD_POLLS'] ?>: <br /><span class="gensmall"><?php echo $user->lang['PRUNE_OLD_POLLS_EXPLAIN']; ?></span></td>
<td class="row2"><input type="radio" name="prune_old_polls" value="1" /> <?php echo $user->lang['YES']; ?> &nbsp; <input type="radio" name="prune_old_polls" value="0" checked="checked" /> <?php echo $user->lang['NO']; ?></td>
@ -220,7 +242,7 @@ else
<td class="row2"><input type="radio" name="prune_sticky" value="1" /> <?php echo $user->lang['YES']; ?> &nbsp; <input type="radio" name="prune_sticky" value="0" checked="checked" /> <?php echo $user->lang['NO']; ?></td>
</tr>
<tr>
<td class="cat" colspan="2" align="center"><input type="submit" name="submit" value="<?php echo $user->lang['SUBMIT']; ?>" class="btnmain"></td>
<td class="cat" colspan="2" align="center"><?php echo $s_hidden_fields; ?><input type="submit" name="submit" value="<?php echo $user->lang['SUBMIT']; ?>" class="btnmain"></td>
</tr>
</table></form>

View File

@ -407,9 +407,9 @@ function delete_posts($where_type, $where_ids, $auto_sync = TRUE)
}
unset($table_ary);
$db->sql_transaction('commit');
delete_attachments($post_ids);
// delete_attachment($post_ids);
$db->sql_transaction('commit');
if ($auto_sync)
{
@ -438,6 +438,217 @@ function delete_posts($where_type, $where_ids, $auto_sync = TRUE)
return count($post_ids);
}
// Delete Attachments
function delete_attachments($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);
}
// TODO - Return number of deleted attachments
}
// All-encompasing sync function
//
// Usage:
@ -1120,7 +1331,7 @@ function verify_data($type, $fieldname, &$need_update, &$data)
}
}
function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true)
{
global $db;
@ -1136,10 +1347,18 @@ function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
$sql_and .= ' AND topic_type <> ' . POST_STICKY;
}
if ($prune_mode == 'posted')
{
$sql_and .= " AND topic_last_post_time < $prune_date";
}
if ($prune_mode == 'viewed')
{
$sql_and .= " AND topic_last_view_time < $prune_date";
}
$sql = 'SELECT topic_id
FROM ' . TOPICS_TABLE . "
WHERE forum_id $sql_forum
AND topic_last_post_time < $prune_date
AND poll_start = 0
$sql_and";
$result = $db->sql_query($sql);
@ -1158,7 +1377,6 @@ function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
WHERE forum_id $sql_forum
AND poll_start > 0
AND poll_last_vote < $prune_date
AND topic_last_post_time < $prune_date
$sql_and";
$result = $db->sql_query($sql);
@ -1175,7 +1393,7 @@ function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
}
// Function auto_prune(), this function now relies on passed vars
function auto_prune($forum_id, $prune_flags, $prune_days, $prune_freq)
function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_freq)
{
global $db;
@ -1189,7 +1407,7 @@ function auto_prune($forum_id, $prune_flags, $prune_days, $prune_freq)
$prune_date = time() - ($prune_days * 86400);
$next_prune = time() + ($prune_freq * 86400);
prune($forum_id, $prune_date, $prune_flags, true);
prune($forum_id, $prune_mode, $prune_date, $prune_flags, true);
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET prune_next = $next_prune

View File

@ -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)
{

View File

@ -741,7 +741,7 @@ class parse_message
}
else
{
delete_attachment($post_id, intval($this->attachment_data[$index]['attach_id']));
delete_attachments($post_id, intval($this->attachment_data[$index]['attach_id']));
}
unset($this->attachment_data[$index]);
}

View File

@ -1029,11 +1029,12 @@ $lang += array(
// Forum Pruning
$lang += array(
'FORUM_PRUNE_EXPLAIN' => 'This will delete any topic which has not been posted to within the number of days you select. If you do not enter a number then all topics will be deleted. It will not remove topics in which polls are still running nor will it remove announcements. You will need to remove these topics manually.',
'PRUNE_NOT_POSTED' => 'Days since last posted',
'PRUNE_NOT_POSTED' => 'Days since last posted',
'PRUNE_NOT_VIEWED' => 'Days since last viewed',
'TOPICS_PRUNED' => 'Topics pruned',
'POSTS_PRUNED' => 'Posts pruned',
'PRUNE_SUCCESS' => 'Pruning of forums was successful',
'TOPICS_PRUNED' => 'Topics pruned',
'POSTS_PRUNED' => 'Posts pruned',
'PRUNE_SUCCESS' => 'Pruning of forums was successful',
);
// Word censors

View File

@ -1760,8 +1760,8 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
'post_attachment' => (sizeof($filename_data['physical_filename'])) ? 1 : 0,
'bbcode_bitfield' => $data['bbcode_bitfield'],
'bbcode_uid' => $bbcode_uid,
'post_edit_locked' => $data['post_edit_locked']
));
'post_edit_locked' => $data['post_edit_locked'])
);
break;
}
@ -1783,11 +1783,11 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
if (!empty($poll['poll_options']))
{
$sql_data['topic']['sql'] += array(
$sql_data['topic']['sql'] = array_merge($sql_data['topic']['sql'], array(
'poll_title' => $poll['poll_title'],
'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
'poll_max_options' => $poll['poll_max_options'],
'poll_length' => $poll['poll_length'] * 86400
'poll_length' => $poll['poll_length'] * 86400)
);
}
@ -1846,8 +1846,8 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
$data['topic_id'] = $db->sql_nextid();
$sql_data['post']['sql'] += array(
'topic_id' => $data['topic_id']
$sql_data['post']['sql'] = array_merge($sql_data['post']['sql'], array(
'topic_id' => $data['topic_id'])
);
unset($sql_data['topic']['sql']);
}
@ -1857,8 +1857,8 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
{
if ($post_mode == 'reply')
{
$sql_data['post']['sql'] += array(
'topic_id' => $data['topic_id']
$sql_data['post']['sql'] = array_merge($sql_data['post']['sql'], array(
'topic_id' => $data['topic_id'])
);
}

View File

@ -176,7 +176,8 @@ if ($forum_data['forum_type'] == FORUM_POST)
if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
{
include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
auto_prune($forum_id, $forum_data['forum_flags'], $forum_data['prune_days'], $forum_data['prune_freq']);
// TODO - include viewed too... new row necessary for auto pruning...
auto_prune($forum_id, 'posted', $forum_data['forum_flags'], $forum_data['prune_days'], $forum_data['prune_freq']);
}
// Forum rules, subscription info and word censors