punbb/include/common_admin.php
author Dan
Thu, 12 Jul 2007 01:04:01 -0400
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
permissions -rw-r--r--
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
// Make sure no one attempts to run this script "directly"
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
if (!defined('PUN'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
// Display the admin navigation menu
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
function generate_admin_menu($page = '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
	global $pun_config, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
	$is_admin = $pun_user['g_id'] == PUN_ADMIN ? true : false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
<div id="adminconsole" class="block2col">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
	<div id="adminmenu" class="blockmenu">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
		<h2><span><?php echo ($is_admin) ? 'Admin' : 'Moderator' ?> menu</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
			<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
				<ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
					<li<?php if ($page == 'index') echo ' class="isactive"'; ?>><a href="admin_index.php">Index</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
<?php if ($is_admin): ?>					<li<?php if ($page == 'categories') echo ' class="isactive"'; ?>><a href="admin_categories.php">Categories</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
<?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'forums') echo ' class="isactive"'; ?>><a href="admin_forums.php">Forums</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
<?php endif; ?>					<li<?php if ($page == 'users') echo ' class="isactive"'; ?>><a href="admin_users.php">Users</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
<?php if ($is_admin): ?>					<li<?php if ($page == 'groups') echo ' class="isactive"'; ?>><a href="admin_groups.php">User groups</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
<?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'options') echo ' class="isactive"'; ?>><a href="admin_options.php">Options</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
<?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'permissions') echo ' class="isactive"'; ?>><a href="admin_permissions.php">Permissions</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    53
<?php endif; ?>					<li<?php if ($page == 'censoring') echo ' class="isactive"'; ?>><a href="admin_censoring.php">Censoring</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    54
<?php if ($is_admin): ?>					<li<?php if ($page == 'ranks') echo ' class="isactive"'; ?>><a href="admin_ranks.php">Ranks</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
<?php endif; ?><?php if ($is_admin || $pun_config['p_mod_ban_users'] == '1'): ?>					<li<?php if ($page == 'bans') echo ' class="isactive"'; ?>><a href="admin_bans.php">Bans</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
<?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'prune') echo ' class="isactive"'; ?>><a href="admin_prune.php">Prune</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
<?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'maintenance') echo ' class="isactive"'; ?>><a href="admin_maintenance.php">Maintenance</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
<?php endif; ?>					<li<?php if ($page == 'reports') echo ' class="isactive"'; ?>><a href="admin_reports.php">Reports</a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
				</ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
	// See if there are any plugins
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
	$plugins = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
	$d = dir(PUN_ROOT.'plugins');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
	while (($entry = $d->read()) !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
		$prefix = substr($entry, 0, strpos($entry, '_'));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
		$suffix = substr($entry, strlen($entry) - 4);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
		if ($suffix == '.php' && ((!$is_admin && $prefix == 'AMP') || ($is_admin && ($prefix == 'AP' || $prefix == 'AMP'))))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
			$plugins[] = array(substr(substr($entry, strpos($entry, '_') + 1), 0, -4), $entry);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
	$d->close();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
	// Did we find any plugins?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
	if (!empty($plugins))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
		<h2 class="block2"><span>Plugins</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
			<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
				<ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
		while (list(, $cur_plugin) = @each($plugins))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
			echo "\t\t\t\t\t".'<li'.(($page == $cur_plugin[1]) ? ' class="isactive"' : '').'><a href="admin_loader.php?plugin='.$cur_plugin[1].'">'.str_replace('_', ' ', $cur_plugin[0]).'</a></li>'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
				</ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
// Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
function prune($forum_id, $prune_sticky, $prune_date)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   112
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
	$extra_sql = ($prune_date != -1) ? ' AND last_post<'.$prune_date : '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
	if (!$prune_sticky)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
		$extra_sql .= ' AND sticky=\'0\'';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
	// Fetch topics to prune
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   120
	$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'topics WHERE forum_id='.$forum_id.$extra_sql, true) or error('Unable to fetch topics', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
	$topic_ids = '';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   123
	while ($row = $pun_db->fetch_row($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
		$topic_ids .= (($topic_ids != '') ? ',' : '').$row[0];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
	if ($topic_ids != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
		// Fetch posts to prune
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   129
		$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id IN('.$topic_ids.')', true) or error('Unable to fetch posts', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
		$post_ids = '';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   132
		while ($row = $pun_db->fetch_row($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
			$post_ids .= (($post_ids != '') ? ',' : '').$row[0];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
		if ($post_ids != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
			// Delete topics
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   138
			$pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.$topic_ids.')') or error('Unable to prune topics', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
			// Delete subscriptions
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   140
			$pun_db->query('DELETE FROM '.$pun_db->prefix.'subscriptions WHERE topic_id IN('.$topic_ids.')') or error('Unable to prune subscriptions', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
			// Delete posts
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   142
			$pun_db->query('DELETE FROM '.$pun_db->prefix.'posts WHERE id IN('.$post_ids.')') or error('Unable to prune posts', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
			// We removed a bunch of posts, so now we have to update the search index
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
			require_once PUN_ROOT.'include/search_idx.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   146
			strip_search_index($post_ids);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   147
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   148
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   149
}