diff --git a/.env.example b/.env.example index 1570bcb..4cd7025 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,6 @@ DEV=true +DB_HOST=mariadb +DB_USER=mapguesser +DB_PASSWORD=mapguesser +DB_NAME=mapguesser GOOGLE_MAPS_JS_API_KEY=your_google_maps_js_api_key diff --git a/install/db.sql b/install/db.sql new file mode 100644 index 0000000..538e3da --- /dev/null +++ b/install/db.sql @@ -0,0 +1,27 @@ +SET NAMES utf8mb4; +SET foreign_key_checks = 0; + + +DROP TABLE IF EXISTS `maps`; +CREATE TABLE `maps` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `description` text NOT NULL, + `bound_south_lat` decimal(8,6) NOT NULL, + `bound_west_lng` decimal(9,6) NOT NULL, + `bound_north_lat` decimal(8,6) NOT NULL, + `bound_east_lng` decimal(9,6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + +DROP TABLE IF EXISTS `places`; +CREATE TABLE `places` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `map_id` int(10) unsigned NOT NULL, + `lat` decimal(8,6) NOT NULL, + `lng` decimal(9,6) NOT NULL, + PRIMARY KEY (`id`), + KEY `map_id` (`map_id`), + CONSTRAINT `places_map_id` FOREIGN KEY (`map_id`) REFERENCES `maps` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/main.php b/main.php index bd37059..b8c37f0 100644 --- a/main.php +++ b/main.php @@ -2,7 +2,9 @@ require 'vendor/autoload.php'; -$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); +const ROOT = __DIR__; + +$dotenv = Dotenv\Dotenv::createImmutable(ROOT); $dotenv->load(); if (!empty($_ENV['DEV'])) { diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..3a37342 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine On +RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^ index.php [L] diff --git a/public/index.php b/public/index.php index 2bb1e39..cae72c9 100644 --- a/public/index.php +++ b/public/index.php @@ -2,39 +2,15 @@ require '../main.php'; -// demo position -$realPosition = new MapGuesser\Geo\Position(47.85239, 13.35101); +// very basic routing +$url = $_SERVER['REQUEST_URI']; +switch($url) { + case '/': + $controller = new MapGuesser\Controller\GuessController(); + break; + default: + echo 'Error 404'; + die; +} -// demo bounds -$bounds = new MapGuesser\Geo\Bounds($realPosition); -$bounds->extend(new MapGuesser\Geo\Position(48.07683,7.35758)); -$bounds->extend(new MapGuesser\Geo\Position(47.57496, 19.08077)); - -?> - - - - - - - MapGuesser - - - - -
-
-
-
- -
-
- - - - - - \ No newline at end of file +echo $controller->render(); diff --git a/public/static/js/mapguesser.js b/public/static/js/mapguesser.js index bf76f05..1dc203d 100644 --- a/public/static/js/mapguesser.js +++ b/public/static/js/mapguesser.js @@ -53,10 +53,6 @@ var googleLink; function initialize() { panorama = new google.maps.StreetViewPanorama(document.getElementById('panorama'), { position: realPosition, - pov: { - heading: 34, - pitch: 10 - }, disableDefaultUI: true, linksControl: true, showRoadLabels: false diff --git a/src/Controller/BaseController.php b/src/Controller/BaseController.php new file mode 100644 index 0000000..9e2c2a7 --- /dev/null +++ b/src/Controller/BaseController.php @@ -0,0 +1,24 @@ +operate(); + + extract($this->variables); + + ob_start(); + require ROOT . '/views/' . $this->view . '.php'; + $content = ob_get_contents(); + ob_end_clean(); + + return $content; + } + + abstract protected function operate() : void; +} diff --git a/src/Controller/GuessController.php b/src/Controller/GuessController.php new file mode 100644 index 0000000..55ec2f4 --- /dev/null +++ b/src/Controller/GuessController.php @@ -0,0 +1,35 @@ +prepare('SELECT lat, lng FROM places WHERE map_id=? ORDER BY RAND() LIMIT 1'); + $stmt->bind_param("i", $mapId); + $stmt->execute(); + + $result = $stmt->get_result(); + $row = $result->fetch_assoc(); + + $realPosition = new Position($row['lat'], $row['lng']); + + // demo bounds + $bounds = new Bounds($realPosition); + $bounds->extend(new Position(48.07683,7.35758)); + $bounds->extend(new Position(47.57496, 19.08077)); + + $this->variables = compact('realPosition', 'bounds'); + } +} diff --git a/src/Geo/Bounds.php b/src/Util/Geo/Bounds.php similarity index 97% rename from src/Geo/Bounds.php rename to src/Util/Geo/Bounds.php index f813f0e..e8c9710 100644 --- a/src/Geo/Bounds.php +++ b/src/Util/Geo/Bounds.php @@ -1,4 +1,4 @@ - + + + + MapGuesser + + + +
+
+
+
+ +
+
+ + + + +