/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
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
<?php

/*
Supported options
    xml  - URL providing actual search
    xslt - XSLT to process results (optional)
    noprops - Do not pass current props to the proxying URL
    nolimits - Do not pass limits to the proxying URL
    searchprop - Search property (search by default)

*/

class PROXYSearch extends SEARCHEngine {
 function __construct(REQUEST $req = NULL, $opts = false) {
    parent::__construct($req, $opts);
    
    $this->modules = array("proxy");
 }

 function Search($search_string, $module, SEARCHFilter $filter = NULL, $opts = false) {
    global $ADEI;

    $xml = $this->GetOption("xml", $opts);
    $xslt = $this->GetOption("xslt", $opts, "null");
    $noprops = $this->GetOption("noprops", $opts);
    $nolimits = $this->GetOption("nolimits", $opts);
    $searchprop = $this->GetOption("searchprop", $opts, false);

    if ($xml) {
	if (preg_match("/^(services\/)?([\w\d_]+\.php)(\?(.*))?$/", $xml, $m)) {
	    $adei_url = $ADEI->GetBaseURL();
	    $xml_url = "{$adei_url}services/" . $m[2];
	    $xml_props = $m[4];
	} else {
	    if (($opts)&&($opts['xml'])) {
		throw new ADEIException(translate("Proxy-search is allowed to ADEI-services only"));
	    } else {
		list($xml_url, $xml_props) = preg_split("/\?/", $xml, 2);
	    }
	}
    } else {
	throw new ADEIException(translate("The proxy URL is required by search module"));
    }
    
    
    if ($noprops) {
	$props = array();
    } else {
	$props = $this->req->GetProps();
	unset($props['search']);
	unset($props['search_modules']);
    }
    
    if (($filter)&&(!$nolimits)) {
	$ivl_filter = $filter->GetLimit('interval');
	if ($ivl_filter) $props['window'] = $ivl_filter;
    }
    
    if ($searchprop === false) {
	$props['search'] = $search_string;
    } else {
	if ($searchprop) $props[$searchprop] = $search_string;
    }
    
    if ($props) {
	$req = new REQUEST($props);
	$xml_props = $req->GetQueryString($xml_props);
	$xml = $xml_url . "?" . $xml_props;
    } else {
	if ($xml_props) $xml = $xml_url . "?" . $xml_props;
	else $xml = $xml_url;
    }

    $html = $ADEI->TransformXML($xslt, $xml);

    $result = new SEARCHResults(NULL, $this, $module, "");
    $result->Append(preg_replace("/^\s*<\?xml.*$/m", "", $html));
    return $result;
 }

}
?>