|
1 <?php |
|
2 /*********************************************************************** |
|
3 |
|
4 Copyright (C) 2002-2008 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 // if (!defined('PUN_ROOT')) |
|
27 // define('PUN_ROOT', '../'); |
|
28 // require PUN_ROOT.'include/common.php'; |
|
29 require PUN_ROOT.'include/common_admin.php'; |
|
30 |
|
31 // import globals (I really hope this isn't dangerous) |
|
32 foreach ( $GLOBALS as $key => $_ ) |
|
33 { |
|
34 $$key =& $GLOBALS[$key]; |
|
35 } |
|
36 |
|
37 ($hook = get_hook('apr_start')) ? eval($hook) : null; |
|
38 |
|
39 if ($session->user_level < USER_LEVEL_ADMIN) |
|
40 message($lang_common['No permission']); |
|
41 |
|
42 // Load the admin.php language file |
|
43 require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php'; |
|
44 $GLOBALS['lang_admin'] = $lang_admin; |
|
45 |
|
46 |
|
47 if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply'])) |
|
48 { |
|
49 if (isset($_POST['prune_comply'])) |
|
50 { |
|
51 $prune_from = $_POST['prune_from']; |
|
52 $prune_days = intval($_POST['prune_days']); |
|
53 $prune_date = ($prune_days) ? time() - ($prune_days*86400) : -1; |
|
54 |
|
55 ($hook = get_hook('apr_prune_comply_form_submitted')) ? eval($hook) : null; |
|
56 |
|
57 @set_time_limit(0); |
|
58 |
|
59 if ($prune_from == 'all') |
|
60 { |
|
61 $query = array( |
|
62 'SELECT' => 'f.id', |
|
63 'FROM' => 'forums AS f' |
|
64 ); |
|
65 |
|
66 ($hook = get_hook('apr_qr_get_all_forums')) ? eval($hook) : null; |
|
67 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
68 $num_forums = $pun_db->num_rows($result); |
|
69 |
|
70 for ($i = 0; $i < $num_forums; ++$i) |
|
71 { |
|
72 $fid = $pun_db->result($result, $i); |
|
73 |
|
74 prune($fid, $_POST['prune_sticky'], $prune_date); |
|
75 sync_forum($fid); |
|
76 } |
|
77 } |
|
78 else |
|
79 { |
|
80 $prune_from = intval($prune_from); |
|
81 prune($prune_from, $_POST['prune_sticky'], $prune_date); |
|
82 sync_forum($prune_from); |
|
83 } |
|
84 |
|
85 delete_orphans(); |
|
86 |
|
87 pun_redirect(pun_link($pun_url['admin_prune']), 'Posts pruned. Redirecting …'); |
|
88 } |
|
89 |
|
90 |
|
91 $prune_days = intval($_POST['req_prune_days']); |
|
92 if ($prune_days < 0) |
|
93 message($lang_admin['Days to prune message']); |
|
94 |
|
95 $prune_date = time() - ($prune_days*86400); |
|
96 $prune_from = $_POST['prune_from']; |
|
97 |
|
98 if ($prune_from != 'all') |
|
99 { |
|
100 $prune_from = intval($prune_from); |
|
101 |
|
102 // Fetch the forum name (just for cosmetic reasons) |
|
103 $query = array( |
|
104 'SELECT' => 'f.forum_name', |
|
105 'FROM' => 'forums AS f', |
|
106 'WHERE' => 'f.id='.$prune_from |
|
107 ); |
|
108 |
|
109 ($hook = get_hook('apr_qr_get_forum_name')) ? eval($hook) : null; |
|
110 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
111 $forum = htmlspecialchars($pun_db->result($result)); |
|
112 } |
|
113 else |
|
114 $forum = 'all forums'; |
|
115 |
|
116 // Count the number of topics to prune |
|
117 $query = array( |
|
118 'SELECT' => 'COUNT(t.id)', |
|
119 'FROM' => 'topics AS t', |
|
120 'WHERE' => 't.last_post<'.$prune_date.' AND t.moved_to IS NULL' |
|
121 ); |
|
122 |
|
123 if ($prune_from != 'all') |
|
124 $query['WHERE'] .= ' AND t.forum_id='.$prune_from; |
|
125 if (!isset($_POST['prune_sticky'])) |
|
126 $query['WHERE'] .= ' AND t.sticky=0'; |
|
127 |
|
128 ($hook = get_hook('apr_qr_get_topic_count')) ? eval($hook) : null; |
|
129 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
130 $num_topics = $pun_db->result($result); |
|
131 |
|
132 if (!$num_topics) |
|
133 message($lang_admin['No days old message']); |
|
134 |
|
135 |
|
136 // Setup breadcrumbs |
|
137 $pun_page['crumbs'] = array( |
|
138 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
139 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
140 array($lang_admin['Prune topics'], pun_link($pun_url['admin_prune'])), |
|
141 $lang_admin['Confirm prune heading'] |
|
142 ); |
|
143 |
|
144 ($hook = get_hook('apr_prune_comply_pre_header_load')) ? eval($hook) : null; |
|
145 |
|
146 define('PUN_PAGE_SECTION', 'management'); |
|
147 define('PUN_PAGE', 'admin-prune'); |
|
148 require PUN_ROOT.'header.php'; |
|
149 |
|
150 ?> |
|
151 <div id="pun-main" class="main sectioned admin"> |
|
152 |
|
153 |
|
154 <?php echo generate_admin_menu(); ?> |
|
155 |
|
156 <div class="main-head"> |
|
157 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
158 </div> |
|
159 |
|
160 <div class="main-content frm"> |
|
161 <div class="frm-head"> |
|
162 <h2><span><?php printf($lang_admin['Prune details head'], ($forum == 'all forums') ? $lang_admin['All forums'] : $forum ) ?></span></h2> |
|
163 </div> |
|
164 <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_prune']) ?>&action=foo"> |
|
165 <div class="hidden"> |
|
166 <input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_prune']).'&action=foo') ?>" /> |
|
167 <input type="hidden" name="prune_days" value="<?php echo $prune_days ?>" /> |
|
168 <input type="hidden" name="prune_sticky" value="<?php echo intval($_POST['prune_sticky']) ?>" /> |
|
169 <input type="hidden" name="prune_from" value="<?php echo $prune_from ?>" /> |
|
170 </div> |
|
171 <div class="frm-info"> |
|
172 <p class="warn"><span><?php printf($lang_admin['Prune topics info 1'], $num_topics, isset($_POST['prune_sticky']) ? ' ('.$lang_admin['Include sticky'].')' : '') ?></span></p> |
|
173 <p class="warn"><span><?php printf($lang_admin['Prune topics info 2'], $prune_days) ?></span></p> |
|
174 </div> |
|
175 <?php ($hook = get_hook('apr_prune_comply_pre_buttons')) ? eval($hook) : null; ?> |
|
176 <div class="frm-buttons"> |
|
177 <span class="submit"><input type="submit" name="prune_comply" value="<?php echo $lang_admin['Prune topics'] ?>" /></span> |
|
178 </div> |
|
179 </form> |
|
180 </div> |
|
181 |
|
182 </div> |
|
183 <?php |
|
184 |
|
185 require PUN_ROOT.'footer.php'; |
|
186 } |
|
187 |
|
188 |
|
189 else |
|
190 { |
|
191 // Setup form |
|
192 $pun_page['set_count'] = $pun_page['fld_count'] = 0; |
|
193 |
|
194 // Setup breadcrumbs |
|
195 $pun_page['crumbs'] = array( |
|
196 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
197 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
198 $lang_admin['Prune topics'] |
|
199 ); |
|
200 |
|
201 ($hook = get_hook('apr_pre_header_load')) ? eval($hook) : null; |
|
202 |
|
203 define('PUN_PAGE_SECTION', 'management'); |
|
204 define('PUN_PAGE', 'admin-prune'); |
|
205 require PUN_ROOT.'header.php'; |
|
206 |
|
207 ?> |
|
208 <div id="pun-main" class="main sectioned admin"> |
|
209 |
|
210 <?php echo generate_admin_menu(); ?> |
|
211 |
|
212 <div class="main-head"> |
|
213 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
214 </div> |
|
215 |
|
216 <div class="main-content frm"> |
|
217 <div class="frm-head"> |
|
218 <h2 class="prefix"><span><?php echo $lang_admin['Prune settings head'] ?></span></h2> |
|
219 </div> |
|
220 <div class="frm-info"> |
|
221 <p><?php echo $lang_admin['Prune intro'] ?></p> |
|
222 <p class="important"><?php echo $lang_admin['Prune caution'] ?></p> |
|
223 </div> |
|
224 <div id="req-msg" class="frm-warn"> |
|
225 <p class="important"><?php printf($lang_common['Required warn'], '<em class="req-text">'.$lang_common['Required'].'</em>') ?></p> |
|
226 </div> |
|
227 <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_prune']) ?>&action=foo"> |
|
228 <div class="hidden"> |
|
229 <input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_prune']).'&action=foo') ?>" /> |
|
230 <input type="hidden" name="form_sent" value="1" /> |
|
231 </div> |
|
232 <?php ($hook = get_hook('apr_pre_prune_fieldset')) ? eval($hook) : null; ?> |
|
233 <fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>"> |
|
234 <legend class="frm-legend"><span><?php echo $lang_admin['Prune legend'] ?></span></legend> |
|
235 <?php ($hook = get_hook('apr_pre_prune_from')) ? eval($hook) : null; ?> |
|
236 <div class="frm-fld select"> |
|
237 <label for="fld<?php echo ++$pun_page['fld_count'] ?>"> |
|
238 <span class="fld-label"><?php echo $lang_admin['Prune from'] ?></span><br /> |
|
239 <span class="fld-input"><select id="fld<?php echo $pun_page['fld_count'] ?>" name="prune_from"> |
|
240 <option value="all"><?php echo $lang_admin['All forums'] ?></option> |
|
241 <?php |
|
242 |
|
243 $query = array( |
|
244 'SELECT' => 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name', |
|
245 'FROM' => 'categories AS c', |
|
246 'JOINS' => array( |
|
247 array( |
|
248 'INNER JOIN' => 'forums AS f', |
|
249 'ON' => 'c.id=f.cat_id' |
|
250 ) |
|
251 ), |
|
252 'WHERE' => 'f.redirect_url IS NULL', |
|
253 'ORDER BY' => 'c.disp_position, c.id, f.disp_position' |
|
254 ); |
|
255 |
|
256 ($hook = get_hook('apr_qr_get_forum_list')) ? eval($hook) : null; |
|
257 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
258 |
|
259 $cur_category = 0; |
|
260 while ($forum = $pun_db->fetch_assoc($result)) |
|
261 { |
|
262 if ($forum['cid'] != $cur_category) // Are we still in the same category? |
|
263 { |
|
264 if ($cur_category) |
|
265 echo "\t\t\t\t\t\t\t\t".'</optgroup>'."\n"; |
|
266 |
|
267 echo "\t\t\t\t\t\t\t\t".'<optgroup label="'.htmlspecialchars($forum['cat_name']).'">'."\n"; |
|
268 $cur_category = $forum['cid']; |
|
269 } |
|
270 |
|
271 echo "\t\t\t\t\t\t\t\t\t".'<option value="'.$forum['fid'].'">'.htmlspecialchars($forum['forum_name']).'</option>'."\n"; |
|
272 } |
|
273 |
|
274 ?> |
|
275 </optgroup> |
|
276 </select></span> |
|
277 </label> |
|
278 </div> |
|
279 <div class="frm-fld text"> |
|
280 <label for="fld<?php echo ++$pun_page['fld_count'] ?>"> |
|
281 <span class="fld-label"><?php echo $lang_admin['Days old'] ?></span><br /> |
|
282 <span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="req_prune_days" size="4" maxlength="4" /></span> |
|
283 <em class="req-text"><?php echo $lang_common['Required'] ?></em> |
|
284 </label> |
|
285 </div> |
|
286 <div class="radbox checkbox"> |
|
287 <label for="fld<?php echo ++$pun_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_admin['Prune sticky'] ?></span><br /><input type="checkbox" id="fld<?php echo $pun_page['fld_count'] ?>" name="prune_sticky" value="1" checked="checked" /> <?php echo $lang_admin['Prune sticky enable'] ?></label> |
|
288 </div> |
|
289 <?php ($hook = get_hook('apr_prune_end')) ? eval($hook) : null; ?> |
|
290 </fieldset> |
|
291 <?php ($hook = get_hook('apr_pre_buttons')) ? eval($hook) : null; ?> |
|
292 <div class="frm-buttons"> |
|
293 <span class="submit"><input type="submit" name="prune" value="<?php echo $lang_admin['Prune topics'] ?>" /></span> |
|
294 </div> |
|
295 </form> |
|
296 </div> |
|
297 |
|
298 </div> |
|
299 <?php |
|
300 |
|
301 require PUN_ROOT.'footer.php'; |
|
302 } |