mirror of
https://github.com/Ahwxorg/Binternet.git
synced 2026-03-11 08:54:37 +00:00
feat: trying to add support for image boards and pin searches, see #13
This commit is contained in:
parent
f8e0d269fd
commit
e6fbeb981d
3 changed files with 130 additions and 0 deletions
BIN
404.jpg
Normal file
BIN
404.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
75
image_board.php
Normal file
75
image_board.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
require "misc/tools.php";
|
||||
require "misc/header.php";
|
||||
?>
|
||||
|
||||
<title>
|
||||
<?php
|
||||
$query = htmlspecialchars(trim($_REQUEST["q"]));
|
||||
echo $query;
|
||||
?> - Binternet</title>
|
||||
</head>
|
||||
<body>
|
||||
<form class="searchContainer" method="get" autocomplete="off">
|
||||
<h1><a class="no-decoration" href="./"><span>B</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>
|
||||
<div class="imageBoard">
|
||||
<?php
|
||||
|
||||
if (!$_REQUEST["imgurl"])
|
||||
{
|
||||
$imgurl = $_REQUEST["imgurl"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$imgurl = "/404.jpg";
|
||||
}
|
||||
|
||||
$instance_url = getenv('HTTP_HOST');
|
||||
echo $instance_url;
|
||||
$allowed_domains = array("pinimg.com", "i.pinimg.com", "pinterest.com", "localhost", "$instance_url"); # TODO
|
||||
|
||||
if (!$imgurl)
|
||||
{
|
||||
echo "No URL passed, showing images matching query.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (in_array(get_root_domain($imgurl), $allowed_domains))
|
||||
{
|
||||
// header("Content-type: image/jpeg");
|
||||
echo "<img src='/image_proxy.php?url=", $imgurl, "'></a>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
echo "<br><br><br><br>";
|
||||
|
||||
include "misc/footer.php";
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
.imageBoard img {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
</style>
|
||||
55
search/pins/index.php
Normal file
55
search/pins/index.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php require "../../misc/header.php"; ?>
|
||||
<title>
|
||||
<?php
|
||||
$query = htmlspecialchars(trim($_REQUEST["q"]));
|
||||
echo $query;
|
||||
?> - Binternet</title>
|
||||
</head>
|
||||
<body>
|
||||
<form class="searchContainer" method="get" autocomplete="off">
|
||||
<h1><a class="no-decoration" href="./"><span>B</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
|
||||
|
||||
$query = $_GET['q'];
|
||||
|
||||
$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 "<a href='/image_proxy.php?url=", $url, "'>";
|
||||
echo "<img src='/image_proxy.php?url=", $url, "'></a>";
|
||||
}
|
||||
return $images;
|
||||
};
|
||||
|
||||
$images = $search("$query");
|
||||
echo "<br><br><br><br>";
|
||||
|
||||
include "misc/footer.php";
|
||||
|
||||
?>
|
||||
Loading…
Reference in a new issue