| 1 |
<?php
|
| 2 |
// $Id: user_list.module,v 1.17.2.6 2008/12/23 17:23:26 cyu Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* This module creates several user lists, which may be viewed as pages and blocks.
|
| 7 |
* User lists may be displayed alphabetically, beginning with A-Z, by newest, by role, or as a list of users who have posted content of a certain type.
|
| 8 |
*/
|
| 9 |
|
| 10 |
function user_list_help($path, $arg) {
|
| 11 |
switch ($path) {
|
| 12 |
case 'admin/help#user_list':
|
| 13 |
return t(
|
| 14 |
'<p>User lists may be displayed alphabetically, beginning with A-Z, by newest, or as a list of users who have posted content of a certain type.</p>
|
| 15 |
<p>Go to !admin to change the global settings for user lists, and to !block to configure specific user listing blocks if desired. Note that all blocks provided by this module are appended with "User List:", so they may be differentiated by similar blocks provided by other modules.</p>
|
| 16 |
<p>Note that you must enable access to the user listings with the \'access user lists\' permission at !access, which controls viewing both blocks and pages. If enabled and allowed, the main user listing page may be viewed at !user_list.</p>',
|
| 17 |
array('!admin' => l('admin/settings/user_list', 'admin/settings/user_list'), '!block' => l('admin/build/block', 'admin/build/block'), '!access' => l('admin/user/permissions', 'admin/user/permissions'), '!user_list' => l('userlist', 'userlist'))
|
| 18 |
);
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
function user_list_perm() {
|
| 23 |
return array('access user lists', 'administer user lists');
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* returns a themed list of users
|
| 28 |
* $op:
|
| 29 |
* 'newest' => the $paginated $number of newest users
|
| 30 |
* 'A' - 'Z' => the $paginated $number of users whose username begins with that letter (case doesn't matter)
|
| 31 |
* 'other' => the $paginated $number of users whose username begins with something other than 'A' - 'Z'
|
| 32 |
* 'content' => the $paginated $number of users who have created at least one node of content-type $content_type
|
| 33 |
* 'roles' => the $paginated $number of users who are in $role_type
|
| 34 |
* $number:
|
| 35 |
* the number of users to return
|
| 36 |
* $paginated:
|
| 37 |
* will this have a paginator at the end?
|
| 38 |
* $default_header:
|
| 39 |
* If this has a value, then the default header for this $op will be overridden.
|
| 40 |
* $default_empty_msg:
|
| 41 |
* If this has a value, then the default empty_msg for this $op will be overridden.
|
| 42 |
* $content_type:
|
| 43 |
* if $op is 'content', then this will be the content type to check, such as 'blog'. otherwise ignored.
|
| 44 |
* $embed_menu:
|
| 45 |
* if true, then prepend a userlist menu to the top of the user list.
|
| 46 |
* $from_block:
|
| 47 |
* true if is this being called from a block
|
| 48 |
* $element_override:
|
| 49 |
* if this is NULL, then we will automatically assign and increment an pager element beginning with 0.
|
| 50 |
* otherwise, we will use the value given.
|
| 51 |
* $role_type:
|
| 52 |
* if $op is 'role', then this will be the user role. otherwise ignored
|
| 53 |
*/
|
| 54 |
function _user_list($op = 'all', $number = NULL, $paginated = TRUE, $include_more_link = NULL, $default_header = NULL, $default_empty_msg = NULL, $content_type = NULL, $embed_menu = NULL, $from_block = FALSE, $element_override = NULL, $role_type = NULL) {
|
| 55 |
static $element = 0;
|
| 56 |
if (!isset($element_override)) {
|
| 57 |
$element_override = $element;
|
| 58 |
$element += 1;
|
| 59 |
}
|
| 60 |
|
| 61 |
if (!$number) {
|
| 62 |
$number = variable_get('user_list_default_number', 10);
|
| 63 |
}
|
| 64 |
|
| 65 |
if ($embed_menu || ($embed_menu === NULL && variable_get('user_list_embed_menu', TRUE))) {
|
| 66 |
if (!$from_block) {
|
| 67 |
$args = array(arg(0), arg(1), arg(2));
|
| 68 |
}
|
| 69 |
else {
|
| 70 |
$args = array('userlist', $op, $content_type);
|
| 71 |
}
|
| 72 |
$embedded_menu = _user_list_embedded_menu($args);
|
| 73 |
}
|
| 74 |
|
| 75 |
if ($op == 'roles') {
|
| 76 |
$roles = variable_get('user_list_role_types', array());
|
| 77 |
}
|
| 78 |
else if ($op == 'content') {
|
| 79 |
$types = variable_get('user_list_content_types', array());
|
| 80 |
}
|
| 81 |
if (drupal_strlen($op) == 1 && variable_get('user_list_alpha_listing', TRUE)) {
|
| 82 |
$result = pager_query("SELECT u.uid, u.name FROM {users} u WHERE u.status <> 0 AND u.access <> 0 AND LOWER(u.name) LIKE '%s%%' ORDER BY u.name ASC", $number, $element_override, NULL, drupal_strtolower($op));
|
| 83 |
if ($include_more_link) {
|
| 84 |
$count = db_result(db_query("SELECT COUNT(u.uid) FROM {users} u WHERE u.status <> 0 AND u.access <> 0 AND LOWER(u.name) LIKE '%s%%'"));
|
| 85 |
}
|
| 86 |
$header = t('Users Beginning with @letter', array('@letter' => drupal_strtoupper($op)));
|
| 87 |
$empty_msg = t('There are currently no users with usernames beginning with @letter.', array('@letter' => $op));
|
| 88 |
}
|
| 89 |
else if ($op == 'content' && ($type_name = node_get_types('name', $content_type)) && $types[$content_type]) {
|
| 90 |
$header = t('Users who have contributed at least one %content', array('%content' => $type_name));
|
| 91 |
$count_query = "SELECT COUNT(DISTINCT(u.uid)) FROM {users} u INNER JOIN {node} n ON n.uid = u.uid AND n.type = '%s' WHERE u.status <> 0 AND u.access <> 0";
|
| 92 |
$result = pager_query("SELECT DISTINCT(u.uid), u.name FROM {users} u INNER JOIN {node} n ON n.uid = u.uid AND n.type = '%s' WHERE u.status <> 0 AND u.access <> 0 ORDER BY u.name ASC", $number, $element_override, $count_query, $content_type);
|
| 93 |
if ($include_more_link) {
|
| 94 |
$count = db_result(db_query($count_query, $content_type));
|
| 95 |
}
|
| 96 |
$empty_msg = t('There are currently no users who have contributed at least one %content.', array('%content' => $type_name));
|
| 97 |
}
|
| 98 |
else if ($op == 'roles' && _user_list_get_roles('base', $role_type) && $roles[$role_type]) {
|
| 99 |
$role = _user_list_get_roles('get', $role_type);
|
| 100 |
$header = t('Users of the %role role', array('%role' => $role->name));
|
| 101 |
$result = pager_query("SELECT u.uid, u.name FROM {users} u INNER JOIN {users_roles} r ON r.uid = u.uid AND r.rid = %d WHERE u.status <> 0 AND u.access <> 0 ORDER BY u.name ASC", $number, $element_override, NULL, $role->rid);
|
| 102 |
if ($include_more_link) {
|
| 103 |
$count = db_result(db_query("SELECT COUNT(u.uid) FROM {users} u INNER JOIN {users_roles} r ON r.uid = u.uid AND r.rid = %d WHERE u.status <> 0 AND u.access <> 0", $role->rid));
|
| 104 |
}
|
| 105 |
$empty_msg = t('There are currently no users of the %role role.', array('%role' => $role->name));
|
| 106 |
}
|
| 107 |
else if ($op == 'newest' && variable_get('user_list_newest', TRUE)) {
|
| 108 |
$header = t('Newest Users');
|
| 109 |
$result = pager_query('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', $number, $element_override);
|
| 110 |
if ($include_more_link) {
|
| 111 |
$count = db_result(db_query("SELECT COUNT(u.uid) FROM {users} u WHERE u.status <> 0 AND u.access <> 0"));
|
| 112 |
}
|
| 113 |
$empty_msg = t('There are currently no users.');
|
| 114 |
}
|
| 115 |
else if ($op == 'other' && variable_get('user_list_alpha_listing', TRUE)) {
|
| 116 |
$header = t('Users Not in A-Z');
|
| 117 |
$result = pager_query("SELECT u.uid, u.name FROM {users} u WHERE (LOWER(u.name) < 'a' OR LOWER(u.name) > 'z') AND u.status <> 0 AND u.access <> 0 ORDER BY u.name ASC", $number, $element_override);
|
| 118 |
if ($include_more_link) {
|
| 119 |
$count = db_result(db_query("SELECT COUNT(u.uid) FROM {users} u WHERE (LOWER(u.name) < 'a' OR LOWER(u.name) > 'z') AND u.status <> 0 AND u.access <> 0"));
|
| 120 |
}
|
| 121 |
$empty_msg = t('There are currently no users with usernames not beginning with A-Z.');
|
| 122 |
}
|
| 123 |
else {
|
| 124 |
$header = t('All Users');
|
| 125 |
$result = pager_query('SELECT u.uid, u.name FROM {users} u WHERE status <> 0 AND access <> 0 ORDER BY u.name ASC', $number, $element_override);
|
| 126 |
if ($include_more_link) {
|
| 127 |
$count = db_result(db_query("SELECT COUNT(u.uid) FROM {users} u WHERE u.status <> 0 AND u.access <> 0"));
|
| 128 |
}
|
| 129 |
$empty_msg = t('There are currently no users.');
|
| 130 |
}
|
| 131 |
while ($account = db_fetch_object($result)) {
|
| 132 |
$users[] = $account;
|
| 133 |
}
|
| 134 |
if ($include_more_link) {
|
| 135 |
$include_more_link = ($count > $number ? $include_more_link : NULL);
|
| 136 |
}
|
| 137 |
$output .= theme('user_list_list', $op, ($default_header === NULL ? $header : $default_header), $users, ($default_empty_msg === NULL ? $empty_msg : $default_empty_msg), $paginated, $number, $element_override, $include_more_link, $embedded_menu);
|
| 138 |
return $output;
|
| 139 |
}
|
| 140 |
|
| 141 |
function _user_list_page() {
|
| 142 |
if (arg(1) == 'content') {
|
| 143 |
return _user_list(arg(1), NULL, TRUE, FALSE, NULL, NULL, arg(2));
|
| 144 |
}
|
| 145 |
else if (arg(1) == 'roles') {
|
| 146 |
return _user_list(arg(1), NULL, TRUE, FALSE, NULL, NULL, NULL, NULL, FALSE, NULL, arg(2));
|
| 147 |
}
|
| 148 |
return _user_list(arg(1));
|
| 149 |
}
|
| 150 |
|
| 151 |
/**
|
| 152 |
* Implementation of hook_menu().
|
| 153 |
*/
|
| 154 |
function user_list_menu() {
|
| 155 |
$items['admin/settings/user_list'] = array(
|
| 156 |
'title' => 'User list',
|
| 157 |
'description' => 'Change the format and types of user lists that appear on the site.',
|
| 158 |
'page callback' => 'drupal_get_form',
|
| 159 |
'page arguments' => array('user_list_admin_settings'),
|
| 160 |
'access arguments' => array('administer user lists'),
|
| 161 |
'type' => MENU_NORMAL_ITEM,
|
| 162 |
);
|
| 163 |
if (variable_get('user_list_provide_page', TRUE)) {
|
| 164 |
$items['userlist'] = array(
|
| 165 |
'title' => 'User list',
|
| 166 |
'access arguments' => array('access user lists'),
|
| 167 |
'page callback' => '_user_list_page',
|
| 168 |
'type' => MENU_NORMAL_ITEM,
|
| 169 |
);
|
| 170 |
if (variable_get('user_list_provide_menu', FALSE)) {
|
| 171 |
$items['userlist/all'] = array(
|
| 172 |
'title' => 'all',
|
| 173 |
'access arguments' => array('access user lists'),
|
| 174 |
'page callback' => '_user_list_page',
|
| 175 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 176 |
'weight' => -3,
|
| 177 |
);
|
| 178 |
if (variable_get('user_list_newest', TRUE)) {
|
| 179 |
$items['userlist/newest'] = array(
|
| 180 |
'title' => 'newest',
|
| 181 |
'access arguments' => array('access user lists'),
|
| 182 |
'page callback' => '_user_list_page',
|
| 183 |
'type' => MENU_LOCAL_TASK,
|
| 184 |
'weight' => -1,
|
| 185 |
);
|
| 186 |
}
|
| 187 |
if (variable_get('user_list_alpha_listing', TRUE)) {
|
| 188 |
$letter = 'a';
|
| 189 |
do {
|
| 190 |
$title = (variable_get('user_list_alpha_listing_caps', FALSE) ? drupal_strtoupper($letter) : $letter);
|
| 191 |
$items['userlist/'. $letter] = array(
|
| 192 |
'title' => '@letter',
|
| 193 |
'title arguments' => array('@letter' => $title),
|
| 194 |
'access arguments' => array('access user lists'),
|
| 195 |
'page callback' => '_user_list_page',
|
| 196 |
'type' => MENU_LOCAL_TASK,
|
| 197 |
);
|
| 198 |
} while ($letter++ < 'z');
|
| 199 |
$items['userlist/other'] = array(
|
| 200 |
'title' => 'other',
|
| 201 |
'access arguments' => array('access user lists'),
|
| 202 |
'page callback' => '_user_list_page',
|
| 203 |
'type' => MENU_LOCAL_TASK,
|
| 204 |
'weight' => 1,
|
| 205 |
);
|
| 206 |
}
|
| 207 |
foreach (variable_get('user_list_content_types', array()) as $type) {
|
| 208 |
if ($name = node_get_types('name', $type)) {
|
| 209 |
$items['userlist/content/'. $type] = array(
|
| 210 |
'title' => $name,
|
| 211 |
'access arguments' => array('access user lists'),
|
| 212 |
'page callback' => '_user_list_page',
|
| 213 |
'type' => MENU_LOCAL_TASK,
|
| 214 |
'weight' => 3,
|
| 215 |
);
|
| 216 |
}
|
| 217 |
}
|
| 218 |
foreach (variable_get('user_list_role_types', array()) as $type) {
|
| 219 |
if (_user_list_get_roles('base', $type)) {
|
| 220 |
$items['userlist/roles/'. $type] = array(
|
| 221 |
'title' => _user_list_get_roles('name', $type),
|
| 222 |
'access arguments' => array('access user lists'),
|
| 223 |
'page callback' => '_user_list_page',
|
| 224 |
'type' => MENU_LOCAL_TASK,
|
| 225 |
'weight' => 4,
|
| 226 |
);
|
| 227 |
}
|
| 228 |
}
|
| 229 |
}
|
| 230 |
}
|
| 231 |
return $items;
|
| 232 |
}
|
| 233 |
|
| 234 |
function user_list_admin_settings() {
|
| 235 |
$form = array();
|
| 236 |
|
| 237 |
$form['user_list_default_number'] = array(
|
| 238 |
'#type' => 'select',
|
| 239 |
'#title' => t('Default Number of Users to List'),
|
| 240 |
'#default_value' => variable_get('user_list_default_number', 10),
|
| 241 |
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30, 40, 50, 100, 125, 150, 200, 250, 500)),
|
| 242 |
'#description' => t('Choose the default number of users to list on the various user list pages. Certain blocks, modules, or themes may override this value.'),
|
| 243 |
);
|
| 244 |
|
| 245 |
$form['user_list_types'] = array(
|
| 246 |
'#type' => 'fieldset',
|
| 247 |
'#title' => t('User List Types'),
|
| 248 |
'#collapsible' => TRUE,
|
| 249 |
'#collapsed' => TRUE,
|
| 250 |
);
|
| 251 |
$form['user_list_types']['user_list_newest'] = array(
|
| 252 |
'#type' => 'checkbox',
|
| 253 |
'#title' => t('Provide Newest Users List'),
|
| 254 |
'#default' => variable_get('user_list_newest', TRUE),
|
| 255 |
'#description' => t('If checked, then a listing of newest users will be offered, ordered by most recently registered.'),
|
| 256 |
);
|
| 257 |
|
| 258 |
$form['user_list_types']['alpha_options'] = array(
|
| 259 |
'#type' => 'fieldset',
|
| 260 |
'#title' => t('Alphabetical User Lists'),
|
| 261 |
'#collapsible' => TRUE,
|
| 262 |
'#collapsed' => TRUE,
|
| 263 |
);
|
| 264 |
$form['user_list_types']['alpha_options']['user_list_alpha_listing'] = array(
|
| 265 |
'#type' => 'checkbox',
|
| 266 |
'#title' => t('Provide Alphabetical Listings'),
|
| 267 |
'#default_value' => variable_get('user_list_alpha_listing', TRUE),
|
| 268 |
'#description' => t('If checked, then you may view users whose usernames begin with a specific letter of the alphabet, such as !a, !m, and !other for other than A-Z.', array('!a' => l('userlist/a', 'userlist/a'), '!m' => l('userlist/m', 'userlist/m'), '!other' => l('userlist/other', 'userlist/other'))),
|
| 269 |
);
|
| 270 |
$form['user_list_types']['alpha_options']['user_list_alpha_listing_caps'] = array(
|
| 271 |
'#type' => 'checkbox',
|
| 272 |
'#title' => t('Capitalize Letter in Menu'),
|
| 273 |
'#default_value' => variable_get('user_list_alpha_listing_caps', FALSE),
|
| 274 |
'#description' => t('If checked, then letters listed in the embedded or tabbed menu for links to alphabetized listings will be capitalized.'),
|
| 275 |
);
|
| 276 |
|
| 277 |
$form['user_list_types']['content_options'] = array(
|
| 278 |
'#type' => 'fieldset',
|
| 279 |
'#title' => t('Content-Based User Lists'),
|
| 280 |
'#collapsible' => TRUE,
|
| 281 |
'#collapsed' => TRUE,
|
| 282 |
);
|
| 283 |
$options = array();
|
| 284 |
foreach (node_get_types() as $type) {
|
| 285 |
$options[$type->type] = $type->name;
|
| 286 |
}
|
| 287 |
$form['user_list_types']['content_options']['user_list_content_types'] = array(
|
| 288 |
'#type' => 'checkboxes',
|
| 289 |
'#title' => t('Content Type User Lists'),
|
| 290 |
'#default_value' => variable_get('user_list_content_types', array()),
|
| 291 |
'#options' => $options,
|
| 292 |
'#multiple' => TRUE,
|
| 293 |
'#description' => t('Select the node types you wish to allow user lists for. For instance, you may have a list of users who have written at least one blog entry at !blog, or who have contributed at least one image at !image.', array('!blog' => l('userlist/content/blog', 'userlist/content/blog'), '!image' => l('userlist/content/image', 'userlist/content/image'))),
|
| 294 |
);
|
| 295 |
|
| 296 |
$form['user_list_types']['role_options'] = array(
|
| 297 |
'#type' => 'fieldset',
|
| 298 |
'#title' => t('Role-Based User Lists'),
|
| 299 |
'#collapsible' => TRUE,
|
| 300 |
'#collapsed' => TRUE,
|
| 301 |
);
|
| 302 |
$options = _user_list_get_roles();
|
| 303 |
$form['user_list_types']['role_options']['user_list_role_types'] = array(
|
| 304 |
'#type' => 'checkboxes',
|
| 305 |
'#title' => t('Role User Lists'),
|
| 306 |
'#default_value' => variable_get('user_list_role_types', array()),
|
| 307 |
'#options' => $options,
|
| 308 |
'#multiple' => TRUE,
|
| 309 |
'#description' => t('Select the roles you wish to allow user lists for. For instance, you may have a list of users who are of the %role role at !role_dest. NOTE: Spaces in role names are converted to underscore, but does not affect the role table.', array('%role' => current($options), '!role_dest' => l('userlist/roles/'. current($options), 'userlist/roles/'. current($options)))),
|
| 310 |
);
|
| 311 |
|
| 312 |
$form['user_list_menu_settings'] = array(
|
| 313 |
'#type' => 'fieldset',
|
| 314 |
'#title' => t('Menu Settings'),
|
| 315 |
'#collapsible' => TRUE,
|
| 316 |
'#collapsed' => TRUE,
|
| 317 |
);
|
| 318 |
$form['user_list_menu_settings']['user_list_provide_page'] = array(
|
| 319 |
'#type' => 'checkbox',
|
| 320 |
'#title' => t('Provide User Listing Page'),
|
| 321 |
'#default_value' => variable_get('user_list_provide_page', TRUE),
|
| 322 |
'#description' => t('If checked, a user listing page will be provided, along with an item in the menu (which may be renamed, moved, or disabled at !admin_menu). Note that when enabled, the profile module also provides a basic user listing page with the same title of \'user list\', although its path is different and it is not listed in the menu by default. This module\'s path is !userlist, while that of the profile module is !profile.', array('!admin_menu' => l('admin/build/menu', 'admin/build/menu'), '!userlist' => l('userlist', 'userlist'), '!profile' => l('profile', 'profile'))),
|
| 323 |
);
|
| 324 |
$form['user_list_menu_settings']['user_list_embed_menu'] = array(
|
| 325 |
'#type' => 'checkbox',
|
| 326 |
'#title' => t('Provide Embedded Menu'),
|
| 327 |
'#default_value' => variable_get('user_list_embed_menu', TRUE),
|
| 328 |
'#description' => t('If checked, a menu will be embedded on the user list page. Note that this bypasses the default menu tab system in Drupal 4.7, and provides its own theme which is easier in most cases to customize.'),
|
| 329 |
);
|
| 330 |
$form['user_list_menu_settings']['user_list_provide_menu'] = array(
|
| 331 |
'#type' => 'checkbox',
|
| 332 |
'#title' => t('Provide Menu Tab'),
|
| 333 |
'#default_value' => variable_get('user_list_provide_menu', FALSE),
|
| 334 |
'#description' => t('If checked, a menu tab will be displayed on the user list page. Note that if the alphabetical listings are provided, this menu tab will be quite long (at least 28 available options), and will most certainly require custom theming. Customizing the theme for menu tabs in Drupal 4.7 is a tricky prospect, so unless you require this functionality and are prepared to do the custom work, it is suggested you leave this item disabled and enable the embedded menu instead, which comes with a more manageable theme and is easier to customize.'),
|
| 335 |
);
|
| 336 |
menu_rebuild();
|
| 337 |
return system_settings_form($form);
|
| 338 |
}
|
| 339 |
|
| 340 |
function user_list_block($op = 'list', $delta = 'all', $edit = array()) {
|
| 341 |
switch ($op) {
|
| 342 |
case 'list':
|
| 343 |
$blocks['all'] = array('info' => t('User List: All users'));
|
| 344 |
$blocks['newest'] = array('info' => t('User List: Newest users'));
|
| 345 |
foreach (variable_get('user_list_content_types', array()) as $type) {
|
| 346 |
if ($name = node_get_types('name', $type)) {
|
| 347 |
$blocks[$type] = array('info' => t('User List: Users with @types', array('@type' => $name)));
|
| 348 |
}
|
| 349 |
}
|
| 350 |
foreach (variable_get('user_list_role_types', array()) as $type) {
|
| 351 |
if (_user_list_get_roles('base', $type)) {
|
| 352 |
$blocks[$type] = array('info' => t('User List: Users with %role', array('%role' => _user_list_get_roles('name', $type))));
|
| 353 |
}
|
| 354 |
}
|
| 355 |
return $blocks;
|
| 356 |
case 'configure':
|
| 357 |
if ($delta == 'all') {
|
| 358 |
$default_header = t('All users');
|
| 359 |
}
|
| 360 |
else if ($delta == 'newest') {
|
| 361 |
$default_header = t('Recent users');
|
| 362 |
}
|
| 363 |
else if (in_array($delta, variable_get('user_list_content_types', array()))) {
|
| 364 |
$default_header = t('Users who have contributed at least one @content', array('@content' => node_get_types('name', $delta)));
|
| 365 |
}
|
| 366 |
else if (in_array($delta, variable_get('user_list_role_types', array()))) {
|
| 367 |
$default_header = t('Users of the %role role', array('%role' => _user_list_get_roles('name', $delta)));
|
| 368 |
}
|
| 369 |
$form['header'] = array(
|
| 370 |
'#type' => 'textfield',
|
| 371 |
'#title' => t('Header'),
|
| 372 |
'#default_value' => variable_get('user_list_block_header_'. $delta, $default_header),
|
| 373 |
'#description' => t('The block header as it will appear to the user.'),
|
| 374 |
);
|
| 375 |
$form['embedded_menu'] = array(
|
| 376 |
'#type' => 'checkbox',
|
| 377 |
'#title' => t('Embed Menu'),
|
| 378 |
'#default_value' => variable_get('user_list_block_embed_'. $delta, FALSE),
|
| 379 |
'#description' => t('If checked, an embedded menu of the various user listing pages will be included in the block.'),
|
| 380 |
);
|
| 381 |
$form['number'] = array(
|
| 382 |
'#type' => 'select',
|
| 383 |
'#title' => t('Number of users to list'),
|
| 384 |
'#default_value' => variable_get('user_list_block_number_'. $delta, variable_get('user_list_default_number', 10)),
|
| 385 |
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30, 40, 50, 100, 125, 150, 200, 250, 500)),
|
| 386 |
'#description' => t('Choose the number of users to list on this block.'),
|
| 387 |
);
|
| 388 |
$form['include_more'] = array(
|
| 389 |
'#type' => 'checkbox',
|
| 390 |
'#title' => t('Include a more link'),
|
| 391 |
'#default_value' => variable_get('user_list_block_more_'. $delta, TRUE),
|
| 392 |
'#description' => t('If checked and the corresponding user list page is available, then this block will include a link to that page at the end, if there are more users than are listed in the block.'),
|
| 393 |
);
|
| 394 |
$form['include_more_msg'] = array(
|
| 395 |
'#type' => 'textfield',
|
| 396 |
'#title' => t('View more link text'),
|
| 397 |
'#default_value' => variable_get('user_list_block_more_msg_'. $delta, t('View More')),
|
| 398 |
'#description' => t('If there are more users than listed in the block, and we make a link available to view them on another page, then this is the text for that link.'),
|
| 399 |
);
|
| 400 |
return $form;
|
| 401 |
case 'save':
|
| 402 |
variable_set('user_list_block_header_'. $delta, $edit['header']);
|
| 403 |
variable_set('user_list_block_embed_'. $delta, $edit['embedded_menu']);
|
| 404 |
variable_set('user_list_block_number_'. $delta, $edit['number']);
|
| 405 |
variable_set('user_list_block_more_'. $delta, $edit['include_more']);
|
| 406 |
variable_set('user_list_block_more_msg_'. $delta, $edit['include_more_msg']);
|
| 407 |
break;
|
| 408 |
case 'view':
|
| 409 |
if (user_access('access user lists')) {
|
| 410 |
$number = variable_get('user_list_block_number_'. $delta, variable_get('user_list_default_number', 10));
|
| 411 |
$include_more = variable_get('user_list_block_more_'. $delta, TRUE);
|
| 412 |
$embed_menu = variable_get('user_list_block_embed_'. $delta, FALSE);
|
| 413 |
if ($delta == 'all') {
|
| 414 |
if ($include_more) {
|
| 415 |
$include_more = l(variable_get('user_list_block_more_msg_'. $delta, t('View More')), 'userlist');
|
| 416 |
}
|
| 417 |
$block['subject'] = variable_get('user_list_block_header_'. $delta, t('All Users'));
|
| 418 |
$block['content'] = _user_list('all', $number, FALSE, $include_more, '', NULL, NULL, $embed_menu, TRUE);
|
| 419 |
}
|
| 420 |
else if ($delta == 'newest') {
|
| 421 |
if ($include_more) {
|
| 422 |
$include_more = l(variable_get('user_list_block_more_msg_'. $delta, t('View More')), 'userlist/newest');
|
| 423 |
}
|
| 424 |
$block['subject'] = variable_get('user_list_block_header_'. $delta, t('Recent Users'));
|
| 425 |
$block['content'] = _user_list('newest', $number, FALSE, $include_more, '', NULL, NULL, $embed_menu, TRUE);
|
| 426 |
}
|
| 427 |
else if (in_array($delta, variable_get('user_list_content_types', array()))) {
|
| 428 |
if ($include_more) {
|
| 429 |
$include_more = l(variable_get('user_list_block_more_msg_'. $delta, t('View More')), 'userlist/content/'. $delta);
|
| 430 |
}
|
| 431 |
$block['subject'] = variable_get('user_list_block_header_'. $delta, t('Users who have contributed at least one @content', array('@content' => node_get_types('name', $delta))));
|
| 432 |
$block['content'] = _user_list('content', $number, FALSE, $include_more, '', NULL, $delta, $embed_menu, TRUE);
|
| 433 |
}
|
| 434 |
else if (in_array($delta, variable_get('user_list_role_types', array()))) {
|
| 435 |
if ($include_more) {
|
| 436 |
$include_more = l(variable_get('user_list_block_more_msg_'. $delta, t('View More')), 'userlist/roles/'. $delta);
|
| 437 |
}
|
| 438 |
$block['subject'] = variable_get('user_list_block_header_'. $delta, t('Users of the %role role', array('%role' => _user_list_get_roles('name', $delta))));
|
| 439 |
$block['content'] = _user_list('roles', $number, FALSE, $include_more, '', NULL, NULL, $embed_menu, TRUE, NULL, $delta);
|
| 440 |
}
|
| 441 |
}
|
| 442 |
return $block;
|
| 443 |
}
|
| 444 |
}
|
| 445 |
|
| 446 |
function _user_list_embedded_menu($args = array()) {
|
| 447 |
$items['all'] = array(
|
| 448 |
'path' => 'userlist',
|
| 449 |
'title' => t('all'),
|
| 450 |
);
|
| 451 |
if (variable_get('user_list_newest', TRUE)) {
|
| 452 |
$items['newest'] = array(
|
| 453 |
'path' => 'userlist/newest',
|
| 454 |
'title' => t('newest'),
|
| 455 |
);
|
| 456 |
}
|
| 457 |
if (variable_get('user_list_alpha_listing', TRUE)) {
|
| 458 |
$letter = 'a';
|
| 459 |
do {
|
| 460 |
$title = (variable_get('user_list_alpha_listing_caps', FALSE) ? drupal_strtoupper($letter) : $letter);
|
| 461 |
$items[$letter] = array(
|
| 462 |
'path' => 'userlist/'. $letter,
|
| 463 |
'title' => t('@letter', array('@letter' => $title)),
|
| 464 |
);
|
| 465 |
if ($args[1] == $letter) {
|
| 466 |
$active = $letter;
|
| 467 |
$items[$letter]['active'] = TRUE;
|
| 468 |
}
|
| 469 |
} while ($letter++ < 'z');
|
| 470 |
$items['other'] = array(
|
| 471 |
'path' => 'userlist/other',
|
| 472 |
'title' => t('other'),
|
| 473 |
);
|
| 474 |
if ($args[1] == 'other') {
|
| 475 |
$active = 'other';
|
| 476 |
$items['other']['active'] = TRUE;
|
| 477 |
}
|
| 478 |
}
|
| 479 |
foreach (variable_get('user_list_content_types', array()) as $type) {
|
| 480 |
if ($name = node_get_types('type', $type)) {
|
| 481 |
$items[$type] = array(
|
| 482 |
'path' => 'userlist/content/'. $type,
|
| 483 |
'title' => $name->name,
|
| 484 |
);
|
| 485 |
if ($args[1] == 'content' && $args[2] == $type) {
|
| 486 |
$active = $type;
|
| 487 |
$items[$type]['active'] = TRUE;
|
| 488 |
}
|
| 489 |
}
|
| 490 |
}
|
| 491 |
foreach (variable_get('user_list_role_types', array()) as $type) {
|
| 492 |
if (_user_list_get_roles('base', $type)) {
|
| 493 |
$items[$type] = array(
|
| 494 |
'path' => 'userlist/roles/'. $type,
|
| 495 |
'title' => _user_list_get_roles('name', $type),
|
| 496 |
);
|
| 497 |
if ($args[1] == 'roles' && $args[2] == $type) {
|
| 498 |
$active = $type;
|
| 499 |
$items[$type]['active'] = TRUE;
|
| 500 |
}
|
| 501 |
}
|
| 502 |
}
|
| 503 |
if (!$active) {
|
| 504 |
$items['all']['active'] = TRUE;
|
| 505 |
$active = 'all';
|
| 506 |
}
|
| 507 |
return theme('user_list_menu', $items);
|
| 508 |
}
|
| 509 |
|
| 510 |
function user_list_theme() {
|
| 511 |
return array(
|
| 512 |
'user_list_menu' => array(
|
| 513 |
'arguments' => array('content', NULL),
|
| 514 |
),
|
| 515 |
'user_list_list' => array(
|
| 516 |
'arguments' => array('content', NULL),
|
| 517 |
)
|
| 518 |
|
| 519 |
);
|
| 520 |
}
|
| 521 |
|
| 522 |
function theme_user_list_menu($items) {
|
| 523 |
drupal_add_css(drupal_get_path('module', 'user_list') .'/user_list.css');
|
| 524 |
foreach ($items as $item) {
|
| 525 |
$output .= ' <li class="leaf'. ($item['active'] ? ' active' : '') .'">'. l(t($item['title']), $item['path']) ."</li>\n";
|
| 526 |
}
|
| 527 |
return "<div class=\"menu user_list_menu\">\n<ul>\n". $output .'</ul></div>';
|
| 528 |
}
|
| 529 |
|
| 530 |
function theme_user_list_list($op = '', $header = '', $users = array(), $empty_msg = 'There are currently no users in this category to list.', $paginated = FALSE, $number = 10, $element = 0, $include_more = NULL, $embedded_menu = '') {
|
| 531 |
drupal_add_css(drupal_get_path('module', 'user_list') .'/user_list.css');
|
| 532 |
$output .= "<div id=\"user_list_$op\" class=\"user_list\">\n";
|
| 533 |
if ($header) {
|
| 534 |
$output .= ' <h3>'. $header ."</h3>\n ";
|
| 535 |
}
|
| 536 |
$output .= " <div class=\"content\">\n ";
|
| 537 |
$output .= $embedded_menu;
|
| 538 |
if (empty($users)) {
|
| 539 |
$output .= $empty_msg;
|
| 540 |
}
|
| 541 |
else {
|
| 542 |
$output .= theme('user_list', $users);
|
| 543 |
}
|
| 544 |
$output .= " </div>\n ";
|
| 545 |
if ($include_more) {
|
| 546 |
$output .= " <div class=\"more\">$include_more</div>\n";
|
| 547 |
}
|
| 548 |
if ($paginated) {
|
| 549 |
$output .= theme('pager', NULL, $number, $element);
|
| 550 |
}
|
| 551 |
$output .= "</div>\n";
|
| 552 |
return $output;
|
| 553 |
}
|
| 554 |
|
| 555 |
/**
|
| 556 |
* returns an array|object|boolean of role table
|
| 557 |
* $op:
|
| 558 |
* 'get' => return a $role object for a $role_type or an array of roles from role table
|
| 559 |
* 'base' => return whether a role exists in role table
|
| 560 |
* 'name' => return just the name of the role specified in $role_type
|
| 561 |
* $role_type:
|
| 562 |
* if role_type is null gets all roles, if role_type is specified grabs information for only that role from role table
|
| 563 |
*/
|
| 564 |
function _user_list_get_roles($op = 'get', $role_type = NULL) {
|
| 565 |
if (!is_null($role_type)) {
|
| 566 |
// need to make sure we translate back to spaces
|
| 567 |
$role_type = str_replace('_', ' ', $role_type);
|
| 568 |
$result = db_query("SELECT r.rid, r.name FROM {role} r WHERE r.name = '%s'", $role_type);
|
| 569 |
}
|
| 570 |
else {
|
| 571 |
$result = db_query("SELECT r.rid, r.name FROM {role} r");
|
| 572 |
}
|
| 573 |
if ($result) {
|
| 574 |
if ($op == 'base') {
|
| 575 |
return TRUE;
|
| 576 |
}
|
| 577 |
else if ($op == 'get') {
|
| 578 |
$roles = array();
|
| 579 |
if (is_null($role_type)) {
|
| 580 |
while ($role = db_fetch_object($result)) {
|
| 581 |
if ($role->rid > 2) {
|
| 582 |
// take care of spaces for url's
|
| 583 |
$roles[str_replace(' ', '_', $role->name)] = $role->name;
|
| 584 |
}
|
| 585 |
}
|
| 586 |
}
|
| 587 |
else {
|
| 588 |
$roles = db_fetch_object($result);
|
| 589 |
}
|
| 590 |
return $roles;
|
| 591 |
}
|
| 592 |
else if ($op == 'name') {
|
| 593 |
$roles = db_fetch_object($result);
|
| 594 |
return $roles->name;
|
| 595 |
}
|
| 596 |
}
|
| 597 |
else {
|
| 598 |
return FALSE;
|
| 599 |
}
|
| 600 |
}
|