forked from php/web-php
/
search.php
186 lines (162 loc) · 6 KB
/
search.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php // vim: et
// $Id$
$_SERVER['BASE_PAGE'] = 'search.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
// ---------------------------------------------------------------------------
// Convert POST -> GET for dumping the user onto a mirror
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$_FORM = &$_POST;
$_SERVER['REQUEST_URI'] = "/search.php?";
$vars = array("show", "pattern", "lang");
foreach ($vars as $varname) {
if (!empty($_POST[$varname])) {
$_SERVER['REQUEST_URI'] .= "$varname=" . urlencode($_POST[$varname]) . "&";
}
}
} else {
$_FORM = &$_GET;
}
// Drive load to mirror sites when searching
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/loadavg.inc';
// ---------------------------------------------------------------------------
// If PHP added some slashes to quotes, get rid of them
if ($MQ) {
foreach ($_FORM as $name => $value) {
$_FORM[$name] = stripslashes($value);
}
}
// We received something to search for
if (!empty($_FORM['pattern'])) {
if (empty($_FORM['show'])) {
$_FORM['show'] = 'all';
}
// Never allow a comma in the show string, that would confuse our JS
$_FORM['show'] = str_replace(",", "", $_FORM['show']);
// Mailing list search base URL
$ml_url = "http://marc.info/?r=1&w=2&q=b&";
$ucp = urlencode($_FORM['pattern']);
// Do redirections for external search engines
switch ($_FORM['show']) {
case "quickref" :
case "404quickref" :
$langparam = (isset($EXPL_LANG) ? "&lang=$EXPL_LANG" : "");
mirror_redirect("/manual-lookup.php?pattern={$ucp}{$langparam}&scope={$_FORM['show']}");
case "maillist" :
mirror_redirect("{$ml_url}l=php-general&s={$ucp}");
case "devlist" :
mirror_redirect("{$ml_url}l=php-internals&s={$ucp}");
case "phpdoc" :
mirror_redirect("{$ml_url}l=phpdoc&s={$ucp}");
case "bugdb" :
// Redirect to bug page in case of exact number
if (preg_match("!^\\d+$!", $_FORM['pattern'])) {
mirror_redirect("http://bugs.php.net/{$ucp}");
}
// Redirect to bug search page in case of some other pattern
else {
mirror_redirect(
"http://bugs.php.net/search.php?" .
"cmd=Display+Bugs&status=All&bug_type=Any&search_for={$ucp}"
);
}
case "manual":
case "404manual":
mirror_redirect($MYSITE . "results.php?q={$ucp}&p={$_FORM['show']}&l=$LANG");
break;
case "news_archive":
$p = urlencode($_FORM['show']);
mirror_redirect($MYSITE . "results.php?q=intitle:news%2Barchive+{$ucp}&p=local");
break;
case "changelogs":
$p = urlencode($_FORM['show']);
mirror_redirect($MYSITE . "results.php?q=intitle:ChangeLog+{$ucp}&p=local");
break;
// Covers the rest
default:
$p = urlencode($_FORM['show']);
mirror_redirect($MYSITE . "results.php?q={$ucp}&l=$LANG&p=$p");
break;
}
}
// No pattern provided, print search page
else {
// Print out common header
$link = array(
"rel" => "search",
"type" => "application/opensearchdescription+xml",
"href" => $MYSITE . "phpnetimprovedsearch.src",
"title" => "Add PHP.net search"
);
site_header("Search", array("link" => array($link), "current" => "FIXME"));
?>
<p>
The autocompleting search feature is accessible via the form elements at the top
right of php.net pages. You should be able to use this feature in a reasonably modern
browser by selecting the 'function list' search option and typing in some letters
into the searchbox. Features:
</p>
<ul>
<li>Dynamically changing list of function names starting with the substring you typed</li>
<li>Navigate in the list with up and down keys</li>
<li>Autocomplete with pressing the space key</li>
<li>Go to a function by clicking on its name with your mouse</li>
</ul>
<p>
If you are not interested in this feature, you can turn it
off for yourself on the <a href="/my.php">My PHP.net</a> page.
</p>
<p>
In case you find any bugs, <a href="http://bugs.php.net/">we are interested</a>
in a detailed writeup, including JS error messages, operating system and browser
information. The source code of this feature is released under the PHP License and
is available <a href="http://svn.php.net/phpdoc/doc-base/trunk/scripts/quickref">from the
PHP SVN server</a> without any support.
</p>
<?php
if (FALSE) {
if (isset($EXPL_LANG)) {
$lang_input = " <input type=\"hidden\" name=\"lang\" value=\"{$EXPL_LANG}\" />\n";
} else {
$lang_input = "\n";
}
?>
<h1>Search</h1>
<form action="/search.php" method="post">
<p><?php echo $lang_input ?>
Search for:
<input type="text" name="pattern" value="" size="30" />
in the
<select name="show">
<?php
if (empty($_FORM['show'])) { $_FORM['show'] = 'quickref'; }
$searchoptions = array(
"quickref" => "function list",
"all" => "all php.net sites",
"local" => "this mirror only",
"manual" => "online documentation [en]",
"bugdb" => "bug database",
"news_archive" => "Site News Archive",
"changelogs" => "All Changelogs",
"pear" => "just pear.php.net",
"pecl" => "just pecl.php.net",
"talks" => "just talks.php.net",
"maillist" => "general mailing list",
"devlist" => "developer mailing list",
"phpdoc" => "documentation mailing list",
);
// Print out an <option> for all search options
foreach ($searchoptions as $key => $value) {
echo ' <option value="' . $key . '"' .
($key == $_FORM['show'] ? ' selected="selected"' : '') .
'>' . $value . "</option>\n";
}
?>
</select>
<input type="submit" value=" Search " />
</p>
</form>
<?php
}
echo '<script type="text/javascript">loadSuggestCode();</script>';
site_footer(array("functionsjs"));
}