Compare commits

...

1 Commits

Author SHA1 Message Date
overplayed df8929f65b not working, unfinished css restructure changes 2025-02-05 15:32:10 -05:00
11 changed files with 7392 additions and 236 deletions

View File

@ -4,26 +4,159 @@ namespace WizdomNetworks\WizeWeb\Controllers;
use WizdomNetworks\WizeWeb\Core\View;
use WizdomNetworks\WizeWeb\Utils\Logger;
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
use Exception;
/**
* HomeController (v6)
*
* This controller handles the rendering of the home page.
*
* ## Features:
* - Initializes configurations for hero, single slider, and sidebar.
* - Ensures default values are applied to avoid undefined variable issues.
* - Implements logging for debugging key execution steps.
* - Uses exception handling to prevent application crashes.
*
* ## Methods:
* - `index()` - Loads and renders the home page.
* - `getHeroConfig()` - Returns configuration settings for the hero section.
* - `getSliderConfig()` - Returns configuration settings for the slider.
* - `getSidebarConfig()` - Returns configuration settings for the sidebar.
*/
class HomeController
{
public function index()
{
Logger::debug("HomeController::index() - Executing home page rendering.");
try {
$data = [
'title' => 'Home - Wizdom Networks',
'content' => "<h1>Welcome to Wizdom Networks</h1><p>Your trusted partner for IT Consulting and Services.</p>"
];
Logger::info("Initializing HomeController::index()");
Logger::debug("HomeController::index() - Data prepared successfully.");
View::render('pages/home', $data);
Logger::info("HomeController::index() - Home page rendered successfully.");
// Define page ID for page-specific styling
$pageId = 'home';
} catch (\Throwable $e) {
Logger::error("HomeController::index() - Error rendering home page: " . $e->getMessage());
// Load configurations
$heroConfig = $this->getHeroConfig();
$sliderConfig = $this->getSliderConfig();
$sidebarConfig = $this->getSidebarConfig();
Logger::info("HomeController loaded configs: hero=" . json_encode($heroConfig) . ", slider=" . json_encode($sliderConfig) . ", sidebar=" . json_encode($sidebarConfig));
// Ensure necessary keys exist
$heroConfig['enabled'] = $heroConfig['enabled'] ?? false;
$sliderConfig['enabled'] = $sliderConfig['enabled'] ?? false;
$sidebarConfig['enabled'] = $sidebarConfig['enabled'] ?? false;
// Log the view rendering attempt
Logger::info("Attempting to render home page");
View::render('pages/home', compact('pageId', 'heroConfig', 'sliderConfig', 'sidebarConfig'));
Logger::info("Successfully rendered Home Page");
} catch (Exception $e) {
ErrorHandler::exception($e);
Logger::error("HomeController::index() encountered an error: " . $e->getMessage());
http_response_code(500);
echo "An internal error occurred. Please check the logs.";
}
}
private function getHeroConfig()
{
return [
'enabled' => false, // Default to false to prevent errors
'title' => 'Welcome to Wizdom Networks',
'description' => 'We provide innovative IT solutions.',
'cta_text' => 'Learn More',
'cta_link' => '/services',
'background_image' => '/assets/images/hero.jpg',
];
}
private function getSliderConfig()
{
return [
'enabled' => true,
'id' => 'main-slider',
'height' => '65vh',
'type' => 'standard',
'slides' => [
[
'src' => '/assets/images/information-light.jpg',
'alt' => 'Information Light Banner',
'title' => 'Innovative Solutions',
'description' => 'Bringing technology and expertise together.',
'cta_text' => 'Learn More',
'cta_link' => '/services/technology',
'cta_top' => '70%',
'cta_left' => '30%',
'text_color' => 'white'
],
[
'src' => '/assets/images/cardcatalouge-banner.jpg',
'alt' => 'Card Catalogue Banner',
'title' => 'Effortless Organization',
'description' => 'Streamline your workflow with our intuitive catalog system.',
'cta_text' => 'Learn More',
'cta_link' => '/services/catalogue-management',
'cta_top' => '45%',
'cta_left' => '75%',
'text_color' => 'white'
],
[
'src' => '/assets/images/rolodex-banner.jpg',
'alt' => 'Rolodex Banner',
'title' => 'Contact Management Made Easy',
'description' => 'Keep track of important contacts and information in one place.',
'cta_text' => 'Get Started',
'cta_link' => '/services/contact-management',
'cta_top' => '45%',
'cta_left' => '70%',
'text_color' => 'black'
],
[
'src' => '/assets/images/oldmic.jpg',
'alt' => 'Old Microphone',
'title' => 'Broadcast Your Message',
'description' => 'Reach your audience with high-quality audio and video solutions.',
'cta_text' => 'Explore Options',
'cta_link' => '/services/media-solutions',
'cta_top' => '56%',
'cta_left' => '65%',
'text_color' => 'white'
],
[
'src' => '/assets/images/ancient-library-shelf-crop1.jpg',
'alt' => 'Library Archives',
'title' => 'Knowledge Preservation',
'description' => 'Store and manage your records securely and efficiently.',
'cta_text' => 'Discover More',
'cta_link' => '/services/data-archiving',
'cta_top' => '50%',
'cta_left' => '50%',
'text_color' => 'white'
],
[
'src' => '/assets/images/combosafedoor.jpg',
'alt' => 'Combination Safe Door',
'title' => 'Secure Your Data',
'description' => 'Advanced encryption and security solutions for your digital assets.',
'cta_text' => 'Protect Now',
'cta_link' => '/services/cybersecurity',
'cta_top' => '56%',
'cta_left' => '35%',
'text_color' => 'white'
]
]
];
}
private function getSidebarConfig()
{
return [
'enabled' => false, // Default to false to prevent errors
'title' => 'Welcome to Wizdom Networks',
'description' => 'We provide innovative IT solutions.',
'cta_text' => 'Learn More',
'cta_link' => '/services',
'background_image' => '/assets/images/hero.jpg',
];
}
}

View File

@ -38,6 +38,7 @@ class ProjectManagementController
View::render('pages/services/project_management', $data);
Logger::info("ProjectManagementController::index() - Project management page rendered successfully.");
} catch (\Throwable $e) {
error_log("projectmanagement\t*******");
Logger::error("ProjectManagementController::index() - Error rendering project management page: " . $e->getMessage());
ErrorHandler::exception($e);
}

View File

@ -4,11 +4,20 @@ namespace WizdomNetworks\WizeWeb\Core;
use WizdomNetworks\WizeWeb\Utils\Logger;
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
use Exception;
/**
* View Renderer
* View Renderer (v2)
*
* Handles view rendering, ensuring proper data passing and error handling.
* Handles view rendering, ensuring proper data passing, logging, and error handling.
*
* ## Features:
* - Dynamically resolves and includes view files.
* - Implements logging to track successful and failed rendering attempts.
* - Implements error handling to prevent fatal crashes.
*
* ## Methods:
* - `render(string $view, array $data = [])` - Renders the specified view file.
*/
class View
{
@ -17,30 +26,35 @@ class View
*
* @param string $view The name of the view file (relative to /resources/views/).
* @param array $data Associative array of variables to pass to the view.
* @throws \Exception If the view file is not found.
* @throws Exception If the view file is not found.
*/
public static function render(string $view, array $data = []): void
{
Logger::debug("Rendering view: $view");
// Extract data to make variables available in the view
extract($data);
// Build the full path to the view file
Logger::debug("[DEBUG] Attempting to load view: " . $view . " | Expected path: " . __DIR__ . "/../../resources/views/" . str_replace('.', '/', $view) . ".php");
$viewPath = realpath(__DIR__ . "/../../resources/views/" . str_replace('.', '/', $view) . ".php");
// Debugging: Log resolved path
Logger::debug("Resolved view path: $viewPath");
// Validate and include the view file
if ($viewPath && file_exists($viewPath)) {
include $viewPath;
Logger::debug("Successfully rendered view: $view");
} else {
Logger::error("View file not found: $view | Resolved path: $viewPath");
throw new \Exception("View file not found: $view");
try {
Logger::info("View::render() - Attempting to render: " . $view);
// Extract data to make variables available in the view
extract($data);
// Build the full path to the view file
$viewPath = realpath(__DIR__ . "/../../resources/views/" . str_replace('.', '/', $view) . ".php");
// Debugging: Log resolved path
Logger::info("View::render() - Resolved view path: " . ($viewPath ?: 'null'));
// Validate and include the view file
if ($viewPath && file_exists($viewPath)) {
include $viewPath;
Logger::info("View::render() - Successfully rendered: " . $view);
} else {
Logger::error("View::render() - View file not found: " . $view . " | Resolved path: " . ($viewPath ?: 'null'));
throw new Exception("View file not found: " . $view);
}
} catch (Exception $e) {
ErrorHandler::exception($e);
Logger::error("View::render() - Error rendering view '$view': " . $e->getMessage());
http_response_code(500);
echo "An internal error occurred. Please check the logs.";
}
}
}

View File

@ -30,8 +30,8 @@ class Logger
{
self::$logFile = $_ENV['LOG_DIRECTORY'] . "app.log" ?: __DIR__ . '/../../logs/app.log';
self::$debugEnabled = $_ENV['APP_DEBUG'] === 'true' || $_ENV['APP_DEBUG'] === true;
//self::$debugEnabled = false;
//self::$debugEnabled = isset($_ENV['APP_DEBUG']) && filter_var($_ENV['APP_DEBUG'], FILTER_VALIDATE_BOOL);
self::$debugEnabled = true;
}
/**

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
/* Auto-generated styles for home sliders */
#slider-main-slider-slide-0 {
top: 70%;
left: 30%;
color: white;
}
#slider-main-slider-slide-1 {
top: 45%;
left: 75%;
color: white;
}
#slider-main-slider-slide-2 {
top: 45%;
left: 70%;
color: black;
}
#slider-main-slider-slide-3 {
top: 56%;
left: 65%;
color: white;
}
#slider-main-slider-slide-4 {
top: 50%;
left: 50%;
color: white;
}
#slider-main-slider-slide-5 {
top: 56%;
left: 35%;
color: white;
}

View File

@ -1,22 +1,24 @@
<?php
<?php
use WizdomNetworks\WizeWeb\Core\View;
use WizdomNetworks\WizeWeb\Utils\Logger;
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
/**
* Main Layout (v7)
* Main Layout (v8)
*
* This file serves as the primary layout template for rendering pages.
* It includes dynamic loading for sidebar, hero, and slider components.
* Implements improved error handling to prevent undefined variable issues.
*
* Implements improved error handling and logging to prevent undefined variable issues.
*
* ## Features:
* - Dynamically loads the `head.php` partial with key page configurations.
* - Includes global navigation, footer, and main content structure.
* - Conditionally renders the hero, slider, and sidebar based on their configurations.
* - Uses Bootstrap's grid system to adjust layout dynamically.
* - Implements robust error handling to prevent undefined variable issues.
*
* - Logs key rendering steps to facilitate debugging.
*
* ## Variables Passed:
* - `$title` (string) - The title of the page.
* - `$heroConfig` (array) - Configuration settings for the hero section.
@ -25,12 +27,18 @@ use WizdomNetworks\WizeWeb\Core\View;
* - `$pageId` (string) - Unique identifier for the page, used for loading page-specific styles.
*/
// Ensure all optional configurations have default values to prevent errors
$title = $title ?? 'Wizdom Networks';
$pageId = $pageId ?? null;
$heroConfig = isset($heroConfig) && is_array($heroConfig) ? $heroConfig : ['enabled' => false];
$sliderConfig = isset($sliderConfig) && is_array($sliderConfig) ? $sliderConfig : ['enabled' => false];
$sidebarConfig = isset($sidebarConfig) && is_array($sidebarConfig) ? $sidebarConfig : ['enabled' => false];
try {
// Ensure all optional configurations have default values to prevent errors
$title = $title ?? 'Wizdom Networks';
$pageId = $pageId ?? null;
$heroConfig = isset($heroConfig) && is_array($heroConfig) ? $heroConfig : ['enabled' => false];
$sliderConfig = isset($sliderConfig) && is_array($sliderConfig) ? $sliderConfig : ['enabled' => false];
$sidebarConfig = isset($sidebarConfig) && is_array($sidebarConfig) ? $sidebarConfig : ['enabled' => false];
Logger::info("Rendering Main Layout for page: " . ($pageId ?? 'unknown'));
} catch (Exception $e) {
ErrorHandler::exception($e);
}
?>
<!DOCTYPE html>
@ -47,12 +55,14 @@ $sidebarConfig = isset($sidebarConfig) && is_array($sidebarConfig) ? $sidebarCon
<!-- Hero Section (Optional) -->
<?php if (isset($heroConfig['enabled']) && $heroConfig['enabled']) : ?>
<?php Logger::info("Rendering Hero Section"); ?>
<?php View::render('partials/hero', compact('heroConfig')); ?>
<?php endif; ?>
<!-- Slider Section (Optional) -->
<?php if (isset($sliderConfig['enabled']) && $sliderConfig['enabled']) : ?>
<?php View::render('partials/slider', compact('sliderConfig')); ?>
<?php Logger::info("Rendering Slider Section"); ?>
<?php View::render('partials/slider', compact('sliderConfig', 'pageId')); ?>
<?php endif; ?>
<div class="row">
@ -63,6 +73,7 @@ $sidebarConfig = isset($sidebarConfig) && is_array($sidebarConfig) ? $sidebarCon
<!-- Sidebar (Optional) -->
<?php if (isset($sidebarConfig['enabled']) && $sidebarConfig['enabled']) : ?>
<?php Logger::info("Rendering Sidebar"); ?>
<div class="col-md-3">
<?php View::render('partials/sidebar', compact('sidebarConfig')); ?>
</div>
@ -71,7 +82,7 @@ $sidebarConfig = isset($sidebarConfig) && is_array($sidebarConfig) ? $sidebarCon
</main>
<!-- Global Footer -->
<?php Logger::info("Rendering Footer"); ?>
<?php View::render('layouts/footer'); ?>
</body>

View File

@ -6,81 +6,42 @@ use WizdomNetworks\WizeWeb\Core\View;
* Home Page View (v2)
*
* This view dynamically renders the homepage using data provided by the HomeController.
*
* ## Features:
* - Loads dynamic configurations for hero, slider, and sidebar.
* - Ensures configurations are correctly passed to avoid undefined variable issues.
* - Uses the main layout structure for rendering.
*
* ## Variables Passed:
* - `$pageId` (string) - Unique identifier for the page, used for loading page-specific styles.
* - `$heroConfig` (array) - Configuration settings for the hero section.
* - `$sliderConfig` (array) - Configuration settings for the slider.
* - `$sidebarConfig` (array) - Configuration settings for the sidebar.
*/
// Ensure data is available before rendering
$title = $data['title'] ?? 'Home - Wizdom Networks';
$content = $data['content'] ?? '';
$title = 'Home - Wizdom Networks';
$content = "
<section class='home-intro'>
<h1>Welcome to Wizdom Networks</h1>
<p>Your trusted partner for IT Consulting and Services.</p>
</section>
<section class='home-services'>
<h2>Our Services</h2>
<ul>
<li><a href='/services/technology'>Technology Solutions</a></li>
<li><a href='/services/catalogue-management'>Catalogue Management</a></li>
<li><a href='/services/contact-management'>Contact Management</a></li>
<li><a href='/services/media-solutions'>Media Solutions</a></li>
<li><a href='/services/data-archiving'>Data Archiving</a></li>
<li><a href='/services/cybersecurity'>Cybersecurity</a></li>
</ul>
</section>
<section class='home-contact'>
<h2>Get in Touch</h2>
<p>Contact us today to learn how Wizdom Networks can help your business thrive.</p>
<a href='/contact' class='btn btn-primary'>Contact Us</a>
</section>
";
// Slider Configuration
$sliderConfig = [
'id' => 'home', // Unique identifier for home page slider styles
'enabled' => true,
'type' => 'standard',
'height' => '65vh',
'slides' => [
[
'src' => '/assets/images/information-light.jpg',
'alt' => 'Information Light Banner',
'title' => 'Innovative Solutions',
'description' => 'Bringing technology and expertise together.',
'cta_text' => 'Learn More',
'cta_link' => '/services/technology',
'cta_top' => '70%',
'cta_left' => '30%'
],
[
'src' => '/assets/images/cardcatalouge-banner.jpg',
'alt' => 'Card Catalogue Banner',
'title' => 'Effortless Organization',
'description' => 'Streamline your workflow with our intuitive catalog system.',
'cta_text' => 'Learn More',
'cta_link' => '/services/catalogue-management',
'cta_top' => '45%',
'cta_left' => '75%'
],
[
'src' => '/assets/images/rolodex-banner.jpg',
'alt' => 'Rolodex Banner',
'title' => 'Contact Management Made Easy',
'description' => 'Keep track of important contacts and information in one place.',
'cta_text' => 'Get Started',
'cta_link' => '/services/contact-management',
'cta_top' => '45%',
'cta_left' => '70%',
'text_color' => 'black'
],
[
'src' => '/assets/images/oldmic.jpg',
'alt' => 'Old Microphone',
'title' => 'Broadcast Your Message',
'description' => 'Reach your audience with high-quality audio and video solutions.',
'cta_text' => 'Explore Options',
'cta_link' => '/services/media-solutions',
'cta_top' => '56%',
'cta_left' => '65%'
],
[
'src' => '/assets/images/ancient-library-shelf-crop1.jpg',
'alt' => 'Library Archives',
'title' => 'Knowledge Preservation',
'description' => 'Store and manage your records securely and efficiently.',
'cta_text' => 'Discover More',
'cta_link' => '/services/data-archiving',
'cta_top' => '50%',
'cta_left' => '50%'
],
[
'src' => '/assets/images/combosafedoor.jpg',
'alt' => 'Combination Safe Door',
'title' => 'Secure Your Data',
'description' => 'Advanced encryption and security solutions for your digital assets.',
'cta_text' => 'Protect Now',
'cta_link' => '/services/cybersecurity',
'cta_top' => '56%',
'cta_left' => '35%'
]
]
];
View::render('layouts/main', compact('title', 'content', 'sliderConfig'));
View::render('layouts/main', compact('title', 'pageId', 'heroConfig', 'sliderConfig', 'sidebarConfig', 'content'));
?>

View File

@ -1,40 +1,57 @@
<?php
/**
* Hero Partial (v2)
* Hero Partial (v2) - Refactored to Remove Inline Styles
*
* This partial dynamically loads hero section configurations and writes styles to a page-specific CSS file (`<pageid>.css`).
*
* This partial dynamically loads a hero section based on the provided configuration.
* It allows pages to enable or disable the hero and define custom styles.
*
* ## Configuration Options:
* - `enabled` (bool) - Determines whether the hero is displayed (default: false)
* - `title` (string) - Hero title text
* - `description` (string) - Hero subtitle or description text
* - `image` (string) - Background image URL (default: 'wizdom-about-definitions.jpg')
* - `height` (string) - Height of the hero section (default: '50vh')
* - `text_align` (string) - Text alignment ('left', 'center', 'right') (default: 'center')
* - `overlay` (bool) - Apply a dark overlay to improve text readability (default: true)
* - `id` (string) - Unique identifier for the hero section.
* - `background_image` (string) - URL for the background image.
* - `height` (string) - Height of the hero section (default: '65vh').
* - `overlay_opacity` (float) - Opacity of the background overlay (default: 0.5).
* - `content_width` (string) - Maximum width of the hero content (default: '60%').
* - `text_align` (string) - Alignment of the hero text (default: 'center').
*/
// Ensure hero visibility is explicitly enabled
if (!isset($heroConfig) || empty($heroConfig['enabled'])) {
if (!isset($heroConfig) || empty($heroConfig['background_image'])) {
error_log("[ERROR] Missing or invalid hero configuration.");
return;
}
$heroTitle = htmlspecialchars($heroConfig['title'] ?? '', ENT_QUOTES, 'UTF-8');
$heroDescription = htmlspecialchars($heroConfig['description'] ?? '', ENT_QUOTES, 'UTF-8');
$heroImage = htmlspecialchars($heroConfig['image'] ?? '/assets/images/wizdom-about-definitions.jpg', ENT_QUOTES, 'UTF-8');
$heroHeight = htmlspecialchars($heroConfig['height'] ?? '50vh', ENT_QUOTES, 'UTF-8');
$heroId = htmlspecialchars($heroConfig['id'] ?? 'default', ENT_QUOTES, 'UTF-8');
$pageCssFile = "/assets/css/" . htmlspecialchars($pageId, ENT_QUOTES, 'UTF-8') . ".css";
$cssFilePath = $_SERVER['DOCUMENT_ROOT'] . $pageCssFile;
$heroHeight = $heroConfig['height'] ?? '65vh';
$overlayOpacity = $heroConfig['overlay_opacity'] ?? 0.5;
$contentWidth = htmlspecialchars($heroConfig['content_width'] ?? '60%', ENT_QUOTES, 'UTF-8');
$textAlign = htmlspecialchars($heroConfig['text_align'] ?? 'center', ENT_QUOTES, 'UTF-8');
$overlay = $heroConfig['overlay'] ?? false;
$cssContent = "/* Auto-generated styles for {$pageId} hero section */\n";
$cssContent .= "#hero-{$heroId} {\n";
$cssContent .= " background-image: url('" . htmlspecialchars($heroConfig['background_image'], ENT_QUOTES, 'UTF-8') . "');\n";
$cssContent .= " height: {$heroHeight};\n";
$cssContent .= " background-size: cover;\n";
$cssContent .= " background-position: center;\n";
$cssContent .= "}\n";
$cssContent .= "#hero-{$heroId} .hero-overlay {\n background: rgba(0, 0, 0, {$overlayOpacity});\n}\n";
$cssContent .= "#hero-{$heroId} .hero-content {\n max-width: {$contentWidth};\n text-align: {$textAlign};\n}\n";
if (!file_exists($cssFilePath) || file_get_contents($cssFilePath) !== $cssContent) {
file_put_contents($cssFilePath, $cssContent);
}
?>
<section class="hero-section" style="background-image: url('<?php echo $heroImage; ?>'); height: <?php echo $heroHeight; ?>;">
<?php if ($overlay) : ?>
<div class="hero-overlay"></div>
<?php endif; ?>
<div class="hero-content" style="text-align: <?php echo $textAlign; ?>;">
<h1><?php echo $heroTitle; ?></h1>
<p><?php echo $heroDescription; ?></p>
<section id="hero-<?php echo $heroId; ?>" class="hero-section">
<div class="hero-overlay"></div>
<div class="hero-content">
<h1><?php echo htmlspecialchars($heroConfig['title'], ENT_QUOTES, 'UTF-8'); ?></h1>
<p><?php echo htmlspecialchars($heroConfig['description'], ENT_QUOTES, 'UTF-8'); ?></p>
<?php if (!empty($heroConfig['cta_text']) && !empty($heroConfig['cta_link'])) : ?>
<a href="<?php echo htmlspecialchars($heroConfig['cta_link'], ENT_QUOTES, 'UTF-8'); ?>" class="btn btn-primary">
<?php echo htmlspecialchars($heroConfig['cta_text'], ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php endif; ?>
</div>
</section>

View File

@ -1,39 +1,64 @@
<?php
use WizdomNetworks\WizeWeb\Utils\Logger;
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
/**
* Sidebar Partial (v1)
* Sidebar Partial (v3) - Refactored for Consistency
*
* This partial dynamically loads sidebar configurations and writes styles to a page-specific CSS file (`<pageid>.css`).
*
* This partial dynamically loads a sidebar based on the provided configuration.
* It allows pages to enable or disable the sidebar and define custom styles.
*
* ## Configuration Options:
* - `enabled` (bool) - Determines whether the sidebar is displayed (default: false)
* - `width` (string) - Sidebar width percentage (default: '25%')
* - `position` (string) - Sidebar alignment: 'left' or 'right' (default: 'right')
* - `widgets` (array) - List of widgets or components to include in the sidebar
* - `id` (string) - Unique identifier for the sidebar.
* - `width` (string) - Width of the sidebar (default: '300px').
* - `position` (string) - Allowed values: 'left', 'right' (default: 'right').
* - `background_color` (string) - Background color of the sidebar (default: '#f8f9fa').
*/
// Ensure sidebar visibility is explicitly enabled
if (!isset($sidebarConfig) || empty($sidebarConfig['enabled'])) {
return;
}
try {
if (!isset($sidebarConfig) || empty($sidebarConfig['id'])) {
throw new Exception("Missing or invalid sidebar configuration.");
}
$sidebarWidth = htmlspecialchars($sidebarConfig['width'] ?? '25%', ENT_QUOTES, 'UTF-8');
$sidebarPosition = htmlspecialchars($sidebarConfig['position'] ?? 'right', ENT_QUOTES, 'UTF-8');
$sidebarId = htmlspecialchars($sidebarConfig['id'] ?? 'default', ENT_QUOTES, 'UTF-8');
$widgets = $sidebarConfig['widgets'] ?? [];
$sidebarId = htmlspecialchars($sidebarConfig['id'] ?? 'default', ENT_QUOTES, 'UTF-8');
$pageCssFile = "/assets/css/" . htmlspecialchars($pageId, ENT_QUOTES, 'UTF-8') . ".css";
$cssFilePath = $_SERVER['DOCUMENT_ROOT'] . $pageCssFile;
$sidebarWidth = htmlspecialchars($sidebarConfig['width'] ?? '300px', ENT_QUOTES, 'UTF-8');
$sidebarPosition = in_array($sidebarConfig['position'] ?? 'right', ['left', 'right']) ? $sidebarConfig['position'] : 'right';
$backgroundColor = htmlspecialchars($sidebarConfig['background_color'] ?? '#f8f9fa', ENT_QUOTES, 'UTF-8');
Logger::info("Generating sidebar styles for page: {$pageId}");
$cssContent = "/* Auto-generated styles for {$pageId} sidebar */\n";
$cssContent .= "#sidebar-{$sidebarId} {\n";
$cssContent .= " width: {$sidebarWidth};\n";
$cssContent .= " background-color: {$backgroundColor};\n";
$cssContent .= " float: {$sidebarPosition};\n";
$cssContent .= " padding: 1rem;\n";
$cssContent .= "}\n";
if (!file_exists($cssFilePath) || file_get_contents($cssFilePath) !== $cssContent) {
file_put_contents($cssFilePath, $cssContent);
Logger::info("Sidebar styles written to {$pageCssFile}.");
}
} catch (Exception $e) {
ErrorHandler::exception($e);
Logger::error("Sidebar generation error: " . $e->getMessage());
}
?>
<aside class="sidebar sidebar-<?php echo $sidebarId; ?>" style="width: <?php echo $sidebarWidth; ?>; float: <?php echo $sidebarPosition; ?>;">
<aside id="sidebar-<?php echo $sidebarId; ?>" class="sidebar">
<div class="sidebar-content">
<?php if (!empty($widgets)) : ?>
<?php foreach ($widgets as $widget): ?>
<div class="sidebar-widget">
<?php echo $widget; ?>
<?php if (!empty($sidebarConfig['title'])) : ?>
<h2><?php echo htmlspecialchars($sidebarConfig['title'], ENT_QUOTES, 'UTF-8'); ?></h2>
<?php endif; ?>
<div class="sidebar-items">
<?php foreach ($sidebarConfig['items'] ?? [] as $item): ?>
<div class="sidebar-item">
<a href="<?php echo htmlspecialchars($item['link'], ENT_QUOTES, 'UTF-8'); ?>">
<?php echo htmlspecialchars($item['text'], ENT_QUOTES, 'UTF-8'); ?>
</a>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No widgets configured.</p>
<?php endif; ?>
</div>
</div>
</aside>

View File

@ -1,11 +1,15 @@
<?php
use WizdomNetworks\WizeWeb\Utils\Logger;
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
/**
* Slider Partial (v12)
* Slider Partial (v14) - Refactored to Remove Inline Styles
*
* This partial dynamically loads different types of sliders based on the provided configuration.
* It supports multiple slider types, including standard and testimonial sliders, and only loads when required.
*
* All styles are written to a page-specific CSS file (`<pageid>.css`) instead of using inline styles.
* Debug logging and error handling are implemented using the Logger and ErrorHandler utilities.
*
* ## Configuration Options:
* - `id` (string) - Unique identifier for the slider (used for styling and debugging)
* - `type` (string) - Allowed values: 'standard', 'testimonial'
@ -19,69 +23,57 @@
* - `cta_width` (string) - Defines CTA container width (default: 'auto')
* - `cta_text_align` (string) - Text alignment within CTA (default: 'center')
* - `lazy_load` (bool) - Enables lazy loading for images (default: true)
* - `cta_top` (string) - Vertical positioning of CTA (default: varies per slide)
* - `cta_left` (string) - Horizontal positioning of CTA (default: varies per slide)
* - `text_color` (string) - Defines text color for each slide (default: 'white')
*/
// Ensure slider visibility is explicitly enabled
if (!isset($sliderConfig) || empty($sliderConfig['type'])) {
error_log("[ERROR] Missing or invalid slider configuration.");
return;
}
try {
if (!isset($sliderConfig) || empty($sliderConfig['type'])) {
throw new Exception("Missing or invalid slider configuration.");
}
$validTypes = ['standard', 'testimonial'];
$sliderType = in_array($sliderConfig['type'], $validTypes) ? $sliderConfig['type'] : 'standard';
$sliderId = htmlspecialchars($sliderConfig['id'] ?? 'default', ENT_QUOTES, 'UTF-8');
$sliderHeight = $sliderConfig['height'] ?? '65vh';
$objectFit = htmlspecialchars($sliderConfig['object_fit'] ?? 'cover', ENT_QUOTES, 'UTF-8');
$interval = $sliderConfig['interval'] ?? 5000; // Default to 5 seconds
$pauseOnHover = isset($sliderConfig['pause_on_hover']) && $sliderConfig['pause_on_hover'] ? 'hover' : 'false';
$showControls = $sliderConfig['controls'] ?? true;
$showIndicators = $sliderConfig['indicators'] ?? true;
$animationType = $sliderConfig['animation'] ?? 'slide';
$ctaWidth = htmlspecialchars($sliderConfig['cta_width'] ?? 'auto', ENT_QUOTES, 'UTF-8');
$ctaTextAlign = htmlspecialchars($sliderConfig['cta_text_align'] ?? 'center', ENT_QUOTES, 'UTF-8');
$lazyLoad = isset($sliderConfig['lazy_load']) && $sliderConfig['lazy_load'] ? 'loading="lazy"' : '';
$sliderImages = $sliderConfig['slides'] ?? [];
$validTypes = ['standard', 'testimonial'];
$sliderType = in_array($sliderConfig['type'], $validTypes) ? $sliderConfig['type'] : 'standard';
$sliderId = htmlspecialchars($sliderConfig['id'] ?? 'default', ENT_QUOTES, 'UTF-8');
$pageCssFile = "/assets/css/" . htmlspecialchars($pageId, ENT_QUOTES, 'UTF-8') . ".css";
$cssFilePath = $_SERVER['DOCUMENT_ROOT'] . $pageCssFile;
$sliderHeight = $sliderConfig['height'] ?? '65vh';
$objectFit = htmlspecialchars($sliderConfig['object_fit'] ?? 'cover', ENT_QUOTES, 'UTF-8');
$interval = $sliderConfig['interval'] ?? 5000;
$pauseOnHover = isset($sliderConfig['pause_on_hover']) && $sliderConfig['pause_on_hover'] ? 'hover' : 'false';
$showControls = $sliderConfig['controls'] ?? true;
$showIndicators = $sliderConfig['indicators'] ?? true;
$animationType = $sliderConfig['animation'] ?? 'slide';
$ctaWidth = htmlspecialchars($sliderConfig['cta_width'] ?? 'auto', ENT_QUOTES, 'UTF-8');
$ctaTextAlign = htmlspecialchars($sliderConfig['cta_text_align'] ?? 'center', ENT_QUOTES, 'UTF-8');
$lazyLoad = isset($sliderConfig['lazy_load']) && $sliderConfig['lazy_load'] ? 'loading="lazy"' : '';
$sliderImages = $sliderConfig['slides'] ?? [];
// Debugging logs for missing or incorrect configurations
if (empty($sliderImages)) {
error_log("[ERROR] Slider '$sliderId' has no slides defined.");
}
if (!in_array($sliderType, $validTypes)) {
error_log("[ERROR] Invalid slider type '$sliderType' for slider '$sliderId'.");
if (empty($sliderImages)) {
Logger::error("Slider '$sliderId' has no slides defined.");
throw new Exception("Slider '$sliderId' has no slides defined.");
}
$cssContent = "/* Auto-generated styles for {$pageId} sliders */\n";
foreach ($sliderImages as $index => $image) {
$cssContent .= "#slider-{$sliderId}-slide-{$index} {\n";
if (!empty($image['cta_top'])) {
$cssContent .= " top: {$image['cta_top']};\n";
}
if (!empty($image['cta_left'])) {
$cssContent .= " left: {$image['cta_left']};\n";
}
if (!empty($image['text_color'])) {
$cssContent .= " color: {$image['text_color']};\n";
}
$cssContent .= "}\n";
}
if (!file_exists($cssFilePath) || file_get_contents($cssFilePath) !== $cssContent) {
file_put_contents($cssFilePath, $cssContent);
}
Logger::info("Slider '$sliderId' styles successfully written to '$pageCssFile'.");
} catch (Exception $e) {
ErrorHandler::exception($e);
}
?>
<section class="slider slider-<?php echo $sliderId; ?> slider-<?php echo htmlspecialchars($sliderType, ENT_QUOTES, 'UTF-8'); ?>"
data-animation="<?php echo htmlspecialchars($animationType, ENT_QUOTES, 'UTF-8'); ?>"
style="height: <?php echo htmlspecialchars($sliderHeight, ENT_QUOTES, 'UTF-8'); ?>; overflow: hidden; position: relative;">
<div id="carousel" class="carousel <?php echo $animationType === 'fade' ? 'carousel-fade' : ''; ?> slide" data-bs-ride="carousel" data-bs-interval="<?php echo $interval; ?>" data-bs-pause="<?php echo $pauseOnHover; ?>">
<?php if ($showIndicators) : ?>
<div class="carousel-indicators">
<?php foreach ($sliderImages as $index => $image): ?>
<button type="button" data-bs-target="#carousel" data-bs-slide-to="<?php echo $index; ?>"
class="<?php echo $index === 0 ? 'active' : ''; ?> indicator-color-<?php echo $index + 1; ?>"
aria-label="Slide <?php echo $index + 1; ?>" <?php echo $index === 0 ? 'aria-current="true"' : ''; ?>></button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="carousel-inner">
<?php foreach ($sliderImages as $index => $image): ?>
<div class="carousel-item <?php echo $index === 0 ? 'active' : ''; ?>">
<img src="<?php echo htmlspecialchars($image['src'], ENT_QUOTES, 'UTF-8'); ?>"
alt="<?php echo htmlspecialchars($image['alt'], ENT_QUOTES, 'UTF-8'); ?>"
class="d-block w-100 slider-image grayscale-effect"
style="height: <?php echo htmlspecialchars($sliderHeight, ENT_QUOTES, 'UTF-8'); ?>; object-fit: <?php echo $objectFit; ?>; filter: grayscale(100%); transition: filter 0.5s ease-in-out;"
<?php echo $lazyLoad; ?>>
<div class="carousel-caption"
style="color: <?php echo htmlspecialchars($image['text_color'] ?? 'white', ENT_QUOTES, 'UTF-8'); ?>; position: absolute; top: <?php echo htmlspecialchars($image['cta_top'], ENT_QUOTES, 'UTF-8'); ?>; left: <?php echo htmlspecialchars($image['cta_left'], ENT_QUOTES, 'UTF-8'); ?>; transform: translate(-50%, -50%); width: <?php echo $ctaWidth; ?>; text-align: <?php echo $ctaTextAlign; ?>;">
<h2><?php echo htmlspecialchars($image['title'], ENT_QUOTES, 'UTF-8'); ?></h2>
<p><?php echo htmlspecialchars($image['description'], ENT_QUOTES, 'UTF-8'); ?></p>
<a href="<?php echo htmlspecialchars($image['cta_link'], ENT_QUOTES, 'UTF-8'); ?>" class="btn btn-primary slider-cta"> <?php echo htmlspecialchars($image['cta_text'], ENT_QUOTES, 'UTF-8'); ?> </a>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</section>