You are here

userloginbar.module in UserLoginBar 5

Same filename and directory in other branches
  1. 8 userloginbar.module
  2. 7 userloginbar.module

File

userloginbar.module
View source
<?php

/*
 * Userloginbar is a module written by developers at Ebizon Technologies (www.ebizontek.com). It is the implementation of http://drupal.org/node/92657#comment-792952. This module creates a new user login bar block.
 */

/**
 * Implementation of hook_menu().
 */
function userloginbar_menu() {
  $items = array();
  $items['admin/settings/userloginbar'] = array(
    'title' => 'UserloginBar Settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'userloginbar_admin',
    ),
    'access arguments' => array(
      'administrator content',
    ),
  );
  return $items;
}

/** implementing the new user login block */
function userloginbar_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks[0]['info'] = t("User Login Bar Block");
    return $blocks;
  }
  elseif ($op == 'view') {
    $block['content'] = theme('userloginbar');
    return $block;
  }
}

/**
 * Implementation of hook_theme()...
 */
function userloginbar_theme() {
  return array(
    'userloginbar' => array(
      'arguments' => array(),
    ),
  );
}

/**
 * Theming function for messages.
 */
function theme_userloginbar() {
  drupal_add_css(drupal_get_path('module', 'userloginbar') . '/userloginbar.css');
  global $user;
  $output = '';
  if (arg(0) == "user" && !is_numeric(arg(1))) {
    return;
  }
  if (!$user->uid) {
    $output .= drupal_get_form('user_login_block');
  }
  else {
    if (!variable_get('disable_welcome_box', FALSE)) {
      $output .= t('<p class="user-info">Hi !user, welcome back.</p>', array(
        '!user' => theme('username', $user),
      ));
      $output .= theme('item_list', array(
        l(t('Your account'), 'user/' . $user->uid, array(
          'title' => t('Edit your account'),
        )),
        l(t('Sign out'), 'logout'),
      ));
    }
  }
  $output = '<div id="user-login-form">' . $output . '</div>';
  return $output;
}
function userloginbar_form_alter(&$form, $form_state, $form_id) {
  global $form_values;
  switch ($form_id) {
    case 'user_login_block':
      $form['#action'] = '?q=user&' . drupal_get_destination();
      $form['#method'] = 'post';
      $form['form_id'] = array(
        '#type' => 'hidden',
        '#default_value' => 'user_login',
      );
      $items = array();
      if (variable_get('user_register', 1)) {
        $items[] = l(t('Register'), 'user/register', array(
          'title' => t('Create a new user account.'),
        )) . ' | &nbsp;';
      }
      $items[] = l(t('Forgot Password?'), 'user/password', array(
        'title' => t('Request new password via e-mail.'),
      ));
      $form['links'] = array(
        '#value' => theme('item_list', $items),
      );
      break;
  }
}
function userloginbar_admin() {
  $form['text'] = array(
    '#type' => 'fieldset',
    '#title' => t('Userloginbar Settings'),
  );
  $form['text']['disable_welcome_box'] = array(
    '#type' => 'checkbox',
    '#title' => t('Check this box, if you want to disable welcome box when the user logs in!'),
    '#default_value' => variable_get('disable_welcome_box', FALSE),
  );
  return system_settings_form($form);
}

Functions

Namesort descending Description
theme_userloginbar Theming function for messages.
userloginbar_admin
userloginbar_block implementing the new user login block
userloginbar_form_alter
userloginbar_menu Implementation of hook_menu().
userloginbar_theme Implementation of hook_theme()...