Skip to content

Commit

Permalink
expose the hide and restore functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Piralein committed Jun 20, 2023
1 parent 5481f29 commit 0cacdb8
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 68 deletions.
24 changes: 24 additions & 0 deletions assets/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ footer {
line-height: 1.8;
}

.asset-links {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 12px;
}

.asset-tools {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 12px;
margin-top: 20px;
}

.asset-tools .panel {
margin-bottom: 0;
}

.flex-container {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}

.asset-search-container {
display: flex;
flex-direction: row;
Expand Down
6 changes: 3 additions & 3 deletions src/queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
'list' => 'SELECT category_id as id, category as name, category_type as type FROM `as_categories` WHERE category_type LIKE :category_type ORDER BY category_id',
],
'asset' => [
'search' => 'SELECT asset_id, title, username as author, user_id as author_id, category, category_id, godot_version, rating, cost, support_level, icon_url, version, version_string, modify_date FROM `as_assets`
'search' => 'SELECT asset_id, title, searchable, username as author, user_id as author_id, category, category_id, godot_version, rating, cost, support_level, icon_url, version, version_string, modify_date FROM `as_assets`
LEFT JOIN `as_users` USING (user_id)
LEFT JOIN `as_categories` USING (category_id)
WHERE searchable = TRUE AND category_id LIKE :category AND category_type LIKE :category_type
WHERE (searchable = TRUE OR user_id = :user_id) AND category_id LIKE :category AND category_type LIKE :category_type
AND support_level RLIKE :support_levels_regex AND username LIKE :username AND cost LIKE :cost
AND godot_version <= :max_godot_version AND godot_version >= :min_godot_version
AND (
Expand Down Expand Up @@ -62,7 +62,7 @@
'search_count' => 'SELECT count(*) as count FROM `as_assets`
LEFT JOIN `as_users` USING (user_id)
LEFT JOIN `as_categories` USING (category_id)
WHERE searchable = TRUE AND category_id LIKE :category AND category_type LIKE :category_type
WHERE (searchable = TRUE OR user_id = :user_id) AND category_id LIKE :category AND category_type LIKE :category_type
AND support_level RLIKE :support_levels_regex AND username LIKE :username AND cost LIKE :cost
AND godot_version <= :max_godot_version AND godot_version >= :min_godot_version
AND (
Expand Down
23 changes: 23 additions & 0 deletions src/routes/asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$app->get('/asset', function ($request, $response, $args) {
$params = $request->getQueryParams();

$user_id = 0;
$category = '%';
$filter = '%';
$username = '%';
Expand Down Expand Up @@ -50,6 +51,14 @@
}
if (isset($params['user'])) {
$username = $params['user'];

if ($token = $this->tokens->validate($request->getParsedBody()['token'])) {
$session_error = $this->utils->getUserFromTokenData(false, $response, $token, $user);

if (!$session_error && $username === $user['username']) {
$user_id = $user['user_id'];
}
}
}
if (isset($params['cost']) && $params['cost'] != "") {
$cost = $params['cost'];
Expand Down Expand Up @@ -104,6 +113,7 @@
$support_levels = implode('|', $support_levels);

$query = $this->queries['asset']['search'];
$query->bindValue(':user_id', $user_id);
$query->bindValue(':category', $category);
$query->bindValue(':category_type', $category_type);
$query->bindValue(':min_godot_version', $min_godot_version, PDO::PARAM_INT);
Expand All @@ -124,6 +134,7 @@
}

$query_count = $this->queries['asset']['search_count'];
$query_count->bindValue(':user_id', $user_id);
$query_count->bindValue(':category', $category);
$query_count->bindValue(':category_type', $category_type);
$query_count->bindValue(':min_godot_version', $min_godot_version, PDO::PARAM_INT);
Expand Down Expand Up @@ -182,6 +193,18 @@
$previews = [];

foreach ($output as $row) {

if (array_key_exists('searchable', $row) && $row['searchable'] === '0') {
$error = $this->utils->ensureLoggedIn(false, $response, $request->getParsedBody(), $user);
$error = $this->utils->errorResponseIfNotOwnerOrLevel($error, $response, $user, $args['id'], 'moderator');
if ($error) {
$response = new \Slim\Http\Response();
return $response->withJson([
'error' => 'Couldn\'t find asset with id '.$args['id'].'!'
], 404);
}
}

foreach ($row as $column => $value) {
if ($value!==null) {
if ($column==='preview_id') {
Expand Down
146 changes: 82 additions & 64 deletions templates/asset.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,109 @@
</div>
<div class="media-body">
<h4 class="media-heading">
<?php if (!$data['searchable']) { ?><del><?php } ?>
<?php echo esc($data['title']) ?>
<?php if (!$data['searchable']) { ?></del><?php } ?>
<small><?php echo esc($data['version_string']) ?></small>

<?php if (!$data['searchable']) { ?>
<span class="label label-default">Deleted</span>
<?php } ?>

<?php echo esc($data['title']) ?>
</h4>
<div class="asset-tags" style="margin: 8px 0;">
<span class="label label-primary"><?php echo esc($data['category']) ?></span>
<span class="label label-info"><?php echo esc(ucfirst(str_replace('_', ' ', $data['godot_version']))) ?></span>
<span class="label label-<?php echo raw([
'official' => 'danger',
'community' => 'success',
'testing' => 'default',
][$data['support_level']]) ?>"><?php echo esc(ucfirst($data['support_level'])) ?></span>
</h4>

<span class="label label-default"><?php echo esc($data['cost']) ?></span>
<?php if (!$data['searchable']) { ?>
<span class="label label-default">Hidden</span>
<?php } ?>
</div>
<p class="text-muted">
Submitted by user <a href="<?php echo raw($basepath) ?>/asset?user=<?php echo esc($data['author']) ?>" title="Search assets by '<?php echo esc($data['author']) ?>'"><?php echo esc($data['author']) ?></a>;
<?php echo esc($data['cost']) ?>;
<?php echo esc(explode(" ", $data['modify_date'])[0]) ?>
</p>
<p>
<?php echo nl2br(esc($data['description']), false) ?>
<b><?php echo esc($data['version_string']) ?></b> | <?php echo esc(explode(" ", $data['modify_date'])[0]) ?> by
<a href="<?php echo raw($basepath) ?>/asset?user=<?php echo esc($data['author']) ?>" title="Search assets by '<?php echo esc($data['author']) ?>'"><?php echo esc($data['author']) ?></a>
</p>
</div>
</div>
<hr/>
<p>
<a class="btn btn-default" href="<?php echo esc($data['browse_url']) ?>">
<i class="glyphicon glyphicon-folder-open"></i> View files
<p><?php echo nl2br(esc($data['description']), false) ?></p>
<hr/>
<div class="asset-links">
<a class="btn btn-primary" href="<?php echo esc($data['browse_url']) ?>">
<i class="glyphicon glyphicon-folder-open"></i>&nbsp; View files
</a>
<a class="btn btn-primary" href="<?php echo esc($data['download_url']) ?>">
<i class="glyphicon glyphicon-download"></i> Download
</a>
<?php if($data['issues_url'] != "") { ?>
<a class="btn btn-success" href="<?php echo esc($data['issues_url']) ?>">
<a class="btn btn-primary" href="<?php echo esc($data['issues_url']) ?>">
<i class="glyphicon glyphicon-check"></i> Submit an issue
</a>
<?php } ?>
<?php if(isset($user) && ($user['user_id'] == $data['author_id'] || $user['type'] >= $constants['user_type']['editor'])) { ?>
<a class="btn btn-success" href="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/edit">
<i class="glyphicon glyphicon-pencil"></i> Edit
</a>
<?php } ?>
<a class="btn btn-warning" href="<?php echo raw($basepath) ?>/asset/edit?asset=<?php echo url($data['asset_id']) ?>&amp;status=new+in_review+accepted+rejected">
<a class="btn btn-default" href="<?php echo raw($basepath) ?>/asset/edit?asset=<?php echo url($data['asset_id']) ?>&amp;status=new+in_review+accepted+rejected">
<i class="glyphicon glyphicon-list"></i> Recent Edits
</a>
</p>
</div>
<div class="asset-tools">
<?php if (isset($user) && (($user['type'] >= $constants['user_type']['editor']) || $user['user_id'] === $data['author_id'])) : ?>
<div class="panel panel-danger">
<div class="panel-heading">
Author tools
</div>
<div class="panel-body">
<?php if ($data['searchable']) { ?>
<form class="form" action="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/delete" method="post">
<?php include("_csrf.phtml") ?>
<p>The asset is currently <b>visible</b> in the library.</p>
<hr>
<div class="flex-container">
<button type="submit" class="btn btn-danger" onclick="return window.confirm('Do you really want to hide this asset?');">
<i class="glyphicon glyphicon-eye-close"></i> Hide in library
</button>
<a class="btn btn-success" href="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/edit">
<i class="glyphicon glyphicon-pencil"></i> Edit asset
</a>
</div>
</form>
<?php } else { ?>
<form class="form" action="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/undelete" method="post">
<?php include("_csrf.phtml") ?>
<p>The asset is currently <b>hidden</b> in the library.</p>
<hr>
<div class="flex-container">
<button type="submit" class="btn btn-warning" onclick="return window.confirm('Do you want to restore this asset?');">
<i class="glyphicon glyphicon-eye-open"></i> Restore to library
</button>
<a class="btn btn-success" href="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/edit">
<i class="glyphicon glyphicon-pencil"></i> Edit asset
</a>
</div>
</form>
<?php } ?>
</div>
</div>
<?php endif ?>
<?php if(isset($user) && ($user['type'] >= $constants['user_type']['moderator'])) { ?>
<div class="panel panel-danger">
<div class="panel-heading">
Admin tools
</div>
<div class="panel-body">
<form class="form" action="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/support_level" method="post">
<?php include("_csrf.phtml") ?>
<p><label for="support_level">Support level</label></p>
<div class="flex-container">
<select id="support_level" name="support_level" class="form-control">
<?php foreach($constants['support_level'] as $id => $name) if(is_int($id)) { ?>
<option value="<?php echo esc($name) ?>" <?php if($name == $data['support_level']) echo 'selected=""'; ?>>
<?php echo esc(ucfirst($name)) ?>
</option>
<?php } ?>
</select>
<button type="submit" class="btn btn-default">Change</button>
</div>
</form>
</div>
</div>
<?php } ?>
</div>
<hr/>
<div class="row">
<?php foreach($data['previews'] as $key => $preview) { ?>
Expand All @@ -70,41 +123,6 @@
<?php } ?>
</a>
</div>
<?php } ?>
<?php } ?>
</div>
<?php if(isset($user) && ($user['type'] >= $constants['user_type']['moderator'])) { ?>
<div class="panel panel-danger">
<div class="panel-heading">
Admin tools
</div>
<div class="panel-body">
<form class="form" style="margin-bottom: 1em;" action="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/support_level" method="post">
<?php include("_csrf.phtml") ?>
<div class="input-group">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">Change support level</button>
</span>
<select id="support_level" name="support_level" class="form-control">
<?php foreach($constants['support_level'] as $id => $name) if(is_int($id)) { ?>
<option value="<?php echo esc($name) ?>" <?php if($name == $data['support_level']) echo 'selected=""'; ?>>
<?php echo esc(ucfirst($name)) ?>
</option>
<?php } ?>
</select>
</div>
</form>
<?php if ($data['searchable']) { ?>
<form class="form" style="margin-bottom: 1em;" action="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/delete" method="post">
<?php include("_csrf.phtml") ?>
<button type="submit" class="btn btn-danger" onclick="javascript:return window.confirm('Do you really want to delete this asset?');">Remove from library</button>
</form>
<?php } else { ?>
<form class="form" style="margin-bottom: 1em;" action="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>/undelete" method="post">
<?php include("_csrf.phtml") ?>
<button type="submit" class="btn btn-info" onclick="javascript:return window.confirm('Do you want to restore this asset?');">Restore to library</button>
</form>
<?php } ?>
</div>
</div>
<?php } ?>
<?php include("_footer.phtml") ?>
7 changes: 6 additions & 1 deletion templates/assets.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@
<a href="<?php echo raw($basepath) . '/asset/' . url($asset['asset_id']) ?>" class="asset-header">
<img class="media-object" src="<?php echo esc($asset['icon_url']) ?>" alt="<?php echo esc($asset['title']) ?>'s icon" width=80 height=80>
<div class="asset-title">
<h4><?php echo esc($asset['title']) ?></h4>
<h4>
<?php if ($asset['searchable'] === '0') { ?><del><?php } ?>
<?php echo esc($asset['title']) ?>
<?php if ($asset['searchable'] === '0') { ?></del><?php } ?>
</h4>
<div class="asset-tags-container">
<div class="asset-tags">
<span class="label label-primary"><?php echo esc($asset['category']) ?></span>
Expand All @@ -117,6 +121,7 @@
'community' => 'success',
'testing' => 'default',
][$asset['support_level']]) ?>"><?php echo esc(ucfirst($asset['support_level'])) ?></span>
<?php if ($asset['searchable'] === '0') { ?><span class="label label-default">Hidden</span><?php } ?>
</div>
<div class="asset-tags">
<span class="label label-default"><?php echo esc($asset['cost']) ?></span>
Expand Down

0 comments on commit 0cacdb8

Please sign in to comment.