security update core+modules

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-26 18:38:56 +02:00
parent 2f45ea820a
commit 7c96373038
1022 changed files with 30319 additions and 11259 deletions

View File

@@ -1,23 +1,27 @@
Custom search 7.x-1.x
--------------------------
Install
-------
* Enable the module
* Go to Administer > Settings > Custom search to change settings
* Go to Configuration > Search And Metadata > Custom Search (admin/config/search/custom_search) to change settings
* Don't forget to set permissions, otherwise nobody will see the changes
Description
-----------
This module alters the default search box in many ways. If you need to have options available like in advanced search, but directly in the search box, this module is for you.
This module alters the default search box in many ways.
If you need to have options available like in advanced search,
but directly in the search box, this module is for you.
The module adds options to select:
- which content type(s) to search,
- which specific module search to use (node, help, user or any module that implements search),
- which specific module search to use
(node, help, user or any module that implements search),
- which taxonomy term to search in the results (by vocabulary).
- For all these choices, there are options to switch between a select box, checkboxes or radio buttons, and also customize the selector label and the default - Any - text.
- For all these choices, there are options to switch between a select box,
checkboxes or radio buttons, and also customize the selector
label and the default - Any - text.
There are also options to:
@@ -30,14 +34,17 @@ There are also options to:
Finally, there's some javascript to:
- check if the search box is not empty on submit,
- clear the default text on focus, and put it back on blur (if search box is empty),
- handle checkboxes (deselect some checkbox if -Any-, or a special module search, is checked),
- clear the default text on focus, and put it back on blur
(if search box is empty),
- handle checkboxes (deselect some checkbox if -Any-,
or a special module search, is checked),
- reselect options in the advanced search options (in results page).
The module integrates well with Internationalization (i18n_string).
This module is inspired by some modules that implements some of these options (search_config, search_type, custom_seach_box).
This module is inspired by some modules that implements some of these options
(search_config, search_type, custom_seach_box).
Author
------

View File

@@ -11,7 +11,7 @@
function custom_search_admin() {
// Basic settings.
$form = _custom_search_default_admin_form();
// Custom search paths
// Custom search paths.
$form = array_merge($form, _custom_search_custom_paths_admin_form());
// Ordering.
$form = array_merge($form, _custom_search_ordering_admin_form());
@@ -49,6 +49,9 @@ function custom_search_content_admin() {
return system_settings_form(_custom_search_content_admin_form());
}
/**
* Results page settings.
*/
function custom_search_results_admin() {
$form['custom_search_target'] = array(
'#type' => 'select',
@@ -131,20 +134,26 @@ function custom_search_results_admin() {
);
}
if (module_exists('taxonomy')) {
$form['search_form']['advanced']['taxonomy'] = array(
// Languages.
$language_options = array();
foreach (language_list('language') as $key => $entity) {
if ($entity->enabled) {
$language_options[$key] = $entity->name;
}
}
if (count($language_options) > 1) {
$form['search_form']['advanced']['languages'] = array(
'#type' => 'fieldset',
'#title' => t('Taxonomy'),
'#description' => t('Select the vocabularies to display on the advanced search form.'),
'#title' => t('Languages'),
'#description' => t('Select the languages to display on the advanced search form.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
$form['search_form']['advanced']['taxonomy']['custom_search_advanced_voc' . $voc->vid . '_display'] = array(
foreach ($language_options as $key => $name) {
$form['search_form']['advanced']['languages']['custom_search_advanced_language_' . $key . '_display'] = array(
'#type' => 'checkbox',
'#title' => $voc->name,
'#default_value' => variable_get('custom_search_advanced_voc' . $voc->vid . '_display', TRUE),
'#title' => $name,
'#default_value' => variable_get('custom_search_advanced_language_' . $key . '_display', TRUE),
);
}
}
@@ -205,4 +214,4 @@ function custom_search_results_admin() {
);
return system_settings_form($form);
}
}

View File

@@ -1,18 +1,21 @@
input.custom-search-default-value { color:#999;}
input.custom-search-default-value {
color: #999;
}
#elements tr.region-message {
font-weight:normal;
color:#999;
font-weight: normal;
color: #999;
}
#elements tr.region-populated {
display:none;
display: none;
}
fieldset.custom_search-popup {
display:none;
position:absolute;
top:auto;
margin:0;
display: none;
position: absolute;
top: auto;
margin: 0;
z-index: 1;
background-color: #fff;
}

View File

@@ -1,20 +1,15 @@
name = Custom Search
description = Customize the default search, change labels, default texts, ordering, and display content types and taxonomy selectors.
core = 7.x
package = Custom Search
package = Search
dependencies[] = search
files[] = custom_search.admin.inc
files[] = custom_search.pages.inc
files[] = custom_search.module
files[] = custom_search.install
configure = admin/config/search/custom_search
; Information added by drupal.org packaging script on 2013-02-26
version = "7.x-1.11+9-dev"
; Information added by Drupal.org packaging script on 2015-02-18
version = "7.x-1.18"
core = "7.x"
project = "custom_search"
datestamp = "1361839667"
datestamp = "1424262482"

View File

@@ -19,64 +19,9 @@ function custom_search_install() {
* Implements hook_uninstall().
*/
function custom_search_uninstall() {
variable_del('custom_search_label_visibility');
variable_del('custom_search_label');
variable_del('custom_search_text');
variable_del('custom_search_size');
variable_del('custom_search_max_length');
variable_del('custom_search_submit_text');
variable_del('custom_search_image_path');
variable_del('custom_search_criteria_or_display');
variable_del('custom_search_criteria_or_label');
variable_del('custom_search_criteria_phrase_display');
variable_del('custom_search_criteria_phrase_label');
variable_del('custom_search_criteria_negative_display');
variable_del('custom_search_criteria_negative_label');
variable_del('custom_search_paths');
variable_del('custom_search_paths_selector');
variable_del('custom_search_paths_selector_label');
variable_del('custom_search_paths_selector_label_visibility');
variable_del('custom_search_search_box_weight');
variable_del('custom_search_content_types_weight');
variable_del('custom_search_criteria_or_weight');
variable_del('custom_search_criteria_phrase_weight');
variable_del('custom_search_criteria_negative_weight');
variable_del('custom_search_custom_paths_weight');
variable_del('custom_search_submit_button_weight');
variable_del('custom_search_search_box_region');
variable_del('custom_search_content_types_region');
variable_del('custom_search_criteria_or_region');
variable_del('custom_search_criteria_phrase_region');
variable_del('custom_search_criteria_negative_region');
variable_del('custom_search_custom_paths_region');
variable_del('custom_search_submit_button_region');
variable_del('custom_search_target');
variable_del('custom_search_node_types');
variable_del('custom_search_node_types_excluded');
variable_del('custom_search_other');
variable_del('custom_search_type_selector');
variable_del('custom_search_type_selector_label');
variable_del('custom_search_type_selector_label_visibility');
variable_del('custom_search_type_selector_all');
variable_del('custom_search_any_restricts');
variable_del('custom_search_any_force');
variable_del('custom_search_results_search');
variable_del('custom_search_results_advanced_search');
variable_del('custom_search_results_advanced_search_collapsible');
variable_del('custom_search_results_advanced_search_collapsed');
variable_del('custom_search_advanced_or_display');
variable_del('custom_search_advanced_phrase_display');
variable_del('custom_search_advanced_negative_display');
$options = node_type_get_names();
foreach ($options as $type => $name) variable_del('custom_search_advanced_type_' . $type . '_display');
variable_del('custom_search_results_info_type');
variable_del('custom_search_results_info_user');
variable_del('custom_search_results_info_date');
if (module_exists('comment')) variable_del('custom_search_results_info_comment');
if (module_exists('upload')) variable_del('custom_search_results_info_upload');
variable_del('custom_search_filter');
variable_del('custom_search_filter_label');
variable_del('custom_search_search_api_page');
db_delete('variable')
->condition('name', 'custom_search_%', 'LIKE')
->execute();
}
/**
@@ -94,7 +39,7 @@ function custom_search_update_7100() {
->fields(array('weight' => 100))
->condition('name', 'custom_search')
->execute();
return t('Module\'s weight increased.');
return t("Module's weight increased.");
}
/**
@@ -127,14 +72,35 @@ function custom_search_update_7103() {
if (count($types)) {
$names = array_keys(node_type_get_names());
foreach ($names as $name) {
if (!in_array($name, $types)) variable_set('custom_search_advanced_type_' . $name . '_display', FALSE);
if (!in_array($name, $types)) {
variable_set('custom_search_advanced_type_' . $name . '_display', FALSE);
}
}
}
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
if (variable_get('custom_search_voc' . $voc->vid . '_selector', 'disabled') == 'disabled') variable_set('custom_search_advanced_voc' . $voc->vid . '_display', FALSE);
if (module_exists('taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
if (variable_get('custom_search_voc' . $voc->vid . '_selector', 'disabled') == 'disabled') {
variable_set('custom_search_advanced_voc' . $voc->vid . '_display', FALSE);
}
}
}
}
variable_del('custom_search_results_advanced_override');
return t('Advanced search form settings changed.');
}
/**
* Store vids - machine names association.
*/
function custom_search_update_7104() {
if (module_exists('taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
$machine_names = array();
foreach ($vocabularies as $voc) {
$machine_names[$voc->machine_name] = $voc->vid;
}
// This will be needed for those upgrading to Drupal 8 or Backdrop.
variable_set('custom_search_taxonomy_machine_names', $machine_names);
}
}

View File

@@ -8,6 +8,7 @@
*/
define('CUSTOM_SEARCH_LABEL_DEFAULT', t('Search this site'));
define('CUSTOM_SEARCH_HINT_TEXT_DEFAULT', t('Enter the terms you wish to search for.'));
define('CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT', t('Search'));
define('CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT', t('Search for'));
define('CUSTOM_SEARCH_MAX_LENGTH_DEFAULT', 128);
@@ -76,12 +77,12 @@ function custom_search_permission() {
return array(
'administer custom search' => array(
'title' => t('Administer custom search'),
'description' => t('Allow users to administer custom search settings')
'description' => t('Allow users to administer custom search settings'),
),
'use custom search' => array(
'title' => t('Use custom search'),
'description' => t('Allow users to use custom search')
)
'description' => t('Allow users to use custom search'),
),
);
}
@@ -90,10 +91,10 @@ function custom_search_permission() {
*/
function custom_search_form_alter(&$form, &$form_state, $form_id) {
// Filter the form_id value to identify all the custom blocks
// Filter the form_id value to identify all the custom blocks.
$form_id_processed = $form_id;
$delta = '';
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
if ($form_id == 'custom_search_blocks_form_' . $a) {
$form_id_processed = 'custom_search_blocks_form';
$delta = 'blocks_' . $a . '_';
@@ -104,40 +105,66 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
case 'search_form':
if (isset($form['module']) && $form['module']['#value'] == 'node' && isset($form['advanced'])) {
if (isset($form['module']) && $form['module']['#value'] == 'node') {
// Criteria
if (!variable_get('custom_search_advanced_or_display', TRUE)) $form['advanced']['keywords']['or']['#type'] = 'hidden';
if (!variable_get('custom_search_advanced_phrase_display', TRUE)) $form['advanced']['keywords']['phrase']['#type'] = 'hidden';
if (!variable_get('custom_search_advanced_negative_display', TRUE)) $form['advanced']['keywords']['negative']['#type'] = 'hidden';
if (isset($form['advanced'])) {
// Taxonomy
if (module_exists('taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
if (!variable_get('custom_search_advanced_voc' . $voc->vid . '_display', TRUE)) unset($form['advanced']['category']['#options'][$voc->name]);
// Criteria.
if (!variable_get('custom_search_advanced_or_display', TRUE)) {
$form['advanced']['keywords']['or']['#type'] = 'hidden';
}
if (!variable_get('custom_search_advanced_phrase_display', TRUE)) {
$form['advanced']['keywords']['phrase']['#type'] = 'hidden';
}
if (!variable_get('custom_search_advanced_negative_display', TRUE)) {
$form['advanced']['keywords']['negative']['#type'] = 'hidden';
}
// Content types.
$names = array_keys(node_type_get_names());
foreach ($names as $name) {
if (!variable_get('custom_search_advanced_type_' . $name . '_display', TRUE)) {
unset($form['advanced']['type']['#options'][$name]);
}
}
if (!count($form['advanced']['type']['#options'])) {
unset($form['advanced']['type']['#type']);
}
// Languages.
foreach (language_list('language') as $key => $entity) {
if ($entity->enabled) {
$language_options[$key] = $entity->name;
}
}
if (count($language_options) > 1) {
foreach ($language_options as $key => $name) {
if (!variable_get('custom_search_advanced_language_' . $key . '_display', TRUE)) {
unset($form['advanced']['language']['#options'][$key]);
}
}
if (!count($form['advanced']['language']['#options'])) {
unset($form['advanced']['language']['#type']);
}
}
if (isset($form['advanced']['category']) && !count($form['advanced']['category']['#options'])) unset($form['advanced']['category']['#type']);
}
// Content types
$names = array_keys(node_type_get_names());
foreach ($names as $name) {
if (!variable_get('custom_search_advanced_type_' . $name . '_display', TRUE)) unset($form['advanced']['type']['#options'][$name]);
}
if (!count($form['advanced']['type']['#options'])) unset($form['advanced']['type']['#type']);
if (!variable_get('custom_search_results_search', TRUE)) {
if (isset($form['basic']['keys'])) {
// If basic search is hidden, original search terms are imported into advanced search.
// If basic search is hidden, import terms into advanced search.
$original_keys = $form['basic']['keys']['#default_value'];
$temp_keys = explode(' ', $original_keys);
foreach ($temp_keys as $value) {
if (drupal_substr($value, 0, 5) != 'type:' && drupal_substr($value, 0, 5) != 'term:') $keys[] = $value;
if (drupal_substr($value, 0, 5) != 'type:' && drupal_substr($value, 0, 5) != 'term:') {
$keys[] = $value;
}
}
$form['advanced']['keywords']['or']['#default_value'] = implode(' ', $keys);
}
if (!isset($GLOBALS['custom_search_nb_results']) || (isset($GLOBALS['custom_search_nb_results']) && !$GLOBALS['custom_search_nb_results'])) $form['advanced']['#collapsed'] = FALSE;
if (!isset($GLOBALS['custom_search_nb_results']) || (isset($GLOBALS['custom_search_nb_results']) && !$GLOBALS['custom_search_nb_results'])) {
$form['advanced']['#collapsed'] = FALSE;
}
$form['basic']['#prefix'] = '<div class="element-invisible">';
$form['basic']['#suffix'] = '</div>';
}
@@ -145,11 +172,13 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
$form['advanced']['#collapsible'] = variable_get('custom_search_results_advanced_search_collapsible', TRUE);
$form['advanced']['#collapsed'] = variable_get('custom_search_results_advanced_search_collapsed', TRUE);
if (!variable_get('custom_search_results_advanced_search', TRUE)) $form['advanced']['#type'] = 'hidden';
if (!variable_get('custom_search_results_advanced_search', TRUE)) {
$form['advanced']['#type'] = 'hidden';
}
}
break;
break;
case 'search_theme_form':
case 'search_block_form':
@@ -158,21 +187,29 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
if (user_access('use custom search')) {
// Title.
$form[$form_id]['#title'] = variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT);
$form[$form_id]['#title_display'] = (!variable_get('custom_search_' . $delta . 'label_visibility', FALSE)) ? 'invisible' : 'before' ;
$form[$form_id]['#title_display'] = (!variable_get('custom_search_' . $delta . 'label_visibility', FALSE)) ? 'invisible' : 'before';
// Search box.
if (module_exists('elements') && variable_get('custom_search_' . $delta . 'element', 'textfield') != 'textfield') {
$form[$form_id]['#type'] = variable_get('custom_search_' . $delta . 'element', 'textfield');
}
$form[$form_id]['#weight'] = variable_get('custom_search_' . $delta . 'search_box_weight', 0);
$form[$form_id]['#attributes'] = array(
'class' => array('custom-search-box'),
'placeholder' => array(variable_get('custom_search_' . $delta . 'text', '')),
);
$form[$form_id]['#size'] = variable_get('custom_search_' . $delta . 'size', CUSTOM_SEARCH_SIZE_DEFAULT);
$form[$form_id]['#maxlength'] = variable_get('custom_search_' . $delta . 'max_length', CUSTOM_SEARCH_MAX_LENGTH_DEFAULT);
if (!isset($form[$form_id]['#attributes'])) {
$form[$form_id]['#attributes'] = array('class' => array());
}
elseif (!isset($form[$form_id]['#attributes']['class'])) {
$form[$form_id]['#attributes']['class'] = array();
}
$form[$form_id]['#attributes']['class'][] = 'custom-search-box';
$form[$form_id]['#attributes']['placeholder'] = variable_get('custom_search_' . $delta . 'text', '');
$form[$form_id]['#attributes']['title'] = variable_get('custom_search_' . $delta . 'hint_text', CUSTOM_SEARCH_HINT_TEXT_DEFAULT);
// CSS
// CSS.
drupal_add_css(drupal_get_path('module', 'custom_search') . '/custom_search.css');
// Criteria
// Criteria.
$criteria = array('or' => 6, 'phrase' => 7, 'negative' => 8);
foreach ($criteria as $c => $w) {
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_display', FALSE)) {
@@ -192,7 +229,9 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
$types = array_keys(array_filter(variable_get('custom_search_' . $delta . 'node_types', array())));
if (count($types)) {
$names = node_type_get_names();
if (count($types) > 1 || variable_get('custom_search_' . $delta . 'any_force', FALSE)) $toptions['c-all'] = variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT);
if (count($types) > 1 || variable_get('custom_search_' . $delta . 'any_force', FALSE)) {
$toptions['c-all'] = variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT);
}
foreach ($types as $type) {
$toptions['c-' . $type] = $names[$type];
}
@@ -210,7 +249,9 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
}
foreach (module_implements('search_info') as $module) {
if ($module != 'node' && $name = module_invoke($module, 'search_info')) {
if (in_array($module, $others)) $options['o-' . $module] = $name['title'];
if (in_array($module, $others)) {
$options['o-' . $module] = t($name['title']);
}
}
}
if (count($options)) {
@@ -219,7 +260,9 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
$selector_type = 'select';
$multiple = TRUE;
}
else $multiple = FALSE;
else {
$multiple = FALSE;
}
$form['custom_search_types'] = array(
'#type' => $selector_type,
'#multiple' => $multiple,
@@ -231,16 +274,18 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
'#validated' => TRUE,
);
// If there's only one type, hide the selector
// If there's only one type, hide the selector.
if (count($others) + count($types) == 1 && !variable_get('custom_search_' . $delta . 'any_force', FALSE)) {
$form['custom_search_types']['#type'] = 'hidden';
$form['custom_search_types']['#default_value'] = key(array_slice($options, count($options)-1));
$form['custom_search_types']['#default_value'] = key(array_slice($options, count($options) - 1));
}
if (!variable_get('custom_search_' . $delta . 'type_selector_label_visibility', TRUE)) $form['custom_search_types']['#title_display'] = 'invisible';
if (!variable_get('custom_search_' . $delta . 'type_selector_label_visibility', TRUE)) {
$form['custom_search_types']['#title_display'] = 'invisible';
}
}
// Custom paths
// Custom paths.
if (variable_get('custom_search_' . $delta . 'paths', '') != '') {
$options = array();
$lines = explode("\n", variable_get('custom_search_' . $delta . 'paths', ''));
@@ -262,7 +307,9 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
'#default_value' => key($options),
'#weight' => variable_get('custom_search_' . $delta . 'custom_paths_weight', 9),
);
if (!variable_get('custom_search_' . $delta . 'paths_selector_label_visibility', TRUE)) $form['custom_search_paths']['#title_display'] = 'invisible';
if (!variable_get('custom_search_' . $delta . 'paths_selector_label_visibility', TRUE)) {
$form['custom_search_paths']['#title_display'] = 'invisible';
}
}
}
@@ -273,13 +320,19 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit']['#type'] = 'image_button';
$form['actions']['submit']['#src'] = variable_get('custom_search_' . $delta . 'image_path', '');
$form['actions']['submit']['#name'] = 'op';
$form['actions']['submit']['#attributes'] = array('alt' => array(variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT)), 'class' => array('custom-search-button'));
$form['actions']['submit']['#attributes'] = array(
'alt' => array(variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT)),
'class' => array('custom-search-button'),
);
unset($form['actions']['submit']['#value']);
}
elseif ($form['actions']['submit']['#value'] == '') {
$form['actions']['submit']['#attributes'] = array('style' => 'display:none;');
}
elseif ($form['actions']['submit']['#value'] == '') $form['actions']['submit']['#attributes'] = array('style' => 'display:none;');
$form['actions']['#weight'] = variable_get('custom_search_' . $delta . 'submit_button_weight', 3);
// Popup
// Popup.
$form['popup'] = array(
'#type' => 'fieldset',
'#weight' => 1 + variable_get('custom_search_' . $delta . 'search_box_weight', 0),
@@ -300,31 +353,47 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
}
}
// Form attributes
// Invoke other modules hooks.
foreach (module_implements('custom_search_box') as $module) {
$function = $module . '_custom_search_box';
if (function_exists($function)) {
call_user_func_array($function, array(&$form, $form_id, $delta));
}
}
// If nothing has been added to the popup, don't output any markup.
if (!count(element_children($form['popup']))) {
unset($form['popup']);
}
// Form attributes.
$form['#attributes']['class'] = array('search-form');
$form['#attributes']['role'] = 'search';
if (!in_array('custom_search_submit', $form['#submit'])) {
$form['#submit'][] = 'custom_search_submit';
}
}
break;
break;
}
}
/**
* Alter the search to respect the search modes selected.
*/
function custom_search_submit($form, &$form_state) {
$delta = (isset($form_state['values']['delta'])) ? 'blocks_' . $form_state['values']['delta'] . '_' : '' ;
variable_set('custom_search_delta', $delta); // save for later use (exclusion & refresh)
// Save delta for later use (exclusion & refresh).
$delta = (isset($form_state['values']['delta'])) ? 'blocks_' . $form_state['values']['delta'] . '_' : '';
variable_set('custom_search_delta', $delta);
$type = 'node';
$keys = $form_state['values'][$form_state['values']['form_id']];
$original_keywords = $keys;
$types = (isset($form_state['values']['custom_search_types'])) ? $form_state['values']['custom_search_types'] : array();
if (!is_array($types)) $types = array($types);
if (!is_array($types)) {
$types = array($types);
}
$types = array_map('_custom_search_filter_keys', array_filter($types));
if (module_exists('taxonomy')) {
@@ -333,15 +402,29 @@ function custom_search_submit($form, &$form_state) {
foreach ($vocabularies as $voc) {
if (isset($form_state['values']['custom_search_vocabulary_' . $voc->vid])) {
$vterms = $form_state['values']['custom_search_vocabulary_' . $voc->vid];
if (!is_array($vterms)) $vterms = array($vterms);
if (!is_array($vterms)) {
$vterms = array($vterms);
}
$terms = array_merge($terms, $vterms);
}
}
$terms = array_map('_custom_search_filter_keys', array_values(array_filter($terms)));
// if one or more -Any- is selected, delete them
while (($index = array_search('all', $terms)) !== FALSE) array_splice($terms, $index, 1);
// If one or more -Any- is selected, delete them.
while (($index = array_search('all', $terms)) !== FALSE) {
array_splice($terms, $index, 1);
}
}
// Invoke other modules hooks.
$other = array();
foreach (module_implements('custom_search_filter') as $module) {
$function = $module . '_custom_search_filter';
if (function_exists($function)) {
$other = call_user_func_array($function, array($form, $form_state, $other));
}
}
$search_types = module_implements('search_info');
if (in_array(current($types), $search_types)) {
$type = current($types);
@@ -350,26 +433,40 @@ function custom_search_submit($form, &$form_state) {
}
else {
$path = $type;
if (isset($form_state['values']['custom_search_criteria_or']) && trim($form_state['values']['custom_search_criteria_or']) != '') $keys .= ' ' . str_replace(' ', ' OR ', trim($form_state['values']['custom_search_criteria_or']));
if (isset($form_state['values']['custom_search_criteria_negative']) && trim($form_state['values']['custom_search_criteria_negative']) != '') $keys .= ' -' . str_replace(' ', ' -', trim($form_state['values']['custom_search_criteria_negative']));
if (isset($form_state['values']['custom_search_criteria_phrase']) && trim($form_state['values']['custom_search_criteria_phrase']) != '') $keys .= ' "' . trim($form_state['values']['custom_search_criteria_phrase']) . '"';
if (isset($form_state['values']['custom_search_criteria_or']) && trim($form_state['values']['custom_search_criteria_or']) != '') {
$keys .= ' ' . str_replace(' ', ' OR ', trim($form_state['values']['custom_search_criteria_or']));
}
if (isset($form_state['values']['custom_search_criteria_negative']) && trim($form_state['values']['custom_search_criteria_negative']) != '') {
$keys .= ' -' . str_replace(' ', ' -', trim($form_state['values']['custom_search_criteria_negative']));
}
if (isset($form_state['values']['custom_search_criteria_phrase']) && trim($form_state['values']['custom_search_criteria_phrase']) != '') {
$keys .= ' "' . trim($form_state['values']['custom_search_criteria_phrase']) . '"';
}
$original_keywords = $keys;
if (count($types)) {
// If a content type is selected, and it's not -Any-, search for that type.
if (!in_array('all', $types)) $keys = search_expression_insert($keys, 'type', implode(',', $types));
// If -Any- is selected and -Any- is set to restrict the search, grab the content types.
// If a content type is selected, and it's not -Any-,
// search for that type.
if (!in_array('all', $types)) {
$keys = search_expression_insert($keys, 'type', implode(',', $types));
}
// If -Any- is selected and -Any- is set to restrict the search,
// grab the content types.
elseif (variable_get('custom_search_' . $delta . 'any_restricts', FALSE)) {
$restricted_types = array_keys(array_filter(variable_get('custom_search_' . $delta . 'node_types', array())));
$keys = search_expression_insert($keys, 'type', implode(',', $restricted_types));
$types = array_keys(array_filter(variable_get('custom_search_' . $delta . 'node_types', array())));
$keys = search_expression_insert($keys, 'type', implode(',', $types));
}
}
if (module_exists('taxonomy') && count($terms)) {
$keys = search_expression_insert($keys, 'term', implode(',', $terms));
}
if (module_exists('custom_search_i18n')) {
if (variable_get('custom_search_i18n_' . $delta . 'search_language', 'all') == 'current') {
$i18n_search_language = variable_get('custom_search_i18n_search_language', 'all');
if ($i18n_search_language == 'current') {
$keys = search_expression_insert($keys, 'language', i18n_language()->language);
}
elseif ($i18n_search_language == 'current_neutral') {
$keys = search_expression_insert($keys, 'language', i18n_language()->language . ',und');
}
}
}
$search_path = array(
@@ -377,9 +474,10 @@ function custom_search_submit($form, &$form_state) {
'query' => array(),
);
// Integrates other search modules
// Integrates other search modules.
if (module_exists('apachesolr_search')) {
for ($i=0; $i<count($types); $i++) {
$fields = field_info_fields();
for ($i = 0; $i < count($types); $i++) {
// Remove the item from the array if it's not a content type.
if (!in_array($types[$i], array_keys(node_type_get_types()))) {
unset($types[$i]);
@@ -389,7 +487,8 @@ function custom_search_submit($form, &$form_state) {
'keywords' => $original_keywords,
'types' => $types,
'terms' => (!empty($terms)) ? $terms : array(),
));
'other' => (!empty($other)) ? $other : array(),
), $keys, $fields);
}
elseif (module_exists('google_appliance')) {
$search_path = _custom_search_google_appliance_search(array(
@@ -415,11 +514,14 @@ function custom_search_submit($form, &$form_state) {
}
}
// Build a custom path if needed
// Build a custom path if needed.
if (isset($form_state['values']['custom_search_paths']) && $form_state['values']['custom_search_paths'] != '') {
$custom_path = str_replace('[key]', $form_state['values'][$form_state['values']['form_id']], $form_state['values']['custom_search_paths']);
if (strpos($form_state['values']['custom_search_paths'], '[terms]') !== FALSE) $custom_path = str_replace('[terms]', (count($terms)) ? implode($form_state['values']['custom_search_paths_terms_separator'], $terms) : '', $custom_path);
// Check for a query string
$custom_path = str_replace('[current_path]', current_path(), $custom_path);
if (strpos($form_state['values']['custom_search_paths'], '[terms]') !== FALSE) {
$custom_path = str_replace('[terms]', (count($terms)) ? implode($form_state['values']['custom_search_paths_terms_separator'], $terms) : '', $custom_path);
}
// Check for a query string.
$custom_path_query_position = strpos($custom_path, '?');
$custom_path_query = array();
if ($custom_path_query_position !== FALSE) {
@@ -432,12 +534,16 @@ function custom_search_submit($form, &$form_state) {
}
$custom_path = substr($custom_path, 0, $custom_path_query_position);
}
// Check for external path. If not, add base path
if (drupal_substr($custom_path, 0, 4) != 'http') $custom_path = url($custom_path, array('absolute' => TRUE));
// Send the final url
// Check for external path. If not, add base path.
if (drupal_substr($custom_path, 0, 4) != 'http') {
$custom_path = url($custom_path, array('absolute' => TRUE));
}
// Send the final url.
$form_state['redirect'] = url($custom_path, array('query' => $custom_path_query, 'absolute' => TRUE));
}
else $form_state['redirect'] = url($search_path['path'], array('query' => $search_path['query'], 'absolute' => TRUE));
else {
$form_state['redirect'] = url($search_path['path'], array('query' => $search_path['query'], 'absolute' => TRUE));
}
}
@@ -445,7 +551,7 @@ function custom_search_submit($form, &$form_state) {
* Rewrite the sql query to exclude content types.
*/
function custom_search_query_alter(QueryAlterableInterface $query) {
if ($query->hasTag('node_access') && $query->hasTag('pager')) {
if (!$query->hasTag('custom_search_ignore') && $query->hasTag('node_access') && $query->hasTag('pager')) {
$excluded_types = array_filter(variable_get('custom_search_' . variable_get('custom_search_delta', '') . 'node_types_excluded', array()));
if (!empty($excluded_types)) {
$tables = $query->getTables();
@@ -458,16 +564,36 @@ function custom_search_query_alter(QueryAlterableInterface $query) {
}
}
/**
* Implements hook_block_view_alter().
* Used to exclude Facet API searching for excluded types.
*/
function custom_search_block_view_alter(&$data, $block) {
if ($block->module == 'facetapi') {
$excluded_types = array_filter(variable_get('custom_search_' . variable_get('custom_search_delta', '') . 'node_types_excluded', array()));
if (!empty($excluded_types) && isset($data['content']['bundle']) && is_array($data['content']['bundle']["#items"])) {
foreach ($data['content']['bundle']["#items"] as $key => $item) {
// Find the type in the link.
preg_match('/<a(.*)href="(.*)bundle%3A(.*?)(&|")(.*)/', $item['data'], $matches);
// Exclude it if not needed.
if (!empty($matches) && in_array($matches[3], $excluded_types)) unset($data['content']['bundle']["#items"][$key]);
}
}
}
}
/**
* Implements hook_init().
*/
function custom_search_init() {
if (user_access('use custom search')) {
drupal_add_js(drupal_get_path('module', 'custom_search') . '/js/custom_search.js');
drupal_add_js(array('custom_search' => array(
'form_target' => variable_get('custom_search_target', '_self'),
'solr' => module_exists('apachesolr_search') ? 1 : 0,
)), array('type' => 'setting'));
drupal_add_js(array(
'custom_search' => array(
'form_target' => variable_get('custom_search_target', '_self'),
'solr' => (module_exists('apachesolr_search') || module_exists('search_api_solr')) ? 1 : 0,
),
), array('type' => 'setting'));
}
}
@@ -499,7 +625,7 @@ function custom_search_theme() {
),
);
// Panels integration
// Panels integration.
$router_item = db_query_range('SELECT page_callback FROM {menu_router} WHERE path = :path', 0, 1, array(':path' => 'search/node/%'))->fetchAssoc();
if ($router_item['page_callback'] == 'page_manager_search_page') {
unset($custom_search_theme_array['search_results'], $custom_search_theme_array['search_result']);
@@ -512,7 +638,9 @@ function custom_search_theme() {
* Implements hook_link().
*/
function custom_search_contextual_links_view_alter(&$element, $items) {
if (isset($element['#element']['#form_id']) && $element['#element']['#form_id'] == 'search_block_form') {
if (isset($element['#element']['#form_id']) &&
($element['#element']['#form_id'] == 'search_block_form') &&
user_access('administer custom search')) {
$element['#links']['custom_search'] = array(
'title' => t('Custom Search configuration'),
'href' => 'admin/config/search/custom_search',
@@ -522,15 +650,16 @@ function custom_search_contextual_links_view_alter(&$element, $items) {
}
/**
* Filter the types
* Filter the types.
*/
function _custom_search_filter_keys($val) {
return (strlen($val) > 2 && $val[1] == '-') ? drupal_substr($val, 2) : $val;
}
/**
* Function used to filter node_type array to only filter those that are configured in Custom Search Form
* Function used to filter node_type array to only filter
* those that are configured in Custom Search Form.
*/
function custom_search_filter_array($value = FALSE) {
return $value !== 0;
}
}

View File

@@ -12,29 +12,22 @@
*
* To return:
* the complete search path
*
*/
function _custom_search_apachesolr_search($variables) {
// Set default path in case the core search page path isn't set yet.
$path = 'search/apachesolr_search';
$solr_info = apachesolr_search_page_load('core_search');
if (isset($solr_info['search_path'])) {
// Use the configured Solr search path instead of default path.
$path = $solr_info['search_path'];
}
$type = $path . '/' . $variables['keywords'];
function _custom_search_apachesolr_search($variables, &$keys, $fields) {
// Use the search info for the apachesolr module to get the search path.
$solr_info = apachesolr_search_search_info();
$type = 'search/' . $solr_info['path'] . '/' . $variables['keywords'];
$keys = array();
if (count($variables['types']) && !in_array('all', $variables['types'])) {
foreach ($variables['types'] as $t) {
$keys['f[' . count($keys) . ']'] = 'bundle:' . $t;
$keys['fq[' . count($keys) . ']'] = 'bundle:' . $t;
}
}
if (module_exists('taxonomy') && count($variables['terms'])) {
// get all fields info to get correct filter names
$fields = field_info_fields();
// Get all fields info to get correct filter names.
$taxonomy_fields = array();
foreach ($fields as $name => $settings) {
if ($settings['type'] == 'taxonomy_term_reference') {
@@ -42,12 +35,19 @@ function _custom_search_apachesolr_search($variables) {
$taxonomy_fields[$voc->vid] = $name;
}
}
// build keys for taxonomy
// Build keys for taxonomy.
foreach ($variables['terms'] as $t) {
$vocid = taxonomy_term_load($t)->vid;
$keys['f[' . count($keys) . ']'] = 'im_' . $taxonomy_fields[$vocid] . ':' . $t;
$keys['fq[' . count($keys) . ']'] = 'im_' . $taxonomy_fields[$vocid] . ':' . $t;
}
}
foreach (module_implements('custom_search_apachesolr_processing') as $module) {
$function = $module . '_custom_search_apachesolr_processing';
if (function_exists($function)) {
call_user_func_array($function, array(&$keys, $fields, $variables['other']));
}
}
return array('path' => $type, 'query' => $keys);
}
}

View File

@@ -8,7 +8,9 @@
* Default admin form.
*/
function _custom_search_default_admin_form($delta = '') {
if ($delta != '') $delta = 'blocks_' . $delta . '_';
if ($delta != '') {
$delta = 'blocks_' . $delta . '_';
}
// Labels & default text.
$form['search_box'] = array(
@@ -33,10 +35,28 @@ function _custom_search_default_admin_form($delta = '') {
);
$form['search_box']['custom_search_' . $delta . 'text'] = array(
'#type' => 'textfield',
'#title' => t('Search box default text'),
'#title' => t('Search box placeholder text'),
'#default_value' => variable_get('custom_search_' . $delta . 'text', ''),
'#description' => t('This will change the default text inside the search form. Leave blank for no text. This field is blank by default.'),
'#description' => t('This will change the default text inside the search form. This is the <a href="http://www.w3schools.com/tags/att_input_placeholder.asp" target="_blank">placeholder</a> attribute for the TextField. Leave blank for no text. This field is blank by default.'),
);
$form['search_box']['custom_search_' . $delta . 'hint_text'] = array(
'#type' => 'textfield',
'#title' => t('Search box hint text'),
'#default_value' => variable_get('custom_search_' . $delta . 'hint_text', CUSTOM_SEARCH_HINT_TEXT_DEFAULT),
'#description' => t('Enter the text that will be displayed when hovering the input field (HTML <em>title</em> attritube).'),
);
if (module_exists('elements')) {
$form['search_box']['custom_search_' . $delta . 'element'] = array(
'#type' => 'select',
'#title' => t('Search box input type'),
'#options' => array(
'textfield' => 'text',
'searchfield' => 'search (HTML5)',
),
'#default_value' => variable_get('custom_search_' . $delta . 'element', 'textfield'),
'#description' => t('The default value is "text".'),
);
}
$form['search_box']['custom_search_' . $delta . 'size'] = array(
'#type' => 'textfield',
'#title' => t('Search box size'),
@@ -73,7 +93,7 @@ function _custom_search_default_admin_form($delta = '') {
$form['submit_button']['custom_search_image'] = array(
'#type' => 'file',
'#title' => t('Submit image'),
'#description' => t('If you don\'t have direct file access to the server, use this field to upload your image.'),
'#description' => t("If you don't have direct file access to the server, use this field to upload your image."),
);
// Criteria.
@@ -144,11 +164,10 @@ function _custom_search_default_admin_form($delta = '') {
),
);
if (module_exists('search_api_page')) {
$search_api_pages = search_api_page_load_multiple();
$options[0] = t('None');
foreach($search_api_pages as $page) {
foreach ($search_api_pages as $page) {
$options[$page->id] = $page->name;
}
$form['searchapi'] = array(
@@ -172,12 +191,14 @@ function _custom_search_default_admin_form($delta = '') {
* Content admin form.
*/
function _custom_search_content_admin_form($delta = '') {
if ($delta != '') $delta = 'blocks_' . $delta . '_';
if ($delta != '') {
$delta = 'blocks_' . $delta . '_';
}
$form['content_selector'] = array(
'#type' => 'fieldset',
'#title' => t('Content selector'),
'#description' => t('Select the search types to present as search options in the search block. If none is selected, no selector will be displayed. <strong>Note</strong>: if there\'s only one type checked, the selector won\'t be displayed BUT only this type will be searched.'),
'#description' => t("Select the search types to present as search options in the search block. If none is selected, no selector will be displayed. <strong>Note</strong>: if there's only one type checked, the selector won't be displayed BUT only this type will be searched."),
);
$form['content_selector']['custom_search_' . $delta . 'node_types'] = array(
'#type' => 'checkboxes',
@@ -255,7 +276,7 @@ function _custom_search_content_admin_form($delta = '') {
$form['custom_search_' . $delta . 'node_types_excluded'] = array(
'#type' => 'checkboxes',
'#title' => t('Content exclusion'),
'#description' => t('Select the content types you don\'t want to be displayed as results.'),
'#description' => t("Select the content types you don't want to be displayed as results.<br/><strong>Notice</strong>: content exclusion only works with the core Search module."),
'#default_value' => variable_get('custom_search_' . $delta . 'node_types_excluded', array()),
'#options' => node_type_get_names(),
);
@@ -267,7 +288,9 @@ function _custom_search_content_admin_form($delta = '') {
* Custom paths admin form.
*/
function _custom_search_custom_paths_admin_form($delta = '') {
if ($delta != '') $delta = 'blocks_' . $delta . '_';
if ($delta != '') {
$delta = 'blocks_' . $delta . '_';
}
$form['custom_search_paths_admin'] = array(
'#type' => 'fieldset',
'#title' => t('Custom search paths'),
@@ -300,18 +323,20 @@ function _custom_search_custom_paths_admin_form($delta = '') {
'#title' => t('Paths'),
'#default_value' => variable_get('custom_search_' . $delta . 'paths', ''),
'#rows' => 3,
'#description' => t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box. Ie: mysearch/[key]|My custom search label.'),
'#description' => t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box. Ie: mysearch/[key]|My custom search label. The [current_path] token can be used to use the current URL path of the page beeing viewed.'),
);
return $form;
}
/**
* Ordering admin form
* Ordering admin form.
*/
function _custom_search_ordering_admin_form($delta = '') {
drupal_add_css(drupal_get_path('module', 'custom_search') . '/custom_search.css');
if ($delta != '') $delta = 'blocks_' . $delta . '_';
if ($delta != '') {
$delta = 'blocks_' . $delta . '_';
}
$form['order'] = array(
'#type' => 'fieldset',
'#title' => t('Elements ordering'),
@@ -330,8 +355,9 @@ function _custom_search_ordering_admin_form($delta = '') {
'custom_paths' => array('title' => t('Custom search paths'), 'default_weight' => 9),
'submit_button' => array('title' => t('Submit button'), 'default_weight' => 10),
);
if (count(array_filter(array_merge(variable_get('custom_search_' . $delta . 'node_types', array()), variable_get('custom_search_' . $delta . 'other', array())))))
if (count(array_filter(array_merge(variable_get('custom_search_' . $delta . 'node_types', array()), variable_get('custom_search_' . $delta . 'other', array()))))) {
$elements['content_types'] = array('title' => t('Content Types'), 'default_weight' => 0);
}
foreach ($elements as $element => $data) {
$form['order']['custom_search_' . $delta . 'order'][$element] = array(
@@ -341,17 +367,27 @@ function _custom_search_ordering_admin_form($delta = '') {
$form['order']['custom_search_' . $delta . 'order'][$element]['sort'] = array(
'#type' => 'weight',
'#default_value' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
'#attributes' => array('class' => array('sort-select', 'sort-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'))),
'#attributes' => array(
'class' => array(
'sort-select',
'sort-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'),
),
),
);
$form['order']['custom_search_' . $delta . 'order'][$element]['region'] = array(
'#type' => 'select',
'#options' => array(
'block' => t('Block'),
'popup' => t('Popup')
'popup' => t('Popup'),
),
'#default_value' => variable_get('custom_search_' . $delta . $element . '_region', 'block'),
'#attributes' => array('class' => array('region-select', 'region-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'))),
'#attributes' => array(
'class' => array(
'region-select',
'region-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'),
),
),
);
}
return $form;
}
}

View File

@@ -12,10 +12,9 @@
*
* To return:
* the complete search path
*
*/
function _custom_search_google_appliance_search($variables) {
$type = variable_get('google_appliance_default_search_path', 'google-appliance');
$type = variable_get('google_appliance_default_search_path', 'gsearch');
return array('path' => $type . '/' . $variables['keys'], 'query' => array());
}
}

View File

@@ -12,7 +12,6 @@
*
* To return:
* the complete search path
*
*/
function _custom_search_lucenapi_search($variables) {
@@ -20,12 +19,16 @@ function _custom_search_lucenapi_search($variables) {
$keys = array();
if (count($variables['types']) && !in_array('all', $variables['types'])) {
foreach ($variables['types'] as $t) $keys["type[$t]"] = $t;
foreach ($variables['types'] as $t) {
$keys["type[$t]"] = $t;
}
}
if (module_exists('taxonomy') && count($variables['terms'])) {
foreach ($variables['terms'] as $t) $keys["category[$t]"] = $t;
foreach ($variables['terms'] as $t) {
$keys["category[$t]"] = $t;
}
}
return array('path' => $type, 'query' => $keys);
}
}

View File

@@ -12,7 +12,6 @@
*
* To return:
* the complete search path
*
*/
function _custom_search_search_api_search($variables) {
@@ -21,11 +20,13 @@ function _custom_search_search_api_search($variables) {
$keys = array();
if (count($variables['types']) && !in_array('all', $variables['types'])) {
foreach ($variables['types'] as $key => $value) $keys["filter[type][$key]"] = "\"$value\"";
foreach ($variables['types'] as $key => $value) {
$keys["filter[type][$key]"] = "\"$value\"";
}
}
if (module_exists('taxonomy') && count($variables['terms'])) {
// Get index fields info, and keeps only the taxonomy ones
// Get index fields info, and keeps only the taxonomy ones.
$index = search_api_index_load($variables['page']->index_id);
$fields = array();
foreach ($index->options['fields'] as $field => $data) {
@@ -34,14 +35,15 @@ function _custom_search_search_api_search($variables) {
$fields[$field_info['settings']['allowed_values'][0]['vocabulary']] = $field;
}
}
// Adds terms
// Adds terms.
foreach ($variables['terms'] as $key => $value) {
$term = taxonomy_term_load($value);
if (array_key_exists($term->vocabulary_machine_name, $fields))
if (array_key_exists($term->vocabulary_machine_name, $fields)) {
$keys['filter[' . $fields[$term->vocabulary_machine_name] . '][' . $key . ']'] = "\"$value\"";
}
}
}
return array('path' => $type, 'query' => $keys);
}
}

View File

@@ -5,15 +5,16 @@
if (!Drupal.settings.custom_search.solr) {
// Check if the search box is not empty on submit
$('form.search-form', context).submit(function(){
var box = $(this).find('input.custom-search-box');
var $this = $(this);
var box = $this.find('input.custom-search-box');
if (box.val() != undefined && box.val() == '') {
$(this).find('input.custom-search-box').addClass('error');
$this.find('input.custom-search-box').addClass('error');
return false;
}
// If basic search is hidden, copy or value to the keys
if ($(this).find('#edit-keys').parents('div.element-invisible').attr('class') == 'element-invisible') {
$(this).find('#edit-keys').val($(this).find('#edit-or').val());
$(this).find('#edit-or').val('');
if ($this.find('#edit-keys').parents('div.element-invisible').attr('class') == 'element-invisible') {
$this.find('#edit-keys').val($this.find('#edit-or').val());
$this.find('#edit-or').val('');
}
return true;
});
@@ -24,11 +25,12 @@
// Displays Popup.
$('form.search-form input.custom-search-box', context).bind('click focus', function(e){
$this = $(this);
$parentForm = $this.parents('form');
var $parentForm = $(this).parents('form');
// check if there's something in the popup and displays it
var popup = $parentForm.find('fieldset.custom_search-popup');
if (popup.find('input,select').length && !popup.hasClass('opened')) popup.fadeIn().addClass('opened');
if (popup.find('input,select').length && !popup.hasClass('opened')) {
popup.fadeIn().addClass('opened');
}
e.stopPropagation();
});
$(document).bind('click focus', function(){
@@ -47,52 +49,61 @@
if (el.val().substr(0,2) == 'c-') {
el.change(function(){
$('.custom-search-selector input:checkbox').each(function(){
if ($(this).val().substr(0,2) == 'o-') $(this).attr('checked', false);
if ($(this).val().substr(0,2) == 'o-') {
$(this).attr('checked', false);
}
});
$(this).parents('.custom-search-selector').find('input:checkbox[value=c-all]').attr('checked', false);
});
} else {
el.change(function(){
$(this).parents('.custom-search-selector').find('input:checkbox[value!='+el.val()+']').attr('checked', false);
$(this).parents('.custom-search-selector').find('input:checkbox[value!=' + el.val() + ']').attr('checked', false);
});
}
}
});
// Reselect types and terms in advanced search
var edit_keys = $('#edit-keys').val();
if(edit_keys) {
var edit_keys = encodeURIComponent($('#edit-keys').val());
if (edit_keys) {
// types
var pos = edit_keys.indexOf('type:');
if (pos) {
var pos2 = edit_keys.indexOf(' ',pos);
if (pos2==-1) pos2 = edit_keys.length;
var types = edit_keys.substring(pos+5,pos2);
if (pos != -1) {
var pos2 = edit_keys.indexOf(' ', pos);
if (pos2 == -1) {
pos2 = edit_keys.length;
}
var types = edit_keys.substring(pos + 5,pos2);
types = types.split(',');
for (var i=0; i<types.length; i++) {
$('.search-form input:checkbox[value='+types[i]+']').attr('checked', true);
for (var i = 0; i < types.length; i++) {
$('.search-form input:checkbox[value=' + types[i] + ']').attr('checked', true);
}
}
// terms
var pos = edit_keys.indexOf('term:');
if (pos) {
var pos2 = edit_keys.indexOf(' ',pos);
if (pos2==-1) pos2 = edit_keys.length;
var terms = edit_keys.substring(pos+5,pos2);
if (pos != -1) {
var pos2 = edit_keys.indexOf(' ', pos);
if (pos2 == -1) {
pos2 = edit_keys.length;
}
var terms = edit_keys.substring(pos + 5, pos2);
terms = terms.split(',');
for (var i=0; i<terms.length; i++) {
$('#edit-term option[value='+terms[i]+']').attr('selected', true);
for (var i = 0; i < terms.length; i++) {
$('#edit-term option[value=' + terms[i] + ']').attr('selected', true);
}
}
// languages
var pos = edit_keys.indexOf('language:');
if (pos) {
var pos2 = edit_keys.indexOf(' ',pos);
if (pos2==-1) pos2 = edit_keys.length;
var languages = edit_keys.substring(pos+9,pos2);
if (pos != -1) {
var pos2 = edit_keys.indexOf(' ', pos);
if (pos2 == -1) {
pos2 = edit_keys.length;
}
var languages = edit_keys.substring(pos + 9,pos2);
languages = languages.split(',');
for (var i=0; i<languages.length; i++) {
$('.search-advanced #edit-language-'+languages[i]).attr('checked', true);
for (var i = 0; i < languages.length; i++) {
$('.search-advanced #edit-language-' + languages[i]).attr('checked', true);
}
}
}
@@ -109,4 +120,4 @@
}
}
})(jQuery);
})(jQuery);

View File

@@ -14,7 +14,8 @@ Drupal.behaviors.customSearchSort = {
}
var table = $('table#elements');
var tableDrag = Drupal.tableDrag.elements; // Get the blocks tableDrag object.
// Get the blocks tableDrag object.
var tableDrag = Drupal.tableDrag.elements;
// Add a handler for when a row is swapped, update empty regions.
tableDrag.row.prototype.onSwap = function (swappedRow) {

View File

@@ -12,7 +12,7 @@ function custom_search_blocks_help($path, $arg) {
switch ($path) {
case 'admin/config/search/custom_search/blocks':
$output = t('If you want custom search blocks, enable them here. Then go to the <a href="@link">block page</a> to place them in a region.', array('@link' => url('admin/build/block')));
break;
break;
}
return $output;
}
@@ -25,4 +25,4 @@ function custom_search_blocks_admin() {
'#default_value' => variable_get('custom_search_blocks_number', 1),
);
return system_settings_form($form);
}
}

View File

@@ -1,19 +1,16 @@
name = Custom Search Blocks
description = Provides additional search blocks.
core = 7.x
package = Custom Search
package = Search
dependencies[] = block
dependencies[] = custom_search
files[] = custom_search_blocks.admin.inc
files[] = custom_search_blocks.module
files[] = custom_search_blocks.install
configure = admin/config/search/custom_search/blocks
; Information added by drupal.org packaging script on 2013-02-26
version = "7.x-1.11+9-dev"
; Information added by Drupal.org packaging script on 2015-02-18
version = "7.x-1.18"
core = "7.x"
project = "custom_search"
datestamp = "1361839667"
datestamp = "1424262482"

View File

@@ -19,65 +19,9 @@ function custom_search_blocks_install() {
* Implements hook_uninstall().
*/
function custom_search_blocks_uninstall() {
$blocks = variable_get('custom_search_blocks_number', 1);
for ($delta=1 ; $delta<=$blocks ; $delta++) {
variable_del('custom_search_blocks_' . $delta . '_label_visibility');
variable_del('custom_search_blocks_' . $delta . '_label');
variable_del('custom_search_blocks_' . $delta . '_text');
variable_del('custom_search_blocks_' . $delta . '_size');
variable_del('custom_search_blocks_' . $delta . '_max_length');
variable_del('custom_search_blocks_' . $delta . '_submit_text');
variable_del('custom_search_blocks_' . $delta . '_image_path');
variable_del('custom_search_blocks_' . $delta . '_criteria_or_display');
variable_del('custom_search_blocks_' . $delta . '_criteria_or_label');
variable_del('custom_search_blocks_' . $delta . '_criteria_phrase_display');
variable_del('custom_search_blocks_' . $delta . '_criteria_phrase_label');
variable_del('custom_search_blocks_' . $delta . '_criteria_negative_display');
variable_del('custom_search_blocks_' . $delta . '_criteria_negative_label');
variable_del('custom_search_blocks_' . $delta . '_submit_text');
variable_del('custom_search_blocks_' . $delta . '_image_path');
variable_del('custom_search_blocks_' . $delta . '_criteria_or_display');
variable_del('custom_search_blocks_' . $delta . '_criteria_or_label');
variable_del('custom_search_blocks_' . $delta . '_criteria_phrase_display');
variable_del('custom_search_blocks_' . $delta . '_criteria_phrase_label');
variable_del('custom_search_blocks_' . $delta . '_criteria_negative_display');
variable_del('custom_search_blocks_' . $delta . '_criteria_negative_label');
variable_del('custom_search_blocks_' . $delta . '_search_box_weight');
variable_del('custom_search_blocks_' . $delta . '_content_types_weight');
variable_del('custom_search_blocks_' . $delta . '_custom_paths_weight');
variable_del('custom_search_blocks_' . $delta . '_submit_button_weight');
variable_del('custom_search_blocks_' . $delta . '_search_box_region');
variable_del('custom_search_blocks_' . $delta . '_content_types_region');
variable_del('custom_search_blocks_' . $delta . '_custom_paths_region');
variable_del('custom_search_blocks_' . $delta . '_submit_button_region');
variable_del('custom_search_blocks_' . $delta . '_node_types');
variable_del('custom_search_blocks_' . $delta . '_node_types_excluded');
variable_del('custom_search_blocks_' . $delta . '_other');
variable_del('custom_search_blocks_' . $delta . '_type_selector');
variable_del('custom_search_blocks_' . $delta . '_type_selector_label_visibility');
variable_del('custom_search_blocks_' . $delta . '_type_selector_label');
variable_del('custom_search_blocks_' . $delta . '_type_selector_all');
variable_del('custom_search_blocks_' . $delta . '_any_restricts');
variable_del('custom_search_blocks_' . $delta . '_paths');
variable_del('custom_search_blocks_' . $delta . '_paths_selector');
variable_del('custom_search_blocks_' . $delta . '_paths_selector_label');
variable_del('custom_search_blocks_' . $delta . '_paths_selector_label_visibility');
variable_del('custom_search_blocks_' . $delta . '_search_api_page');
if (module_exists('custom_search_i18n')) variable_del('custom_search_i18n_' . $delta . '_search_language');
if (module_exists('custom_search_taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label_visibility');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all');
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_weight');
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region');
}
variable_del('custom_search_blocks_' . $delta . '_paths_terms_separator');
}
}
variable_del('custom_search_blocks_number');
db_delete('variable')
->condition('name', 'custom_search_blocks_%', 'LIKE')
->execute();
}
/**
@@ -92,7 +36,7 @@ function custom_search_blocks_update_7100() {
function custom_search_blocks_update_7101() {
$blocks = variable_get('custom_search_blocks_number', 1);
for ($delta=1 ; $delta<=$blocks ; $delta++) {
for ($delta = 1; $delta <= $blocks; $delta++) {
variable_set('custom_search_blocks_' . $delta . '_submit_text', variable_get('custom_search_submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
variable_set('custom_search_blocks_' . $delta . '_image_path', variable_get('custom_search_image_path', ''));
variable_set('custom_search_blocks_' . $delta . '_criteria_or_display', variable_get('custom_search_criteria_or_display', FALSE));
@@ -102,4 +46,4 @@ function custom_search_blocks_update_7101() {
variable_set('custom_search_blocks_' . $delta . '_criteria_negative_display', variable_get('custom_search_criteria_negative_display', FALSE));
variable_set('custom_search_blocks_' . $delta . '_criteria_negative_label', variable_get('custom_search_criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT));
}
}
}

View File

@@ -30,12 +30,12 @@ function custom_search_blocks_permission() {
return array(
'administer custom search blocks' => array(
'title' => t('Administer custom search blocks'),
'description' => t('Allow users to administer custom search blocks settings')
'description' => t('Allow users to administer custom search blocks settings'),
),
'use custom search blocks' => array(
'title' => t('Use custom search blocks'),
'description' => t('Allow users to use custom search blocks')
)
'description' => t('Allow users to use custom search blocks'),
),
);
}
@@ -44,7 +44,7 @@ function custom_search_blocks_permission() {
*/
function custom_search_blocks_block_info() {
$blocks = array();
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
$blocks[$a]['info'] = "Custom Search $a";
$blocks[$a]['cache'] = DRUPAL_NO_CACHE;
}
@@ -76,9 +76,9 @@ function custom_search_blocks_block_configure($delta = '') {
'#collapsed' => TRUE,
);
$form['content'] = array_merge($form['content'], _custom_search_content_admin_form($delta));
// Custom search paths
// Custom search paths.
$form = array_merge($form, _custom_search_custom_paths_admin_form($delta));
// Ordering
// Ordering.
$form = array_merge($form, _custom_search_ordering_admin_form($delta));
$form['order']['#weight'] = 50;
@@ -90,7 +90,9 @@ function custom_search_blocks_block_configure($delta = '') {
*/
function custom_search_blocks_block_save($delta = '', $edit = array()) {
foreach ($edit as $key => $value) {
if (drupal_substr($key, 0, 20) == 'custom_search_blocks') variable_set($key, $value);
if (drupal_substr($key, 0, 20) == 'custom_search_blocks') {
variable_set($key, $value);
}
}
foreach ($edit['custom_search_blocks_' . $delta . '_order'] as $key => $data) {
variable_set('custom_search_blocks_' . $delta . '_' . $key . '_weight', $data['sort']);
@@ -108,10 +110,11 @@ function custom_search_blocks_block_save($delta = '', $edit = array()) {
}
/**
* Implements hook_forms(). Generates a unique form_id with the same form builder function
* Implements hook_forms().
*/
function custom_search_blocks_forms($form_id, $args) {
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
$forms = array();
for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
$forms['custom_search_blocks_form_' . $a] = array(
'callback' => 'custom_search_blocks_form',
'callback arguments' => array($a),
@@ -137,7 +140,7 @@ function custom_search_blocks_form($form, &$form_state, $delta) {
$form['#submit'] = array('custom_search_submit');
if (function_exists('apachesolr_autocomplete_variable_get_widget')) {
// support for apachesolr_autocomplete module
// Support for apachesolr_autocomplete module.
if (apachesolr_autocomplete_variable_get_widget() == 'custom') {
$form['custom_search_blocks_form_' . $delta]['#attributes']['class'] = array('apachesolr-autocomplete', 'unprocessed');
}

View File

@@ -12,7 +12,7 @@ function custom_search_i18n_help($path, $arg) {
switch ($path) {
case 'admin/config/search/custom_search/taxonomy':
$output = t('Select the vocabularies to present as search options in the search block. If none is selected, no selector will be displayed.');
break;
break;
}
return $output;
}
@@ -25,18 +25,17 @@ function custom_search_i18n_admin() {
/**
* Content admin form.
*/
function _custom_search_i18n_admin_form($delta = '') {
if ($delta != '') $delta = 'blocks_' . $delta . '_';
$form['custom_search_i18n_' . $delta . 'search_language'] = array(
function _custom_search_i18n_admin_form() {
$form['custom_search_i18n_search_language'] = array(
'#type' => 'select',
'#title' => t('Search content from'),
'#options' => array(
'all' => t('any language'),
'current' => t('current language'),
'all' => t('any language'),
'current' => t('current language'),
'current_neutral' => t('current language and language neutral'),
),
'#description' => t('Choose which language will be used to search content.'),
'#default_value' => variable_get('custom_search_i18n_' . $delta . 'search_language', 'all'),
'#default_value' => variable_get('custom_search_i18n_search_language', 'all'),
);
return $form;

View File

@@ -1,17 +1,14 @@
name = Custom Search Internationalization
description = Provides Internationalization to Custom Search.
core = 7.x
package = Custom Search
package = Search
dependencies[] = custom_search
dependencies[] = i18n_string
files[] = custom_search_i18n.module
files[] = custom_search_i18n.admin.inc
files[] = custom_search_i18n.install
; Information added by drupal.org packaging script on 2013-02-26
version = "7.x-1.11+9-dev"
; Information added by Drupal.org packaging script on 2015-02-18
version = "7.x-1.18"
core = "7.x"
project = "custom_search"
datestamp = "1361839667"
datestamp = "1424262482"

View File

@@ -19,11 +19,7 @@ function custom_search_i18n_install() {
* Implements hook_uninstall().
*/
function custom_search_i18n_uninstall() {
variable_del('custom_search_i18n_search_language');
if (module_exists('custom_search_blocks')) {
$blocks = variable_get('custom_search_blocks_number', 1);
for ($delta=1 ; $delta<=$blocks ; $delta++) {
variable_del('custom_search_i18n_' . $delta . '_search_language');
}
}
}
db_delete('variable')
->condition('name', 'custom_search_i18n_%', 'LIKE')
->execute();
}

View File

@@ -3,7 +3,6 @@
/**
* @file
* Brings Internationalization to Custom Search
*
*/
/**
@@ -22,136 +21,148 @@ function custom_search_i18n_menu() {
return $items;
}
/**
* Implements hook_custom_search_box().
*/
function custom_search_i18n_custom_search_box(&$form, $form_id, $delta = '') {
// Criteria.
$criteria = array('or', 'phrase', 'negative');
foreach ($criteria as $c) {
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_display', FALSE)) {
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_region', 'block') == 'popup') {
$form['popup']['custom_search_criteria_' . $c]['#title'] = i18n_string_translate('custom_search:criterion:1:' . $delta . $c . '_label', variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')));
}
else {
$form['custom_search_criteria_' . $c]['#title'] = i18n_string_translate('custom_search:criterion:1:' . $delta . $c . '_label', variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')));
}
}
}
// Title.
$form[$form_id]['#title'] = i18n_string_translate('custom_search:common:1:' . $delta . 'label', variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT));
// Default text.
$form[$form_id]['#attributes']['placeholder'] = i18n_string_translate('custom_search:common:1:' . $delta . 'text', variable_get('custom_search_' . $delta . 'text', ''));
// Hint text.
$form[$form_id]['#attributes']['title'] = i18n_string_translate('custom_search:common:1:' . $delta . 'hint_text', variable_get('custom_search_' . $delta . 'hint_text', CUSTOM_SEARCH_HINT_TEXT_DEFAULT));
// Submit button.
$submit_text = i18n_string_translate('custom_search:common:1:' . $delta . 'submit_text', variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
if ($form['actions']['submit']['#type'] == 'image_button') {
$form['actions']['submit']['#attributes']['alt'] = array($submit_text);
} else {
$form['actions']['submit']['#value'] = $submit_text;
if ($form['actions']['submit']['#value'] == '') {
$form['actions']['submit']['#attributes'] = array('style' => 'display:none;');
}
}
// Type selector.
if ((!empty($form['custom_search_types']) && is_array($form['custom_search_types'])) || (!empty($form['popup']['custom_search_types']) && is_array($form['popup']['custom_search_types']))) {
if (variable_get('custom_search_' . $delta . 'content_types_region', 'block') == 'popup') {
$form['popup']['custom_search_types']['#title'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
if (array_key_exists('c-all', $form['popup']['custom_search_types']['#options'])) {
$form['popup']['custom_search_types']['#options']['c-all'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
else {
$form['custom_search_types']['#title'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
if (array_key_exists('c-all', $form['custom_search_types']['#options'])) {
$form['custom_search_types']['#options']['c-all'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
}
// Taxonomy.
if (module_exists('custom_search_taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
// Translate label and -all-.
foreach ($vocabularies as $voc) {
if ((!empty($form['custom_search_vocabulary_' . $voc->vid]) && is_array($form['custom_search_vocabulary_' . $voc->vid])) || (!empty($form['popup']['custom_search_vocabulary_' . $voc->vid]) && is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]))) {
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#title'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name));
if (is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']) && array_key_exists('c-all', $form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'])) {
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']['c-all'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
else {
$form['custom_search_vocabulary_' . $voc->vid]['#title'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name));
if (!empty($form['custom_search_vocabulary_' . $voc->vid]['#options']) && array_key_exists('c-all', $form['custom_search_vocabulary_' . $voc->vid]['#options'])) {
$form['custom_search_vocabulary_' . $voc->vid]['#options']['c-all'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
}
}
// Translate terms.
if (module_exists('i18n_taxonomy')) {
foreach ($vocabularies as $voc) {
if ((!empty($form['custom_search_vocabulary_' . $voc->vid]) && !empty($form['custom_search_vocabulary_' . $voc->vid]['#options'])) || (!empty($form['popup']['custom_search_vocabulary_' . $voc->vid]) && !empty($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']))) {
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
foreach ($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'] as $tid => $name) {
if ($tid != 'c-all') {
$real_tid = substr($tid, 2);
$translated_term = i18n_string_translate('taxonomy:term:' . $real_tid . ':name', $name);
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'][$tid] = ($translated_term[0] != '-') ? str_repeat('-', _custom_search_i18n_term_depth($real_tid)) . ' ' . $translated_term : $translated_term;
}
}
}
else {
foreach ($form['custom_search_vocabulary_' . $voc->vid]['#options'] as $tid => $name) {
if ($tid != 'c-all') {
$real_tid = substr($tid, 2);
$translated_term = i18n_string_translate('taxonomy:term:' . $real_tid . ':name', $name);
$form['custom_search_vocabulary_' . $voc->vid]['#options'][$tid] = ($translated_term[0] != '-') ? str_repeat('-', _custom_search_i18n_term_depth($real_tid)) . ' ' . $translated_term : $translated_term;
}
}
}
}
}
}
}
// Custom Paths.
if ((!empty($form['custom_search_paths']) && is_array($form['custom_search_paths'])) || (!empty($form['popup']['custom_search_paths']) && is_array($form['popup']['custom_search_paths']))) {
if (variable_get('custom_search_' . $delta . 'custom_paths_region', 'block') == 'popup') {
$form['popup']['custom_search_paths']['#title'] = i18n_string_translate('custom_search:paths:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
}
else {
$form['custom_search_paths']['#title'] = i18n_string_translate('custom_search:paths:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
}
}
}
/**
* Implements hook_form_alter().
*/
function custom_search_i18n_form_alter(&$form, &$form_state, $form_id) {
// Filter the form_id value to identify all the custom blocks
$form_id_processed = $form_id;
$delta = '';
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
if ($form_id == 'custom_search_blocks_form_' . $a) {
$form_id_processed = 'custom_search_blocks_form';
$delta = 'blocks_' . $a . '_';
}
}
switch ($form_id) {
switch ($form_id_processed) {
case 'search_theme_form':
case 'search_block_form':
case 'custom_search_blocks_form':
case 'custom_search_admin':
$form['#submit'][] = 'custom_search_i18n_admin_submit';
break;
if (user_access('use custom search')) {
// Criteria
$criteria = array('or', 'phrase', 'negative');
foreach ($criteria as $c) {
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_display', FALSE)) {
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_region', 'block') == 'popup') {
$form['popup']['custom_search_criteria_' . $c]['#title'] = i18n_string_translate('custom_search:criterion:1:' . $delta . $c . '_label', variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')));
}
else {
$form['custom_search_criteria_' . $c]['#title'] = i18n_string_translate('custom_search:criterion:1:' . $delta . $c . '_label', variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')));
}
}
}
case 'custom_search_content_admin':
$form['#submit'][] = 'custom_search_i18n_content_admin_submit';
break;
// Title
$form[$form_id]['#title'] = i18n_string_translate('custom_search:common:1:' . $delta . 'label', variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT));
case 'custom_search_taxonomy_admin':
$form['#submit'][] = 'custom_search_i18n_taxonomy_admin_submit';
break;
// Default text
$form[$form_id]['#attributes']['placeholder'] = array(i18n_string_translate('custom_search:common:1:' . $delta . 'text', variable_get('custom_search_' . $delta . 'text', '')));
case 'custom_search_results_admin':
$form['#submit'][] = 'custom_search_i18n_results_admin_submit';
break;
// Submit button
$form['actions']['submit']['#value'] = i18n_string_translate('custom_search:common:1:' . $delta . 'submit_text', variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
if ($form['actions']['submit']['#value'] == '') $form['actions']['submit']['#attributes'] = array('style' => 'display:none;');
// Type selector
if ((!empty($form['custom_search_types']) && is_array($form['custom_search_types'])) || (!empty($form['popup']['custom_search_types']) && is_array($form['popup']['custom_search_types']))) {
if (variable_get('custom_search_' . $delta . 'content_types_region', 'block') == 'popup') {
$form['popup']['custom_search_types']['#title'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
if (array_key_exists('c-all', $form['popup']['custom_search_types']['#options'])) {
$form['popup']['custom_search_types']['#options']['c-all'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
else {
$form['custom_search_types']['#title'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
if (array_key_exists('c-all', $form['custom_search_types']['#options'])) {
$form['custom_search_types']['#options']['c-all'] = i18n_string_translate('custom_search:content_types:1:' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
}
// Taxonomy
if (module_exists('custom_search_taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
// Translate label and -all-
foreach ($vocabularies as $voc) {
if ((!empty($form['custom_search_vocabulary_' . $voc->vid]) && is_array($form['custom_search_vocabulary_' . $voc->vid])) || (!empty($form['popup']['custom_search_vocabulary_' . $voc->vid]) && is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]))) {
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#title'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name));
if (is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']) && array_key_exists('c-all', $form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'])) {
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']['c-all'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
else {
$form['custom_search_vocabulary_' . $voc->vid]['#title'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name));
if (!empty($form['custom_search_vocabulary_' . $voc->vid]['#options']) && array_key_exists('c-all', $form['custom_search_vocabulary_' . $voc->vid]['#options'])) {
$form['custom_search_vocabulary_' . $voc->vid]['#options']['c-all'] = i18n_string_translate('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
}
}
// Translate terms
if (module_exists('i18n_taxonomy')) {
foreach ($vocabularies as $voc) {
if ((!empty($form['custom_search_vocabulary_' . $voc->vid]) && !empty($form['custom_search_vocabulary_' . $voc->vid]['#options'])) || (!empty($form['popup']['custom_search_vocabulary_' . $voc->vid]) && !empty($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']))) {
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
foreach ($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'] as $tid => $name) {
if ($tid != 'c-all') {
$real_tid = substr($tid, 2);
$translated_term = i18n_string_translate('taxonomy:term:' . $real_tid . ':name', $name);
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'][$tid] = ($translated_term[0] != '-') ? str_repeat('-', _custom_search_i18n_term_depth($real_tid)) . ' ' . $translated_term : $translated_term ;
}
}
}
else {
foreach ($form['custom_search_vocabulary_' . $voc->vid]['#options'] as $tid => $name) {
if ($tid != 'c-all') {
$real_tid = substr($tid, 2);
$translated_term = i18n_string_translate('taxonomy:term:' . $real_tid . ':name', $name);
$form['custom_search_vocabulary_' . $voc->vid]['#options'][$tid] = ($translated_term[0] != '-') ? str_repeat('-', _custom_search_i18n_term_depth($real_tid)) . ' ' . $translated_term : $translated_term ;
}
}
}
}
}
}
}
// Custom Paths
if ((!empty($form['custom_search_paths']) && is_array($form['custom_search_paths'])) || (!empty($form['popup']['custom_search_paths']) && is_array($form['popup']['custom_search_paths']))) {
if (variable_get('custom_search_' . $delta . 'custom_paths_region', 'block') == 'popup') {
$form['popup']['custom_search_paths']['#title'] = i18n_string_translate('custom_search:paths:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
}
else {
$form['custom_search_paths']['#title'] = i18n_string_translate('custom_search:paths:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
}
}
}
break;
case 'custom_search_admin': $form['#submit'][] = 'custom_search_i18n_admin_submit'; break;
case 'custom_search_content_admin': $form['#submit'][] = 'custom_search_i18n_content_admin_submit'; break;
case 'custom_search_taxonomy_admin': $form['#submit'][] = 'custom_search_i18n_taxonomy_admin_submit'; break;
case 'custom_search_results_admin': $form['#submit'][] = 'custom_search_i18n_results_admin_submit'; break;
case 'block_admin_configure':
// Custom Search Blocks
// Custom Search Blocks.
if (isset($form['module']) && $form['module']['#value'] == 'custom_search_blocks') {
$form['#submit'][] = 'custom_search_i18n_block_admin_configure_submit';
}
break;
break;
}
}
@@ -168,6 +179,7 @@ function custom_search_i18n_preprocess_search_results(&$variables) {
function custom_search_i18n_admin_submit($form, &$form_state) {
i18n_string_update('custom_search:common:1:label', $form_state['values']['custom_search_label']);
i18n_string_update('custom_search:common:1:text', $form_state['values']['custom_search_text']);
i18n_string_update('custom_search:common:1:hint_text', $form_state['values']['custom_search_hint_text']);
i18n_string_update('custom_search:common:1:submit_text', $form_state['values']['custom_search_submit_text']);
i18n_string_update('custom_search:criterion:1:or_label', $form_state['values']['custom_search_criteria_or_label']);
i18n_string_update('custom_search:criterion:1:phrase_label', $form_state['values']['custom_search_criteria_phrase_label']);
@@ -196,6 +208,7 @@ function custom_search_i18n_block_admin_configure_submit($form, &$form_state) {
$delta = $form_state['values']['delta'];
i18n_string_update('custom_search:common:1:blocks_' . $delta . '_label', $form_state['values']['custom_search_blocks_' . $delta . '_label']);
i18n_string_update('custom_search:common:1:blocks_' . $delta . '_text', $form_state['values']['custom_search_blocks_' . $delta . '_text']);
i18n_string_update('custom_search:common:1:blocks_' . $delta . '_hint_text', $form_state['values']['custom_search_blocks_' . $delta . '_hint_text']);
i18n_string_update('custom_search:common:1:blocks_' . $delta . '_submit_text', $form_state['values']['custom_search_blocks_' . $delta . '_submit_text']);
i18n_string_update('custom_search:criterion:1:blocks_' . $delta . '_or_label', $form_state['values']['custom_search_blocks_' . $delta . '_criteria_or_label']);
i18n_string_update('custom_search:criterion:1:blocks_' . $delta . '_phrase_label', $form_state['values']['custom_search_blocks_' . $delta . '_criteria_phrase_label']);
@@ -216,20 +229,24 @@ function custom_search_i18n_block_admin_configure_submit($form, &$form_state) {
* Implements hook_locale().
*/
function custom_search_i18n_locale($op = 'groups', $group = NULL) {
$value = array();
switch ($op) {
case 'groups':
return array('custom_search' => t('Custom Search'));
break;
$value['custom_search'] = t('Custom Search');
break;
case 'info':
$info['custom_search']['refresh callback'] = 'custom_search_i18n_locale_refresh';
return $info;
break;
$value['custom_search']['refresh callback'] = 'custom_search_i18n_locale_refresh';
break;
}
return $value;
}
function custom_search_i18n_locale_refresh() {
i18n_string_update('custom_search:common:1:label', variable_get('custom_search_label', CUSTOM_SEARCH_LABEL_DEFAULT));
i18n_string_update('custom_search:common:1:text', variable_get('custom_search_text', ''));
i18n_string_update('custom_search:common:1:hint_text', variable_get('custom_search_hint_text', CUSTOM_SEARCH_HINT_TEXT_DEFAULT));
i18n_string_update('custom_search:common:1:submit_text', variable_get('custom_search_submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
i18n_string_update('custom_search:content_types:1:selector_label', variable_get('custom_search_type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
i18n_string_update('custom_search:content_types:1:selector_all', variable_get('custom_search_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
@@ -239,26 +256,27 @@ function custom_search_i18n_locale_refresh() {
i18n_string_update('custom_search:criterion:1:negative_label', variable_get('custom_search_criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT));
i18n_string_update('custom_search:filter:1:label', variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT));
if (module_exists('custom_search_taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':selector_label', variable_get('custom_search_voc' . $voc->vid . '_selector_label', $voc->name));
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':selector_all', variable_get('custom_search_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
if (module_exists('custom_search_blocks')) {
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_voc' . $voc->vid . '_selector_label', $voc->name));
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $a . '_selector_all', variable_get('custom_search_blocks_' . $a . '_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':selector_label', variable_get('custom_search_voc' . $voc->vid . '_selector_label', $voc->name));
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':selector_all', variable_get('custom_search_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
if (module_exists('custom_search_blocks')) {
for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_voc' . $voc->vid . '_selector_label', $voc->name));
i18n_string_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $a . '_selector_all', variable_get('custom_search_blocks_' . $a . '_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
}
}
}
}
if (module_exists('custom_search_blocks')) {
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
i18n_string_update('custom_search:common:1:blocks_' . $a . '_label', variable_get('custom_search_blocks_' . $a . '_label', CUSTOM_SEARCH_LABEL_DEFAULT));
i18n_string_update('custom_search:common:1:blocks_' . $a . '_text', $form_state['values']['custom_search_blocks_' . $a . '_text']);
i18n_string_update('custom_search:common:1:blocks_' . $a . '_submit_text', $form_state['values']['custom_search_blocks_' . $a . '_submit_text']);
i18n_string_update('custom_search:criterion:1:blocks_' . $a . '_or_label', $form_state['values']['custom_search_blocks_' . $a . '_criteria_or_label']);
i18n_string_update('custom_search:criterion:1:blocks_' . $a . '_phrase_label', $form_state['values']['custom_search_blocks_' . $a . '_criteria_phrase_label']);
i18n_string_update('custom_search:criterion:1:blocks_' . $a . '_negative_label', $form_state['values']['custom_search_blocks_' . $a . '_criteria_negative_label']);
i18n_string_update('custom_search:common:1:blocks_' . $a . '_text', variable_get('custom_search_blocks_' . $a . '_text', ''));
i18n_string_update('custom_search:common:1:blocks_' . $a . '_hint_text', variable_get('custom_search_blocks_' . $a . '_hint_text', CUSTOM_SEARCH_HINT_TEXT_DEFAULT));
i18n_string_update('custom_search:common:1:blocks_' . $a . '_submit_text', variable_get('custom_search_blocks_' . $a . '_submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
i18n_string_update('custom_search:criterion:1:blocks_' . $a . '_or_label', variable_get('custom_search_blocks_' . $a . '_criteria_or_label', CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT));
i18n_string_update('custom_search:criterion:1:blocks_' . $a . '_phrase_label', variable_get('custom_search_blocks_' . $a . '_criteria_phrase_label', CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT));
i18n_string_update('custom_search:criterion:1:blocks_' . $a . '_negative_label', variable_get('custom_search_blocks_' . $a . '_criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT));
i18n_string_update('custom_search:content_types:1:blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
i18n_string_update('custom_search:content_types:1:blocks_' . $a . '_selector_all', variable_get('custom_search_blocks_' . $a . '_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
i18n_string_update('custom_search:paths:1:blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
@@ -273,7 +291,9 @@ function _custom_search_i18n_term_depth($tid) {
while ($parent = db_query_range('SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid', 0, 1, array(':tid' => $tid))->fetchObject()) {
$tid = $parent->parent;
$depth++;
if ($depth > $limit) break;
if ($depth > $limit) {
break;
}
}
return $depth;
}
}

View File

@@ -12,13 +12,15 @@ function custom_search_taxonomy_help($path, $arg) {
switch ($path) {
case 'admin/config/search/custom_search/taxonomy':
$output = t('Select the vocabularies to present as search options in the search block. If none is selected, no selector will be displayed.');
break;
break;
}
return $output;
}
function custom_search_taxonomy_admin() {
$vocabularies = taxonomy_get_vocabularies();
if (count($vocabularies)) $form = _custom_search_taxonomy_admin_form($vocabularies);
return system_settings_form($form);
}
if (count($vocabularies)) {
$form = _custom_search_taxonomy_admin_form($vocabularies);
return system_settings_form($form);
}
}

View File

@@ -1,19 +1,16 @@
name = Custom Search Taxonomy
description = Adds taxonomy selectors to Custom Search.
core = 7.x
package = Custom Search
package = Search
dependencies[] = custom_search
dependencies[] = taxonomy
files[] = custom_search_taxonomy.admin.inc
files[] = custom_search_taxonomy.module
files[] = custom_search_taxonomy.install
configure = admin/config/search/custom_search/taxonomy
; Information added by drupal.org packaging script on 2013-02-26
version = "7.x-1.11+9-dev"
; Information added by Drupal.org packaging script on 2015-02-18
version = "7.x-1.18"
core = "7.x"
project = "custom_search"
datestamp = "1361839667"
datestamp = "1424262482"

View File

@@ -19,27 +19,16 @@ function custom_search_taxonomy_install() {
* Implements hook_uninstall().
*/
function custom_search_taxonomy_uninstall() {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
variable_del('custom_search_voc' . $voc->vid . '_selector');
variable_del('custom_search_voc' . $voc->vid . '_selector_depth');
variable_del('custom_search_voc' . $voc->vid . '_selector_label_visibility');
variable_del('custom_search_voc' . $voc->vid . '_selector_label');
variable_del('custom_search_voc' . $voc->vid . '_selector_all');
variable_del('custom_search_taxonomy' . $voc->vid . '_weight');
variable_del('custom_search_taxonomy' . $voc->vid . '_region');
if (module_exists('custom_search_blocks')) {
$blocks = variable_get('custom_search_blocks_number', 1);
for ($delta=1 ; $delta<=$blocks ; $delta++) {
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_depth');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label_visibility');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label');
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all');
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_weight');
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region');
variable_del('custom_search_blocks_' . $delta . '_paths_terms_separator');
}
}
}
}
db_delete('variable')
->condition('name', 'custom_search_voc%', 'LIKE')
->execute();
db_delete('variable')
->condition('name', 'custom_search_taxonomy%', 'LIKE')
->execute();
db_delete('variable')
->condition('name', 'custom_search_blocks_%_voc%', 'LIKE')
->execute();
db_delete('variable')
->condition('name', 'custom_search_blocks_%_taxonomy%', 'LIKE')
->execute();
}

View File

@@ -10,7 +10,9 @@
/*
* Includes.
*/
if (module_exists('hs_taxonomy')) module_load_include('inc', 'hierarchical_select', 'includes/common');
if (module_exists('hs_taxonomy')) {
module_load_include('inc', 'hierarchical_select', 'includes/common');
}
/**
* Implements hook_menu().
@@ -28,15 +30,79 @@ function custom_search_taxonomy_menu() {
return $items;
}
/**
* Implements hook_custom_search_box().
*/
function custom_search_taxonomy_custom_search_box(&$form, $form_id, $delta = '') {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
if (variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled') != 'disabled') {
$options = array();
$options['c-all'] = variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT);
$vocabulary_depth = (!variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth', 0)) ? NULL : variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth', 0);
$terms = taxonomy_get_tree($voc->vid, 0, $vocabulary_depth);
foreach ($terms as $term) {
$options['c-' . $term->tid] = (drupal_substr(variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled'), 0, 6) == 'select') ? str_repeat('-', $term->depth) . ' ' . $term->name : $term->name;
}
$selector_type = variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'select');
if ($selector_type == 'selectmultiple') {
$selector_type = 'select';
$multiple = TRUE;
}
else {
$multiple = FALSE;
}
$form['custom_search_vocabulary_' . $voc->vid] = array(
'#type' => $selector_type,
'#multiple' => $multiple,
'#title' => variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name),
'#options' => $options,
'#default_value' => ($selector_type == 'checkboxes') ? array('c-all') : 'c-all',
'#attributes' => array('class' => array('custom-search-selector', 'custom-search-vocabulary')),
'#weight' => variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_weight', 2),
);
if (module_exists('hs_taxonomy') && $selector_type == 'hierarchical_select') {
$hs_config = hierarchical_select_common_config_get('taxonomy-' . $voc->vid);
$hs_config['module'] = 'hs_taxonomy';
$hs_config['params'] = array(
'vid' => $voc->vid,
'exclude_tid' => 0,
'root_term' => 0,
'entity_count_for_node_type' => 0,
);
$form['custom_search_vocabulary_' . $voc->vid]['#config'] = $hs_config;
unset($form['custom_search_vocabulary_' . $voc->vid]['#options']);
}
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
$form['popup']['custom_search_vocabulary_' . $voc->vid] = $form['custom_search_vocabulary_' . $voc->vid];
unset($form['custom_search_vocabulary_' . $voc->vid]);
}
if (!variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label_visibility', TRUE)) {
$form['custom_search_vocabulary_' . $voc->vid]['#title_display'] = 'invisible';
}
}
}
// Custom paths.
if (variable_get('custom_search_' . $delta . 'paths', '') != '') {
$form['custom_search_paths_terms_separator'] = array(
'#type' => 'hidden',
'#default_value' => variable_get('custom_search_' . $delta . 'paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
);
}
}
/**
* Implements hook_form_alter().
*/
function custom_search_taxonomy_form_alter(&$form, &$form_state, $form_id) {
// Filter the form_id value to identify all the custom blocks
// Filter the form_id value to identify all the custom blocks.
$form_id_processed = $form_id;
$delta = '';
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
if ($form_id == 'custom_search_blocks_form_' . $a) {
$form_id_processed = 'custom_search_blocks_form';
$delta = 'blocks_' . $a . '_';
@@ -45,69 +111,6 @@ function custom_search_taxonomy_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id_processed) {
case 'search_theme_form':
case 'search_block_form':
case 'custom_search_blocks_form':
if (user_access('use custom search')) {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
if (variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled') != 'disabled') {
$options = array();
$options['c-all'] = variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT);
$vocabulary_depth = (!variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth', 0)) ? NULL : variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth', 0);
$terms = taxonomy_get_tree($voc->vid, 0, $vocabulary_depth);
foreach ($terms as $term) {
$options['c-' . $term->tid] = (drupal_substr(variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled'), 0, 6) == 'select') ? str_repeat('-', $term->depth) . ' ' . $term->name : $term->name ;
}
$selector_type = variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'select');
if ($selector_type == 'selectmultiple') {
$selector_type = 'select';
$multiple = TRUE;
}
else $multiple = FALSE;
$form['custom_search_vocabulary_' . $voc->vid] = array(
'#type' => $selector_type,
'#multiple' => $multiple,
'#title' => variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name),
'#options' => $options,
'#default_value' => ($selector_type == 'checkboxes') ? array('c-all') : 'c-all',
'#attributes' => array('class' => array('custom-search-selector', 'custom-search-vocabulary')),
'#weight' => variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_weight', 2),
);
if (module_exists('hs_taxonomy') && $selector_type == 'hierarchical_select') {
$hs_config = hierarchical_select_common_config_get('taxonomy-' . $voc->vid);
$hs_config['module'] = 'hs_taxonomy';
$hs_config['params'] = array(
'vid' => $voc->vid,
'exclude_tid' => 0,
'root_term' => 0,
'entity_count_for_node_type' => 0,
);
$form['custom_search_vocabulary_' . $voc->vid]['#config'] = $hs_config;
unset($form['custom_search_vocabulary_' . $voc->vid]['#options']);
}
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
$form['popup']['custom_search_vocabulary_' . $voc->vid] = $form['custom_search_vocabulary_' . $voc->vid];
unset($form['custom_search_vocabulary_' . $voc->vid]);
}
if (!variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label_visibility', TRUE)) $form['custom_search_vocabulary_' . $voc->vid]['#title_display'] = 'invisible';
}
}
// Custom paths
if (variable_get('custom_search_' . $delta . 'paths', '') != '') {
$form['custom_search_paths_terms_separator'] = array(
'#type' => 'hidden',
'#default_value' => variable_get('custom_search_' . $delta . 'paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
);
}
}
break;
case 'block_admin_configure':
if (isset($form['module']) && $form['module']['#value'] == 'custom_search_blocks') {
@@ -121,12 +124,14 @@ function custom_search_taxonomy_form_alter(&$form, &$form_state, $form_id) {
'#description' => t('Select the vocabularies to present as search options in the search block. If none is selected, no selector will be displayed.'),
'#collapsible' => TRUE,
);
// Get vocabularies forms
// Get vocabularies forms.
$form['settings']['taxonomy'] = _custom_search_taxonomy_admin_form($vocabularies, $delta);
$form['settings']['order']['custom_search_blocks_' . $delta . '_order'] = array_merge($form['settings']['order']['custom_search_blocks_' . $delta . '_order'], _custom_search_taxonomy_sort_form($vocabularies, $delta));
$collapsed = TRUE;
foreach ($vocabularies as $voc) {
if (variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector', 'disabled') != 'disabled') $collapsed = FALSE;
if (variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector', 'disabled') != 'disabled') {
$collapsed = FALSE;
}
}
$form['settings']['taxonomy']['#collapsed'] = $collapsed;
}
@@ -136,25 +141,27 @@ function custom_search_taxonomy_form_alter(&$form, &$form_state, $form_id) {
'#type' => 'textfield',
'#title' => t('Taxonomy terms separator'),
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
'#size' => 2
'#size' => 2,
);
}
break;
break;
case 'custom_search_admin':
$vocabularies = taxonomy_get_vocabularies();
if (count($vocabularies)) $form['order']['custom_search_order'] = array_merge($form['order']['custom_search_order'], _custom_search_taxonomy_sort_form($vocabularies));
if (count($vocabularies)) {
$form['order']['custom_search_order'] = array_merge($form['order']['custom_search_order'], _custom_search_taxonomy_sort_form($vocabularies));
}
$form['custom_search_paths_admin']['custom_search_paths']['#description'] = t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box, and the [terms] token will be replaced by the selected taxonomy term id(s). Ie: mysearch/[key]/[terms]|My custom search label.');
$form['custom_search_paths_admin']['custom_search_paths_terms_separator'] = array(
'#type' => 'textfield',
'#title' => t('Taxonomy terms separator'),
'#default_value' => variable_get('custom_search_paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
'#size' => 2
'#size' => 2,
);
break;
break;
}
@@ -164,13 +171,15 @@ function custom_search_taxonomy_form_alter(&$form, &$form_state, $form_id) {
* Default admin form.
*/
function _custom_search_taxonomy_admin_form($vocabularies, $delta = '') {
if ($delta != '') $delta = 'blocks_' . $delta . '_';
if ($delta != '') {
$delta = 'blocks_' . $delta . '_';
}
$form = array();
foreach ($vocabularies as $voc) {
$form[$voc->name] = array(
'#type' => 'fieldset',
'#title' => $voc->name,
'#title' => check_plain($voc->name),
'#collapsible' => TRUE,
'#collapsed' => (variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled') == 'disabled') ? TRUE : FALSE,
);
@@ -187,7 +196,9 @@ function _custom_search_taxonomy_admin_form($vocabularies, $delta = '') {
'#description' => t('Choose which selector type to use.'),
'#default_value' => variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled'),
);
if (module_exists('hs_taxonomy')) $form[$voc->name]['custom_search_' . $delta . 'voc' . $voc->vid . '_selector']['#options']['hierarchical_select'] = t('Hierarchical selector');
if (module_exists('hs_taxonomy')) {
$form[$voc->name]['custom_search_' . $delta . 'voc' . $voc->vid . '_selector']['#options']['hierarchical_select'] = t('Hierarchical selector');
}
$form[$voc->name]['custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth'] = array(
'#type' => 'textfield',
'#title' => t('Depth'),
@@ -204,7 +215,7 @@ function _custom_search_taxonomy_admin_form($vocabularies, $delta = '') {
'#type' => 'textfield',
'#title' => t('Label text'),
'#default_value' => variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name),
'#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => $voc->name)),
'#description' => t('Enter the label text for the selector. The default value is "@default".', array('@default' => $voc->name)),
'#states' => array(
'visible' => array(
':input[name="custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label_visibility"]' => array('checked' => TRUE),
@@ -228,31 +239,43 @@ function _custom_search_taxonomy_admin_form($vocabularies, $delta = '') {
* Sort form.
*/
function _custom_search_taxonomy_sort_form($vocabularies, $delta = '') {
if ($delta != '') $delta = 'blocks_' . $delta . '_';
if ($delta != '') {
$delta = 'blocks_' . $delta . '_';
}
$form = array();
$w = 1;
foreach ($vocabularies as $voc) {
$form['taxonomy' . $voc->vid] = array(
'#title' => t('Taxonomy') . ': ' . $voc->name,
'#title' => t('Taxonomy') . ': ' . check_plain($voc->name),
'#weight' => variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_weight', $w),
);
$form['taxonomy' . $voc->vid]['sort'] = array(
'#type' => 'weight',
'#default_value' => variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_weight', $w),
'#attributes' => array('class' => array('sort-select', 'sort-select-' . variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block'))),
'#attributes' => array(
'class' => array(
'sort-select',
'sort-select-' . variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block'),
),
),
);
$form['taxonomy' . $voc->vid]['region'] = array(
'#type' => 'select',
'#options' => array(
'block' => t('Block'),
'popup' => t('Popup')
'popup' => t('Popup'),
),
'#default_value' => variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block'),
'#attributes' => array('class' => array('region-select', 'region-select-' . variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block'))),
'#attributes' => array(
'class' => array(
'region-select',
'region-select-' . variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block'),
),
),
);
$w++;
}
return $form;
}
}

View File

@@ -55,7 +55,6 @@
<?php endif; ?>
<?php if ($info) : ?>
<p class="search-info"><?php print $info; ?></p>
<?php endif; ?>
<?php //print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
<?php endif; ?>
</div>
</li>

View File

@@ -22,19 +22,19 @@
?>
<?php if ($search_results) : ?>
<h2><?php print t('Search results');?></h2>
<?php if (isset($filter) && $filter != '' && $filter_position == 'above') { ?>
<?php if (isset($filter) && $filter != '' && $filter_position == 'above') : ?>
<div class="custom-search-filter">
<?php print $filter; ?>
</div>
<?php } ?>
<?php endif; ?>
<ol class="search-results <?php print $module; ?>-results">
<?php print $search_results; ?>
</ol>
<?php if (isset($filter) && $filter != '' && $filter_position == 'below') { ?>
<?php if (isset($filter) && $filter != '' && $filter_position == 'below') : ?>
<div class="custom-search-filter">
<?php print $filter; ?>
</div>
<?php } ?>
<?php endif; ?>
<?php print $pager; ?>
<?php else : ?>
<h2><?php print t('Your search yielded no results');?></h2>

View File

@@ -9,15 +9,17 @@
'block' => array('title' => t('Block'), 'count' => 0),
'popup' => array('title' => t('Popup'), 'count' => 0),
);
foreach (element_children($form) as $element) $element_regions[$form[$element]['region']['#value']]['count']++;
foreach (element_children($form) as $element) :
$element_regions[$form[$element]['region']['#value']]['count']++;
endforeach;
// Add table javascript.
drupal_add_js('misc/tableheader.js');
drupal_add_js(drupal_get_path('module', 'custom_search') . '/js/custom_search_sort.js');
foreach ($element_regions as $region => $title) {
foreach ($element_regions as $region => $title) :
drupal_add_tabledrag('elements', 'match', 'sibling', 'region-select', 'region-select-' . $region, NULL, FALSE);
drupal_add_tabledrag('elements', 'order', 'sibling', 'sort-select', 'sort-select-' . $region);
}
endforeach;
?>
<table id="elements" class="sticky-enabled">
<thead>
@@ -33,7 +35,7 @@
<tr class="region-title region-title-<?php print $region?>">
<td colspan="3"><?php print $region_data['title']; ?></td>
</tr>
<tr class="region-message region-<?php print $region?>-message <?php print((!$region_data['count']) ? 'region-empty' : 'region-populated'); ?>">
<tr class="region-message region-<?php print $region?>-message <?php print ((!$region_data['count']) ? 'region-empty' : 'region-populated'); ?>">
<td colspan="3"><em><?php print t('No elements in this region'); ?></em></td>
</tr>
<?php foreach (element_children($form) as $element):
@@ -49,4 +51,4 @@
endforeach;
endforeach; ?>
</tbody>
</table>
</table>

View File

@@ -11,37 +11,49 @@
function custom_search_preprocess_search_results(&$variables) {
if ($variables['module'] == 'node') {
$variables['filter_position'] = variable_get('custom_search_filter', 'disabled');
// save # of results for collapsing advanced search
// Save # of results for collapsing advanced search.
$GLOBALS['custom_search_nb_results'] = count($variables['results']);
// generate the filter
// Generate the filter.
if (user_access('use custom search') && $variables['filter_position'] != 'disabled') {
// Get search words (minus type:node_type)
// Get search words (minus type:node_type).
$path = explode('/', $_GET['q'], 3);
$keys = empty($_REQUEST['keys']) ? '' : $_REQUEST['keys'];
if (count($path) == 3) $keys = $path[2];
if (strpos($keys, 'type:') !== FALSE) {
$keys = drupal_substr($keys, 0, strpos($keys, 'type:')-1);
if (count($path) == 3) {
$keys = $path[2];
}
// Get Custom Search authorized types
if (strpos($keys, 'type:') !== FALSE) {
$keys = drupal_substr($keys, 0, strpos($keys, 'type:') - 1);
}
// Get Custom Search authorized types.
$searchable_node_types = variable_get('custom_search_node_types', array());
$searchable_node_types = array_keys(array_filter($searchable_node_types, 'custom_search_filter_array'));
if (!count($searchable_node_types)) $searchable_node_types = array_keys(node_type_get_names());
if (!count($searchable_node_types)) {
$searchable_node_types = array_keys(node_type_get_names());
}
$node_types = db_query("SELECT type, name FROM {node_type} WHERE type IN (:ntypes)", array(':ntypes' => $searchable_node_types));
// Build menu
// Build menu.
$items = array();
$items[] = l(variable_get('custom_search_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT), 'search/node/' . $keys);
foreach ($node_types as $node_type) {
// count # of results per type
// Count # of results per type.
$nbresults = 0;
foreach ($variables['results'] as $result) {
if ($result['node']->type == $node_type->type) $nbresults++;
if ($result['node']->type == $node_type->type) {
$nbresults++;
}
}
if ($nbresults) {
$items[] = l($node_type->name, 'search/node/' . $keys . ' type:' . $node_type->type);
}
if ($nbresults) $items[] = l($node_type->name, 'search/node/' . $keys . ' type:' . $node_type->type);
}
if (!isset($variables['filter-title'])) $variables['filter-title'] = variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT);
if (count($items) > 2) $variables['filter'] = theme('item_list', array('items' => $items, 'title' => $variables['filter-title']));
if (!isset($variables['filter-title'])) {
$variables['filter-title'] = filter_xss(variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT));
}
if (count($items) > 2) {
$variables['filter'] = theme('item_list', array('items' => $items, 'title' => $variables['filter-title']));
}
}
$variables['theme_hook_suggestions'][] = 'custom_search_results';
$variables['theme_hook_suggestions'][] = 'custom_search_results';
}
}
@@ -63,4 +75,4 @@ function custom_search_preprocess_search_result(&$variables) {
}
$variables['info'] = implode(' - ', $infos);
$variables['theme_hook_suggestions'][] = 'custom_search_result';
}
}