<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'anka4915_volkher3');
define('DB_PASS', '80--19--aA');   // ← BURAYA MySQL şifrenizi yazın
define('DB_NAME', 'anka4915_volkher3');
define('SITE_URL', 'https://lisansim.com.tr/volker/');

// Error reporting - hide errors from visitors
error_reporting(0);
ini_set('display_errors', 0);

function db() {
    static $pdo = null, $failed = false;
    if ($failed) return null;
    if (!$pdo) {
        try {
            $pdo = new PDO(
                "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=utf8mb4",
                DB_USER, DB_PASS,
                [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
            );
        } catch(Exception $e) {
            $failed = true;
            return null;
        }
    }
    return $pdo;
}

function setting($key, $default = '') {
    static $cache = [];
    if (isset($cache[$key])) return $cache[$key];
    try {
        $d = db();
        if (!$d) return $default;
        $s = $d->prepare("SELECT value FROM vs_settings WHERE `key`=?");
        $s->execute([$key]);
        $r = $s->fetch();
        $cache[$key] = $r ? $r['value'] : $default;
    } catch(Exception $e) { $cache[$key] = $default; }
    return $cache[$key];
}

function slugify($text) {
    $tr = ['ş'=>'s','ı'=>'i','ğ'=>'g','ü'=>'u','ö'=>'o','ç'=>'c','Ş'=>'S','İ'=>'I','Ğ'=>'G','Ü'=>'U','Ö'=>'O','Ç'=>'C'];
    $text = strtr($text, $tr);
    $text = strtolower(trim($text));
    $text = preg_replace('/[^a-z0-9-]/', '-', $text);
    $text = preg_replace('/-+/', '-', $text);
    return trim($text, '-');
}

function clean($v) { return htmlspecialchars($v ?? '', ENT_QUOTES, 'UTF-8'); }

session_start();
function isAdmin() { return isset($_SESSION['vs_admin']); }
function requireAdmin() { if(!isAdmin()){header('Location:'.SITE_URL.'/admin/login.php');exit;} }
?>
