diff --git a/.editorconfig b/.editorconfig index ccc4f0d..4506a5e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,7 @@ root = true [*] end_of_line = lf insert_final_newline = true +trim_trailing_whitespace = true charset = utf-8 # CSS diff --git a/src/Helpers/Utils.php b/src/Helpers/Utils.php index ea73ad3..8c639d6 100644 --- a/src/Helpers/Utils.php +++ b/src/Helpers/Utils.php @@ -19,37 +19,37 @@ class Utils if (is_int($provider)) { $provider = $this->c->constants['download_provider'][$provider]; } - $warning_suffix = "Please, ensure that the URL and the repository provider are, indeed, correct."; + $warning_suffix = "Please, ensure that the URL and the repository provider are correct."; $light_warning_suffix = "Please, doublecheck that the URL and the repository provider are correct."; switch ($provider) { case 'GitHub': if (sizeof(preg_grep('/^https:\/\/github\.com\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) { - $warning = "\"$repo_url\" doesn't look correct; it should be similar to \"https://github.com//\". $warning_suffix"; + $warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"https://github.com//\". $warning_suffix\n"; } return "$repo_url/archive/$commit.zip"; case 'GitLab': if (sizeof(preg_grep('/^https:\/\/(gitlab\.com|[^\/]+)\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) { - $warning = "\"$repo_url\" doesn't look correct; it should be similar to \"https:////\". $warning_suffix"; + $warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"https:////\". $warning_suffix\n"; } elseif (sizeof(preg_grep('/^https:\/\/(gitlab\.com)\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) { - $warning = "\"$repo_url\" might not be correct; it should be similar to \"https://gitlab.com//\", unless the asset is hosted on a custom instance of GitLab. $light_warning_suffix"; + $warning .= "\"$repo_url\" might not be correct; it should be similar to \"https://gitlab.com//\", unless the asset is hosted on\n a custom instance of GitLab. $light_warning_suffix"; } return "$repo_url/repository/archive.zip?ref=$commit"; case 'BitBucket': if (sizeof(preg_grep('/^https:\/\/bitbucket\.org\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) { - $warning = "\"$repo_url\" doesn't look correct; it should be similar to \"https://bitbucket.org//\". $warning_suffix"; + $warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"https://bitbucket.org//\". $warning_suffix\n"; } return "$repo_url/get/$commit.zip"; case 'Gogs': if (sizeof(preg_grep('/^https?:\/\/[^\/]+?\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) { - $warning = "\"$repo_url\" doesn't look correct; it should be similar to \"http:////\". $warning_suffix"; + $warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"http:////\". $warning_suffix\n"; } - $warning = "Since Gogs might be self-hosted, we can't be sure that \"$repo_url\" is a valid Gogs URL. $light_warning_suffix"; + $warning .= "Since Gogs might be self-hosted, we can't be sure that \"$repo_url\" is a valid Gogs URL. $light_warning_suffix\n"; return "$repo_url/archive/$commit.zip"; case 'cgit': if (sizeof(preg_grep('/^https?:\/\/[^\/]+?\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) { - $warning = "\"$repo_url\" doesn't look correct; it should be similar to \"http:////\". $warning_suffix"; + $warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"http:////\". $warning_suffix\n"; } - $warning = "Since cgit might be self-hosted, we can't be sure that \"$repo_url\" is a valid cgit URL. $light_warning_suffix"; + $warning .= "Since cgit might be self-hosted, we can't be sure that \"$repo_url\" is a valid cgit URL. $light_warning_suffix\n"; return "$repo_url/snapshot/$commit.zip"; default: return "$repo_url/$commit.zip"; // Obviously incorrect, but we would like to have some default case... @@ -76,8 +76,8 @@ class Utils public function getFormattedGodotVersion($internal_id, &$warning=null) { - if ($internal_id == 0) { - $warning = "Setting Godot version as \"unknown\" is not recommended, as it would prevent people from finding your asset easily."; + if ($internal_id == $this->c->constants['special_godot_versions']['unknown']) { + $warning .= "Setting Godot version as \"unknown\" is not recommended, as it would prevent people from finding your asset easily.\n"; } if (isset($this->c->constants['special_godot_versions'][$internal_id])) { return $this->c->constants['special_godot_versions'][$internal_id]; @@ -124,7 +124,7 @@ class Utils return false; } - public function errorResponseIfNotOwner($currentStatus, &$response, $user, $asset_id, $message = 'You are not authorized to do this') + public function errorResponseIfNotOwnerOrLevel($currentStatus, &$response, $user, $asset_id, $required_level_name, $message = 'You are not authorized to do this') { if($user === false || $currentStatus) { return true; @@ -141,8 +141,7 @@ class Utils $asset = $query->fetch(); if($asset['author_id'] != $user['user_id']) { - $response = $response->withJson(['error' => $message], 403); - return true; + return $this->errorResponseIfNotUserHasLevel(false, $response, $user, $required_level_name, $message); } return false; diff --git a/src/constants.php b/src/constants.php index bb5db77..6167970 100644 --- a/src/constants.php +++ b/src/constants.php @@ -54,7 +54,7 @@ return $constants = [ ], 'special_godot_versions' => double_map([ 0 => 'unknown', - 9999999 => 'custom' + 9999999 => 'custom_build' ]), 'common_godot_versions' => [ '1.0', @@ -64,6 +64,6 @@ return $constants = [ '2.2', '3.0', //'3.1' 'unknown', - 'custom', + 'custom_build', ] ]; diff --git a/src/middleware.php b/src/middleware.php index fe510f8..7885420 100644 --- a/src/middleware.php +++ b/src/middleware.php @@ -58,7 +58,6 @@ if (FRONTEND) { $result = []; } - if (isset($result['url'])) { $response = new \Slim\Http\Response(303); $response = $response->withHeader('Location', $request->getUri()->getBasePath() . '/' . $result['url']); diff --git a/src/queries.php b/src/queries.php index b8fcdb4..c923e7f 100644 --- a/src/queries.php +++ b/src/queries.php @@ -100,7 +100,10 @@ return [ 'set_support_level' => 'UPDATE `as_assets` SET support_level=:support_level - WHERE asset_id=:asset_id' + WHERE asset_id=:asset_id', + + 'delete' => 'UPDATE `as_assets` SET searchable=FALSE WHERE asset_id=:asset_id', + 'undelete' => 'UPDATE `as_assets` SET searchable=TRUE WHERE asset_id=:asset_id' ], 'asset_edit' => [ 'get_one' => 'SELECT edit_id, `as_asset_edits`.asset_id, user_id, title, description, category_id, godot_version, version_string, @@ -173,8 +176,6 @@ return [ WHERE edit_id=:edit_id AND edit_preview_id=:edit_preview_id', 'set_asset_id' => 'UPDATE `as_asset_edits` SET asset_id=:asset_id WHERE edit_id=:edit_id', - 'set_status_and_reason' => 'UPDATE `as_asset_edits` SET status=:status, reason=:reason WHERE edit_id=:edit_id', - 'delete' => 'UPDATE `as_assets` SET searchable=FALSE WHERE asset_id=:asset_id', - 'undelete' => 'UPDATE `as_assets` SET searchable=TRUE WHERE asset_id=:asset_id' + 'set_status_and_reason' => 'UPDATE `as_asset_edits` SET status=:status, reason=:reason WHERE edit_id=:edit_id' ] ]; diff --git a/src/routes/asset.php b/src/routes/asset.php index bd83741..73e43dd 100644 --- a/src/routes/asset.php +++ b/src/routes/asset.php @@ -259,11 +259,11 @@ $app->post('/asset/{id:[0-9]+}/delete', function ($request, $response, $args) { $body = $request->getParsedBody(); $error = $this->utils->ensureLoggedIn(false, $response, $body, $user); - $error = $this->utils->errorResponseIfNotOwner($error, $response, $user, $args['id']); + $error = $this->utils->errorResponseIfNotOwnerOrLevel($error, $response, $user, $args['id'], 'moderator'); if($error) return $response; - $query = $this->queries['asset_edit']['delete']; + $query = $this->queries['asset']['delete']; $query->bindValue(':asset_id', (int) $args['id'], PDO::PARAM_INT); $query->execute(); @@ -272,7 +272,7 @@ $app->post('/asset/{id:[0-9]+}/delete', function ($request, $response, $args) { return $response->withJson([ 'changed' => true, - 'url' => 'asset/', + 'url' => 'asset/' . $args['id'], ], 200); }); @@ -284,11 +284,11 @@ $app->post('/asset/{id:[0-9]+}/undelete', function ($request, $response, $args) $body = $request->getParsedBody(); $error = $this->utils->ensureLoggedIn(false, $response, $body, $user); - $error = $this->utils->errorResponseIfNotOwner($error, $response, $user, $args['id']); + $error = $this->utils->errorResponseIfNotOwnerOrLevel($error, $response, $user, $args['id'], 'moderator'); if($error) return $response; - $query = $this->queries['asset_edit']['undelete']; + $query = $this->queries['asset']['undelete']; $query->bindValue(':asset_id', (int) $args['id'], PDO::PARAM_INT); $query->execute(); @@ -297,6 +297,6 @@ $app->post('/asset/{id:[0-9]+}/undelete', function ($request, $response, $args) return $response->withJson([ 'changed' => true, - 'url' => 'asset/', + 'url' => 'asset/' . $args['id'], ], 200); }); diff --git a/src/routes/asset_edit.php b/src/routes/asset_edit.php index 29d8e0e..e1148ce 100644 --- a/src/routes/asset_edit.php +++ b/src/routes/asset_edit.php @@ -88,7 +88,7 @@ function _insert_asset_edit_fields($c, $error, &$response, $query, $body, $requi } } if (isset($body['godot_version'])) { - $body['godot_version'] = $c->utils->getUnformattedGodotVersion($body['godot_version']); + $body['godot_version'] = (string) $c->utils->getUnformattedGodotVersion($body['godot_version']); } foreach ($c->constants['asset_edit_fields'] as $i => $field) { @@ -350,6 +350,8 @@ $get_edit = function ($request, $response, $args) { return $response; } + $warning = null; + $output = $query->fetchAll(); $previews = []; @@ -381,8 +383,6 @@ $get_edit = function ($request, $response, $args) { $asset_edit['status'] = $this->constants['edit_status'][(int) $value]; } elseif ($column==='download_provider') { $asset_edit['download_provider'] = $this->constants['download_provider'][(int) $value]; - } elseif ($column==='godot_version') { - $asset_edit['godot_version'] = $this->utils->getFormattedGodotVersion((int) $value); } else { $asset_edit[$column] = $value; } @@ -427,7 +427,7 @@ $get_edit = function ($request, $response, $args) { $asset_edit['download_commit'] ?: $asset_edit['original']['download_commit'], $warning ); - if ($asset_edit['issues_url'] == '') { + if ($asset_edit['issues_url'] === '') { $asset_edit['issues_url'] = $this->utils->getDefaultIssuesUrl( $asset_edit['browse_url'] ?: $asset_edit['original']['browse_url'], $asset_edit['download_provider'] ?: $asset_edit['original']['download_provider'] @@ -437,15 +437,20 @@ $get_edit = function ($request, $response, $args) { $asset_edit['download_url'] = null; } - $asset_edit['original']['download_url'] = $this->utils->getComputedDownloadUrl($asset_edit['original']['browse_url'], $asset_edit['original']['download_provider'], $asset_edit['original']['download_commit'], $warning); + if ($asset_edit['godot_version'] != null) { + $asset_edit['godot_version'] = $this->utils->getFormattedGodotVersion((int) $asset_edit['godot_version'], $warning); + } + + $asset_edit['original']['download_url'] = $this->utils->getComputedDownloadUrl($asset_edit['original']['browse_url'], $asset_edit['original']['download_provider'], $asset_edit['original']['download_commit']); if ($asset_edit['original']['issues_url'] == '') { $asset_edit['original']['issues_url'] = $this->utils->getDefaultIssuesUrl($asset_edit['original']['browse_url'], $asset_edit['original']['download_provider']); } } else { $asset_edit['download_url'] = $this->utils->getComputedDownloadUrl($asset_edit['browse_url'], $asset_edit['download_provider'], $asset_edit['download_commit'], $warning); + $asset_edit['godot_version'] = $this->utils->getFormattedGodotVersion((int) $asset_edit['godot_version'], $warning); - if ($asset_edit['issues_url'] == '') { + if ($asset_edit['issues_url'] === '') { $asset_edit['issues_url'] = $this->utils->getDefaultIssuesUrl($asset_edit['browse_url'], $asset_edit['download_provider']); } } diff --git a/style/base.css b/style/base.css index 754a020..536cf0a 100644 --- a/style/base.css +++ b/style/base.css @@ -22,3 +22,12 @@ } } } + +.required_mark::after { + content: ' *'; + color: #d9534f; +} +.media-object { + overflow: hidden; + text-overflow: ellipsis; +} diff --git a/templates/_asset_fields.phtml b/templates/_asset_fields.phtml index 65f0b97..64bfd65 100644 --- a/templates/_asset_fields.phtml +++ b/templates/_asset_fields.phtml @@ -4,6 +4,7 @@ $_asset_values = array_merge([ 'title' => '', 'category_id' => '0', + 'godot_version' => 'unknown', 'version_string' => '', 'download_provider' => '0', 'download_commit' => '', @@ -16,37 +17,38 @@ $_asset_values = array_merge([ ], $_asset_values); ?>
- +
- Set the name of your asset + The name of the asset
- -
- -
-
- -
- +
- + $type_name) if(is_int($type)) { ?> + + $category) if($category['type'] == $type) { ?> + + + + + + The category the asset belongs to +
+
+
+ +
+ @@ -55,90 +57,92 @@ $_asset_values = array_merge([
- -
- - Set the version of your asset -
+ +
+ + The version of the asset +
- -
- - We really need to know where your repository is hosted in order to compute the final download URL. If your Git repository provider is missing, you might like to open an issue about it. -
+ +
+ + We need to know where your repository is hosted in order to compute the final download URL. If your Git repository provider is missing, you might like to open an issue about it. +
- -
- - Set the url to browse the asset's files (webpage). Should be similar to https://github.com/<user>/<project> (Might be different depending on your "provider") -
+ +
+ + The url to browse the asset's files (webpage). Should be similar to https://github.com/<user>/<project> (Might be different depending on your "provider") +
- -
- - Set the url to issues list of the asset. Should be similar to https://github.com/<user>/<project>/issues (Might be different depending on your "provider"). If you use your provider's issue list, you can leave it empty. -
+ +
+ + The url to issues list of the asset. Should be similar to https://github.com/<user>/<project>/issues (Might be different depending on your "provider"). If you use your provider's issue list, you can leave it empty. +
- -
- - Set the commit or tag to download the asset. Should be similar to b1d3172f89b86e52465a74f63a74ac84c491d3e1 or v1.0. The final download url would be computed from this. -
+ +
+ + The commit or tag to download the asset. Should be similar to b1d3172f89b86e52465a74f63a74ac84c491d3e1 or v1.0. The final download url would be computed from this. +
- -
- - Set the url to the asset's icon (png or jpg image) -
+ +
+ + The url to the asset's icon (png or jpg image) +
- -
- -
+ +
+ + The license under which the asset is available. Check opensource.org for a more detailed description of each.
In case an OSI-approved license you are using is missing, you might open an issue about it.
+
- -
- -
+ +
+ + The description which would be visible on the asset page +
'image', 'link' => '', 'thumbnail' => ''] + else $preview = ['type' => 'image', 'link' => '', 'thumbnail' => '']; ?>
@@ -189,34 +193,34 @@ $_asset_values = array_merge([
-
+
- -
- -
-
- -
- +
- +
- +
- + +
+
+ +
+ +
+
diff --git a/templates/asset.phtml b/templates/asset.phtml index 599fe61..f9095cf 100644 --- a/templates/asset.phtml +++ b/templates/asset.phtml @@ -5,13 +5,21 @@

+ + + + + + Deleted + + - + +
- +
+ +
+ + +
+ +
+ + +
+

Sha256 Hash:


diff --git a/templates/asset_edit.phtml b/templates/asset_edit.phtml index 0a8837a..2d7bec5 100644 --- a/templates/asset_edit.phtml +++ b/templates/asset_edit.phtml @@ -31,6 +31,8 @@ $preview_field_names = [
+ + @@ -46,7 +48,11 @@ $preview_field_names = [ "" Creation of asset - "" + + "" + + "" + @@ -57,6 +63,18 @@ $preview_field_names = [ + + + + + + + - - - - diff --git a/templates/asset_edits.phtml b/templates/asset_edits.phtml index 4802838..fac79e4 100644 --- a/templates/asset_edits.phtml +++ b/templates/asset_edits.phtml @@ -1,7 +1,7 @@ -
+