✨Change name to AlpineFind & some enhancements
This commit is contained in:
58
index.php
58
index.php
@@ -9,6 +9,12 @@ if (isset($_GET['q'])) { // if there's a search query, show the results for it
|
||||
$query = urlencode($_GET["q"]);
|
||||
$show_results = TRUE;
|
||||
$search_url = "https://html.duckduckgo.com/html?q=" . $query;
|
||||
|
||||
// Configuration de la pagination
|
||||
$results_per_page = 5; // Nombre de résultats par page
|
||||
$current_page = isset($_GET['p']) ? intval($_GET['p']) : 1;
|
||||
if ($current_page < 1) $current_page = 1;
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Cache-Control: no-cache\r\n" .
|
||||
@@ -26,9 +32,17 @@ if (isset($_GET['q'])) { // if there's a search query, show the results for it
|
||||
|
||||
$result_blocks = explode('<h2 class="result__title">', $simple_results);
|
||||
$total_results = count($result_blocks) - 1;
|
||||
|
||||
// Calcul des paramètres de pagination
|
||||
$total_pages = ceil($total_results / $results_per_page);
|
||||
if ($total_pages == 0) $total_pages = 1; // Éviter la division par zéro
|
||||
|
||||
$start_result = ($current_page - 1) * $results_per_page + 1;
|
||||
$end_result = min($start_result + $results_per_page - 1, $total_results);
|
||||
|
||||
for ($x = 1; $x <= $total_results; $x++) {
|
||||
if (strpos($result_blocks[$x], '<a class="badge--ad">') === false) { //only return non ads
|
||||
// Affichage des résultats pour la page actuelle seulement
|
||||
for ($x = $start_result; $x <= $end_result; $x++) {
|
||||
if ($x <= $total_results && strpos($result_blocks[$x], '<a class="badge--ad">') === false) { //only return non ads
|
||||
// result link, redirected through our proxy
|
||||
$result_link = explode('class="result__a" href="', $result_blocks[$x])[1];
|
||||
$result_topline = explode('">', $result_link);
|
||||
@@ -47,6 +61,17 @@ if (isset($_GET['q'])) { // if there's a search query, show the results for it
|
||||
. $result_display_url . "</font></a><br>" . $result_snippet . "<br><br><hr>";
|
||||
}
|
||||
}
|
||||
|
||||
// Ajout des liens de pagination
|
||||
$final_result_html .= "<br><center>";
|
||||
if ($current_page > 1) {
|
||||
$final_result_html .= "<a href='/?q=" . $query . "&p=" . ($current_page - 1) . "'>< Previous</a> ";
|
||||
}
|
||||
$final_result_html .= "Page " . $current_page . " of " . $total_pages;
|
||||
if ($current_page < $total_pages) {
|
||||
$final_result_html .= " <a href='/?q=" . $query . "&p=" . ($current_page + 1) . "'>Next ></a>";
|
||||
}
|
||||
$final_result_html .= "</center>";
|
||||
}
|
||||
|
||||
//replace chars that old machines probably can't handle
|
||||
@@ -69,7 +94,7 @@ function clean_str($str)
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>FrogFind!</title>
|
||||
<title>AlpineFind!</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<style type="text/css">
|
||||
a {
|
||||
@@ -98,6 +123,12 @@ function clean_str($str)
|
||||
margin: 10px 0;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function showLoading() {
|
||||
document.getElementById('loading').style.display = 'inline';
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body style="margin: 5px; padding: 0;">
|
||||
@@ -105,14 +136,19 @@ function clean_str($str)
|
||||
<?php if ($show_results) { // there's a search query in q, so show search results
|
||||
?>
|
||||
|
||||
<form action="/" method="get" class="search-form">
|
||||
<form action="/" method="get" onsubmit="return showLoading();" class="search-form">
|
||||
<a href="/">
|
||||
<font size=6 color="#008000">Frog</font>
|
||||
<font size=6 color="#008000">Alpine</font>
|
||||
<font size=6 color="#000000">Find!</font>
|
||||
</a>
|
||||
<div style="margin: 8px 0;">Leap again: <br>
|
||||
<div style="margin: 8px 0;">
|
||||
<p>Leap again:</p>
|
||||
<input type="text" size="30" name="q" value="<?php echo urldecode($query) ?>">
|
||||
<?php if (isset($_GET['p'])) { ?>
|
||||
<input type="hidden" name="p" value="1">
|
||||
<?php } ?>
|
||||
</div>
|
||||
<span id="loading" style="display: none;">Loading...</span>
|
||||
<input type="submit" value="Ribbbit!">
|
||||
</form>
|
||||
<hr>
|
||||
@@ -127,7 +163,7 @@ function clean_str($str)
|
||||
<center>
|
||||
<h1>
|
||||
<font size=7>
|
||||
<font color="#008000">Frog</font>Find!
|
||||
<font color="#008000">Alpine</font>Find!
|
||||
</font>
|
||||
</h1>
|
||||
</center>
|
||||
@@ -136,9 +172,10 @@ function clean_str($str)
|
||||
</center>
|
||||
<br><br>
|
||||
<center>
|
||||
<form action="/" method="get">
|
||||
Leap to: <br>
|
||||
<form action="/" method="get" onsubmit="return showLoading();">
|
||||
<p>Leap to:</p>
|
||||
<input type="text" size="30" name="q"><br>
|
||||
<span id="loading" style="display: none;">Loading...</span>
|
||||
<input type="submit" value="Ribbbit!" style="margin: 10px auto;">
|
||||
</form>
|
||||
</center>
|
||||
@@ -150,9 +187,6 @@ function clean_str($str)
|
||||
</small>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user