function search_autocomplete_init in Search Autocomplete 6.4
Same name and namespace in other branches
- 6.2 search_autocomplete.module \search_autocomplete_init()
- 7.2 search_autocomplete.module \search_autocomplete_init()
- 7.3 search_autocomplete.module \search_autocomplete_init()
Implementation of hook_init().
File
- ./
search_autocomplete.module, line 20
Code
function search_autocomplete_init() {
// Checkout if user have authorization to access the autocompleted form.
if (user_access('use Search Autocomplete')) {
// Checkout if the db exists (it should).
if (db_table_exists('search_autocomplete_forms')) {
// Get every form to autocomplete.
$results = db_query('SELECT * FROM {search_autocomplete_forms} WHERE enabled=1');
// Build the setting array to transfert to JS.
while ($match = db_fetch_array($results)) {
$form_id = 'form' . $match['fid'];
$input_data = explode("\n", $match['data_static']);
$data_static = array();
for ($i = 0; $i < count($input_data); $i++) {
$cut = strripos($input_data[$i], '=>');
$object = array();
if ($cut > 0) {
$object['label'] = trim(substr($input_data[$i], 0, $cut));
$object['value'] = trim(substr($input_data[$i], 0, $cut));
$object['link'] = trim(substr($input_data[$i], $cut + 2, strlen($input_data[$i])));
}
else {
$object['label'] = trim($input_data[$i]);
$object['value'] = trim($input_data[$i]);
}
$data_static[] = $object;
}
$data_source = $match['data_callback'];
if (($match['data_source'] == 1 || $match['data_source'] == 3) && !menu_path_is_external($match['data_callback'])) {
$data_source = urldecode(url($match['data_callback'], array(
'absolute' => TRUE,
)));
}
drupal_add_css(drupal_get_path('module', 'search_autocomplete') . '/css/default_styles/global.css');
drupal_add_js(array(
'search_autocomplete' => array(
$form_id => array(
'selector' => $match['selector'],
'minChars' => $match['min_char'],
'max_sug' => $match['max_sug'],
'no_results' => $match['no_results'],
'type' => $match['data_source'],
'datas' => $match['data_source'] == 2 ? $data_static : $data_source,
'fid' => $match['fid'],
// Get the css filename with '-' instead of ' ', lower case and no '.css'.
'theme' => str_replace(' ', '-', strtolower($match['theme'])),
'auto_submit' => $match['auto_submit'],
'auto_redirect' => $match['auto_redirect'],
),
),
), 'setting');
drupal_add_css(drupal_get_path('module', 'search_autocomplete') . '/css/custom_styles/' . $match['theme'] . '.css');
}
// If there is some results: need to include the css and js....
if ($results) {
// jquery_ui_add(array('ui.widget', 'ui.position', 'ui.autocomplete'));
drupal_add_js(drupal_get_path('module', 'search_autocomplete') . '/js/jquery-ui-autocomplete.min.js');
//jquery_ui_add('jquery-ui.autocomplete');
drupal_add_js(drupal_get_path('module', 'search_autocomplete') . '/js/jquery.autocomplete.js');
}
}
}
}