function masquerade_block_1 in Masquerade 7
Same name and namespace in other branches
- 5 masquerade.module \masquerade_block_1()
- 6 masquerade.module \masquerade_block_1()
Masquerade block form.
1 string reference to 'masquerade_block_1'
- masquerade_block_view in ./
masquerade.module - Implements hook_block_view().
File
- ./
masquerade.module, line 584 - The masquerade module allows administrators to masquerade as other user.
Code
function masquerade_block_1() {
global $user;
$quick_switch_links = array();
$markup_value = '';
if (isset($_SESSION['masquerading'])) {
$quick_switch_links[] = l(t('Switch back'), 'masquerade/unswitch', array(
'query' => array(
'token' => drupal_get_token('masquerade/unswitch'),
),
));
if ($user->uid > 0) {
$markup_value = t('You are masquerading as <a href="@user-url">%masq_as</a>.', array(
'@user-url' => url('user/' . $user->uid),
'%masq_as' => $user->name,
));
}
else {
$markup_value = t('You are masquerading as %anonymous.', array(
'%anonymous' => variable_get('anonymous', t('Anonymous')),
));
}
}
else {
$quick_switches = variable_get('masquerade_quick_switches', array());
// Add in user-specific switches, and prevent duplicates.
$user_switches = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array(
':uid_from' => $user->uid,
))
->fetchCol();
$masquerade_switches = array_unique(array_merge($quick_switches, $user_switches));
foreach ($masquerade_switches as $switch_user) {
if (!isset($_SESSION['user']->uid) || $switch_user != $_SESSION['user']->uid) {
$account = user_load($switch_user);
if (isset($account->uid)) {
$switch_link = 'masquerade/switch/' . $account->uid;
if ($account->uid) {
$quick_switch_links[] = l($account->name, $switch_link, array(
'query' => array(
'token' => drupal_get_token($switch_link),
),
));
}
if ($switch_user == 0) {
$account->name = variable_get('anonymous', t('Anonymous'));
$quick_switch_links[] = l($account->name, $switch_link, array(
'query' => array(
'token' => drupal_get_token($switch_link),
),
));
}
}
}
}
if (masquerade_menu_access('autocomplete')) {
$markup_value .= t('Enter the username to masquerade as.');
$form['masquerade_user_field'] = array(
'#prefix' => '<div class="container-inline">',
'#type' => 'textfield',
'#size' => '18',
'#default_value' => '',
'#autocomplete_path' => 'masquerade/autocomplete',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Go'),
'#suffix' => '</div>',
);
}
}
if ($quick_switch_links) {
$markup_value .= '<div id="quick_switch_links">' . t('Quick switches:') . theme('item_list', array(
'items' => $quick_switch_links,
)) . '</div>';
}
$form['masquerade_desc'] = array(
'#prefix' => '<div class="form-item"><div class="description">',
'#markup' => $markup_value,
'#suffix' => '</div></div>',
);
return $form;
}