om_tools.module in OM Tools 6
Same filename and directory in other branches
This is a collection of OM Tools.
File
om_tools.moduleView source
<?php
/**
* @file
* This is a collection of OM Tools.
*/
/**
* Implementation of hook_menu().
*
*/
function om_tools_menu() {
$items = array();
$items['admin/settings/om_tools'] = array(
'title' => t('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' => t(''),
);
$items['user/login-register'] = array(
'title' => t(''),
'page callback' => 'user_login_register',
'access callback' => 'user_access',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'description' => t(''),
);
return $items;
}
/**
* Implementation of hook_perm().
*
*/
function om_tools_perm() {
return array(
'administer OM Tools',
);
}
/**
* User Login and Register page.
*
*/
function user_login_register() {
$login_title = variable_get('om_tools_user_login_title', 'Log In');
$register_title = variable_get('om_tools_user_register_title', 'Register');
$out = '';
$out .= '<table class="user-login-register"><tr><td class="user-login-col">';
$out .= '<h2 class="login-title">' . $login_title . '</h2>';
$out .= drupal_get_form('user_login');
$out .= '</td><td class="user-register-col">';
$out .= '<h2 class="login-title">' . $register_title . '</h2>';
$out .= drupal_get_form('user_register');
$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_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);
}
}
}
/**
* Override or insert om variables into the templates.
*/
function om_tools_preprocess_block(&$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_block';
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));
}
/**
* Mediaqueries
* http://plugins.jquery.com/project/MediaQueries
*
* - rename jquery.mediaqueries.js to mediaqueries.js
*
*/
if (variable_get('om_tools_system_switch', 0)) {
drupal_add_js(drupal_get_path('module', 'om_tools') . '/contrib/mediaqueries.js', 'module');
}
Functions
Name | 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_perm | Implementation of hook_perm(). |
om_tools_preprocess_block | Override or insert om variables into the templates. |
om_tools_preprocess_page | Override or insert om variables into the templates. |
om_tools_settings | OM Tools requires tools dynamically |
user_login_register | User Login and Register page. |