You are here

fancy_login.module in Fancy Login 7.2

File

fancy_login.module
View source
<?php

/**
 * Implementation of hook_menu()
 */
function fancy_login_menu() {
  $menu['admin/config/people/fancy_login'] = array(
    'title' => 'Fancy Login',
    'description' => 'Settings for Fancy Login Page',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'fancy_login_settings',
    ),
    'access arguments' => array(
      'Administer fancy login',
    ),
    'file' => 'fancy_login.pages.inc',
  );
  return $menu;
}

/**
 * Implmentation of hook_permission()
 */
function fancy_login_permission() {
  return array(
    'Administer fancy login' => array(
      'title' => t('Administer fancy login'),
      'description' => t('Allows users to change the settings for the Fancy Login module'),
    ),
  );
}

/**
 * Implementation of hook_forms()
 *
 * Aliases the form: user_login_block()
 * To: fancy_login_user_login_block()
 * so that we can target use/extend this block
 * in our popup using hook_form_alter,
 * leaving the original block unaltered
 */
function fancy_login_forms($form_id, $args) {
  $forms = array();
  if ($form_id == 'fancy_login_user_login_block') {
    $forms['fancy_login_user_login_block'] = array(
      'callback' => 'user_login_block',
    );
  }
  return $forms;
}

/**
 * Implementation of hook_page_build()
 *
 * Adds login form and page dimmer to the footer of the page
 */
function fancy_login_page_build(&$page) {
  if (user_is_anonymous()) {
    $form = drupal_get_form('user_login_block');
    $path = drupal_get_path('module', 'fancy_login');
    $login_path = drupal_get_path_alias('user/login');
    $fl_settings = array(
      'screenFadeColor' => variable_get('screen_fade_color', 'white'),
      'screenFadeZIndex' => variable_get('screen_fade_z_index', '10'),
      'loginBoxWidth' => variable_get('login_box_width', '175px'),
      'loginBoxBackgroundColor' => variable_get('login_box_background_color', 'white'),
      'loginBoxTextColor' => variable_get('login_box_text_color', 'black'),
      'loginBoxBorderColor' => variable_get('login_box_border_color', 'black'),
      'loginBoxBorderWidth' => variable_get('login_box_border_width', '3px'),
      'loginBoxBorderStyle' => variable_get('login_box_border_style', 'solid'),
      'loginPath' => $login_path,
      'dimFadeSpeed' => (int) variable_get('fancy_login_dim_fade_speed', 500),
      'boxFadeSpeed' => (int) variable_get('fancy_login_box_fade_speed', 1000),
      'hideObjects' => variable_get('fancy_login_hide_objects', 0),
    );
    $page['page_bottom']['fancy_login'] = array(
      '#prefix' => '<div id="fancy_login_dim_screen"></div><div id="fancy_login_login_box">',
      '#suffix' => '</div>',
      'form_wrapper' => array(
        '#prefix' => '<div id="fancy_login_form_contents"><a href="#" id="fancy_login_close_button">X</a>',
        '#suffix' => '</div>',
        'form' => drupal_get_form('fancy_login_user_login_block'),
      ),
      '#attached' => array(
        'js' => array(
          array(
            'type' => 'file',
            'data' => $path . '/scripts/fancy_login.js',
          ),
          array(
            'type' => 'setting',
            'data' => array(
              'fancyLogin' => $fl_settings,
            ),
          ),
        ),
        'css' => array(
          array(
            'type' => 'file',
            'data' => $path . '/css/fancy_login.css',
          ),
        ),
      ),
    );
  }
}

/**
 * Implementation of hook_form_alter()
 */
function fancy_login_form_alter(&$form, &$form_state, $form_id) {
  global $base_url;
  if ($form_id == 'fancy_login_user_login_block') {
    foreach (module_implements('form_user_login_block_alter') as $module) {
      $function = $module . '_form_user_login_block_alter';
      $function($form, $form_state);
    }
    $id = 'user_login_block';
    foreach (module_implements('form_alter') as $module) {
      $function = $module . '_form_alter';
      $function($form, $form_state, $id);
    }
    if (variable_get('fancy_login_https', 0)) {
      if (strpos($form['#action'], 'https') !== 0) {
        if (strpos($form['#action'], 'http') === 0) {
          $form['#action'] = preg_replace('/^http/', 'https', $form['#action']);
        }
        elseif (strpos($form['#action'], '//') === 0) {
          $form['#action'] = 'https:' . $form['#action'];
        }
        else {
          $form['#action'] = 'https://' . $form['#action'];
        }
      }
    }
    $icon_position = variable_get('fancy_login_icon_position', 0);
    if ($icon_position) {
      $icon = theme('ssl_icon', array(
        'base_url' => $base_url,
      ));
      $form['ssl_logo'] = array(
        '#markup' => $icon,
      );
      if ($icon_position == 1) {
        $form['ssl_logo']['#weight'] = -100;
        $form['#attributes'] = array(
          'class' => 'ssl_icon_above',
        );
      }
      elseif ($icon_position == 2) {
        $form['ssl_logo']['#weight'] = 100;
        $form['#attributes'] = array(
          'class' => 'ssl_icon_below',
        );
      }
    }

    // Store the current path and set it before all other validation so that
    // any modules (such as Login Destination) that depend on the current
    // path will respond properly
    $form['current_path'] = array(
      '#type' => 'value',
      '#value' => current_path(),
    );
    array_unshift($form['#validate'], 'fancy_login_insert_current_path');
    if (!isset($form['#prefix'])) {
      $form['#prefix'] = '';
    }
    $form['#prefix'] = '<div id="fancy_login_user_login_block_wrapper">';
    $form['#suffix'] = '</div>';
    $form['actions']['submit']['#ajax'] = array(
      'wrapper' => 'fancy_login_user_login_block_wrapper',
      'callback' => 'fancy_login_user_login_block_ajax_callback',
    );
  }
}

/**
 * Insert current path in to $_GET['q'] so that any modules that depend upon it
 * will have the correct path to work with
 */
function fancy_login_insert_current_path($form, &$form_state) {
  $_GET['q'] = $form_state['values']['current_path'];
}

/**
 * Ajax callback function for user_login_block submit button
 */
function fancy_login_user_login_block_ajax_callback($form, &$form_state) {
  global $destination;
  $commands = array();
  $form = render($form);
  $message_data = drupal_get_messages(NULL, FALSE);
  if (!count($message_data['error'])) {
    if (variable_get('fancy_login_no_redirect', 0)) {
      drupal_set_message(t('You have been successfully logged in. Please wait the page is refreshed.'));
      $commands[] = array(
        'command' => 'fancyLoginRefreshPage',
        'closePopup' => TRUE,
      );
    }
    else {
      drupal_set_message(t('You have been successfully logged in. Please wait while you are redirected.'));
      $dest = $destination && is_array($destination) && isset($destination[0]) ? $destination[0] : $form_state['redirect'];
      $commands[] = array(
        'command' => 'fancyLoginRedirect',
        'closePopup' => TRUE,
        'destination' => url($dest),
      );
    }
  }
  $messages = theme('status_messages');
  $commands[] = ajax_command_replace(NULL, $messages . $form);
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}

/**
 * Implementation of hook_block_info()
 */
function fancy_login_block_info() {
  $blocks['fancy_login_login_block'] = array(
    'info' => t('Fancy Login Link'),
    'cache' => DRUPAL_CACHE_PER_ROLE,
  );
  return $blocks;
}

/**
 * Implementation of hook_block_view()
 */
function fancy_login_block_view($delta = '') {
  if ($delta == 'fancy_login_login_block') {
    if (user_is_anonymous()) {
      $block['subject'] = t('Login');
      $block['content'] = array(
        'link' => array(
          '#markup' => l(t('Login'), 'user/login'),
          '#prefix' => '<div id="fancy_login_login_link_wrapper">',
          '#suffix' => '</div>',
        ),
      );
      return $block;
    }
  }
}

/**
 * Implementation of hook_theme()
 */
function fancy_login_theme() {
  $path = drupal_get_path('module', 'fancy_login');
  return array(
    'ssl_icon' => array(
      'arguments' => array(
        'base_url' => NULL,
      ),
      'path' => $path . '/templates',
      'template' => 'ssl-icon',
    ),
  );
}

Functions

Namesort descending Description
fancy_login_block_info Implementation of hook_block_info()
fancy_login_block_view Implementation of hook_block_view()
fancy_login_forms Implementation of hook_forms()
fancy_login_form_alter Implementation of hook_form_alter()
fancy_login_insert_current_path Insert current path in to $_GET['q'] so that any modules that depend upon it will have the correct path to work with
fancy_login_menu Implementation of hook_menu()
fancy_login_page_build Implementation of hook_page_build()
fancy_login_permission Implmentation of hook_permission()
fancy_login_theme Implementation of hook_theme()
fancy_login_user_login_block_ajax_callback Ajax callback function for user_login_block submit button