mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-30 03:09:22 +02:00
Rewriting the router v2
To be more flexible
This commit is contained in:
parent
7bfa21a239
commit
60f64e21d8
@ -52,9 +52,6 @@ if(!$logged || !admin()) {
|
|||||||
$page = 'login';
|
$page = 'login';
|
||||||
}
|
}
|
||||||
|
|
||||||
// more pages have action, lets define it here
|
|
||||||
$action = $_REQUEST['action'] ?? '';
|
|
||||||
|
|
||||||
// include our page
|
// include our page
|
||||||
$file = BASE . 'admin/pages/' . $page . '.php';
|
$file = BASE . 'admin/pages/' . $page . '.php';
|
||||||
if(!@file_exists($file)) {
|
if(!@file_exists($file)) {
|
||||||
|
51
index.php
51
index.php
@ -28,19 +28,13 @@ require_once 'common.php';
|
|||||||
require_once SYSTEM . 'functions.php';
|
require_once SYSTEM . 'functions.php';
|
||||||
|
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
$uri = $_SERVER['REQUEST_URI'];
|
||||||
|
if(false !== strpos($uri, 'index.php')) {
|
||||||
$tmp = BASE_DIR;
|
$uri = str_replace_first('/index.php', '', $uri);
|
||||||
if(!empty($tmp))
|
|
||||||
$uri = str_replace(BASE_DIR . '/', '', $uri);
|
|
||||||
else
|
|
||||||
$uri = str_replace_first('/', '', $uri);
|
|
||||||
|
|
||||||
$uri = str_replace_first('index.php', '', $uri);
|
|
||||||
if(($pos = strpos($uri, '?') === 0) || $pos == 9) {
|
|
||||||
$uri = str_replace_first('?', '', $uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
define('URI', $uri);
|
if(0 === strpos($uri, '/')) {
|
||||||
|
$uri = str_replace_first('/', '', $uri);
|
||||||
|
}
|
||||||
|
|
||||||
if(preg_match("/^[A-Za-z0-9-_%'+]+\.png$/i", $uri)) {
|
if(preg_match("/^[A-Za-z0-9-_%'+]+\.png$/i", $uri)) {
|
||||||
$tmp = explode('.', $uri);
|
$tmp = explode('.', $uri);
|
||||||
@ -51,7 +45,7 @@ if(preg_match("/^[A-Za-z0-9-_%'+]+\.png$/i", $uri)) {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|php|zip|rar|gz|ttf|woff|ico)$/i", $_SERVER['REQUEST_URI'])) {
|
if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|zip|rar|gz|ttf|woff|ico)$/i", $_SERVER['REQUEST_URI'])) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -98,6 +92,8 @@ require_once SYSTEM . 'status.php';
|
|||||||
$twig->addGlobal('config', $config);
|
$twig->addGlobal('config', $config);
|
||||||
$twig->addGlobal('status', $status);
|
$twig->addGlobal('status', $status);
|
||||||
|
|
||||||
|
require_once SYSTEM . 'router.php';
|
||||||
|
|
||||||
require SYSTEM . 'migrate.php';
|
require SYSTEM . 'migrate.php';
|
||||||
|
|
||||||
$hooks->trigger(HOOK_STARTUP);
|
$hooks->trigger(HOOK_STARTUP);
|
||||||
@ -146,35 +142,6 @@ if($config['visitors_counter'])
|
|||||||
$visitors = new Visitors($config['visitors_counter_ttl']);
|
$visitors = new Visitors($config['visitors_counter_ttl']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// page content loading
|
|
||||||
if(!isset($content[0]))
|
|
||||||
$content = '';
|
|
||||||
$load_it = true;
|
|
||||||
|
|
||||||
// check if site has been closed
|
|
||||||
$site_closed = false;
|
|
||||||
if(fetchDatabaseConfig('site_closed', $site_closed)) {
|
|
||||||
$site_closed = ($site_closed == 1);
|
|
||||||
if($site_closed) {
|
|
||||||
if(!admin())
|
|
||||||
{
|
|
||||||
$title = getDatabaseConfig('site_closed_title');
|
|
||||||
$content .= '<p class="note">' . getDatabaseConfig('site_closed_message') . '</p><br/>';
|
|
||||||
$load_it = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$logged)
|
|
||||||
{
|
|
||||||
ob_start();
|
|
||||||
require SYSTEM . 'pages/account/manage.php';
|
|
||||||
$content .= ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
$load_it = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
define('SITE_CLOSED', $site_closed);
|
|
||||||
|
|
||||||
// backward support for gesior
|
// backward support for gesior
|
||||||
if($config['backward_support']) {
|
if($config['backward_support']) {
|
||||||
define('INITIALIZED', true);
|
define('INITIALIZED', true);
|
||||||
@ -212,8 +179,6 @@ if($config['backward_support']) {
|
|||||||
$config['status']['serverStatus_' . $key] = $value;
|
$config['status']['serverStatus_' . $key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
require SYSTEM . 'router.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var OTS_Account $account_logged
|
* @var OTS_Account $account_logged
|
||||||
*/
|
*/
|
||||||
|
@ -40,11 +40,9 @@
|
|||||||
"method": "GET",
|
"method": "GET",
|
||||||
"priority": "130"
|
"priority": "130"
|
||||||
},
|
},
|
||||||
"Second Route": {
|
"Redirect Example": {
|
||||||
"pattern": "/YourSecondRoute",
|
"pattern": "/redirectExample",
|
||||||
"file": "plugins/your-plugin/your-awesome-page-two.php",
|
"file": "account/manage"
|
||||||
"method": "GET,POST",
|
|
||||||
"priority": "120"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,10 @@ switch($page)
|
|||||||
$page = 'news';
|
$page = 'news';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'newsarchive':
|
||||||
|
$page = 'news/archive';
|
||||||
|
break;
|
||||||
|
|
||||||
case 'tibiarules':
|
case 'tibiarules':
|
||||||
$page = 'rules';
|
$page = 'rules';
|
||||||
break;
|
break;
|
||||||
|
@ -62,20 +62,20 @@ function getFullLink($page, $name, $blank = false) {
|
|||||||
function getLink($page, $action = null)
|
function getLink($page, $action = null)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
return BASE_URL . ($config['friendly_urls'] ? '' : '?') . $page . ($action ? '/' . $action : '');
|
return BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . $page . ($action ? '/' . $action : '');
|
||||||
}
|
}
|
||||||
function internalLayoutLink($page, $action = null) {return getLink($page, $action);}
|
function internalLayoutLink($page, $action = null) {return getLink($page, $action);}
|
||||||
|
|
||||||
function getForumThreadLink($thread_id, $page = NULL)
|
function getForumThreadLink($thread_id, $page = NULL)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
return BASE_URL . ($config['friendly_urls'] ? '' : '?') . 'forum/thread/' . (int)$thread_id . (isset($page) ? '/' . $page : '');
|
return BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . 'forum/thread/' . (int)$thread_id . (isset($page) ? '/' . $page : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getForumBoardLink($board_id, $page = NULL)
|
function getForumBoardLink($board_id, $page = NULL)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
return BASE_URL . ($config['friendly_urls'] ? '' : '?') . 'forum/board/' . (int)$board_id . (isset($page) ? '/' . $page : '');
|
return BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . 'forum/board/' . (int)$board_id . (isset($page) ? '/' . $page : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayerLink($name, $generate = true)
|
function getPlayerLink($name, $generate = true)
|
||||||
@ -90,7 +90,7 @@ function getPlayerLink($name, $generate = true)
|
|||||||
$name = $player->getName();
|
$name = $player->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = BASE_URL . ($config['friendly_urls'] ? '' : '?') . 'characters/' . urlencode($name);
|
$url = BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . 'characters/' . urlencode($name);
|
||||||
|
|
||||||
if(!$generate) return $url;
|
if(!$generate) return $url;
|
||||||
return generateLink($url, $name);
|
return generateLink($url, $name);
|
||||||
@ -100,7 +100,7 @@ function getMonsterLink($name, $generate = true)
|
|||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$url = BASE_URL . ($config['friendly_urls'] ? '' : '?') . 'creatures/' . urlencode($name);
|
$url = BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . 'creatures/' . urlencode($name);
|
||||||
|
|
||||||
if(!$generate) return $url;
|
if(!$generate) return $url;
|
||||||
return generateLink($url, $name);
|
return generateLink($url, $name);
|
||||||
@ -118,7 +118,7 @@ function getHouseLink($name, $generate = true)
|
|||||||
$name = $house->fetchColumn();
|
$name = $house->fetchColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = BASE_URL . ($config['friendly_urls'] ? '' : '?') . 'houses/' . urlencode($name);
|
$url = BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . 'houses/' . urlencode($name);
|
||||||
|
|
||||||
if(!$generate) return $url;
|
if(!$generate) return $url;
|
||||||
return generateLink($url, $name);
|
return generateLink($url, $name);
|
||||||
@ -136,7 +136,7 @@ function getGuildLink($name, $generate = true)
|
|||||||
$name = $guild->fetchColumn();
|
$name = $guild->fetchColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = BASE_URL . ($config['friendly_urls'] ? '' : '?') . 'guilds/' . urlencode($name);
|
$url = BASE_URL . ($config['friendly_urls'] ? '' : 'index.php/') . 'guilds/' . urlencode($name);
|
||||||
|
|
||||||
if(!$generate) return $url;
|
if(!$generate) return $url;
|
||||||
return generateLink($url, $name);
|
return generateLink($url, $name);
|
||||||
@ -268,6 +268,13 @@ function getForumBoards()
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// convert forum threads links from just forum/ID
|
||||||
|
// INTO: forum/thread-name-id, like in XenForo
|
||||||
|
//function convertForumThreadTitle($title) {
|
||||||
|
// return str_replace(' ', '-', strtolower($title));
|
||||||
|
//}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves data from myaac database config.
|
* Retrieves data from myaac database config.
|
||||||
*
|
*
|
||||||
@ -1493,6 +1500,11 @@ function getAccountLoginByLabel()
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function camelCaseToUnderscore($input)
|
||||||
|
{
|
||||||
|
return ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $input)), '_');
|
||||||
|
}
|
||||||
|
|
||||||
// validator functions
|
// validator functions
|
||||||
require_once LIBS . 'validator.php';
|
require_once LIBS . 'validator.php';
|
||||||
require_once SYSTEM . 'compat/base.php';
|
require_once SYSTEM . 'compat/base.php';
|
||||||
|
@ -34,6 +34,10 @@ $cache = Cache::getInstance();
|
|||||||
// twig
|
// twig
|
||||||
require_once SYSTEM . 'twig.php';
|
require_once SYSTEM . 'twig.php';
|
||||||
|
|
||||||
|
// action, used by many pages
|
||||||
|
$action = $_REQUEST['action'] ?? '';
|
||||||
|
define('ACTION', $action);
|
||||||
|
|
||||||
// trim values we receive
|
// trim values we receive
|
||||||
if(isset($_POST))
|
if(isset($_POST))
|
||||||
{
|
{
|
||||||
|
@ -9,5 +9,4 @@
|
|||||||
* @link https://my-aac.org
|
* @link https://my-aac.org
|
||||||
*/
|
*/
|
||||||
$_GET['archive'] = true;
|
$_GET['archive'] = true;
|
||||||
require 'news.php';
|
require __DIR__ . '/../news.php';
|
||||||
?>
|
|
@ -8,6 +8,35 @@
|
|||||||
* @link https://my-aac.org
|
* @link https://my-aac.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if(!isset($content[0]))
|
||||||
|
$content = '';
|
||||||
|
|
||||||
|
// check if site has been closed
|
||||||
|
$load_it = true;
|
||||||
|
$site_closed = false;
|
||||||
|
if(fetchDatabaseConfig('site_closed', $site_closed)) {
|
||||||
|
$site_closed = ($site_closed == 1);
|
||||||
|
if($site_closed) {
|
||||||
|
if(!admin())
|
||||||
|
{
|
||||||
|
$title = getDatabaseConfig('site_closed_title');
|
||||||
|
$content .= '<p class="note">' . getDatabaseConfig('site_closed_message') . '</p><br/>';
|
||||||
|
$load_it = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$logged)
|
||||||
|
{
|
||||||
|
ob_start();
|
||||||
|
require SYSTEM . 'pages/account/manage.php';
|
||||||
|
$content .= ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
$load_it = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
define('SITE_CLOSED', $site_closed);
|
||||||
|
|
||||||
|
/** @var boolean $load_it */
|
||||||
if(!$load_it) {
|
if(!$load_it) {
|
||||||
// ignore warnings in some functions/plugins
|
// ignore warnings in some functions/plugins
|
||||||
// page is not loaded anyways
|
// page is not loaded anyways
|
||||||
@ -17,59 +46,55 @@ if(!$load_it) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var string $content */
|
||||||
if(SITE_CLOSED && admin())
|
if(SITE_CLOSED && admin())
|
||||||
$content .= '<p class="note">Site is under maintenance (closed mode). Only privileged users can see it.</p>';
|
$content .= '<p class="note">Site is under maintenance (closed mode). Only privileged users can see it.</p>';
|
||||||
|
|
||||||
$ignore = false;
|
$ignore = false;
|
||||||
|
|
||||||
|
/** @var boolean $logged */
|
||||||
|
/** @var OTS_Account $account_logged */
|
||||||
$logged_access = 1;
|
$logged_access = 1;
|
||||||
if($logged && $account_logged && $account_logged->isLoaded()) {
|
if($logged && $account_logged && $account_logged->isLoaded()) {
|
||||||
$logged_access = $account_logged->getAccess();
|
$logged_access = $account_logged->getAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = false;
|
/**
|
||||||
$tmp_content = getCustomPage($uri, $success);
|
* Routes loading
|
||||||
if($success) {
|
*/
|
||||||
$content .= $tmp_content;
|
|
||||||
if(hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) {
|
|
||||||
$pageInfo = getCustomPageInfo($uri);
|
|
||||||
$content = $twig->render('admin.pages.links.html.twig', array(
|
|
||||||
'page' => array('id' => $pageInfo !== null ? $pageInfo['id'] : 0, 'hidden' => $pageInfo !== null ? $pageInfo['hidden'] : '0')
|
|
||||||
)) . $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
$page = $uri;
|
|
||||||
} else {
|
|
||||||
// old support for pages like /?subtopic=accountmanagement
|
|
||||||
$page = $_REQUEST['p'] ?? ($_REQUEST['subtopic'] ?? '');
|
|
||||||
if(!empty($page) && preg_match('/^[A-z0-9\-]+$/', $page)) {
|
|
||||||
if(config('backward_support')) {
|
|
||||||
require SYSTEM . 'compat_pages.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
$file = SYSTEM . 'pages/' . $page . '.php';
|
|
||||||
if (!is_file($file)) {
|
|
||||||
$page = '404';
|
|
||||||
$file = SYSTEM . 'pages/404.php';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$dispatcher = FastRoute\cachedDispatcher(function (FastRoute\RouteCollector $r) {
|
$dispatcher = FastRoute\cachedDispatcher(function (FastRoute\RouteCollector $r) {
|
||||||
$routes = require SYSTEM . 'routes.php';
|
$routes = require SYSTEM . 'routes.php';
|
||||||
|
|
||||||
$duplicates = [];
|
$duplicates = [];
|
||||||
|
|
||||||
|
$routesTmp = [];
|
||||||
|
foreach(getDatabasePages() as $page) {
|
||||||
|
$duplicates[$page] = true;
|
||||||
|
$routesTmp[] = [['GET', 'POST'], $page, 'database/' . $page, true];
|
||||||
|
}
|
||||||
|
|
||||||
Plugins::clearWarnings();
|
Plugins::clearWarnings();
|
||||||
foreach (Plugins::getRoutes() as $route) {
|
foreach (Plugins::getRoutes() as $route) {
|
||||||
|
if(!isset($duplicates[$route[1]])) {
|
||||||
$duplicates[$route[1]] = true;
|
$duplicates[$route[1]] = true;
|
||||||
$r->addRoute($route[0], '/' . $route[1], $route[2]);
|
$routesTmp[] = [$route[0], $route[1], $route[2]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($routes as $route) {
|
foreach ($routes as $route) {
|
||||||
if(!isset($duplicates[$route[1]])) {
|
if(!isset($duplicates[$route[1]])) {
|
||||||
$r->addRoute($route[0], '/' . $route[1], 'system/pages/' . $route[2]);
|
$routesTmp[] = [$route[0], $route[1], 'system/pages/' . $route[2]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($routesTmp as $route) {
|
||||||
|
if (strpos($route[2], '.php') === false && !isset($route[3])) {
|
||||||
|
$route[2] = str_replace('system/pages/', '', 'redirect/' . $route[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$r->addRoute($route[0], $route[1], $route[2]);
|
||||||
|
}
|
||||||
|
|
||||||
if (config('env') === 'dev') {
|
if (config('env') === 'dev') {
|
||||||
foreach(Plugins::getWarnings() as $warning) {
|
foreach(Plugins::getWarnings() as $warning) {
|
||||||
log_append('router.log', $warning);
|
log_append('router.log', $warning);
|
||||||
@ -82,11 +107,11 @@ if($success) {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetch method and URI from somewhere
|
// Fetch method and URI
|
||||||
$httpMethod = $_SERVER['REQUEST_METHOD'];
|
$httpMethod = $_SERVER['REQUEST_METHOD'];
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
|
||||||
|
|
||||||
// Strip query string (?foo=bar) and decode URI
|
// Strip query string (?foo=bar) and decode URI
|
||||||
|
/** @var string $uri */
|
||||||
if (false !== $pos = strpos($uri, '?')) {
|
if (false !== $pos = strpos($uri, '?')) {
|
||||||
if ($pos !== 1) {
|
if ($pos !== 1) {
|
||||||
$uri = substr($uri, 0, $pos);
|
$uri = substr($uri, 0, $pos);
|
||||||
@ -95,50 +120,39 @@ if($success) {
|
|||||||
$uri = str_replace_first('?', '', $uri);
|
$uri = str_replace_first('?', '', $uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$uri = rawurldecode($uri);
|
|
||||||
|
|
||||||
|
$uri = rawurldecode($uri);
|
||||||
|
define('URI', $uri);
|
||||||
|
|
||||||
|
$found = true;
|
||||||
|
|
||||||
|
// old support for pages like /?subtopic=accountmanagement
|
||||||
|
$page = $_REQUEST['p'] ?? ($_REQUEST['subtopic'] ?? '');
|
||||||
|
if(!empty($page) && preg_match('/^[A-z0-9\-]+$/', $page)) {
|
||||||
|
if (config('backward_support')) {
|
||||||
|
require SYSTEM . 'compat/pages.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = loadPageFromFileSystem($page, $found);
|
||||||
|
if(!$found) {
|
||||||
|
$file = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
|
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
|
||||||
switch ($routeInfo[0]) {
|
switch ($routeInfo[0]) {
|
||||||
case FastRoute\Dispatcher::NOT_FOUND:
|
case FastRoute\Dispatcher::NOT_FOUND:
|
||||||
// ... 404 Not Found
|
// ... 404 Not Found
|
||||||
$tmp = URI;
|
//var_dump('not found');
|
||||||
$found = true;
|
/**
|
||||||
|
* Fallback to load page from templates/ or system/pages/ directory
|
||||||
$page = $tmp;
|
*/
|
||||||
if (preg_match('/^[A-z0-9\/\-]+$/', $tmp)) {
|
$page = $uri;
|
||||||
global $template_path;
|
if (preg_match('/^[A-z0-9\/\-]+$/', $page)) {
|
||||||
$file = $template_path . '/pages/' . $tmp . '.php';
|
$file = loadPageFromFileSystem($page, $found);
|
||||||
if (!is_file($file)) {
|
} else {
|
||||||
$file = SYSTEM . 'pages/' . $tmp . '.php';
|
|
||||||
if (!is_file($file)) {
|
|
||||||
$found = false;
|
$found = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$tmp_ = BASE_DIR;
|
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
|
||||||
if (!empty($tmp)) {
|
|
||||||
$uri = str_replace(BASE_DIR . '/', '', $uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false !== $pos = strpos($uri, '?')) {
|
|
||||||
$tmp = substr($uri, 0, $pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($tmp)) {
|
|
||||||
$page = 'news';
|
|
||||||
$file = SYSTEM . 'pages/news.php';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$found = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$found) {
|
|
||||||
$page = '404';
|
|
||||||
$file = SYSTEM . 'pages/404.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -156,6 +170,29 @@ if($success) {
|
|||||||
$_REQUEST = array_merge($_REQUEST, $vars);
|
$_REQUEST = array_merge($_REQUEST, $vars);
|
||||||
$_GET = array_merge($_GET, $vars);
|
$_GET = array_merge($_GET, $vars);
|
||||||
|
|
||||||
|
if (strpos($path, 'database/') !== false) {
|
||||||
|
//var_dump($path);
|
||||||
|
$pageName = str_replace('database/', '', $path);
|
||||||
|
|
||||||
|
$success = false;
|
||||||
|
$tmp_content = getCustomPage($pageName, $success);
|
||||||
|
if ($success) {
|
||||||
|
$content .= $tmp_content;
|
||||||
|
if (hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) {
|
||||||
|
$pageInfo = getCustomPageInfo($pageName);
|
||||||
|
$content = $twig->render('admin.pages.links.html.twig', array(
|
||||||
|
'page' => array('id' => $pageInfo !== null ? $pageInfo['id'] : 0, 'hidden' => $pageInfo !== null ? $pageInfo['hidden'] : '0')
|
||||||
|
)) . $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = $pageName;
|
||||||
|
$file = false;
|
||||||
|
}
|
||||||
|
} else if (strpos($path, 'redirect/') !== false) {
|
||||||
|
$path = str_replace('redirect/', '', $path);
|
||||||
|
header('Location: ' . BASE_URL . $path);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
// parse for define PAGE
|
// parse for define PAGE
|
||||||
$tmp = BASE_DIR;
|
$tmp = BASE_DIR;
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
$uri = $_SERVER['REQUEST_URI'];
|
||||||
@ -172,24 +209,23 @@ if($success) {
|
|||||||
|
|
||||||
$page = $uri;
|
$page = $uri;
|
||||||
$file = BASE . $path;
|
$file = BASE . $path;
|
||||||
|
}
|
||||||
|
|
||||||
unset($tmp, $uri);
|
unset($tmp, $uri);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$found) {
|
||||||
|
$page = '404';
|
||||||
|
$file = SYSTEM . 'pages/404.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
define('PAGE', $page);
|
define('PAGE', $page);
|
||||||
if(config('backward_support')) {
|
|
||||||
$subtopic = $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = isset($_REQUEST['action']) ? strtolower($_REQUEST['action']) : '';
|
|
||||||
define('ACTION', $action);
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
if($hooks->trigger(HOOK_BEFORE_PAGE)) {
|
if($hooks->trigger(HOOK_BEFORE_PAGE)) {
|
||||||
if(!$ignore)
|
if(!$ignore && $file !== false)
|
||||||
require $file;
|
require $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,13 +238,49 @@ $content .= ob_get_contents();
|
|||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
$hooks->trigger(HOOK_AFTER_PAGE);
|
$hooks->trigger(HOOK_AFTER_PAGE);
|
||||||
|
|
||||||
if(config('backward_support')) {
|
|
||||||
$main_content = $content;
|
|
||||||
if(!isset($title)) {
|
if(!isset($title)) {
|
||||||
$title = ucfirst($page);
|
$title = ucfirst($page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config('backward_support')) {
|
||||||
|
$main_content = $content;
|
||||||
$topic = $title;
|
$topic = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($page);
|
unset($page);
|
||||||
|
|
||||||
|
function getDatabasePages() {
|
||||||
|
global $db;
|
||||||
|
$pages = $db->query('SELECT `name` FROM ' . TABLE_PREFIX . 'pages');
|
||||||
|
$ret = [];
|
||||||
|
|
||||||
|
if ($pages->rowCount() < 1) {
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($pages->fetchAll() as $page) {
|
||||||
|
$ret [] = $page['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadPageFromFileSystem($page, &$found) {
|
||||||
|
$file = SYSTEM . 'pages/' . $page . '.php';
|
||||||
|
if (!is_file($file)) {
|
||||||
|
// feature: convert camelCase to snake_case
|
||||||
|
// so instead of forum/move_thread
|
||||||
|
// we can write: forum/moveThread
|
||||||
|
$file = SYSTEM . 'pages/' . camelCaseToUnderscore($page) . '.php';
|
||||||
|
if (!is_file($file)) {
|
||||||
|
// feature: load pages from templates/ dir
|
||||||
|
global $template_path;
|
||||||
|
$file = $template_path . '/pages/' . $page . '.php';
|
||||||
|
if (!is_file($file)) {
|
||||||
|
$found = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
@ -9,9 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
['GET', '', 'news'], // redirect empty URL to news
|
||||||
|
['GET', 'news/archive/{id:[0-9]+}[/]', 'news/archive.php'],
|
||||||
|
|
||||||
[['GET', 'POST'], 'account/base[/]', '404.php'], // this is to block account/base.php
|
[['GET', 'POST'], 'account/base[/]', '404.php'], // this is to block account/base.php
|
||||||
[['GET', 'POST'], 'account/password[/]', 'account/change_password.php'],
|
[['GET', 'POST'], 'account/password[/]', 'account/change_password.php'],
|
||||||
[['GET', 'POST'], 'account/register[/]', 'account/register.php'],
|
|
||||||
[['GET', 'POST'], 'account/register/new[/]', 'account/register_new.php'],
|
[['GET', 'POST'], 'account/register/new[/]', 'account/register_new.php'],
|
||||||
[['GET', 'POST'], 'account/email[/]', 'account/change_email.php'],
|
[['GET', 'POST'], 'account/email[/]', 'account/change_email.php'],
|
||||||
[['GET', 'POST'], 'account/info[/]', 'account/change_info.php'],
|
[['GET', 'POST'], 'account/info[/]', 'account/change_info.php'],
|
||||||
@ -22,7 +24,7 @@ return [
|
|||||||
[['GET', 'POST'], 'account/character/comment[/{name:[A-Za-z0-9-_%+\']+}]', 'account/change_comment.php'],
|
[['GET', 'POST'], 'account/character/comment[/{name:[A-Za-z0-9-_%+\']+}]', 'account/change_comment.php'],
|
||||||
['GET', 'account/confirm_email/{hash:[A-Za-z0-9-_]+}[/]', 'account/confirm_email.php'],
|
['GET', 'account/confirm_email/{hash:[A-Za-z0-9-_]+}[/]', 'account/confirm_email.php'],
|
||||||
|
|
||||||
['GET', 'bans[/{page:\d+}]', 'bans.php'],
|
['GET', 'bans/{page:\d+}[/]', 'bans.php'],
|
||||||
[['GET', 'POST'], 'characters[/{name:[A-Za-z0-9-_%+\']+}]', 'characters.php'],
|
[['GET', 'POST'], 'characters[/{name:[A-Za-z0-9-_%+\']+}]', 'characters.php'],
|
||||||
['GET', 'changelog[/{page:\d+}]', 'changelog.php'],
|
['GET', 'changelog[/{page:\d+}]', 'changelog.php'],
|
||||||
['GET', 'creatures[/{name:[A-Za-z0-9-_%+\']+}]', 'creatures.php'],
|
['GET', 'creatures[/{name:[A-Za-z0-9-_%+\']+}]', 'creatures.php'],
|
||||||
@ -45,9 +47,7 @@ return [
|
|||||||
['GET', 'highscores/{list:[A-Za-z0-9-_]+}/{vocation:[A-Za-z0-9-_]+}[/]', 'highscores.php'],
|
['GET', 'highscores/{list:[A-Za-z0-9-_]+}/{vocation:[A-Za-z0-9-_]+}[/]', 'highscores.php'],
|
||||||
['GET', 'highscores/{list:[A-Za-z0-9-_]+}[/]', 'highscores.php'],
|
['GET', 'highscores/{list:[A-Za-z0-9-_]+}[/]', 'highscores.php'],
|
||||||
|
|
||||||
['GET', '', 'news.php'],
|
['GET', 'online/{order:[A-Za-z0-9-_]+}[/]', 'online.php'],
|
||||||
[['GET', 'POST'], 'news/archive[/]', 'newsarchive.php'],
|
|
||||||
['GET', 'news/archive/{id:[0-9]+}[/]', 'newsarchive.php'],
|
|
||||||
/*
|
/*
|
||||||
'/^gifts\/history\/?$/' => array('subtopic' => 'gifts', 'action' => 'show_history'),
|
'/^gifts\/history\/?$/' => array('subtopic' => 'gifts', 'action' => 'show_history'),
|
||||||
'/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1'),
|
'/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1'),
|
||||||
|
@ -85,14 +85,14 @@
|
|||||||
<table border="0" cellspacing="1" cellpadding="4" width="100%">
|
<table border="0" cellspacing="1" cellpadding="4" width="100%">
|
||||||
<tr bgcolor="{{ config.vdarkborder }}">
|
<tr bgcolor="{{ config.vdarkborder }}">
|
||||||
{% if config.account_country %}
|
{% if config.account_country %}
|
||||||
<td width="11px"><a href="?subtopic=online&order=country" class="white">#</A></td>
|
<td width="11px"><a href="{{ getLink('online?order=country') }}" class="white">#</A></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.online_outfit %}
|
{% if config.online_outfit %}
|
||||||
<td class="white"><b>Outfit</b></td>
|
<td class="white"><b>Outfit</b></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td width="60%"><a href="?subtopic=online&order=name" class="white">Name</A></td>
|
<td width="60%"><a href="{{ getLink('online?order=name') }}" class="white">Name</A></td>
|
||||||
<td width="20%"><a href="?subtopic=online&order=level" class="white">Level</A></td>
|
<td width="20%"><a href="{{ getLink('online?order=level') }}" class="white">Level</A></td>
|
||||||
<td width="20%"><a href="?subtopic=online&order=vocation" class="white">Vocation</td>
|
<td width="20%"><a href="{{ getLink('online?order=vocation') }}" class="white">Vocation</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% set i = 0 %}
|
{% set i = 0 %}
|
||||||
{% for player in players %}
|
{% for player in players %}
|
||||||
|
@ -388,7 +388,7 @@ foreach($config['menu_categories'] as $id => $cat) {
|
|||||||
<?php echo tickers(); ?>
|
<?php echo tickers(); ?>
|
||||||
|
|
||||||
|
|
||||||
<div id="<?php echo PAGE; ?>" class="Box">
|
<div id="News" class="Box">
|
||||||
<div class="Corner-tl" style="background-image:url(<?php echo $template_path; ?>/images/content/corner-tl.gif);"></div>
|
<div class="Corner-tl" style="background-image:url(<?php echo $template_path; ?>/images/content/corner-tl.gif);"></div>
|
||||||
<div class="Corner-tr" style="background-image:url(<?php echo $template_path; ?>/images/content/corner-tr.gif);"></div>
|
<div class="Corner-tr" style="background-image:url(<?php echo $template_path; ?>/images/content/corner-tr.gif);"></div>
|
||||||
<div class="Border_1" style="background-image:url(<?php echo $template_path; ?>/images/content/border-1.gif);"></div>
|
<div class="Border_1" style="background-image:url(<?php echo $template_path; ?>/images/content/border-1.gif);"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user