commit 71bb20fa0ccef5e7bcfdbf3255720dfeea72119f
parent e75bb5d2ecc7381112b7d5b190bd97199834e1da
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Tue, 9 Jul 2024 19:30:49 +0200
feat: decreasing process tasks; code cleanup
Diffstat:
M | index.php | | | 208 | ++++++++++++++++++++++++++++++++++++++++++++----------------------------------- |
1 file changed, 117 insertions(+), 91 deletions(-)
diff --git a/index.php b/index.php
@@ -4,67 +4,66 @@
<!-- Process input (if given) -->
<?php
-/* Load Configuration */
-include("config/config.php");
-
-/* Fetch and sanitize search query via GET request */
-$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
-if (!is_null($_GET["query"])) {
- $query = rawurldecode($_GET["query"]);
-} else if (!is_null($_GET["q"])) {
- $query = rawurldecode($_GET["q"]);
-} else {
- $query = null;
-}
-
-if (strlen($query) > 0) {
-
- /* Find keywords (only first one is considered) */
- $keyword = preg_replace(
- '/^.*?\!([A-Za-z0-9_\-\.]+).*$/',
- '${1}',
- $query
- );
- $keyword = strtolower($keyword);
-
- /* Based on given keyword, choose a search engine */
- $search = $default_search;
- foreach (array_keys($searches) as $key) {
- if (array_search($keyword, $searches[$key]["keywords"]) !== false) {
- /* If keyword has been found, assign search engine and end the loop */
- $search = $key;
- break;
- }
+ /* Load Configuration */
+ include("config/config.php");
+
+ /* Fetch and sanitize search query via GET request */
+ $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
+ if (!is_null($_GET["query"])) {
+ $query = rawurldecode($_GET["query"]);
+ } else if (!is_null($_GET["q"])) {
+ $query = rawurldecode($_GET["q"]);
+ } else {
+ $query = null;
}
- /* Strip keyword from search term */
- $search_term = preg_replace(
- '/\![A-Za-z0-9_\-\.]+/',
- '',
- $query
- );
-
- /* Remove preceding and trailing spaces */
- $search_term = preg_replace(
- '/^\s+|\s+$/',
- '',
- $search_term
- );
-
- /* Construct search query */
- $target = str_replace(
- '%s',
- rawurlencode($search_term),
- $searches[$search]["query"]
- );
-
- /* Redirect to target search engine: 307 - Temporary Redirect */
- header("Location: " . $target, true, 307);
- die();
-}
+ if (strlen($query) > 0) {
+
+ /* Find keywords (only first one is considered) */
+ $keyword = preg_replace(
+ '/^.*?\!([A-Za-z0-9_\-\.]+).*$/',
+ '${1}',
+ $query
+ );
+ $keyword = strtolower($keyword);
+
+ /* Based on given keyword, choose a search engine */
+ $search = $default_search;
+ foreach (array_keys($searches) as $key) {
+ if (array_search($keyword, $searches[$key]["keywords"]) !== false) {
+ /* If keyword has been found, assign search engine & end loop */
+ $search = $key;
+ break;
+ }
+ }
-?>
+ /* Strip keyword from search term */
+ $search_term = preg_replace(
+ '/\![A-Za-z0-9_\-\.]+/',
+ '',
+ $query
+ );
+
+ /* Remove preceding and trailing spaces */
+ $search_term = preg_replace(
+ '/^\s+|\s+$/',
+ '',
+ $search_term
+ );
+
+ /* Construct search query */
+ $target = str_replace(
+ '%s',
+ rawurlencode($search_term),
+ $searches[$search]["query"]
+ );
+
+ /* Redirect to target search engine: 307 - Temporary Redirect */
+ header("Location: " . $target, true, 307);
+ die();
+ }
+?>
<!-- Head -->
<head>
@@ -74,8 +73,13 @@ if (strlen($query) > 0) {
<link rel=icon href=/assets/img/favicon.ico type=x-image/ico>
<link rel=stylesheet href=/assets/css/simple.min.css media=all>
<link rel=stylesheet href=/assets/css/custom.css>
- <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="serĉi - search with !keywords">
<link rel="manifest" href="manifest.json">
+ <link
+ rel="search"
+ type="application/opensearchdescription+xml"
+ href="/opensearch.xml"
+ title="serĉi - search with !keywords"
+ >
<title>serĉi - search with !keywords</title>
</head>
@@ -105,50 +109,72 @@ if (strlen($query) > 0) {
<!-- FAQs -->
<h3>FAQs</h3>
<ul>
- <li><a href="https://src.jayvii.de/pub/serci/#what-does-serĉi-mean" target="_blank">
- What does <em>serĉi</em> mean?
- </a></li>
- <li><a href="https://src.jayvii.de/pub/serci/#what-are-keywords" target="_blank">
- What are keywords?
- </a></li>
- <li><a href="https://src.jayvii.de/pub/serci/#how-can-i-use-serĉi" target="_blank">
- How to use serĉi?
- </a></li>
- <li><a href="https://src.jayvii.de/pub/serci/" target="_blank">
- Help with development!
- </a></li>
+ <li>
+ <a href="https://src.jayvii.de/pub/serci/#what-does-serĉi-mean"
+ target="_blank">What does <em>serĉi</em> mean?</a>
+ </li>
+ <li>
+ <a href="https://src.jayvii.de/pub/serci/#what-are-keywords"
+ target="_blank">What are keywords?</a>
+ </li>
+ <li>
+ <a href="https://src.jayvii.de/pub/serci/#how-can-i-use-serĉi"
+ target="_blank">How to use serĉi?</a>
+ </li>
+ <li>
+ <a href="https://src.jayvii.de/pub/serci/"
+ target="_blank">Help with development!</a>
+ </li>
</ul>
<!-- Search Engine Table -->
<h3>Search Engines</h3>
+ <span>
+ Default Search:
+ <a href="<?php echo $searches[$default_search]["website"]; ?>"
+ target="_blank">
+ <?php
+ echo $searches[$default_search]["name"];
+ ?>
+ </a>
+ </span>
<table>
<tr>
<th>Engine</th>
<th>keywords</th>
<tr>
-<?php
+ <?php
+ /* Print one table row for each configured search engine */
+ foreach (array_keys($searches) as $key) {
+ ?>
-/* Print one table row for each configured search engine */
-$engine_table = "";
-foreach (array_keys($searches) as $key) {
- $engine_table .= "<tr><td>" .
- "<a href=\"" . $searches[$key]["website"] . "\" " .
- "target=\"_blank\">" .
- $searches[$key]["name"];
-
- if ($key == $default_search) {
- $engine_table .= " (default)";
- }
-
- $engine_table .= "</a>" .
- "</td><td>" .
- "<code>!" . implode("</code>, <code>!", $searches[$key]["keywords"]) .
- "</code>" .
- "</td></tr>";
-}
-echo $engine_table;
-?>
+ <tr>
+ <td>
+ <a href="<?php echo $searches[$key]["website"]; ?>"
+ target="_blank">
+ <?php
+ echo $searches[$key]["website"];
+ ?>
+ </a>
+ </td>
+ <td>
+ <code>
+ <?php
+ echo "!" .
+ implode(
+ "</code>, <code>!",
+ $searches[$key]["keywords"]
+ );
+ ?>
+ </code>
+ </td>
+ </tr>
+
+ <?php
+ /* End for-loop across search engines */
+ }
+ ?>
</table>
</body>