You are here

om_tools.module in OM Tools 7

This is a collection of OM Tools.

File

om_tools.module
View source
<?php

/**
 * @file
 * This is a collection of OM Tools.
 */

/**
 * Implementation of hook_menu().
 *
 */
function om_tools_menu() {
  $items = array();
  $items['admin/config/system/om_tools'] = array(
    'title' => 'OM Tools',
    'page callback' => 'drupal_get_form',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer om tools',
    ),
    'page arguments' => array(
      'om_tools_admin',
    ),
    'type' => MENU_NORMAL_ITEM,
    'description' => 'Form Overrides and Other Utilities',
  );
  $items['user/login-register'] = array(
    'title' => '',
    'page callback' => 'user_login_register',
    'access callback' => 'user_access',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
    'description' => '',
  );
  return $items;
}

/**
 * Implementation of hook_perm().
 *
 */
function om_tools_permission() {
  return array(
    'administer om tools' => array(
      'title' => t('Administer OM Tools'),
      'description' => t('Perform administration tasks for OM Tools.'),
    ),
  );
}

/**
 * User Login and Register page.
 *
 */
function user_login_register() {
  $login_title = variable_get('om_tools_user_login_title', 'User Login');
  $login_form = drupal_get_form('user_login');
  $register_title = variable_get('om_tools_user_register_title', 'User Register');
  $register_form = drupal_get_form('user_register_form');
  $out = '';
  $out .= '<table class="user-login-register"><tr><td class="user-login-col">';
  $out .= '<h2 class="login-title">' . $login_title . '</h2>';
  $out .= drupal_render($login_form);
  $out .= '</td><td class="user-register-col">';
  $out .= '<h2 class="login-title">' . $register_title . '</h2>';
  $out .= drupal_render($register_form);
  $out .= '</td></tr></table>';
  drupal_set_title(t(''));
  return $out;
}

/**
 * Admin Forms
 *
 */
function om_tools_admin() {
  drupal_set_title(t('OM Tools Settings'));
  $tools = om_tools_get();
  $form = array();
  foreach ($tools as $key => $tool_name) {
    om_tools_settings($form, $tool_name);
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Settings'),
  );
  return $form;
}

/**
 * Submit
 *
 */
function om_tools_admin_submit($form, $form_state) {
  $form_values = $form_state['values'];
  foreach ($form_values as $key => $value) {
    variable_set('om_tools_' . $key, $value);
  }
  drupal_set_message(t('Your settings has been saved.'));
}

/**
 * Implementation of hook_form_alter().
 *
 * @param $form
 * @param $form_state
 * @param $form_id
 * @return array()
 */
function om_tools_form_alter(&$form, &$form_state, $form_id) {
  $tools = om_tools_get();
  foreach ($tools as $key => $tool_name) {
    include_once drupal_get_path('module', 'om_tools') . '/tools/' . $tool_name . '/' . $tool_name . '.inc';
    $function = 'om_' . $tool_name . '_alter';
    if (function_exists($function)) {
      $function($form, $form_state, $form_id);
    }
  }
}

/**
 * Override or insert om variables into the templates.
 */
function om_tools_preprocess_html(&$vars) {
  $tools = om_tools_get();
  foreach ($tools as $key => $tool_name) {
    include_once drupal_get_path('module', 'om_tools') . '/tools/' . $tool_name . '/' . $tool_name . '.inc';
    $function = 'om_' . $tool_name . '_preprocess_html';
    if (function_exists($function)) {
      $function($vars);
    }
  }
}

/**
 * Override or insert om variables into the templates.
 */
function om_tools_process_html(&$vars) {
  $tools = om_tools_get();
  foreach ($tools as $key => $tool_name) {
    include_once drupal_get_path('module', 'om_tools') . '/tools/' . $tool_name . '/' . $tool_name . '.inc';
    $function = 'om_' . $tool_name . '_process_html';
    if (function_exists($function)) {
      $function($vars);
    }
  }
}

/**
 * Override or insert om variables into the templates.
 */
function om_tools_preprocess_page(&$vars) {
  $tools = om_tools_get();
  foreach ($tools as $key => $tool_name) {
    include_once drupal_get_path('module', 'om_tools') . '/tools/' . $tool_name . '/' . $tool_name . '.inc';
    $function = 'om_' . $tool_name . '_preprocess_page';
    if (function_exists($function)) {
      $function($vars);
    }
  }
}

/**
 * OM Tools requires tools dynamically
 *
 */
function om_tools_settings(&$form, $module = NULL) {
  if (module_exists($module)) {
    include_once drupal_get_path('module', 'om_tools') . '/tools/' . $module . '/' . $module . '.inc';
    $function = 'om_' . $module;
    if (function_exists($function)) {
      return $function($form);
    }
  }
}

/**
 * OM Tools get file names from /tools directory
 * - reads directory names
 */
function om_tools_get() {
  $files = array();
  $dir = drupal_get_path('module', 'om_tools') . '/tools/';
  $folders = scandir($dir);
  $excluded_files = array(
    '.',
    '..',
    '.cvs',
    '.svn',
    '.git',
  );
  foreach ($folders as $key => $val) {
    if (!in_array($val, $excluded_files)) {
      is_dir($dir . $val) ? $files[] = $val : '';
    }
  }
  return $files;
}

/**
 * Safe classes
 */
function om_tools_class_safe($string) {

  // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
  return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
}

Functions

Namesort descending Description
om_tools_admin Admin Forms
om_tools_admin_submit Submit
om_tools_class_safe Safe classes
om_tools_form_alter Implementation of hook_form_alter().
om_tools_get OM Tools get file names from /tools directory
om_tools_menu Implementation of hook_menu().
om_tools_permission Implementation of hook_perm().
om_tools_preprocess_html Override or insert om variables into the templates.
om_tools_preprocess_page Override or insert om variables into the templates.
om_tools_process_html Override or insert om variables into the templates.
om_tools_settings OM Tools requires tools dynamically
user_login_register User Login and Register page.