Repositories | Polyback | Log in to see private repositories


polyback-website / 8b48bedad56346c44734ee80e6f153429435481c / directory_admin/fetch-archive.php

3,905 bytes | parent directory

<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';

// Administrators fetch ROBLOX assets straight into the Roblox archive, with the token a super
// admin stored. /admin/fetch-archive

use pizzaboxer\ProjectPolygon\Archive;
use pizzaboxer\ProjectPolygon\PageBuilder;
use pizzaboxer\ProjectPolygon\Users;

Users::RequireAdmin(Users::STAFF_ADMINISTRATOR);

$Error = false;
$Rows = $Left = [];
$Asked = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
	if (!is_string($_POST["polygon_csrf"] ?? null) || !hash_equals((string) SESSION["csrfToken"], $_POST["polygon_csrf"])) die(http_response_code(403));
	$Asked = (string) ($_POST["ids"] ?? "");
	preg_match_all('/[0-9]{1,19}/', $Asked, $m);
	$ids = array_values(array_unique($m[0]));
	if (!$ids) $Error = "Enter one or more ROBLOX ids";
	else if (count($ids) > Archive::FETCH_AT_ONCE) $Error = "At most " . Archive::FETCH_AT_ONCE . " ids at a time";
	else
	{
		@set_time_limit(Archive::FETCH_SECONDS + 60);
		[$Rows, $Left, $Error] = Archive::FetchFromRoblox($ids, isset($_POST["dependencies"]));
		$archived = count(array_filter($Rows, fn($r) => str_starts_with($r[2], "archived")));
		if ($archived) Users::LogStaffAction("[ Archive ] Fetched $archived assets from ROBLOX into the archive (" . implode(", ", array_slice($ids, 0, 10)) . (count($ids) > 10 ? ", ..." : "") . ")");
	}
}

$Info = Archive::RobloxTokenInfo();
$csrf = '<input type="hidden" name="polygon_csrf" value="' . htmlspecialchars(SESSION["csrfToken"]) . '">';

$pageBuilder = new PageBuilder(["title" => "Fetch Archive Assets"]);
$pageBuilder->buildHeader();
?>
<h2 class="font-weight-normal">Fetch Archive Assets</h2>
<p>Fetches assets from ROBLOX straight into the Roblox archive, under their ROBLOX ids, with their names, descriptions and kinds. What they use (meshes, textures, sounds) can come along. Anything archived already is left as it is. Then it can be put in the catalog on <a href="/admin/sell-archive">Sell from archive</a>.</p>
<?php if (!$Info) { ?><div class="alert alert-warning px-2 py-1">No ROBLOX token is stored, so nothing can be fetched. A super admin can add one on the <b>ROBLOX token</b> page.</div><?php } ?>
<?php if ($Error) { ?><div class="alert alert-danger px-2 py-1" role="alert"><?=htmlspecialchars($Error)?></div><?php } ?>
<form method="post" style="max-width:40rem">
	<?=$csrf?>
	<div class="form-group"><label for="ids">ROBLOX ids (up to <?=Archive::FETCH_AT_ONCE?>):</label>
		<textarea class="form-control form-control-sm" id="ids" name="ids" rows="3" placeholder="Separated by spaces, commas or lines"><?=htmlspecialchars($Left ? implode(" ", $Left) : ($Error ? $Asked : ""))?></textarea></div>
	<div class="custom-control custom-checkbox mb-2"><input type="checkbox" class="custom-control-input" id="dependencies" name="dependencies" checked><label class="custom-control-label" for="dependencies">Also what they use (meshes, textures, sounds)</label></div>
	<button class="btn btn-primary"<?=$Info ? "" : " disabled"?> onclick="this.innerText = 'Fetching...'">Fetch</button>
</form>
<?php if ($Left) { ?><div class="alert alert-info px-2 py-1 mt-3">There wasn't time for everything: the ones left are in the box, press Fetch again.</div><?php } ?>
<?php if ($Rows) { ?>
<div class="table-responsive-sm mt-3">
	<table class="table table-sm table-hover">
		<thead class="table-bordered bg-light"><tr><th class="font-weight-normal">ROBLOX id</th><th class="font-weight-normal">Name</th><th class="font-weight-normal">What happened</th></tr></thead>
		<tbody>
			<?php foreach ($Rows as [$id, $name, $what]) { ?>
			<tr<?=str_starts_with($what, "archived") || $what === "in the archive already" ? "" : " class=\"text-danger\""?>><td><?=htmlspecialchars($id)?></td><td><?=htmlspecialchars($name)?></td><td><?=htmlspecialchars($what)?></td></tr>
			<?php } ?>
		</tbody>
	</table>
</div>
<?php } ?>
<?php $pageBuilder->buildFooter(); ?>