56 lines
2.8 KiB
PHP
56 lines
2.8 KiB
PHP
|
#!/usr/bin/env php
|
||
|
<?php
|
||
|
|
||
|
$dir = new RecursiveDirectoryIterator("temple-src");
|
||
|
$iterator = new RecursiveIteratorIterator($dir);
|
||
|
$matches = new RegexIterator($iterator, "/^.+\.(DD|HC)$/i", RecursiveRegexIterator::GET_MATCH);
|
||
|
|
||
|
foreach ($matches as $match) {
|
||
|
$file = $match[0];
|
||
|
$content = file_get_contents($file);
|
||
|
|
||
|
$filename = basename($file);
|
||
|
$bodyclass = "BG-15 FG-0 ";
|
||
|
if (str_contains($content, '$WW,1$')) {
|
||
|
$bodyclass .= "word-wrap";
|
||
|
}
|
||
|
|
||
|
$content = htmlentities($content, ENT_NOQUOTES); // Escape HTML
|
||
|
$content = nl2br($content, false); // Use <br> for newlines
|
||
|
$content = str_replace("\u{5}", "", $content); // Remove cursor position
|
||
|
$content = preg_replace('/\$(FG|BG),(\d+)\$(.+?)\$FG\$/s', '<span class="$1-$2">$3</span>', $content); // Foreground / background color
|
||
|
$content = preg_replace('/\$LK,"([^"]+?)",A="(FI:)?::(.+?)"\$/s', '<a href="/src$3.HTML">$1</a>', $content); // File links
|
||
|
$content = preg_replace('/\$LK,"([^"]+?)",A="FF:::(.+?),(.+?)"\$/s', '<a href="/src$2.HTML#$3">$1</a>', $content); // File links with search
|
||
|
$content = preg_replace('/\$LK,"([^"]+?)",A="(MN|HI):(.+?)"\$/s', '<a href="#" onclick="alert(\'This type of link is not implemented yet\')">$1</a>', $content); // Unimplemented links
|
||
|
$content = preg_replace('/\$LK,"(FI:)?::(.+?)"\$/s', '<a href="/src$2.HTML">$2</a>', $content); // File links without title
|
||
|
$content = preg_replace('/\$ID,(\d+)\$(.+?)\$ID,-\1\$/s', '<div style="margin-left: $1ch;">$2</div>', $content); // Indentation
|
||
|
$content = preg_replace('/\$\$/', '$', $content); // Escaping dollar signs
|
||
|
$content = preg_replace('/\$TX\+CX,"(.+?)"\$/s', '<center>$1</center>', $content); // Centered text
|
||
|
$content = preg_replace('/\$TX\+RX,"(.+?)"\$/s', '<div style="text-align: right;">$1</div>', $content); // Right-justified text
|
||
|
$content = preg_replace('/\$UL,1\$(.+?)\$UL,0\$/s', '<u>$1</u>', $content); // Underlined text
|
||
|
$content = preg_replace('/\$IV,1\$(.+?)\$IV,0\$/s', '<span class="invert">$1</span>', $content); // Inverted text
|
||
|
$content = preg_replace('/\$BK,1\$(.+?)\$BK,0\$/s', '<span class="blink">$1</span>', $content); // Blinking text
|
||
|
$content = preg_replace('/\$SY,(-?\d+)\$(.+?)\$SY,0\$/s', '<span style="position: relative; top: $1px;">$2</span>', $content); // Shift-y
|
||
|
$content = preg_replace('/\$WW.+?\$/', "", $content); // Word wrap
|
||
|
$content = <<<HTML
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>$filename</title>
|
||
|
<link rel="stylesheet" href="/style/templeos.css">
|
||
|
<script src="/script/templeos.js" defer></script>
|
||
|
</head>
|
||
|
<body class="$bodyclass">
|
||
|
$content
|
||
|
</body>
|
||
|
</html>
|
||
|
HTML;
|
||
|
|
||
|
$newfile = str_replace("temple-src/", "/public/src/", $file) . ".HTML";
|
||
|
if (!is_dir(__DIR__ . dirname($newfile))) mkdir(__DIR__ . dirname($newfile), 0755, true);
|
||
|
|
||
|
file_put_contents(__DIR__ . $newfile, $content);
|
||
|
}
|
||
|
|