Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
14 changes: 7 additions & 7 deletions scripts/browse-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions scripts/create.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
22 changes: 11 additions & 11 deletions scripts/index.js → scripts/game.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions scripts/sdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Vue.component('mod-box', {
<div class="thumbnail">\
<div class="ksp-update">KSP ${mod.default_version.gameversion.friendly_version}</div>\
<div class=\"following-mod\" v-if=\"currentUser != null && currentUser.following.hasObject(mod.id)\">Following</div>\
<a v-bind:href="\'{{ path_for("mod.view", {"id": "<id>", "name": "<name>"}) }}\'.replace(/<id>/, mod.id).replace(/<name>/, mod.name)">\
<a v-bind:href="\'{{ path_for("mod.view", {"gameshort": "<gameshort>", "id": "<id>", "name": "<name>"}) }}\'.replace(/<gameshort>/, mod.game_short).replace(/<id>/, mod.id).replace(/<name>/, mod.name)">\
<div class="header-img" v-if="mod.meta.hasOwnProperty(\'background\')" v-bind:style="\'background-image: url(//{{ backend_url }}\' + mod.meta[\'background\'].replace(/.jpg/g, \'_thumb.jpg\').replace(/.png/g, \'_thumb.png\') + \');\'"></div>\
<div class="header-img" v-else style="background-image: url({{ path_for('images', {'filename': 'background.png'}) }});"></div>\
</a>\
Expand Down
20 changes: 10 additions & 10 deletions scripts/view-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/anonymus.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

$app->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');
Expand Down
12 changes: 8 additions & 4 deletions src/browse.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

$app->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'];
} else {
$page = '1';
}
return $this->view->render($response, 'templates/browse-list.html', [
'gameshort' => $args['gameshort'],
'page' => $page,
'url' => '/browse/new',
'name' => 'Newest Mods',
Expand All @@ -16,14 +17,15 @@
]);
})->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'];
} else {
$page = '1';
}
return $this->view->render($response, 'templates/browse-list.html', [
'gameshort' => $args['gameshort'],
'page' => $page,
'url' => '/browse/updated',
'name' => 'Recently Updated Mods',
Expand All @@ -32,14 +34,15 @@
]);
})->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'];
} else {
$page = '1';
}
return $this->view->render($response, 'templates/browse-list.html', [
'gameshort' => $args['gameshort'],
'page' => $page,
'url' => '/browse/top',
'name' => 'Popular Mods',
Expand All @@ -48,14 +51,15 @@
]);
})->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'];
} else {
$page = '1';
}
return $this->view->render($response, 'templates/browse-list.html', [
'gameshort' => $args['gameshort'],
'page' => $page,
'url' => '/browse/featured',
'name' => 'Featured Mods',
Expand Down
23 changes: 18 additions & 5 deletions src/mods.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
<?php

$app->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) {
Expand Down
12 changes: 9 additions & 3 deletions templates/browse-list.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
{% extends "templates/layout.html" %}

{% block styles %}
<link rel="stylesheet" type="text/css" href="{{ path_for('styles', {'filename': 'index.css'}) }}" />
<link rel="stylesheet" type="text/css" href="{{ path_for('styles', {'filename': 'stylesheet.css'}) }}" />
<link rel="stylesheet" type="text/css" href="{{ path_for('styles', {'filename': 'typeahead.css'}) }}" />
<link rel="stylesheet" type="text/css" href="{{ path_for('styles', {'filename': 'navigation.css'}) }}" />
<link rel="stylesheet" type="text/css" href="{{ path_for('styles', {'filename': 'listing.css'}) }}" />
{% endblock %}

{% block scripts %}
<script type="text/javascript">
var page = {{ page }};
var url = "{{ url }}";
var search = {{ search }};
var gameshort = "{{ gameshort }}";
var page = {{ page }};
var url = "{{ url }}";
var search = {{ search }};
</script>
<script src="{{ path_for('scripts', {'filename' : 'browse-list.js'}) }}"></script>
<script type="text/javascript">
fillBrowseList();
</script>
{% endblock %}

{% block title %}
{% if search == "true" %}
<title>Search {{ site_name }}</title>
{% else %}
<title>{{ name }} on {{ site_name }}</title>
{% endif %}
{% endblock %}

{% block search %}
<form class="navbar-form navbar-right" role="search" action="/search" method="GET" style="margin-right: 5px;">
<div class="form-group">
<input type="text" class="form-control search-box" name="query" placeholder="Search mods..." value="{{query}}">
</div>
</form>
{% endblock %}

{% block body %}
<div class="well">
<div class="container">
Expand Down
1 change: 1 addition & 0 deletions templates/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% block scripts %}
<script src="{{ path_for('scripts', {'filename': 'create.js'}) }}"></script>
<script type="text/javascript">
var gameshort = "{{ gameshort }}";
fillCreate();
</script>
{% endblock %}
Expand Down
5 changes: 3 additions & 2 deletions templates/index.html → templates/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<link rel="stylesheet" type="text/css" href="{{ path_for('styles', {'filename': 'listing.css'}) }}" />
{% endblock %}
{% block scripts %}
<script src="{{ path_for('scripts', {'filename' : 'index.js'}) }}"></script>
<script src="{{ path_for('scripts', {'filename' : 'game.js'}) }}"></script>
<script>
fillIndex();
var gameshort = "{{ gameshort }}";
fillGame();
</script>
{% endblock %}
{% block body %}
Expand Down
Loading