Compare commits

...
Author SHA1 Message Date
bence b75eb16b3d Merged in feature/MAPG-178-add-google-analytics (pull request #151)
Feature/MAPG-178 add google analytics
2020-06-25 12:06:43 +00:00
bence f8a570d0d5 MAPG-178 add Google Analytics
style adaptations
cookie notice improvements
2020-06-25 14:02:39 +02:00
bence e7ee7bbe8e MAPG-178 add endpoint that can send valid data based on started session 2020-06-25 14:01:17 +02:00
bence 2f4f66cc94 MAPG-178 make style compatible with cookie notice on the top of the page 2020-06-25 14:00:38 +02:00
bence 4afbc046ff MAPG-178 add GOOGLE_ANALITICS_ID to .env.example 2020-06-25 13:57:05 +02:00
bence 79bd5b98d5 Merged in feature/MAPG-94-unittest-output (pull request #150)
MAPG-94 save test results and save only the result xml as artifact
2020-06-25 08:17:45 +00:00
bence c1cdeba1d3 MAPG-94 save test results and save only the result xml as artifact 2020-06-25 10:16:28 +02:00
bence 255168ffb6 Merged in bugfix/MAPG-94-introduce-automatic-unit-testing (pull request #147)
MAPG-94 fix possible syntax error in yml
2020-06-24 22:45:01 +00:00
bence ca0b8da733 MAPG-94 fix possible syntax error in yml 2020-06-25 00:44:24 +02:00
bence 34206cac12 Merged in feature/MAPG-94-introduce-automatic-unit-testing (pull request #146)
Feature/MAPG-94 introduce automatic unit testing
2020-06-24 22:38:36 +00:00
bence 47a2f15fc5 MAPG-94 don't install Composer dev packages during update 2020-06-25 00:37:48 +02:00
bence 17658f70ba MAPG-94 create Bitbucket pipeline for unit testing 2020-06-25 00:35:36 +02:00
bence 500ec958cb MAPG-94 add tests for Util\Geo 2020-06-25 00:35:36 +02:00
bence d2fa2050ac MAPG-94 install php-xml to Docker because it is a dependency of PHPUnit
install unzip as well because it is sometimes needed
2020-06-25 00:35:36 +02:00
bence e8be433ee6 MAPG-94 add PHPUnit to composer.json 2020-06-25 00:27:01 +02:00
bence 506072017c Merged in hotfix/MAPG-172-create-cookie-notice (pull request #145)
MAPG-172 make variable local
2020-06-24 21:22:05 +00:00
bence 4561c825a4 MAPG-172 make variable local 2020-06-24 23:21:14 +02:00
bence 693bddbcf0 Merged in hotfix/MAPG-172-create-cookie-notice (pull request #144)
MAPG-172 don't close the cookie DIV if not the agree button was clicked
2020-06-24 21:01:34 +00:00
bence eae7cefae1 MAPG-172 don't close the cookie DIV if not the agree button was clicked 2020-06-24 23:00:26 +02:00
bence 212728e138 Merged in bugfix/MAPG-172-create-cookie-notice (pull request #143)
MAPG-172 quote I agree
2020-06-24 20:55:36 +00:00
bence 0d627f297e MAPG-172 quote I agree 2020-06-24 22:55:13 +02:00
bence f07ae979a2 Merged in feature/MAPG-175-unify-styles (pull request #142)
MAPG-175 align noPano middle and center as other elements
2020-06-24 20:37:59 +00:00
bence 8bdbbafcff MAPG-175 align noPano middle and center as other elements 2020-06-24 22:37:33 +02:00
bence 3856ccb576 Merged in feature/MAPG-174-adjust-map-description-style (pull request #141)
MAPG-174 create separate div for description and align description vertically middle
2020-06-24 20:34:00 +00:00
bence 9f839d3f5d MAPG-174 create separate div for description and align description vertically middle 2020-06-24 22:32:54 +02:00
bence 721b611cdb Merged in feature/MAPG-174-adjust-map-description-style (pull request #140)
MAPG-174 align description center
2020-06-24 20:11:08 +00:00
bence 70fb30f673 MAPG-174 align description center 2020-06-24 22:10:24 +02:00
bence e200dab2a4 Merged in feature/MAPG-172-create-cookie-notice (pull request #139)
Feature/MAPG-172 create cookie notice
2020-06-24 20:03:29 +00:00
bence e8c246f002 MAPG-172 add cookie consent DIV and JS handler 2020-06-24 21:57:41 +02:00
bence 251bf1be3d MAPG-172 add new styles 2020-06-24 21:57:40 +02:00
bence 0be20a6097 MAPG-172 don't send session if user didn't consent the cookies 2020-06-24 21:57:40 +02:00
22 changed files with 2061 additions and 54 deletions

No files matched your search

+1
View File
@@ -14,3 +14,4 @@ MAIL_HOST=mail
MAIL_PORT=2500 MAIL_PORT=2500
GOOGLE_OAUTH_CLIENT_ID=your_google_oauth_client_id GOOGLE_OAUTH_CLIENT_ID=your_google_oauth_client_id
GOOGLE_OAUTH_CLIENT_SECRET=your_google_oauth_client_secret GOOGLE_OAUTH_CLIENT_SECRET=your_google_oauth_client_secret
GOOGLE_ANALITICS_ID=your_google_analytics_id
+1
View File
@@ -1,3 +1,4 @@
.env .env
installed installed
unit_test_results.xml
vendor vendor
+15
View File
@@ -0,0 +1,15 @@
image: php:7.4.7-cli-buster
pipelines:
default:
- step:
name: Unit Testing
caches:
- composer
artifacts:
- unit_test_results.xml
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- vendor/bin/phpunit --log-junit unit_test_results.xml --testdox tests
+3 -1
View File
@@ -8,7 +8,9 @@
"symfony/console": "^5.1", "symfony/console": "^5.1",
"phpmailer/phpmailer": "^6.1" "phpmailer/phpmailer": "^6.1"
}, },
"require-dev": {}, "require-dev": {
"phpunit/phpunit": "^9"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"MapGuesser\\": "src" "MapGuesser\\": "src"
Generated
+1701 -2
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -4,8 +4,8 @@ ENV DEBIAN_FRONTEND noninteractive
# Install Nginx, PHP and further necessary packages # Install Nginx, PHP and further necessary packages
RUN apt update --fix-missing RUN apt update --fix-missing
RUN apt install -y curl git mariadb-client nginx \ RUN apt install -y curl git unzip mariadb-client nginx \
php-apcu php-xdebug php7.4-cli php7.4-curl php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-zip php-apcu php-xdebug php7.4-cli php7.4-curl php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-zip php7.4-xml
# Configure Nginx with PHP # Configure Nginx with PHP
RUN mkdir -p /run/php RUN mkdir -p /run/php
+11 -8
View File
@@ -1,12 +1,15 @@
#panorama { #panorama {
width: 100%; position: absolute;
height: calc(100% - 40px); top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1; z-index: 1;
} }
#guessCover { #panoCover {
position: absolute; position: absolute;
top: 40px; top: 0;
left: 0; left: 0;
bottom: 0; bottom: 0;
right: 0; right: 0;
@@ -111,7 +114,7 @@
z-index: 2; z-index: 2;
} }
#guess { #guess {
top: 50px; top: 10px;
left: 20px; left: 20px;
opacity: 0.95; opacity: 0.95;
visibility: hidden; visibility: hidden;
@@ -157,7 +160,7 @@
#guess.result { #guess.result {
width: initial; width: initial;
height: initial; height: initial;
top: 50px; top: 10px;
left: 50px; left: 50px;
right: 50px; right: 50px;
bottom: 50px; bottom: 50px;
@@ -167,11 +170,11 @@
} }
@media screen and (max-height: 424px) { @media screen and (max-height: 424px) {
#guess { #guess {
top: 50px; top: 10px;
height: initial; height: initial;
} }
#guess.adapt:hover { #guess.adapt:hover {
top: 50px; top: 10px;
height: initial; height: initial;
} }
#guess.result { #guess.result {
+18 -9
View File
@@ -1,9 +1,13 @@
#map { #map {
width: 100%; position: absolute;
height: calc(100% - 40px); top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1; z-index: 1;
} }
/* modify the cursor for the Leaflet map */
.leaflet-container { .leaflet-container {
cursor: crosshair; cursor: crosshair;
} }
@@ -16,6 +20,8 @@
#noPano { #noPano {
display: flex; display: flex;
justify-content: center;
align-items: center;
position: absolute; position: absolute;
z-index: 2; z-index: 2;
visibility: hidden; visibility: hidden;
@@ -23,12 +29,12 @@
} }
#noPano>p { #noPano>p {
margin: auto; text-align: center;
} }
#control { #control {
position: absolute; position: absolute;
top: 50px; top: 10px;
right: 10px; right: 10px;
width: 125px; width: 125px;
z-index: 3; z-index: 3;
@@ -48,31 +54,34 @@
@media screen and (max-width: 999px) and (min-height: 600px) { @media screen and (max-width: 999px) and (min-height: 600px) {
#map.selected { #map.selected {
height: calc(50% - 20px); height: 50%;
} }
#panorama, #noPano { #panorama, #noPano {
left: 0; left: 0;
bottom: 0; bottom: 0;
right: 0; right: 0;
height: calc(50% - 20px); height: 50%;
} }
#placeControl { #placeControl {
top: calc(50% + 30px); top: calc(50% + 10px);
} }
} }
@media screen and (min-width: 1000px), (max-height: 599px) { @media screen and (min-width: 1000px), (max-height: 599px) {
#map.selected { #map.selected {
top: 0;
bottom: 0;
left: 0;
width: 50%; width: 50%;
} }
#panorama, #noPano { #panorama, #noPano {
top: 40px; top: 0;
bottom: 0; bottom: 0;
right: 0; right: 0;
width: 50%; width: 50%;
} }
#placeControl { #placeControl {
top: 50px; top: 10px;
} }
#modified.selected { #modified.selected {
right: calc(50% + 10px); right: calc(50% + 10px);
+20 -1
View File
@@ -84,7 +84,7 @@ hr {
} }
p.small, span.small { p.small, span.small {
font-size: 12px; font-size: 14px;
} }
.justify { .justify {
@@ -148,6 +148,13 @@ button, a.button {
line-height: 35px; line-height: 35px;
} }
button.small {
font-size: 14px;
padding: 0 12px;
height: 32px;
line-height: 32px;
}
button:enabled:hover, button:enabled:focus, a.button:hover, a.button:focus { button:enabled:hover, button:enabled:focus, a.button:hover, a.button:focus {
background-color: #29457f; background-color: #29457f;
outline: none; outline: none;
@@ -317,6 +324,12 @@ main {
padding: 6px 12px; padding: 6px 12px;
} }
div.full {
position: relative;
width: 100%;
height: calc(100% - 40px);
}
footer { footer {
background-color: #444444; background-color: #444444;
padding: 6px 12px; padding: 6px 12px;
@@ -336,6 +349,12 @@ div.buttonContainer>button {
margin: 0 auto; margin: 0 auto;
} }
#cookiesNotice {
background-color: #eeeeee;
padding: 10px;
text-align: center;
}
#loading { #loading {
position: fixed; position: fixed;
width: 64px; width: 64px;
+6
View File
@@ -46,6 +46,12 @@ div.mapItem>div.inner>div.info {
grid-template-columns: auto auto; grid-template-columns: auto auto;
} }
div.mapItem>div.inner>div.description {
display: flex;
justify-content: center;
align-items: center;
}
div.mapItem>div.inner>div.info>p:nth-child(1) { div.mapItem>div.inner>div.info>p:nth-child(1) {
text-align: left; text-align: left;
} }
+12 -4
View File
@@ -16,7 +16,7 @@
initialize: function () { initialize: function () {
document.getElementById('loading').style.visibility = 'visible'; document.getElementById('loading').style.visibility = 'visible';
document.getElementById('guessCover').style.visibility = 'visible'; document.getElementById('panoCover').style.visibility = 'visible';
document.getElementById('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS); document.getElementById('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS);
document.getElementById('currentScoreSum').innerHTML = '0/0'; document.getElementById('currentScoreSum').innerHTML = '0/0';
@@ -27,7 +27,7 @@
MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () { MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () {
document.getElementById('loading').style.visibility = 'hidden'; document.getElementById('loading').style.visibility = 'hidden';
document.getElementById('guessCover').style.visibility = 'hidden'; document.getElementById('panoCover').style.visibility = 'hidden';
if (this.response.error) { if (this.response.error) {
//TODO: handle this error //TODO: handle this error
@@ -98,7 +98,7 @@
lastRound.line.setVisible(false); lastRound.line.setVisible(false);
} }
document.getElementById('guessCover').style.visibility = 'hidden'; document.getElementById('panoCover').style.visibility = 'hidden';
document.getElementById('showGuessButton').style.visibility = null; document.getElementById('showGuessButton').style.visibility = null;
document.getElementById('guess').style.visibility = null; document.getElementById('guess').style.visibility = null;
document.getElementById('guess').classList.remove('result') document.getElementById('guess').classList.remove('result')
@@ -152,7 +152,7 @@
document.getElementById('guess').classList.remove('adapt'); document.getElementById('guess').classList.remove('adapt');
} }
document.getElementById('loading').style.visibility = 'visible'; document.getElementById('loading').style.visibility = 'visible';
document.getElementById('guessCover').style.visibility = 'visible'; document.getElementById('panoCover').style.visibility = 'visible';
var data = new FormData(); var data = new FormData();
data.append('lat', String(guessPosition.lat)); data.append('lat', String(guessPosition.lat));
@@ -370,6 +370,14 @@
} }
}; };
MapGuesser.sessionAvailableHooks.reinitializeGame = function () {
MapGuesser.httpRequest('GET', '/game/' + mapId + '/json', function () {
mapBounds = this.response.bounds;
Game.initialize();
});
};
if (!('ontouchstart' in document.documentElement)) { if (!('ontouchstart' in document.documentElement)) {
Game.adaptGuess = true; Game.adaptGuess = true;
} }
+45
View File
@@ -1,4 +1,49 @@
var MapGuesser = { var MapGuesser = {
cookiesAgreed: false,
sessionAvailableHooks: {},
initGoogleAnalitics: function () {
if (typeof GOOGLE_ANALITICS_ID === 'undefined') {
return;
}
// Global site tag (gtag.js) - Google Analytics
var script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + GOOGLE_ANALITICS_ID;
script.async = true;
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', GOOGLE_ANALITICS_ID);
},
agreeCookies: function () {
if (MapGuesser.cookiesAgreed) {
return;
}
var expirationDate = new Date(new Date().getTime() + 20 * 365 * 24 * 60 * 60 * 1000).toUTCString();
document.cookie = 'COOKIES_CONSENT=1; expires=' + expirationDate + '; path=/';
MapGuesser.initGoogleAnalitics();
MapGuesser.httpRequest('GET', '/startSession.json', function () {
ANTI_CSRF_TOKEN = this.response.antiCsrfToken;
for (var hookId in MapGuesser.sessionAvailableHooks) {
if (!MapGuesser.sessionAvailableHooks.hasOwnProperty(hookId)) {
continue;
}
MapGuesser.sessionAvailableHooks[hookId]();
}
});
MapGuesser.cookiesAgreed = true;
},
httpRequest: function (method, url, callback, data) { httpRequest: function (method, url, callback, data) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
+1 -1
View File
@@ -5,7 +5,7 @@ ROOT_DIR=$(dirname $(readlink -f "$0"))/..
. ${ROOT_DIR}/.env . ${ROOT_DIR}/.env
echo "Installing Composer packages..." echo "Installing Composer packages..."
(cd ${ROOT_DIR} && composer install) (cd ${ROOT_DIR} && composer install --no-dev)
echo "Installing Yarn packages..." echo "Installing Yarn packages..."
(cd ${ROOT_DIR}/public/static && yarn install) (cd ${ROOT_DIR}/public/static && yarn install)
+18
View File
@@ -1,12 +1,30 @@
<?php namespace MapGuesser\Controller; <?php namespace MapGuesser\Controller;
use MapGuesser\Interfaces\Request\IRequest;
use MapGuesser\Interfaces\Response\IContent;
use MapGuesser\Interfaces\Response\IRedirect; use MapGuesser\Interfaces\Response\IRedirect;
use MapGuesser\Response\JsonContent;
use MapGuesser\Response\Redirect; use MapGuesser\Response\Redirect;
class HomeController class HomeController
{ {
private IRequest $request;
public function __construct(IRequest $request)
{
$this->request = $request;
}
public function getIndex(): IRedirect public function getIndex(): IRedirect
{ {
return new Redirect(\Container::$routeCollection->getRoute('maps')->generateLink(), IRedirect::TEMPORARY); return new Redirect(\Container::$routeCollection->getRoute('maps')->generateLink(), IRedirect::TEMPORARY);
} }
public function startSession(): IContent
{
// session starts with the request, this method just sends valid data to the client
$data = ['antiCsrfToken' => $this->request->session()->get('anti_csrf_token')];
return new JsonContent($data);
}
} }
+98
View File
@@ -0,0 +1,98 @@
<?php namespace MapGuesser\Tests\Util\Geo;
use MapGuesser\Util\Geo\Bounds;
use MapGuesser\Util\Geo\Position;
use PHPUnit\Framework\TestCase;
final class BoundsTest extends TestCase
{
public function testCanBeCreatedEmpty(): void
{
$bounds = new Bounds();
$this->assertEquals(90.0, $bounds->getSouthLat());
$this->assertEquals(180.0, $bounds->getWestLng());
$this->assertEquals(-90.0, $bounds->getNorthLat());
$this->assertEquals(-180.0, $bounds->getEastLng());
}
public function testCanBeCreatedWithPosition(): void
{
$position = new Position(45.25, 18.12);
$bounds = new Bounds($position);
$this->assertEquals($position->getLat(), $bounds->getSouthLat());
$this->assertEquals($position->getLng(), $bounds->getWestLng());
$this->assertEquals($position->getLat(), $bounds->getNorthLat());
$this->assertEquals($position->getLng(), $bounds->getEastLng());
}
public function testCanBeCreatedDirectly(): void
{
$bounds = Bounds::createDirectly(44.12, 7.33, 50.12, 15.11);
$this->assertEquals(44.12, $bounds->getSouthLat());
$this->assertEquals(7.33, $bounds->getWestLng());
$this->assertEquals(50.12, $bounds->getNorthLat());
$this->assertEquals(15.11, $bounds->getEastLng());
}
public function testExtendingWithOnePositionIsTheSameAsCreatingWithPosition(): void
{
$position = new Position(45.25, 18.12);
$bounds1 = new Bounds();
$bounds1->extend($position);
$bounds2 = new Bounds($position);
$this->assertEquals($bounds1, $bounds2);
}
public function testCanBeExtendedWithTwoPositions(): void
{
$bounds = new Bounds();
$position1 = new Position(45.25, 18.12);
$position2 = new Position(43.15, 19.28);
$bounds->extend($position1);
$bounds->extend($position2);
$this->assertEquals($position2->getLat(), $bounds->getSouthLat());
$this->assertEquals($position1->getLng(), $bounds->getWestLng());
$this->assertEquals($position1->getLat(), $bounds->getNorthLat());
$this->assertEquals($position2->getLng(), $bounds->getEastLng());
$bounds = new Bounds();
$position1 = new Position(43.15, 18.12);
$position2 = new Position(45.25, 19.28);
$bounds->extend($position1);
$bounds->extend($position2);
$this->assertEquals($position1->getLat(), $bounds->getSouthLat());
$this->assertEquals($position1->getLng(), $bounds->getWestLng());
$this->assertEquals($position2->getLat(), $bounds->getNorthLat());
$this->assertEquals($position2->getLng(), $bounds->getEastLng());
}
public function testCanCalculateApproximateArea(): void
{
$bounds = Bounds::createDirectly(44.12, 7.33, 50.12, 15.11);
$this->assertEqualsWithDelta(391766.09, $bounds->calculateApproximateArea(), 0.01);
}
public function testCanBeConvertedToArray(): void
{
$bounds = Bounds::createDirectly(44.12, 7.33, 50.12, 15.11);
$this->assertEquals(
['south' => 44.12, 'west' => 7.33, 'north' => 50.12, 'east' => 15.11],
$bounds->toArray()
);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php namespace MapGuesser\Tests\Util\Geo;
use MapGuesser\Util\Geo\Position;
use PHPUnit\Framework\TestCase;
final class PositionTest extends TestCase
{
public function testCanBeCreatedWithLatAndLng(): void
{
$position = new Position(45.25, 18.12);
$this->assertEquals(45.25, $position->getLat());
$this->assertEquals(18.12, $position->getLng());
}
public function testCanCalculateDistanceToAnotherPosition(): void
{
$position1 = new Position(44.12, 7.33);
$position2 = new Position(50.12, 15.11);
$this->assertEqualsWithDelta(888785.73, $position1->calculateDistanceTo($position2), 0.01);
}
public function testCanBeConvertedToArray(): void
{
$position = new Position(45.25, 18.12);
$this->assertEquals(
['lat' => 45.25, 'lng' => 18.12],
$position->toArray()
);
}
}
+5 -3
View File
@@ -59,19 +59,21 @@ $jsFiles = [
</div> </div>
</form> </form>
</div> </div>
<div class="full">
<div id="map"></div> <div id="map"></div>
<div id="control">
<button id="saveButton" class="fullWidth" disabled>Save</button>
</div>
<div id="panorama"></div> <div id="panorama"></div>
<div id="noPano"> <div id="noPano">
<p class="bold">No panorama is available for this location.</p> <p class="bold">No panorama is available for this location.</p>
</div> </div>
<div id="control">
<button id="saveButton" class="fullWidth" disabled>Save</button>
</div>
<div id="placeControl"> <div id="placeControl">
<button id="applyButton" class="fullWidth">Apply</button> <button id="applyButton" class="fullWidth">Apply</button>
<button id="closeButton" class="gray fullWidth marginTop">Close</button> <button id="closeButton" class="gray fullWidth marginTop">Close</button>
<button id="deleteButton" class="red fullWidth marginTop">Delete</button> <button id="deleteButton" class="red fullWidth marginTop">Delete</button>
</div> </div>
</div>
<script> <script>
var tileUrl = '<?= $_ENV['LEAFLET_TILESERVER_URL'] ?>'; var tileUrl = '<?= $_ENV['LEAFLET_TILESERVER_URL'] ?>';
var tileAttribution = '<?= $_ENV['LEAFLET_TILESERVER_ATTRIBUTION'] ?>'; var tileAttribution = '<?= $_ENV['LEAFLET_TILESERVER_ATTRIBUTION'] ?>';
+3 -1
View File
@@ -21,7 +21,8 @@ $jsFiles = [
--><span>Score <span id="currentScoreSum" class="bold"></span></span> --><span>Score <span id="currentScoreSum" class="bold"></span></span>
</p> </p>
</header> </header>
<div id="guessCover"></div> <div class="full">
<div id="panoCover"></div>
<div id="panorama"></div> <div id="panorama"></div>
<div id="showGuessButtonContainer"> <div id="showGuessButtonContainer">
<button id="showGuessButton" class="fullWidth">Show guess map</button> <button id="showGuessButton" class="fullWidth">Show guess map</button>
@@ -55,6 +56,7 @@ $jsFiles = [
<button id="startNewGameButton" class="fullWidth">Play this map again</button> <button id="startNewGameButton" class="fullWidth">Play this map again</button>
</div> </div>
</div> </div>
</div>
<script> <script>
var mapId = <?= $mapId ?>; var mapId = <?= $mapId ?>;
var mapBounds = <?= json_encode($bounds) ?>; var mapBounds = <?= json_encode($bounds) ?>;
+23 -21
View File
@@ -30,7 +30,9 @@ $cssFiles = [
-->~ <?= $map['area'][0] ?> <?= $map['area'][1] ?><sup>2</sup> -->~ <?= $map['area'][0] ?> <?= $map['area'][1] ?><sup>2</sup>
</p> </p>
</div> </div>
<p class="small justify marginTop"><?= $map['description'] ?></p> <div class="description marginTop">
<p class="small center"><?= $map['description'] ?></p>
</div>
</div> </div>
<?php if ($isAdmin): ?> <?php if ($isAdmin): ?>
<div class="buttonContainer"> <div class="buttonContainer">
@@ -64,7 +66,7 @@ $cssFiles = [
const GOOGLE_MAPS_JS_API_KEY = '<?= $_ENV['GOOGLE_MAPS_JS_API_KEY'] ?>'; const GOOGLE_MAPS_JS_API_KEY = '<?= $_ENV['GOOGLE_MAPS_JS_API_KEY'] ?>';
var Maps = { var Maps = {
innerDivs: null, descriptionDivs: null,
addStaticMaps: function () { addStaticMaps: function () {
var imgContainers = document.getElementById('mapContainer').getElementsByClassName('imgContainer'); var imgContainers = document.getElementById('mapContainer').getElementsByClassName('imgContainer');
@@ -81,29 +83,29 @@ $cssFiles = [
} }
}, },
initializeInnerDivs: function () { initializeDescriptionDivs: function () {
Maps.innerDivs = document.getElementById('mapContainer').getElementsByClassName('inner'); Maps.descriptionDivs = document.getElementById('mapContainer').getElementsByClassName('description');
for (var i = 0; i < Maps.innerDivs.length; i++) { for (var i = 0; i < Maps.descriptionDivs.length; i++) {
var inner = Maps.innerDivs[i]; var description = Maps.descriptionDivs[i];
var boundingClientRect = inner.getBoundingClientRect(); var boundingClientRect = description.getBoundingClientRect();
inner.defaultHeight = boundingClientRect.height; description.defaultHeight = boundingClientRect.height;
} }
}, },
calculateInnerDivHeights: function () { calculateDescriptionDivHeights: function () {
var currentY; var currentY;
var rows = []; var rows = [];
for (var i = 0; i < Maps.innerDivs.length; i++) { for (var i = 0; i < Maps.descriptionDivs.length; i++) {
var inner = Maps.innerDivs[i]; var description = Maps.descriptionDivs[i];
var boundingClientRect = inner.getBoundingClientRect(); var boundingClientRect = description.getBoundingClientRect();
if (currentY !== boundingClientRect.y) { if (currentY !== boundingClientRect.y) {
rows.push([]); rows.push([]);
} }
rows[rows.length - 1].push(inner); rows[rows.length - 1].push(description);
currentY = boundingClientRect.y; currentY = boundingClientRect.y;
} }
@@ -113,17 +115,17 @@ $cssFiles = [
var maxHeight = 0; var maxHeight = 0;
for (var j = 0; j < row.length; j++) { for (var j = 0; j < row.length; j++) {
var inner = row[j]; var description = row[j];
if (inner.defaultHeight > maxHeight) { if (description.defaultHeight > maxHeight) {
maxHeight = inner.defaultHeight; maxHeight = description.defaultHeight;
} }
} }
for (var j = 0; j < row.length; j++) { for (var j = 0; j < row.length; j++) {
var inner = row[j]; var description = row[j];
inner.style.height = maxHeight + 'px'; description.style.height = maxHeight + 'px';
} }
} }
} }
@@ -131,11 +133,11 @@ $cssFiles = [
Maps.addStaticMaps(); Maps.addStaticMaps();
Maps.initializeInnerDivs(); Maps.initializeDescriptionDivs();
Maps.calculateInnerDivHeights(); Maps.calculateDescriptionDivHeights();
window.onresize = function () { window.onresize = function () {
Maps.calculateInnerDivHeights(); Maps.calculateDescriptionDivHeights();
}; };
})(); })();
</script> </script>
+32 -1
View File
@@ -1,7 +1,10 @@
<script> <script>
const STATIC_ROOT = '<?= $_ENV['STATIC_ROOT'] ?>'; const STATIC_ROOT = '<?= $_ENV['STATIC_ROOT'] ?>';
const REVISION = '<?= REVISION ?>'; const REVISION = '<?= REVISION ?>';
const ANTI_CSRF_TOKEN = '<?= $_SESSION['anti_csrf_token'] ?>'; var ANTI_CSRF_TOKEN = '<?= \Container::$request->session()->get('anti_csrf_token') ?>';
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
const GOOGLE_ANALITICS_ID = '<?= $_ENV['GOOGLE_ANALITICS_ID'] ?>';
<?php endif; ?>
</script> </script>
<script src="<?= $_ENV['STATIC_ROOT'] ?>/js/mapguesser.js?rev=<?= REVISION ?>"></script> <script src="<?= $_ENV['STATIC_ROOT'] ?>/js/mapguesser.js?rev=<?= REVISION ?>"></script>
<?php if (isset($jsFiles)) : ?> <?php if (isset($jsFiles)) : ?>
@@ -14,5 +17,33 @@
<script src="<?= $jsFile ?>"></script> <script src="<?= $jsFile ?>"></script>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?> <?php endif; ?>
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
<script>
(function () {
// we don't want user to agree cookies when clicking on the notice itself
document.getElementById('cookiesNotice').onclick = function (e) {
e.stopPropagation();
};
document.getElementById('agreeCookiesButton').onclick = function () {
MapGuesser.agreeCookies();
document.getElementById('cookiesNotice').style.display = 'none';
};
window.onclick = function () {
MapGuesser.agreeCookies();
};
})();
</script>
<?php else: ?>
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
<script>
(function () {
MapGuesser.initGoogleAnalitics();
})();
</script>
<?php endif; ?>
<?php endif; ?>
</body> </body>
</html> </html>
+8
View File
@@ -22,6 +22,14 @@
<link rel="icon" type="image/png" sizes="16x16" href="<?= $_ENV['STATIC_ROOT'] ?>/img/favicon/16x16.png?rev=<?= REVISION ?>"> <link rel="icon" type="image/png" sizes="16x16" href="<?= $_ENV['STATIC_ROOT'] ?>/img/favicon/16x16.png?rev=<?= REVISION ?>">
</head> </head>
<body> <body>
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
<div id="cookiesNotice">
<p class="small">
<?= $_ENV['APP_NAME'] ?> uses cookies to improve user experience. By using the app or clicking 'Agree', you consent to our use of cookies.
</p>
<button id="agreeCookiesButton" class="small marginTop">Agree</button>
</div>
<?php endif; ?>
<div id="loading"> <div id="loading">
<img src="<?= $_ENV['STATIC_ROOT'] ?>/img/loading.svg?rev=<?= REVISION ?>" width="64" height="64"> <img src="<?= $_ENV['STATIC_ROOT'] ?>/img/loading.svg?rev=<?= REVISION ?>" width="64" height="64">
</div> </div>
+5
View File
@@ -13,6 +13,7 @@ if (!empty($_ENV['DEV'])) {
Container::$routeCollection = new MapGuesser\Routing\RouteCollection(); Container::$routeCollection = new MapGuesser\Routing\RouteCollection();
Container::$routeCollection->get('index', '', [MapGuesser\Controller\MapsController::class, 'getMaps']); Container::$routeCollection->get('index', '', [MapGuesser\Controller\MapsController::class, 'getMaps']);
Container::$routeCollection->get('startSession', 'startSession.json', [MapGuesser\Controller\HomeController::class, 'startSession']);
Container::$routeCollection->group('login', function (MapGuesser\Routing\RouteCollection $routeCollection) { Container::$routeCollection->group('login', function (MapGuesser\Routing\RouteCollection $routeCollection) {
$routeCollection->get('login', '', [MapGuesser\Controller\LoginController::class, 'getLoginForm']); $routeCollection->get('login', '', [MapGuesser\Controller\LoginController::class, 'getLoginForm']);
$routeCollection->post('login-action', '', [MapGuesser\Controller\LoginController::class, 'login']); $routeCollection->post('login-action', '', [MapGuesser\Controller\LoginController::class, 'login']);
@@ -49,6 +50,7 @@ Container::$routeCollection->group('admin', function (MapGuesser\Routing\RouteCo
$routeCollection->post('admin.deleteMap', 'deleteMap/{mapId}', [MapGuesser\Controller\MapAdminController::class, 'deleteMap']); $routeCollection->post('admin.deleteMap', 'deleteMap/{mapId}', [MapGuesser\Controller\MapAdminController::class, 'deleteMap']);
}); });
if (isset($_COOKIE['COOKIES_CONSENT'])) {
Container::$sessionHandler = new MapGuesser\Session\DatabaseSessionHandler(); Container::$sessionHandler = new MapGuesser\Session\DatabaseSessionHandler();
session_set_save_handler(Container::$sessionHandler, true); session_set_save_handler(Container::$sessionHandler, true);
@@ -58,6 +60,9 @@ session_start([
'cookie_httponly' => true, 'cookie_httponly' => true,
'cookie_samesite' => 'Lax' 'cookie_samesite' => 'Lax'
]); ]);
} else {
$_SESSION = [];
}
Container::$request = new MapGuesser\Request\Request($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], $_GET, $_POST, $_SESSION); Container::$request = new MapGuesser\Request\Request($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], $_GET, $_POST, $_SESSION);