[Scummvm-git-logs] scummvm-web master -> 95aaec5f3e0d000e65ae4b405d5232ae35c556f4
Mataniko
mataniko at gmail.com
Thu Apr 25 02:57:17 CEST 2019
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm-web' repo located at https://github.com/scummvm/scummvm-web .
Summary:
95aaec5f3e WEB: Use AltoRouter instead of apache rewrites
Commit: 95aaec5f3e0d000e65ae4b405d5232ae35c556f4
https://github.com/scummvm/scummvm-web/commit/95aaec5f3e0d000e65ae4b405d5232ae35c556f4
Author: Matan Bareket (mataniko at gmail.com)
Date: 2019-04-24T20:57:03-04:00
Commit Message:
WEB: Use AltoRouter instead of apache rewrites
This makes debugging and using other web servers much easier, and scales better when adding functionality and pages
Changed paths:
R dev-os.php
R dev-router.php
composer.json
composer.lock
include/Pages/CompatibilityPage.php
include/Pages/DocumentationPage.php
include/Pages/FeedsPage.php
include/Pages/NewsPage.php
include/Pages/ScreenshotsPage.php
index.php
diff --git a/composer.json b/composer.json
index 90af9ad..118318c 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,8 @@
"require": {
"leafo/scssphp": "^0.7.6",
"smarty/smarty": "^3.1",
- "ezyang/htmlpurifier": "^4.10"
+ "ezyang/htmlpurifier": "^4.10",
+ "altorouter/altorouter": "^1.2"
},
"scripts": {
"post-install-cmd": [
@@ -20,11 +21,26 @@
"pscss -f compressed ./scss/pages/_mirrorbrain.scss > ./css/mirrorbrain.css",
"php include/I18N.php"
],
+ "build-common": [
+ "glue images/icons/games/ --img=images/ --scss=scss/sprites/ --retina",
+ "glue images/icons/platforms/ --img=images/ --scss=scss/sprites/ --retina",
+ "mv scss/sprites/games.scss scss/sprites/_games.scss",
+ "mv scss/sprites/platforms.scss scss/sprites/_platforms.scss",
+ "composer install --no-dev",
+ "npm install --production"
+ ],
+ "build-win":[
+ "if NOT EXIST css mkdir css",
+ "@build-common",
+ "if NOT EXIST vendor\\smarty\\smarty\\libs\\template_c mkdir vendor\\smarty\\smarty\\libs\\template_c"
+ ],
"build": [
- "cd site-update;./install.sh;cd .."
+ "mkdir css -p",
+ "@build-common",
+ "mkdir vendor/smarty/smarty/libs/template_c -p"
],
"run": [
- "php -S localhost:8000 dev-router.php & php dev-os.php"
+ "php -S localhost:8000"
],
"develop": [
"@build",
diff --git a/composer.lock b/composer.lock
index 19675df..dd399a7 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,9 +4,64 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "4c580db7ed458bec6deff0a071432aef",
+ "content-hash": "14d3d7305a0d894696affd2ee62cc370",
"packages": [
{
+ "name": "altorouter/altorouter",
+ "version": "v1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/dannyvankooten/AltoRouter.git",
+ "reference": "39c50092470128c12284d332bb57f306bb5b58e4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/dannyvankooten/AltoRouter/zipball/39c50092470128c12284d332bb57f306bb5b58e4",
+ "reference": "39c50092470128c12284d332bb57f306bb5b58e4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "require-dev": {
+ "codeclimate/php-test-reporter": "dev-master",
+ "phpunit/phpunit": "4.5.*"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "AltoRouter.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Danny van Kooten",
+ "email": "dannyvankooten at gmail.com",
+ "homepage": "http://dannyvankooten.com/"
+ },
+ {
+ "name": "Koen Punt",
+ "homepage": "https://github.com/koenpunt"
+ },
+ {
+ "name": "niahoo",
+ "homepage": "https://github.com/niahoo"
+ }
+ ],
+ "description": "A lightning fast router for PHP",
+ "homepage": "https://github.com/dannyvankooten/AltoRouter",
+ "keywords": [
+ "lightweight",
+ "router",
+ "routing"
+ ],
+ "time": "2015-11-30T00:47:43+00:00"
+ },
+ {
"name": "ezyang/htmlpurifier",
"version": "v4.10.0",
"source": {
@@ -322,7 +377,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.",
+ "description": "? Nette Bootstrap: the simple way to configure and bootstrap your Nette application.",
"homepage": "https://nette.org",
"keywords": [
"bootstrapping",
@@ -387,7 +442,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.",
+ "description": "? Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.",
"homepage": "https://nette.org",
"keywords": [
"compiled",
@@ -452,7 +507,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "🔍 Nette Finder: find files and directories with an intuitive API.",
+ "description": "? Nette Finder: find files and directories with an intuitive API.",
"homepage": "https://nette.org",
"keywords": [
"filesystem",
@@ -512,7 +567,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "🍸 Nette NEON: encodes and decodes NEON file format.",
+ "description": "? Nette NEON: encodes and decodes NEON file format.",
"homepage": "http://ne-on.org",
"keywords": [
"export",
@@ -575,7 +630,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.2 features.",
+ "description": "? Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.2 features.",
"homepage": "https://nette.org",
"keywords": [
"code",
@@ -639,7 +694,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.",
+ "description": "? Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.",
"homepage": "https://nette.org",
"keywords": [
"autoload",
@@ -712,7 +767,7 @@
"homepage": "https://nette.org/contributors"
}
],
- "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.",
+ "description": "? Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.",
"homepage": "https://nette.org",
"keywords": [
"array",
diff --git a/dev-os.php b/dev-os.php
deleted file mode 100644
index f53d4e3..0000000
--- a/dev-os.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
- switch (PHP_OS) {
- case "Darwin":
- exec('open http://localhost:8000');
- break;
- case "Linux":
- exec('xdg-open http://localhost:8000');
- break;
- case "Windows":
- exec('start http://localhost:8000');
- break;
- default:
- exec('xdg-open http://localhost:8000');
- break;
- }
-?>
diff --git a/dev-router.php b/dev-router.php
deleted file mode 100644
index 8a43a18..0000000
--- a/dev-router.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js|svg)/', basename($_SERVER["REQUEST_URI"]))) {
- return false; // serve the requested resource as-is.
-} else {
- $url = str_replace('index.php', '', strtolower($_SERVER['PHP_SELF']));
- $url = trim($url, '/');
- $urlArray = explode("/", $url);
-
- $_GET['p'] = $urlArray[0];
- switch ($urlArray[0]) {
- case "feeds":
- $_GET['f'] = $urlArray[1];
- break;
- case "compatibility":
- $_GET['v'] = $urlArray[1];
- $_GET['t'] = $urlArray[2];
- break;
- case "news":
- $_GET['d'] = $urlArray[1];
- break;
- case "screenshots":
- $_GET['cat'] = $urlArray[1];
- $_GET['game'] = $urlArray[2];
- $_GET['num'] = $urlArray[3];
- break;
- }
-
-}
-$_SERVER['SCRIPT_NAME'] = '/index.php';
-require 'index.php';
diff --git a/include/Pages/CompatibilityPage.php b/include/Pages/CompatibilityPage.php
index 1dec6da..ec9b4a1 100644
--- a/include/Pages/CompatibilityPage.php
+++ b/include/Pages/CompatibilityPage.php
@@ -36,10 +36,10 @@ class CompatibilityPage extends Controller
}
/* Display the index page. */
- public function index()
+ public function index($args)
{
- $version = (!empty($_GET['v']) ? $_GET['v'] : 'DEV');
- $target = $_GET['t'];
+ $version = $args['version'];
+ $target = $args['game'];
/* Default to DEV */
$versions = CompatibilityModel::getAllVersions();
diff --git a/include/Pages/DocumentationPage.php b/include/Pages/DocumentationPage.php
index 0fe1e2a..ec7b63b 100644
--- a/include/Pages/DocumentationPage.php
+++ b/include/Pages/DocumentationPage.php
@@ -18,7 +18,6 @@ class DocumentationPage extends Controller
/* Display the index page. */
public function index()
{
- $document = $_GET['d'];
$documents = DocumentationModel::getAllDocuments();
return $this->renderPage(
diff --git a/include/Pages/FeedsPage.php b/include/Pages/FeedsPage.php
index c448348..3abee35 100644
--- a/include/Pages/FeedsPage.php
+++ b/include/Pages/FeedsPage.php
@@ -18,9 +18,9 @@ class FeedsPage extends Controller
}
/* Display the index page. */
- public function index()
+ public function index($args)
{
- $feed = $_GET['f'];
+ $feed = $args['type'];
if ($feed == 'atom') {
$template = $this->template_atom;
} else {
diff --git a/include/Pages/NewsPage.php b/include/Pages/NewsPage.php
index 7196cbc..98f46fd 100644
--- a/include/Pages/NewsPage.php
+++ b/include/Pages/NewsPage.php
@@ -17,9 +17,9 @@ class NewsPage extends Controller
}
/* Display the index page. */
- public function index()
+ public function index($args)
{
- $filename = isset($_GET['d']) ? $_GET['d'] : null;
+ $filename = $args['date'];
if ($filename != null) {
if (strtolower($filename) == 'archive' || $filename == '') {
diff --git a/include/Pages/ScreenshotsPage.php b/include/Pages/ScreenshotsPage.php
index cb0fd0e..ec1e49a 100644
--- a/include/Pages/ScreenshotsPage.php
+++ b/include/Pages/ScreenshotsPage.php
@@ -16,22 +16,19 @@ class ScreenshotsPage extends Controller
}
/* Display the index page. */
- public function index()
+ public function index($args)
{
- $category = $_GET['cat'];
- $game = $_GET['game'];
- $json = $_POST['json'];
+ $category = $args['category'];
+ $game = $args['game'];
- if (!empty($json)) {
- return $this->getAllJSON();
- } elseif (!empty($category)) {
+ $this->addJSFiles(array(
+ 'baguetteBox.min.js'
+ ));
+
+ if (!empty($category)) {
return $this->getCategory($category, $game);
}
- $this->addJSFiles(array(
- 'baguetteBox.min.js'
- ));
-
$screenshot = ScreenshotsModel::getAllScreenshots();
$random_shot = ScreenshotsModel::getRandomScreenshot();
@@ -50,10 +47,6 @@ class ScreenshotsPage extends Controller
/* Display the selected category. */
public function getCategory($category, $game)
{
- $this->addJSFiles(array(
- 'baguetteBox.min.js'
- ));
-
if (empty($game)) {
$screenshots = ScreenshotsModel::getCategoryScreenshots($category);
} else {
@@ -75,20 +68,4 @@ class ScreenshotsPage extends Controller
)
);
}
-
- /* Get a list with all screenshot filenames/captions as a JSON list. */
- public function getAllJSON()
- {
- $sshots = array();
- foreach (ScreenshotsModel::getAllScreenshots() as $category) {
- foreach ($category['games'] as $screenshot) {
- foreach ($screenshot->getFiles() as $files) {
- $files['filename'] = DIR_SCREENSHOTS . "/{$files['filename']}-full.png";
- $sshots[] = array_values($files);
- }
- }
- }
- print json_encode($sshots);
- return true;
- }
}
diff --git a/index.php b/index.php
index 80e3327..a4deccf 100644
--- a/index.php
+++ b/index.php
@@ -35,8 +35,9 @@ function get_preferred_languages()
return array();
}
-if (!empty($_REQUEST['lang'])) {
- $lang = $_REQUEST['lang'];
+if (!empty($_GET['lang'])) {
+ $lang = $_GET['lang'];
+ setcookie("lang", $lang, time()+86400, "/");
} elseif (!empty($_COOKIE['lang'])) {
$lang = $_COOKIE['lang'];
} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
@@ -53,12 +54,6 @@ if (!array_key_exists($lang, $available_languages)) {
$lang = 'en';
}
-/* We have to clean the mess introduced by double cookie at the wrong level */
-if (empty($_COOKIE['clear_lang'])) {
- setcookie("lang", 'deleted', 1); // Setting it a current domain level, as it stays one level up
- setcookie("clear_lang", "deleted", 1456167472); // Hardcoded to 22-Feb-2016 when previous cookie expires
-}
-
/* Load the global constants. */
new Constants();
@@ -78,28 +73,47 @@ set_exception_handler(array('ScummVM\ExceptionHandler', 'handleException'));
/* Page mapping. */
$pages = array(
- 'compatibility' => 'ScummVM\Pages\CompatibilityPage',
- 'contact' => 'ScummVM\Pages\ContactPage',
- 'credits' => 'ScummVM\Pages\CreditsPage',
- 'demos' => 'ScummVM\Pages\DemosPage',
- 'documentation' => 'ScummVM\Pages\DocumentationPage',
- 'downloads' => 'ScummVM\Pages\DownloadsPage',
- 'games' => 'ScummVM\Pages\GamesPage',
- 'faq' => 'ScummVM\Pages\FAQPage',
- 'feeds' => 'ScummVM\Pages\FeedsPage',
- 'links' => 'ScummVM\Pages\LinksPage',
- 'news' => 'ScummVM\Pages\NewsPage',
- 'press' => 'ScummVM\Pages\PressPage',
- 'presssnowberry' => 'ScummVM\Pages\PressSnowberryPage',
- 'screenshots' => 'ScummVM\Pages\ScreenshotsPage',
- 'subprojects' => 'ScummVM\Pages\SubprojectsPage',
+ '/compatibility' => '\ScummVM\Pages\CompatibilityPage',
+ '/compatibility/[cId:version]' => '\ScummVM\Pages\CompatibilityPage',
+ '/compatibility/[cId:version]/[a:game]' => '\ScummVM\Pages\CompatibilityPage',
+ '/contact' => '\ScummVM\Pages\ContactPage',
+ '/credits' => '\ScummVM\Pages\CreditsPage',
+ '/demos' => '\ScummVM\Pages\DemosPage',
+ '/documentation' => '\ScummVM\Pages\DocumentationPage',
+ '/downloads' => '\ScummVM\Pages\DownloadsPage',
+ '/games' => '\ScummVM\Pages\GamesPage',
+ '/faq' => '\ScummVM\Pages\FAQPage',
+ '/feeds' => '\ScummVM\Pages\FeedsPage',
+ '/feeds/[a:type]' => '\ScummVM\Pages\FeedsPage',
+ '/links' => '\ScummVM\Pages\LinksPage',
+ '/' => '\ScummVM\Pages\NewsPage',
+ '/news' => '\ScummVM\Pages\NewsPage',
+ '/news/[a:date]' => '\ScummVM\Pages\NewsPage',
+ '/press' => '\ScummVM\Pages\PressPage',
+ '/presssnowberry' => '\ScummVM\Pages\PressSnowberryPage', // HACK
+ '/screenshots' => '\ScummVM\Pages\ScreenshotsPage',
+ '/screenshots/[a:category]' => '\ScummVM\Pages\ScreenshotsPage',
+ '/screenshots/[a:category]/[a:game]' => '\ScummVM\Pages\ScreenshotsPage',
+ '/subprojects' => '\ScummVM\Pages\SubprojectsPage',
);
-/* Default to the news page. */
-if (!array_key_exists(($page = isset($_GET['p']) ? $_GET['p'] : null), $pages)) {
- $page = 'news';
+$router = new \AltoRouter();
+
+// Custom match for Compatability ID.
+$router->addMatchTypes(array('cId' => '(DEV)|[0-9\.]++'));
+
+foreach ($pages as $key => $value) {
+ $router->map('GET', $key, $value);
+ $router->map('GET', $key . '/', $value);
}
-/* Switch to the requested page */
-$p = new $pages[$page]();
-return $p->index();
+$match = $router->match();
+if ($match) {
+ $page = new $match['target']();
+ return $page->index($match['params']);
+} else {
+ $page = new \ScummVM\Pages\NewsPage();
+ return $page->index(array());
+}
+
+
More information about the Scummvm-git-logs
mailing list