I already had this made up a while ago, but only decided to release it after noticing someone requesting it. This snippet gives you a very simple list of all users on the forum and their email addresses. User names a coloured, so you can see if they are an admin or a moderator, etc.
I've also included a little security in this - if you are not a founder, you will be shown an error saying the page does not exist. We don't want spambots harvesting all your user emails now do we? I don't think your users would appreciate that
The list is also paginated. The value is hard-coded, so if you want to change it then change this value:
Code: Select all
$tf = '20';
list.php (can be renamed to whatever you like, just remember to change all the instances of list.php in the php file)
Code: Select all
<?php
/**
*
* @package User Email List
* @version $Id: list.php,v 0006 11:45 12/03/2009 cherokee red Exp $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// add a mode for a CSV Listing
$mode = request_var('mode', '');
// now check the mode...no surprises
if (!in_array($mode, array('', 'list')))
{
trigger_error('NO_MODE');
}
// Founders only access
if ($user->data['user_type'] <> USER_FOUNDER)
{
trigger_error('NOT_AUTHORISED');
}
if ($mode == 'list')
{
$csv_output = $config['sitename'] . ' ' . $user->lang['EMAIL'];
$csv_output .= "\n";
$csv_output .= '#,' . $user->lang['USERNAME'] . ','. $user->lang['EMAIL_ADDRESS'];
$csv_output .= "\n";
//Pull Users from the database
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE (user_type =' . USER_NORMAL . ' OR user_type =' . USER_FOUNDER . ')
ORDER BY user_id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$csv_output .= $row['user_id'] . ',' . $row['username'] . ',' . $row['user_email'];
$csv_output .="\n";
}
$db->sql_freeresult($result);
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=" . $config['sitename'] . '_' . $user->lang['EMAIL'] . 's_' . date("Y-m-d").".csv");
print $csv_output;
exit;
}
$start = request_var('start', 0);
// How many Users do we have?
$sql = 'SELECT COUNT(user_id) AS total_users
FROM ' . USERS_TABLE . '
WHERE (user_type =' . USER_NORMAL . ' OR user_type =' . USER_FOUNDER . ')';
$result = $db->sql_query($sql);
$total_users = (int) $db->sql_fetchfield('total_users');
$db->sql_freeresult($result);
$pagination_url = append_sid("list.$phpEx");
$tf = '20';
//Pull Users from the database
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE (user_type =' . USER_NORMAL . ' OR user_type =' . USER_FOUNDER . ')
ORDER BY user_id';
$result = $db->sql_query_limit($sql, $tf, $start);
// Assign specific vars
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('list', array(
'ID' => $row['user_id'],
'EMAIL' => $row['user_email'],
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'PAGINATION' => generate_pagination($pagination_url, $total_users, $tf, $start),
'PAGE_NUMBER' => on_page($total_users, $tf, $start),
'U_CSV_LIST' => append_sid("{$phpbb_root_path}list.$phpEx", 'mode=list'),
'TOTAL_USERS' => ($total_users == 1) ? $user->lang['USER_COUNT'] : sprintf($user->lang['USER_COUNTS'], $total_users),
));
// Output page
page_header("User Email List");
$template->set_filenames(array(
'body' => 'email_list_body.html')
);
page_footer();
?>
I have found that if you have spaces in your site name, then the generated csv will not be named properly. This can be sorted by adding an str_replace to the sitename.
FIND:
REPLACE WITH:
FIND:
Code: Select all
header("Content-disposition: attachment; filename=" . $config['sitename'] . "_Email_List_" .date("Y-m-d").".csv"); Â
REPLACE WITH:
Code: Select all
header("Content-disposition: attachment; filename=" . str_replace(" ", "_", $config['sitename']) . '_' . $user->lang['EMAIL'] . 's_' . date("Y-m-d").".csv"); Â
styles/prosilver/template/email_list_body.html
Code: Select all
<!-- INCLUDE overall_header.html -->
<br />
<h2>{PAGE_TITLE}</h2>
<div class="pagination">
<a href="{U_CSV_LIST}">Export as CSV List</a> • {TOTAL_USERS}<!-- IF PAGE_NUMBER --><!-- IF PAGINATION --> • <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{PAGE_NUMBER}</a> • <span>{PAGINATION}</span><!-- ELSE --> • {PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
</div>
<br /><br />
<div class="forumbg forumbg-table">
<div class="inner"><span class="corners-top"><span></span></span>
<table class="table1" cellspacing="1" padding="1">
<thead>
<tr>
<th class="table1" style="text-align:center;"> # </th>
<th class="table1" style="text-align:center;">Username</th>
<th class="table1" style="text-align:center;">Email</th>
</tr>
</thead>
<tbody>
<!-- IF .list -->
<!-- IF not S_IS_BOT -->
<!-- BEGIN list -->
<tr class="<!-- IF S_ROW_COUNT is even -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">
<td style="text-align:center;">{list.ID}</td>
<td>{list.USERNAME_FULL}</td>
<td><a href="mailto:{list.EMAIL}">{list.EMAIL}</a></td>
</tr>
<!-- END list -->
<!-- ENDIF -->
</tbody>
</table>
<span class="corners-bottom"><span></span></span></div>
</div>
<!-- ELSE -->
</tbody>
</table>
<span class="corners-bottom"><span></span></span></div>
<div>
<div class="errorbox">
<br />
<p><strong>There are no users in your database - you shouldn't ever see this message</strong></p>
<br />
</div>
<br />
<!-- ENDIF -->
<div class="pagination">
{TOTAL_USERS}<!-- IF PAGE_NUMBER --><!-- IF PAGINATION --> • <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{PAGE_NUMBER}</a> • <span>{PAGINATION}</span><!-- ELSE --> • {PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
</div>
<br /><br />
<!-- INCLUDE overall_footer.html -->
Lastly, make the following edit:
OPEN: language/en/common.php
FIND:
Code: Select all
'USER_AVATAR' => 'User avatar',
AFTER ADD:
Code: Select all
'USER_COUNT' => '1 user',
'USER_COUNTS' => '%d users',