Browse Source

added search query and ip logging

2.x-ebsco
Paul Pound 11 years ago
parent
commit
c5ff03f276
  1. 42
      roblib_search.install
  2. 12
      roblib_search.module
  3. 4
      targets/evergreen/roblib_search_evergreen.module

42
roblib_search.install

@ -1,2 +1,44 @@
<?php <?php
/**
* @file
* Installation hooks.
*/
/**
* Implements hook_schema().
*/
function roblib_search_schema() {
$schema = array();
$schema['roblib_search_log'] = array(
'description' => 'stores search data such as date/time ip etc.',
'fields' => array(
'sid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'unique id for each row',
),
'query' => array(
'description' => 'the search string',
'type' => 'varchar',
'not null' => TRUE,
'length' => 1024,
),
'searched_date' => array(
'description' => 'the date the search request occured',
'type' => 'varchar',
'mysql_type' => 'DATETIME',
'not null' => TRUE,
),
'ipaddress' => array(
'description' => 'the ip or domain of the users computer ',
'type' => 'varchar',
'not null' => TRUE,
'length' => 255,
),
),
'primary key' => array('sid'),
);
return $schema;
}

12
roblib_search.module

@ -108,11 +108,23 @@ function roblib_search_simple_form_submit($form, &$form_state) {
global $base_url; global $base_url;
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
$search_string = $form_state['values']['roblib_search_simple_search_query']; $search_string = $form_state['values']['roblib_search_simple_search_query'];
$search_string = filter_xss($search_string);
roblib_search_log_query($search_string);
$redirect_url = variable_get('roblib_search_panel_page', 'roblib/panel'); $redirect_url = variable_get('roblib_search_panel_page', 'roblib/panel');
$redirect_url = $base_url . '/' . $redirect_url; $redirect_url = $base_url . '/' . $redirect_url;
drupal_goto($redirect_url, array('query' => array('roblib_query' => $search_string))); drupal_goto($redirect_url, array('query' => array('roblib_query' => $search_string)));
} }
function roblib_search_log_query($search_string) {
$eid = db_insert('roblib_search_log')
->fields(array(
'query' => $search_string,
'searched_date' => format_date(time(), 'custom', 'Y-m-d H:i:s'),
'ipaddress' => ip_address(),
))
->execute();
}
/** /**
* Roblib search simple search form * Roblib search simple search form
* *

4
targets/evergreen/roblib_search_evergreen.module

@ -85,7 +85,7 @@ function roblib_search_evergreen_config_form($form, &$form_state) {
); );
//http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t= //http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=
$form['roblib_search_evergreen_catalog_base_search_url'] = array( $form['roblib_search_evergreen_catalog_base_search_url'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Evergreen catalog base search url'), '#title' => t('Evergreen catalog base search url'),
'#default_value' => variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='), '#default_value' => variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='),
'#description' => t('The Catalog base url so we can repeat the search in the catalog, for example, http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='), '#description' => t('The Catalog base url so we can repeat the search in the catalog, for example, http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='),
@ -186,7 +186,7 @@ function roblib_search_evergreen_get_results($query) {
$number_of_records = variable_get('roblib_search_evergreen_num_results', '5'); $number_of_records = variable_get('roblib_search_evergreen_num_results', '5');
$query = str_replace(' ', '%20AND%20',$query);//hack until the library decides if we want phrase or individual words $query = str_replace(' ', '%20AND%20',$query);//hack until the library decides if we want phrase or individual words
$search_url = $url . $url_suffix . $query . '&maximumRecords=' . $number_of_records; $search_url = $url . $url_suffix . $query . '&maximumRecords=' . $number_of_records;
$catalog_base_search_url = variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=');
drupal_add_js(array('roblib_search_evergreen' => array('catalog_url' => $catalog_base_search_url)), array('type' => 'setting')); drupal_add_js(array('roblib_search_evergreen' => array('catalog_url' => $catalog_base_search_url)), array('type' => 'setting'));
$results = drupal_http_request($search_url); $results = drupal_http_request($search_url);
if ($results->code == '200') { if ($results->code == '200') {

Loading…
Cancel
Save