The response from the search define('SGA_DEFAULT_ERROR_LIB_XML_PARSE_ERROR_FORMAT', NULL); /** - * Minimize redundant trips to the db when looking for module settings. - * Hooks that change module settings should run this function with - * $refresh = TRUE so other hooks can just get settings without a db - * query. + * Returns all module settings for the Google Appliance module. * - * @arg $refresh - * TRUE >> query the db for the settings - * - * @return - * a keyed array of module settings keyed by $field_keys + * @return array + * An associative array of module settings keyed by $field_keys. */ -function _google_appliance_get_settings($refresh = FALSE) { - - static $settings; - +function _google_appliance_get_settings() { $field_keys = array( 'hostname', 'collection', @@ -53,6 +45,7 @@ function _google_appliance_get_settings($refresh = FALSE) { 'timeout', 'autofilter', 'language_filter_toggle', + 'language_filter_options', 'query_inspection', 'search_title', 'results_per_page', @@ -69,35 +62,28 @@ function _google_appliance_get_settings($refresh = FALSE) { 'error_lib_xml_parse_error_format', ); - if ($refresh || empty($settings)) { - - // Settings fall back to default constants. - foreach ($field_keys as $field) { - $settings[$field] = variable_get( - 'google_appliance_' . $field, - constant('SGA_DEFAULT_' . strtoupper($field)) - ); - } - - // The default value of language_filter_options is an array, which - // cannot be used as a PHP constant. We set it here. - $settings['language_filter_options'] = variable_get( - 'google_appliance_language_filter_options', - array('***CURRENT_LANGUAGE***') + // Settings fall back to default constants. + foreach ($field_keys as $field) { + $settings[$field] = variable_get( + 'google_appliance_' . $field, + constant('SGA_DEFAULT_' . strtoupper($field)) ); + } - // Convert onebox_modules from string to array. - $settings['onebox_modules'] = explode("\n", $settings['onebox_modules']); - $settings['onebox_modules'] = array_map('trim', $settings['onebox_modules']); - $settings['onebox_modules'] = array_filter($settings['onebox_modules'], 'strlen'); - - // The empty string in the define block above for block visibility - // settings is really just a flag that nothing has been set yet. - // Using an empty string is problematic, so we just set it to an - // empty array instead. - if ($settings['block_visibility_settings'] === '') { - $settings['block_visibility_settings'] = array(); - } + // Convert onebox_modules from string to array. + $settings['onebox_modules'] = explode("\n", $settings['onebox_modules']); + $settings['onebox_modules'] = array_map('trim', $settings['onebox_modules']); + $settings['onebox_modules'] = array_filter($settings['onebox_modules'], 'strlen'); + + // The empty string in the define block above for block visibility + // settings is really just a flag that nothing has been set yet. + // Using an empty string is problematic, so we just set it to an + // empty array instead. + if ($settings['block_visibility_settings'] === '') { + $settings['block_visibility_settings'] = array(); + } + if ($settings['language_filter_options'] === '') { + $settings['language_filter_options'] = array(); } return $settings; diff --git a/google_appliance.module b/google_appliance.module index c1b39a8..d0d5399 100644 --- a/google_appliance.module +++ b/google_appliance.module @@ -249,7 +249,7 @@ function google_appliance_block_form_submit($form, &$form_state) { * conditionally hide content from the crawler using googleon/googleoff tags. */ function google_appliance_form_block_admin_configure_alter(&$form, &$form_state, $form_id) { - $settings = _google_appliance_get_settings(TRUE); + $settings = _google_appliance_get_settings(); // Determine the default value for this block. $default = 'none'; @@ -295,7 +295,7 @@ function google_appliance_form_block_admin_configure_alter(&$form, &$form_state, * Submit handler to save block-specific crawler visibility settings. */ function google_appliance_block_visibility_submit($form, &$form_state) { - $settings = _google_appliance_get_settings(TRUE); + $settings = _google_appliance_get_settings(); $module = $form_state['values']['module']; $delta = $form_state['values']['delta']; diff --git a/google_appliance.variable.inc b/google_appliance.variable.inc new file mode 100644 index 0000000..36517a9 --- /dev/null +++ b/google_appliance.variable.inc @@ -0,0 +1,207 @@ + t('Google Search Appliance'), + 'description' => t('Google Search Appliance settings and configuration'), + 'access' => 'administer_google_appliance', + 'path' => array('admin/config/search/google_appliance/settings'), + ); + + return $groups; +} + + +/** + * Implements hook_variable_info(). + */ +function google_appliance_variable_info($options) { + // Appliance hostname. + $variables['google_appliance_hostname'] = array( + 'title' => t('Google Search Appliance Host Name', array(), $options), + 'description' => t('Valid URL or IP address of the GSA device, including http:// or https://. Do not include /search at the end, or a trailing slash, but you should include a port number if needed. Example: http://my.gsabox.com:8443', array(), $options), + 'type' => 'string', + 'default' => SGA_DEFAULT_HOSTNAME, + 'required' => TRUE, + 'group' => 'google_appliance', + ); + + // Default collection. + $variables['google_appliance_collection'] = array( + 'title' => t('Collection', array(), $options), + 'description' => t('The name of a valid collection on the GSA device (case sensitive).', array(), $options), + 'type' => 'string', + 'default' => SGA_DEFAULT_COLLECTION, + 'required' => TRUE, + 'group' => 'google_appliance', + ); + + // Default frontend. + $variables['google_appliance_frontend'] = array( + 'title' => t('Frontend client', array(), $options), + 'description' => t('The name of a valid frontend client on the GSA device (case sensitive).', array(), $options), + 'type' => 'string', + 'default' => SGA_DEFAULT_FRONTEND, + 'required' => TRUE, + 'group' => 'google_appliance', + ); + + // Request timeout interval. + $variables['google_appliance_timeout'] = array( + 'title' => t('Search Timeout', array(), $options), + 'description' => t('Length of time to wait for response from the GSA device before giving up (timeout in seconds).', array(), $options), + 'type' => 'number', + 'default' => SGA_DEFAULT_TIMEOUT, + 'required' => TRUE, + 'group' => 'google_appliance', + ); + + // Auto-filtering. + $variables['google_appliance_autofilter'] = array( + 'title' => t('Search Results Auto-Filtering Options', array(), $options), + 'description' => t('Learn more about GSA auto-filtering here. In general, employing both filters enhances results, but sites with smaller indexes may suffer from over-filtered results.', array('@gsa-doc-af' => 'http://code.google.com/apis/searchappliance/documentation/68/xml_reference.html#request_filter_auto'), $options), + 'type' => 'options', + 'options' => array( + '0' => t('No filtering'), + 's' => t('Duplicate Directory Filter'), + 'p' => t('Duplicate Snippet Filter'), + '1' => t('Both Duplicate Directory and Duplicate Snippet Filters') + ), + 'default' => SGA_DEFAULT_AUTOFILTER, + 'group' => 'google_appliance', + ); + + // Language filter settings. + if (module_exists('locale')) { + // Toggle to enable/disable language filtering. + $variables['google_appliance_language_filter_toggle'] = array( + 'title' => t('Enable Language Filtering', array(), $options), + 'type' => 'boolean', + 'default' => SGA_DEFAULT_LANGUAGE_FILTER_TOGGLE, + 'group' => 'google_appliance', + ); + + // Language filter selection + $variables['google_appliance_language_filter_options'] = array( + 'title' => t('Restrict searches to specified languages', array(), $options), + 'description' => t('If there are no results in the specified language, the search appliance is expected to return results in all languages.', array(), $options), + 'type' => 'options', + 'options' => array( + '***CURRENT_LANGUAGE***' => t("Current user's language"), + '***DEFAULT_LANGUAGE***' => t("Default site language"), + ) + locale_language_list(), + 'default' => SGA_DEFAULT_LANGUAGE_FILTER_OPTIONS, + 'group' => 'google_appliance', + ); + } + + // Query inspection. + $variables['google_appliance_query_inspection'] = array( + 'title' => t('Enable Query Inspection', array(), $options), + 'description' => t('Inspect the search query parameters sent to the GSA device in the Drupal message area every time a search is performed. Only really useful for sites not using the Devel module, as dsm() provides more information. The inspector is only shown to administrators, but should be disabled in a production environment.', array(), $options), + 'type' => 'boolean', + 'default' => SGA_DEFAULT_QUERY_INSPECTION, + 'group' => 'google_appliance', + ); + + // Search page path. + $variables['google_appliance_search_title'] = array( + 'title' => t('Search path', array(), $options), + 'description' => t('The URL of the search page provided by this module. Include neither leading nor trailing slash.', array(), $options), + 'type' => 'string', + 'default' => SGA_DEFAULT_DRUPAL_PATH, + 'required' => TRUE, + 'group' => 'google_appliance', + ); + + // Search page title. + $variables['google_appliance_search_title'] = array( + 'title' => t('Search Name', array(), $options), + 'description' => t('Serves as the page title on results pages and the default menu item title', array(), $options), + 'type' => 'string', + 'default' => SGA_DEFAULT_SEARCH_TITLE, + 'required' => TRUE, + 'localize' => TRUE, + 'group' => 'google_appliance', + ); + + // Results per page. + $variables['google_appliance_results_per_page'] = array( + 'title' => t('Results per page', array(), $options), + 'description' => t('Number of results to show on the results page. More results will be available via a Drupal pager.', array(), $options), + 'type' => 'number', + 'default' => SGA_DEFAULT_RESULTS_PER_PAGE, + 'required' => TRUE, + 'group' => 'google_appliance', + ); + + // Spelling suggestions. + $variables['google_appliance_spelling_suggestions'] = array( + 'title' => t('Display Spelling Suggestions', array(), $options), + 'type' => 'boolean', + 'default' => SGA_DEFAULT_SPELLING_SUGGESTIONS, + 'group' => 'google_appliance', + ); + + // Search reporting. + $variables['google_appliance_advanced_search_reporting'] = array( + 'title' => t('Enable Advanced Search Reporting', array(), $options), + 'description' => t('Learn more about !this_feature. You need to enable Advanced Search Reporting on the front end client. The device should provide a file named "/clicklog_compiled.js" when using the search interface on the GSA.', array('!this_feature' => l(t('this feature'), 'http://www.google.com/support/enterprise/static/gsa/docs/admin/70/gsa_doc_set/xml_reference/advanced_search_reporting.html')), $options), + 'type' => 'boolean', + 'default' => SGA_DEFAULT_SPELLING_SUGGESTIONS, + 'group' => 'google_appliance', + ); + + // Onebox modules. + $variables['google_appliance_onebox_modules'] = array( + 'title' => t('Onebox modules', array(), $options), + 'description' => t('A list of Onebox modules, one per line. Each module listed will have a corresponding block. These blocks must be placed via the block configuration page, or another layout mechanism like Context or Panels.', array(), $options), + 'type' => 'text', + 'default' => SGA_DEFAULT_ONEBOX_MODULES, + 'localize' => FALSE, + 'group' => 'google_appliance', + ); + + // No results error message. + $variables['google_appliance_error_gsa_no_results'] = array( + 'title' => t('No results error message', array(), $options), + 'description' => t('The message displayed to the user when no results are found for the given search query.', array(), $options), + 'type' => 'text', + 'default' => SGA_DEFAULT_ERROR_GSA_NO_RESULTS, + 'required' => TRUE, + 'localize' => TRUE, + 'group' => 'google_appliance', + ); + + // Connection error message. + $variables['google_appliance_error_curl_error'] = array( + 'title' => t('Connection error message', array(), $options), + 'description' => t('The message displayed to the user when there is an error connecting to the search appliance.', array(), $options), + 'type' => 'text', + 'default' => SGA_DEFAULT_ERROR_CURL_ERROR, + 'required' => TRUE, + 'localize' => TRUE, + 'group' => 'google_appliance', + ); + + // Parse error message. + $variables['google_appliance_error_lib_xml_parse_error'] = array( + 'title' => t('XML parse error message', array(), $options), + 'description' => t('The message displayed to the user when the XML returned by the appliance is malformed.', array(), $options), + 'type' => 'text', + 'default' => SGA_DEFAULT_ERROR_LIB_XML_PARSE_ERROR, + 'required' => TRUE, + 'localize' => TRUE, + 'group' => 'google_appliance', + ); + return $variables; +}