From d55a062d4d4bd033414401e2a91cc8194ff71954 Mon Sep 17 00:00:00 2001 From: Ahwx Date: Tue, 14 Feb 2023 16:02:08 +0100 Subject: [PATCH] trying to get it to work by basically copying librex and trying to customize it for pinterest --- README.txt | 8 ++ board.php | 22 ---- config.php | 63 ++++++++++- engines/pinterest.php | 59 ++++++++++ image_proxy.php | 19 ++++ misc/tools.php | 246 ++++++++++++++++++++++++++++++++++++++++++ search.php | 25 +++-- 7 files changed, 409 insertions(+), 33 deletions(-) create mode 100644 README.txt delete mode 100644 board.php create mode 100644 engines/pinterest.php create mode 100644 image_proxy.php create mode 100644 misc/tools.php diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..620dde5 --- /dev/null +++ b/README.txt @@ -0,0 +1,8 @@ +The main concept is that you don't want the random popups forcing you to log in, and you don't want a bunch of JS. + + +Credits: + +https://github.com/hnhx/librex | https://femboy.hu - image proxy + + diff --git a/board.php b/board.php deleted file mode 100644 index 2a909a4..0000000 --- a/board.php +++ /dev/null @@ -1,22 +0,0 @@ -'; - echo '' . $pin['; - echo '

' . $pin["description"] . '

'; - echo ''; -} - -?> diff --git a/config.php b/config.php index 3724535..3b08acc 100644 --- a/config.php +++ b/config.php @@ -1,7 +1,68 @@ https://google.fr/ + "google_domain" => "com", + // Google results will be in this language + "google_language" => "en", + + // If you have a local instance you can change this to http://localhost:3000 + "invidious_instance_for_video_results" => "https://invidious.namazso.eu", + + "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", + + "disable_hidden_service_search" => false, + + /* + Preset privacy friendly frontends for users, these can be overwritten by users in settings + e.g.: "invidious" => "https://yewtu.be", + */ + "invidious" => "", // youtube + "bibliogram" => "", // instagram + "rimgo" => "", // imgur + "scribe" => "", // medium + "librarian" => "", // odysee + "gothub" => "", // github + "nitter" => "", // twitter + "libreddit" => "", // reddit + "proxitok" => "", // tiktok + "wikiless" => "", // wikipedia + "quetre" => "", // quora + "libremdb" => "", // imdb, + "breezewiki" => "", // fandom, + "anonymousoverflow" => "", // stackoverflow + + /* + To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE: + + CURLOPT_PROXYTYPE options: + + CURLPROXY_HTTP + CURLPROXY_SOCKS4 + CURLPROXY_SOCKS4A + CURLPROXY_SOCKS5 + CURLPROXY_SOCKS5_HOSTNAME + + !!! ONLY CHANGE THE OTHER OPTIONS IF YOU KNOW WHAT YOU ARE DOING !!! + */ + "curl_settings" => array( + // CURLOPT_PROXY => "ip:port", + // CURLOPT_PROXYTYPE => CURLPROXY_HTTP, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36", + CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, + CURLOPT_CUSTOMREQUEST => "GET", + CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP, + CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP, + CURLOPT_MAXREDIRS => 5, + CURLOPT_TIMEOUT => 18, + CURLOPT_VERBOSE => false + ) + + ); ?> diff --git a/engines/pinterest.php b/engines/pinterest.php new file mode 100644 index 0000000..8c0d24b --- /dev/null +++ b/engines/pinterest.php @@ -0,0 +1,59 @@ +query("//a[@rel='noopener']") as $result) + { + $image = $xpath->evaluate(".//img", $result)[0]; + + if ($image) + { + $encoded_url = $result->getAttribute("href"); + $encoded_url_split1 = explode("==/", $encoded_url)[1]; + $encoded_url_split2 = explode("?position", $encoded_url_split1)[0]; + $real_url = urldecode(base64_decode($encoded_url_split2)); + $real_url = check_for_privacy_frontend($real_url); + + $alt = $image->getAttribute("alt"); + $thumbnail = urlencode($image->getAttribute("src")); + + array_push($results, + array ( + "thumbnail" => urldecode(htmlspecialchars($thumbnail)), + "alt" => htmlspecialchars($alt), + "url" => htmlspecialchars($real_url) + ) + ); + + } + } + + return $results; + } + + function print_image_results($results) + { + echo "
"; + + foreach($results as $result) + { + $thumbnail = urlencode($result["thumbnail"]); + $alt = $result["alt"]; + $url = $result["url"]; + + echo ""; + echo ""; + echo ""; + } + + echo "
"; + } +?> diff --git a/image_proxy.php b/image_proxy.php new file mode 100644 index 0000000..eb1038d --- /dev/null +++ b/image_proxy.php @@ -0,0 +1,19 @@ + + diff --git a/misc/tools.php b/misc/tools.php new file mode 100644 index 0000000..5846c4f --- /dev/null +++ b/misc/tools.php @@ -0,0 +1,246 @@ +$frontend)) + { + if (isset($_COOKIE[$frontend])) + $frontend = $_COOKIE[$frontend]; + else if (isset($_REQUEST[$frontend])) + $frontend = $_REQUEST[$frontend]; + else if (!empty($config->$frontend)) + $frontend = $config->$frontend; + + if ($original == "instagram.com") + { + if (!strpos($url, "/p/")) + $frontend .= "/u"; + } + + if (empty(trim($frontend))) + return $url; + + if (strpos($url, "wikipedia.org") !== false) + { + $wiki_split = explode(".", $url); + if (count($wiki_split) > 1) + { + $lang = explode("://", $wiki_split[0])[1]; + $url = $frontend . explode($original, $url)[1] . "?lang=" . $lang; + } + } + else if (strpos($url, "fandom.com") !== false) + { + $fandom_split = explode(".", $url); + if (count($fandom_split) > 1) + { + $wiki_name = explode("://", $fandom_split[0])[1]; + $url = $frontend . "/" . $wiki_name . explode($original, $url)[1]; + } + } + else + { + $url = $frontend . explode($original, $url)[1]; + } + + + return $url; + } + + return $url; +} + +function check_for_privacy_frontend($url) +{ + if (isset($_COOKIE["disable_frontends"])) + return $url; + + $frontends = array( + "youtube.com" => "invidious", + "instagram.com" => "bibliogram", + "imgur.com" => "rimgo", + "medium.com" => "scribe", + "github.com" => "gothub", + "odysee.com" => "librarian", + "twitter.com" => "nitter", + "reddit.com" => "libreddit", + "tiktok.com" => "proxitok", + "wikipedia.org" => "wikiless", + "quora.com" => "quetre", + "imdb.com" => "libremdb", + "fandom.com" => "breezewiki", + "stackoverflow.com" => "anonymousoverflow" + ); + + foreach($frontends as $original => $frontend) + { + if (strpos($url, $original)) + { + $url = try_replace_with_frontend($url, $frontend, $original); + break; + } + } + + return $url; +} + +function check_ddg_bang($query) +{ + + $bangs_json = file_get_contents("static/misc/ddg_bang.json"); + $bangs = json_decode($bangs_json, true); + + if (substr($query, 0, 1) == "!") + $search_word = substr(explode(" ", $query)[0], 1); + else + $search_word = substr(end(explode(" ", $query)), 1); + + $bang_url = null; + + foreach($bangs as $bang) + { + if ($bang["t"] == $search_word) + { + $bang_url = $bang["u"]; + break; + } + } + + if ($bang_url) + { + $bang_query_array = explode("!" . $search_word, $query); + $bang_query = trim(implode("", $bang_query_array)); + + $request_url = str_replace("{{{s}}}", $bang_query, $bang_url); + $request_url = check_for_privacy_frontend($request_url); + + header("Location: " . $request_url); + die(); + } +} + +function check_for_special_search($query) +{ + if (isset($_COOKIE["disable_special"]) || isset($_REQUEST["disable_special"])) + return 0; + + $query_lower = strtolower($query); + $split_query = explode(" ", $query); + + if (strpos($query_lower, "to") && count($split_query) >= 4) // currency + { + $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 + { + return 2; + } + else if (strpos($query_lower, "my") !== false) + { + if (strpos($query_lower, "ip")) + { + return 3; + } + else if (strpos($query_lower, "user agent") || strpos($query_lower, "ua")) + { + return 4; + } + } + else if (strpos($query_lower, "weather") !== false) + { + return 5; + } + else if ($query_lower == "tor") + { + return 6; + } + else if (3 > count(explode(" ", $query))) // wikipedia + { + return 7; + } + + return 0; +} + +function get_xpath($response) +{ + $htmlDom = new DOMDocument; + @$htmlDom->loadHTML($response); + $xpath = new DOMXPath($htmlDom); + + return $xpath; +} + +function request($url) +{ + global $config; + + $ch = curl_init($url); + curl_setopt_array($ch, $config->curl_settings); + $response = curl_exec($ch); + + return $response; +} + +function human_filesize($bytes, $dec = 2) +{ + $size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor]; +} + +function remove_special($string) +{ + $string = preg_replace("/[\r\n]+/", "\n", $string); + return trim(preg_replace("/\s+/", ' ', $string)); + } + +function print_elapsed_time($start_time) + { + $end_time = number_format(microtime(true) - $start_time, 2, '.', ''); + echo "

Fetched the results in $end_time seconds

"; + } + +function print_next_page_button($text, $page, $query, $type) +{ + echo "
"; + foreach($_REQUEST as $key=>$value) + { + if ($key != "q" && $key != "p" && $key != "t") + { + echo ""; + } + } + echo ""; + echo ""; + echo ""; + echo ""; + echo "
"; +} + +?> diff --git a/search.php b/search.php index faf0a34..473b92d 100644 --- a/search.php +++ b/search.php @@ -1,18 +1,23 @@ -loadHTML($html); +//$doc = new DOMDocument(); +//@$doc->loadHTML($html); - $items = $doc->getElementsByTagName('img'); +//$items = $doc->getElementsByTagName('img'); - foreach ($items as $item) { - echo ""; - } +//foreach ($items as $item) { +// echo ""; +//} + +$imgResults = get_image_results($query); +print_image_results($imgResults); // echo $pinterestPage;