diff --git a/index.php b/index.php index 4ab93be..395d9b4 100644 --- a/index.php +++ b/index.php @@ -34,7 +34,7 @@ $view->getEnvironment()->addGlobal('irc_channel', $container->get('settings')['irc-channel']); $view->getEnvironment()->addGlobal('donation_link', $container->get('settings')['donation-link']); $view->getEnvironment()->addGlobal('backend_url', $container->get('settings')['backend-url']); - $view->getEnvironment()->addGlobal('gameshort', $container->get('settings')['gameshort']); + // $view->getEnvironment()->addGlobal('gameshort', $container->get('settings')['gameshort']); $view->getEnvironment()->addGlobal('debug', $container->get('settings')['debug']); $view->getEnvironment()->addGlobal('update_interval', $container->get('settings')['update-interval']); $view->getEnvironment()->addGlobal('registration', $container->get('settings')['registration']); diff --git a/scripts/browse-list.js b/scripts/browse-list.js index 2f3cc50..dd9f9e5 100644 --- a/scripts/browse-list.js +++ b/scripts/browse-list.js @@ -13,9 +13,9 @@ function fillBrowseList() { browseURL = "/api/browse/" + gameshort + "/featured?site=" + page + "&count=30"; } when(getJSON(backend + '/api/users/current'), - getJSON(backend + '/api/mods/' + gameshort), - getJSON(backend + browseURL)). - done(function(currentUser, mods, browse) { + getJSON(backend + '/api/mods/' + gameshort), + getJSON(backend + browseURL)). + done(function(currentUser, mods, browse) { app = new Vue({ el: '#site', data: { @@ -52,10 +52,10 @@ function updateBrowseList() { if (url == "/browse/featured") { browseURL = "/api/browse/" + gameshort + "/featured?site=" + page + "&count=30"; } - swhen(getJSON(backend + '/api/users/current'), - getJSON(backend + '/api/mods/' + gameshort), - getJSON(backend + browseURL)). - done(function(currentUser, mods, browse) { + when(getJSON(backend + '/api/users/current'), + getJSON(backend + '/api/mods/' + gameshort), + getJSON(backend + browseURL)). + done(function(currentUser, mods, browse) { app.$data.currentUser = currentUser.error ? null : currentUser.data; app.$data.mods = mods; app.$data.browse = browse; diff --git a/scripts/create.js b/scripts/create.js index e30ec50..f781262 100644 --- a/scripts/create.js +++ b/scripts/create.js @@ -1,7 +1,7 @@ function fillCreate() { when(getJSON(backend + '/api/users/current'), - getJSON(backend + '/api/games/' + gameshort + '/versions')). - done(function(currentUser, gameversions) { + getJSON(backend + '/api/games/' + gameshort + '/versions')). + done(function(currentUser, gameversions) { if (currentUser.error) { window.location.href = "{{ path_for('accounts.login') }}"; return; @@ -39,8 +39,8 @@ function fillCreate() { function updateCreate() { when(getJSON(backend + '/api/users/current'), - getJSON(backend + '/api/games/' + gameshort + '/versions')). - done(function(currentUser, gameversions) { + getJSON(backend + '/api/games/' + gameshort + '/versions')). + done(function(currentUser, gameversions) { if (currentUser.error) { window.location.href = "{{ path_for('accounts.login') }}"; return; @@ -119,7 +119,7 @@ function onSubmitClick() { createMod(name, gameshort, shortDescription, license, version, gameVersion, zipFile, function(i, id, data) { $('#progress').removeClass('active'); if (!data.error) { - window.location.href = `{{ path_for("mod.view", {"id": "${mod.id}", "name": "${mod.name}"}) }}`; + window.location.href = `{{ path_for("mod.view", {"gameshort": "${gameshort}", "id": "${mod.id}", "name": "${mod.name}"}) }}`; return; } else { $('#error-alert').removeClass('hidden'); diff --git a/scripts/index.js b/scripts/game.js similarity index 70% rename from scripts/index.js rename to scripts/game.js index e942409..58ad29c 100644 --- a/scripts/index.js +++ b/scripts/game.js @@ -1,9 +1,9 @@ -function fillIndex() { +function fillGame() { when(getJSON(backend + '/api/users/current'), - getJSON(backend + '/api/mods/' + gameshort), - getJSON(backend + '/api/users'), - getJSON(backend + '/api/browse/' + gameshort)). - done(function(currentUser, mods, users, browse) { + getJSON(backend + '/api/mods/' + gameshort), + getJSON(backend + '/api/users'), + getJSON(backend + '/api/browse/' + gameshort)). + done(function(currentUser, mods, users, browse) { app = new Vue({ el: '#site', data: { @@ -25,17 +25,17 @@ function fillIndex() { }, delimiters: ['${', '}'] }); - window.setInterval(updateIndex, update_interval); + window.setInterval(updateGame, update_interval); $.loadingBlockHide(); }); } -function updateIndex() { +function updateGame() { when(getJSON(backend + '/api/users/current'), - getJSON(backend + '/api/mods/' + gameshort), - getJSON(backend + '/api/users'), - getJSON(backend + '/api/browse/' + gameshort)) - done(function(currentUser, mods, users, browse) { + getJSON(backend + '/api/mods/' + gameshort), + getJSON(backend + '/api/users'), + getJSON(backend + '/api/browse/' + gameshort)) + done(function(currentUser, mods, users, browse) { app.$data.currentUser = currentUser.error ? null : currentUser.data; app.$data.mods = mods; app.$data.users = users; diff --git a/scripts/sdb.js b/scripts/sdb.js index cadaf28..afc84ce 100644 --- a/scripts/sdb.js +++ b/scripts/sdb.js @@ -148,11 +148,11 @@ function followMod(user, mod, callback) { window.location.href = "path_for('register')"; return; } - getJSON(backend + '/api/mods/' + gameshort + '/' + mod.id + '/follow', callback) + getJSON(backend + '/api/mods/' + mod.game_short + '/' + mod.id + '/follow', callback) } function unfollowMod(mod, callback) { - getJSON(backend + '/api/mods/' + gameshort + '/' + mod.id + '/unfollow', callback); + getJSON(backend + '/api/mods/' + mod.game_short + '/' + mod.id + '/unfollow', callback); } function hasPermission(permission, pub, params, callback) { @@ -267,7 +267,7 @@ function createMod(name, gameshort, shortDescription, license, version, gameVers } function updateMod(mod, version, gameVersion, notifyFollowers, isBeta, changelog, _zipFile, callback) { - postJSON(backend + '/api/mods/' + gameshort + '/' + mod.id + '/versions', { + postJSON(backend + '/api/mods/' + mod.game_short + '/' + mod.id + '/versions', { 'version': version, 'game-version': gameVersion, 'notify-followers': notifyFollowers, diff --git a/scripts/update.js b/scripts/update.js index 9589379..44d4ea7 100644 --- a/scripts/update.js +++ b/scripts/update.js @@ -109,7 +109,7 @@ function onSubmitClick(mod) { updateMod(mod, version, gameVersion, notifyFollowers, isBeta, changelog, zipFile, function(i, data) { $('#progress').removeClass('active'); if (!data.error) { - window.location.href = `{{ path_for("mod.view", {"id": "${mod.id}", "name": "${mod.name}"}) }}`;W + window.location.href = `{{ path_for("mod.view", {"gameshort": "${gameshort}", "id": "${mod.id}", "name": "${mod.name}"}) }}`;W return; } else { $('#error-alert').removeClass('hidden'); diff --git a/scripts/utils.js b/scripts/utils.js index 708c4c7..b3680c1 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -15,7 +15,7 @@ Vue.component('mod-box', {
\
KSP ${mod.default_version.gameversion.friendly_version}
\
Following
\ - ", "name": ""}) }}\'.replace(//, mod.id).replace(//, mod.name)">\ + ", "id": "", "name": ""}) }}\'.replace(//, mod.game_short).replace(//, mod.id).replace(//, mod.name)">\
\
\
\ diff --git a/scripts/view-profile.js b/scripts/view-profile.js index 9f68568..35650de 100644 --- a/scripts/view-profile.js +++ b/scripts/view-profile.js @@ -4,11 +4,11 @@ function fillViewProfile() { window.location.href = "{{ path_for('not-found') }}"; } when(getJSON(backend + '/api/users/current'), - hasPermission('user-edit', false, {'userid': user_id}), - hasPermission('admin-impersonate', true, {'userid': user_id}), - hasPermission('admin-confirm', true, {}), - hasPermission('view-users-full', false, {})). - done(function (currentUser, editable, canImpersonate, canConfirm, viewFull) { + hasPermission('user-edit', false, {'userid': user_id}), + hasPermission('admin-impersonate', true, {'userid': user_id}), + hasPermission('admin-confirm', true, {}), + hasPermission('view-users-full', false, {})). + done(function (currentUser, editable, canImpersonate, canConfirm, viewFull) { app = new Vue({ el: '#site', data: { @@ -42,11 +42,11 @@ function updateViewProfile() { window.location.href = "{{ path_for('not-found') }}"; } when(getJSON(backend + '/api/users/current'), - hasPermission('user-edit', false, {'userid': user_id}), - hasPermission('admin-impersonate', true, {'userid': user_id}), - hasPermission('admin-confirm', true, {}), - hasPermission('view-users-full', false, {})). - done(function (currentUser, editable, canImpersonate, canConfirm, viewFull) { + hasPermission('user-edit', false, {'userid': user_id}), + hasPermission('admin-impersonate', true, {'userid': user_id}), + hasPermission('admin-confirm', true, {}), + hasPermission('view-users-full', false, {})). + done(function (currentUser, editable, canImpersonate, canConfirm, viewFull) { app.$data.currentUser = currentUser.error ? null : currentUser.data; app.$data.user = user.data; app.$data.editable = editable; diff --git a/src/anonymus.php b/src/anonymus.php index 95bce19..a5707d7 100644 --- a/src/anonymus.php +++ b/src/anonymus.php @@ -1,9 +1,18 @@ get('/', function($request, $response) { - return $this->view->render($response, 'templates/index.html'); + // return $this->view->render($response, 'templates/index.html'); + // TODO: Add index page + $gameshort = $this->get('settings')['gameshort']; + return $response->withRedirect("/{$gameshort}", 302); })->setName('index'); +$app->get('/{gameshort}', function($request, $response, $args) { + return $this->view->render($response, 'templates/game.html' [ + 'gameshort' => $args['gameshort'] + ]); +})->setName('game'); + $app->get('/privacy', function($request, $response) { return $this->view->render($response, 'templates/privacy.html'); })->setName('privacy'); diff --git a/src/browse.php b/src/browse.php index 3962406..39745c2 100644 --- a/src/browse.php +++ b/src/browse.php @@ -1,6 +1,6 @@ get('/browse/new[/{page}]', function($request, $response, $args) { +$app->get('/{gameshort}/browse/new[/{page}]', function($request, $response, $args) { $page = ""; if (isset($args['page'])) { $page = $args['page']; @@ -8,6 +8,7 @@ $page = '1'; } return $this->view->render($response, 'templates/browse-list.html', [ + 'gameshort' => $args['gameshort'], 'page' => $page, 'url' => '/browse/new', 'name' => 'Newest Mods', @@ -16,7 +17,7 @@ ]); })->setName('browse.new'); -$app->get('/browse/updated[/{page}]', function($request, $response, $args) { +$app->get('/{gameshort}/browse/updated[/{page}]', function($request, $response, $args) { $page = ""; if (isset($args['page'])) { $page = $args['page']; @@ -24,6 +25,7 @@ $page = '1'; } return $this->view->render($response, 'templates/browse-list.html', [ + 'gameshort' => $args['gameshort'], 'page' => $page, 'url' => '/browse/updated', 'name' => 'Recently Updated Mods', @@ -32,7 +34,7 @@ ]); })->setName('browse.updated'); -$app->get('/browse/top[/{page}]', function($request, $response, $args) { +$app->get('/{gameshort}/browse/top[/{page}]', function($request, $response, $args) { $page = ""; if (isset($args['page'])) { $page = $args['page']; @@ -40,6 +42,7 @@ $page = '1'; } return $this->view->render($response, 'templates/browse-list.html', [ + 'gameshort' => $args['gameshort'], 'page' => $page, 'url' => '/browse/top', 'name' => 'Popular Mods', @@ -48,7 +51,7 @@ ]); })->setName('browse.top'); -$app->get('/browse/featured[/{page}]', function($request, $response, $args) { +$app->get('/{gameshort}/browse/featured[/{page}]', function($request, $response, $args) { $page = ""; if (isset($args['page'])) { $page = $args['page']; @@ -56,6 +59,7 @@ $page = '1'; } return $this->view->render($response, 'templates/browse-list.html', [ + 'gameshort' => $args['gameshort'], 'page' => $page, 'url' => '/browse/featured', 'name' => 'Featured Mods', diff --git a/src/mods.php b/src/mods.php index 934744d..88e9a58 100644 --- a/src/mods.php +++ b/src/mods.php @@ -1,22 +1,35 @@ get('/mod/{id}[/{name}]', function($request, $response, $args) { + $backend_url = $this->get('settings')['backend-url']; + $json = file_get_contents("http://{$backend_url}/api/adapter/mods/{$$args['id']}"); + $mod = json_decode($json, true); + + return $response->withRedirect("{$mod['data']['game_short']}/mod/{$random_mod['data']['id']}/{$random_mod['data']['name']}", 302); +})->setName('mod.view.adapter'); + +$app->get('/{gameshort}/mod/{id}[/{name}]', function($request, $response, $args) { return $this->view->render($response, 'templates/mod.html', [ - 'modid' => $args['id'] + 'modid' => $args['id'], + 'gameshort' => $args['gameshort'] ]); })->setName('mod.view'); -$app->get('/random', function($request, $response, $args) { +$app->get('/{gameshort}/random', function($request, $response, $args) { $backend_url = $this->get('settings')['backend-url']; - $gameshort = $this->get('settings')['gameshort']; + // $gameshort = $this->get('settings')['gameshort']; + // TODO(TMSP): Add an general API for this (without gameshort as an URL param) + $gameshort = $args['gameshort']; $json = file_get_contents("http://{$backend_url}/api/mods/{$gameshort}/random"); $random_mod = json_decode($json, true); return $response->withRedirect("mod/{$random_mod['data']['id']}/{$random_mod['data']['name']}", 302); })->setName('mod.random'); -$app->get('/create/mod', function($request, $response, $args) { - return $this->view->render($response, 'templates/create.html'); +$app->get('/{gameshort}/create/mod', function($request, $response, $args) { + return $this->view->render($response, 'templates/create.html', [ + 'gameshort' => $args['gameshort'] + ]); })->setName('mod.create'); $app->get('/update/mod/{id}[/{name}]', function($request, $response, $args) { diff --git a/templates/browse-list.html b/templates/browse-list.html index 58a39e9..0bfb7d8 100644 --- a/templates/browse-list.html +++ b/templates/browse-list.html @@ -1,4 +1,5 @@ {% extends "templates/layout.html" %} + {% block styles %} @@ -6,17 +7,20 @@ {% endblock %} + {% block scripts %} {% endblock %} + {% block title %} {% if search == "true" %} Search {{ site_name }} @@ -24,6 +28,7 @@ {{ name }} on {{ site_name }} {% endif %} {% endblock %} + {% block search %} {% endblock %} + {% block body %}
diff --git a/templates/create.html b/templates/create.html index ee34f6c..8f523e1 100644 --- a/templates/create.html +++ b/templates/create.html @@ -8,6 +8,7 @@ {% block scripts %} {% endblock %} diff --git a/templates/index.html b/templates/game.html similarity index 98% rename from templates/index.html rename to templates/game.html index 52d0765..94580d5 100644 --- a/templates/index.html +++ b/templates/game.html @@ -7,9 +7,10 @@ {% endblock %} {% block scripts %} - + {% endblock %} {% block body %} diff --git a/templates/layout.html b/templates/layout.html index d7d4335..65ad890 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -37,14 +37,19 @@ - - - -
+ + + + +
+
+ +
+
+
{% block nav %}
@@ -231,7 +232,7 @@

Outdated Mod

Author Tools

These are the tools you can use to manage your mod listing. You can also - view your mod as if you were not logged + view your mod as if you were not logged in.

@@ -289,7 +290,7 @@

Version ${v.friendly_version} for Kerbal Space Program ${v.gameversio

No changelog provided

- + Download