summaryrefslogtreecommitdiff
path: root/utilities/diatheke/soap/sapouni.cgi
blob: 24df769326984bb861333519c6a5d05379c7e217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl

#version 1.0

package sapouni;
$sapouni = "nice /usr/bin/diatheke";  # location of diatheke command line program -- if you are using a MS Windows server, you might need to remove the "nice"

$sword_path = "/home/sword";  # SWORD_PATH environment variable you want to use
$maxverses = 0; # maximum number of verses diatheke will return per query (prevents people from asking for Gen1:1-Rev22:21; 0 for unlim.)
$defversion = "KJV"; # book to query when none is selected, but a verse/search is entered
$deflocale = "abbr";  # this is just the default for cases where user has not selected a locale and his browser does not reveal one -- you can also set locale using locael=<locale> in the GET URL


###############################################################################
## You should not need to edit anything below this line.
## Unless you want to modify functionality of course. :)
###############################################################################

$ENV{'SWORD_PATH'} = $sword_path;

use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI
    -> dispatch_to('sapouni')
    -> handle;

package sapouni;

sub biblequery {
    my ($class, $books, $key, $options, $encoding, $markup, $searchtype, $locale, $script, $max) = @_;

    if ($key eq "") {
	$key = "Jn 3:16";
    }

    @booklist = split ' ', $books;
    
    $n = scalar(@booklist);
    if ($n == 0) {
	@booklist[0] = $defversion;
	$n++;
    }

    $query = "";

    if ($options ne "") {
	$query .= " -o \"$options\"";
    }

    if ($encoding ne "") {
	$query .= " -e \"$encoding\"";
    }
    else {
	$query .= " -e UTF8";
    }

    if ($markup ne "") {
	$query .= " -f \"$markup\"";
    }
    else {
	$query .= " -f ThML";
    }

    if ($searchtype ne "") {
	$query .= " -s \"$searchtype\"";
    }

    if ($locale ne "") {
	$query .= " -l \"$locale\"";
    }
    else {
	$query .= " -l $deflocale";
    }

    if ($script ne "") {
	$query .= " -t \"$script\"";
    }
    
    if ($max ne "" && $max ne 0) {
	$query .= " -m \"$max\"";
    }

    $rval = "";
    for ($i = 0; $i < $n; $i++) {   
	$line = "$sapouni $query -b $booklist[$i] -k \"$key\" 2> /dev/null";
	
	# uncomment to print the command line send to Diatheke (for debugging)
	# $rval .= "$line\n";

	$line = `$line`;
	chomp($line);
	
	$rval .= "$line\n";
    }	

    return "$rval";
}