Källkod

Välj en PHP-fil för att visa dess källkod.

viewsource.php

<?php
require __DIR__ . '/incl/config.php';
$title = 'Källkod – Webbserverprogrammering';
$pageId = 'viewsource';
$baseUrl = '';
require 
__DIR__ . '/source.php';
require 
__DIR__ . '/incl/header.php';

$files = getProjectPhpFiles(__DIR__);
$requestedFile = isset($_GET['file']) && is_string($_GET['file']) ? $_GET['file'] : '';
$sourcePath = $requestedFile === '' ? false : getSafeProjectPhpPath(__DIR__, $requestedFile);
?>
<h1>Källkod</h1>
<p>Välj en PHP-fil för att visa dess källkod.</p>
<ul>
    <?php foreach ($files as $file): ?>
        <li><a href="?file=<?= rawurlencode($file) ?>"><?= htmlspecialchars($file, ENT_QUOTES, 'UTF-8') ?></a></li>
    <?php endforeach; ?>
</ul>

<?php if ($requestedFile !== '' && $sourcePath === false): ?>
    <p class="error">Den valda filen kunde inte visas.</p>
<?php elseif ($sourcePath !== false): ?>
    <h2><?= htmlspecialchars($requestedFile, ENT_QUOTES, 'UTF-8') ?></h2>
    <div class="source-code"><?= highlight_file($sourcePath, true) ?></div>
<?php endif; ?>
<?php 
require __DIR__ . '/incl/footer.php'; ?>