2 require "search_functions.php";
4 $mode = array_key_exists('v', $_GET)?$_GET['v']:"";
5 $query = array_key_exists('query', $_GET)?$_GET['query']:"";
6 $query = preg_replace("/[^a-zA-Z0-9\-\_\.\x80-\xFF]/i", " ", $query );
8 $query_results = run_query($query);
12 case "opensearch.xml":
13 opensearch_description();
16 opensearch_json_results($query, $query_results);
19 opensearch_xml_results($query, $query_results);
22 invalid_format($query, $query_results);
26 function opensearch_description()
31 $shortname = $translator['search']." ".$config['PROJECT_NAME'];
32 $link = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']);
33 header("Content-Type: application/xml");
34 echo <<<END_OPENSEARCH
35 <?xml version="1.0" encoding="UTF-8"?>
36 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
37 <ShortName>$shortname</ShortName>
38 <Description>Doxygen Search</Description>
39 <InputEncoding>UTF-8</InputEncoding>
41 <Image height="16" width="16" type="image/x-icon">
42 http://dev.squello.com/doc/html/favicon.ico</Image>
44 <Url type="text/html" method="GET"
45 template="$link/search.php?query={searchTerms}" />
46 <Url type="application/x-suggestions+json" method="GET"
47 template="$link/search_opensearch.php?v=json&query={searchTerms}" />
48 <Url type="application/x-suggestions+xml" method="GET"
49 template="$link/search_opensearch.php?v=xml&query={searchTerms}" />
50 </OpenSearchDescription>
54 function opensearch_xml_results($query, array $results)
56 // Much as I hate copy'n'paste code re-use, this is for testing;
57 // I expect a richer version to come soon.
58 // Although I hate that IE does this richer than FF more...
59 $qs_results = array();
60 foreach ($results as $i => $val)
62 foreach ($val['words'] as $j => $word)
64 if (array_key_exists($word, $qs_results))
65 $qs_results[$word['match']]++;
67 $qs_results[$word['match']] = 1;
72 <SearchSuggestion xmlns="http://schemas.microsoft.com/Search/2008/suggestions">
76 foreach ($qs_results as $word => $count)
78 $result .= <<<END_FRAG
81 <Description>$count results</Description>
85 $result .= <<<END_FRAG
92 function opensearch_json_results($query, array $results)
94 $qs_results = array();
95 foreach ($results as $i => $val)
97 foreach ($val['words'] as $j => $word)
99 if (array_key_exists($word, $qs_results))
100 $qs_results[$word['match']]++;
102 $qs_results[$word['match']] = 1;
105 $result = '["'.$query.'", [';
107 $json_descriptions = "";
109 foreach ($qs_results as $word => $count)
114 $json_descriptions .= ", ";
116 $json_words .= '"'.$word.'"';
117 $json_descriptions .= '"'.$count.' result'.($count==1?'':'s').'"';
120 print "[\"$query\", [$json_words],[$json_descriptions]]";
123 function invalid_format($query, array $results)
125 print "Search results for '$query':\n\n";