function apachesolrlang_block in Apache Solr Search 5
Implementation of hook_block().
File
- contrib/
apachesolr_lang/ apachesolrlang.module, line 7
Code
function apachesolrlang_block($op = 'list', $delta = 0, $edit = array()) {
$title = t('ApacheSolr: Filter by language');
switch ($op) {
case 'list':
$blocks['language'] = array(
'info' => $title,
);
return $blocks;
case 'view':
if (apachesolr_has_searched()) {
// Get the query and response. Without these no blocks make sense.
$response =& apachesolr_static_response_cache();
if (empty($response)) {
return;
}
$query =& apachesolr_drupal_query();
switch ($delta) {
case 'language':
if (is_array($response->facets->language)) {
$contains_active = FALSE;
$languages = array();
foreach ($response->facets->language as $language => $count) {
$unclick_link = '';
unset($active);
$new_query = clone $query;
if ($active = $query
->has_field('language', $language)) {
$contains_active = TRUE;
$new_query
->remove_field('language', $language);
$path = 'search/' . arg(1) . '/' . $new_query
->get_query();
$unclick_link = theme('apachesolr_unclick_link', $path);
}
else {
$new_query
->add_field('language', $language);
$path = 'search/' . arg(1) . '/' . $new_query
->get_query();
}
$countsort = $count == 0 ? '' : 1 / $count;
// if numdocs == 1 and !active, don't add.
if ($response->numFound == 1 && !$active) {
// skip
}
else {
$result = db_query("SELECT name FROM {locales_meta} WHERE locale = '%s' LIMIT 1", $language);
$lang_name = db_result($result);
$languages[] = theme('apachesolr_facet_item', $lang_name ? $lang_name : $language, $count, $path, $active, $unclick_link);
}
}
if (count($languages) > 0) {
$facet_display_limits = variable_get('apachesolr_facet_query_limits', array());
$facet_display_limit = isset($facet_display_limits[$delta]) ? $facet_display_limits[$delta] : 10;
$languages = array_slice($languages, 0, $facet_display_limit);
$output = theme('apachesolr_facet_list', $languages);
return array(
'subject' => $title,
'content' => $output,
);
}
}
break;
}
}
break;
case 'configure':
return apachesolr_block($op, $delta);
case 'save':
return apachesolr_block($op, $delta, $edit);
}
}