punbb/include/common_admin.php
changeset 7 98bbc533541c
child 9 a932ce8c4827
equal deleted inserted replaced
6:5e1f1e916419 7:98bbc533541c
       
     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 // Make sure no one attempts to run this script "directly"
       
    26 if (!defined('PUN'))
       
    27 	exit;
       
    28 
       
    29 // Check for Enano authentication
       
    30 global $db, $session, $paths, $template, $plugins; // Common objects
       
    31 if ( $session->auth_level < USER_LEVEL_ADMIN )
       
    32 {
       
    33   redirect(makeUrlComplete('Special', 'Login/' . $paths->fullpage, 'level=' . $session->user_level, false), 'Permission denied', 'Re-auth needed.', 0);
       
    34 }
       
    35 
       
    36 //
       
    37 // Display the admin navigation menu
       
    38 //
       
    39 function generate_admin_menu()
       
    40 {
       
    41 	global $pun_config, $pun_url, $pun_user, $lang_admin, $db_type;
       
    42   global $db, $session, $paths, $template, $plugins; // Common objects
       
    43   
       
    44 	$adnav_sublinks = array();
       
    45 
       
    46 	if ($session->user_level < USER_LEVEL_ADMIN)
       
    47 	{
       
    48 		$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-information') ? ' class="li-first isactive">' : ' class="li-first">').'<a href="'.pun_link($pun_url['admin_index']).'">'.$lang_admin['Information'].'</span></a></li>';
       
    49 		$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-users') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_users']).'">'.$lang_admin['User search'].'</a></li>';
       
    50 		$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-censoring') ? ' class="isactive">' : '>').'<a href="'.pun_link($pun_url['admin_censoring']).'">'.$lang_admin['Censoring'].'</a></li>';
       
    51 		$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-reports') ? ' class="isactive">' : '>').'<a href="'.pun_link($pun_url['admin_reports']).'">'.$lang_admin['Reports'].'</a></li>';
       
    52 
       
    53 		if ($pun_user['g_mod_ban_users'] == '1')
       
    54 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-bans') ? ' class="isactive">' : '>').'<a href="'.pun_link($pun_url['admin_bans']).'">'.$lang_admin['Bans'].'</a></li>';
       
    55 	}
       
    56 	else
       
    57 	{
       
    58 		if (PUN_PAGE_SECTION == 'start')
       
    59 		{
       
    60 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-information') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_index']).'">'.$lang_admin['Information'].'</a></li>';
       
    61 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-categories') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_categories']).'">'.$lang_admin['Categories'].'</a></li>';
       
    62 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-forums') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_forums']).'">'.$lang_admin['Forums'].'</a></li>';
       
    63 		}
       
    64 		else if (PUN_PAGE_SECTION == 'users')
       
    65 		{
       
    66 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-users') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_users']).'">'.$lang_admin['Searches'].'</a></li>';
       
    67 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-groups') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_groups']).'">'.$lang_admin['Groups'].'</a></li>';
       
    68 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-ranks') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_ranks']).'">'.$lang_admin['Ranks'].'</a></li>';
       
    69 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-bans') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_bans']).'">'.$lang_admin['Bans'].'</a></li>';
       
    70 		}
       
    71 		else if (PUN_PAGE_SECTION == 'options')
       
    72 		{
       
    73 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-options-setup') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_options_setup']).'">'.$lang_admin['Setup'].'</a></li>';
       
    74 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-options-features') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_options_features']).'">'.$lang_admin['Features'].'</a></li>';
       
    75 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-options-email') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_options_email']).'">'.$lang_admin['E-mail'].'</a></li>';
       
    76 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-options-registration') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_options_registration']).'">'.$lang_admin['Registration'].'</a></li>';
       
    77 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-censoring') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_censoring']).'">'.$lang_admin['Censoring'].'</a></li>';
       
    78 		}
       
    79 		else if (PUN_PAGE_SECTION == 'management')
       
    80 		{
       
    81 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-reports') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_reports']).'">'.$lang_admin['Reports'].'</a></li>';
       
    82 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-prune') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_prune']).'">'.$lang_admin['Prune topics'].'</a></li>';
       
    83 
       
    84 			if ($db_type != 'mysql' && $db_type != 'mysqli')
       
    85 				$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-reindex') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_reindex']).'">'.$lang_admin['Rebuild index'].'</a></li>';
       
    86 
       
    87 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-options-maintenance') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_options_maintenance']).'">'.$lang_admin['Maintenance mode'].'</a></li>';
       
    88 		}
       
    89 		else if (PUN_PAGE_SECTION == 'extensions')
       
    90 		{
       
    91 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-extensions-manage') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_extensions_manage']).'">'.$lang_admin['Manage extensions'].'</a></li>';
       
    92 			$adnav_sublinks[] = '<li'.((PUN_PAGE == 'admin-extensions-install') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['admin_extensions_install']).'">'.$lang_admin['Install extensions'].'</a></li>';
       
    93 		}
       
    94 	}
       
    95 
       
    96 	($hook = get_hook('ca_admin_menu_new_sublink')) ? eval($hook) : null;
       
    97 
       
    98 	if (count($adnav_sublinks) > 1)
       
    99 		$adnav_submenu = "\n\t\t\t\t".'<div><ul>'."\n\t\t\t\t\t".implode("\n\t\t\t\t\t", $adnav_sublinks)."\n\t\t\t\t".'</ul></div>';
       
   100 	else
       
   101 		$adnav_submenu = '';
       
   102 
       
   103 	if ($session->user_level < USER_LEVEL_ADMIN)
       
   104 		$adnav_links[] = '<li class="topactive"><a href="'.pun_link($pun_url['admin_index']).'"><span>'.$lang_admin['Moderate'].'</span></a>'.$adnav_submenu."\n\t\t\t".'</li>';
       
   105 	else
       
   106 	{
       
   107 		$adnav_links[] = '<li'.((PUN_PAGE_SECTION == 'start') ? ' class="topactive"' : '').'><a href="'.pun_link($pun_url['admin_index']).'"><span>'.$lang_admin['Start'].'</span></a>'.(((PUN_PAGE_SECTION == 'start') && ($adnav_submenu != '')) ? $adnav_submenu."\n\t\t\t" : '').'</li>';
       
   108 		$adnav_links[] = '<li'.((PUN_PAGE_SECTION == 'options') ? ' class="topactive"' : '').'><a href="'.pun_link($pun_url['admin_options_setup']).'"><span>'.$lang_admin['Settings'].'</span></a>'.(((PUN_PAGE_SECTION == 'options') && ($adnav_submenu != '')) ? $adnav_submenu."\n\t\t\t" : '').'</li>';
       
   109 		$adnav_links[] = '<li'.((PUN_PAGE_SECTION == 'users') ? ' class="topactive"' : '').'><a href="'.pun_link($pun_url['admin_users']).'"><span>'.$lang_admin['Users'].'</span></a>'.(((PUN_PAGE_SECTION == 'users') && ($adnav_submenu != '')) ? $adnav_submenu."\n\t\t\t" : '').'</li>';
       
   110 		$adnav_links[] = '<li'.((PUN_PAGE_SECTION == 'management') ? ' class="topactive"' : '').'><a href="'.pun_link($pun_url['admin_reports']).'"><span>'.$lang_admin['Management'].'</span></a>'.(((PUN_PAGE_SECTION == 'management') && ($adnav_submenu != '')) ? $adnav_submenu."\n\t\t\t" : '').'</li>';
       
   111 		$adnav_links[] = '<li'.((PUN_PAGE_SECTION == 'extensions') ? ' class="topactive"' : '').'><a href="'.pun_link($pun_url['admin_extensions_manage']).'"><span>'.$lang_admin['Extensions'].'</span></a>'.(((PUN_PAGE_SECTION == 'extensions') && ($adnav_submenu != '')) ? $adnav_submenu."\n\t\t\t" : '').'</li>';
       
   112 	}
       
   113 
       
   114 ?>
       
   115 	<div class="main-nav<?php if ($adnav_submenu != '') echo ' submenu' ?>">
       
   116 		<ul>
       
   117 			<?php echo implode("\n\t\t\t", $adnav_links)."\n" ?>
       
   118 		</ul>
       
   119 	</div>
       
   120 <?php
       
   121 
       
   122 }
       
   123 
       
   124 
       
   125 //
       
   126 // Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted)
       
   127 //
       
   128 function prune($forum_id, $prune_sticky, $prune_date)
       
   129 {
       
   130 	global $pun_db, $db_type;
       
   131 
       
   132 	// Fetch topics to prune
       
   133 	$query = array(
       
   134 		'SELECT'	=> 't.id',
       
   135 		'FROM'		=> 'topics AS t',
       
   136 		'WHERE'		=> 't.forum_id='.$forum_id
       
   137 	);
       
   138 
       
   139 	if ($prune_date != -1)
       
   140 		$query['WHERE'] .= ' AND last_post<'.$prune_date;
       
   141 	if (!$prune_sticky)
       
   142 		$query['WHERE'] .= ' AND sticky=\'0\'';
       
   143 
       
   144 	($hook = get_hook('ca_qr_get_topics_to_prune')) ? eval($hook) : null;
       
   145 	$result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__);
       
   146 
       
   147 	$topic_ids = '';
       
   148 	while ($row = $pun_db->fetch_row($result))
       
   149 		$topic_ids .= (($topic_ids != '') ? ',' : '').$row[0];
       
   150 
       
   151 	if ($topic_ids != '')
       
   152 	{
       
   153 		// Fetch posts to prune (used lated for updating the search index)
       
   154 		$query = array(
       
   155 			'SELECT'	=> 'p.id',
       
   156 			'FROM'		=> 'posts AS p',
       
   157 			'WHERE'		=> 'p.topic_id IN('.$topic_ids.')'
       
   158 		);
       
   159 
       
   160 		($hook = get_hook('ca_qr_get_posts_to_prune')) ? eval($hook) : null;
       
   161 		$result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__);
       
   162 
       
   163 		$post_ids = '';
       
   164 		while ($row = $pun_db->fetch_row($result))
       
   165 			$post_ids .= (($post_ids != '') ? ',' : '').$row[0];
       
   166 
       
   167 		// Delete topics
       
   168 		$query = array(
       
   169 			'DELETE'	=> 'topics',
       
   170 			'WHERE'		=> 'id IN('.$topic_ids.')'
       
   171 		);
       
   172 
       
   173 		($hook = get_hook('ca_qr_prune_topics')) ? eval($hook) : null;
       
   174 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   175 
       
   176 		// Delete posts
       
   177 		$query = array(
       
   178 			'DELETE'	=> 'posts',
       
   179 			'WHERE'		=> 'topic_id IN('.$topic_ids.')'
       
   180 		);
       
   181 
       
   182 		($hook = get_hook('ca_qr_prune_posts')) ? eval($hook) : null;
       
   183 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   184 
       
   185 		// Delete subscriptions
       
   186 		$query = array(
       
   187 			'DELETE'	=> 'subscriptions',
       
   188 			'WHERE'		=> 'topic_id IN('.$topic_ids.')'
       
   189 		);
       
   190 
       
   191 		($hook = get_hook('ca_qr_prune_subscriptions')) ? eval($hook) : null;
       
   192 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   193 
       
   194 		// We removed a bunch of posts, so now we have to update the search index
       
   195 		if ($db_type != 'mysql' && $db_type != 'mysqli')
       
   196 		{
       
   197 			require_once PUN_ROOT.'include/search_idx.php';
       
   198 			strip_search_index($post_ids);
       
   199 		}
       
   200 	}
       
   201 }
       
   202 
       
   203 ($hook = get_hook('ca_new_function')) ? eval($hook) : null;