commit 1a91e6a06afbdd6612b694034e287e51049e042d Author: hnhx Date: Thu Feb 17 21:14:56 2022 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..fd0dd16 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# librex diff --git a/api.php b/api.php new file mode 100644 index 0000000..8d8428f --- /dev/null +++ b/api.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/config.php b/config.php new file mode 100755 index 0000000..494b8a7 --- /dev/null +++ b/config.php @@ -0,0 +1,10 @@ + https://google.fr/ + $config_google_domain = "com"; + + // Results will be in this language + $config_google_language = "en"; +?> \ No newline at end of file diff --git a/donate.xhtml b/donate.xhtml new file mode 100644 index 0000000..0dcbb1b --- /dev/null +++ b/donate.xhtml @@ -0,0 +1,26 @@ + + + + + LibreX - Donate + + + + + + + + +
+ LibreX + Source code & Other instances + Donate ❤️ +
+ + \ No newline at end of file diff --git a/fetch.php b/fetch.php new file mode 100644 index 0000000..3a64cb2 --- /dev/null +++ b/fetch.php @@ -0,0 +1,98 @@ + true, + // CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME, + // CURLOPT_PROXY => "127.0.0.1:9150", + CURLOPT_HEADER => false, + CURLOPT_FOLLOWLOCATION => false, + CURLOPT_ENCODING => "", + CURLOPT_USERAGENT => $config_user_agent, + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_VERBOSE => 1, + ]); + + $response = curl_exec($ch); + + $htmlDom = new DOMDocument; + @$htmlDom->loadHTML($response); + $xpath = new DOMXPath($htmlDom); + + $results = array(); + + if ($get_images) + { + + $mh = curl_multi_init(); + $chs = array(); + + foreach($xpath->query(".//following::img") as $image) + { + $alt = $image->getAttribute("alt"); + $src = $image->getAttribute("data-src"); + + if (!empty($src) && !empty($alt)) + { + $ch = curl_init($src); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + array_push($chs, $ch); + curl_multi_add_handle($mh, $ch); + } + } + + $running = null; + do { + curl_multi_exec($mh, $running); + } while ($running); + + foreach($chs as $ch) + { + $img_base64 = base64_encode(curl_multi_getcontent($ch)); + array_push($results, + array ( + "base64" => $img_base64, + "alt" => $alt + ) + ); + } + + } + else + { + foreach($xpath->query("//div[contains(@class, 'yuRUbf')]") as $div) + { + $title = $div->getElementsByTagName("h3")[0]->textContent; + $url = $div->getElementsByTagName("a")[0]->getAttribute("href"); + $base_url = get_base_url($url); + + array_push($results, + array ( + "title" => $title, + "url" => $url, + "base_url" => $base_url + ) + ); + } + } + + return $results; + } +?> \ No newline at end of file diff --git a/index.xhtml b/index.xhtml new file mode 100644 index 0000000..acd82c8 --- /dev/null +++ b/index.xhtml @@ -0,0 +1,27 @@ + + + + + LibreX + + + + + + +
+

LibreX

+ + +
+ + +
+ +
+ LibreX + Source code & Other instances + Donate ❤️ +
+ + \ No newline at end of file diff --git a/opensearch.xml b/opensearch.xml new file mode 100644 index 0000000..164d08d --- /dev/null +++ b/opensearch.xml @@ -0,0 +1,14 @@ + + + LibreX + A meta search engine for Google. + UTF-8 + LibreX search + + + + + + \ No newline at end of file diff --git a/search.php b/search.php new file mode 100644 index 0000000..e789b8d --- /dev/null +++ b/search.php @@ -0,0 +1,66 @@ + + + + + <?php echo $_REQUEST["q"]; ?> - LibreX + + + + + + + +
+

LibreX

+ + strlen($_REQUEST["q"]) || strlen($_REQUEST["q"]) > 256) + $valid_query = false; + + if ($valid_query) + { + $query = $_REQUEST["q"]; + echo "value=\"$query\""; + + $_SESSION["q"] = $query; + $_SESSION["p"] = $_REQUEST["p"]; + $_SESSION["type"] = $_REQUEST["type"]; + } + else + { + header("Location: /"); + die(); + } + ?> + > +
+ "; + ?> + +
+ + +
+ +
+
+ + + +
+ LibreX + Source code & Other instances + Donate ❤️ +
+ + \ No newline at end of file diff --git a/search_frame.php b/search_frame.php new file mode 100644 index 0000000..22d5aea --- /dev/null +++ b/search_frame.php @@ -0,0 +1,83 @@ + + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + } + + session_start(); + + require("fetch.php"); + + $query = $_SESSION["q"]; + $page = (int) htmlspecialchars($_SESSION["p"]); + $search_type = $_SESSION["type"] == "img" ? true : false; + + $start_time = microtime(true); + $results = fetch_results($query, $page, $search_type); + $end_time = number_format(microtime(true) - $start_time, 2, '.', ''); + + echo "

Fetched the results in $end_time seconds

"; + + if ($_SESSION["type"] != "img") + { + + foreach($results as $result) + { + $title = $result["title"]; + $url = $result["url"]; + $base_url = $result["base_url"]; + + echo "
"; + echo ""; + echo "$base_url"; + echo "

$title

"; + echo "
"; + echo "
"; + } + + echo "
"; + + if ($page != 0) + { + print_next_pages(0, "<<", $query); + print_next_pages($page - 10, "<", $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); + } + + print_next_pages($page + 10, ">", $query); + + echo "
"; + } + else + { + foreach($results as $result) + { + $src = $result["base64"]; + $alt = $result["alt"]; + echo ""; + } + } + + require "session_destroy.php"; + ?> + + \ No newline at end of file diff --git a/session_destroy.php b/session_destroy.php new file mode 100644 index 0000000..355c409 --- /dev/null +++ b/session_destroy.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..ccdd354 --- /dev/null +++ b/static/styles.css @@ -0,0 +1,172 @@ +html { + color: #e8eaed; + font-family: Arial, Helvetica, sans-serif; + font-size: 18px; +} + +body { + background-color: #202124; + margin: 0; + padding: 0; +} + +hr { margin:30px 0px 30px 0px; } + +iframe { + width: 100%; + height: 100vh; +} + +img { padding:15px; } + +.search-container { + text-align: center; + margin-top:13%; +} + +.search-container input , .small-search-container input { + padding:10px; + font-size: 16px; + border:1px solid #5f6368; + border-radius: 25px; + color: inherit; + background-color: inherit; +} + +.search-container input { width: 520px; } + +.small-search-container input { + width: 600px; + margin-left:-10px; +} + +.search-container input:hover, .small-search-container input:hover { + background-color: #303134; + border-color: #303134; +} + +.search-container input:focus , .small-search-container input:focus { outline: none; } + +.search-container h1 { font-size:70px; } + +.search-container button { + background-color: #303134; + border:none; + border-radius: 4px; + color:inherit; + padding:13px 10px 13px 10px; + margin-top:30px; + font-size: 14px; + margin-left:20px; +} + +.search-container button:hover { + border: 1px solid #5f6368; + cursor:pointer; +} + +.info-container { + position: fixed; + bottom: 0; + width: 100%; + background-color:#171717; + font-size:15px; + padding-top: 15px; + padding-bottom: 15px; + border-top:1px solid #303134; +} + +.info-container a , p { + color:#999da2; + text-decoration: none; +} + +.info-container a { + padding-left: 25px; + font-size:16px; +} + +.info-container #right { float:right; } + +.info-container a:hover { text-decoration: underline; } + +.small-search-container h1, a { + display: inline; + margin-right:40px; + color:inherit; + text-decoration: none; +} + +.small-search-container { margin:2%; } + +.result-container, #time { + margin-left:10%; +} + +.result-container a { + font-size: 14px; + color:#bdc1c6; + text-decoration: none; +} + +.result-container h2 { + font-size: 20px; + color:#8ab4f8; + padding-top:5px; + margin-top:1px; +} + +.result-container h2:hover { text-decoration: underline; } + +.result-container { + margin-top:6px; +} + +.page-container { + margin-bottom:70px; + margin-left:15%; +} + +.page-container #page { display: inline; } + +.page-container #page button { + padding-right: 10px; + background-color: inherit; + font-size: 16px; + color:#8ab4f8; + border: none; +} + +.page-container #page button:hover { + cursor:pointer; + text-decoration: underline; +} + +.result_change button { + color:#c58af9; + background-color: inherit; + border:none; + text-decoration: underline; + display: inline; + margin:20px 0px 0px 0px; + font-size: 18px; +} + +.result_change { margin-left: 11%;} + +.result_change button:hover { cursor: pointer; } + +.donate-container { + margin-left: 25%; + margin-right: 25%; + margin-top: 13%; + border: 1px solid #bdc1c6; + border-top: none; + border-bottom: none; + text-align: center; +} + +.donate-container a { + color:#8ab4f8; + text-decoration: underline; +} \ No newline at end of file