1 <script language="PHP">
2 require "search-functions.php";
4 $mode = array_key_exists('v', $_GET)?$_GET['v']:"";
5 $query = array_key_exists('query', $_GET)?$_GET['query']:"";
7 $query_results = run_query($query);
11 case "opensearch.xml":
12 opensearch_description();
15 opensearch_json_results($query, $query_results);
18 opensearch_xml_results($query, $query_results);
21 invalid_format($query, $query_results);
25 function opensearch_description()
30 $shortname = $translator['search']." ".$config['PROJECT_NAME'];
31 $link = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']);
32 header("Content-Type: application/xml");
33 echo <<<END_OPENSEARCH
34 <?xml version="1.0" encoding="UTF-8"?>
35 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
36 <ShortName>$shortname</ShortName>
37 <Description>Doxygen Search</Description>
38 <InputEncoding>UTF-8</InputEncoding>
40 <Image height="16" width="16" type="image/x-icon">
41 http://dev.squello.com/doc/html/favicon.ico</Image>
43 <Url type="text/html" method="GET"
44 template="$link/search.php?query={searchTerms}" />
45 <Url type="application/x-suggestions+json" method="GET"
46 template="$link/search-opensearch.php?v=json&query={searchTerms}" />
47 <Url type="application/x-suggestions+xml" method="GET"
48 template="$link/search-opensearch.php?v=xml&query={searchTerms}" />
49 </OpenSearchDescription>
53 function opensearch_xml_results($query, array $results)
55 // Much as I hate copy'n'paste code re-use, this is for testing;
56 // I expect a richer version to come soon.
57 // Although I hate that IE does this richer than FF more...
58 $qs_results = array();
59 foreach ($results as $i => $val)
61 foreach ($val['words'] as $j => $word)
63 if (array_key_exists($word, $qs_results))
64 $qs_results[$word['match']]++;
66 $qs_results[$word['match']] = 1;
71 <SearchSuggestion xmlns="http://schemas.microsoft.com/Search/2008/suggestions">
75 foreach ($qs_results as $word => $count)
77 $result .= <<<END_FRAG
80 <Description>$count results</Description>
84 $result .= <<<END_FRAG
91 function opensearch_json_results($query, array $results)
93 $qs_results = array();
94 foreach ($results as $i => $val)
96 foreach ($val['words'] as $j => $word)
98 if (array_key_exists($word, $qs_results))
99 $qs_results[$word['match']]++;
101 $qs_results[$word['match']] = 1;
104 $result = '["'.$query.'", [';
106 $json_descriptions = "";
108 foreach ($qs_results as $word => $count)
113 $json_descriptions .= ", ";
115 $json_words .= '"'.$word.'"';
116 $json_descriptions .= '"'.$count.' result'.($count==1?'':'s').'"';
119 print "[\"$query\", [$json_words],[$json_descriptions]]";
122 function invalid_format($query, array $results)
124 print "Search results for '$query':\n\n";