Pl4tform_website/load.php
2025-02-03 19:29:59 +01:00

267 lines
8.9 KiB
PHP

<html>
<head></head>
<body>
<script type="text/javascript" src="includes/soundplay.js"></script>
<script>
// AUDIO STOP BTN fAILED
function audioStop() {
var source = document.getElementById('audioSource');
source.pause();
// document.getElementById('soundPauseBtn').style.visibility = 'hidden';
// document.getElementById('soundPlayBtn').style.display = 'visible';
};
function f2() {
document.getElementById('content').style.display = 'none';
}
</script>
<?php
include 'includes/Parsedown.php';
$Parsedown = new Parsedown();
// $catO = $_POST["cat"];
// $cat = substr($catO, 0, strlen($catO)-1);
$cat = $_POST["cat"];
if ($cat == "archive"){
$cat = "";
}
$dataPath = "/var/www/pl4tform.org/website/data";
$dataLink = "https://pl4tform.org/data";
include 'includes/nc-data-request.php';
////////////////// ANALYSING THE MYSQL REQUEST //////////////////
if ($result1->num_rows > 0) {
echo "<div class='contentColumn' id=''>";
while ($row = $result1->fetch_assoc()) {
$file_id = $row['fileid'];
$file_name = $row['file_name'];
$file_size = $row['size'];
$mimetype_id = $row['mimetype'];
$mimetype_name = isset($mimetypes[$mimetype_id]) ? $mimetypes[$mimetype_id] : 'Unknown';
// Hole die Tags für diese Datei
$file_tags = isset($fileTags[$file_id]) ? implode(' ', $fileTags[$file_id]) : 'No Tags';
// Prüfen, ob der Dateiname mit einem Datum im gewünschten Format beginnt (YYMMDD-HHMM oder YYMMDD_HHMM)
if (preg_match('/^(\d{2})(\d{2})(\d{2})[-_](\d{4})/', $file_name, $matches)) {
// Extrahiere Jahr, Monat, Tag, Stunde und Minute
$file_year = $matches[1]; // Jahr (z.B. "21" wird zu "2021")
$file_month = $matches[2]; // Monat
$file_day = $matches[3]; // Tag
$file_hour = substr($matches[4], 0, 2); // Stunde (erste zwei Zeichen)
$file_minute = substr($matches[4], 2, 2); // Minute (letzte zwei Zeichen)
// Entferne Datum und Uhrzeit aus dem Dateinamen, also den Anfang
$file_title = substr($file_name, strlen($matches[0])); // Rest des Dateinamens nach Datum/Uhrzeit
// Überprüfen, ob eine Dateiendung existiert
// if (pathinfo($file_title, PATHINFO_EXTENSION)) {
// // Entferne die Dateiendung, wenn sie existiert
// $file_title = pathinfo($file_title, PATHINFO_FILENAME);
// }
// Finde die Position des letzten Punktes im Dateinamen
$last_dot_position = strrpos($file_title, '.');
// Überprüfe, ob ein Punkt im Dateinamen existiert
if ($last_dot_position !== false) {
// Extrahiere den Dateinamen ohne die Erweiterung (alles vor dem letzten Punkt)
$file_title = substr($file_title, 0, $last_dot_position);
}
// Entferne alles nach dem '@' (falls vorhanden)
$file_title = strtok($file_title, '@');
// Entferne einen führenden Unterstrich (falls vorhanden)
$file_title = ltrim($file_title, '_');
} else {
// Wenn das Format nicht stimmt, überspringen
continue;
}
////////////////// OUTPUT //////////////////
if (str_contains($file_tags, $cat)) {
$file_path_root = '/var/www/nextcloud/data/radio_admin/files/archive/'.$file_name;
$show = "";
$about = "";
if ($cat == ""){
if (str_contains($file_tags, "about")){
$show = "noshow";
}
if (str_contains($file_tags, "onlyincat")){
$show = "noshow";
}
}
////////////////// IMAGE FILES //////////////////
if (str_contains($mimetype_name, 'image')) {
echo "<div class='contentItemBox $show $about' id='$file_id'>";
echo "<img loading='lazy' class='imageItem item' id='$file_id' src='https://pl4tform.org/ncdata/$file_name' width='300px' alt='' onclick='focusItem(\"".$file_id."\");'>";
echo "</div>";
}
////////////////// AUDIO FILES //////////////////
if (str_contains($mimetype_name, 'audio')) {
echo "<div class='contentItemBox $show $about' id='$file_id'>";
echo "<div class='soundItem item' id='$file_id' onclick='focusItem(\"$file_id\")'> <div class='soundInfos'> ";
$soundInfosFormat = "<div class='soundDate'> $file_day.$file_month.20$file_year - $file_hour:$file_minute H </div><div class='soundTitle' onclick='focusItem(\"$file_id\")'><h1> $file_title </h1> </div> <br>";
echo $soundInfosFormat;
echo '<button id="playBtn'.$file_id.'" class="soundItemBtn soundPlayBtn" onclick=\'audioPlay("https://pl4tform.org/ncdata/'.$file_name.'","'.$file_name.'","'.$file_id.'");\'>> Play</button> </div>';
echo "</div>";
echo "</div>";
}
////////////////// MARKDOWN FILES //////////////////
if (str_contains($mimetype_name, 'markdown')) {
$item = $file_name;
$columnPath = "/var/www/pl4tform.org/website/data/files";
$soundFiles = scandir($columnPath,1);
$discriptionFileWithOutEnd = substr($item, 0, strlen($item)-4);
foreach($soundFiles as $soundFile){
if (str_contains($soundFile, ".mp3")) {
if (str_contains($soundFile, $discriptionFileWithOutEnd)) {
$matchingSoundFile = "true";
break;
}
else {
$matchingSoundFile = "false";
}
}
}
if ($matchingSoundFile == "false") {
$about = "";
$show = "";
$long = "";
if ($cat == ""){
if (str_contains($file_tags, "about")){
$show = "noshow";
}
if (str_contains($file_tags, "onlyincat")){
$show = "noshow";
}
}
else {
$show = "";
if (str_contains($file_tags, "about")){
$about = "about";
$long = "long";
}
}
if (str_contains($file_tags, "long")){
$long = "long";
}
echo "<div class='contentItemBox $show $about' id='$file_id'>";
echo "<div class='textItem item $long' id='$file_id' onclick='focusItem(\"".$file_id."\");'>";
$file_content = file_get_contents($file_path_root);
// $file_content = str_replace(".attachments.", "https://pl4tform.org/data/mdtransformation/03_attatchements_imgs/.attachments.", $file_content);
$file_content = str_replace(".attachments.", "/ncdata/.attachments.", $file_content);
echo $Parsedown->text($file_content);
echo "</div></div>";
}
}
////////////////// TXT AND HTML FILES //////////////////
if (str_contains($mimetype_name, 'text/html') or str_contains($mimetype_name, 'text/plain')) {
echo "<div class='contentItemBox $show $about' id='$file_id'>";
echo "<div class='textItem item $long' id='$file_id' onclick='focusItem(\"".$file_id."\");'>";
$file_content = file_get_contents($file_path_root);
$file_content = str_replace(".attachments.", "/ncdata/.attachments.", $file_content);
echo $file_content;
echo "</div></div>";
}
////////////////// PDF FILES //////////////////
if (str_contains($mimetype_name, 'application/pdf')) {
echo "<div class='contentItemBox $show $about' id='$file_id'>";
echo "<div class='textItem item $long' id='$file_id' onclick='focusItem(\"".$file_id."\");'>";
echo "<h1>$file_title</h1>";
echo "<embed class='pdfembed' src='https://pl4tform.org/ncdata/$file_name' type='application/pdf' /> ";
echo "</div></div>";
}
////////////////// END //////////////////
}
////////////////// END OUTPUT //////////////////
}
echo "</div>";
}
?>
</body>
</html>