summaryrefslogtreecommitdiffstats
path: root/prog/sear.php/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'prog/sear.php/index.php')
-rw-r--r--prog/sear.php/index.php46
1 files changed, 35 insertions, 11 deletions
diff --git a/prog/sear.php/index.php b/prog/sear.php/index.php
index 4324fba..1f90c9c 100644
--- a/prog/sear.php/index.php
+++ b/prog/sear.php/index.php
@@ -93,11 +93,14 @@ function query_google ($s, $image = false, $noredirect = false, $bindstring = fa
$breadcrumbs = $span->nodeValue;
}
$table = $a->parentNode->parentNode->getElementsByTagName("table")[0];
- $description = "nisem uspel izluščiti opisa.";
+ $description = false;
if ($table)
foreach ($table->getElementsByTagName("span") as $span)
if ($span->getAttribute("class") == $descclass)
- $description = $span->nodeValue;
+ if (!$description)
+ $description = $span->nodeValue;
+ if (!$description)
+ $description = "ni mi uspelo izluščiti opisa";
$results[] = ["url" => $hreflink, "title" => $firstspan->nodeValue, "breadcrumbs" => $breadcrumbs, "description" => $description];
}
$suggested = [];
@@ -113,7 +116,7 @@ function query_google ($s, $image = false, $noredirect = false, $bindstring = fa
$suggestion = $suggested[0];
return ["status" => true, "query" => $s, "suggestion" => $suggestion, "results" => $results, "url" => $url];
}
-function template ($title, $queryinfo, $body, $query = "", $additionalform = "", $imgfirst = false) {
+function template ($title, $queryinfo, $body, $query = "", $additionalform = "", $imgfirst = false, $add_footer = "") {
$query = htmlspecialchars($query);
$title = htmlspecialchars($title);
$buttons = "
@@ -151,9 +154,10 @@ function template ($title, $queryinfo, $body, $query = "", $additionalform = "",
$body
<hr>
<h4 align=center>
- <a href=//ni.šijanec.eu/projects/r/tree/prog/sear.php>sear.php</a>
- <a href=javascript:window.external.AddSearchProvider(window.location.origin+'/osdd.xml') id=r hidden=hidden >registriraj v brskalnik</a>
+ <a href=//ni.šijanec.eu./sijanec/r/tree/prog/sear.php>sear.php</a>
+ <a href=javascript:window.external.AddSearchProvider(window.location.origin+'/osdd.xml') id=r hidden=hidden ><!--registriraj v brskalnik--></a>
</h4>
+ $add_footer
<script>
if (typeof window.external.AddSearchProvider === 'function')
document.getElementById('r').hidden = false;
@@ -201,7 +205,19 @@ function results_html ($results, $plaintext, $limit) {
}
return $r;
}
-function handle_response ($query, $response, $limit, $plaintext, $horseshoe, $add_url, $add_form, $image) {
+function samostalnik ($n, $ednina, $dvojina, $trojina, $mno) {
+ switch ($n % 100) {
+ case 1:
+ return $ednina;
+ case 2:
+ return $dvojina;
+ case 3:
+ case 4:
+ return $trojina;
+ }
+ return $mno;
+}
+function handle_response ($query, $response, $limit, $plaintext, $horseshoe, $add_url, $add_form, $image, $add_footer) {
if (sizeof($response["results"]) == 0)
die(template($query, "ni rezultatov", "vaše iskanje ni obrodilo sadov.", $query, "", $image));
if ($horseshoe)
@@ -217,9 +233,9 @@ function handle_response ($query, $response, $limit, $plaintext, $horseshoe, $ad
$safequeryhtml = htmlspecialchars($response["suggestion"]);
$queryinfo .= "predlagam iskanje <a href='?e=e$add_url&q=$safequeryurl'>$safequeryhtml</a> | ";
}
- $queryinfo .= sizeof($response["results"]) . " zadetkov";
+ $queryinfo .= sizeof($response["results"]) . " " . samostalnik(sizeof($response["results"]), "zadetek", "zadetka", "zadetki", "zadetkov");
$resultshtml = results_html($response["results"], $plaintext, $limit);
- die(template($response["query"], $queryinfo, $resultshtml, $response["query"], $add_form, $image));
+ die(template($response["query"], $queryinfo, $resultshtml, $response["query"], $add_form, $image, $add_footer));
}
function try_query_google ($q, $image, $exact) {
$bindstrings = [];
@@ -237,9 +253,13 @@ function try_query_google ($q, $image, $exact) {
}
if (getenv("BINDSTRINGS"))
$bindstrings = explode(",", getenv("BINDSTRINGS"));
- foreach ($bindstrings as $bindstring) {
+ $bindstring_timings = [];
+ foreach ($bindstrings as $bs) {
// file_put_contents("/dev/stderr", "trying bindstring $bindstring\n");
- $response = query_google($q, $image, $exact, $bindstring);
+ $start_ns = hrtime(true);
+ $response = query_google($q, $image, $exact, $bs);
+ $bindstring_timings[$bs] = hrtime(true)-$start_ns;
+ $response["bindstring"] = $bs;
if ($response["status"] == true)
break;
if ($response["code"] == "captcha")
@@ -248,6 +268,8 @@ function try_query_google ($q, $image, $exact) {
continue;
break;
}
+ $response["bindstrings"] = $bindstrings;
+ $response["bindstring_timings"] = $bindstring_timings;
return $response;
}
if (!isset($_REQUEST["debug"]))
@@ -295,6 +317,8 @@ if ($q == null) {
die(template("", "iskalnik sear.php", "dobrodošli v iskalniku sear.php, nasledniku programa sear.c. za iskanje po spletu nekaj vnesite v iskalno vrstico zgoraj in pritisnite na gumb."));
}
$response = try_query_google($q, $image, $exact);
+$ms = $response["bindstring_timings"][$response["bindstring"]]/(1000*1000);
+$add_footer = "<hr>razhroščevanje: <a href='" . htmlspecialchars($response["url"]) . "'>" . $response["bindstring"] . "</a> v $ms ms";
if ($response["status"] != true) {
if ($response["code"] == "captcha") {
foreach (["http://searc.oliwerix.com/sear.php?ref=b"] as $fallback) {
@@ -318,5 +342,5 @@ if ($response["status"] != true) {
http_response_code(500);
die(template("napaka", "napaka pri poizvedbi", "poizvedba na iskalno zaledje je vrnila napako " . $response["code"] . ".", $q));
}
-handle_response($q, $response, $limit, $plaintext, $horseshoe, $add_url, $add_form, $image);
+handle_response($q, $response, $limit, $plaintext, $horseshoe, $add_url, $add_form, $image, $add_footer);
?>