2023-10-16 01:30:43 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class imgur{
|
|
|
|
|
|
|
|
public function __construct(){
|
|
|
|
|
2024-06-07 19:47:08 -05:00
|
|
|
include "lib/heckhtml.php";
|
|
|
|
$this->heckhtml = new heckhtml();
|
2023-11-07 08:04:56 -05:00
|
|
|
|
|
|
|
include "lib/backend.php";
|
|
|
|
$this->backend = new backend("imgur");
|
2023-10-16 01:30:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getfilters($page){
|
|
|
|
|
|
|
|
return [
|
|
|
|
"sort" => [ // /score/
|
|
|
|
"display" => "Sort by",
|
|
|
|
"option" => [
|
|
|
|
"score" => "Highest scoring",
|
|
|
|
"relevance" => "Most relevant",
|
|
|
|
"time" => "Newest first"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"time" => [ // /score/day/
|
|
|
|
"display" => "Time posted",
|
|
|
|
"option" => [
|
|
|
|
"all" => "All time",
|
|
|
|
"day" => "Today",
|
|
|
|
"week" => "This week",
|
|
|
|
"month" => "This month",
|
|
|
|
"year" => "This year"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"format" => [ // q_type
|
|
|
|
"display" => "Format",
|
|
|
|
"option" => [
|
|
|
|
"any" => "Any format",
|
|
|
|
"jpg" => "JPG",
|
|
|
|
"png" => "PNG",
|
|
|
|
"gif" => "GIF",
|
|
|
|
"anigif" => "Animated GIF",
|
|
|
|
"album" => "Albums"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"size" => [ // q_size_px
|
|
|
|
"display" => "Size",
|
|
|
|
"option" => [
|
|
|
|
"any" => "Any size",
|
|
|
|
"small" => "Small (500px or less)",
|
|
|
|
"med" => "Medium (500px to 2000px)",
|
|
|
|
"big" => "Big (2000px to 5000px)",
|
|
|
|
"lrg" => "Large (5000px to 10000px)",
|
|
|
|
"huge" => "Huge (10000px and above)"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-11-07 08:04:56 -05:00
|
|
|
private function get($proxy, $url, $get = []){
|
2023-10-16 01:30:43 -05:00
|
|
|
|
|
|
|
$curlproc = curl_init();
|
|
|
|
|
|
|
|
if($get !== []){
|
|
|
|
$get = http_build_query($get);
|
|
|
|
$url .= "?scrolled&" . $get;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_setopt($curlproc, CURLOPT_URL, $url);
|
|
|
|
|
|
|
|
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
|
|
|
curl_setopt($curlproc, CURLOPT_HTTPHEADER,
|
2023-11-07 08:04:56 -05:00
|
|
|
["User-Agent: " . config::USER_AGENT,
|
2023-10-16 01:30:43 -05:00
|
|
|
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
|
|
"Accept-Language: en-US,en;q=0.5",
|
|
|
|
"Accept-Encoding: gzip",
|
|
|
|
"DNT: 1",
|
|
|
|
"Referer: https://imgur.com/search/",
|
|
|
|
"Connection: keep-alive",
|
|
|
|
"Sec-Fetch-Dest: empty",
|
|
|
|
"Sec-Fetch-Mode: cors",
|
|
|
|
"Sec-Fetch-Site: same-origin",
|
|
|
|
"TE: trailers",
|
|
|
|
"X-Requested-With: XMLHttpRequest"]
|
|
|
|
);
|
|
|
|
|
|
|
|
curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
|
|
|
|
curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
|
|
|
|
curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
|
|
|
|
curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
|
2023-11-07 08:04:56 -05:00
|
|
|
|
|
|
|
$this->backend->assign_proxy($curlproc, $proxy);
|
2023-10-16 01:30:43 -05:00
|
|
|
|
|
|
|
$data = curl_exec($curlproc);
|
|
|
|
|
|
|
|
if(curl_errno($curlproc)){
|
|
|
|
|
|
|
|
throw new Exception(curl_error($curlproc));
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_close($curlproc);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function image($get){
|
|
|
|
|
|
|
|
if($get["npt"]){
|
|
|
|
|
2023-11-07 08:04:56 -05:00
|
|
|
[$filter, $proxy] =
|
|
|
|
$this->backend->get(
|
|
|
|
$get["npt"],
|
|
|
|
"images"
|
2023-10-16 01:30:43 -05:00
|
|
|
);
|
|
|
|
|
2023-11-07 08:04:56 -05:00
|
|
|
$filter = json_decode($filter, true);
|
|
|
|
|
2023-10-16 01:30:43 -05:00
|
|
|
$search = $filter["s"];
|
|
|
|
unset($filter["s"]);
|
|
|
|
|
|
|
|
$sort = $filter["sort"];
|
|
|
|
unset($filter["sort"]);
|
|
|
|
|
|
|
|
$time = $filter["time"];
|
|
|
|
unset($filter["time"]);
|
|
|
|
|
|
|
|
$format = $filter["format"];
|
|
|
|
unset($filter["format"]);
|
|
|
|
|
|
|
|
$size = $filter["size"];
|
|
|
|
unset($filter["size"]);
|
|
|
|
|
|
|
|
$page = $filter["page"];
|
|
|
|
unset($filter["page"]);
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$search = $get["s"];
|
2023-11-07 08:04:56 -05:00
|
|
|
if(strlen($search) === 0){
|
|
|
|
|
|
|
|
throw new Exception("Search term is empty!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$proxy = $this->backend->get_ip();
|
2023-10-16 01:30:43 -05:00
|
|
|
$sort = $get["sort"];
|
|
|
|
$time = $get["time"];
|
|
|
|
$format = $get["format"];
|
|
|
|
$size = $get["size"];
|
|
|
|
$page = 0;
|
|
|
|
|
|
|
|
$filter = [
|
|
|
|
"q" => $search
|
|
|
|
];
|
|
|
|
|
|
|
|
if($format != "any"){
|
|
|
|
|
|
|
|
$filter["q_type"] = $format;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($size != "any"){
|
|
|
|
|
|
|
|
$filter["q_size_px"] = $size;
|
|
|
|
$filter["q_size_is_mpx"] = "off";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = [
|
|
|
|
"status" => "ok",
|
|
|
|
"npt" => null,
|
|
|
|
"image" => []
|
|
|
|
];
|
|
|
|
|
|
|
|
try{
|
|
|
|
$html =
|
|
|
|
$this->get(
|
2023-11-07 08:04:56 -05:00
|
|
|
$proxy,
|
2023-10-16 01:30:43 -05:00
|
|
|
"https://imgur.com/search/$sort/$time/page/$page",
|
|
|
|
$filter
|
|
|
|
);
|
|
|
|
|
|
|
|
}catch(Exception $error){
|
|
|
|
|
|
|
|
throw new Exception("Failed to fetch HTML");
|
|
|
|
}
|
|
|
|
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml->load($html);
|
2023-10-16 01:30:43 -05:00
|
|
|
|
|
|
|
$posts =
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml
|
2023-10-16 01:30:43 -05:00
|
|
|
->getElementsByClassName(
|
|
|
|
"post",
|
|
|
|
"div"
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($posts as $post){
|
|
|
|
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml->load($post);
|
2023-10-16 01:30:43 -05:00
|
|
|
|
|
|
|
$image =
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml
|
2023-10-16 01:30:43 -05:00
|
|
|
->getElementsByTagName("img")[0];
|
|
|
|
|
2024-06-07 19:47:08 -05:00
|
|
|
$image_url = "https:" . substr($this->heckhtml->getTextContent($image["attributes"]["src"]), 0, -5);
|
2023-10-16 01:30:43 -05:00
|
|
|
|
|
|
|
$out["image"][] = [
|
|
|
|
"title" =>
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml
|
2023-10-16 01:30:43 -05:00
|
|
|
->getTextContent(
|
|
|
|
$image["attributes"]["alt"]
|
|
|
|
),
|
|
|
|
"source" => [
|
|
|
|
[
|
|
|
|
"url" => $image_url . ".jpg",
|
|
|
|
"width" => null,
|
|
|
|
"height" => null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"url" => $image_url . "m.jpg",
|
|
|
|
"width" => null,
|
|
|
|
"height" => null
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"url" =>
|
|
|
|
"https://imgur.com" .
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml
|
2023-10-16 01:30:43 -05:00
|
|
|
->getTextContent(
|
2024-06-07 19:47:08 -05:00
|
|
|
$this->heckhtml
|
2023-10-16 01:30:43 -05:00
|
|
|
->getElementsByClassName(
|
|
|
|
"image-list-link",
|
|
|
|
"a"
|
|
|
|
)
|
|
|
|
[0]
|
|
|
|
["attributes"]
|
|
|
|
["href"]
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($out["image"][0])){
|
|
|
|
|
|
|
|
// store nextpage
|
|
|
|
$filter["s"] = $search;
|
|
|
|
$filter["sort"] = $sort;
|
|
|
|
$filter["time"] = $time;
|
|
|
|
$filter["format"] = $format;
|
|
|
|
$filter["size"] = $size;
|
|
|
|
$filter["page"] = $page + 1;
|
|
|
|
|
|
|
|
$out["npt"] =
|
2023-11-07 08:04:56 -05:00
|
|
|
$this->backend->store(
|
2023-10-16 01:30:43 -05:00
|
|
|
json_encode($filter),
|
2023-11-07 08:04:56 -05:00
|
|
|
"images",
|
|
|
|
$proxy
|
2023-10-16 01:30:43 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
}
|