/
common_admin.php
149 lines (116 loc) · 4.67 KB
/
common_admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Copyright (C) 2008-2012 FluxBB
* based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Attempt to load the admin_common language file
$lang->load('admin_common');
//
// Display the admin navigation menu
//
function generate_admin_menu($page = '')
{
global $pun_config, $pun_user, $lang;
$is_admin = $pun_user['g_id'] == PUN_ADMIN ? true : false;
?>
<div id="adminconsole" class="block2col">
<div id="adminmenu" class="blockmenu">
<h2><span><?php echo $lang->t('Moderator menu') ?></span></h2>
<div class="box">
<div class="inbox">
<ul>
<li<?php if ($page == 'index') echo ' class="isactive"'; ?>><a href="admin_index.php"><?php echo $lang->t('Index') ?></a></li>
<li<?php if ($page == 'users') echo ' class="isactive"'; ?>><a href="admin_users.php"><?php echo $lang->t('Users') ?></a></li>
<?php if ($is_admin || $pun_user['g_mod_ban_users'] == '1'): ?> <li<?php if ($page == 'bans') echo ' class="isactive"'; ?>><a href="admin_bans.php"><?php echo $lang->t('Bans') ?></a></li>
<?php endif; if ($is_admin || $pun_config['o_report_method'] == '0' || $pun_config['o_report_method'] == '2'): ?> <li<?php if ($page == 'reports') echo ' class="isactive"'; ?>><a href="admin_reports.php"><?php echo $lang->t('Reports') ?></a></li>
<?php endif; ?> </ul>
</div>
</div>
<?php
if ($is_admin)
{
?>
<h2 class="block2"><span><?php echo $lang->t('Admin menu') ?></span></h2>
<div class="box">
<div class="inbox">
<ul>
<li<?php if ($page == 'options') echo ' class="isactive"'; ?>><a href="admin_options.php"><?php echo $lang->t('Options') ?></a></li>
<li<?php if ($page == 'permissions') echo ' class="isactive"'; ?>><a href="admin_permissions.php"><?php echo $lang->t('Permissions') ?></a></li>
<li<?php if ($page == 'categories') echo ' class="isactive"'; ?>><a href="admin_categories.php"><?php echo $lang->t('Categories') ?></a></li>
<li<?php if ($page == 'forums') echo ' class="isactive"'; ?>><a href="admin_forums.php"><?php echo $lang->t('Forums') ?></a></li>
<li<?php if ($page == 'groups') echo ' class="isactive"'; ?>><a href="admin_groups.php"><?php echo $lang->t('User groups') ?></a></li>
<li<?php if ($page == 'censoring') echo ' class="isactive"'; ?>><a href="admin_censoring.php"><?php echo $lang->t('Censoring') ?></a></li>
<li<?php if ($page == 'ranks') echo ' class="isactive"'; ?>><a href="admin_ranks.php"><?php echo $lang->t('Ranks') ?></a></li>
<li<?php if ($page == 'maintenance') echo ' class="isactive"'; ?>><a href="admin_maintenance.php"><?php echo $lang->t('Maintenance') ?></a></li>
</ul>
</div>
</div>
<?php
}
?>
</div>
<?php
}
//
// Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted)
//
function prune($forum_id, $prune_sticky, $prune_date)
{
global $db;
// Fetch topics to prune
$query = $db->select(array('id' => 't.id'), 'topics AS t');
$query->where = 't.forum_id = :forum_id';
$params = array(':forum_id' => $forum_id);
if ($prune_date != -1)
{
$query->where .= ' AND t.last_post < :prune_date';
$params[':prune_date'] = $prune_date;
}
if (!$prune_sticky)
$query->where .= ' AND t.sticky = 0';
$result = $query->run($params);
$topic_ids = array();
foreach ($result as $row)
$topic_ids[] = $row['id'];
unset($query, $params, $result);
if (!empty($topic_ids))
{
// Fetch posts to prune
$query = $db->select(array('id' => 'p.id'), 'posts AS p');
$query->where = 'p.topic_id IN :topic_ids';
$params = array(':topic_ids' => $topic_ids);
$result = $query->run($params);
$post_ids = array();
foreach ($result as $row)
$post_ids[] = $row['id'];
unset($query, $params, $result);
if (!empty($post_ids))
{
// Delete topics
$query = $db->delete('topics');
$query->where = 'id IN :topic_ids';
$params = array(':topic_ids' => $topic_ids);
$query->run($params);
unset($query, $params);
// Delete subscriptions
$query = $db->delete('topic_subscriptions');
$query->where = 'topic_id IN :topic_ids';
$params = array(':topic_ids' => $topic_ids);
$query->run($params);
unset($query, $params);
// Delete posts
$query = $db->delete('posts');
$query->where = 'id IN :post_ids';
$params = array(':post_ids' => $post_ids);
$query->run($params);
unset($query, $params);
// We removed a bunch of posts, so now we have to update the search index
require_once PUN_ROOT.'include/search_idx.php';
strip_search_index($post_ids);
}
}
}