Files
2025-10-01 23:07:32 +02:00

209 lines
8.2 KiB
PHP

<?php
$_POST["nsfw"] = isset($_POST["nsfw"]) ? "1" : "0";
function myErrorHandler($errno, $errstr, $errfile, $errline) {
echo "<p>Custom error:</p> [$errno] $errstr<br>";
echo "Error on line $errline in $errfile<br>";
}
// Set user-defined error handler function
//set_error_handler("myErrorHandler");
$furatalog = new mysqli("10.0.0.200", "furatalog_admin_usr", "NR6tLk7c56bPT5[]", "furatalog");
if (isset($_POST["url"])) {
$givenURL = $_POST["url"];
$isExisting = $furatalog->query("SELECT * FROM species WHERE url='" . $givenURL . "'");
if ($isExisting->num_rows > 0) {
$isExistent = true;
} else {
if (str_contains($givenURL, "gumroad")) {
$creatorURL = implode('/', array_slice(explode('/', $givenURL), 0, 3));
$creatorRequestResult = $furatalog->query("SELECT * FROM creator WHERE `gumroad_url`='" . $creatorURL . "'");
if ($creatorRequestResult->num_rows > 0) {
$creatorID = $creatorRequestResult->fetch_assoc()["id"];
} else {
$scrapingUrl = $creatorURL;
$string = file_get_contents($scrapingUrl);
$dom = new DomDocument();
$dom->loadHTML($string);
$finder = new DomXPath($dom);
$creatorName = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' profile ')]")[0]->childNodes[0]->childNodes[0]->textContent;
$creatorUrl = $scrapingUrl;
$creatorpicture = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' profile ')]")[0]->childNodes[0]->childNodes[0]->childNodes[0]->attributes[1]->textContent;
$creatorCreateResult = $furatalog->query("INSERT INTO `creator` (`id`, `name`, `pb_url`, `booth_url`, `gumroad_url`, `payhip_url`, `jinxxy_url`) VALUES (NULL, '" . str_replace("'", "\'", $creatorName) . "', '" . $creatorpicture . "', '', '" . $creatorURL . "', '', '')");
$creatorResult = $furatalog->query("SELECT id FROM `creator` WHERE gumroad_url='" . $creatorURL . "'");
$creatorID = $creatorResult->fetch_assoc()["id"];
}
$newCreatorResult = $furatalog->query("SELECT * FROM creator WHERE id=" . $creatorID . "");
$newCreatorResultResult = $newCreatorResult->fetch_assoc();
$new_creatorid = $newCreatorResultResult["id"];
$new_creatorName = $newCreatorResultResult["name"];
$new_creatorPb = $newCreatorResultResult["pb_url"];
$new_boothURL = $newCreatorResultResult["booth_url"];
$new_gumroadURL = $newCreatorResultResult["gumroad_url"];
$new_payhipURL = $newCreatorResultResult["payhip_url"];
$new_jinxxyURL = $newCreatorResultResult["jinxxy_url"];
$tempURL = file_get_contents($givenURL);
$dom = new DomDocument();
$dom->loadHTML($tempURL);
$finder = new DomXPath($dom);
$content = $finder->query("//*[contains(concat(' ', normalize-space(@data-component-name), ' '), ' ProductPage ')]")[0]->textContent;
if ($content == "" || $content == null) {
$content = $finder->query("//*[contains(concat(' ', normalize-space(@data-component-name), ' '), ' ProfileProductPage ')]")[0]->textContent;
}
$content = json_decode($content);
$contentItem = $content->product;
if ($contentItem->thumbnail_url == "" || $contentItem->thumbnail_url == null) {
$newThumbnail = $contentItem->covers[0]->url;
} else {
$newThumbnail = $contentItem->thumbnail_url;
}
$newPrice = $contentItem->price_cents;
if (isset($contentItem->options[0]->price_difference_cents)) {
$newPrice = $contentItem->options[0]->price_difference_cents;
}
$furatalog->query("INSERT INTO `species` (`name`, `tag`, `url`, `creator_id`) VALUES ('" .
str_replace("'", "\'", $_POST["name"]) . "', '" .
$_POST["tag"] . "', '" .
$givenURL . "', '" .
$new_creatorid . "')");
$contentResult = $furatalog->query("SELECT * FROM species WHERE url='" . $givenURL . "'");
$contentResultResult = $contentResult->fetch_assoc();
$new_id = $contentResultResult["id"];
$new_name = $contentResultResult["name"];
$new_tag = $contentResultResult["tag"];
$new_url = $contentResultResult["url"];
$new_creatorid = $contentResultResult["creator_id"];
}
}
} else {
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo file_get_contents("/var/www/furatalog-cdn/mainHead-Admin.html"); ?>
<title>Insert Species - Admin Panel - Furatalog.xyz</title>
<style>
html, body {
margin: 0;
height: 100%;
padding: 0;
}
</style>
</head>
<body>
<div class="sidebar">
<a href="logout.php">Logout</a>
<a href="/admin/">Dashboard</a>
<a href="/admin/insert.php">Insert Data (Gumroad)</a>
<a class="active" href="/admin/insert-species.php">Insert Species</a>
</div>
<div class="content">
<div class="insert">
<h2>Insert Data</h2>
<form action="/admin/insert-species.php" method="post">
<input type="text" name="name" placeholder="Name" autocomplete="off">
<input type="text" name="tag" placeholder="Tag" autocomplete="off">
<input type="text" id="url" name="url" placeholder="URL" autocomplete="off">
<input type="submit" value="Submit">
<input type="text" name="species" id="speciesIncluded" style="display: none;">
</form>
</div>
<div class="insert-result">
<?php
if (isset($isExistent) && $isExistent) {
echo "<p>Content already exists in the database.</p>";
}
?>
<div class="summary">
<table>
<tr>
<th>New Species Inserted</th>
</tr>
<tr>
<td>ID</td>
<td><?php echo $new_id; ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $new_name; ?></td>
</tr>
<tr>
<td>Tag</td>
<td><?php echo $new_tag; ?></td>
</tr>
<tr>
<td>URL</td>
<td><?php echo $new_url; ?></td>
</tr>
<tr>
<td>Creator ID</td>
<td><?php echo $new_creatorid; ?></td>
</tr>
</table>
<table>
<tr>
<th>Creator</th>
</tr>
<tr>
<td>ID</td>
<td><?php echo $new_creatorid; ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $new_creatorName; ?></td>
</tr>
<tr>
<td>Creator PB</td>
<td><?php echo $new_creatorPb; ?></td>
</tr>
<tr>
<td>Booth URL</td>
<td><?php echo $new_boothURL; ?></td>
</tr>
<tr>
<td>Gumroad URL</td>
<td><?php echo $new_gumroadURL; ?></td>
</tr>
<tr>
<td>Payhip URL</td>
<td><?php echo $new_payhipURL; ?></td>
</tr>
<tr>
<td>Jinxxy URL</td>
<td><?php echo $new_jinxxyURL; ?></td>
</tr>
</table>
</div>
</div>
</body>
</html>