150 lines
4.3 KiB
PHP
150 lines
4.3 KiB
PHP
<!DOCTYPE html>
|
|
|
|
<?php
|
|
|
|
function get_color_from_ip($ip) {
|
|
$ip_elem = explode(".", $ip);
|
|
$css = "background-color: hsl(";
|
|
$number = abs(crc32($ip));
|
|
$css .= ($number % 360).", ";
|
|
$css .= (50 + (($number >> 3) % 51))."%, ";
|
|
$css .= (50 + (($number >> 5) % 51))."%);";
|
|
|
|
return $css;
|
|
}
|
|
|
|
//header("refresh: 28");
|
|
header("Cache-Control: no-cache, no-store, must-revalidate");
|
|
|
|
if (!is_dir("data")) {
|
|
// initialize everything
|
|
mkdir("data", 0755);
|
|
file_put_contents("data/sentences.txt", "<!-- automatically created empty sentences file -->\n");
|
|
file_put_contents("data/archive-links.txt", "<!-- automatically created empty archive links file -->\n");
|
|
file_put_contents("data/config.json", "{\n\n}\n");
|
|
print("<p>Data directory automatically initialized</p>");
|
|
}
|
|
|
|
if (array_key_exists("submitted", $_REQUEST)) {
|
|
$word = urldecode($_REQUEST["submitted"]);
|
|
//print("Jemand schreibt ".$word."<br>");
|
|
|
|
$botrequest = false;
|
|
|
|
if (isset($_REQUEST["bot"])) {
|
|
$botrequest = true;
|
|
$content .= "<!-- FranzelbertML -->";
|
|
}
|
|
|
|
$sentences = fopen("./data/sentences.txt", "a") or die("unable to open sentences file");
|
|
$content = "<span data-user='";
|
|
$content .= $_REQUEST["user"];
|
|
$content .= "' data-time='";
|
|
$content .= time();
|
|
$content .= "' style='";
|
|
|
|
if ($botrequest) {
|
|
$content .= "background-color: darksalmon; color: white;'>";
|
|
} else {
|
|
$content .= get_color_from_ip($_SERVER['REMOTE_ADDR'])."'>";
|
|
}
|
|
|
|
$ends_of_sentence = ['.', '!', '?'];
|
|
|
|
$word = rtrim($word);
|
|
if (preg_match("/[\p{L}0-9]/", $word[0])) { // check if first character is letter (including ä, ê, ß stuff)
|
|
$content .= " ";
|
|
}
|
|
$content .= htmlentities($word);
|
|
|
|
if ($botrequest) {
|
|
$content .= "<!-- FranzelbertML -->";
|
|
}
|
|
|
|
$content .= "</span>";
|
|
|
|
if (in_array($word[-1], $ends_of_sentence)) {
|
|
$content .= "<br>\n";
|
|
}
|
|
|
|
if (!empty($word)) {
|
|
fwrite($sentences, $content);
|
|
}
|
|
fclose($sentences);
|
|
header("location: ".htmlentities($_SERVER['PHP_SELF']));
|
|
}
|
|
|
|
$raw_json_config = file_get_contents("data/config.json");
|
|
$config_data = json_decode($raw_json_config, false);
|
|
|
|
?>
|
|
|
|
<html>
|
|
<head>
|
|
<title><?php print($config_data->title ?? "One Word Each"); ?></title>
|
|
<link rel="stylesheet" href="style.css?<?php print(time()); ?>">
|
|
<?php
|
|
//if (!isset($config_data->send_logo)) {
|
|
print("<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css' integrity='sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==' crossorigin='anonymous' />");
|
|
//}
|
|
?>
|
|
<link rel="icon" href="<?php print($config_data->logo->icon_path ?? "favicon.ico"); ?>" type="image/x-icon">
|
|
</head>
|
|
<body>
|
|
<?php
|
|
if (isset($config_data->style)) {
|
|
print("<style>\n");
|
|
print($config_data->style);
|
|
print("\n</style>");
|
|
}
|
|
?>
|
|
<div class="header">
|
|
<img src="<?php print($config_data->logo->image_path ?? "OWE_Logo.png"); ?>" style="width: 10%; float: left;">
|
|
<h3 style="padding: 30px;"><?php print($config_data->headline ?? "One Word Each Seite"); ?></h3>
|
|
<button onclick="toggleArchives();" id="sidebar_button">
|
|
<?php
|
|
print(isset($config_data->archive) ? ("<img id='archive_image' src='".$config_data->archive->logo_path_closed."' width='64'>") : "<i class='fas fa-bars'></i>");
|
|
?></button>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="scrollbox">
|
|
<div class="archive_links">
|
|
<?php
|
|
$content = file_get_contents("./data/archive-links.txt") or die("ungültiger Dateiname");
|
|
print($content);
|
|
?>
|
|
<br><br>
|
|
<a href="admin.php">Admin</a>
|
|
</div>
|
|
|
|
<div class="main">
|
|
<div class="sentences">
|
|
<?php
|
|
//print(file_get_contents("./data/sentences.txt"));
|
|
?>
|
|
</div>
|
|
<button onclick="onReloadClicked()" id="but-reload">aktualisieren</button>
|
|
<br>
|
|
<div id="login_area">
|
|
</div>
|
|
<div class="word_input_area">
|
|
<?php if ($config_data->ose) : ?>
|
|
<textarea name="submitted" id="wordinput" placeholder="Nächster Satz" autocomplete="off"></textarea> <button id="sendbut" class="send_button" onclick="sendWord()">
|
|
<?php else: ?>
|
|
<input type="text" name="submitted" id="wordinput" placeholder="Nächstes Wort" autocomplete="off"> <button id="sendbut" class="send_button" onclick="sendWord()">
|
|
<?php
|
|
endif;
|
|
|
|
print(isset($config_data->send_logo) ? ("<img src='data/".$config_data->send_logo."' width='64'>") : "<i class='far fa-paper-plane'></i>");
|
|
?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="owe.js?<?php print(time()); ?>"></script>
|
|
</body>
|
|
</html>
|