You are here

function finder_results in Finder 7

Same name and namespace in other branches
  1. 6 finder.module \finder_results()

Create finder results output.

Parameters

$finder: The finder object.

Return value

Themed output of finder results.

1 call to finder_results()
finder_view in ./finder.module
Generate display of a given finder.

File

./finder.module, line 675
The finder module.

Code

function finder_results($finder) {
  $output = '';
  $finder_form_state = finder_form_state($finder->finder_id);
  finder_invoke_finderapi($finder, 'finder_results', $finder_form_state);
  if ($finder_form_state && $finder_form_state['storage']['finished'] || $finder->settings['advanced']['filter']) {

    // I can't remember what this is for...
    foreach ($_REQUEST as $k => $v) {
      unset($_REQUEST[$k]);
    }
    $keywords = array();
    $pager =& $finder->settings['advanced']['pager'];
    foreach ($finder->elements as $element) {
      $match =& $element->settings['advanced']['match'];
      $keyword = array();
      if (!is_null($finder_form_state['values'][$element->finder_element_id])) {
        $keyword = (array) $finder_form_state['values'][$element->finder_element_id];
        if (!empty($element->settings['advanced']['delimit'])) {

          // This enables escaped characters to work in delimiters.
          $delimiter = stripcslashes($element->settings['advanced']['delimit']);
          foreach ($keyword as $k => $v) {
            unset($keyword[$k]);
            $exploded = explode($delimiter, $v);
            foreach ($exploded as $e) {
              $keyword[] = trim($e);
            }
          }
        }
      }
      $keywords[$element->finder_element_id] = $keyword;
    }
    $goto =& $finder->settings['advanced']['goto'];
    if (isset($_GET['go']) && $_GET['go'] || isset($finder_form_state['clicked_button']) && $finder_form_state['clicked_button']['#name'] == 'go' && $finder_form_state['storage']['finished'] || $goto == 'always') {
      $finder->go = TRUE;
    }
    $result = finder_find($finder, $keywords, 'results', $match, $pager);
    if ($finder->settings['advanced']['hide_args']) {
      if ($pager && !isset($finder_form_state['storage']['pager_token'])) {
        $token = drupal_get_token();
        $finder_form_state['storage']['pager_token'] = $token;
        $_SESSION['finder'][$token] = $finder_form_state;
      }
    }
    $base_module =& $finder->base_handler['#module'];
    if (isset($finder->go) && $finder->go && count($result) || $goto == 'best' && count($result) === 1 && empty($_GET['page'])) {
      drupal_alter('finder_goto', $result, $finder);
      $current_result = current($result);
      module_invoke($base_module, 'finder_goto', $finder, $current_result);
    }
    $results = module_invoke($base_module, 'finder_result', $finder, $keywords, $result, $finder_form_state);
    $params = array();
    if (!empty($finder_form_state['storage']['pager_token'])) {
      $params['finder'] = $finder_form_state['storage']['pager_token'];
    }
    if (!empty($finder->settings['advanced']['no_results']['no_results'])) {
      $variables = array(
        'finder' => $finder,
        'keywords' => $keywords,
        'form_state' => $finder_form_state,
      );
      $no_results = finder_eval($finder->settings['advanced']['no_results']['no_results'], $variables);
    }
    else {

      // Default text.
      $no_results = t('There are no results to display');
    }
    $output .= theme('finder_results', array(
      'results' => $results,
      'finder' => $finder,
      'keywords' => $keywords,
      'pager' => $pager,
      'params' => $params,
      'form_state' => $finder_form_state,
      'no_results' => $no_results,
    ));
  }
  return $output;
}