function login_history_block in Login History 6
Implements hook_block().
File
- ./
login_history.module, line 69
Code
function login_history_block($op = 'list', $delta = '', $edit = array()) {
switch ($op) {
case 'list':
// Show their last login info.
$blocks['login_history_last']['info'] = t("Last login");
$blocks['login_history_last']['cache'] = BLOCK_CACHE_PER_USER;
return $blocks;
case 'view':
switch ($delta) {
case 'login_history_last':
if (user_is_anonymous()) {
return;
}
// Retrieve a list of new users who have subsequently accessed the site successfully.
if ($last_login = login_history_last_login()) {
$hostname = $last_login->hostname == ip_address() ? t('this IP address') : $last_login->hostname;
$user_agent = $last_login->user_agent == $_SERVER['HTTP_USER_AGENT'] ? t('this browser') : $last_login->user_agent;
$output = '<p>' . t('You last logged in from @hostname using @user_agent.', array(
'@hostname' => $hostname,
'@user_agent' => $user_agent,
)) . '</p>';
if (user_access('view own login history')) {
global $user;
$output .= '<span class="read-more">' . t('<a href="@link">View your login history.</a>', array(
'@link' => url('user/' . $user->uid . '/login_history'),
)) . '</span>';
}
$block['subject'] = t('Last login');
$block['content'] = $output;
return $block;
}
}
}
}