77 lines
3.4 KiB
PHP
77 lines
3.4 KiB
PHP
<?php
|
|
|
|
class getGumroadData {
|
|
public $jsonData;
|
|
//public $jsonOBJ;
|
|
public $setURL;
|
|
|
|
function load($url) {
|
|
if (str_contains($url, '.gumroad.com/')) {
|
|
$string = file_get_contents($url);
|
|
|
|
$dom = new DomDocument();
|
|
$dom->loadHTML($string);
|
|
$finder = new DomXPath($dom);
|
|
|
|
$this->jsonData = $finder->query("//*[contains(concat(' ', normalize-space(@data-component-name), ' '), ' ProductPage ')]")[0]->textContent;
|
|
} elseif (str_contains($url, 'booth.pm/')) {
|
|
|
|
$string = file_get_contents($url);
|
|
|
|
$dom = new DomDocument();
|
|
$dom->loadHTML($string);
|
|
$finder = new DomXPath($dom);
|
|
|
|
$tmp = $finder->query("//*[contains(concat(' ', normalize-space(@type), ' '), ' application/ld+json ')]")[0]->textContent;
|
|
|
|
$tmp = json_decode($tmp);
|
|
|
|
$boothArray = array('product' => array('name' => $tmp->name,
|
|
'description_html' => str_replace("\n", "<br>", $tmp->description) . "<br><br><br><br>",
|
|
'long_url' => $tmp->url,
|
|
'price_cents' => str_replace("¥ ", "", str_replace(",", "", $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' variation-price u-text-right ')]")[0]->textContent)) * 100,
|
|
'currency_code' => $tmp->offers->priceCurrency,
|
|
'rating_counts' => array(0,0,0,0,0),
|
|
'covers' => array(
|
|
array('url' => $tmp->image, 'filetype' => "png", 'type' => "image"),
|
|
array('url' => $tmp->image, 'filetype' => "png", 'type' => "image")
|
|
),
|
|
'seller' => array(
|
|
'name' => $finder->query("//*[contains(concat(' ', normalize-space(@data-product-list), ' '), ' from market_show via market_item_detail to shop_index ')]")[0]->textContent,
|
|
'avatar_url' => str_replace("48x48", "128x128", $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' h-[24px] rounded-oval w-[24px] ')]")[0]->attributes[2]->value)
|
|
)
|
|
));
|
|
|
|
$this->jsonData = json_encode($boothArray);
|
|
//echo $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getURL($id) {
|
|
$servername = "localhost";
|
|
$username = "database_access";
|
|
$password = "DataAccess1.";
|
|
$dbname = "avali_shop";
|
|
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
$sql = "SELECT * FROM content WHERE id=\"" . $id . "\"";
|
|
$result = $conn->query($sql);
|
|
$row = $result->fetch_assoc();
|
|
$this->setURL = str_replace("?layout=profile","", $row["url_link"]);
|
|
}
|
|
}
|
|
|
|
$thisGumroad = new getGumroadData();
|
|
$thisGumroad->getURL($_POST["id"]);
|
|
|
|
//$thisGumroad->getURL("173");
|
|
|
|
$thisGumroad->load($thisGumroad->setURL);
|
|
print_r($thisGumroad->jsonData); |