Path : /home/vishqocm/pcib.in/includes/
File Upload :
Current File : //home/vishqocm/pcib.in/includes/theme_loader.php

<?php
/**
 * Theme Loader
 * This file loads theme settings from the database and applies them to the website
 */

// Get theme settings from database
function get_theme_settings() {
    global $conn;
    
    // Default theme settings
    $default_settings = [
        'theme_name' => 'default',
        'header_bg_color' => '#ffffff',
        'footer_bg_color' => '#f8f9fc',
        'text_color' => '#333333',
        'link_color' => '#4e73df',
        'button_style' => 'rounded',
        'font_family' => 'Roboto, sans-serif',
        'custom_css' => ''
    ];
    
    $theme_settings = $default_settings;
    
    // First check if the theme_settings table exists
    $table_exists = false;
    if ($conn instanceof mysqli) {
        $check_table = $conn->query("SHOW TABLES LIKE 'theme_settings'");
        $table_exists = ($check_table && $check_table->num_rows > 0);
    }
    
    // Only query for settings if the table exists
    if ($table_exists) {
        // Query database for theme settings
        $settings_query = "SELECT * FROM theme_settings";
        $settings_result = mysqli_query($conn, $settings_query);
        
        if ($settings_result && mysqli_num_rows($settings_result) > 0) {
            while ($row = mysqli_fetch_assoc($settings_result)) {
                $theme_settings[$row['setting_key']] = $row['setting_value'];
            }
        }
    } else {
        // Log that the table doesn't exist
        error_log("Theme settings table doesn't exist. Using default theme settings.");
    }
    
    return $theme_settings;
}

// Get theme settings
$theme_settings = get_theme_settings();

// Extract theme settings
$theme_name = $theme_settings['theme_name'];
$header_bg_color = $theme_settings['header_bg_color'];
$footer_bg_color = $theme_settings['footer_bg_color'];
$text_color = $theme_settings['text_color'];
$link_color = $theme_settings['link_color'];
$button_style = $theme_settings['button_style'];
$font_family = $theme_settings['font_family'];
$custom_css = $theme_settings['custom_css'];

// Get button radius based on style
$button_radius = '4px'; // Default rounded
if ($button_style == 'square') {
    $button_radius = '0';
} elseif ($button_style == 'pill') {
    $button_radius = '50px';
}

// Output CSS variables and theme styles
?>
<style id="theme-dynamic-styles">
    :root {
        --header-bg-color: <?php echo $header_bg_color; ?>;
        --footer-bg-color: <?php echo $footer_bg_color; ?>;
        --text-color: <?php echo $text_color; ?>;
        --link-color: <?php echo $link_color; ?>;
        --font-family: <?php echo $font_family; ?>;
        --button-radius: <?php echo $button_radius; ?>;
    }
    
    /* Apply theme settings */
    body {
        font-family: var(--font-family);
        color: var(--text-color);
    }
    
    .navbar, .header {
        background-color: var(--header-bg-color) !important;
    }
    
    footer {
        background-color: var(--footer-bg-color) !important;
    }
    
    a:not(.btn) {
        color: var(--link-color);
    }
    
    a:hover:not(.btn) {
        color: var(--link-color);
        opacity: 0.8;
    }
    
    .btn {
        border-radius: var(--button-radius) !important;
    }
    
    /* Custom CSS from theme settings */
    <?php echo $custom_css; ?>
</style>

<!-- Font families -->
<?php if (strpos($font_family, 'Roboto') !== false): ?>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
<?php endif; ?>

<?php if (strpos($font_family, 'Open Sans') !== false): ?>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700&display=swap" rel="stylesheet">
<?php endif; ?>

<?php if (strpos($font_family, 'Lato') !== false): ?>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&display=swap" rel="stylesheet">
<?php endif; ?>

<?php if (strpos($font_family, 'Montserrat') !== false): ?>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<?php endif; ?>

<?php if (strpos($font_family, 'Poppins') !== false): ?>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<?php endif; ?>

<?php if (strpos($font_family, 'Source Sans Pro') !== false): ?>
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;600;700&display=swap" rel="stylesheet">
<?php endif; ?>