Browse Source

added next pages for video results, improved mobile css

hnhx 3 years ago
parent
commit
63aee96388
9 changed files with 111 additions and 90 deletions
  1. 1 1
      api.php
  2. 1 0
      donate.xhtml
  3. 1 0
      index.xhtml
  4. 0 2
      results/currency.php
  5. 1 1
      results/image.php
  6. 6 4
      results/text.php
  7. 3 3
      results/video.php
  8. 78 66
      search.php
  9. 20 13
      static/styles.css

+ 1 - 1
api.php

@@ -9,5 +9,5 @@
 
     $results = get_google_results($query, $page, $type);
 
-    echo json_encode($results, true);
+    echo json_encode($results, JSON_PRETTY_PRINT);
 ?>

+ 1 - 0
donate.xhtml

@@ -6,6 +6,7 @@
         <meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
         <meta name="description" content="A privacy respecting meta search engine."/>
+        <meta name="referrer" content="no-referrer">
         <link rel="stylesheet" type="text/css" href="static/styles.css"/>
         <link rel="shortcut icon" href="static/librex.png" />
     </head>

+ 1 - 0
index.xhtml

@@ -6,6 +6,7 @@
         <meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
         <meta name="description" content="A privacy respecting meta search engine."/>
+        <meta name="referrer" content="no-referrer">
         <link rel="stylesheet" type="text/css" href="static/styles.css"/>
         <link rel="shortcut icon" href="static/librex.png" />
     </head>

+ 0 - 2
results/currency.php

@@ -1,6 +1,4 @@
 <?php
-
-
     function currency_results($query)
     {
         require "config.php"; 

+ 1 - 1
results/image.php

@@ -33,7 +33,7 @@
             array_push($results, 
                 array (
                     "base64" => $img_base64,
-                    "alt" => $alts[$i]
+                    "alt" => htmlspecialchars($alts[$i])
                 )
             );
         }

+ 6 - 4
results/text.php

@@ -29,10 +29,12 @@
 
             array_push($results, 
                 array (
-                    "title" => $title->textContent,
-                    "url" =>  $url,
-                    "base_url" => get_base_url($url),
-                    "description" => $description == null ? "No description was provided for this site." : $description->textContent
+                    "title" => htmlspecialchars($title->textContent),
+                    "url" =>  htmlspecialchars($url),
+                    "base_url" => htmlspecialchars(get_base_url($url)),
+                    "description" =>  $description == null ? 
+                                      "No description was provided for this site." : 
+                                      htmlspecialchars($description->textContent)
                 )
             );
         }

+ 3 - 3
results/video.php

@@ -27,9 +27,9 @@
             
             array_push($results, 
                 array (
-                    "title" => $title->textContent,
-                    "url" =>  $url,
-                    "base_url" => get_base_url($url)
+                    "title" => htmlspecialchars($title->textContent),
+                    "url" =>  htmlspecialchars($url),
+                    "base_url" => htmlspecialchars(get_base_url($url))
                 )
             );
         }

+ 78 - 66
search.php

@@ -6,6 +6,7 @@
         <meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
         <meta name="description" content="A privacy respecting meta search engine."/>
+        <meta name="referrer" content="no-referrer">
         <link rel="stylesheet" type="text/css" href="static/styles.css"/>
         <link title="LibreX search" type="application/opensearchdescription+xml" href="/opensearch.xml?method=POST" rel="search"/>
         <link rel="shortcut icon" href="static/librex.png" />
@@ -43,31 +44,24 @@
         </form>
 
         <?php
-            function print_next_pages($page, $button_val, $q) 
+
+            require_once "google.php";
+            require_once "config.php";
+            require_once "tools.php";
+
+            function print_next_page_button($page, $button_val, $q, $type) 
             {
                 echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
                 echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
                 echo "<input type=\"hidden\" name=\"q\" value=\"$q\" />";
+                echo "<input type=\"hidden\" name=\"type\" value=\"$type\" />";
                 echo "<button type=\"submit\">$button_val</button>";
                 echo "</form>"; 
             }
 
-            require_once "google.php";
-            require_once "tools.php";
-            require_once "config.php";
-
-            $page = isset($_REQUEST["p"]) ? (int) htmlspecialchars($_REQUEST["p"]) : 0;
-            $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
-
-            $start_time = microtime(true);
-            $results = get_google_results($query, $page, $type);
-            $end_time = number_format(microtime(true) - $start_time, 2, '.', '');
-
-            echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
-            
-
-            if ($type == 0) // text search
+            function print_text_results($results) 
             {
+                global $query;
                 check_for_special_search($query);
                 
                 foreach($results as $result)
@@ -85,68 +79,86 @@
                     echo "<span>$description</span>";
                     echo "</div>";
                 }
-                
-                echo "<div class=\"page-container\">";
+            }
 
-                if ($page != 0) 
-                {
-                    print_next_pages(0, "&lt;&lt;", $query);
-                    print_next_pages($page - 10, "&lt;", $query);
-                }
-                
-                for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
-                {
-                    $page_input = $i * 10;
-                    $page_button = $i + 1;
-                    
-                    print_next_pages($page_input, $page_button, $query);
-                }
+            function print_image_results($results)
+            {
+                echo "<div class=\"image-result-container\">";
 
-                print_next_pages($page + 10, "&gt;", $query);
+                    foreach($results as $result)
+                    {
+                        $src = $result["base64"];
+                        $alt = $result["alt"];
+        
+                        echo "<a title=\"$alt\" href=\"data:image/jpeg;base64,$src\" target=\"_blank\">";
+                        echo "<img src=\"data:image/jpeg;base64,$src\" width=\"350\" height=\"200\">";
+                        echo "</a>";
+                    }
 
-                echo "</div>";
+                    echo "</div>";
             }
-            else if ($type == 1) // image search
+
+            function print_video_results($results)
             {
+                    foreach($results as $result)
+                    {
+                        $title = $result["title"];
+                        $url = $result["url"];
+                        $base_url = $result["base_url"];
+
+                        echo "<div class=\"result-container\">";
+                        echo "<a href=\"$url\">";
+                        echo "$base_url";
+                        echo "<h2>$title</h2>";
+                        echo "</a>";
+                        echo "</div>";
+                    }
+            }
 
-                echo "<div class=\"image-result-container\">";
+            $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
+            $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
 
-                foreach($results as $result)
-                {
-                    $src = $result["base64"];
-                    $alt = $result["alt"];
-    
-                    echo "<a title=\"$alt\" href=\"data:image/jpeg;base64,$src\" target=\"_blank\">";
-                    echo "<img src=\"data:image/jpeg;base64,$src\" width=\"350\" height=\"200\">";
-                    echo "</a>";
-                }
+            $start_time = microtime(true);
+            $results = get_google_results($query, $page, $type);
+            $end_time = number_format(microtime(true) - $start_time, 2, '.', '');
 
-                echo "</div>";
-            }
-            else if ($type == 2) // video search
+            echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
+            
+            switch ($type)
             {
-                echo "<div class=\"results-wrapper\">";
+                case 0:
+                    print_text_results($results);
+                    break;
+                case 1:
+                    print_image_results($results);
+                    break;
+                case 2:
+                    print_video_results($results);
+                    break;
+                default:
+                    print_text_results($results);
+                    break;
+            }
 
-                if ($config_replace_yt_with_invidious != null)
-                {
-                    echo "<p id=\"special-result\">";
-                    echo  "YouTube results got replaced with a privacy friendly Invidious instance.";
-                    echo "</p>";
-                }
+            if ($type != 1 )
+            {
+                echo "<div class=\"page-container\">";
 
-                foreach($results as $result)
-                {
-                    $title = $result["title"];
-                    $url = $result["url"];
-                    $base_url = $result["base_url"];
+                    if ($page != 0) 
+                    {
+                        print_next_page_button(0, "&lt;&lt;", $query, $type); 
+                        print_next_page_button($page - 10, "&lt;", $query, $type);
+                    }
+                    
+                    for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
+                    {
+                        $page_input = $i * 10;
+                        $page_button = $i + 1;
+                        
+                        print_next_page_button($page_input, $page_button, $query, $type);
+                    }
 
-                    echo "<div class=\"result-container\">";
-                    echo "<a href=\"$url\">";
-                    echo "$base_url";
-                    echo "<h2>$title</h2>";
-                    echo "</a>";
-                    echo "</div>";
-                }
+                    print_next_page_button($page + 10, "&gt;", $query, $type);
 
                 echo "</div>";
             }

+ 20 - 13
static/styles.css

@@ -14,7 +14,11 @@ hr {
 
 img { 
     border: 1px solid #5f6368;
-} 
+}
+
+button {
+    outline: none;
+}
 
 /* .search-container START */
 
@@ -198,10 +202,6 @@ img {
         text-decoration: underline; 
     }
 
-    .results-wrapper {
-        height: 105vh;
-    }
-
 /* .result-container END */
 
 
@@ -224,7 +224,7 @@ img {
     .page-container {
         margin-top:50px;
         margin-bottom:100px;
-        margin-left:15%;
+        margin-left:10%;
     }
 
     .page-container #page { 
@@ -263,6 +263,7 @@ img {
         display: inline;
 
         border:none;
+        
 
         margin-right: 20px;
 
@@ -379,15 +380,17 @@ img {
 
 
     @media only screen and (max-width:900px) {
-        .info-container {
+        .info-container 
+        {
             display: flex;
             flex-wrap: wrap;
-
-            justify-content: space-between;
+            
+            flex-direction: column;
         }
 
-        .info-container a {
-            margin-top: 10px;
+        .info-container a
+        {
+            margin-top:5px;
         }
 
         .small-search-container input {
@@ -424,11 +427,15 @@ img {
         }
 
         #special-result {
-            width: 80%;
+            width: 70%;
         } 
 
         .result-container {
-            width: 80%;
+            width: 70%;
+        }
+
+        #time {
+            margin-top: 30px;
         }
     }