1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 07:30:10 +01:00

mod.php: use modern array syntax

This commit is contained in:
Zankaria 2024-08-15 16:52:29 +02:00
parent e16dc142b7
commit 19082aec56

24
mod.php
View File

@ -1,13 +1,13 @@
<?php
/*
* Copyright (c) 2010-2014 Tinyboard Development Group
*/
require_once 'inc/bootstrap.php';
if ($config['debug'])
if ($config['debug']) {
$parse_start_time = microtime(true);
}
require_once 'inc/mod/pages.php';
@ -15,7 +15,7 @@ check_login(true);
$query = isset($_SERVER['QUERY_STRING']) ? rawurldecode($_SERVER['QUERY_STRING']) : '';
$pages = array(
$pages = [
'' => ':?/', // redirect to dashboard
'/' => 'dashboard', // dashboard
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
@ -109,14 +109,14 @@ $pages = array(
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread',
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '!')) => 'view_thread50',
str_replace([ '%d','%s' ], [ '(\d+)', '[a-z0-9-]+' ], preg_quote($config['file_page50_slug'], '!')) => 'view_thread50',
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '!')) => 'view_thread',
);
str_replace([ '%d','%s' ], [ '(\d+)', '[a-z0-9-]+' ], preg_quote($config['file_page_slug'], '!')) => 'view_thread',
];
if (!$mod) {
$pages = array('!^(.+)?$!' => 'login');
$pages = [ '!^(.+)?$!' => 'login' ];
} elseif (isset($_GET['status'], $_GET['r'])) {
header('Location: ' . $_GET['r'], true, (int)$_GET['status']);
exit;
@ -126,10 +126,11 @@ if (isset($config['mod']['custom_pages'])) {
$pages = array_merge($pages, $config['mod']['custom_pages']);
}
$new_pages = array();
$new_pages = [];
foreach ($pages as $key => $callback) {
if (is_string($callback) && preg_match('/^secure /', $callback))
if (is_string($callback) && preg_match('/^secure /', $callback)) {
$key .= '(/(?P<token>[a-f0-9]{8}))?';
}
$key = str_replace('\%b', '?P<board>' . sprintf(substr($config['board_path'], 0, -1), $config['board_regex']), $key);
$new_pages[(!empty($key) and $key[0] == '!') ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!u'] = $callback;
}
@ -172,11 +173,11 @@ foreach ($pages as $uri => $handler) {
}
if ($config['debug']) {
$debug['mod_page'] = array(
$debug['mod_page'] = [
'req' => $query,
'match' => $uri,
'handler' => $handler,
);
];
$debug['time']['parse_mod_req'] = '~' . round((microtime(true) - $parse_start_time) * 1000, 2) . 'ms';
}
@ -204,4 +205,3 @@ foreach ($pages as $uri => $handler) {
}
error($config['error']['404']);