View source
<?php
function clientside_validation_enable() {
db_update('system')
->fields(array(
'weight' => 5,
))
->condition('type', 'module')
->condition('name', 'clientside_validation')
->execute();
}
function clientside_validation_schema() {
$schema = array();
$schema['clientside_validation_settings'] = array(
'description' => 'Table for storing Clientside Validation Settings',
'fields' => array(
'cvsid' => array(
'description' => 'The primary identifier for the clientside validation settings',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The type of setting: content_type, webform or custom',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'The status for this form. 1 for enabled (validate), 0 for disabled (don\'t validate)',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'form_id' => array(
'description' => 'The form id these settings apply to',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'translatable' => TRUE,
'serialize' => TRUE,
),
),
'indexes' => array(
'clientside_validation_settings_form_id' => array(
'form_id',
),
'clientside_validation_settings_type' => array(
'type',
),
'clientside_validation_settings_form_id_type' => array(
'form_id',
'type',
),
),
'unique keys' => array(
'cvs_form_id' => array(
'form_id',
),
),
'primary key' => array(
'cvsid',
),
);
return $schema;
}
function clientside_validation_uninstall() {
$variables = array(
'clientside_validation_default_settings',
'clientside_validation_filter_paths',
'clientside_validation_override_jquery_form',
'clientside_validation_path_list',
'clientside_validation_use_minified',
'clientside_validation_validate_all',
'clientside_validation_validate_specific',
'clientside_validation_usexregxp',
'clientside_validation_xregxp_variant',
);
foreach ($variables as $name) {
variable_del($name);
}
}
function clientside_validation_install() {
$paths = array(
'admin/structure/views/*',
);
variable_set('clientside_validation_path_list', implode("\n", $paths));
}
function clientside_validation_update_7100() {
module_enable(array(
'clientside_validation_form',
'clientside_validation_webform',
));
}
function clientside_validation_update_7101() {
if (!db_table_exists('clientside_validation_settings')) {
$schema['clientside_validation_settings'] = array(
'description' => 'Table for storing Clientside Validation Settings',
'fields' => array(
'cvsid' => array(
'description' => 'The primary identifier for the clientside validation settings',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The type of setting: content_type, webform or custom',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'The status for this form. 1 for enabled (validate), 0 for disabled (don\'t validate)',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'form_id' => array(
'description' => 'The form id these settings apply to',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'translatable' => TRUE,
),
),
'indexes' => array(
'clientside_validation_settings_form_id' => array(
'form_id',
),
'clientside_validation_settings_type' => array(
'type',
),
'clientside_validation_settings_form_id_type' => array(
'form_id',
'type',
),
),
'unique keys' => array(
'cvs_form_id' => array(
'form_id',
),
),
'primary key' => array(
'cvsid',
),
);
db_create_table('clientside_validation_settings', $schema['clientside_validation_settings']);
}
$default_settings = array(
'validate_options' => array(
'disable_html5' => variable_get('clientside_validation_disable_html5', 1),
'validate_onsubmit' => variable_get('clientside_validation_validate_onsubmit', 1),
'validate_onblur' => variable_get('clientside_validation_validate_onblur', 1),
'validate_onblur_always' => variable_get('clientside_validation_validate_onblur_always', 0),
'validate_onkeyup' => variable_get('clientside_validation_validate_onkeyup', 1),
'show_messages' => variable_get('clientside_validation_show_messages', 0),
),
'error' => array(
'prefix' => variable_get('clientside_validation_prefix', ''),
'suffix' => variable_get('clientside_validation_suffix', ''),
'scrollto_errormessage' => variable_get('clientside_validation_scrollto_errormessage', 1),
'scroll_speed' => variable_get('clientside_validation_scroll_speed', 1000),
'error_element' => variable_get('clientside_validation_error_element', 'label'),
),
'error_placement' => array(
'error_placement_default' => variable_get('clientside_validation_error_placement_default', CLIENTSIDE_VALIDATION_TOP_OF_FORM),
'jquery_selector' => variable_get('clientside_validation_jquery_selector', ''),
'custom_error_function' => variable_get('clientside_validation_custom_error_function', ''),
),
'include_hidden' => array(
'include_hidden' => variable_get('clientside_validation_include_hidden', ''),
'include_hidden_fields' => FALSE,
'validate_tabs' => variable_get('clientside_validation_validate_tabs', ''),
),
);
variable_set('clientside_validation_default_settings', $default_settings);
$after_input = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_after_input', ''), -1, PREG_SPLIT_NO_EMPTY);
foreach ($after_input as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_AFTER_INPUT;
_clientside_validation_update_7101_save($formid, $settings);
}
$after_label = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_after_label', ''), -1, PREG_SPLIT_NO_EMPTY);
foreach ($after_label as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_AFTER_LABEL;
_clientside_validation_update_7101_save($formid, $settings);
}
$before_input = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_before_input', ''), -1, PREG_SPLIT_NO_EMPTY);
foreach ($before_input as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_BEFORE_INPUT;
_clientside_validation_update_7101_save($formid, $settings);
}
$before_label = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_before_label', ''), -1, PREG_SPLIT_NO_EMPTY);
foreach ($before_label as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_BEFORE_LABEL;
_clientside_validation_update_7101_save($formid, $settings);
}
$custom_function = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_custom_function', ''), -1, PREG_SPLIT_NO_EMPTY);
foreach ($custom_function as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_CUSTOM_ERROR_FUNCTION;
_clientside_validation_update_7101_save($formid, $settings);
}
$jquery = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_jquery', ''), -1, PREG_SPLIT_NO_EMPTY);
$jquery_selector = variable_get('clientside_validation_jquery_selector', '');
if (!empty($jquery_selector)) {
foreach ($jquery as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_JQUERY_SELECTOR;
_clientside_validation_update_7101_save($formid, $settings);
}
}
$top_of_form = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_top_of_form', ''), -1, PREG_SPLIT_NO_EMPTY);
foreach ($after_input as $formid) {
$settings = $default_settings;
$settings['error_placement_override_default'] = TRUE;
$settings['error_placement']['error_placement_default'] = CLIENTSIDE_VALIDATION_TOP_OF_FORM;
_clientside_validation_update_7101_save($formid, $settings);
}
}
function _clientside_validation_update_7101_save($formid, $settings) {
static $contenttypes;
$saved = FALSE;
if (!$contenttypes) {
$contenttypes = node_type_get_types();
}
$formid = str_replace('-', '_', $formid);
if (strpos($formid, 'webform_client_form_') !== FALSE) {
$nid = str_replace('webform_client_form_', '', $formid);
if (is_numeric($nid)) {
clientside_validation_settings_add('webforms', $nid, $settings, TRUE);
$saved = TRUE;
}
}
if (strpos($formid, '_node_form') !== FALSE) {
$type = str_replace('_node_form', '', $formid);
if (is_string($type) && array_key_exists($type, $contenttypes)) {
clientside_validation_settings_add('content-types', $type, $settings, TRUE);
$saved = TRUE;
}
}
if (!$saved) {
clientside_validation_settings_add('custom-forms', $formid, $settings, TRUE);
}
}
function clientside_validation_update_7102() {
$dependants = array(
'clientside_validation_fapi',
'clientside_validation_field_validation',
'clientside_validation_html5',
'clientside_validation_ife',
'clientside_validation_webform',
);
foreach ($dependants as $dependant) {
if (module_exists($dependant) && !module_exists('clientside_validation_form')) {
module_enable(array(
'clientside_validation_form',
));
break;
}
}
}
function clientside_validation_update_7103() {
$default_settings_db = variable_get('clientside_validation_default_settings', FALSE);
if (!$default_settings_db) {
return;
}
module_load_include('module', 'clientside_validation', 'clientside_validation');
$default_settings = clientside_validation_settings_load_defaults();
if (!isset($default_settings['validate_options']['captcha'])) {
$default_settings['validate_options']['captcha'] = 1;
}
variable_set('clientside_validation_default_settings', $default_settings);
}
function clientside_validation_update_7104() {
$paths = explode("\n", variable_get('clientside_validation_path_list', ''));
if (array_search('admin/structure/views/view/*', $paths) === FALSE) {
$paths[] = 'admin/structure/views/view/*';
}
variable_set('clientside_validation_path_list', implode("\n", $paths));
}
function clientside_validation_update_7105() {
$paths = explode("\n", variable_get('clientside_validation_path_list', ''));
$filter_type = variable_get('clientside_validation_filter_paths', CLIENTSIDE_VALIDATION_EXCLUDE_PATHS);
if (array_search('admin/structure/views/*', $paths) === FALSE && $filter_type == CLIENTSIDE_VALIDATION_EXCLUDE_PATHS) {
$paths[] = 'admin/structure/views/*';
}
variable_set('clientside_validation_path_list', implode("\n", $paths));
}