You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
seacms/index.php

70 lines
1.6 KiB

<?php
/**
* Copyright 2022 Jeremy Dufraisse
* Authors: see /README.md
*/
// TODO remove this file
// Only for tests
$messages = [];
set_error_handler(function (
int $errno,
string $errstr,
string $errfile = '',
int $errline = -1
) {
$context = json_encode($errcontext);
$GLOBALS['messages'][] = <<<HTML
<div>
Error : $errstr<br>
in file '$errfile' (line '$errline').<br/>
ErrCode : $errno
</div>
HTML;
return true;
});
if (is_file(__DIR__ . '/vendor/autoload.php')) {
include_once(__DIR__ . '/vendor/autoload.php');
}
try {
// instance Pico
$pico = new Pico(
__DIR__, // root dir
'vendor/picocms/pico/config/', // config dir
'vendor/picocms/pico/plugins/', // plugins dir
'vendor/picocms/themes/' // themes dir
);
// run application
$output = $pico->run();
} catch (Throwable $th) {
$messages[] = <<<HTML
<div style="color:red;">
Exception : {$th->__toString()}
</div>
HTML;
}
if (!empty($messages)) {
$formattedMessages = implode("\n", $messages);
$formattedMessages = <<<HTML
<div style="background-color:navajowhite;">
$formattedMessages
</div>
HTML;
if (preg_match('/<div[^>]*id="main"[^>]*>/i', $output, $match)) {
$output = str_replace($match[0], $match[0].$formattedMessages, $output);
} elseif (preg_match('/<body[^>]*>/i', $output, $match)) {
$output = str_replace($match[0], $match[0].$formattedMessages, $output);
} else {
$output = $formattedMessages.$output;
}
}
echo $output;