punbb/include/common_admin.php
changeset 6 5e1f1e916419
parent 5 e3d7322305bf
child 7 98bbc533541c
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
     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 // Make sure no one attempts to run this script "directly"
       
    26 if (!defined('PUN'))
       
    27 	exit;
       
    28 
       
    29 
       
    30 //
       
    31 // Display the admin navigation menu
       
    32 //
       
    33 function generate_admin_menu($page = '')
       
    34 {
       
    35 	global $pun_config, $pun_user;
       
    36 
       
    37 	$is_admin = $pun_user['g_id'] == PUN_ADMIN ? true : false;
       
    38 
       
    39 ?>
       
    40 <div id="adminconsole" class="block2col">
       
    41 	<div id="adminmenu" class="blockmenu">
       
    42 		<h2><span><?php echo ($is_admin) ? 'Admin' : 'Moderator' ?> menu</span></h2>
       
    43 		<div class="box">
       
    44 			<div class="inbox">
       
    45 				<ul>
       
    46 					<li<?php if ($page == 'index') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Index'); ?>">Index</a></li>
       
    47 <?php if ($is_admin): ?>					<li<?php if ($page == 'categories') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Categories'); ?>">Categories</a></li>
       
    48 <?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'forums') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Forums'); ?>">Forums</a></li>
       
    49 <?php endif; ?>					<li<?php if ($page == 'users') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Users'); ?>">Users</a></li>
       
    50 <?php if ($is_admin): ?>					<li<?php if ($page == 'groups') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Groups'); ?>">User groups</a></li>
       
    51 <?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'options') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Options'); ?>">Options</a></li>
       
    52 <?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'permissions') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Permissions'); ?>">Permissions</a></li>
       
    53 <?php endif; ?>					<li<?php if ($page == 'censoring') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Censoring'); ?>">Censoring</a></li>
       
    54 <?php if ($is_admin): ?>					<li<?php if ($page == 'ranks') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Ranks'); ?>">Ranks</a></li>
       
    55 <?php endif; ?><?php if ($is_admin || $pun_config['p_mod_ban_users'] == '1'): ?>					<li<?php if ($page == 'bans') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Bans'); ?>">Bans</a></li>
       
    56 <?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'prune') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Prune'); ?>">Prune</a></li>
       
    57 <?php endif; ?><?php if ($is_admin): ?>					<li<?php if ($page == 'maintenance') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Maintenance'); ?>">Maintenance</a></li>
       
    58 <?php endif; ?>					<li<?php if ($page == 'reports') echo ' class="isactive"'; ?>><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_Reports'); ?>">Reports</a></li>
       
    59 				</ul>
       
    60 			</div>
       
    61 		</div>
       
    62 <?php
       
    63 
       
    64 	// See if there are any plugins
       
    65 	$plugins = array();
       
    66 	$d = dir(PUN_ROOT.'plugins');
       
    67 	while (($entry = $d->read()) !== false)
       
    68 	{
       
    69 		$prefix = substr($entry, 0, strpos($entry, '_'));
       
    70 		$suffix = substr($entry, strlen($entry) - 4);
       
    71 
       
    72 		if ($suffix == '.php' && ((!$is_admin && $prefix == 'AMP') || ($is_admin && ($prefix == 'AP' || $prefix == 'AMP'))))
       
    73 			$plugins[] = array(substr(substr($entry, strpos($entry, '_') + 1), 0, -4), $entry);
       
    74 	}
       
    75 	$d->close();
       
    76 
       
    77 	// Did we find any plugins?
       
    78 	if (!empty($plugins))
       
    79 	{
       
    80 
       
    81 ?>
       
    82 		<h2 class="block2"><span>Plugins</span></h2>
       
    83 		<div class="box">
       
    84 			<div class="inbox">
       
    85 				<ul>
       
    86 <?php
       
    87 
       
    88 		while (list(, $cur_plugin) = @each($plugins))
       
    89 			echo "\t\t\t\t\t".'<li'.(($page == $cur_plugin[1]) ? ' class="isactive"' : '').'><a href="' . makeUrlNS('Special', 'Forum/Admin_Loader', 'plugin='.$cur_plugin[1], true) . '">'.str_replace('_', ' ', $cur_plugin[0]).'</a></li>'."\n";
       
    90 
       
    91 ?>
       
    92 				</ul>
       
    93 			</div>
       
    94 		</div>
       
    95 <?php
       
    96 
       
    97 	}
       
    98 
       
    99 ?>
       
   100 	</div>
       
   101 
       
   102 <?php
       
   103 
       
   104 }
       
   105 
       
   106 
       
   107 //
       
   108 // Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted)
       
   109 //
       
   110 function prune($forum_id, $prune_sticky, $prune_date)
       
   111 {
       
   112 	global $pun_db;
       
   113 
       
   114 	$extra_sql = ($prune_date != -1) ? ' AND last_post<'.$prune_date : '';
       
   115 
       
   116 	if (!$prune_sticky)
       
   117 		$extra_sql .= ' AND sticky=\'0\'';
       
   118 
       
   119 	// Fetch topics to prune
       
   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());
       
   121 
       
   122 	$topic_ids = '';
       
   123 	while ($row = $pun_db->fetch_row($result))
       
   124 		$topic_ids .= (($topic_ids != '') ? ',' : '').$row[0];
       
   125 
       
   126 	if ($topic_ids != '')
       
   127 	{
       
   128 		// Fetch posts to prune
       
   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());
       
   130 
       
   131 		$post_ids = '';
       
   132 		while ($row = $pun_db->fetch_row($result))
       
   133 			$post_ids .= (($post_ids != '') ? ',' : '').$row[0];
       
   134 
       
   135 		if ($post_ids != '')
       
   136 		{
       
   137 			// Delete topics
       
   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());
       
   139 			// Delete subscriptions
       
   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());
       
   141 			// Delete posts
       
   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());
       
   143 
       
   144 			// We removed a bunch of posts, so now we have to update the search index
       
   145 			require_once PUN_ROOT.'include/search_idx.php';
       
   146 			strip_search_index($post_ids);
       
   147 		}
       
   148 	}
       
   149 }