You are here

function _search_by_page_view in Search by Page 6

Same name and namespace in other branches
  1. 8 search_by_page.module \_search_by_page_view()
  2. 7 search_by_page.module \_search_by_page_view()

Returns rendered search form and/or results page.

Parameters

$envstring: The environment ID, with 'env' prepended, to avoid argument substitution in hook_menu().

1 string reference to '_search_by_page_view'
search_by_page_menu in ./search_by_page.module
Implementation of hook_menu().

File

./search_by_page.module, line 821
Main module file for Drupal module Search by Page.

Code

function _search_by_page_view($envstring) {
  $environment = intval(drupal_substr($envstring, 3));

  // This pretty much follows search_view()
  $path = explode('/', $_GET['q'], 2);
  $keys = '';
  if (count($path) > 1) {
    $keys = trim($path[1]);
  }

  // Display a search form
  $output = drupal_get_form('search_by_page_form', $environment, $keys, FALSE);

  // Get search results, if any, and display them
  $path = search_by_page_setting_get('page_path', $environment, 'search_pages');
  if ($keys) {
    watchdog('search_by_page', '%keys', array(
      '%keys' => $keys,
    ), WATCHDOG_NOTICE, l(t('results'), $path . '/' . $keys));
    $entered_keys = $keys;
    $keys = search_query_insert($keys, 'environment', $environment);
    $results = search_data($keys, 'search_by_page');
    if ($results) {
      $title = theme('search_by_page_results_title', $entered_keys);
      $results = theme('box', $title, $results);
    }
    else {
      $results = theme('search_by_page_no_results', $entered_keys);
    }
    $output .= $results;
  }
  return $output;
}