You are here

janrain_capture_ui.module in Janrain Registration 7

Same filename and directory in other branches
  1. 6 janrain_capture_ui.module

This module implements UI elements for Janrain Capture

File

janrain_capture_ui.module
View source
<?php

/**
 * @file
 * This module implements UI elements for Janrain Capture
 *
 * @see http://www.janrain.com/products/capture
 */

/**
 * Implements hook_init().
 */
function janrain_capture_ui_init() {

  // Don't do anything if the module settings have not been configured.
  if (!janrain_capture_configured()) {
    return;
  }
  $js_css = janrain_capture_ui_js_css();
  foreach ($js_css as $type => $files) {
    foreach ($files as $name => $filename) {

      // Find the location of the library file and add it using the appropriate
      // function, i.e. drupal_add_js or drupal_add_css.
      $full_path = janrain_capture_ui_get_library_path($name) . '/' . $filename;
      $drupal_add = 'drupal_add_' . $type;
      $drupal_add($full_path, array(
        'every_page' => TRUE,
      ));
    }
  }

  // Finally, add the custom JavaScript.
  drupal_add_js(drupal_get_path('module', 'janrain_capture') . '/janrain_capture_ui.js', array(
    'every_page' => TRUE,
    'weight' => 10,
  ));
}

/**
 * Helper function as a centralized list of JS and CSS files.
 */
function janrain_capture_ui_js_css() {
  $js_css = array(
    'js' => array(
      'fancybox' => 'jquery.fancybox-1.3.4.pack.js',
    ),
    'css' => array(
      'fancybox' => 'jquery.fancybox-1.3.4.css',
    ),
  );
  return $js_css;
}

/**
 * Find the location of library JS and CSS files.
 */
function janrain_capture_ui_get_library_path($name) {
  $lib_paths =& drupal_static(__FUNCTION__, array());
  if (!isset($lib_paths[$name])) {
    $cid = 'janrain_capture_libraries';
    $cache = cache_get($cid);
    if (!empty($cache->data)) {
      $lib_paths = $cache->data;
      if (isset($lib_paths[$name])) {
        return $lib_paths[$name];
      }
    }

    // Use Libraries module, if available, to find the correct path.
    if (function_exists('libraries_get_path')) {
      $lib_path = libraries_get_path($name);
      if (!empty($lib_path)) {
        $lib_paths[$name] = $lib_path;
      }
    }

    // If we still haven't found a path, assume it's at sites/all/libraries
    if (!isset($lib_paths[$name])) {
      $lib_paths[$name] = 'sites/all/libraries/' . $name;
    }
    cache_set($cid, $lib_paths);
  }
  return $lib_paths[$name];
}

/**
 * Implements hook_form_FROM_ID_alter().
 */
function janrain_capture_ui_form_user_profile_form_alter(&$form, &$form_state) {
  global $user;
  if ($form['#user_category'] != 'account') {

    // @todo - should core profile module tabs be blocked?
    return;
  }
  $account = $form['#user'];
  $enforce = variable_get('janrain_capture_enforce', FALSE);
  if ($enforce || janrain_capture_mapping_exists($account->uid)) {

    // Account information.
    $form['account'] = array(
      '#type' => 'fieldset',
      '#weight' => -10,
    );
    if ($user->uid == $account->uid) {
      $link = janrain_capture_profile_link();
      $link['#title'] = t('Edit Profile');
    }
    else {
      $link = array(
        '#markup' => t('Profile managed in Janrain Capture'),
      );
    }
    $form['account']['janrain_capture_profile'] = array(
      '#type' => 'item',
      'link' => $link,
    );
    $form['account']['mail'] = array(
      '#type' => 'item',
      '#title' => t('E-mail address'),
      '#markup' => check_plain($account->mail),
    );
  }
}

/**
 * Implements hook_block_info().
 */
function janrain_capture_ui_block_info() {
  return array(
    'janrain_capture' => array(
      'info' => t('Janrain Capture user login'),
      'cache' => DRUPAL_NO_CACHE,
    ),
  );
}

/**
 * Implements hook_block_view().
 */
function janrain_capture_ui_block_view($delta) {
  if (!janrain_capture_configured()) {
    return array();
  }
  $block = array();
  switch ($delta) {
    case 'janrain_capture':
      $block['subject'] = t('Janrain Capture');
      $block['content'] = janrain_capture_block_content();
      break;
  }
  return $block;
}

Functions

Namesort descending Description
janrain_capture_ui_block_info Implements hook_block_info().
janrain_capture_ui_block_view Implements hook_block_view().
janrain_capture_ui_form_user_profile_form_alter Implements hook_form_FROM_ID_alter().
janrain_capture_ui_get_library_path Find the location of library JS and CSS files.
janrain_capture_ui_init Implements hook_init().
janrain_capture_ui_js_css Helper function as a centralized list of JS and CSS files.