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