You are here

function _search_by_page_view in Search by Page 7

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

Returns a ready-to-render 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
Implements hook_menu().

File

./search_by_page.module, line 1120
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]);
  }
  $build = array();

  // Display a search form
  $build['search_form'] = drupal_get_form('search_by_page_form', $environment, $keys, FALSE);

  // Get search results 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));
    $keys = search_expression_insert($keys, 'environment', $environment);
    $results = search_data($keys, 'search_by_page');
    $build['search_results'] = $results;
  }
  return $build;
}