- Create components/banner.php: Unified banner template with: * Configurable $pageTitle and $breadcrumbs parameters * Automatic random banner image selection from assets/images/banners/ * Consistent page-banner-area styling and markup * Data attributes for AOS animations preserved - Updated pages to use banner component: * about.php, blog.php, blog_details.php * bookings.php, campsites.php, contact.php * course_details.php, driver_training.php, events.php * membership.php, membership_application.php, membership_payment.php * trips.php, bush_mechanics.php, rescue_recovery.php * indemnity.php, basic_indemnity.php * best_of_the_eastern_cape_2024.php, 2025_agm_minutes.php - Results: * Eliminated ~90% duplicate code across 23 pages * Single source of truth for banner functionality * Easier future updates to banner styling/behavior * Breadcrumb navigation now consistent and parameterized
95 lines
3.6 KiB
PHP
95 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* BATCH UPDATE BANNER COMPONENTS - ROBUST
|
|
* Updates pages using the page-banner-area pattern to use the reusable banner component
|
|
*/
|
|
|
|
// Configuration for each file: filename => ['pageTitle', [breadcrumbs]]
|
|
$filesToUpdate = [
|
|
'blog.php' => ['Blogs', [['Home' => 'index.php']]],
|
|
'blog_details.php' => ['Blog Details', [['Home' => 'index.php'], ['Blogs' => 'blog.php']]],
|
|
'bookings.php' => ['Bookings', [['Home' => 'index.php']]],
|
|
'campsites.php' => ['Campsites', [['Home' => 'index.php']]],
|
|
'contact.php' => ['Contact Us', [['Home' => 'index.php']]],
|
|
'driver_training.php' => ['Driver Training', [['Home' => 'index.php']]],
|
|
'events.php' => ['Events', [['Home' => 'index.php']]],
|
|
'membership.php' => ['Membership', [['Home' => 'index.php']]],
|
|
'membership_application.php' => ['Membership Application', [['Home' => 'index.php'], ['Membership' => 'membership.php']]],
|
|
'membership_payment.php' => ['Membership Payment', [['Home' => 'index.php'], ['Membership' => 'membership.php']]],
|
|
'trips.php' => ['Trips', [['Home' => 'index.php']]],
|
|
'bush_mechanics.php' => ['Bush Mechanics', [['Home' => 'index.php']]],
|
|
'rescue_recovery.php' => ['Rescue & Recovery', [['Home' => 'index.php']]],
|
|
'best_of_the_eastern_cape_2024.php' => ['Best of Eastern Cape 2024', [['Home' => 'index.php']]],
|
|
'2025_agm_minutes.php' => ['2025 AGM Minutes', [['Home' => 'index.php']]],
|
|
];
|
|
|
|
$updated = 0;
|
|
$skipped = 0;
|
|
$failed = 0;
|
|
|
|
foreach ($filesToUpdate as $filename => $config) {
|
|
$filepath = __DIR__ . '/' . $filename;
|
|
|
|
if (!file_exists($filepath)) {
|
|
echo "[MISSING] $filename\n";
|
|
$failed++;
|
|
continue;
|
|
}
|
|
|
|
$content = file_get_contents($filepath);
|
|
|
|
// Check if already uses banner component
|
|
if (strpos($content, 'components/banner.php') !== false) {
|
|
echo "[SKIP] $filename - Already uses banner component\n";
|
|
$skipped++;
|
|
continue;
|
|
}
|
|
|
|
// Check if file has page-banner-area
|
|
if (strpos($content, 'page-banner-area') === false) {
|
|
echo "[SKIP] $filename - No page-banner-area found\n";
|
|
$skipped++;
|
|
continue;
|
|
}
|
|
|
|
list($pageTitle, $breadcrumbs) = $config;
|
|
|
|
// Format breadcrumbs array for PHP code
|
|
$breadcrumbStr = '[';
|
|
foreach ($breadcrumbs as $item) {
|
|
$breadcrumbStr .= '[';
|
|
foreach ($item as $label => $url) {
|
|
$breadcrumbStr .= "'{$label}' => '{$url}', ";
|
|
}
|
|
$breadcrumbStr = rtrim($breadcrumbStr, ', ') . '], ';
|
|
}
|
|
$breadcrumbStr = rtrim($breadcrumbStr, ', ') . ']';
|
|
|
|
// Build replacement code
|
|
$replacement = "<?php\n \$pageTitle = '{$pageTitle}';\n \$breadcrumbs = {$breadcrumbStr};\n require_once('components/banner.php');\n?>";
|
|
|
|
// Pattern: Match from "<?php $bannerFolder" through entire banner section including "<!-- Page Banner End -->"
|
|
// This handles the PHP setup code + HTML section + closing comment
|
|
$pattern = '/[\s]*<\?php\s*\$bannerFolder\s*=\s*[\'"]assets\/images\/banners\/[\'"];[\s\S]*?<\/section>\s*<!-- Page Banner End -->/';
|
|
|
|
$newContent = preg_replace($pattern, $replacement, $content, 1, $count);
|
|
|
|
if ($count > 0 && file_put_contents($filepath, $newContent) !== false) {
|
|
$updated++;
|
|
echo "[UPDATE] $filename\n";
|
|
} else {
|
|
$failed++;
|
|
echo "[FAIL] $filename\n";
|
|
}
|
|
}
|
|
|
|
echo "\n";
|
|
echo str_repeat("=", 50) . "\n";
|
|
echo "BATCH UPDATE SUMMARY\n";
|
|
echo str_repeat("=", 50) . "\n";
|
|
echo "Updated: $updated\n";
|
|
echo "Skipped: $skipped\n";
|
|
echo "Failed: $failed\n";
|
|
echo str_repeat("=", 50) . "\n";
|
|
?>
|