punbb/admin_prune.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
equal deleted inserted replaced
1:8f6143115bf5 2:a8a21e1c7afa
    24 
    24 
    25 
    25 
    26 // Tell header.php to use the admin template
    26 // Tell header.php to use the admin template
    27 define('PUN_ADMIN_CONSOLE', 1);
    27 define('PUN_ADMIN_CONSOLE', 1);
    28 
    28 
    29 define('PUN_ROOT', './');
    29 //define('PUN_ROOT', './');
    30 require PUN_ROOT.'include/common.php';
    30 //require PUN_ROOT.'include/common.php';
       
    31 
       
    32 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    33 
    31 require PUN_ROOT.'include/common_admin.php';
    34 require PUN_ROOT.'include/common_admin.php';
    32 
    35 
    33 
    36 
    34 if ($pun_user['g_id'] > PUN_ADMIN)
    37 if ($pun_user['g_id'] < PUN_ADMIN)
    35 	message($lang_common['No permission']);
    38 	message($lang_common['No permission']);
    36 
    39 
    37 
    40 
    38 if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply']))
    41 if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply']))
    39 {
    42 {
    47 
    50 
    48 		@set_time_limit(0);
    51 		@set_time_limit(0);
    49 
    52 
    50 		if ($prune_from == 'all')
    53 		if ($prune_from == 'all')
    51 		{
    54 		{
    52 			$result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
    55 			$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
    53 			$num_forums = $db->num_rows($result);
    56 			$num_forums = $pun_db->num_rows($result);
    54 
    57 
    55 			for ($i = 0; $i < $num_forums; ++$i)
    58 			for ($i = 0; $i < $num_forums; ++$i)
    56 			{
    59 			{
    57 				$fid = $db->result($result, $i);
    60 				$fid = $pun_db->result($result, $i);
    58 
    61 
    59 				prune($fid, $_POST['prune_sticky'], $prune_date);
    62 				prune($fid, $_POST['prune_sticky'], $prune_date);
    60 				update_forum($fid);
    63 				update_forum($fid);
    61 			}
    64 			}
    62 		}
    65 		}
    66 			prune($prune_from, $_POST['prune_sticky'], $prune_date);
    69 			prune($prune_from, $_POST['prune_sticky'], $prune_date);
    67 			update_forum($prune_from);
    70 			update_forum($prune_from);
    68 		}
    71 		}
    69 
    72 
    70 		// Locate any "orphaned redirect topics" and delete them
    73 		// Locate any "orphaned redirect topics" and delete them
    71 		$result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
    74 		$result = $pun_db->query('SELECT t1.id FROM '.$pun_db->prefix.'topics AS t1 LEFT JOIN '.$pun_db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $pun_db->error());
    72 		$num_orphans = $db->num_rows($result);
    75 		$num_orphans = $pun_db->num_rows($result);
    73 
    76 
    74 		if ($num_orphans)
    77 		if ($num_orphans)
    75 		{
    78 		{
    76 			for ($i = 0; $i < $num_orphans; ++$i)
    79 			for ($i = 0; $i < $num_orphans; ++$i)
    77 				$orphans[] = $db->result($result, $i);
    80 				$orphans[] = $pun_db->result($result, $i);
    78 
    81 
    79 			$db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
    82 			$pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $pun_db->error());
    80 		}
    83 		}
    81 
    84 
    82 		redirect('admin_prune.php', 'Posts pruned. Redirecting &hellip;');
    85 		pun_redirect('admin_prune.php', 'Posts pruned. Redirecting &hellip;');
    83 	}
    86 	}
    84 
    87 
    85 
    88 
    86 	$prune_days = $_POST['req_prune_days'];
    89 	$prune_days = $_POST['req_prune_days'];
    87 	if (!@preg_match('#^\d+$#', $prune_days))
    90 	if (!@preg_match('#^\d+$#', $prune_days))
    89 
    92 
    90 	$prune_date = time() - ($prune_days*86400);
    93 	$prune_date = time() - ($prune_days*86400);
    91 	$prune_from = $_POST['prune_from'];
    94 	$prune_from = $_POST['prune_from'];
    92 
    95 
    93 	// Concatenate together the query for counting number or topics to prune
    96 	// Concatenate together the query for counting number or topics to prune
    94 	$sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
    97 	$sql = 'SELECT COUNT(id) FROM '.$pun_db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
    95 
    98 
    96 	if ($_POST['prune_sticky'] == '0')
    99 	if ($_POST['prune_sticky'] == '0')
    97 		$sql .= ' AND sticky=\'0\'';
   100 		$sql .= ' AND sticky=\'0\'';
    98 
   101 
    99 	if ($prune_from != 'all')
   102 	if ($prune_from != 'all')
   100 	{
   103 	{
   101 		$prune_from = intval($prune_from);
   104 		$prune_from = intval($prune_from);
   102 		$sql .= ' AND forum_id='.$prune_from;
   105 		$sql .= ' AND forum_id='.$prune_from;
   103 
   106 
   104 		// Fetch the forum name (just for cosmetic reasons)
   107 		// Fetch the forum name (just for cosmetic reasons)
   105 		$result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
   108 		$result = $pun_db->query('SELECT forum_name FROM '.$pun_db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $pun_db->error());
   106 		$forum = '"'.pun_htmlspecialchars($db->result($result)).'"';
   109 		$forum = '"'.pun_htmlspecialchars($pun_db->result($result)).'"';
   107 	}
   110 	}
   108 	else
   111 	else
   109 		$forum = 'all forums';
   112 		$forum = 'all forums';
   110 
   113 
   111 	$result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error());
   114 	$result = $pun_db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $pun_db->error());
   112 	$num_topics = $db->result($result);
   115 	$num_topics = $pun_db->result($result);
   113 
   116 
   114 	if (!$num_topics)
   117 	if (!$num_topics)
   115 		message('There are no topics that are '.$prune_days.' days old. Please decrease the value of "Days old" and try again.');
   118 		message('There are no topics that are '.$prune_days.' days old. Please decrease the value of "Days old" and try again.');
   116 
   119 
   117 
   120 
   188 									<td>
   191 									<td>
   189 										<select name="prune_from" tabindex="3">
   192 										<select name="prune_from" tabindex="3">
   190 											<option value="all">All forums</option>
   193 											<option value="all">All forums</option>
   191 <?php
   194 <?php
   192 
   195 
   193 	$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
   196 	$result = $pun_db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$pun_db->prefix.'categories AS c INNER JOIN '.$pun_db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $pun_db->error());
   194 
   197 
   195 	$cur_category = 0;
   198 	$cur_category = 0;
   196 	while ($forum = $db->fetch_assoc($result))
   199 	while ($forum = $pun_db->fetch_assoc($result))
   197 	{
   200 	{
   198 		if ($forum['cid'] != $cur_category)	// Are we still in the same category?
   201 		if ($forum['cid'] != $cur_category)	// Are we still in the same category?
   199 		{
   202 		{
   200 			if ($cur_category)
   203 			if ($cur_category)
   201 				echo "\t\t\t\t\t\t\t\t\t\t\t".'</optgroup>'."\n";
   204 				echo "\t\t\t\t\t\t\t\t\t\t\t".'</optgroup>'."\n";