archive creation assistant
This commit is contained in:
parent
7de49f16a6
commit
56c689af6a
107
admin.php
107
admin.php
@ -13,6 +13,16 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<?php
|
||||||
|
if (isset($config_data->style)) {
|
||||||
|
print("<style>\n");
|
||||||
|
print($config_data->style);
|
||||||
|
print("\n</style>");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<h1><?php print($config_data->headline ?? "One Word Each"); ?> - Administration</h1>
|
||||||
|
<p><a href="./">Startseite</a></p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (file_exists('data/admin_pwd')):
|
if (file_exists('data/admin_pwd')):
|
||||||
@ -47,7 +57,23 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
if ($login):
|
if ($login):
|
||||||
?>
|
?>
|
||||||
|
|
||||||
Du bist angemeldet.
|
<h3>Archiv erstellen</h3>
|
||||||
|
|
||||||
|
Bisherige Archive:
|
||||||
|
<p id="archive_links">
|
||||||
|
<?php
|
||||||
|
$content = file_get_contents("./data/archive-links.txt") or die("ungültiger Dateiname");
|
||||||
|
print($content);
|
||||||
|
?></p>
|
||||||
|
|
||||||
|
Neues Archiv:<br>
|
||||||
|
<label>Erster Tag: <input id="firstday" oninput="previewNewArchive();" type="date" style="font-size: xx-large; border: 2px solid white;"></label><br>
|
||||||
|
<label>Letzter Tag: <input id="lastday" oninput="previewNewArchive();" type="date" style="font-size: xx-large; border: 2px solid white;"></label><br>
|
||||||
|
Vorschau<br>
|
||||||
|
Dateiname: <span id="archive_filename_preview"></span><br>
|
||||||
|
Linktext: <span id="archive_link_preview"></span><br>
|
||||||
|
Inhalt: <span class="sentences" id="archive_sentences_preview"></span><br>
|
||||||
|
<button onclick="createArchive();">erstellen</button>
|
||||||
|
|
||||||
<?php elseif (file_exists('data/admin_pwd')): ?>
|
<?php elseif (file_exists('data/admin_pwd')): ?>
|
||||||
|
|
||||||
@ -70,5 +96,84 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
|
|
||||||
endif; ?>
|
endif; ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var sentences;
|
||||||
|
|
||||||
|
function fetchSentences() {
|
||||||
|
fetch("./data/sentences.txt", {headers: {"Cache-Control": "no-cache, no-store"}})
|
||||||
|
.then((response) => {
|
||||||
|
return response.text().then((text) => {
|
||||||
|
sentences = text;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function previewNewArchive() {
|
||||||
|
month_names = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
|
||||||
|
month_abbr = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
||||||
|
|
||||||
|
fd = document.getElementById("firstday").valueAsDate;
|
||||||
|
ld = document.getElementById("lastday").valueAsDate;
|
||||||
|
filename_preview = document.getElementById("archive_filename_preview");
|
||||||
|
link_preview = document.getElementById("archive_link_preview");
|
||||||
|
sentences_preview = document.getElementById("archive_sentences_preview");
|
||||||
|
|
||||||
|
var display_first_month = (fd.getMonth() != ld.getMonth()) || (fd.getFullYear() != ld.getFullYear());
|
||||||
|
var display_first_year = fd.getFullYear() != ld.getFullYear();
|
||||||
|
|
||||||
|
filename_preview.innerHTML = `sentences-archive-${fd.getDate()}${display_first_month ? '-'+month_abbr[fd.getMonth()] : ''}${display_first_year ? '-'+fd.getFullYear()%100 : ''}-${ld.getDate()}-${month_abbr[ld.getMonth()]}-${ld.getFullYear()%100}.txt`;
|
||||||
|
link_preview.innerHTML = `Archiveintrag ${fd.getDate()}. ${display_first_month ? month_names[fd.getMonth()] : ''} ${display_first_year ? fd.getFullYear() : ''} \
|
||||||
|
bis ${ld.getDate()}. ${month_names[ld.getMonth()]} ${ld.getFullYear()}`;
|
||||||
|
|
||||||
|
fetchSentences();
|
||||||
|
var htmltxt = document.createElement("html");
|
||||||
|
htmltxt.innerHTML = sentences;
|
||||||
|
spans = htmltxt.getElementsByTagName("span");
|
||||||
|
sentences_preview.innerHTML = '';
|
||||||
|
for (i=0; i<3; i++) {
|
||||||
|
sentences_preview.appendChild(spans[i].cloneNode(true));
|
||||||
|
}
|
||||||
|
sentences_preview.innerHTML += "<span style='color: white'>...</span>";
|
||||||
|
for (i=3; i>0; i--) {
|
||||||
|
sentences_preview.appendChild(spans[spans.length - i].cloneNode(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function createArchive() {
|
||||||
|
var data = new FormData();
|
||||||
|
data.append('filename', encodeURI(document.getElementById("archive_filename_preview").innerText));
|
||||||
|
data.append('linktext', encodeURI(document.getElementById("archive_link_preview").innerText));
|
||||||
|
const Http = new XMLHttpRequest();
|
||||||
|
Http.open('POST', './archive_creator.php');
|
||||||
|
Http.onreadystatechange=(e)=>{
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
Http.send(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultNewArchive() {
|
||||||
|
lastlink = document.getElementById("archive_links").lastElementChild.getAttribute("href");
|
||||||
|
var re = /(\d+)-(\w\w\w)-(\d+)\.txt/;
|
||||||
|
res = re.exec(lastlink);
|
||||||
|
|
||||||
|
month_abbr = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
||||||
|
d = parseInt(res[1]);
|
||||||
|
m = month_abbr.indexOf(res[2]);
|
||||||
|
y = 2000 + parseInt(res[3]);
|
||||||
|
|
||||||
|
date = new Date(Date.UTC(y, m, d));
|
||||||
|
document.getElementById("firstday").value = date.toISOString().split("T")[0];
|
||||||
|
document.getElementById("lastday").valueAsNumber = Date.now()
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchSentences();
|
||||||
|
setTimeout(previewNewArchive, 500);
|
||||||
|
defaultNewArchive();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
21
archive_creator.php
Normal file
21
archive_creator.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$linktext = urldecode($_REQUEST['linktext']);
|
||||||
|
$filename = urldecode($_REQUEST['filename']);
|
||||||
|
|
||||||
|
$filename = basename($filename); // don't allow any relative paths
|
||||||
|
|
||||||
|
//print("ein archiv mit dem linktext ".$linktext." und dem dateinamen ".$filename." soll erstellt werden");
|
||||||
|
if (file_exists('data/'.$filename)) {
|
||||||
|
http_response_code(409); // conflict
|
||||||
|
print("Archiv mit dem Namen '".$filename."' existiert bereits!");
|
||||||
|
} else {
|
||||||
|
rename("data/sentences.txt", "data/".$filename);
|
||||||
|
file_put_contents("data/sentences.txt", "");
|
||||||
|
$html_link = "<br>\n<a href='./archiv.php?file=".$filename."'>".$linktext."</a>";
|
||||||
|
file_put_contents("data/archive-links.txt", $html_link, FILE_APPEND);
|
||||||
|
http_response_code(200);
|
||||||
|
print("Neues Archiv erstellt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user