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

80 lines
2.3 KiB
PHTML

<?php
require_once '+getenv.php';
$instruction_files = glob("+instructions/*.txt");
function file_language($file) {
$filename = pathinfo($file)['filename'];
return explode(" ", $filename)[0];
}
function file_language_code($file) {
$filename = pathinfo($file)['filename'];
$code_in_brackets = explode(" ", $filename)[1];
return mb_substr($code_in_brackets, 1, mb_strlen($code_in_brackets) - 2);
}
$languages = array_map('file_language', array_slice($instruction_files, 0, 10));
$language_enumeration = join(", ", $languages);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include "+components/page-head.php" ?>
<link rel="stylesheet" href="/css/common-dark.css">
<link rel="stylesheet" href="/css/instructions.css">
<style type="text/css">
<?php foreach ($instruction_files as $i => $file): ?>
#language-selection-<?=$i?>:checked ~
#instructions #instructions-<?=$i?> {
display: block;
}
<?php endforeach; ?>
</style>
</head>
<body>
<header>
<h1>Instructions for joining Session Communities</h1>
</header>
<main>
<p id="link-return">
<a href="/" title="Return to the Session Community listing">
Go back to Community list
</a>
</p>
<h2 id="language-selection-title">
Choose your language:
</h2>
<br>
<?php foreach ($instruction_files as $i => $file): ?>
<input
id="language-selection-<?=$i?>"
class="language-selection"
name="language"
type="radio"
<?=file_language($file) == 'English' ? 'checked="checked"' : ''?>
><label for="language-selection-<?=$i?>">&nbsp;<?=
file_language($file);
?></label>
<?php endforeach; ?>
<article id="instructions">
<?php foreach ($instruction_files as $i => $file): ?>
<section id="instructions-<?=$i?>" class="instructions" lang="<?=file_language_code($file)?>"><?php
// Sanitization as second layer of protection
// for user-submitted instruction files.
// Should not ever have to be used.
$content = trim(file_get_contents($file));
$content = htmlentities($content);
// Minimal formatting so that contributions are easier
$content = str_replace("\n-", "\n\n•", $content);
$content = str_replace("\n\n\n", "<br><br>", $content);
$content = str_replace("\n\n", "<br>", $content);
echo $content;
?>
</section>
<?php endforeach; ?>
</article>
</main>
</body>
</html>