View source
<?php
if (module_exists('apachesolr_search')) {
$plugin = array(
'single' => TRUE,
'no title override' => TRUE,
'title' => t('Apache Solr search results'),
'icon' => 'icon_search.png',
'description' => t('The results of an Apache Solr search.'),
'required context' => new ctools_context_optional(t('Context to fetch search query from'), 'string'),
'category' => t('Apache Solr Search'),
'defaults' => array(
'keys_action' => 'none',
'keys' => '',
'keys_required' => TRUE,
'filters_action' => 'none',
'filters' => '',
'rows' => 10,
'env_id' => '',
'sort_action' => 'none',
'sort' => '',
'breadcrumb' => TRUE,
'title_override' => FALSE,
'title_override_text' => '',
'empty_override' => FALSE,
'empty_override_title' => '',
'empty_override_text' => '',
'empty_override_format' => FILTER_FORMAT_DEFAULT,
'log' => FALSE,
'substitute' => FALSE,
),
'render first' => TRUE,
);
}
function apachesolr_panels_apachesolr_result_content_type_render($subtype, $conf, $args, $context) {
$block = new stdClass();
$block->module = 'apachesolr_panels';
$block->delta = 'results';
$search = array(
'keys' => '',
'filters' => $_GET['filters'],
'sort' => $_GET['solrsort'],
);
if (!empty($context) && !empty($context->data)) {
$search['keys'] = $context->data;
}
$display = panels_get_current_page_display();
foreach ($search as $key => $value) {
$value = trim($value);
if ($conf[$key . '_action'] != 'none' && !empty($conf['substitute']) && !empty($display->context)) {
$conf[$key] = ctools_context_keyword_substitute($conf[$key], array(), $display->context);
}
if ($conf[$key . '_action'] == 'append') {
$search[$key] .= ' ' . $conf[$key];
}
elseif ($conf[$key . '_action'] == 'fallback' && empty($value) || $conf[$key . '_action'] == 'override') {
$search[$key] = $conf[$key];
}
}
$menu_item = menu_get_item();
$search['path'] = $menu_item['href'];
$search['page'] = isset($_GET['page']) ? $_GET['page'] : 0;
$search['rows'] = isset($conf['rows']) ? $conf['rows'] : 10;
$search['env_id'] = isset($conf['env_id']) ? $conf['env_id'] : '';
if (!empty($conf['log'])) {
watchdog('search', '%keys (@type).', array(
'%keys' => $search['keys'],
'@type' => t('Search'),
), WATCHDOG_NOTICE, l(t('results'), $_GET['q']));
}
$results = NULL;
if (!empty($search['keys']) || !$conf['keys_required']) {
if (empty($conf['breadcrumb'])) {
$breadcrumb = drupal_get_breadcrumb();
}
$results = apachesolr_panels_search_execute($search);
if (empty($conf['breadcrumb'])) {
drupal_set_breadcrumb($breadcrumb);
}
}
if ($results) {
if (!empty($conf['title_override'])) {
if (!empty($conf['substitute']) && !empty($display->context)) {
$conf['title_override_text'] = ctools_context_keyword_substitute($conf['title_override_text'], array(), $display->context);
}
$block->title = $conf['title_override_text'];
}
else {
$block->title = t('Search results');
}
$block->content = $results;
}
elseif (!empty($search['keys'])) {
if (!empty($conf['empty_override'])) {
if (!empty($conf['substitute']) && !empty($display->context)) {
$conf['empty_override_title'] = ctools_context_keyword_substitute($conf['empty_override_title'], array(), $display->context);
$conf['empty_override_text'] = ctools_context_keyword_substitute($conf['empty_override_text'], array(), $display->context);
}
$block->title = $conf['empty_override_title'];
$block->content = check_markup($conf['empty_override_text'], $conf['empty_override_format'], FALSE);
}
else {
$block->title = t('Your search yielded no results');
$block->content = search_help('search#noresults', drupal_help_arg());
}
}
return $block;
}
function apachesolr_panels_apachesolr_result_content_type_edit_form(&$form, &$form_state) {
$conf = $form_state['conf'];
$action_options = array(
'none' => t('From context'),
'override' => t('Override'),
'append' => t('Append to'),
'fallback' => t('Fallback if empty'),
);
$form['keys_action'] = array(
'#prefix' => '<div class="form-item container-inline">',
'#title' => t('Keywords'),
'#type' => 'select',
'#options' => $action_options,
'#default_value' => $conf['keys_action'],
);
$form['keys'] = array(
'#title' => '',
'#type' => 'textfield',
'#default_value' => $conf['keys'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-keys-action' => array(
'fallback',
'override',
'append',
),
),
);
$form['keys_required'] = array(
'#title' => t('Required'),
'#type' => 'checkbox',
'#default_value' => $conf['keys_required'],
'#suffix' => '</div>',
);
$form['filters_action'] = array(
'#prefix' => '<div class="form-item container-inline">',
'#title' => t('Filters'),
'#type' => 'select',
'#options' => $action_options,
'#default_value' => $conf['filters_action'],
);
$form['filters'] = array(
'#title' => '',
'#type' => 'textfield',
'#default_value' => $conf['filters'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-filters-action' => array(
'fallback',
'override',
'append',
),
),
'#suffix' => '</div>',
);
$form['sort_action'] = array(
'#prefix' => '<div class="form-item container-inline">',
'#title' => t('Sort'),
'#type' => 'select',
'#options' => $action_options,
'#default_value' => $conf['sort_action'],
);
$form['sort'] = array(
'#title' => '',
'#type' => 'textfield',
'#default_value' => $conf['sort'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-sort-action' => array(
'fallback',
'override',
'append',
),
),
'#suffix' => '</div>',
);
$form['rows'] = array(
'#prefix' => '<div class="form-item container-inline">',
'#title' => t('Results per page'),
'#type' => 'textfield',
'#default_value' => isset($conf['rows']) ? $conf['rows'] : 10,
'#suffix' => '</div>',
);
$form['env_id'] = array(
'#prefix' => '<div class="form-item container-inline">',
'#title' => t('Solr Environment ID'),
'#description' => t('The machine name of the Solr environment, as defined in the Settings page of the Apache Solr module'),
'#type' => 'textfield',
'#default_value' => isset($conf['env_id']) ? $conf['env_id'] : '',
'#suffix' => '</div>',
);
$form['title_override'] = array(
'#prefix' => '<div class="form-item container-inline">',
'#title' => t('Override title'),
'#type' => 'checkbox',
'#default_value' => $conf['title_override'],
);
$form['title_override_text'] = array(
'#type' => 'textfield',
'#default_value' => $conf['title_override_text'],
'#size' => 35,
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-title-override' => array(
1,
),
),
'#dependency_type' => 'disable',
'#suffix' => '</div>',
);
$form['empty_override'] = array(
'#title' => t('Override "no result" text'),
'#type' => 'checkbox',
'#default_value' => $conf['empty_override'],
);
$form['empty_override_field']['empty_override_title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#default_value' => $conf['empty_override_title'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-empty-override' => array(
1,
),
),
);
$form['empty_override_field']['empty_override_text'] = array(
'#title' => t('No result text'),
'#type' => 'textarea',
'#default_value' => $conf['empty_override_text'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-empty-override' => array(
1,
),
),
);
$form['empty_override_field']['format_prefix'] = array(
'#type' => 'hidden',
'#id' => 'edit-empty-override-format',
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-empty-override' => array(
1,
),
),
'#prefix' => '<div><fieldset id="edit-empty-override-format" class="collapsed collapsible"><legend>' . t('Input format') . '</legend>',
);
$form['empty_override_field']['empty_override_format'] = filter_form($conf['empty_override_format'], NULL, array(
'empty_override_format',
));
unset($form['empty_override_field']['empty_override_format']['#type']);
$form['empty_override_field']['format_suffix'] = array(
'#value' => '</fieldset></div>',
);
$form['breadcrumb'] = array(
'#title' => t('Show keywords and filters in the breadcrumb trail'),
'#type' => 'checkbox',
'#default_value' => $conf['breadcrumb'],
);
$form['log'] = array(
'#title' => t('Record a watchdog log entry when searches are made'),
'#type' => 'checkbox',
'#default_value' => $conf['log'],
);
if (!empty($form_state['contexts'])) {
$form['substitute'] = array(
'#type' => 'checkbox',
'#title' => t('Use context keywords'),
'#description' => t('If checked, context keywords will be substituted in this content.'),
'#default_value' => !empty($conf['substitute']),
);
$form['contexts'] = array(
'#title' => t('Substitutions'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$header = array(
t('Keyword'),
t('Value'),
);
$rows = array();
foreach ($form_state['contexts'] as $context) {
foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
$rows[] = array(
check_plain($keyword),
t('@identifier: @title', array(
'@title' => $title,
'@identifier' => $context->identifier,
)),
);
}
}
$form['contexts']['context'] = array(
'#value' => theme('table', $header, $rows),
);
}
return $form;
}
function apachesolr_panels_apachesolr_result_content_type_edit_form_submit(&$form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}