mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Add website-type TFE support: URLs stored as thesis_files rows, HTMX-toggle on Site web format
This commit is contained in:
@@ -331,9 +331,12 @@ class ThesisEditController
|
||||
}
|
||||
$filePath = $this->db->deleteThesisFile($fileId, $thesisId);
|
||||
if ($filePath && defined('STORAGE_ROOT')) {
|
||||
$abs = STORAGE_ROOT . '/' . $filePath;
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
// Skip filesystem deletion for website URLs (not real files)
|
||||
if (!str_starts_with($filePath, 'http://') && !str_starts_with($filePath, 'https://')) {
|
||||
$abs = STORAGE_ROOT . '/' . $filePath;
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -358,6 +361,9 @@ class ThesisEditController
|
||||
if (!empty($files['files']['name'][0])) {
|
||||
$this->handleThesisFiles($thesisId, $post, $files['files']);
|
||||
}
|
||||
|
||||
// ── Website URL — add or update ──────────────────────────────────────
|
||||
$this->handleWebsiteUrl($thesisId, $post);
|
||||
}
|
||||
|
||||
// ── Private: file uploads ─────────────────────────────────────────────────
|
||||
@@ -703,4 +709,50 @@ class ThesisEditController
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a website URL thesis_file row.
|
||||
*
|
||||
* If a website row already exists for this thesis, it is replaced.
|
||||
* Otherwise a new row is inserted.
|
||||
*/
|
||||
private function handleWebsiteUrl(int $thesisId, array $post): void
|
||||
{
|
||||
$websiteUrl = trim($post['website_url'] ?? '');
|
||||
|
||||
// Remove existing website rows
|
||||
$existingFiles = $this->db->getThesisFiles($thesisId);
|
||||
foreach ($existingFiles as $f) {
|
||||
if ($f['file_type'] === 'website') {
|
||||
$this->db->deleteThesisFile((int)$f['id'], $thesisId);
|
||||
}
|
||||
}
|
||||
|
||||
if ($websiteUrl === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate URL
|
||||
$websiteUrl = filter_var($websiteUrl, FILTER_VALIDATE_URL);
|
||||
if ($websiteUrl === false) {
|
||||
error_log('ThesisEditController: invalid website URL, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
$label = trim($post['website_label'] ?? '');
|
||||
$sortOrder = isset($post['website_order']) ? (int)$post['website_order'] : null;
|
||||
$fileName = rtrim(preg_replace('#^https?://#i', '', $websiteUrl), '/');
|
||||
|
||||
$this->db->insertThesisFile(
|
||||
$thesisId,
|
||||
'website',
|
||||
$websiteUrl,
|
||||
$fileName,
|
||||
0,
|
||||
'text/html',
|
||||
$label !== '' ? $label : null,
|
||||
$sortOrder
|
||||
);
|
||||
error_log("ThesisEditController: website stored → $websiteUrl");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user