116 lines
3.6 KiB
Text
116 lines
3.6 KiB
Text
<?php
|
|
require ("header.php");
|
|
|
|
/* Output an error box */
|
|
function writeerror (string $message, bool $link) {
|
|
print ("<center>");
|
|
print (" <table class=\"header\" align=\"center\">");
|
|
print (" <tr>");
|
|
print (" <td align=\"center\">");
|
|
print (" <b class=\"subheading\">$message</b>");
|
|
if ($link == true) {
|
|
printf (" <br>Click <a href=\"https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]\" title=\"Retry Search\">here</a> to retry your search.");
|
|
}
|
|
print (" </td>");
|
|
print (" </tr>");
|
|
print (" </table>");
|
|
print ("</center>");
|
|
print ("<br>");
|
|
}
|
|
|
|
/* Construct the url */
|
|
$url = "https://slackware.uk/cgi-bin/searchapi.cgi?";
|
|
if (isset ($_GET[l])) {
|
|
$url = $url . "l=$_GET[l]&";
|
|
}
|
|
if (isset ($_GET[p])) {
|
|
$url = $url . "p=$_GET[p]&";
|
|
} else {
|
|
$url = $url . "p=/&";
|
|
}
|
|
if (isset ($_GET[q])) {
|
|
$url = $url . "q=$_GET[q]";
|
|
} else {
|
|
$url = $url . "q=";
|
|
}
|
|
|
|
/* Query the search API */
|
|
if ($fh = fopen ($url, "r")) {
|
|
/* Read and extract the status number */
|
|
$status_line = stream_get_line ($fh, 0, "\n");
|
|
$status = explode (":", $status_line);
|
|
if ($status[1] == "0") {
|
|
?>
|
|
<center>
|
|
<table class="header" align="center">
|
|
<tr>
|
|
<td align="center">
|
|
<b class="heading">Search Results</b><br><br>
|
|
<b class="subheading">Search query: <?php print ($_GET["q"]) ?></b><br>
|
|
Searches may contain multiple terms, include (basic) globs,<br>
|
|
and descend down from the current directory.
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
<table width="90%" align="center" cellspacing="15">
|
|
<tr>
|
|
<td class="search" align="right" valign="center">
|
|
<form action="/search">
|
|
<input type="hidden" name="p" value="$X_p">
|
|
<input class="searchinput" title="Search" alt="Search Box" type="text" name="q" value="<?php print ($_GET["q"]) ?>" autocomplete="on" required>
|
|
</form>
|
|
</td>
|
|
<td width="100%">
|
|
<!-- This cell is intentionally empty -->
|
|
</td>
|
|
<td class="search" align="left" valign="center">
|
|
<a href="/html/toggletheme.php" title="Toggle Theme" alt="Toggle Theme"><img src="/html/toggletheme.png" title="Toggle Theme" alt="Toggle Theme"></a>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="searchresults" colspan="3">
|
|
<hr>
|
|
<code>
|
|
<?php
|
|
/* Read the results and turn into urls */
|
|
$count = 0;
|
|
while ($result_line = stream_get_line ($fh, 0, "\n")) {
|
|
print ("• <a href=\"https://slackware.uk$result_line\" title=\"$result_line\">$result_line</a><br>");
|
|
$count++;
|
|
}
|
|
/* Output a total */
|
|
if ($count == 0) {
|
|
print (" No results - try to widen your search.");
|
|
} elseif ($count == 1) {
|
|
print (" " . $count . " result found.");
|
|
} else {
|
|
print (" " . $count . " results found.");
|
|
}
|
|
?>
|
|
</code>
|
|
<hr>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<?php
|
|
} else {
|
|
/* The status line indicates an error */
|
|
$error_line = stream_get_line ($fh, 0, "\n");
|
|
$error = explode (":", $error_line);
|
|
if ($status[1] == 1) {
|
|
writeerror ($error[1], true);
|
|
} elseif ($status[1] == 2) {
|
|
writeerror ($error[1], false);
|
|
} else {
|
|
writeerror ("An unexpected error occured", false);
|
|
}
|
|
}
|
|
} else {
|
|
/* Error from the API */
|
|
writeerror ("Search facility unavailable at present, sorry!", false);
|
|
}
|
|
|
|
fclose ($fh);
|
|
require ("footer.shtml");
|
|
?>
|