logged_in.module in Util 6.3
Same filename and directory in other branches
Adds a "Logged In As" block.
File
contribs/logged_in/logged_in.moduleView source
<?php
/**
* @file
* Adds a "Logged In As" block.
*/
/**
* Implementation of hook_block().
*/
function logged_in_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
return _logged_in_block_list();
case 'view':
return _logged_in_block_view($delta);
case 'configure':
return _logged_in_block_configure($delta);
case 'save':
_logged_in_block_save($delta, $edit);
break;
}
}
/**
* Get the list of the blocks.
*
* @param
* none.
*
* @return
* array containing the title ("info") of the block.
*/
function _logged_in_block_list() {
$block = array();
$block[0]['info'] = t('Util: Logged in as');
return $block;
}
/**
* Get the output to be displayed by the block.
*
* @param
* $delta - integer for the block number.
*
* @return
* array containing the title ("subject") and content of the block.
*/
function _logged_in_block_view($delta) {
$block = array();
switch ($delta) {
case 0:
$block = array(
'content' => _logged_in_data(),
);
break;
}
return $block;
}
/**
* Get the extra form elements for the block.
*
* @param
* $delta - integer for the block number.
*
* @return
* array containing the extra form elements for the block.
*/
function _logged_in_block_configure($delta) {
drupal_add_css(drupal_get_path('module', 'logged_in') . '/logged_in.css');
$form = array();
$yesno = array(
1 => t('Yes'),
0 => t('No'),
);
switch ($delta) {
case 0:
$form['logged_in'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Logged In Display'),
'#description' => t('Select the options for the display.'),
'#prefix' => '<div id="logged-in-settings">',
'#suffix' => '</div>',
);
$form['logged_in']['show_roles'] = array(
'#type' => 'radios',
'#options' => $yesno,
'#title' => t('Show user roles'),
'#default_value' => (int) variable_get('logged_in_show_roles', 0),
'#suffix' => '<div class="clear-block"></div>',
);
$form['logged_in']['show_perms'] = array(
'#type' => 'radios',
'#options' => $yesno,
'#title' => t('Show permissions'),
'#description' => t('This can be a very lengthy list.'),
'#default_value' => (int) variable_get('logged_in_show_perms', 0),
);
break;
}
return $form;
}
/**
* Process the extra form values for the block.
*
* @param
* $delta - integer for the block number.
* @param
* $edit - entered form values.
*/
function _logged_in_block_save($delta, $edit) {
switch ($delta) {
case 0:
variable_set('logged_in_show_roles', $edit['show_roles']);
variable_set('logged_in_show_perms', $edit['show_perms']);
break;
}
}
function _logged_in_data() {
global $user;
$output = NULL;
$show_roles = variable_get('logged_in_show_roles', 0);
$show_perms = variable_get('logged_in_show_perms', 0);
if ($user->uid) {
$output .= t('You are logged in as !username (@userid).', array(
'!username' => theme('username', $user),
'@userid' => $user->uid,
));
}
else {
$output .= t('You are not logged in.');
}
if ($show_roles) {
if ($user->uid == 1) {
$roles = t('super-user');
}
else {
$roles = implode(', ', $user->roles);
}
$output .= '<br />' . t('Your roles: ') . $roles;
}
if (!$show_perms) {
return $output;
}
if ($uid == 1) {
$perms = array(
'all',
);
}
else {
$result = db_query("SELECT p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (" . db_placeholders($user->roles) . ")", array_keys($user->roles));
$perms = array();
while ($row = db_fetch_object($result)) {
$perms += explode(', ', $row->perm);
}
}
$perms = array_unique($perms);
asort($perms);
$class = count($perms) > 25 ? 'logged-in-xsmall' : 'logged-in-small';
$output .= '<br />' . t('Your permissions: ') . "<div class=\"{$class}\">" . implode(', ', $perms) . '</div>';
return $output;
}
Functions
Name![]() |
Description |
---|---|
logged_in_block | Implementation of hook_block(). |
_logged_in_block_configure | Get the extra form elements for the block. |
_logged_in_block_list | Get the list of the blocks. |
_logged_in_block_save | Process the extra form values for the block. |
_logged_in_block_view | Get the output to be displayed by the block. |
_logged_in_data |