Вход Регистрация
Файл: new_top/index.php
Строк: 57
<?php
/**
 * Front controller — resides in project root
 */

declare(strict_types=1);

if (
PHP_SAPI === 'cli-server') {
    
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
    
$file = __DIR__ . $path;
    if (
$path !== '/' && is_file($file) && !preg_match('/.php$/i', $file)) {
        return 
false;
    }
}

require 
__DIR__ . '/core/bootstrap.php';

// If not installed — only install is allowed
if (!file_exists(CONFIG_PATH)) {
    if (
strpos($_SERVER['REQUEST_URI'] ?? '', '/install') !== false) {
        
// let install handle itself
        
return;
    }
    
header('Location: /install/');
    exit;
}

// Parse path
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?? '/';
$uri = rawurldecode($uri);
$uri = rtrim($uri, '/') ?: '/';

// Strip script directory if running in subfolder
$scriptDir = rtrim(str_replace('\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '')), '/');
if ($scriptDir && $scriptDir !== '
/' && strpos($uri, $scriptDir) === 0) {
    $uri = substr($uri, strlen($scriptDir)) ?: '
/';
}

// ---------- Counter image: /cn/big/123 or /cn/small/123 ----------
if (preg_match('
#^/cn/(big|small)/(d+)$#', $uri, $m)) {
    
$type = $m[1];
    
$id   = (int)$m[2];
    try {
        
$pf = Counter::registerView($id);
        
Counter::renderImage($pf, $type);
    } catch (
Throwable $e) {
        
header('Content-Type: image/gif');
        
header('Cache-Control: no-store');
        echo 
base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
    }
    exit;
}

// ---------- Inbound click: /in/123 ----------
if (preg_match('#^/in/(d+)$#', $uri, $m)) {
    
$id = (int)$m[1];
    
$pf = Counter::registerIn($id);
    if (
$pf) {
        
$url = external_redirect_url((string)$pf['url']);
        if (
$url) {
            
header('Location: ' . $url, true, 302);
            exit;
        }
    }
    
http_response_code(404);
    echo 
'Площадка не найдена';
    exit;
}

// ---------- Simple module routing via ?module= or path ----------
$module = $_GET['module'] ?? null;

if (
$module === 'admin' || $uri === '/admin' || strpos($uri, '/admin/') === 0) {
    require 
ROOT . '/modules/admin/index.php';
    exit;
}

if (
$module === 'office' || $uri === '/office' || strpos($uri, '/office/') === 0) {
    require 
ROOT . '/modules/office/index.php';
    exit;
}

if (
$module === 'stats' || preg_match('#^/stats/(d+)$#', $uri, $sm)) {
    if (!empty(
$sm[1])) {
        
$_GET['id'] = $sm[1];
    }
    require 
ROOT . '/modules/stats.php';
    exit;
}

if (
$module === 'cat' || $uri === '/cat' || preg_match('#^/cat/(d+)$#', $uri, $cm)) {
    if (!empty(
$cm[1])) {
        
$_GET['id'] = $cm[1];
    }
    require 
ROOT . '/modules/cat.php';
    exit;
}



if (
$module === 'rules' || $uri === '/rules') {
    require 
ROOT . '/modules/rules.php';
    exit;
}

if (
$module === 'search' || $uri === '/search') {
    require 
ROOT . '/modules/search.php';
    exit;
}

if (
$module === 'rand' || $uri === '/rand') {
    require 
ROOT . '/modules/rand.php';
    exit;
}

if (
$module === 'cron') {
    require 
ROOT . '/modules/cron.php';
    exit;
}

// Default: home (top list)
require ROOT . '/modules/home.php';
Онлайн: 1
Реклама