Files
godot-asset-library/templates/asset_edit.phtml
Bojidar Marinov afc9fc8c18 Remove download hashes (#209)
* Remove download hashes, as they caused too much hassle without much security

* Make usage of git commits compulsory for non-moderators

That way, we can be sure that users would download the asset as it was accepted, at least when working with large repository providers.
Note that moderators still need to be able to input invalid hashes when using the "Custom" provider; and allowing a bit of flexibility would help in the long run.
2020-04-14 23:08:14 +03:00

211 lines
10 KiB
PHTML

<?php include("_header.phtml") ?>
<?php $field_names = [
'title' => 'Title',
'description' => 'Description',
'category_id' => 'Category',
'cost' => 'License',
'download_provider' => 'Repository Provider',
'browse_url' => 'Repository Url',
'issues_url' => 'Issues Url',
'godot_version' => 'Godot version',
'version_string' => 'Version String',
'download_commit' => 'Download Commit',
'download_url' => 'Download Url (Computed)',
'icon_url' => 'Icon Url',
];
$preview_field_names = [
'type' => 'Type',
'link' => 'Image/Video URL',
'thumbnail' => 'Thumbnail',
]; ?>
<?php function output_field($data, $name, $categories = []) { ?>
<?php if (strpos($name, 'url') !== false || strpos($name, 'link') !== false || strpos($name, 'thumbnail') !== false) { ?>
<a href="<?php echo esc($data) ?>" rel="nofollow"><?php echo esc($data) ?></a>
<?php if ($name == 'icon_url') { ?>
<br><img src="<?php echo esc($data) ?>" width="80" height="80"></a>
<?php }?>
<?php if ($name == 'preview_link') { ?>
<br><img src="<?php echo esc($data) ?>" style="max-height:80px"></a>
<?php }?>
<?php if ($name == 'preview_thumbnail') { ?>
<br><img src="<?php echo esc($data) ?>" style="max-height:345px"></a>
<?php }?>
<?php } elseif($name == 'godot_version') { ?>
Godot <?php echo raw(ucfirst(str_replace('_', ' ', $data))) ?>
<?php } elseif($name == 'category_id') { ?>
<?php echo raw($categories[$data]['name']) ?>
<?php } elseif($name == 'description') { ?>
<?php echo nl2br(esc($data)) ?>
<?php } else { ?>
<?php echo esc($data) ?>
<?php } ?>
<?php } ?>
<h1>
<?php if(isset($data['original'])) { ?>
Edit of asset
<a href="<?php echo raw($basepath) ?>/asset/<?php echo raw($data['asset_id']) ?>">"<?php echo esc($data['original']['title']) ?>"</a>
<?php } else { ?>
Creation of asset
<?php if($data['asset_id'] != -1) { ?>
<a href="<?php echo raw($basepath) ?>/asset/<?php echo url($data['asset_id']) ?>">"<?php echo esc($data['title']) ?>"</a>
<?php } else { ?>
<a href="#">"<?php echo esc($data['title']) ?>"</a>
<?php } ?>
<?php } ?>
<span class="label label-<?php echo raw(['new' => 'info', 'in_review' => 'primary', 'rejected' => 'danger', 'accepted' => 'success'][$data['status']]) ?>">
<?php echo raw(ucfirst(str_replace('_', ' ', $data['status']))) ?>
</span>
</h1>
<?php if(isset($user) && $data['user_id'] == $user['user_id'] && $data['status'] == 'new') { ?>
<div class="form-group">
<a class="btn btn-success" href="<?php echo raw($basepath) ?>/asset/edit/<?php echo url($data['edit_id']) ?>/edit">Edit modifications</a>
</div>
<?php } ?>
<?php if(isset($data['warning'])) { ?>
<div class="alert alert-warning" role="alert">
<?php foreach ($data['warning'] as $warning) { ?>
<strong>Warning:</strong> <?php echo esc($warning) ?> <br><br>
<?php } ?>
<em>If you think that this warning is incorrect, you can always <a href="https://github.com/godotengine/asset-library/issues">open an issue</a>.</em>
</div>
<?php } ?>
<?php if(isset($user) && $data['user_id'] == $user['user_id'] && $data['status'] == 'new') { ?>
<div class="alert alert-info" role="alert">
<?php if($data['asset_id'] != -1) { ?>
This edit you made is currently pending approval by our moderators. <strong>When it is approved, changes would finally go live</strong>. To access this page again later, you can use the "View pending" button on the asset's page, or just use the "Feed" button in the toolbar. <!--You will be notified by email when decision is made.-->
<?php } else { ?>
This new asset is currently pending approval by our moderators. <strong>Only when it is approved, it would be searchable</strong>. To access this page again later, you can use the <em>"View pending"</em> button on the "My assets" page, or just use the "Feed" button in the toolbar. <!--You will be notified by email when decision is made.-->
<?php } ?>
</div>
<?php } ?>
<?php if($data['status'] == 'rejected') { ?>
<div class="alert alert-danger" role="alert">
This asset <?php if($data['asset_id'] != -1) echo 'edit ' ?>has been rejected. Reason: <?php echo esc($data['reason']) ?>
</div>
<?php } ?>
<table class="table table-bordered">
<tbody>
<tr>
<th>Property</th>
<?php if(isset($data['original'])) { ?>
<th style="min-width: 50%" class="text-center">Old/Current</th>
<?php } ?>
<th style="min-width: 50%" class="text-center">New/Edit</th>
</tr>
<?php foreach($field_names as $field => $name) { ?>
<tr>
<td>
<?php echo raw($name) ?>
</td>
<?php if(isset($data['original']) && $data[$field] === null) { ?>
<td colspan="2" class="text-center active">
<?php output_field($data['original'][$field], $field, $categories) ?>
</td>
<?php } else { ?>
<?php if(isset($data['original'])) { ?>
<td class="text-right danger">
<?php output_field($data['original'][$field], $field, $categories) ?>
</td>
<?php } ?>
<td class="text-left success">
<?php output_field($data[$field], $field, $categories) ?>
</td>
<?php } ?>
</tr>
<?php } ?>
<?php foreach($data['previews'] as $i => $preview) if(isset($preview['edit_preview_id'])) { ?>
<tr>
<th colspan="3" class="text-center">
Preview
<span class="label label-danger"><?php output_field(ucfirst($preview['operation']), 'preview_operation') ?></span>
</th>
</tr>
<?php foreach($preview_field_names as $field => $name) { ?>
<tr>
<td>
<?php echo raw($name) ?>
</td>
<?php if(isset($preview['original']) && $preview['operation'] != "remove" && ($preview[$field] === null || $preview[$field] === $preview['original'][$field])) { ?>
<td colspan="2" class="text-center active">
<?php output_field($preview['original'][$field], 'preview_' . $field, $categories) ?>
</td>
<?php } else { ?>
<?php if(isset($preview['original'])) { ?>
<?php if($preview['operation'] == "remove") { ?>
<td class="text-center danger" colspan="2">
<?php output_field($preview['original'][$field], 'preview_' . $field, $categories) ?>
</td>
<?php } else { ?>
<td class="text-right danger">
<?php output_field($preview['original'][$field], 'preview_' . $field, $categories) ?>
</td>
<td class="text-left success">
<?php output_field($preview[$field], 'preview_' . $field, $categories) ?>
</td>
<?php } ?>
<?php } else { ?>
<td class="text-center success" colspan="2">
<?php output_field($preview[$field], 'preview_' . $field, $categories) ?>
</td>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>
<?php if(isset($user)) { ?>
<?php if($user['type'] >= $constants['user_type']['moderator']) { ?>
<?php if($data['status'] == 'new') { ?>
<form class="form-inline" action="<?php echo raw($basepath) ?>/asset/edit/<?php echo url($data['edit_id']) ?>/review" method="post">
<?php include("_csrf.phtml") ?>
<button type="submit" class="btn btn-primary">Put in queue</button>
</form>
<?php } elseif($data['status'] == 'in_review') { ?>
<form class="form-inline" action="<?php echo raw($basepath) ?>/asset/edit/<?php echo url($data['edit_id']) ?>/accept" method="post">
<?php include("_csrf.phtml") ?>
<button type="submit" class="btn btn-success">Accept</button>
<div class="form-group panel">
<?php if($data['asset_id'] == -1) { ?>
<label class="control-label" for="support_level">Support level:</label>
<select id="support_level" name="support_level" class="form-control btn btn-default">
<?php foreach($constants['support_level'] as $id => $name) if(is_int($id)) { ?>
<option value="<?php echo esc($name) ?>" <?php if($name == 'community') echo 'selected=""'; ?>>
<?php echo esc(ucfirst($name)) ?>
</option>
<?php } ?>
</select>
<?php } ?>
</div>
</form>
<form class="form-inline" action="<?php echo raw($basepath) ?>/asset/edit/<?php echo url($data['edit_id']) ?>/reject" method="post">
<?php include("_csrf.phtml") ?>
<button type="submit" class="btn btn-danger">Reject</button>
<div class="form-group panel">
<label class="control-label" for="reason" required>Reason:</label>
<input type="text" class="form-control" id="reason" name="reason">
</div>
</form>
<?php } ?>
<?php } ?>
<?php } ?>
<?php include("_footer.phtml") ?>