function rich_snippets_preprocess_search_result in Rich Snippets 7
Implements hook_preprocess_HOOK() for theme_search_result().
Base properties:
- additionalType
- description
- image
- name
- url
File
- ./
rich_snippets.module, line 169 - Overrides the standard search results templates and CSS to display results similar to major search engines.
Code
function rich_snippets_preprocess_search_result(&$variables) {
static $included;
if (!$included) {
// Add the CSS here since this hook is the most reliable place to do so.
// @see http://drupal.org/node/1871480
$path = drupal_get_path('module', 'rich_snippets');
drupal_add_css($path . '/rich_snippets.css');
// The preprocess hooks are stuck in another file for code organization.
module_load_include('inc', 'rich_snippets', 'rich_snippets.preprocess');
$included = TRUE;
}
// Get the module that executed the search so we can extract the schema.
if (0 === strpos($variables['module'], 'apachesolr_')) {
// Lump all apachesolr search modules together.
$module = 'apachesolr';
}
elseif ('search_facetapi' == $variables['module']) {
// Faceted Navigation for Search is really the node module, too.
$module = 'node';
}
else {
// Catch-all for everything else.
$module = $variables['module'];
}
// Get the schema from the module's hook implementation.
$schema = module_invoke($module, 'search_result_schema', $variables['result']);
// Initialize our custom variables.
$variables['image'] = '';
// Allow highlighting of the title.
// @todo Make the allowed tag match what is passed though to Solr.
$variables['title'] = filter_xss($variables['result']['title'], array(
'strong',
));
// Shortened the URL for display in the search results.
$variables['url_shortened'] = rich_snippets_shorten_url($variables['url']);
// This is a legacy variable from Rich Snippets <= 7.x-1.0-alpha2. We will
// maintain it for a little while in case people are using it.
// @see http://drupal.org/node/1851924
// @todo Remove this in beta.
$variables['title_shortened'] = $variables['title'];
// Get the schema via the module's hook_search_result_schema() implementation,
// invoke the schema specific preprocess hook, and instantiate the module's
// preprocessor
$variables['schema'] = $preprocessed = FALSE;
if ($schema) {
$preprocessor = rich_snippets_preprocessor_load($module, $variables);
if ($preprocessor) {
$preprocessed = rich_snippets_invoke_preprocess_hooks($variables, $schema, $preprocessor);
}
}
// Use the default preprocessing logic if the schema wasn't defined or the
// schema specific preprocessor wasn't found.
if (!$preprocessed) {
rich_snippets_default_preprocessor($variables);
}
// Rebuild the search info since the split was probably modified.
$variables['info'] = implode(' - ', $variables['info_split']);
}