From c5ff03f2769e94f228aa5272e05256a1ec8ac5f1 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Tue, 27 May 2014 15:12:27 -0300 Subject: [PATCH] added search query and ip logging --- roblib_search.install | 42 +++++++++++++++++++ roblib_search.module | 12 ++++++ .../evergreen/roblib_search_evergreen.module | 4 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/roblib_search.install b/roblib_search.install index a4abe2d..5eb7a7d 100644 --- a/roblib_search.install +++ b/roblib_search.install @@ -1,2 +1,44 @@ '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; +} + diff --git a/roblib_search.module b/roblib_search.module index 7f7f062..4eaee81 100644 --- a/roblib_search.module +++ b/roblib_search.module @@ -108,11 +108,23 @@ function roblib_search_simple_form_submit($form, &$form_state) { global $base_url; $form_state['rebuild'] = TRUE; $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 = $base_url . '/' . $redirect_url; 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 * diff --git a/targets/evergreen/roblib_search_evergreen.module b/targets/evergreen/roblib_search_evergreen.module index 5ba0982..fd41fa4 100644 --- a/targets/evergreen/roblib_search_evergreen.module +++ b/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= $form['roblib_search_evergreen_catalog_base_search_url'] = array( - '#type' => 'textfield', + '#type' => 'textfield', '#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='), '#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'); $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; - + $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')); $results = drupal_http_request($search_url); if ($results->code == '200') {