mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Update of pruning to add admin interface, and change error_die's to message_die's
git-svn-id: file:///svn/phpbb/trunk@683 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
58d05e84fb
commit
931fd9d642
5 changed files with 275 additions and 7 deletions
202
phpBB/admin/admin_forum_prune.php
Normal file
202
phpBB/admin/admin_forum_prune.php
Normal file
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* admin_forum_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.
|
||||
*
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* This file is for the setup of the auto_pruning and also will allow for
|
||||
* immediate forum pruning as well.
|
||||
***************************************************************************/
|
||||
//
|
||||
// Warning: Parts of this code were shamelessly stolen verbatim from Paul's
|
||||
// work on the Auth admin stuff :) JLH
|
||||
//
|
||||
|
||||
//
|
||||
//First we through in the modules stuff :)
|
||||
//
|
||||
|
||||
if( $setmodules == 1 )
|
||||
{
|
||||
$filename = basename(__FILE__);
|
||||
$module['Forums']['prune'] = $filename;
|
||||
|
||||
return;
|
||||
}
|
||||
//
|
||||
// Now include the relevant files.
|
||||
//
|
||||
$phpbb_root_path = "./../";
|
||||
include($phpbb_root_path . 'extension.inc');
|
||||
include($phpbb_root_path . 'common.'.$phpEx);
|
||||
include($phpbb_root_path . 'includes/prune.'.$phpEx);
|
||||
|
||||
//
|
||||
// Start session management
|
||||
//
|
||||
$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
|
||||
init_userprefs($userdata);
|
||||
//
|
||||
// End sessionmanagement
|
||||
//
|
||||
|
||||
//
|
||||
// Check user permissions
|
||||
//
|
||||
if( !$userdata['session_logged_in'] )
|
||||
{
|
||||
header("Location: ../login.$phpEx?forward_page=/admin/");
|
||||
}
|
||||
else if( $userdata['user_level'] != ADMIN )
|
||||
{
|
||||
message_die(GENERAL_MESSAGE, "You are not authorised to administer this board");
|
||||
}
|
||||
|
||||
//
|
||||
// Get the forum ID for pruning
|
||||
//
|
||||
if(isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]))
|
||||
{
|
||||
$forum_id = (isset($HTTP_POST_VARS[POST_FORUM_URL])) ? $HTTP_POST_VARS[POST_FORUM_URL] : $HTTP_GET_VARS[POST_FORUM_URL];
|
||||
if($forum_id == "ALL")
|
||||
{
|
||||
$forum_sql = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
$forum_sql = "AND forum_id = $forum_id";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($forum_id);
|
||||
$forum_sql = "";
|
||||
}
|
||||
//
|
||||
// Get a list of forum's or the data for the forum that we are pruning.
|
||||
//
|
||||
$sql = "SELECT f.*
|
||||
FROM " . FORUMS_TABLE . " f, " . CATEGORIES_TABLE . " c
|
||||
WHERE c.cat_id = f.cat_id
|
||||
$forum_sql
|
||||
ORDER BY c.cat_order ASC, f.forum_order ASC";
|
||||
$f_result = $db->sql_query($sql);
|
||||
|
||||
$forum_rows = $db->sql_fetchrowset($f_result);
|
||||
|
||||
//
|
||||
// Check for the submit variable.
|
||||
//
|
||||
if(isset($HTTP_GET_VARS['submit']) || isset($HTTP_POST_VARS['submit']))
|
||||
{
|
||||
$submit = (isset($HTTP_POST_VARS['submit'])) ? $HTTP_POST_VARS['submit'] : $HTTP_GET_VARS['submit'];
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($submit);
|
||||
}
|
||||
|
||||
//
|
||||
// Check for submit to be equal to Prune. If so then proceed with the pruning.
|
||||
//
|
||||
if($submit == "Prune")
|
||||
{
|
||||
$prunedays = $HTTP_POST_VARS['prunedays'];
|
||||
// Convert days to seconds for timestamp functions...
|
||||
$prunesecs = $prunedays * 1440 * 60;
|
||||
$prunedate = time() - $prunesecs;
|
||||
$template->set_filenames(array(
|
||||
"body" => "admin/forum_prune_result_body.tpl")
|
||||
);
|
||||
reset($forum_rows);
|
||||
while(list(, $forum_data) = each ($forum_rows))
|
||||
{
|
||||
$p_result = prune($forum_data['forum_id'], $prunedate);
|
||||
$template->assign_block_vars("prune_results", array(
|
||||
"FORUM_NAME" => $forum_data['forum_name'],
|
||||
"FORUM_TOPICS" => $p_result['topics'],
|
||||
"FORUM_POSTS" => $p_result['posts'])
|
||||
);
|
||||
}
|
||||
$template->assign_vars(array(
|
||||
"PRUNE_MSG" => "Pruning of forums was successful")
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If they haven't selected a forum for pruning yet then
|
||||
// display a select box to use for pruning.
|
||||
//
|
||||
if(empty($forum_id))
|
||||
{
|
||||
//
|
||||
// Output a selection table if no forum id has been specified.
|
||||
//
|
||||
$template->set_filenames(array(
|
||||
"body" => "admin/forum_prune_select_body.tpl")
|
||||
);
|
||||
$select_list = "<select name=\"" . POST_FORUM_URL . "\">\n";
|
||||
$select_list .= "<option value=\"\">Select a Forum</option>\n";
|
||||
$select_list .= "<option value=\"ALL\">All Forums</option>\n";
|
||||
for($i = 0; $i < count($forum_rows); $i++)
|
||||
{
|
||||
$select_list .= "<option value=\"" . $forum_rows[$i]['forum_id'] . "\">" . $forum_rows[$i]['forum_name'] . "</option>\n";
|
||||
}
|
||||
$select_list .= "</select>\n";
|
||||
//
|
||||
// Assign the template variables.
|
||||
//
|
||||
$template->assign_vars(array(
|
||||
"S_FORUMPRUNE_ACTION" => append_sid("admin_forum_prune.$phpEx"),
|
||||
"S_FORUMS_SELECT" => $select_list)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Output the form to retrieve Prune information.
|
||||
//
|
||||
$template->set_filenames(array(
|
||||
"body" => "admin/forum_prune_body.tpl")
|
||||
);
|
||||
|
||||
$forum_name = ($forum_id == "ALL") ? 'All Forums' : $forum_rows[0]['forum_name'];
|
||||
$prune_data = "Prune Topics that haven't been posted to in the last ";
|
||||
$prune_data .= "<input type=\"text\" name=\"prunedays\" size=\"4\"> Days.";
|
||||
$hidden_input = "<input type=\"hidden\" name=\"" . POST_FORUM_URL . "\" value=\"$forum_id\">";
|
||||
|
||||
//
|
||||
// Assign the template variables.
|
||||
//
|
||||
$template->assign_vars(array(
|
||||
"S_FORUMPRUNE_ACTION" => append_sid("admin_forum_prune.$phpEx"),
|
||||
"FORUM_NAME" => $forum_name,
|
||||
"S_PRUNE_DATA" => $prune_data,
|
||||
"S_HIDDEN_VARS" => $hidden_input)
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Actually output the page here.
|
||||
//
|
||||
$template->pparse("body");
|
||||
|
||||
include('page_footer_admin.'.$phpEx);
|
||||
|
||||
?>
|
|
@ -40,11 +40,11 @@ function prune($forum_id, $prune_date)
|
|||
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
|
||||
WHERE t.forum_id = $forum_id
|
||||
AND p.post_id = t.topic_last_post_id
|
||||
AND t.topic_type != " . POST_ANNOUNCE . "
|
||||
AND t.topic_type = " . POST_NORMAL . "
|
||||
AND p.post_time < $prune_date";
|
||||
if(!$result = $db->sql_query($sql))
|
||||
{
|
||||
error_die(SQL_QUERY, "Couldn't obtain list of topics to prune.", __LINE__, __FILE__);
|
||||
message_die(GENERAL_ERROR, "Couldn't obtain list of topics to prune.", __LINE__, __FILE__);
|
||||
} // End if(!$result...
|
||||
$pruned_topics = $db->sql_numrows($result);
|
||||
if($pruned_topics > 0)
|
||||
|
@ -66,14 +66,31 @@ function prune($forum_id, $prune_date)
|
|||
$prune_topic_sql .= ')';
|
||||
if(!$result = $db->sql_query($prune_posts_sql))
|
||||
{
|
||||
error_die(SQL_QUERY, "While Pruning: Couldn't remove affected posts.<br>$prune_posts_sql", __LINE__, __FILE__);
|
||||
message_die(GENERAL_ERROR, "While Pruning: Couldn't remove affected posts.<br>$prune_posts_sql", __LINE__, __FILE__);
|
||||
} // end if(!$result...
|
||||
$pruned_posts = $db->sql_affectedrows();
|
||||
if(!$result = $db->sql_query($prune_topic_sql))
|
||||
{
|
||||
error_die(SQL_QUERY, "While Pruning: Couldn't remove affected topics.", __LINE__, __FILE__);
|
||||
message_die(GENERAL_ERROR, "While Pruning: Couldn't remove affected topics.", __LINE__, __FILE__);
|
||||
} // end if(!$result...
|
||||
|
||||
//
|
||||
// Update forum info to reflect proper topic and post counts...
|
||||
//
|
||||
|
||||
$sql = "UPDATE " . FORUMS_TABLE . "
|
||||
SET forum_posts = (forum_posts - $pruned_posts), forum_topics = (forum_topics - $pruned_topics)
|
||||
WHERE forum_id = $forum_id";
|
||||
if(!$result = $db->sql_query($sql))
|
||||
{
|
||||
message_die(GENERAL_ERROR, "While Pruning: Couldn't update topic/post counts<br>" .mysql_error() , __LINE__, __FILE__);
|
||||
}
|
||||
|
||||
} // End if $prune_topics
|
||||
return $pruned_topics;
|
||||
$returnval = array (
|
||||
"topics" => $pruned_topics,
|
||||
"posts" => $pruned_posts);
|
||||
return $returnval;
|
||||
} // End function prune.
|
||||
|
||||
/***************************************************************************\
|
||||
|
@ -92,7 +109,7 @@ function auto_prune($forum_id = 0)
|
|||
|
||||
if(!$result = $db->sql_query($sql))
|
||||
{
|
||||
error_die(SQL_QUERY, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
|
||||
message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
|
||||
} // End if(!$result...
|
||||
while($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
|
@ -105,7 +122,7 @@ function auto_prune($forum_id = 0)
|
|||
WHERE forum_id = '$forum_id'";
|
||||
if(!$db->sql_query($sql))
|
||||
{
|
||||
error_die(SQL_QUERY, "Auto-Prune: Couldn't update forum table.", __LINE__, __FILE__);
|
||||
message_die(GENERAL_ERROR, "Auto-Prune: Couldn't update forum table.", __LINE__, __FILE__);
|
||||
} // End if(!$db->sql..
|
||||
} // End While Loop.
|
||||
} // End auto_prune function.
|
||||
|
|
17
phpBB/templates/PSO/admin/forum_prune_body.tpl
Normal file
17
phpBB/templates/PSO/admin/forum_prune_body.tpl
Normal file
|
@ -0,0 +1,17 @@
|
|||
<h1>Forum Pruning</h1>
|
||||
|
||||
<h2>Forum: {FORUM_NAME}</h2>
|
||||
|
||||
<div align="center"><table cellspacing="1" cellpadding="4" border="0">
|
||||
<tr><form method="post" action="{S_FORUMPRUNE_ACTION}">{S_HIDDEN_VARS}
|
||||
<td>{S_PRUNE_DATA}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><input type="submit" name="submit" value="Prune"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>Note: This will not prune announcements or sticky topics, these must be removed manually.</i></td>
|
||||
</tr>
|
||||
</form>
|
||||
</table></div>
|
||||
<br clear="all">
|
19
phpBB/templates/PSO/admin/forum_prune_result_body.tpl
Normal file
19
phpBB/templates/PSO/admin/forum_prune_result_body.tpl
Normal file
|
@ -0,0 +1,19 @@
|
|||
<h1>Forum Pruning</h1>
|
||||
|
||||
<p>Here are the results from your forum pruning:</p>
|
||||
|
||||
<div align="center"><table cellspacing="1" cellpadding="4" border="0">
|
||||
<tr>
|
||||
<th>FORUM NAME</th>
|
||||
<th>TOPICS PRUNED</th>
|
||||
<th>POSTS PRUNED</th>
|
||||
</tr>
|
||||
<!-- BEGIN prune_results -->
|
||||
<tr>
|
||||
<td class="row1" align="center">{prune_results.FORUM_NAME}</td>
|
||||
<td class="row1" align="center">{prune_results.FORUM_TOPICS}</td>
|
||||
<td class="row1" align="center">{prune_results.FORUM_POSTS}</td>
|
||||
</tr>
|
||||
<!-- END prune_results -->
|
||||
</table></div>
|
||||
<br clear="all">
|
13
phpBB/templates/PSO/admin/forum_prune_select_body.tpl
Normal file
13
phpBB/templates/PSO/admin/forum_prune_select_body.tpl
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
<div align="center"><h1>Forum Pruning</h1>
|
||||
|
||||
<table cellspacing="1" cellpadding="4" border="0">
|
||||
<tr>
|
||||
<th bgcolor="#CCCCCC">Select a Forum</th>
|
||||
</tr>
|
||||
<tr><form method="get" action="{S_FORUMPRUNE_ACTION}">
|
||||
<td class="row1" align="center">{S_FORUMS_SELECT} <input type="submit" value="Select"> </td>
|
||||
</form></tr>
|
||||
</table></div>
|
||||
|
||||
<br clear="all">
|
Loading…
Add table
Reference in a new issue