1
0
www.mikescher.com/www/index.php

178 lines
12 KiB
PHP
Raw Normal View History

2017-10-21 23:04:06 +02:00
<?php
2017-11-09 17:43:34 +01:00
require_once (__DIR__ . '/internals/base.php');
$URL_RULES =
[
[ 'url' => [], 'target' => 'pages/main.php', 'options' => [], ],
[ 'url' => ['index'], 'target' => 'pages/main.php', 'options' => [], ],
[ 'url' => ['index.php'], 'target' => 'pages/main.php', 'options' => [], ],
[ 'url' => ['msmain', 'index'], 'target' => 'pages/main.php', 'options' => [], ],
[ 'url' => ['about'], 'target' => 'pages/about.php', 'options' => [], ],
[ 'url' => ['msmain', 'about'], 'target' => 'pages/about.php', 'options' => [], ],
[ 'url' => ['programs'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ],
[ 'url' => ['programs', 'index'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '%GET%' ], ],
[ 'url' => ['programs', 'index'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ],
[ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '%URL%' ], ],
[ 'url' => ['downloads', 'details.php'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ],
[ 'url' => ['downloads', 'downloads.php'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ],
[ 'url' => ['programs', 'view', '?{id}'], 'target' => 'pages/programs_view.php', 'options' => [ 'id' => '%URL%' ], ],
[ 'url' => ['programs', 'view'], 'target' => 'pages/programs_view.php', 'options' => [ 'id' => '%GET%' ], ],
[ 'url' => ['downloads', '?{id}'], 'target' => 'pages/programs_download.php', 'options' => [ 'id' => '%URL%' ], ],
[ 'url' => ['programs', 'download', '?{id}'], 'target' => 'pages/programs_download.php', 'options' => [ 'id' => '%URL%' ], ],
[ 'url' => ['programs', 'download'], 'target' => 'pages/programs_download.php', 'options' => [ 'id' => '%GET%' ], ],
[ 'url' => ['update.php'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%GET%' ], ],
[ 'url' => ['update.php', '?{Name}'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%URL%' ], ],
[ 'url' => ['update'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%GET%' ], ],
[ 'url' => ['update', '?{Name}'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%URL%' ], ],
[ 'url' => ['update2'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%GET%' ], ],
[ 'url' => ['api', 'update'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%GET%' ], ],
[ 'url' => ['api', 'update', '?{Name}'], 'target' => 'pages/api_updatecheck.php', 'options' => [ 'Name' => '%URL%' ], ],
[ 'url' => ['api', 'test'], 'target' => 'pages/api_test.php', 'options' => [], ],
[ 'url' => ['api', 'setselfadress'], 'target' => 'pages/api_setselfadress.php', 'options' => [], ],
2017-12-04 17:45:10 +01:00
[ 'url' => ['api', 'statsping'], 'target' => 'pages/api_stats.php', 'options' => [ 'Name' => '%GET%', 'ClientID' => '%GET%', 'Version' => '%GET%', 'ProviderStr' => '%GET%', 'ProviderID' => '%GET%', 'NoteCount' => '%GET%', ], ],
2017-11-09 17:43:34 +01:00
[ 'url' => ['msmain', 'admin', 'egh', '?{commandcode}'], 'target' => 'pages/admin_egh.php', 'options' => [ 'commandcode' => '%URL%' ], ],
[ 'url' => ['msmain', 'adminEGH'], 'target' => 'pages/admin_egh.php', 'options' => [ 'commandcode' => '%GET%' ], ],
2017-12-30 23:11:51 +01:00
2017-11-09 17:43:34 +01:00
[ 'url' => ['blog'], 'target' => 'pages/blog_list.php', 'options' => [], ],
2017-12-30 23:11:51 +01:00
[ 'url' => ['log'], 'target' => 'pages/blog_list.php', 'options' => [], ],
2017-11-09 17:43:34 +01:00
[ 'url' => ['blogpost', 'index'], 'target' => 'pages/blog_list.php', 'options' => [], ],
[ 'url' => ['blog', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['blog', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ],
2017-12-30 23:11:51 +01:00
[ 'url' => ['log', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['log', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ],
2017-11-09 17:43:34 +01:00
[ 'url' => ['blogpost', 'view'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%GET%', 'subview' => '' ], ],
[ 'url' => ['highscores', 'list.php'], 'target' => 'pages/highscores_listentries.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'list'], 'target' => 'pages/highscores_listentries.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'listentries'], 'target' => 'pages/highscores_listentries.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'list.php'], 'target' => 'pages/highscores_listgames.php', 'options' => [], ],
[ 'url' => ['highscores', 'list'], 'target' => 'pages/highscores_listgames.php', 'options' => [], ],
[ 'url' => ['highscores', 'listgames'], 'target' => 'pages/highscores_listgames.php', 'options' => [], ],
[ 'url' => ['highscores', 'insert.php'], 'target' => 'pages/highscores_insert.php', 'options' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ],
[ 'url' => ['highscores', 'insert'], 'target' => 'pages/highscores_insert.php', 'options' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ],
[ 'url' => ['highscores', 'update.php'], 'target' => 'pages/highscores_update.php', 'options' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'update'], 'target' => 'pages/highscores_update.php', 'options' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'list_top50.php'], 'target' => 'pages/highscores_top50.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'list_top50'], 'target' => 'pages/highscores_top50.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'getNewID.php'], 'target' => 'pages/highscores_newid.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['highscores', 'newid'], 'target' => 'pages/highscores_newid.php', 'options' => [ 'gameid' => '%GET%' ], ],
[ 'url' => ['404'], 'target' => 'pages/error_404.php', 'options' => [], ],
];
//#############################################################################
2018-01-03 17:28:08 +01:00
try {
InitPHP();
2017-10-21 23:04:06 +02:00
2018-01-03 22:08:56 +01:00
if (isProd())
$requri = $_SERVER['REQUEST_URI'];
else
$requri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'localhost:80/';
$parse = parse_url($requri);
$path = strtolower(isset($parse['path']) ? $parse['path'] : '');
2018-01-03 17:28:08 +01:00
$pathparts = preg_split('@/@', $path, NULL, PREG_SPLIT_NO_EMPTY);
$partcount = count($pathparts);
2018-01-03 01:03:43 +01:00
2018-01-03 17:28:08 +01:00
global $OPTIONS;
global $HEADER_ACTIVE;
2017-10-21 23:04:06 +02:00
2018-01-03 17:28:08 +01:00
$HEADER_ACTIVE = 'none';
foreach ($URL_RULES as $rule)
2017-11-09 17:43:34 +01:00
{
2018-01-03 17:28:08 +01:00
if ($partcount !== count($rule['url'])) continue;
$urlparams = [];
$match = true;
for($i = 0; $i < $partcount; $i++)
2017-11-09 17:43:34 +01:00
{
2018-01-03 17:28:08 +01:00
$comp = $rule['url'][$i];
if (startsWith($comp, '?{') && endsWith($comp, '}'))
{
$ident = substr($comp, 2, strlen($comp)-3);
$urlparams[$ident] = $pathparts[$i];
}
else
{
if (strtolower($comp) !== strtolower($pathparts[$i])) { $match = false; break; }
}
2017-11-09 17:43:34 +01:00
}
2018-01-03 17:28:08 +01:00
if (!$match) continue;
$opt = [];
foreach($rule['options'] as $optname => $optvalue)
2017-11-09 17:43:34 +01:00
{
2018-01-03 17:28:08 +01:00
$value = $optvalue;
if ($value === '%GET%')
{
if (!isset($_GET[$optname])) { $match = false; break; }
$value = $_GET[$optname];
}
else if ($value === '%POST%')
{
if (!isset($_POST[$optname])) { $match = false; break; }
$value = $_POST[$optname];
}
else if ($value === '%URL%')
{
if (!isset($urlparams[$optname])) { $match = false; break; }
2018-01-20 03:05:15 +01:00
$value = urldecode($urlparams[$optname]);
2018-01-03 17:28:08 +01:00
}
$opt[strtolower($optname)] = $value;
2017-11-09 17:43:34 +01:00
}
2018-01-03 17:28:08 +01:00
if (!$match) continue;
$OPTIONS = $opt;
include $rule['target'];
return;
2017-11-09 17:43:34 +01:00
}
2018-01-03 17:28:08 +01:00
2017-11-09 17:43:34 +01:00
{
2018-01-03 17:28:08 +01:00
// [404] - Page Not Found
$OPTIONS = [];
httpError('404', 'Page not found');
return;
}
} catch (Exception $e) {
if (isProd())
{
httpError('500 ', 'Internal server error');
}
else
{
echo '<table class="xdebug-error xe-uncaught-exception" dir="ltr" border="1" cellspacing="0" cellpadding="1">'.$e->xdebug_message.'</table>';
2017-11-09 17:43:34 +01:00
}
2017-10-21 23:04:06 +02:00
}
2017-12-04 17:45:10 +01:00
//TODO printed books 2 hp
//TODO programs (sort out)
//TODO fast
//TODO gzip (?)
//TODO better gh widget
2017-12-15 17:22:59 +01:00
//TODO remove db table prefixes
2018-01-20 03:05:15 +01:00
//TODO euler insert+show 32bit | 64bit mode
//TODO euler best of on top of list (?)
//TODO optimize image sizes for display/download (? - auto?)
//TODO send cache header (?)
2018-01-21 15:29:01 +01:00
//TODO programs add [license]
//TODO admin
//TODO last 3 blog entries on /index/ (?)