Commits

Anonymous committed 703f7a5

#838: Refactor code

  • Participants
  • Parent commits 215eb49

Comments (0)

Files changed (5)

 	!$is_admmod)
 	message($lang_common['No permission'], false, '403 Forbidden');
 
-if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], explode(',', $pun_config['o_admin_ids'])))
+if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], get_admin_ids()))
 	message($lang_common['No permission'], false, '403 Forbidden');
 
 // Load the delete.php language file
 	!$is_admmod)
 	message($lang_common['No permission'], false, '403 Forbidden');
 
-if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], explode(',', $pun_config['o_admin_ids'])))
+if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], get_admin_ids()))
 	message($lang_common['No permission'], false, '403 Forbidden');
 
 // Load the post.php language file

File moderate.php

 				message($lang_common['Bad request']);
 
 			// Verify that the post IDs are valid
-			$check_admin_ids = ($pun_user['g_id'] != PUN_ADMIN) ? ' AND poster_id NOT IN('.$pun_config['o_admin_ids'].')' : '';
-			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid.$check_admin_ids) or error('Unable to check posts', __FILE__, __LINE__, $db->error());
+			$admins_sql = ($pun_user['g_id'] != PUN_ADMIN) ? ' AND poster_id NOT IN('.implode(',', get_admin_ids()).')' : ''; 
+			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid.$admins_sql) or error('Unable to check posts', __FILE__, __LINE__, $db->error());
 
 			if ($db->num_rows($result) != substr_count($posts, ',') + 1)
 				message($lang_common['Bad request']);
 		// Verify that the posts are not by admins
 		if ($pun_user['g_id'] != PUN_ADMIN)
 		{
-			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.') AND poster_id IN('.$pun_config['o_admin_ids'].')') or error('Unable to check posts', __FILE__, __LINE__, $db->error());
+			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.') AND poster_id IN('.implode(',', get_admin_ids()).')') or error('Unable to check posts', __FILE__, __LINE__, $db->error());
 			if ($db->num_rows($result))
-				message($lang_common['Bad request']);
+				message($lang_common['No permission'], false, '403 Forbidden');
 		}
 
 		// Delete the topics and any redirect topics
 	generate_users_info_cache();
 
 	if ($old_group_id == PUN_ADMIN || $new_group_id == PUN_ADMIN)
-	{
-		$result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE group_id='.PUN_ADMIN) or error('Unable to fetch users info', __FILE__, __LINE__, $db->error());
-		$admin_ids = array();
-		for ($i = 0;$cur_user_id = $db->result($result, $i);$i++)
-			$admin_ids[] = $cur_user_id;
-
-		$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.implode(',', $admin_ids).'\' WHERE conf_name=\'o_admin_ids\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
-
-		generate_config_cache();
-	}
+		generate_admins_cache();
 
 	$result = $db->query('SELECT g_moderator FROM '.$db->prefix.'groups WHERE g_id='.$new_group_id) or error('Unable to fetch group', __FILE__, __LINE__, $db->error());
 	$new_group_mod = $db->result($result);
 		generate_users_info_cache();
 
 		if ($group_id == PUN_ADMIN)
-		{
-			$result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE group_id='.PUN_ADMIN) or error('Unable to fetch users info', __FILE__, __LINE__, $db->error());
-			$admin_ids = array();
-			for ($i = 0;$cur_user_id = $db->result($result, $i);$i++)
-				$admin_ids[] = $cur_user_id;
-
-			$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.implode(',', $admin_ids).'\' WHERE conf_name=\'o_admin_ids\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
-
-			generate_config_cache();
-		}
+			generate_admins_cache();
 
 		redirect('index.php', $lang_profile['User delete redirect']);
 	}

File viewtopic.php

 // Sort out who the moderators are and if we are currently a moderator (or an admin)
 $mods_array = ($cur_topic['moderators'] != '') ? unserialize($cur_topic['moderators']) : array();
 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
-$admin_ids = explode(',', $pun_config['o_admin_ids']);
+if ($is_admmod)
+	$admin_ids = get_admin_ids();
 
 // Can we or can we not post replies?
 if ($cur_topic['closed'] == '0')