works now, image proxy needs to be fixed tho

This commit is contained in:
Ahwx 2023-02-16 13:10:46 +01:00
parent 4f320e60f7
commit b20f3e9c0f
12 changed files with 324 additions and 404 deletions

39
api.php
View file

@ -1,39 +0,0 @@
<?php
$config = require "config.php";
require "example/path.php";
if (!isset($_REQUEST["q"]))
{
echo "<p>Example API request: ./api.php?q=pinternet";
die();
}
$query = $_REQUEST["q"];
// Pinterest API Endpoint
$api_url = "https://api.pinterest.com/v1/boards/{board_id}/pins/";
// Replace {board_id} with the actual board ID
$board_id = "replace_with_actual_board_id";
// Replace {access_token} with a valid Pinterest access token
$access_token = "replace_with_actual_access_token";
// Create the API request URL
$request_url = $api_url . "?access_token=" . $access_token;
// Send a GET request to the Pinterest API
$response = file_get_contents($request_url);
// Decode the JSON response into a PHP array
$pins = json_decode($response, true);
// Loop through the pins and display each one
foreach ($pins["data"] as $pin) {
echo '<div>';
echo '<img src="' . $pin["image"]["original"]["url"] . '" alt="' . $pin["description"] . '">';
echo '<p>' . $pin["description"] . '</p>';
echo '</div>';
}
?>

View file

@ -1,53 +1,5 @@
<?php
return (object) array(
// e.g.: fr -> 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,
@ -62,7 +14,7 @@
CURLOPT_TIMEOUT => 18,
CURLOPT_VERBOSE => false
)
);
?>
// settings basically stolen from LibreX - https://github.com/hnhx/librex

View file

@ -1,60 +0,0 @@
<?php
require "misc/tools.php";
function get_image_results($query)
{
// $url = "https://www.pinterest.com/search/pins/?q=$query";
$url = "https://lite.qwant.com/?q=$query&t=images";
$response = request($url);
$xpath = get_xpath($response);
$results = array();
foreach($xpath->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 "<div class=\"image-result-container\">";
foreach($results as $result)
{
$thumbnail = urlencode($result["thumbnail"]);
$alt = $result["alt"];
$url = $result["url"];
echo "<a title=\"$alt\" href=\"$url\" target=\"_blank\">";
echo "<img src=\"image_proxy.php?url=$thumbnail\">";
echo "</a>";
}
echo "</div>";
}
?>

View file

@ -1,19 +1,21 @@
<?php
require "misc/tools.php";
$config = require "config.php";
require "misc/tools.php";
$url = $_REQUEST["url"];
$requested_root_domain = get_root_domain($url);
$url = $_REQUEST["url"];
$requested_root_domain = get_root_domain($url);
$allowed_domains = array("pinterest.com", "i.pinimg.com", "pinimg.com");
$allowed_domains = array("pinimg.com", "i.pinimg.com", "pinterest.com");
//if (in_array($requested_root_domain, $allowed_domains))
//{
$image = $url;
$image_src = request($image);
if (in_array($requested_root_domain, $allowed_domains))
{
$image = $url;
$image_src = request($image);
header("Content-Type: image/jpeg");
echo $image_src;
//}
header("Content-Type: image/jpeg");
echo $image_src;
}
?>
// basically stolen from LibreX - https://github.com/hnhx/LibreX

View file

@ -1,4 +1,5 @@
<?php require "static/header.php"; ?>
<?php require "misc/header.php"; ?>
<title>Pinternet</title>
</head>
<body>
<div class="mainContainer">
@ -10,4 +11,4 @@
</div>
</form>
</div>
<?php require "static/footer.php"; ?>
<?php require "misc/footer.php"; ?>

22
misc/footer.php Normal file
View file

@ -0,0 +1,22 @@
<footer>
<div class="footer">
<p id="footerText">
|
<a href="./" target="_blank">Pinternet</a>
|
<a href="https://github.com/Ahwxorg/Pinternet/" target="_blank">Source code</a>
|
<a href="https://ahwx.org/donate.php" target="_blank">Donate</a>
|
<?php
if (isset($images)) {
echo "<br><br>";
print(count($images). " images found");
}
?>
</p>
</div>
</footer>
</body>
</html>

8
misc/header.php Normal file
View file

@ -0,0 +1,8 @@
<!DOCTYPE html >
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="UTF-8"/>
<meta name="description" content="A privacy respecting Pinterest image search"/>
<meta name="referrer" content="no-referrer"/>
<link rel="stylesheet" type="text/css" href="misc/style-dark.css">

View file

@ -79,3 +79,11 @@ input {
margin: 10px;
}
img {
max-width: 25vw;
max-height: 25vw;
height: auto;
width: auto;
border-radius: 10px;
box-shadow: 5px 5px 5px black;
}

View file

@ -1,246 +1,244 @@
<?php
$config = require "config.php";
function get_base_url($url)
{
$split_url = explode("/", $url);
$base_url = $split_url[0] . "//" . $split_url[2] . "/";
return $base_url;
}
function get_root_domain($url)
{
$split_url = explode("/", $url);
$base_url = $split_url[2];
$base_url_main_split = explode(".", strrev($base_url));
$root_domain = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
return $root_domain;
}
function try_replace_with_frontend($url, $frontend, $original)
{
$config = require "config.php";
if (isset($_COOKIE[$frontend]) || isset($_REQUEST[$frontend]) || !empty($config->$frontend))
function get_base_url($url)
{
if (isset($_COOKIE[$frontend]))
$frontend = $_COOKIE[$frontend];
else if (isset($_REQUEST[$frontend]))
$frontend = $_REQUEST[$frontend];
else if (!empty($config->$frontend))
$frontend = $config->$frontend;
$split_url = explode("/", $url);
$base_url = $split_url[0] . "//" . $split_url[2] . "/";
return $base_url;
}
if ($original == "instagram.com")
function get_root_domain($url)
{
$split_url = explode("/", $url);
$base_url = $split_url[2];
$base_url_main_split = explode(".", strrev($base_url));
$root_domain = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
return $root_domain;
}
function try_replace_with_frontend($url, $frontend, $original)
{
$config = require "config.php";
if (isset($_COOKIE[$frontend]) || isset($_REQUEST[$frontend]) || !empty($config->$frontend))
{
if (!strpos($url, "/p/"))
$frontend .= "/u";
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;
}
if (empty(trim($frontend)))
return $url;
}
function check_for_privacy_frontend($url)
{
if (isset($_COOKIE["disable_frontends"]))
return $url;
if (strpos($url, "wikipedia.org") !== false)
$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)
{
$wiki_split = explode(".", $url);
if (count($wiki_split) > 1)
if (strpos($url, $original))
{
$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];
$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)
{
$url = $frontend . explode($original, $url)[1];
if ($bang["t"] == $search_word)
{
$bang_url = $bang["u"];
break;
}
}
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))
if ($bang_url)
{
$url = try_replace_with_frontend($url, $frontend, $original);
break;
$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();
}
}
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)
function check_for_special_search($query)
{
if ($bang["t"] == $search_word)
{
$bang_url = $bang["u"];
break;
}
}
if (isset($_COOKIE["disable_special"]) || isset($_REQUEST["disable_special"]))
return 0;
if ($bang_url)
{
$bang_query_array = explode("!" . $search_word, $query);
$bang_query = trim(implode("", $bang_query_array));
$query_lower = strtolower($query);
$split_query = explode(" ", $query);
$request_url = str_replace("{{{s}}}", $bang_query, $bang_url);
$request_url = check_for_privacy_frontend($request_url);
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;
}
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 "<p id=\"time\">Fetched the results in $end_time seconds</p>";
}
function print_next_page_button($text, $page, $query, $type)
{
echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"get\" autocomplete=\"off\">";
foreach($_REQUEST as $key=>$value)
function get_xpath($response)
{
if ($key != "q" && $key != "p" && $key != "t")
{
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\"/>";
}
}
echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
echo "<input type=\"hidden\" name=\"q\" value=\"$query\" />";
echo "<input type=\"hidden\" name=\"t\" value=\"$type\" />";
echo "<button type=\"submit\">$text</button>";
echo "</form>";
}
$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 "<p id=\"time\">Fetched the results in $end_time seconds</p>";
}
function print_next_page_button($text, $page, $query, $type)
{
echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"get\" autocomplete=\"off\">";
foreach($_REQUEST as $key=>$value)
{
if ($key != "q" && $key != "p" && $key != "t")
{
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\"/>";
}
}
echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
echo "<input type=\"hidden\" name=\"q\" value=\"$query\" />";
echo "<input type=\"hidden\" name=\"t\" value=\"$type\" />";
echo "<button type=\"submit\">$text</button>";
echo "</form>";
}
?>
//basically stolen from LibreX - https://github.com/hnhx/LibreX

View file

@ -1,10 +1,60 @@
<?php require "misc/header.php"; ?>
<title>
<?php
require "static/header.php";
require "engines/pinterest.php";
$query = htmlspecialchars(trim($_REQUEST["q"]));
echo $query;
?> - Pinternet</title>
</head>
<body>
<form class="searchContainer" method="get" autocomplete="off">
<h1><a class="no-decoration" href="./"><span>P</span>inter<span>n</span>et</a></h1>
<input type="text" name="q"
<?php
$query_encoded = urlencode($query);
if (1 > strlen($query) || strlen($query) > 64)
{
header("Location: ./");
die();
}
echo "value=\"$query\"";
?>
<br>
<hr>
</form>
<?php
//require "engines/pinterest.php";
$query = $_GET['q'];
$imgResults = get_image_results($query);
print_image_results($imgResults);
//$imgResults = get_image_results($query);
//print_image_results($imgResults);
$baseurl = "https://pinterest.com/resource/BaseSearchResource/get/?data=%7B%22options%22%3A%7B%22query%22%3A%22{}%22%7D%7D";
$search = function($query) use($baseurl)
{
$url = str_replace("{}", str_replace(" ", "%20", $query), $baseurl);
$json = file_get_contents($url);
$data = json_decode($json);
$images = array();
foreach ($data->{"resource_response"}->{"data"}->{"results"} as $result)
{
$image = $result->{"images"}->{"orig"};
$url = $image->{"url"};
array_push($images, $url);
echo "<img src='/image_proxy.php?url=", $url, "'>";
}
return $images;
};
$images = $search("$query");
echo "<br><br>";
echo "<hr>";
print(count($images)." images found");
include "misc/footer.php";
?>

View file

@ -1,12 +0,0 @@
<footer>
<div class="footer">
<p id="footerText">
<!--<a href="./api.php" target="_blank">API</a>-->
|
<a href="https://github.com/Ahwxorg/Pinternet/" target="_blank">Source code</a>
|
</p>
</div>
</footer>
</body>
</html>

View file

@ -1,10 +0,0 @@
<!DOCTYPE html >
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="UTF-8"/>
<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="stylesheet" type="text/css" href="static/style-dark.css">