/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/search/proxysearch.php

  • Committer: Suren A. Chilingaryan
  • Date: 2009-01-30 23:56:42 UTC
  • Revision ID: csa@dside.dyndns.org-20090130235642-gw9n5v9y7w23dmmd
Further search improvements, support for custom properties (config)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/*
 
4
Supported options
 
5
    xml  - URL providing actual search
 
6
    xslt - XSLT to process results (optional)
 
7
    noprops - Do not pass current props to the proxying URL
 
8
    nolimits - Do not pass limits to the proxying URL
 
9
    searchprop - Search property (search by default)
 
10
 
 
11
*/
 
12
 
 
13
class PROXYSearch extends SEARCHEngine {
 
14
 function __construct(REQUEST $req = NULL, $opts = false) {
 
15
    parent::__construct($req, $opts);
 
16
    
 
17
    $this->modules = array("proxy");
 
18
 }
 
19
 
 
20
 function Search($search_string, $module, SEARCHFilter $filter = NULL, $opts = false) {
 
21
    global $ADEI;
 
22
 
 
23
    $xml = $this->GetOption("xml", $opts);
 
24
    $xslt = $this->GetOption("xslt", $opts, "null");
 
25
    $noprops = $this->GetOption("noprops", $opts);
 
26
    $nolimits = $this->GetOption("nolimits", $opts);
 
27
    $searchprop = $this->GetOption("searchprop", $opts, false);
 
28
 
 
29
    if ($xml) {
 
30
        if (preg_match("/^(services\/)?([\w\d_]+\.php)(\?(.*))?$/", $xml, $m)) {
 
31
            $adei_url = $ADEI->GetBaseURL();
 
32
            $xml_url = "{$adei_url}services/" . $m[2];
 
33
            $xml_props = $m[4];
 
34
        } else {
 
35
            if (($opts)&&($opts['xml'])) {
 
36
                throw new ADEIException(translate("Proxy-search is allowed to ADEI-services only"));
 
37
            } else {
 
38
                list($xml_url, $xml_props) = preg_split("/\?/", $xml, 2);
 
39
            }
 
40
        }
 
41
    } else {
 
42
        throw new ADEIException(translate("The proxy URL is required by search module"));
 
43
    }
 
44
    
 
45
    
 
46
    if ($noprops) {
 
47
        $props = array();
 
48
    } else {
 
49
        $props = $this->req->GetProps();
 
50
        unset($props['search']);
 
51
        unset($props['search_modules']);
 
52
    }
 
53
    
 
54
    if (($filter)&&(!$nolimits)) {
 
55
        $ivl_filter = $filter->GetLimit('interval');
 
56
        if ($ivl_filter) $props['window'] = $ivl_filter;
 
57
    }
 
58
    
 
59
    if ($searchprop === false) {
 
60
        $props['search'] = $search_string;
 
61
    } else {
 
62
        if ($searchprop) $props[$searchprop] = $search_string;
 
63
    }
 
64
    
 
65
    if ($props) {
 
66
        $req = new REQUEST($props);
 
67
        $xml_props = $req->GetQueryString($xml_props);
 
68
        $xml = $xml_url . "?" . $xml_props;
 
69
    } else {
 
70
        if ($xml_props) $xml = $xml_url . "?" . $xml_props;
 
71
        else $xml = $xml_url;
 
72
    }
 
73
 
 
74
    $html = $ADEI->TransformXML($xslt, $xml);
 
75
 
 
76
    $result = new SEARCHResults(NULL, $this, $module, "");
 
77
    $result->Append(preg_replace("/^\s*<\?xml.*$/m", "", $html));
 
78
    return $result;
 
79
 }
 
80
 
 
81
}
 
82
?>
 
 
b'\\ No newline at end of file'