T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/public_html/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/includes/translations.php
<?php
/**
 * Translation System for SoundStudioPro
 * Supports English and French
 */

// Initialize session if not already started
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Define available languages
define('AVAILABLE_LANGUAGES', ['en', 'fr']);
define('DEFAULT_LANGUAGE', 'en');

/**
 * Get current language from session or browser preference
 */
function getCurrentLanguage() {
    // Check if language is set in session
    if (isset($_SESSION['language']) && in_array($_SESSION['language'], AVAILABLE_LANGUAGES)) {
        return $_SESSION['language'];
    }
    
    // Check if language is set via GET parameter
    if (isset($_GET['lang']) && in_array($_GET['lang'], AVAILABLE_LANGUAGES)) {
        $_SESSION['language'] = $_GET['lang'];
        return $_GET['lang'];
    }
    
    // Try to detect from browser Accept-Language header
    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $browserLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        if (in_array($browserLang, AVAILABLE_LANGUAGES)) {
            $_SESSION['language'] = $browserLang;
            return $browserLang;
        }
    }
    
    // Default to English
    $_SESSION['language'] = DEFAULT_LANGUAGE;
    return DEFAULT_LANGUAGE;
}

/**
 * Set language
 */
function setLanguage($lang) {
    if (in_array($lang, AVAILABLE_LANGUAGES)) {
        $_SESSION['language'] = $lang;
        return true;
    }
    return false;
}

/**
 * Load translation file
 */
function loadTranslations($lang) {
    static $translations = [];
    
    if (isset($translations[$lang])) {
        return $translations[$lang];
    }
    
    $translationFile = __DIR__ . '/../lang/' . $lang . '.php';
    
    if (file_exists($translationFile)) {
        $translations[$lang] = require $translationFile;
        return $translations[$lang];
    }
    
    // Fallback to English if translation file doesn't exist
    if ($lang !== DEFAULT_LANGUAGE) {
        $translationFile = __DIR__ . '/../lang/' . DEFAULT_LANGUAGE . '.php';
        if (file_exists($translationFile)) {
            $translations[$lang] = require $translationFile;
            return $translations[$lang];
        }
    }
    
    // Return empty array if no translation file exists
    return [];
}

/**
 * Translation function - main function to use throughout the site
 * Usage: t('key') or t('key', ['param' => 'value'])
 */
function t($key, $params = []) {
    $lang = getCurrentLanguage();
    $translations = loadTranslations($lang);
    
    // Get translation
    $translation = $translations[$key] ?? $key;
    
    // Replace parameters if provided
    if (!empty($params)) {
        foreach ($params as $paramKey => $paramValue) {
            $translation = str_replace(':' . $paramKey, $paramValue, $translation);
        }
    }
    
    return $translation;
}

/**
 * Echo translation (shorthand)
 */
function te($key, $params = []) {
    echo t($key, $params);
}

/**
 * Helper to fetch localized plan names with graceful fallback.
 */
function getPlanLabel($planKey, $defaultName = null) {
    $translationKey = 'plans.label.' . $planKey;
    $translated = t($translationKey);
    
    if ($translated === $translationKey) {
        if ($defaultName !== null) {
            return $defaultName;
        }
        $readable = str_replace('_', ' ', $planKey);
        return ucwords($readable);
    }
    
    return $translated;
}

/**
 * Helper to fetch localized plan target audience text.
 */
function getPlanAudienceLabel($planKey, $defaultDescription = null) {
    $translationKey = 'plans.target_audience.' . $planKey;
    $translated = t($translationKey);

    if ($translated === $translationKey) {
        if ($defaultDescription !== null) {
            return $defaultDescription;
        }
        return $translationKey;
    }

    return $translated;
}

/**
 * Get language name
 */
function getLanguageName($lang) {
    $names = [
        'en' => 'English',
        'fr' => 'Français'
    ];
    return $names[$lang] ?? $lang;
}

/**
 * Get language direction (for RTL support in future)
 */
function getLanguageDirection($lang = null) {
    if ($lang === null) {
        $lang = getCurrentLanguage();
    }
    return 'ltr'; // Both English and French are LTR
}

/**
 * Translate credit transaction descriptions
 * Maps known English descriptions to translation keys
 */
function translateCreditDescription($description) {
    // Map of known English descriptions to translation keys
    $descriptionMap = [
        'Holiday Gift - 5 Free Songs' => 'credits.desc.holiday_gift',
        'Subscription renewal' => 'credits.desc.subscription_renewal',
        'Credit purchase' => 'credits.desc.credit_purchase',
        'Track generation' => 'credits.desc.track_generation',
        'Welcome bonus' => 'credits.desc.welcome_bonus',
        'Refund' => 'credits.desc.refund',
    ];
    
    // Check for exact match
    if (isset($descriptionMap[$description])) {
        return t($descriptionMap[$description]);
    }
    
    // Handle "Music track creation" descriptions with mode and track title
    // Format: "Music track creation (Pro Mode): Track Title" or "Music track creation: Track Title"
    // Note: Track title may be empty, so we use .* instead of .+
    if (preg_match('/^Music track creation(?: \(([^)]+)\))?(?:: (.*))?$/i', $description, $matches)) {
        $mode = $matches[1] ?? '';
        $trackTitle = $matches[2] ?? '';
        
        // Translate mode
        $translatedMode = '';
        if ($mode) {
            switch ($mode) {
                case 'Pro Mode':
                    $translatedMode = t('credits.desc.mode_pro');
                    break;
                case 'Advanced Mode':
                    $translatedMode = t('credits.desc.mode_advanced');
                    break;
                case 'Simple Mode':
                case 'Basic Mode':
                    $translatedMode = t('credits.desc.mode_simple');
                    break;
                default:
                    $translatedMode = $mode;
            }
        }
        
        // Build translated description
        $result = t('credits.desc.track_creation');
        if ($translatedMode) {
            $result .= ' (' . $translatedMode . ')';
        }
        if ($trackTitle) {
            $result .= ' : ' . $trackTitle;
        }
        return $result;
    }
    
    // Check for pattern matches (for descriptions with dynamic content)
    foreach ($descriptionMap as $pattern => $key) {
        if (stripos($description, $pattern) !== false) {
            return t($key);
        }
    }
    
    // Return original if no translation found
    return $description;
}

/**
 * Format a date in the current language
 * @param int|string $timestamp Unix timestamp or date string
 * @param string $format Format key: 'short', 'medium', 'long', 'datetime', 'time'
 * @return string Localized date string
 */
function formatLocalizedDate($timestamp, $format = 'medium') {
    if (is_string($timestamp)) {
        $timestamp = strtotime($timestamp);
    }
    
    $lang = getCurrentLanguage();
    
    // French month names
    $frenchMonths = [
        1 => 'janvier', 2 => 'février', 3 => 'mars', 4 => 'avril',
        5 => 'mai', 6 => 'juin', 7 => 'juillet', 8 => 'août',
        9 => 'septembre', 10 => 'octobre', 11 => 'novembre', 12 => 'décembre'
    ];
    
    $frenchMonthsShort = [
        1 => 'janv.', 2 => 'févr.', 3 => 'mars', 4 => 'avr.',
        5 => 'mai', 6 => 'juin', 7 => 'juil.', 8 => 'août',
        9 => 'sept.', 10 => 'oct.', 11 => 'nov.', 12 => 'déc.'
    ];
    
    $day = date('j', $timestamp);
    $month = (int)date('n', $timestamp);
    $year = date('Y', $timestamp);
    $hour = date('G', $timestamp);
    $minute = date('i', $timestamp);
    
    $timezone = date('T', $timestamp);
    
    if ($lang === 'fr') {
        switch ($format) {
            case 'short':
                // 13 déc.
                return $day . ' ' . $frenchMonthsShort[$month];
            case 'medium':
                // 13 déc. 2025
                return $day . ' ' . $frenchMonthsShort[$month] . ' ' . $year;
            case 'long':
                // 13 décembre 2025
                return $day . ' ' . $frenchMonths[$month] . ' ' . $year;
            case 'datetime':
                // 13 déc., 14h30
                return $day . ' ' . $frenchMonthsShort[$month] . ', ' . $hour . 'h' . $minute;
            case 'full':
                // 13 décembre 2025 à 14h30 UTC
                return $day . ' ' . $frenchMonths[$month] . ' ' . $year . ' à ' . $hour . 'h' . $minute . ' ' . $timezone;
            case 'time':
                // 14h30
                return $hour . 'h' . $minute;
            default:
                return $day . ' ' . $frenchMonthsShort[$month] . ' ' . $year;
        }
    } else {
        // English formats
        $englishMonths = date('F', $timestamp);
        $englishMonthsShort = date('M', $timestamp);
        $ampm = date('A', $timestamp);
        $hour12 = date('g', $timestamp);
        
        switch ($format) {
            case 'short':
                // Dec 13
                return $englishMonthsShort . ' ' . $day;
            case 'medium':
                // Dec 13, 2025
                return $englishMonthsShort . ' ' . $day . ', ' . $year;
            case 'long':
                // December 13, 2025
                return $englishMonths . ' ' . $day . ', ' . $year;
            case 'datetime':
                // Dec 13, 2:30 PM
                return $englishMonthsShort . ' ' . $day . ', ' . $hour12 . ':' . $minute . ' ' . $ampm;
            case 'full':
                // December 13, 2025 at 2:30 PM UTC
                return $englishMonths . ' ' . $day . ', ' . $year . ' at ' . $hour12 . ':' . $minute . ' ' . $ampm . ' ' . $timezone;
            case 'time':
                // 2:30 PM
                return $hour12 . ':' . $minute . ' ' . $ampm;
            default:
                return $englishMonthsShort . ' ' . $day . ', ' . $year;
        }
    }
}


CasperSecurity Mini