<?php
/**
 * @intranet-file common/url.php
 * @intranet-file-version 2026.03.13.1
 * @intranet-file-date 2026-03-13
 * @intranet-file-owner CSIF Intranet
 */
require_once __DIR__ . '/config.php';


if (!function_exists('h')) {
    function h($s): string
    {
        return htmlspecialchars((string) $s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
    }
}

function app_base_path(): string
{
    $base = defined('APP_BASE_PATH') ? (string) APP_BASE_PATH : '';
    $base = trim(str_replace('\\', '/', $base));
    if ($base === '' || $base === '/') {
        return '';
    }
    return '/' . trim($base, '/');
}

function app_url(string $path = ''): string
{
    $path = ltrim($path, '/');
    $base = app_base_path();
    return $base . ($path !== '' ? '/' . $path : '');
}

function login_url(string $query = ''): string
{
    $url = app_url('login.php');
    if ($query !== '') {
        $url .= '?' . ltrim($query, '?');
    }
    return $url;
}

function asset_url(string $path = ''): string
{
    return app_url($path);
}
