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

121 lines
3.4 KiB
PHP

<?php
/**
* \file
* Generate instructions page.
*/
require_once '+getenv.php';
/**
* @var string[] $instruction_files
* List of all files containing localized site instructions.
*/
$instruction_files = glob("+instructions/*.txt");
/**
* Get the language name of the given localized file.
*
* @param string $file File containing site instructions.
*
* @return string
*/
function file_language($file) {
$filename = pathinfo($file)['filename'];
return explode(" ", $filename)[0];
}
/**
* Get the language code of the given localized file.
*
* @param string $file File containing site instructions.
*
* @return string
*/
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);
}
/**
* @var string $languages
* List of languages in which instructions are available.
*/
$languages = array_map('file_language', array_slice($instruction_files, 0, 10));
/**
* @var string $language_enumeration
* Enumerated list of languages with available instructions.
*/
$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>
<div id="instructions-image" title="Mobile phone scanning a QR code from SessionCommunities.online."></div>
<input id="language-selection-show" class="hidden" type="checkbox">
<h2 id="language-selection-title" title="Click to show available languages">
<label for="language-selection-show" tabindex="0">
Choose language
</label>
</h2>
<?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 class="language-selection-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.
/**
* @var string $content
* Instructions file contents.
*/
$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>