Browse Source

added islandscholar target

2.x-ebsco
Paul Pound 11 years ago
parent
commit
976c32eac3
  1. 21
      targets/islandscholar/css/roblib_search_islandscholar.css
  2. 115
      targets/islandscholar/js/islandscholar_results.js
  3. 8
      targets/islandscholar/roblib_search_islandscholar.info
  4. 2
      targets/islandscholar/roblib_search_islandscholar.install
  5. 156
      targets/islandscholar/roblib_search_islandscholar.module
  6. 24
      targets/islandscholar/theme/roblib-search-islandscholar.tpl.php
  7. 24
      targets/islandscholar/theme/theme.inc

21
targets/islandscholar/css/roblib_search_islandscholar.css

@ -0,0 +1,21 @@
/*
Document : roblib_search_evergreen
Created on : Apr 11, 2013, 2:27:50 PM
Author : ppound
Description:
Purpose of the stylesheet follows.
*/
.islandscholar-citation{
font-size: smaller;
}
.islandscholar-hostTitle{
font-size: smaller;
}
.islandscholar-author, .islandscholar-genre, .islandscholar-volume{
padding-left: 10px; font-size: smaller;
}
.islandscholar-label {
padding-left: 10px; font-size: smaller; font-weight: bolder;
}

115
targets/islandscholar/js/islandscholar_results.js

@ -0,0 +1,115 @@
Drupal.behaviors.roblib_search_islandscholar = {
attach: function(context, settings) {
url = settings.roblib_search_islandscholar.search_url;
jQuery.getJSON(url, function(data) {
var items = [];
var numberOfDocs = 0;
try {
numberOfDocs = data.response.docs.length;
} catch (err) {
// do nothing leave docLength at 0
}
if (numberOfDocs < 1) {
jQuery('#' + 'roblib-search-content-islandscholar').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-islandscholar-site-roblib-search-islandscholar-results').hide();
} else {
jQuery.each(data.response.docs, function(key, val) {
items.push('<div class ="roblib-search-row">\n\
<div class="roblib-title islandscholar">\n\
<a href="http://www.islandscholar.ca/fedora/repository/' + val.PID +'">' + val.Title_sorted + '</a></div>');
try {
items.push('<div class="islandscholar-authors">');
jQuery.each(val.author, function(key2, val2){
items.push('<span class="islandscholar-author">' + val2 + ';</span> ')
})
items.push('</div>')
} catch (e){
}
try {
items.push('<div class="islandscholar-source">');
jQuery.each(val.genre, function(key2, val2){
items.push('<span class="islandscholar-label">' + val2 + '</span> ')
})
try{
jQuery.each(val["mods.hostTitle"], function(key2, val2){
items.push('<span class="islandscholar-hostTitle">' + val2 + '</span> ')
})
} catch (err){
}
try{
jQuery.each(val["mods.volume"], function(key2, val2){
items.push('<span class="islandscholar-citation">Vol. </span><span class="islandscholar-citation">' + val2 + '</span> ')
})
} catch (err){
}
try{
jQuery.each(val["mods.issue"], function(key2, val2){
items.push('<span class="islandscholar-citation">Issue </span><span class="islandscholar-citation">' + val2 + ',</span> ')
})
} catch (err){
}
try{
jQuery.each(val["mods.pageStart"], function(key2, val2){
items.push('<span class="islandscholar-citation">p</span><span class="islandscholar-citation">' + val2 + '</span>')
})
} catch (err){
}
try{
jQuery.each(val["mods.pageEnd"], function(key2, val2){
items.push('<span class="islandscholar-citation">-</span><span class="islandscholar-citation">' + val2 + ',</span>')
})
} catch (err){
}
try{
if(jQuery.inArray('OBJ',val.hasDatastreams) > 0){
items.push('<div>full text</div>') ;
}
} catch (err){
}
items.push('</div>')
} catch (e){
}
items.push('</div>');
});
var number = parseInt(data.rows);
jQuery('#roblib-search-content-islandscholar').empty().append(items.join(''));
items = showMoreItems(items, number);
}
});
}
}
function showMoreItems(items, number) {
for (var i = 0; i < number; i++) {
jQuery('#' + 'roblib-search-content-solr-site').append(items.pop());
}
if (items.length > 0)
{
jQuery('#roblib-search-solr-site-more').empty().append('<a id="islandscholar_see_more_result">see ' + items.length + ' more results</a>');
jQuery('#see_more_result').click(function() {
items = showMoreItems(items, number);
});
}
else
{
jQuery('#roblib-search-solr-site-more').empty().append('no more results');
}
return items;
}

8
targets/islandscholar/roblib_search_islandscholar.info

@ -0,0 +1,8 @@
name = Roblib Search IslandScholar
dependencies[] = roblib_search
configure = admin/roblib_search/islandscholar_search
description = implements the Roblib Search IslandScholar results
package = Roblib Search
version = 7.x-dev
core = 7.x
stylesheets[all][] = css/roblib_search_islandscholar.css

2
targets/islandscholar/roblib_search_islandscholar.install

@ -0,0 +1,2 @@
<?php

156
targets/islandscholar/roblib_search_islandscholar.module

@ -0,0 +1,156 @@
<?php
/**
* @file
* Implementation of Roblib search for searching several targets.
*/
/**
* Implements hook_menu().
*/
function roblib_search_islandscholar_menu() {
$items = array();
$items['admin/roblib_search/islandscholar_search'] = array(
'title' => 'Roblib Islandscholar Search Target configuration',
'description' => 'Configuration for the Roblib Islandscholar site search target',
'page callback' => 'drupal_get_form',
'page arguments' => array('roblib_search_islandscholar_config_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items['roblib_search/islandscholar/ajax/%'] = array(
'title' => 'islandscholar ajax',
'page callback' => 'roblib_search_islandscholar_ajax',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib islandscholar'),
);
return $items;
}
function roblib_search_islandscholar_config_form($form, &$form_state) {
$form['roblib_search_islandscholar_url'] = array(
'#type' => 'textfield',
'#title' => t('Islandscholar Solr url'),
'#default_value' => variable_get('roblib_search_islandscholar_url', 'http://www.islandscholar.ca:8080/solr/'),
'#description' => t('The base Islandscholar Solr URL, for example http://www.islandscholar.ca:8080/solr/'),
'#required' => TRUE,
);
$form['roblib_search_islandscholar_num_results'] = array(
'#type' => 'textfield',
'#title' => t('Number of results to return'),
'#default_value' => variable_get('roblib_search_islandscholar_num_results', '5'),
'#description' => t('The number of results to display in the Bento box'),
'#required' => TRUE,
);
return system_settings_form($form);
}
/**
* Implements hook_permission().
*/
function roblib_search_islandscholar_permission() {
return array(
'search roblib islandscholar' => array(
'title' => t('Search the islandscholar target'),
'description' => t('Search all Roblib islandscholar target. This permission exposes the search blocks and allows you to see search results.'),
),
'administer roblib search_islandscholar' => array(
'title' => t('Administer Roblib Search Evergreen'),
'description' => t('Administer settings for the Roblib islandscholar search client.'),
),
);
}
/**
* Implements hook_theme().
*/
function roblib_search_islandscholar_theme() {
// set path
$path = drupal_get_path('module', 'roblib_search_islandscholar');
$file = 'theme.inc';
return array(
// results page
'roblib_search_islandscholar' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-islandscholar',
'variables' => array('results' => NULL),
)
);
}
function roblib_search_islandscholar_block_info() {
$blocks['roblib_search_islandscholar_results'] = array(
// info: The name of the block.
'info' => t('Roblib Islandscholar Solr Search Results block'),
// Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE, // default
);
return $blocks;
}
function roblib_search_islandscholar_block_view($delta = '') {
//The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'roblib_search_islandscholar_results':
$block['subject'] = t('IslandScholar');
$block['content'] = theme('roblib_search_islandscholar', array('results' => NULL));
break;
}
return $block;
}
function roblib_search_islandscholar_ajax($query) {
$output = roblib_search_islandscholar_get_results($query);
print $output;
exit();
}
/**
*
* @param string $query
* @return string
* json
*/
function roblib_search_islandscholar_get_results($query) {
$solr_url = variable_get('roblib_search_islandscholar_url', 'http://localhost:8983/solr');
//$query = $solr_url . '/select?wt=json&q=test page';
$num_results = variable_get('roblib_search_islandscholar_num_results', '5');
$data = array(
'wt' => 'json',
'q' => $query,
'fq' => 'PID:ir*',
);
$url = url($solr_url . '/select', array('query' => $data));
$results = drupal_http_request($url);
if($results->code != '200'){
return "";
}
$temp = substr($results->data, 1);
//$out = '{"rows":"' . $num_results . '",' . $results->data;
return $results->data;
}
/**
* Implements hook_help().
*/
function roblib_search_islandscholar_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search_islandscholar':
return t(
'<p>
provides an Islandscholar target for the Roblib search module
</p>'
);
}
}

24
targets/islandscholar/theme/roblib-search-islandscholar.tpl.php

@ -0,0 +1,24 @@
<?php
/**
* @file islandora-solr-wrapper.tpl.php
* Islandora solr search results wrapper template
*
* Variables available:
* - $variables: all array elements of $variables can be used as a variable. e.g. $base_url equals $variables['base_url']
* - $base_url: The base url of the current website. eg: http://example.com .
* - $user: The user object.
*
*
* - $results: Rendered search results (primary profile)
*
*
* @see template_preprocess_roblib_search_wrapper()
*/
?>
<div class ="roblib-search-content solr-site" id="roblib-search-content-islandscholar">
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div>
<div class ="roblib-search-more" id="roblib-search-solr-site-more">Search all Results</div>

24
targets/islandscholar/theme/theme.inc

@ -0,0 +1,24 @@
<?php
/*
* all we do here is pass a url to some javascript so results can be loaded
* indepentantly
*/
function roblib_search_islandscholar_preprocess_roblib_search_islandscholar(&$variables) {
global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/'.'spinner.gif';
$variables['spinner_path'] = $spinner_path;
$search_url = $base_url .'/roblib_search/islandscholar/ajax/'.urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_islandscholar') . '/js/islandscholar_results.js');
drupal_add_js(array('roblib_search_islandscholar' => array('search_url' => $search_url)), array('type' => 'setting'));
}
?>
Loading…
Cancel
Save