function template_preprocess_google_appliance_results in Google Search Appliance 7
Preprocess google-search-appliance-results.tpl.php (results page).
File
- theme/
google_appliance.theme.inc, line 169 - theme registry and preprocess functions for the default templates
Code
function template_preprocess_google_appliance_results(&$vars) {
// Grab module settings.
$settings = _google_appliance_get_settings();
// Report debug info to admins if module settings.
if ($vars['is_admin'] && $settings['query_inspection'] == '1') {
if (isset($vars['search_query_data']['debug_info'])) {
foreach ($vars['search_query_data']['debug_info'] as $info_slice) {
drupal_set_message(filter_xss_admin($info_slice));
}
}
}
// Grab the search form.
$vars['search_form'] = drupal_get_form('google_appliance_search_form', $vars['search_query_data']['gsa_query_params']['q']);
// Get spelling suggestion.
$vars['spelling_suggestion'] = $settings['spelling_suggestions'] && isset($vars['response_data']['spelling_suggestion']) ? theme('google_appliance_spelling_suggestion', $vars['response_data']) : '';
// If we have errors, decode them and skip building results entities.
if (isset($vars['response_data']['error'])) {
$vars['results_heading'] = t('No Results Found');
$vars['error_reason'] = '';
$log_message_errors = '';
// Build hook_help-based error messages for display.
foreach ($vars['response_data']['error'] as $error_key => $error_response) {
// Replace error responses with those configured.
$help_message = check_markup($settings['error_' . $error_key], $settings['error_' . $error_key . '_format']);
$vars['error_reason'] .= $help_message != '' ? $help_message : $error_response;
// Build error message for the log (ignore 'no results' condition).
if ($error_key != 'gsa_no_results') {
$log_message_errors .= '{ ' . $error_response . ' } ';
}
}
// Report communication errors to the log.
if ($log_message_errors != '') {
_google_appliance_log_search_error($vars['search_query_data']['gsa_query_params']['q'], $log_message_errors);
}
}
else {
// Build results entities.
$vars['results_heading'] = t('Search Results');
// Get themed sort headers.
$vars['sort_headers'] = theme('google_appliance_sort_headers', $vars['search_query_data']);
// Get themed keymatch listing.
$vars['keymatch_results'] = '';
// GSA device may not be configured for keymatches
if (array_key_exists('keymatch', $vars['response_data'])) {
$count = 0;
foreach ($vars['response_data']['keymatch'] as $keymatch) {
$keymatch['keymatch_idx'] = ++$count;
$vars['keymatch_results'] .= theme('google_appliance_keymatch', $keymatch);
}
}
// Get themed synonym listing.
$vars['synonyms'] = '';
$vars['show_synonyms'] = FALSE;
// GSA device may not be configured for synonyms
if (array_key_exists('synonyms', $vars['response_data'])) {
$count = 0;
foreach ($vars['response_data']['synonyms'] as $synonym) {
$synonym['synonym_idx'] = ++$count;
$vars['synonyms'] .= theme('google_appliance_synonym', $synonym);
}
$vars['show_synonyms'] = $count;
}
// Get themed results listing.
$vars['search_results'] = '';
$count = 0;
foreach ($vars['response_data']['entry'] as $result) {
$result['result_idx'] = ++$count;
$vars['search_results'] .= theme('google_appliance_result', $result);
}
// Get themed search stats.
$search_stats_data = array(
'response_data' => $vars['response_data'],
'search_query_data' => $vars['search_query_data'],
);
$vars['search_stats'] = theme('google_appliance_search_stats', $search_stats_data);
// Get themed drupal pager.
$pager_data = array(
'total_results_count' => $vars['response_data']['total_results'],
'last_result_index' => $vars['response_data']['last_result'],
);
$vars['pager'] = theme('google_appliance_pager', $pager_data);
// Add Advanced Search Reporting if applicable.
if ($settings['advanced_search_reporting']) {
// Path to callback.
// When clean URLs are disabled we do not want the '?q=' version which won't work.
// Hence we do not use url() -- we build the path ourselves from $base_url.
global $base_url;
$callback_path = $base_url . '/' . drupal_get_path('module', 'google_appliance') . '/google_appliance.callback.click.php';
// Add javascript.
drupal_add_js(array(
'google_appliance' => array(
'clickTracking' => array(
'host' => $callback_path,
'pathPart' => '',
'collection' => $vars['search_query_data']['gsa_query_params']['site'],
'query' => $vars['search_query_data']['gsa_query_params']['q'],
'start' => $vars['search_query_data']['gsa_query_params']['start'],
'clickTypes' => array(
'c' => '.google-appliance-result a',
'cluster' => '#block-google-appliance-ga-related-searches .content a',
'logo' => 'a#logo',
'nav.page' => '.content .pager-item a',
'nav.next' => '.content .pager-next a',
'nav.prev' => '.content .pager-previous a, .content .pager-first a',
'keymatch' => '.google-appliance-keymatch-results a',
'onebox' => '.google-appliance-onebox-module a',
'sort' => '.google-appliance-sorter a',
'synonym' => '.google-appliance-synonym a',
'spell' => '.google-appliance-spelling-suggestion a',
),
),
),
), 'setting');
drupal_add_library('google_appliance', 'jquery.gsa-clicks');
drupal_add_js(drupal_get_path('module', 'google_appliance') . '/js/clicklog.js');
}
}
// Render template.
}