<?php
/**
 * Phase 2 Integration Script
 * Helps verify and apply Phase 2 helpers across the site
 * Run: php phase2_integration_check.php
 */

error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "=== Phase 2 Integration Verification ===\n\n";

// Check if all helper files exist
$helpers = [
    'image_alt_helper.php' => '/helpers/image_alt_helper.php',
    'internal_linking_helper.php' => '/helpers/internal_linking_helper.php',
    'heading_helper.php' => '/helpers/heading_helper.php',
    'meta_tags_helper.php' => '/helpers/meta_tags_helper.php'
];

$basePath = __DIR__;
$missingFiles = [];

echo "1. Checking Helper Files:\n";
foreach ($helpers as $name => $path) {
    $fullPath = $basePath . $path;
    if (file_exists($fullPath)) {
        echo "   ✓ {$name} - Found\n";
    } else {
        echo "   ✗ {$name} - MISSING\n";
        $missingFiles[] = $path;
    }
}

echo "\n2. Checking Page Files:\n";
$pages = [
    'index.php',
    'product.php',
    'blog.php',
    'category.php',
    'shop.php'
];

$pagesToUpdate = [];

foreach ($pages as $page) {
    $fullPath = $basePath . '/' . $page;
    if (file_exists($fullPath)) {
        echo "   ✓ {$page} - Found\n";
        
        // Check if it includes helpers
        $content = file_get_contents($fullPath);
        
        $needsUpdate = true;
        if (strpos($content, 'meta_tags_helper') !== false) {
            $needsUpdate = false;
        }
        
        if ($needsUpdate) {
            $pagesToUpdate[] = $page;
        }
    } else {
        echo "   ✗ {$page} - NOT FOUND\n";
    }
}

echo "\n3. Documentation Files:\n";
$docFiles = [
    'PHASE_2_GUIDE.md' => '/PHASE_2_GUIDE.md',
];

foreach ($docFiles as $name => $path) {
    $fullPath = $basePath . $path;
    if (file_exists($fullPath)) {
        echo "   ✓ {$name} - Found\n";
    } else {
        echo "   ✗ {$name} - NOT FOUND\n";
    }
}

echo "\n4. Integration Status:\n";
if (empty($missingFiles)) {
    echo "   ✓ All helper files are in place\n";
} else {
    echo "   ✗ Missing files: " . implode(', ', $missingFiles) . "\n";
}

echo "\n5. Pages Needing SEO Update:\n";
if (!empty($pagesToUpdate)) {
    foreach ($pagesToUpdate as $page) {
        echo "   → {$page}\n";
    }
    echo "\n   Next: See PHASE_2_GUIDE.md for integration instructions\n";
} else {
    echo "   ✓ All pages appear to have SEO helpers\n";
}

echo "\n=== Integration Complete ===\n";
echo "\nNext Steps:\n";
echo "1. Review PHASE_2_GUIDE.md for detailed integration steps\n";
echo "2. Update header.php to include the helper files\n";
echo "3. Integrate helpers into each page (index.php, product.php, etc.)\n";
echo "4. Test pages with SEO tools (Google PageSpeed, Schema.org validator)\n";
echo "5. Verify heading structure and meta tags on all pages\n";

?>
