| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/admin/ |
Upload File : |
<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/includes/functions.php';
require_login();
$keys = [
'social_top_enabled',
'instagram_url',
'facebook_url',
'tiktok_url',
'youtube_url',
'x_url',
'pinterest_url',
'linkedin_url',
'tripadvisor_url',
'google_maps_url',
];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
try {
$stmt = db()->prepare(
'INSERT INTO settings (setting_key, setting_value)
VALUES (?, ?)
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)'
);
foreach ($keys as $key) {
$value = trim((string)($_POST[$key] ?? ''));
$stmt->execute([$key, $value]);
}
$upload = $_FILES['social_share_image'] ?? null;
if ($upload && (int)($upload['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_NO_FILE) {
if ((int)$upload['error'] !== UPLOAD_ERR_OK) {
throw new RuntimeException('Błąd wysyłania grafiki social.');
}
if ((int)$upload['size'] > 8 * 1024 * 1024) {
throw new RuntimeException('Grafika social jest za duża. Maksymalnie 8 MB.');
}
$tmp = (string)$upload['tmp_name'];
if (!is_uploaded_file($tmp)) {
throw new RuntimeException('Nieprawidłowy upload.');
}
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($tmp);
$extMap = [
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/webp' => 'webp',
];
if (!isset($extMap[$mime])) {
throw new RuntimeException('Grafika social: użyj JPG, PNG albo WEBP.');
}
$dir = dirname(__DIR__) . '/assets/img/social';
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
throw new RuntimeException('Nie udało się utworzyć katalogu social.');
}
foreach (glob($dir . '/social-share.*') ?: [] as $old) {
@unlink($old);
}
$filename = 'social-share.' . $extMap[$mime];
$target = $dir . '/' . $filename;
if (!move_uploaded_file($tmp, $target)) {
throw new RuntimeException('Nie udało się zapisać grafiki social.');
}
@chmod($target, 0644);
$stmt->execute([
'default_og_image',
site_url('/assets/img/social/' . $filename),
]);
}
admin_log('socials_update', 'Zmieniono sociale i grafikę udostępnień');
flash('success', 'Sociale zostały zapisane.');
redirect('/admin/socials.php');
} catch (Throwable $e) {
flash('error', $e->getMessage());
redirect('/admin/socials.php');
}
}
$values = [];
foreach ($keys as $key) {
$values[$key] = setting($key, $key === 'social_top_enabled' ? '1' : '');
}
render_admin_header('Sociale');
?>
<div class="admin-title-row">
<div>
<h1>Sociale</h1>
<p>Wpisujesz link – ikona pojawia się automatycznie na górze WWW i w stopce.</p>
</div>
</div>
<form class="form-card form-grid" method="post" enctype="multipart/form-data">
<?= csrf_field() ?>
<label>
Ikony na górze strony
<select name="social_top_enabled">
<option value="1" <?= $values['social_top_enabled'] === '1' ? 'selected' : '' ?>>Włączone</option>
<option value="0" <?= $values['social_top_enabled'] === '0' ? 'selected' : '' ?>>Wyłączone</option>
</select>
</label>
<label>
Instagram
<input type="url" name="instagram_url" value="<?= e($values['instagram_url']) ?>" placeholder="https://instagram.com/...">
</label>
<label>
Facebook
<input type="url" name="facebook_url" value="<?= e($values['facebook_url']) ?>" placeholder="https://facebook.com/...">
</label>
<label>
TikTok
<input type="url" name="tiktok_url" value="<?= e($values['tiktok_url']) ?>" placeholder="https://tiktok.com/@...">
</label>
<label>
YouTube
<input type="url" name="youtube_url" value="<?= e($values['youtube_url']) ?>" placeholder="https://youtube.com/...">
</label>
<label>
X / Twitter
<input type="url" name="x_url" value="<?= e($values['x_url']) ?>" placeholder="https://x.com/...">
</label>
<label>
Pinterest
<input type="url" name="pinterest_url" value="<?= e($values['pinterest_url']) ?>" placeholder="https://pinterest.com/...">
</label>
<label>
LinkedIn
<input type="url" name="linkedin_url" value="<?= e($values['linkedin_url']) ?>" placeholder="https://linkedin.com/...">
</label>
<label>
Tripadvisor
<input type="url" name="tripadvisor_url" value="<?= e($values['tripadvisor_url']) ?>" placeholder="https://tripadvisor...">
</label>
<label class="full">
Google / mapa / profil firmy
<input type="url" name="google_maps_url" value="<?= e($values['google_maps_url']) ?>" placeholder="https://maps.google.com/...">
</label>
<div class="full admin-section-title">
<h2>Grafika do udostępnień</h2>
<p>Ta grafika będzie używana np. przy wklejaniu linku strony na Facebooku, komunikatorach i innych serwisach.</p>
</div>
<?php if (setting('default_og_image') !== ''): ?>
<div class="full social-share-preview">
<img src="<?= e(setting('default_og_image')) ?>" alt="Aktualna grafika social">
</div>
<?php endif; ?>
<label class="full">
Podmień grafikę social
<input type="file" name="social_share_image" accept="image/jpeg,image/png,image/webp">
</label>
<div class="full">
<button class="btn btn-primary" type="submit">Zapisz sociale</button>
</div>
</form>
<?php render_admin_footer(); ?>