commons_search.module in Drupal Commons 7.3
File
modules/commons/commons_search/commons_search.module
View source
<?php
include_once 'commons_search.features.inc';
function commons_search_module_implements_alter(&$implementations, $hook) {
if ($hook == 'form_alter') {
$group = $implementations['commons_search'];
unset($implementations['commons_search']);
$implementations['commons_search'] = $group;
}
}
function commons_search_menu_alter(&$items) {
if (isset($items['search'])) {
$items['search']['type'] = MENU_NORMAL_ITEM;
$items['search']['menu_name'] = 'main-menu';
$items['search']['weight'] = 3;
}
}
function commons_search_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$site_key = 'c-all';
$form['search_block_form']['#weight'] = 1;
if (module_exists('commons_search_core')) {
$site_key = 'o-search_facetapi';
}
else {
if (module_exists('apachesolr_search')) {
$site_key = 'o-solr';
}
}
$form['custom_search_types']['#options'] = array(
$site_key => t('Site'),
'c-user' => t('Users'),
);
$group = FALSE;
$node = current_path();
if ((strrpos($node, 'node/') !== FALSE || strrpos($node, 'group/') !== FALSE) && is_numeric(substr($node, strrpos($node, '/') + 1))) {
$node = node_load(substr($node, strrpos($node, '/') + 1));
if (!empty($node)) {
$group = $node->type == 'group';
}
}
if ($group) {
$form['custom_search_types']['#options']['o-commons_search'] = t('This group');
$form['custom_search_types']["#default_value"] = 'o-commons_search';
$form_state['search_group_id'] = $node->nid;
}
if (arg(0) == 'search') {
$form['search_block_form']['#default_value'] = check_plain(arg(2));
if (arg(1) == 'user') {
$form['custom_search_types']["#default_value"] = 'c-user';
}
}
$keys = arg(2);
if (!module_exists('commons_search_solr') && !empty($keys)) {
$form['#action'] = str_replace("/" . check_plain(arg(2)), '', $form['#action']);
}
}
}
function commons_search_search_form_submit($form, &$form_state) {
if ($form_state['values']['custom_search_types'] == 'o-commons_search' && isset($form_state['search_group_id'])) {
$keys = $form_state['values']['search_block_form'];
if (module_exists('apachesolr_search')) {
$qm = strpos($form_state['redirect'], '?') !== FALSE ? '' : '?';
$form_state['redirect'] .= $qm . '&f[1]=sm_og_group_ref:node:' . $form_state['search_group_id'];
}
else {
drupal_goto('search/group/' . $form_state['search_group_id'], array(
'query' => array(
'keys' => $keys,
),
));
}
}
else {
if ($form_state['values']['custom_search_types'] == 'c-user') {
$keys = check_plain($form_state['values']['search_block_form']);
$form_state['redirect'] = 'search/user/' . $keys;
}
}
}
function commons_search_process_search_result(&$variables) {
}
function commons_search_process_search_results(&$variables) {
$variables['result_count'] = count($variables['results']);
if (isset($variables['response']) && isset($variables['response']->request) && preg_match('/sm_og_group_ref:"node:([0-9]+)"&/', urldecode($variables['response']->request), $match)) {
$group = node_load($match[1]);
$title = t('Search within !group', array(
'!group' => '<em>' . $group->title . '</em>',
));
$variables['title'] = $title;
}
}
function commons_search_theme_registry_alter(&$theme_registry) {
$theme_registry['breadcrumb']['preprocess functions'] = array_flip($theme_registry['breadcrumb']['preprocess functions']);
unset($theme_registry['breadcrumb']['preprocess functions']['adaptivetheme_preprocess_breadcrumb']);
$theme_registry['breadcrumb']['preprocess functions'] = array_flip($theme_registry['breadcrumb']['preprocess functions']);
}