Révision 3461d8cb
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/masquerade/masquerade.module | ||
---|---|---|
370 | 370 |
} |
371 | 371 |
} |
372 | 372 |
|
373 |
/** |
|
374 |
* Implements hook_field_extra_fields(). |
|
375 |
*/ |
|
376 |
function masquerade_field_extra_fields() { |
|
377 |
$return['user']['user'] = array( |
|
378 |
'form' => array( |
|
379 |
'masquerade' => array( |
|
380 |
'label' => t('Masquerade'), |
|
381 |
'description' => t('User masquerade settings.'), |
|
382 |
'weight' => 50, |
|
383 |
), |
|
384 |
), |
|
385 |
'display' => array( |
|
386 |
'masquerade' => array( |
|
387 |
'label' => t('Masquerade'), |
|
388 |
'description' => t('Masquerade as user link.'), |
|
389 |
'weight' => 50, |
|
390 |
), |
|
391 |
), |
|
392 |
); |
|
393 |
|
|
394 |
return $return; |
|
395 |
} |
|
396 |
|
|
373 | 397 |
/** |
374 | 398 |
* Implements hook_user_view(). |
375 | 399 |
*/ |
... | ... | |
382 | 406 |
|
383 | 407 |
global $user; |
384 | 408 |
|
385 |
if (user_access($perm) && empty($account->masquerading) && $user->uid != $account->uid) { |
|
409 |
// Query allowed uids so the "masquerade as <user>" link can be shown or |
|
410 |
// hidden. |
|
411 |
$allowed_uids = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid)) |
|
412 |
->fetchCol(); |
|
413 |
|
|
414 |
if (user_access($perm) && empty($account->masquerading) && $user->uid != $account->uid && in_array($account->uid, $allowed_uids)) { |
|
386 | 415 |
$account->content['masquerade'] = array( |
387 | 416 |
'#markup' => l(t('Masquerade as !user', array('!user' => $account->name)), |
388 | 417 |
'masquerade/switch/' . $account->uid, |
389 | 418 |
array('query' => array( |
390 | 419 |
'token' => drupal_get_token('masquerade/switch/' . $account->uid)), |
391 | 420 |
'destination' => $_GET['q'], |
392 |
'attributes' => array('class' => 'masquerade-switch'),
|
|
421 |
'attributes' => array('class' => array('masquerade-switch')),
|
|
393 | 422 |
)), |
394 | 423 |
'#weight' => 10, |
395 | 424 |
); |
... | ... | |
616 | 645 |
global $user; |
617 | 646 |
//unset($form); |
618 | 647 |
$name = $form_state['values']['masquerade_user_field']; |
648 |
$allowed = FALSE; |
|
649 |
$to_uid = db_select('users', 'u') |
|
650 |
->fields('u', array('uid')) |
|
651 |
->condition('u.name', $name, '=') |
|
652 |
->execute() |
|
653 |
->fetchField(); |
|
654 |
if ($to_uid !== FALSE) { |
|
655 |
$allowed = db_select('masquerade_users', 'm') |
|
656 |
->fields('m', array('uid_to')) |
|
657 |
->condition('m.uid_to', $to_uid, '=') |
|
658 |
->condition('m.uid_from', $user->uid, '=') |
|
659 |
->execute() |
|
660 |
->fetchField(); |
|
661 |
} |
|
619 | 662 |
if (isset($_SESSION['masquerading'])) { |
620 | 663 |
form_set_error('masquerade_user_field', t('You are already masquerading. Please <a href="@unswitch">switch back</a> to your account to masquerade as another user.', array('@unswitch' => url('masquerade/unswitch', array('query' => array('token' => drupal_get_token('masquerade/unswitch'))))))); |
621 | 664 |
} |
665 |
if ($allowed === FALSE) { |
|
666 |
form_set_error('masquerade_user_field', t('You are not allowed to masquerade as the selected user.')); |
|
667 |
} |
|
668 |
|
|
622 | 669 |
if ($name != variable_get('anonymous', t('Anonymous')) && module_exists('alt_login')) { |
623 | 670 |
$alt_login = db_query("SELECT u.name FROM {users} u INNER JOIN {alt_login} al ON u.uid = al.uid WHERE al.alt_login = :alt_login", array( |
624 | 671 |
':alt_login' => $name |
625 | 672 |
))->fetchObject(); |
626 |
if ($alt_login->name) {
|
|
673 |
if (isset($alt_login->name)) {
|
|
627 | 674 |
$name = $alt_login->name; |
628 | 675 |
} |
629 | 676 |
} |
... | ... | |
840 | 887 |
':uid_as' => $user->uid, |
841 | 888 |
))->fetchField(); |
842 | 889 |
// erase record |
843 |
$conditions = db_or(); |
|
844 |
$conditions->condition('sid', session_id()); |
|
845 |
$conditions->condition('uid_as', $user->uid); |
|
846 |
$query = db_delete('masquerade'); |
|
847 |
$query->condition($conditions); |
|
848 |
$query->execute(); |
|
890 |
db_delete('masquerade') |
|
891 |
->condition('sid', session_id()) |
|
892 |
->condition('uid_as', $user->uid) |
|
893 |
->execute(); |
|
894 |
|
|
849 | 895 |
$oldname = ($user->uid == 0 ? variable_get('anonymous', t('Anonymous')) : $user->name); |
850 | 896 |
|
851 | 897 |
// Call logout hooks when switching from masquerading user. |
Formats disponibles : Unified diff
Weekly update of contrib modules