0
|
1 |
<?php
|
|
2 |
/***********************************************************************
|
|
3 |
|
|
4 |
Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
|
|
5 |
|
|
6 |
This file is part of PunBB.
|
|
7 |
|
|
8 |
PunBB is free software; you can redistribute it and/or modify it
|
|
9 |
under the terms of the GNU General Public License as published
|
|
10 |
by the Free Software Foundation; either version 2 of the License,
|
|
11 |
or (at your option) any later version.
|
|
12 |
|
|
13 |
PunBB is distributed in the hope that it will be useful, but
|
|
14 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
GNU General Public License for more details.
|
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License
|
|
19 |
along with this program; if not, write to the Free Software
|
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
21 |
MA 02111-1307 USA
|
|
22 |
|
|
23 |
************************************************************************/
|
|
24 |
|
|
25 |
|
|
26 |
// Tell header.php to use the admin template
|
|
27 |
define('PUN_ADMIN_CONSOLE', 1);
|
|
28 |
|
|
29 |
define('PUN_ROOT', './');
|
|
30 |
require PUN_ROOT.'include/common.php';
|
|
31 |
require PUN_ROOT.'include/common_admin.php';
|
|
32 |
|
|
33 |
|
|
34 |
if ($pun_user['g_id'] > PUN_ADMIN)
|
|
35 |
message($lang_common['No permission']);
|
|
36 |
|
|
37 |
|
|
38 |
if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply']))
|
|
39 |
{
|
|
40 |
if (isset($_POST['prune_comply']))
|
|
41 |
{
|
|
42 |
confirm_referrer('admin_prune.php');
|
|
43 |
|
|
44 |
$prune_from = $_POST['prune_from'];
|
|
45 |
$prune_days = intval($_POST['prune_days']);
|
|
46 |
$prune_date = ($prune_days) ? time() - ($prune_days*86400) : -1;
|
|
47 |
|
|
48 |
@set_time_limit(0);
|
|
49 |
|
|
50 |
if ($prune_from == 'all')
|
|
51 |
{
|
|
52 |
$result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
|
|
53 |
$num_forums = $db->num_rows($result);
|
|
54 |
|
|
55 |
for ($i = 0; $i < $num_forums; ++$i)
|
|
56 |
{
|
|
57 |
$fid = $db->result($result, $i);
|
|
58 |
|
|
59 |
prune($fid, $_POST['prune_sticky'], $prune_date);
|
|
60 |
update_forum($fid);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
else
|
|
64 |
{
|
|
65 |
$prune_from = intval($prune_from);
|
|
66 |
prune($prune_from, $_POST['prune_sticky'], $prune_date);
|
|
67 |
update_forum($prune_from);
|
|
68 |
}
|
|
69 |
|
|
70 |
// Locate any "orphaned redirect topics" and delete them
|
|
71 |
$result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
|
|
72 |
$num_orphans = $db->num_rows($result);
|
|
73 |
|
|
74 |
if ($num_orphans)
|
|
75 |
{
|
|
76 |
for ($i = 0; $i < $num_orphans; ++$i)
|
|
77 |
$orphans[] = $db->result($result, $i);
|
|
78 |
|
|
79 |
$db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
|
|
80 |
}
|
|
81 |
|
|
82 |
redirect('admin_prune.php', 'Posts pruned. Redirecting …');
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
$prune_days = $_POST['req_prune_days'];
|
|
87 |
if (!@preg_match('#^\d+$#', $prune_days))
|
|
88 |
message('Days to prune must be a positive integer.');
|
|
89 |
|
|
90 |
$prune_date = time() - ($prune_days*86400);
|
|
91 |
$prune_from = $_POST['prune_from'];
|
|
92 |
|
|
93 |
// Concatenate together the query for counting number or topics to prune
|
|
94 |
$sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
|
|
95 |
|
|
96 |
if ($_POST['prune_sticky'] == '0')
|
|
97 |
$sql .= ' AND sticky=\'0\'';
|
|
98 |
|
|
99 |
if ($prune_from != 'all')
|
|
100 |
{
|
|
101 |
$prune_from = intval($prune_from);
|
|
102 |
$sql .= ' AND forum_id='.$prune_from;
|
|
103 |
|
|
104 |
// Fetch the forum name (just for cosmetic reasons)
|
|
105 |
$result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
|
|
106 |
$forum = '"'.pun_htmlspecialchars($db->result($result)).'"';
|
|
107 |
}
|
|
108 |
else
|
|
109 |
$forum = 'all forums';
|
|
110 |
|
|
111 |
$result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error());
|
|
112 |
$num_topics = $db->result($result);
|
|
113 |
|
|
114 |
if (!$num_topics)
|
|
115 |
message('There are no topics that are '.$prune_days.' days old. Please decrease the value of "Days old" and try again.');
|
|
116 |
|
|
117 |
|
|
118 |
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Prune';
|
|
119 |
require PUN_ROOT.'header.php';
|
|
120 |
|
|
121 |
generate_admin_menu('prune');
|
|
122 |
|
|
123 |
?>
|
|
124 |
<div class="blockform">
|
|
125 |
<h2><span>Prune</span></h2>
|
|
126 |
<div class="box">
|
|
127 |
<form method="post" action="admin_prune.php?action=foo">
|
|
128 |
<div class="inform">
|
|
129 |
<input type="hidden" name="prune_days" value="<?php echo $prune_days ?>" />
|
|
130 |
<input type="hidden" name="prune_sticky" value="<?php echo $_POST['prune_sticky'] ?>" />
|
|
131 |
<input type="hidden" name="prune_from" value="<?php echo $prune_from ?>" />
|
|
132 |
<fieldset>
|
|
133 |
<legend>Confirm prune posts</legend>
|
|
134 |
<div class="infldset">
|
|
135 |
<p>Are you sure that you want to prune all topics older than <?php echo $prune_days ?> days from <?php echo $forum ?>? (<?php echo $num_topics ?> topics)</p>
|
|
136 |
<p>WARNING! Pruning posts deletes them permanently.</p>
|
|
137 |
</div>
|
|
138 |
</fieldset>
|
|
139 |
</div>
|
|
140 |
<p><input type="submit" name="prune_comply" value="Prune" /><a href="javascript:history.go(-1)">Go back</a></p>
|
|
141 |
</form>
|
|
142 |
</div>
|
|
143 |
</div>
|
|
144 |
<div class="clearer"></div>
|
|
145 |
</div>
|
|
146 |
<?php
|
|
147 |
|
|
148 |
require PUN_ROOT.'footer.php';
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
else
|
|
153 |
{
|
|
154 |
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Prune';
|
|
155 |
$required_fields = array('req_prune_days' => 'Days old');
|
|
156 |
$focus_element = array('prune', 'req_prune_days');
|
|
157 |
require PUN_ROOT.'header.php';
|
|
158 |
|
|
159 |
generate_admin_menu('prune');
|
|
160 |
|
|
161 |
?>
|
|
162 |
<div class="blockform">
|
|
163 |
<h2><span>Prune</span></h2>
|
|
164 |
<div class="box">
|
|
165 |
<form id="prune" method="post" action="admin_prune.php?action=foo" onsubmit="return process_form(this)">
|
|
166 |
<div class="inform">
|
|
167 |
<input type="hidden" name="form_sent" value="1" />
|
|
168 |
<fieldset>
|
|
169 |
<legend>Prune old posts</legend>
|
|
170 |
<div class="infldset">
|
|
171 |
<table class="aligntop" cellspacing="0">
|
|
172 |
<tr>
|
|
173 |
<th scope="row">Days old</th>
|
|
174 |
<td>
|
|
175 |
<input type="text" name="req_prune_days" size="3" maxlength="3" tabindex="1" />
|
|
176 |
<span>The number of days "old" a topic must be to be pruned. E.g. if you were to enter 30, every topic that didn't contain a post dated less than 30 days old would be deleted.</span>
|
|
177 |
</td>
|
|
178 |
</tr>
|
|
179 |
<tr>
|
|
180 |
<th scope="row">Prune sticky topics</th>
|
|
181 |
<td>
|
|
182 |
<input type="radio" name="prune_sticky" value="1" tabindex="2" checked="checked" /> <strong>Yes</strong> <input type="radio" name="prune_sticky" value="0" /> <strong>No</strong>
|
|
183 |
<span>When enabled sticky topics will also be pruned.</span>
|
|
184 |
</td>
|
|
185 |
</tr>
|
|
186 |
<tr>
|
|
187 |
<th scope="row">Prune from forum</th>
|
|
188 |
<td>
|
|
189 |
<select name="prune_from" tabindex="3">
|
|
190 |
<option value="all">All forums</option>
|
|
191 |
<?php
|
|
192 |
|
|
193 |
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
|
|
194 |
|
|
195 |
$cur_category = 0;
|
|
196 |
while ($forum = $db->fetch_assoc($result))
|
|
197 |
{
|
|
198 |
if ($forum['cid'] != $cur_category) // Are we still in the same category?
|
|
199 |
{
|
|
200 |
if ($cur_category)
|
|
201 |
echo "\t\t\t\t\t\t\t\t\t\t\t".'</optgroup>'."\n";
|
|
202 |
|
|
203 |
echo "\t\t\t\t\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($forum['cat_name']).'">'."\n";
|
|
204 |
$cur_category = $forum['cid'];
|
|
205 |
}
|
|
206 |
|
|
207 |
echo "\t\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$forum['fid'].'">'.pun_htmlspecialchars($forum['forum_name']).'</option>'."\n";
|
|
208 |
}
|
|
209 |
|
|
210 |
?>
|
|
211 |
</optgroup>
|
|
212 |
</select>
|
|
213 |
<span>The forum from which you want to prune posts.</span>
|
|
214 |
</td>
|
|
215 |
</tr>
|
|
216 |
</table>
|
|
217 |
<p class="topspace">Use this feature with caution. Pruned posts can <strong>never</strong> be recovered. For best performance you should put the forum in maintenance mode during pruning.</p>
|
|
218 |
<div class="fsetsubmit"><input type="submit" name="prune" value="Prune" tabindex="5" /></div>
|
|
219 |
</div>
|
|
220 |
</fieldset>
|
|
221 |
</div>
|
|
222 |
</form>
|
|
223 |
</div>
|
|
224 |
</div>
|
|
225 |
<div class="clearer"></div>
|
|
226 |
</div>
|
|
227 |
<?php
|
|
228 |
|
|
229 |
require PUN_ROOT.'footer.php';
|
|
230 |
}
|