Browse Source

improved mobile css, privacy friendly frontends are now only managed by the user

hnhx 3 years ago
parent
commit
0405992309
8 changed files with 137 additions and 152 deletions
  1. 3 23
      config.php
  2. 8 6
      donate.php
  3. 15 14
      engines/google/text.php
  4. 8 7
      engines/google/video.php
  5. 2 1
      misc/footer.php
  6. 15 17
      misc/tools.php
  7. 45 36
      settings.php
  8. 41 48
      static/css/styles.css

+ 3 - 23
config.php

@@ -1,6 +1,6 @@
 <?php
     return (object) array(
-    
+
         // e.g.: fr -> https://google.fr/
         "google_domain" => "com",
 
@@ -10,22 +10,6 @@
         "disable_bittorent_search" => false,
         "bittorent_trackers" => "&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
 
-        /*
-            These are privacy friendly front-ends for popular sites, these settings can be managed by end users as well for their session via cookies.
-
-            Online invidious instances: https://docs.invidious.io/Invidious-Instances/
-            Online bibliogram instances: https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md
-            Online nitter instances: https://github.com/zedeus/nitter/wiki/Instances
-            Online libreddit instances: https://github.com/spikecodes/libreddit
-            
-            If you don't want to replace YouTube for an example:
-            $replace_youtube_with_invidious = isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"]  : null;
-        */
-        "replace_youtube_with_invidious" => isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"]  : "https://yewtu.be",
-        "replace_instagram_with_bibliogram" => isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"]  : "https://bibliogram.pussthecat.org",
-        "replace_twitter_with_nitter" => isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"]  : "https://nitter.namazso.eu",
-        "replace_reddit_with_libreddit" => isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"]  : "https://libreddit.dothq.co",
-
         /*
             To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE:
 
@@ -37,10 +21,6 @@
                 CURLPROXY_SOCKS5
                 CURLPROXY_SOCKS5_HOSTNAME
 
-            As an example, for a TOR connection you would use these settings:
-            CURLOPT_PROXY => "127.0.0.1:9050",
-            CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
-
             !!! ONLY CHANGE THE OTHER OPTIONS IF YOU KNOW WHAT YOU ARE DOING !!!
         */
         "curl_settings" => array(
@@ -57,6 +37,6 @@
             CURLOPT_VERBOSE => false,
             CURLOPT_TCP_FASTOPEN => true
         )
-        
+
     );
-?>
+?>

+ 8 - 6
donate.php

@@ -3,12 +3,14 @@
     <title>LibreX - Donate</title>
     </head>
     <body>
-        <div class="donate-container">
-               <p>Support the host</p>
-               <span>(Your donation thingy goes here...)</span>
-               <p>Support the creator</p>
-               <span>Monero (XMR):  <br/><br/>41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC</span>
+        <div class="misc-container">
+              <h1>Donate</h1>
+               <h2>Support the host of this instance</h2>
+               <p>(Your donation thingy goes here...)</p>
+               <h2>Support the creator</h2>
+               <h3>Monero (XMR):</h3>
+               <p>41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC</p>
                <img src="static/images/xmr.png" alt="xmr qr code"/>
         </div>
 
-<?php require "misc/footer.php"; ?>
+<?php require "misc/footer.php"; ?>

+ 15 - 14
engines/google/text.php

@@ -6,8 +6,8 @@
 
          if (strpos($query_lower, "to") && count($split_query) >= 4) // currency
          {
-            $amount_to_convert = floatval($split_query[0]);   
-            if ($amount_to_convert != 0) 
+            $amount_to_convert = floatval($split_query[0]);
+            if ($amount_to_convert != 0)
                 return 1;
          }
          else if (strpos($query_lower, "mean") && count($split_query) >= 2) // definition
@@ -18,7 +18,7 @@
         return 0;
      }
 
-    function get_text_results($query, $page=0) 
+    function get_text_results($query, $page=0)
     {
         global $config;
 
@@ -26,12 +26,12 @@
         $query_lower = strtolower($query);
         $query_encoded = urlencode($query);
         $results = array();
-        
+
         $url = "https://www.google.$config->google_domain/search?&q=$query_encoded&start=$page&hl=$config->google_language";
         $google_ch = curl_init($url);
         curl_setopt_array($google_ch, $config->curl_settings);
         curl_multi_add_handle($mh, $google_ch);
- 
+
 
         $special_search = $page == 0 ? check_for_special_search($query) : 0;
         $special_ch = null;
@@ -64,7 +64,7 @@
         do {
             curl_multi_exec($mh, $running);
         } while ($running);
-       
+
         if ($special_search != 0)
         {
             $special_result = null;
@@ -104,21 +104,22 @@
                     if (end($results)["url"] == $url->textContent)
                         continue;
             }
-               
+
 
             $url = $url->textContent;
-            $url = check_for_privacy_friendly_alternative($url);
-            
+            if (substr_count($_SERVER["HTTP_COOKIE"], " ") >= 1)
+              $url = check_for_privacy_friendly_alternative($url);
+
             $title = $xpath->evaluate(".//h3", $result)[0];
             $description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];
 
-            array_push($results, 
+            array_push($results,
                 array (
                     "title" => htmlspecialchars($title->textContent),
                     "url" =>  htmlspecialchars($url),
                     "base_url" => htmlspecialchars(get_base_url($url)),
-                    "description" =>  $description == null ? 
-                                      "No description was provided for this site." : 
+                    "description" =>  $description == null ?
+                                      "No description was provided for this site." :
                                       htmlspecialchars($description->textContent)
                 )
             );
@@ -127,7 +128,7 @@
         return $results;
     }
 
-    function print_text_results($results) 
+    function print_text_results($results)
     {
         echo "<div class=\"text-result-container\">";
 
@@ -163,4 +164,4 @@
 
         echo "</div>";
     }
-?>
+?>

+ 8 - 7
engines/google/video.php

@@ -2,7 +2,7 @@
     function get_video_results($query, $page=0)
     {
         global $config;
-        
+
         $url = "https://www.google.$config->google_domain/search?&q=$query&start=$page&hl=$config->google_language&tbm=vid";
         $response = request($url);
         $xpath = get_xpath($response);
@@ -15,17 +15,18 @@
 
             if ($url == null)
                 continue;
-            
+
             if (!empty($results)) // filter duplicate results
                 if (end($results)["url"] == $url->textContent)
                     continue;
 
             $url = $url->textContent;
-            $url = check_for_privacy_friendly_alternative($url);
-            
+            if (substr_count($_SERVER["HTTP_COOKIE"], " ") >= 1)
+              $url = check_for_privacy_friendly_alternative($url);
+
             $title = $xpath->evaluate(".//h3", $result)[0];
-            
-            array_push($results, 
+
+            array_push($results,
                 array (
                     "title" => htmlspecialchars($title->textContent),
                     "url" =>  htmlspecialchars($url),
@@ -57,4 +58,4 @@
 
         echo "</div>";
     }
-?>
+?>

+ 2 - 1
misc/footer.php

@@ -2,8 +2,9 @@
     <a href="/">LibreX</a>
     <a href="https://github.com/hnhx/librex/" target="_blank">Source &amp; Instance list</a>
     <a href="/settings.php">Settings</a>
+      <a href="https://based-or-botnet.neocities.org/" target="_blank">Privacy guides</a>
     <a href="/api.php" target="_blank">API</a>
     <a href="/donate.php">Donate ❤️</a>
 </div>
 </body>
-</html>
+</html>

+ 15 - 17
misc/tools.php

@@ -8,21 +8,19 @@
 
     function check_for_privacy_friendly_alternative($url)
     {
-        global $config;
-
-        if ($config->replace_youtube_with_invidious != null && strpos($url, "youtube.com"))
-            $url = $config->replace_youtube_with_invidious . explode("youtube.com", $url)[1];
-        else if ($config->replace_instagram_with_bibliogram != null && strpos($url, "instagram.com"))
+        if (isset($_COOKIE["invidious"]) && strpos($url, "youtube.com"))
+            $url = $_COOKIE["invidious"] . explode("youtube.com", $url)[1];
+        else if (isset($_COOKIE["bibliogram"]) && strpos($url, "instagram.com"))
         {
             if (!strpos($url, "/p/"))
-                $config->replace_instagram_with_bibliogram .= "/u";
+                $_COOKIE["bibliogram"] .= "/u";
 
-            $url = $config->replace_instagram_with_bibliogram . explode("instagram.com", $url)[1];
+            $url = $_COOKIE["bibliogram"] . explode("instagram.com", $url)[1];
         }
-        else if ($config->replace_twitter_with_nitter != null && strpos($url, "twitter.com"))
-            $url = $config->replace_twitter_with_nitter . explode("twitter.com", $url)[1];
-        else if ($config->replace_reddit_with_libreddit != null && strpos($url, "reddit.com"))
-            $url = $config->replace_reddit_with_libreddit . explode("reddit.com", $url)[1];
+        else if (isset($_COOKIE["nitter"]) && strpos($url, "twitter.com"))
+            $url = $_COOKIE["nitter"] . explode("twitter.com", $url)[1];
+        else if (isset($_COOKIE["libreddit"]) && strpos($url, "reddit.com"))
+            $url = $_COOKIE["libreddit"] . explode("reddit.com", $url)[1];
 
         return $url;
     }
@@ -47,7 +45,7 @@
         return $response;
     }
 
-    function human_filesize($bytes, $dec = 2) 
+    function human_filesize($bytes, $dec = 2)
     {
         $size   = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
         $factor = floor((strlen($bytes) - 1) / 3);
@@ -55,10 +53,10 @@
         return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
     }
 
-    function remove_special($string) 
+    function remove_special($string)
     {
         $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
-     
+
         return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
      }
 
@@ -68,13 +66,13 @@
             echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
         }
 
-    function print_next_page_button($text, $page, $query, $type) 
+    function print_next_page_button($text, $page, $query, $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=\"$query\" />";
         echo "<input type=\"hidden\" name=\"type\" value=\"$type\" />";
         echo "<button type=\"submit\">$text</button>";
-        echo "</form>"; 
+        echo "</form>";
     }
-?>
+?>

+ 45 - 36
settings.php

@@ -3,13 +3,14 @@
     <title>LibreX - Settings</title>
     </head>
     <body>
-        <div class="settings-container">
+        <div class="misc-container">
             <h1>Settings</h1>
             <form method="post" enctype="multipart/form-data" autocomplete="off">
+              <div>
                 <label for="theme">Theme:</label>
                 <select name="theme">
                 <?php
-                    
+
                     $themes = "<option value=\"dark\">Dark</option>
                     <option value=\"light\">Light</option>
                     <option value=\"auto\">Auto</option>
@@ -18,7 +19,7 @@
                     <option value=\"discord\">Discord</option>";
 
                     if (isset($_COOKIE["theme"]))
-                    {                  
+                    {
                         $cookie_theme = $_COOKIE["theme"];
                         $themes = str_replace($cookie_theme . "\"", $cookie_theme . "\" selected", $themes);
                     }
@@ -26,36 +27,43 @@
                     echo $themes;
                 ?>
                 </select>
-                <br><br>
+              </div>
                 <h2>Privacy friendly frontends</h2>
-                <p>Replace popular sites with privacy friendly frontends</p>
+                <p>For an example if you want to view YouTube without getting spied on, click on "Invidious", find the instance that is most suitable for you then paste it in (correct format: https://url.domain)</p>
                 <div class="instances-container">
-                    <a for="invidious" href="https://docs.invidious.io/Invidious-Instances/" target="_blank">Invidious</a>
-                    <input type="text" name="invidious" placeholder="e.g.: https://yewtu.be" value=
-                        <?php echo isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"]  : "\"\""; ?>
-                    >
-
-                    <br><br>
-                    <a for="bibliogram" href="https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md" target="_blank">Bibliogram</a>
-                    <input type="text" name="bibliogram"  value=
-                        <?php echo isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"]  : "\"\""; ?>
-                    >
-
-                    <br><br>
-                    <a for="nitter" href="https://github.com/zedeus/nitter/wiki/Instances" target="_blank">Nitter</a>
-                    <input type="text" name="nitter" value=
-                        <?php echo isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"]  : "\"\""; ?>
-                    >
-
-                    <br><br>
-                    <a for="libreddit" href=" https://github.com/spikecodes/libreddit" target="_blank">Libreddit</a>
-                    <input type="text" name="libreddit" value=
-                        <?php echo isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"]  : "\"\""; ?>
-                    >
+
+                      <div>
+                        <a for="invidious" href="https://docs.invidious.io/Invidious-Instances/" target="_blank">Invidious</a>
+                        <input type="text" name="invidious" placeholder="Replace YouTube" value=
+                            <?php echo isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"]  : "\"\""; ?>
+                        >
+                      </div>
+
+                      <div>
+                        <a for="bibliogram" href="https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md" target="_blank">Bibliogram</a>
+                        <input type="text" name="bibliogram" placeholder="Replace Instagram" value=
+                            <?php echo isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"]  : "\"\""; ?>
+                        >
+                      </div>
+
+                      <div>
+                        <a for="nitter" href="https://github.com/zedeus/nitter/wiki/Instances" target="_blank">Nitter</a>
+                        <input type="text" name="nitter" placeholder="Replace Twitter" value=
+                            <?php echo isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"]  : "\"\""; ?>
+                        >
+                      </div>
+
+                      <div>
+                        <a for="libreddit" href="https://github.com/spikecodes/libreddit" target="_blank">Libreddit</a>
+                        <input type="text" name="libreddit" placeholder="Replace Reddit" value=
+                            <?php echo isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"]  : "\"\""; ?>
+                        >
+                      </div>
+                </div>
+                <div>
+                  <button type="submit" name="save" value="1">Save</button>
+                  <button type="submit" name="reset" value="1">Reset</button>
                 </div>
-                <br>
-                <button type="submit" name="save" value="1">Save</button>
-                <button type="submit" name="reset" value="1">Reset</button>
             </form>
 
 
@@ -74,6 +82,7 @@
                     if (!empty($_REQUEST["libreddit"]))
                         setcookie("libreddit", $_REQUEST["libreddit"]);
 
+
                     setcookie("theme", $_REQUEST["theme"]);
 
                     header("Location: /settings.php");
@@ -81,13 +90,13 @@
                 }
                 else if (isset($_REQUEST["reset"]))
                 {
-                    if (isset($_SERVER['HTTP_COOKIE'])) {
-                        $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
+                    if (isset($_SERVER["HTTP_COOKIE"])) {
+                        $cookies = explode(";", $_SERVER["HTTP_COOKIE"]);
                         foreach($cookies as $cookie) {
-                            $parts = explode('=', $cookie);
+                            $parts = explode("=", $cookie);
                             $name = trim($parts[0]);
-                            setcookie($name, '', time()-1000);
-                            setcookie($name, '', time()-1000, '/');
+                            setcookie($name, "", time()-1000);
+                            setcookie($name, "", time()-1000, "/");
                         }
 
                         header("Location: /settings.php");
@@ -97,4 +106,4 @@
             ?>
         </div>
 
-<?php require "misc/footer.php"; ?>
+<?php require "misc/footer.php"; ?>

+ 41 - 48
static/css/styles.css

@@ -1,11 +1,11 @@
 html {
     color: var(--main-fg);
-    background-color: var(--main-bg); 
+    background-color: var(--main-bg);
     font-family: Arial, Helvetica, sans-serif;
     font-size: 16px;
 }
 
-input, 
+input,
 button {
     outline: none;
 }
@@ -24,6 +24,10 @@ a,
     text-decoration: none;
 }
 
+.text-result-wrapper a:visited h2 {
+  color: var(--alt-fg);
+}
+
 a:hover, .text-result-wrapper h2:hover {
     text-decoration: underline;
 }
@@ -41,7 +45,7 @@ a:hover, .text-result-wrapper h2:hover {
 .sub-search-container input {
     width: 500px;
     color: inherit;
-    background-color: inherit;  
+    background-color: inherit;
     padding: 10px;
     font-size: inherit;
     font-family: inherit;
@@ -49,9 +53,9 @@ a:hover, .text-result-wrapper h2:hover {
     border-radius: 25px;
 }
 
-.search-button-wrapper button, 
-.settings-container button, 
-.settings-container select {
+.search-button-wrapper button,
+.misc-container button,
+.misc-container select {
     color: inherit;
     background-color: var(--button-bg);
     font-size: 14px;
@@ -61,7 +65,7 @@ a:hover, .text-result-wrapper h2:hover {
 }
 
 .search-button-wrapper button {
-   
+
     margin: 30px 60px 0px 60px;
 }
 
@@ -89,7 +93,7 @@ a:hover, .text-result-wrapper h2:hover {
 }
 
 .search-button-wrapper button:hover,
-.settings-container button:hover { 
+.misc-container button:hover {
     border: 1px solid #5f6368;
     cursor: pointer;
 }
@@ -107,29 +111,42 @@ a:hover, .text-result-wrapper h2:hover {
     margin-right: 25px;
 }
 
-.settings-container {
+.misc-container {
     text-align: center;
     word-wrap: break-word;
+    width: 450px;
+    margin-left: auto;
+    margin-right: auto;
+}
+
+.misc-container div {
+    margin-bottom: 30px;
 }
 
-.settings-container button {
+.misc-container button {
     margin-right:10px;
     margin-left:10px;
 }
 
-.settings-container a {
+.misc-container a {
     color:inherit;
     text-decoration: underline;
 }
 
+.instances-container div {
+  text-align: left;
+  margin-bottom: 25px;
+}
+
 .instances-container input {
     color: inherit;
-    background-color: inherit;  
+    background-color: inherit;
     padding: 5px;
     font-size: inherit;
     font-family: inherit;
     border: 1px solid #5f6368;
     border-radius: 5px;
+    float: right;
 }
 
 .text-result-container,
@@ -183,7 +200,8 @@ a:hover, .text-result-wrapper h2:hover {
     border:none;
     background-color: inherit;
     color: var(--result-link-fg);
-    font-size: 18px;
+    font-size: 20px;
+    margin-right: 6px;
 }
 
 .next-page-button-wrapper #page {
@@ -208,25 +226,6 @@ a:hover, .text-result-wrapper h2:hover {
     margin: 10px;
 }
 
-.donate-container {
-    text-align: center;
-    word-wrap: break-word;
-    margin-left: auto;
-    margin-right: auto;
-    margin-top: 8%;
-    border: 1px solid var(--main-fg);
-    max-width: 500px;
-    padding:0px 20px 20px 20px;
-}
-
-.donate-container img {
-    margin-top:10px;
-}
-
-.donate-container a {
-    color: var(--alt-fg);
-}
-
 .footer-container {
     position: fixed;
     left: 0;
@@ -246,7 +245,7 @@ a:hover, .text-result-wrapper h2:hover {
 }
 
 /* mobile view */
-@media only screen and (max-width: 900px) { 
+@media only screen and (max-width: 900px) {
     .search-container input {
         width: 80%;
     }
@@ -271,7 +270,7 @@ a:hover, .text-result-wrapper h2:hover {
         margin-left:auto;
         margin-right:auto;
         display: block;
-        
+
     }
 
     .sub-search-container input {
@@ -283,7 +282,7 @@ a:hover, .text-result-wrapper h2:hover {
         margin:0;
         padding:0;
         display: flex;
-        
+        align-items: baseline;
     }
 
     .sub-search-button-wrapper img {
@@ -296,27 +295,21 @@ a:hover, .text-result-wrapper h2:hover {
         margin-left:auto;
         margin-right:auto;
         padding:0;
-       
         display: flex;
         flex-direction: column;
         align-items: center;
-    } 
-
-    .special-result-container {
-        max-width: 80%;
     }
 
-    .donate-container {
+    .special-result-container {
         max-width: 80%;
     }
 
-    .donate-container img {
-        display: block;
-        margin-left:auto;
-        margin-right:auto;
+    .misc-container {
+        margin-bottom: 200px;
+        width: 95%;
     }
 
-    .settings-container {
-        margin-bottom: 100px;
+    .search-container h1 {
+      font-size: 55px;
     }
-}
+}