feat(settings): save uploaded logos to uploads/public/logo
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79a0047f29
commit
4446224c19
2 files changed
+8
-4
No files matched your search
@@ -131,4 +131,4 @@ or adapted for production, and these accounts must never exist in a production d
|
|||||||
|
|
||||||
## Brand feed (2026-10-09)
|
## Brand feed (2026-10-09)
|
||||||
- `api/brand.php` is a one-line stub to `shared/platform-tools/api/brand.php` (public JSON: name, logos, colours; README "Brand feed"). Declared in `platform_connect(['brand' => ...])` in `config/db.php`; colours are the `:root` tokens (`--fitme-accent` #c2d500, `--fitme-dark` #0b0b0d, `--fitme-accent-dark` #a6b600). `logo_light` = light-coloured logo (`logo_crossfit_white.svg`), `logo_dark` = `logo_crossfit.svg`.
|
- `api/brand.php` is a one-line stub to `shared/platform-tools/api/brand.php` (public JSON: name, logos, colours; README "Brand feed"). Declared in `platform_connect(['brand' => ...])` in `config/db.php`; colours are the `:root` tokens (`--fitme-accent` #c2d500, `--fitme-dark` #0b0b0d, `--fitme-accent-dark` #a6b600). `logo_light` = light-coloured logo (`logo_crossfit_white.svg`), `logo_dark` = `logo_crossfit.svg`.
|
||||||
- `site_logo_rel()` (config/functions.php) resolves logos for both the feed and `load_email_template()`: setting file in `uploads/public/logo/` (convention), then legacy `assets/img/logo/`, then the static logo. Gotcha: `views/sysadmin/system_settings.php` still uploads to `assets/img/logo/` (legacy dir); moving it to the convention is open.
|
- `site_logo_rel()` (config/functions.php) resolves logos for both the feed and `load_email_template()`: setting file in `uploads/public/logo/` (convention), then legacy `assets/img/logo/`, then the static logo. `views/sysadmin/system_settings.php` now uploads logos to `uploads/public/logo/` (dir created on demand, 0755; `uploads/.htaccess` blocks script execution); old files in `assets/img/logo/` still resolve as fallback and in the settings preview. Brand block in `config/db.php` already prefers the setting file via `site_logo_rel()`, else the static SVGs.
|
||||||
@@ -3,7 +3,7 @@ require __DIR__ . '/../../config/db.php';
|
|||||||
require __DIR__ . '/../../config/functions.php';
|
require __DIR__ . '/../../config/functions.php';
|
||||||
$user = require_sysadmin(); // zona de sysadmin: o link só aparece a sysadmin e o servidor tem de concordar
|
$user = require_sysadmin(); // zona de sysadmin: o link só aparece a sysadmin e o servidor tem de concordar
|
||||||
|
|
||||||
$logo_dir = __DIR__ . '/../../assets/img/logo/';
|
$logo_dir = __DIR__ . '/../../uploads/public/logo/'; // convenção da plataforma (uploads/.htaccess bloqueia PHP)
|
||||||
$allowed_ext = ['png', 'jpg', 'jpeg', 'svg', 'webp'];
|
$allowed_ext = ['png', 'jpg', 'jpeg', 'svg', 'webp'];
|
||||||
$max_upload = 2 * 1024 * 1024; // 2 MB
|
$max_upload = 2 * 1024 * 1024; // 2 MB
|
||||||
$errors = [];
|
$errors = [];
|
||||||
@@ -61,6 +61,10 @@ function _settings_handle_logo_upload(array $file, string $dir, array $allowed,
|
|||||||
$errors[] = "Tipo de ficheiro não permitido (ou SVG com conteúdo ativo) para o logo {$kind}.";
|
$errors[] = "Tipo de ficheiro não permitido (ou SVG com conteúdo ativo) para o logo {$kind}.";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!is_dir($dir) && !@mkdir($dir, 0755, true) && !is_dir($dir)) {
|
||||||
|
$errors[] = "Não foi possível criar a pasta do logo {$kind}.";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$name = bin2hex(random_bytes(16)) . '.' . $ext;
|
$name = bin2hex(random_bytes(16)) . '.' . $ext;
|
||||||
if (!move_uploaded_file($file['tmp_name'], $dir . $name)) {
|
if (!move_uploaded_file($file['tmp_name'], $dir . $name)) {
|
||||||
$errors[] = "Não foi possível guardar o logo {$kind}.";
|
$errors[] = "Não foi possível guardar o logo {$kind}.";
|
||||||
@@ -166,7 +170,7 @@ include __DIR__ . '/../../includes/navbar.php';
|
|||||||
<label class="form-label small">Logo claro (para fundos escuros — navbar)</label>
|
<label class="form-label small">Logo claro (para fundos escuros — navbar)</label>
|
||||||
<?php if ($logo_light): ?>
|
<?php if ($logo_light): ?>
|
||||||
<div class="mb-2 p-2 rounded" style="background:#161c18;">
|
<div class="mb-2 p-2 rounded" style="background:#161c18;">
|
||||||
<img src="<?= base_url('assets/img/logo/' . rawurlencode($logo_light)) ?>" alt="Logo claro" style="max-height:48px;">
|
<img src="<?= base_url(is_file($logo_dir . basename($logo_light)) ? 'uploads/public/logo/' . rawurlencode($logo_light) : 'assets/img/logo/' . rawurlencode($logo_light)) ?>" alt="Logo claro" style="max-height:48px;">
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<input type="file" name="logo_light" class="form-control" accept=".png,.jpg,.jpeg,.svg,.webp">
|
<input type="file" name="logo_light" class="form-control" accept=".png,.jpg,.jpeg,.svg,.webp">
|
||||||
@@ -176,7 +180,7 @@ include __DIR__ . '/../../includes/navbar.php';
|
|||||||
<label class="form-label small">Logo escuro (para fundos claros — emails)</label>
|
<label class="form-label small">Logo escuro (para fundos claros — emails)</label>
|
||||||
<?php if ($logo_dark): ?>
|
<?php if ($logo_dark): ?>
|
||||||
<div class="mb-2 p-2 rounded border" style="background:#ffffff;">
|
<div class="mb-2 p-2 rounded border" style="background:#ffffff;">
|
||||||
<img src="<?= base_url('assets/img/logo/' . rawurlencode($logo_dark)) ?>" alt="Logo escuro" style="max-height:48px;">
|
<img src="<?= base_url(is_file($logo_dir . basename($logo_dark)) ? 'uploads/public/logo/' . rawurlencode($logo_dark) : 'assets/img/logo/' . rawurlencode($logo_dark)) ?>" alt="Logo escuro" style="max-height:48px;">
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<input type="file" name="logo_dark" class="form-control" accept=".png,.jpg,.jpeg,.svg,.webp">
|
<input type="file" name="logo_dark" class="form-control" accept=".png,.jpg,.jpeg,.svg,.webp">
|
||||||
|
|||||||
Reference in new issue
Block a user