/adei/ui

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

require($ADEI_ROOTDIR . "/classes/searchengine.php");

class SEARCH {
 var $engines;
 var $modules;
 
 function __construct(REQUEST $req) {
    global $SEARCH_ENGINES;

    $this->modules = array();
    $this->engines = array();
    
    foreach ($SEARCH_ENGINES as $cl => &$opts) {
	if (!include_once("search/" . strtolower($cl) . '.php')) {
	    throw new ADEIException(translate("Unsupported search engine is configured: \"%s\"", $cl));
	}
    
    	$engine = new $cl($req, $opts);
	$modules = $engine->GetModules();
	
	foreach ($modules as $module) {
	    if (isset($this->modules[$module])) {
		throw new ADEIException(translate("SEARCH engines are conflicting. Module (%s) is provided by two different engines: \"" . get_class($this->modules[$module]) . "\" and \"$cl\""));
	    }
	    $this->modules[$module] = $engine;
	}
	
	$this->engines[$cl] = $engine;
    }
 }
 
 
 function Search($string = false, $modules = false, $threshold = false) {
    if ($string === false) $string = $this->req->props['search'];

    if (($modules === false)&&($this->req->props['search_modules'])) {
	$modules = $this->req->props['search_modules'];
    }

    if (($threshold === false)&&(isset($this->req->props['search_threshold']))) {
	$threshold = $this->req->props['search_threshold'];
    }
    
    if (($modules)&&(is_string($modules))) {
	if (strpos($modules, "{") === false) {
	    $mstr = explode(",", $modules);
	    $modules = array();
	    foreach ($mstr as $mod) {
		if (preg_match("/^([\w\d_]+)(\(.*\))$/", $mod, $m)) {
		    $module = $m[1];
		    $modules[$module] = array();
		    
		    if ($m[2]) {
			$params = explode(";", $m[2]);
			foreach ($params as $param) {
			    if (preg_match("/^([^=]+)=(.*)$/", $param, $m)) {
				$modules[$module][$m[1]] = $m[2];
			    } else {
				$modules[$module][$param] = true;
			    }
			}
		    }
		}
	    }
	} else {
	    $modules = json_decode($modules);
	}
    }
    
    if ($modules) {
	$result = array();
	
	foreach ($modules as $module => $opts) {
	    if (isset($this->modules[$module])) {
	        $result[$module] = $this->modules[$module]->Search($string, $module, $opts, $threshold);
	    } else {
		throw new ADEIException(translate("The requested search module (%s) is not provided by any of search engines", $module));
	    }
	}
    } else {
	foreach ($this->engines as $engine) {
	    $engine->EngineSearch($string, $threshold);
	}
    }
    
 }
 
}

?>