<?php
declare(strict_types=1);
session_start();
if (!isset($_SESSION['user_id']) || (int)$_SESSION['user_id'] <= 0) {
    header('Location: login.html');
    exit;
}
$file = __DIR__ . DIRECTORY_SEPARATOR . 'listing-ads.html';
$html = @file_get_contents($file);
if ($html === false) { readfile($file); exit; }
// Replace header button with Logout
$html = str_replace('<a class="tp-btn-theme" href="listing-ads.html"><span>Post Your Ad <i', '<a class="tp-btn-theme" href="logout.php"><span>Logout <i', $html);
$html = str_replace('<a href="login.html"><i class="fa-light fa-user"></i>Sign In</a>', '<a href="logout.php"><i class="fa-solid fa-right-from-bracket"></i>Logout</a>', $html);
$html = str_replace('href="index-2.html"', 'href="index-2.php"', $html);
// Ensure Chat link goes to chat page
$html = str_replace('href="conversation.html"', 'href="chat.php"', $html);
echo $html;
