Updating Simple Remote Search Module
bomarmonk - June 11, 2008 - 23:53
I am trying to get a very simple module working in Drupal 5: it allows a remote site to be searched with a "GET URL." Right now, this just produces a blank screen when the block is enabled. I'm not sure what is amiss. Thank you for any help...
<?php
/*
remote_search.module, a simple Druapal (5.x) module for searching remote databases using GET URLs.
Written by Mark Jordan, mjordan@sfu.ca, and placed in the public domain.
Last updated 2008-06-11 (version 0.2).
Usage:
1) Upload into your Drupal's modules directory.
2) Go to administer > settings > remote_search and enter the URL you want to search and the title of the search block.
3) Go to administer > blocks and activate/configure the block.
*/
/**
* Implementation of hook_menu()
*/
function remote_search_menu($may_cache = true) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'remote_search',
'access' => user_access('search remotely'),
'callback' => 'remote_search_get'
);
$items[] = array(
'path' => 'admin/settings/remote_search',
'title' => t('Remote Search'),
'description' => t('Set remote search configuration options'),
'callback' => 'drupal_get_form',
'callback arguments' => 'remote_search_settings',
'access' => user_access('administer site configuration'),
);
}
return $items;
}
/**
* Implementation of hook_perm().
*/
function remote_search_perm() {
return array('administer remote_search');
}
/**
* Implementation of hook_settings().
*/
function remote_search_settings() {
$form = array();
$form['remote_search_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Remote database GET URL'),
'#size' => 80,
'#maxlength' => 100,
'#description' => t("URL of the remote database (GET URL)"),
'#default_value' => variable_get('remote_search_base_url', ''),
);
$form['remote_search_block_title'] = array(
'#type' => 'textfield',
'#title' => t('Title of search form block'),
'#size' => 80,
'#maxlength' => 100,
'#description' => t("The title of the block containing the search form"),
'#default_value' => variable_get('remote_search_block_title', ''),
);
return system_settings_form($form);
}
function remote_search_block($op = "list", $delta = 0) {
$block_title = variable_get('remote_search_block_title', '');
if ($op == 'list') {
$block[0]['info'] = t($block_title);
return $block;
}
elseif ($op == 'view') {
$block['subject'] = $block_title;
$block['content'] = remote_search_form();
return $block;
}
}
function remote_search_form($edit = null) {
$form['terms'] = array(
'#type' => 'textfield',
'#default_value' => $edit['terms'],
'#size' => 20,
'#maxlength' => 100,
'#required' => true,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#submit' => TRUE,
);
return drupal_get_form('remote_search_form', $form);
}
function remote_search_form_submit($form_id, $form_values) {
$remote_search_url = variable_get('remote_search_base_url', '');
$search_params = $form_values['terms'];
$remote_search_url = $remote_search_url . $search_params;
$remote_search_url = check_url($remote_search_url);
drupal_goto($remote_search_url);
}
The original...
...is posted here: http://drupalib.interoperating.info/remote_search_module
Nice to see someone using this module
Hi bomarmonk,
I think this was the first module I ever wrote... cool to see someone using it.
The following version works on Drupal 5.7:
<?php
/*
remote_search.module, a simple Drupal (5.x) module for searching remote databases using GET URLs.
Written by Mark Jordan, mjordan@sfu.ca, and placed in the public domain.
Last updated 2008-06-11 (version 0.2).
Usage:
1) Upload into your Drupal's modules directory.
2) Go to administer > settings > remote_search and enter the URL you want to search and the title of the search block.
3) Go to administer > blocks and activate/configure the block.
*/
/**
* Implementation of hook_menu()
*/
function remote_search_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'remote_search',
'access' => user_access('search remotely'),
'callback' => 'remote_search_get'
);
$items[] = array(
'path' => 'admin/settings/remote_search',
'title' => t('Remote Search'),
'description' => t('Set remote search configuration options'),
'callback' => 'drupal_get_form',
'callback arguments' => 'remote_search_settings',
'access' => user_access('administer remote_search'),
);
}
return $items;
}
/**
* Implementation of hook_perm().
*/
function remote_search_perm() {
return array('administer remote_search');
}
/**
* Implementation of hook_settings().
*/
function remote_search_settings() {
$form = array();
$form['remote_search_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Remote database GET URL'),
'#size' => 80,
'#maxlength' => 100,
'#description' => t("URL of the remote database (GET URL)"),
'#default_value' => variable_get('remote_search_base_url', ''),
);
$form['remote_search_block_title'] = array(
'#type' => 'textfield',
'#title' => t('Title of search form block'),
'#size' => 80,
'#maxlength' => 100,
'#description' => t("The title of the block containing the search form"),
'#default_value' => variable_get('remote_search_block_title', ''),
);
return system_settings_form($form);
}
function remote_search_block($op = "list", $delta = 0, $edit = array()) {
$block_title = variable_get('remote_search_block_title', '');
if ($op == 'list') {
$block[0]['info'] = t($block_title);
return $block;
}
elseif ($op == 'view') {
$block['subject'] = $block_title;
$block['content'] = drupal_get_form('remote_search_form');
return $block;
}
}
function remote_search_form($edit = null) {
$form['terms'] = array(
'#type' => 'textfield',
'#default_value' => $edit['terms'],
'#size' => 20,
'#maxlength' => 100,
'#required' => true,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#submit' => TRUE,
);
return $form;
}
function remote_search_form_submit($form_id, $form_values) {
$remote_search_url = variable_get('remote_search_base_url', '');
$search_params = $form_values['terms'];
$remote_search_url = $remote_search_url . $search_params;
$remote_search_url = check_url($remote_search_url);
drupal_goto($remote_search_url);
}
Basically, the problem was that you need to return $form (not drupal_get_form) in remote_search_form(), and use $block['content'] = drupal_get_form('remote_search_form'); within your block.
Mark
Thank you!
I am trying to get this working with our PAC, but the GET URL is a bit tricky. There also seems to be a slight problem with the menu code, as this injects an empty menu item into the regular navigation menu of Drupal. I'm also wondering how this module will return the results of the search? Is there any way to open a new page and target an iframe with this? Mark, thanks again for your initial help in getting this to work.
Maybe move discussion to Drupalib?
Since you're using this in a library context, which may not be of much interest to general d.o. users, feel free to move this discussion over to http://drupalib.interoperating.info/, where we might get some further input on how this module might work for searching PACs.
One issue with an iframe is that there would be no way to theme the results if you were doing a straight render of the remote system's output.
Mark