From db2a73d2f07cd04e787c0b9ecc5533e4895a400b Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 7 Sep 2003 17:16:12 +0000 Subject: [PATCH] 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 --- phpBB/adm/admin_prune.php | 72 ++++++--- phpBB/includes/functions_admin.php | 232 ++++++++++++++++++++++++++- phpBB/includes/functions_posting.php | 209 ------------------------ phpBB/includes/message_parser.php | 2 +- phpBB/language/en/lang_admin.php | 9 +- phpBB/posting.php | 16 +- phpBB/viewforum.php | 3 +- 7 files changed, 288 insertions(+), 255 deletions(-) diff --git a/phpBB/adm/admin_prune.php b/phpBB/adm/admin_prune.php index 2663cad24a..5a469f9a64 100644 --- a/phpBB/adm/admin_prune.php +++ b/phpBB/adm/admin_prune.php @@ -1,23 +1,15 @@ 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'])) 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 lang['PRUNE_NOT_POSTED']; ?> + + lang['PRUNE_NOT_VIEWED']; ?> + + lang['PRUNE_OLD_POLLS'] ?>:
lang['PRUNE_OLD_POLLS_EXPLAIN']; ?> lang['YES']; ?>   lang['NO']; ?> @@ -220,7 +242,7 @@ else lang['YES']; ?>   lang['NO']; ?> - + diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index d4da25127b..25439ac4d9 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -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 diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 858fd4d3ec..8bfd9b72bb 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -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) { diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 817f0befa7..6617ddae74 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -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]); } diff --git a/phpBB/language/en/lang_admin.php b/phpBB/language/en/lang_admin.php index eaffb8bb76..9223a75fd6 100644 --- a/phpBB/language/en/lang_admin.php +++ b/phpBB/language/en/lang_admin.php @@ -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 diff --git a/phpBB/posting.php b/phpBB/posting.php index 094a2caabc..dc92ad4a85 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -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']) ); } diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index ec51f8e118..5f25b89dbb 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -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