| 1 |
<?php |
<?php |
| 2 |
// $Id: invite.module,v 1.25.2.7 2009/10/04 12:34:24 smk Exp $ |
// $Id: invite.module,v 1.25.2.8 2009/10/04 12:43:37 smk Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 175 |
$items['user/%user/invites'] = array( |
$items['user/%user/invites'] = array( |
| 176 |
'title' => 'Invitations', |
'title' => 'Invitations', |
| 177 |
'page callback' => 'invite_user_overview', |
'page callback' => 'invite_user_overview', |
| 178 |
'access callback' => 'invite_access_callback', |
'access callback' => 'invite_user_access', |
| 179 |
'access arguments' => array('track invitations', 1), |
'access arguments' => array('track invitations', 1), |
| 180 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 181 |
'file' => 'invite_admin.inc', |
'file' => 'invite_admin.inc', |
| 184 |
'title' => 'Accepted', |
'title' => 'Accepted', |
| 185 |
'page callback' => 'invite_user_overview', |
'page callback' => 'invite_user_overview', |
| 186 |
'page arguments' => array('accepted'), |
'page arguments' => array('accepted'), |
| 187 |
'access callback' => 'invite_access_callback', |
'access callback' => 'invite_user_access', |
| 188 |
'access arguments' => array('track invitations', 1), |
'access arguments' => array('track invitations', 1), |
| 189 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 190 |
'weight' => -5, |
'weight' => -5, |
| 194 |
'title' => 'Pending', |
'title' => 'Pending', |
| 195 |
'page callback' => 'invite_user_overview', |
'page callback' => 'invite_user_overview', |
| 196 |
'page arguments' => array('pending'), |
'page arguments' => array('pending'), |
| 197 |
'access callback' => 'invite_access_callback', |
'access callback' => 'invite_user_access', |
| 198 |
'access arguments' => array('track invitations', 1), |
'access arguments' => array('track invitations', 1), |
| 199 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 200 |
'file' => 'invite_admin.inc', |
'file' => 'invite_admin.inc', |
| 203 |
'title' => 'Expired', |
'title' => 'Expired', |
| 204 |
'page callback' => 'invite_user_overview', |
'page callback' => 'invite_user_overview', |
| 205 |
'page arguments' => array('expired'), |
'page arguments' => array('expired'), |
| 206 |
'access callback' => 'invite_access_callback', |
'access callback' => 'invite_user_access', |
| 207 |
'access arguments' => array('track invitations', 1), |
'access arguments' => array('track invitations', 1), |
| 208 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 209 |
'weight' => 5, |
'weight' => 5, |
| 213 |
'title' => 'New invitation', |
'title' => 'New invitation', |
| 214 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 215 |
'page arguments' => array('invite_form', 'page', array()), |
'page arguments' => array('invite_form', 'page', array()), |
| 216 |
'access callback' => 'invite_access_callback', |
'access callback' => 'invite_user_access', |
| 217 |
'access arguments' => array('send invitations', 1), |
'access arguments' => array('send invitations', 1), |
| 218 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 219 |
'weight' => 10, |
'weight' => 10, |
| 223 |
} |
} |
| 224 |
|
|
| 225 |
/** |
/** |
| 226 |
|
* Implementation of hook_menu_alter(). |
| 227 |
|
* |
| 228 |
|
* Override the user/register menu access handler with a custom |
| 229 |
|
* implementation. |
| 230 |
|
*/ |
| 231 |
|
function invite_menu_alter(&$items) { |
| 232 |
|
if (invite_user_registration_by_invite_only()) { |
| 233 |
|
$items['user/register']['access callback'] = 'invite_user_register_access'; |
| 234 |
|
} |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
/** |
| 238 |
|
* Determine if user registration mode is set to invite only. |
| 239 |
|
*/ |
| 240 |
|
function invite_user_registration_by_invite_only() { |
| 241 |
|
return (variable_get('user_register', 1) === '1-inviteonly'); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
/** |
| 245 |
|
* Access callback; determine access to user registration form. |
| 246 |
|
*/ |
| 247 |
|
function invite_user_register_access() { |
| 248 |
|
$invite = invite_load_from_session(); |
| 249 |
|
|
| 250 |
|
// Legacy url support (user/register/regcode). |
| 251 |
|
if (!$invite && $code = arg(2)) { |
| 252 |
|
if ($invite = invite_load($code)) { |
| 253 |
|
if (invite_validate($invite)) { |
| 254 |
|
$_SESSION[INVITE_SESSION] = $invite->reg_code; |
| 255 |
|
} |
| 256 |
|
} |
| 257 |
|
} |
| 258 |
|
if (!$invite && !user_access('administer users')) { |
| 259 |
|
drupal_set_message(t('Sorry, new user registration by invitation only.')); |
| 260 |
|
return FALSE; |
| 261 |
|
} |
| 262 |
|
|
| 263 |
|
// Let the default handler take care of standard conditions. |
| 264 |
|
return user_register_access(); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
/** |
| 268 |
* Title callback allowing for customization of the invite page title. |
* Title callback allowing for customization of the invite page title. |
| 269 |
* |
* |
| 270 |
* @param $title |
* @param $title |
| 292 |
* @param $account |
* @param $account |
| 293 |
* A user object. |
* A user object. |
| 294 |
*/ |
*/ |
| 295 |
function invite_access_callback($permission, $account) { |
function invite_user_access($permission, $account) { |
| 296 |
return ($account->uid == $GLOBALS['user']->uid && user_access($permission)); |
return ($account->uid == $GLOBALS['user']->uid && user_access($permission)); |
| 297 |
} |
} |
| 298 |
|
|
| 336 |
function invite_form_alter(&$form, $form_state, $form_id) { |
function invite_form_alter(&$form, $form_state, $form_id) { |
| 337 |
switch ($form_id) { |
switch ($form_id) { |
| 338 |
case 'user_admin_settings': |
case 'user_admin_settings': |
| 339 |
// Add new registration mode. |
// Add new registration mode 'by invitation only'. By prepending the |
| 340 |
// We prepend the option value with a numeric value to make 3rd party |
// option value with a numeric value, other modules still work as |
| 341 |
// modules like LoginToboggan act like expected. This works because |
// expected, as long as they are using the non-strict PHP comparison |
| 342 |
// checking for ('1-inviteonly' == 1) returns TRUE. To reliably determine |
// operator (since '1-inviteonly' == 1 yields TRUE). To determine the real |
| 343 |
// the variable value later, we need to use the strict equality operator |
// setting use invite_user_registration_by_invite_only(). |
| 344 |
// (===). |
// |
| 345 |
$form['registration']['user_register']['#options']['1-inviteonly'] = t('New user registration by invitation only.'); |
// However, setting the new mode is only allowed if no other module |
| 346 |
|
// has overridden the menu access handler for the user registration form. |
| 347 |
|
$item = menu_get_item('user/register'); |
| 348 |
|
if (in_array($item['access_callback'], array('user_register_access', 'invite_user_register_access'))) { |
| 349 |
|
$form['registration']['user_register']['#options']['1-inviteonly'] = t('New user registration by invitation only.'); |
| 350 |
|
} |
| 351 |
|
// Clear menu cache on submit to allow our custom access handler to |
| 352 |
|
// snap in. |
| 353 |
|
$form['#submit'][] = 'menu_rebuild'; |
| 354 |
break; |
break; |
| 355 |
|
|
| 356 |
case 'user_register': |
case 'user_register': |
| 368 |
} |
} |
| 369 |
} |
} |
| 370 |
} |
} |
|
|
|
| 371 |
if ($invite) { |
if ($invite) { |
| 372 |
// Preset the e-mail field. |
// Preset the e-mail field. |
| 373 |
if (isset($form['account'])) { |
if (isset($form['account'])) { |
| 380 |
$field['mail']['#default_value'] = $invite->email; |
$field['mail']['#default_value'] = $invite->email; |
| 381 |
} |
} |
| 382 |
} |
} |
|
else if (variable_get('user_register', 1) === '1-inviteonly' && !user_access('administer users')) { |
|
|
drupal_set_message(t('Sorry, new user registration by invitation only.')); |
|
|
drupal_goto(); |
|
|
} |
|
| 383 |
break; |
break; |
| 384 |
|
|
| 385 |
case 'user_login_block': |
case 'user_login_block': |
| 386 |
// Remove temptation for non members to try and register. |
// Remove temptation for non members to try and register. |
| 387 |
if (variable_get('user_register', 1) === '1-inviteonly') { |
if (invite_user_registration_by_invite_only()) { |
| 388 |
$new_items = array(); |
$new_items = array(); |
| 389 |
$new_items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); |
$new_items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); |
| 390 |
$form['links']['#value'] = theme('item_list', $new_items); |
$form['links']['#value'] = theme('item_list', $new_items); |
| 1312 |
* Implementation of hook_disable(). |
* Implementation of hook_disable(). |
| 1313 |
*/ |
*/ |
| 1314 |
function invite_disable() { |
function invite_disable() { |
| 1315 |
if (variable_get('user_register', 1) === '1-inviteonly') { |
if (invite_user_registration_by_invite_only()) { |
| 1316 |
variable_set('user_register', 1); |
variable_set('user_register', 1); |
| 1317 |
drupal_set_message(t('User registration option reset to %no_approval.', array('%no_approval' => t('Visitors can create accounts and no administrator approval is required.')))); |
drupal_set_message(t('User registration option reset to %no_approval.', array('%no_approval' => t('Visitors can create accounts and no administrator approval is required.')))); |
| 1318 |
} |
} |