<?php
// Tema ayarlarının varsayılanları. Panelden kaydedilenler settings tablosunda "theme_" önekiyle durur.
function theme_defaults()
{
return [
'logo' => '',
'logo_light' => '',
'favicon' => '',
'logo_height' => '32',
'color_primary' => '#0a0a0a',
'color_accent' => '#e03d0b',
'color_bg' => '#ffffff',
'color_soft' => '#fafafa',
'color_text' => '#18181b',
'announce_bg' => '#0a0a0a',
'announce_text' => '#ffffff',
'footer_style' => 'dark',
'font_heading' => 'Inter Tight',
'font_body' => 'Inter',
'heading_weight' => '600',
'base_size' => '16',
'radius' => 'soft',
'button_style' => 'solid',
'shadow' => 'soft',
'header_layout' => 'center',
'header_sticky' => '1',
'header_menu_count' => '6',
'card_ratio' => '4/5',
'card_hover_image' => '1',
'card_quick_add' => '1',
'card_rating' => '1',
'card_columns' => '4',
'badge_new_days' => '30',
'badge_bestseller' => '10',
'badge_low_stock' => '3',
'gallery_layout' => 'side',
'product_tabs' => 'tabs',
'related_count' => '4',
'trust_strip' => '1',
'footer_text' => '',
'container' => '1400',
];
}
function theme_palettes()
{
return [
'Siyah beyaz' => ['color_primary' => '#0a0a0a', 'color_accent' => '#e03d0b', 'color_bg' => '#ffffff', 'color_soft' => '#fafafa', 'color_text' => '#18181b', 'announce_bg' => '#0a0a0a', 'announce_text' => '#ffffff'],
'Lacivert' => ['color_primary' => '#0f1e3d', 'color_accent' => '#d4a017', 'color_bg' => '#ffffff', 'color_soft' => '#f5f7fb', 'color_text' => '#111827', 'announce_bg' => '#0f1e3d', 'announce_text' => '#f8fafc'],
'Toprak' => ['color_primary' => '#3b2a20', 'color_accent' => '#c2652a', 'color_bg' => '#fbf8f4', 'color_soft' => '#f3ede5', 'color_text' => '#2a211b', 'announce_bg' => '#c2652a', 'announce_text' => '#ffffff'],
'Orman' => ['color_primary' => '#14342b', 'color_accent' => '#7cb342', 'color_bg' => '#ffffff', 'color_soft' => '#f2f6f3', 'color_text' => '#0f1f1a', 'announce_bg' => '#14342b', 'announce_text' => '#e8f5e9'],
'Gül' => ['color_primary' => '#2b1a22', 'color_accent' => '#e2557b', 'color_bg' => '#fffafb', 'color_soft' => '#fbf0f3', 'color_text' => '#24161c', 'announce_bg' => '#e2557b', 'announce_text' => '#ffffff'],
'Okyanus' => ['color_primary' => '#0b3b4f', 'color_accent' => '#06b6d4', 'color_bg' => '#ffffff', 'color_soft' => '#f0f9fb', 'color_text' => '#0b1f29', 'announce_bg' => '#06b6d4', 'announce_text' => '#ffffff'],
];
}
function theme_fonts()
{
return ['Inter', 'Inter Tight', 'Manrope', 'DM Sans', 'Plus Jakarta Sans', 'Outfit', 'Sora', 'Space Grotesk', 'Poppins', 'Montserrat',
'Work Sans', 'Rubik', 'Urbanist', 'Figtree', 'Playfair Display', 'Cormorant Garamond', 'Fraunces', 'Lora', 'DM Serif Display', 'Libre Baskerville'];
}
function theme_radius_scales()
{
return [
'sharp' => ['Keskin', 0],
'soft' => ['Hafif', 0.6],
'round' => ['Yuvarlak', 1],
'pill' => ['Çok yuvarlak', 1.6],
];
}
// Tema değerini okur. Yönetici kaydetmeden önizleme yapıyorsa taslak geçerlidir.
function theme($key)
{
$draft = theme_draft();
if ($draft !== null && array_key_exists($key, $draft)) {
return $draft[$key];
}
$value = setting('theme_' . $key);
return $value ?? (theme_defaults()[$key] ?? '');
}
function theme_on($key)
{
return theme($key) === '1';
}
function theme_draft()
{
return is_admin() ? sess('theme_draft') : null;
}
function theme_all()
{
$all = [];
foreach (array_keys(theme_defaults()) as $key) {
$all[$key] = theme($key);
}
return $all;
}
function theme_save($values)
{
$data = [];
foreach (theme_defaults() as $key => $default) {
if (array_key_exists($key, $values)) {
$data['theme_' . $key] = (string) $values[$key];
}
}
setting_save($data);
}
function hex_color($value, $fallback)
{
return preg_match('/^#[0-9a-fA-F]{6}$/', (string) $value) ? strtolower($value) : $fallback;
}
// Google Fonts bağlantısı: seçili başlık ve metin fontları.
function theme_font_url()
{
$families = array_unique([theme('font_heading'), theme('font_body')]);
$query = implode('&', array_map(fn($font) => 'family=' . str_replace(' ', '+', $font) . ':wght@400;500;600;700;800', $families));
return 'https://fonts.googleapis.com/css2?' . $query . '&display=swap';
}
// Tailwind tema değişkenleri: renkler, fontlar, köşe yuvarlaklığı, gölgeler.
function theme_css()
{
$defaults = theme_defaults();
$primary = hex_color(theme('color_primary'), $defaults['color_primary']);
$accent = hex_color(theme('color_accent'), $defaults['color_accent']);
$scale = theme_radius_scales()[theme('radius')][1] ?? 0.6;
$radius = fn($rem) => round($rem * $scale, 3) . 'rem';
$mix = fn($color, $amount, $with) => "color-mix(in oklab, $color $amount%, $with)";
$vars = [
'--font-sans' => '"' . theme('font_body') . '", ui-sans-serif, system-ui, sans-serif',
'--font-display' => '"' . theme('font_heading') . '", ui-sans-serif, system-ui, sans-serif',
'--color-ink' => $primary,
'--color-accent-50' => $mix($accent, 8, 'white'),
'--color-accent-100'=> $mix($accent, 16, 'white'),
'--color-accent-500'=> $mix($accent, 85, 'white'),
'--color-accent-600'=> $accent,
'--color-accent-700'=> $mix($accent, 82, 'black'),
'--color-page' => hex_color(theme('color_bg'), $defaults['color_bg']),
'--color-soft' => hex_color(theme('color_soft'), $defaults['color_soft']),
'--color-body' => hex_color(theme('color_text'), $defaults['color_text']),
'--radius-md' => $radius(0.375),
'--radius-lg' => $radius(0.5),
'--radius-xl' => $radius(0.75),
'--radius-2xl' => $radius(1),
'--radius-3xl' => $radius(1.5),
'--radius-panel' => $radius(1.75),
];
if (theme('shadow') === 'none') {
foreach (['xs', 'sm', 'md', 'lg', 'xl', '2xl'] as $size) {
$vars['--shadow-' . $size] = '0 0 #0000';
}
}
$css = '';
foreach ($vars as $name => $value) {
$css .= " $name: $value;\n";
}
return $css;
}
function heading_weight_class()
{
return ['500' => 'font-medium', '600' => 'font-semibold', '700' => 'font-bold', '800' => 'font-extrabold'][theme('heading_weight')] ?? 'font-semibold';
}
function card_ratio_class()
{
return ['4/5' => 'aspect-[4/5]', '1/1' => 'aspect-square', '3/4' => 'aspect-[3/4]', '2/3' => 'aspect-[2/3]'][theme('card_ratio')] ?? 'aspect-[4/5]';
}
function card_columns_class()
{
return ['3' => 'lg:grid-cols-3', '4' => 'lg:grid-cols-4', '5' => 'lg:grid-cols-4 xl:grid-cols-5'][theme('card_columns')] ?? 'lg:grid-cols-4';
}
function container_style()
{
$width = max(1000, min(1800, (int) theme('container')));
return '--container-site: ' . $width . 'px;';
}
function logo_html($light = false, $class = '')
{
$file = $light && theme('logo_light') ? theme('logo_light') : theme('logo');
if ($file) {
return '<img src="' . e(upload_url($file)) . '" alt="' . e(store_name()) . '" data-logo style="height: ' . (int) theme('logo_height') . 'px" class="w-auto ' . $class . '">';
}
return '<span data-store-name class="font-display text-[26px] leading-none font-bold tracking-tight ' . $class . '">' . e(store_name()) . '</span>';
}
// Ürün rozetleri: elle girilen + otomatik (yeni, çok satan, son ürünler, indirim).
function product_badges($product)
{
$badges = [];
if (!empty($product['badge'])) {
$badges[] = [$product['badge'], 'bg-ink text-white'];
}
if ($rate = discount_rate($product)) {
$badges[] = ['−%' . $rate, 'bg-accent-600 text-white'];
}
if ($product['stock'] < 1) {
$badges[] = ['Tükendi', 'bg-white/90 text-zinc-700'];
return $badges;
}
$low = (int) theme('badge_low_stock');
if ($low > 0 && $product['stock'] <= $low) {
$badges[] = ['Son ' . (int) $product['stock'] . ' ürün', 'bg-amber-400 text-amber-950'];
}
$best = (int) theme('badge_bestseller');
if ($best > 0 && ($product['sold'] ?? 0) >= $best) {
$badges[] = ['Çok satan', 'bg-white/90 text-ink'];
}
$days = (int) theme('badge_new_days');
if ($days > 0 && !discount_rate($product) && strtotime($product['created_at']) > strtotime("-$days days")) {
$badges[] = ['Yeni', 'bg-white/90 text-ink'];
}
return array_slice($badges, 0, 3);
}
// Kartta üzerine gelince gösterilecek ikinci görsel (galerinin ilk görseli).
function hover_image($product_id)
{
static $map = null;
if ($map === null) {
$map = [];
foreach (db_all('SELECT product_id, file FROM product_images ORDER BY sort, id') as $row) {
$map[$row['product_id']] ??= $row['file'];
}
}
return $map[$product_id] ?? null;
}
Lisans bilgisi projenin LICENSE dosyasında.