<?php
$root = dirname(__DIR__);
$dirs = array('data', 'config', 'yanscms', 'inc', 'system');
$extensions = array('php'=>true, 'txt'=>true, 'md'=>true, 'json'=>true);
$changed = 0;
$scanned = 0;

foreach($dirs as $dir){
    $base = $root . '/' . $dir;
    if(!is_dir($base)) continue;
    $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base, FilesystemIterator::SKIP_DOTS));
    foreach($it as $file){
        if(!$file->isFile()) continue;
        $ext = strtolower($file->getExtension());
        if(!isset($extensions[$ext])) continue;
        $path = $file->getPathname();
        $scanned++;
        $content = file_get_contents($path);
        $next = str_replace('.svg', '.jpg', $content);
        if($next === $content) continue;
        file_put_contents($path, $next, LOCK_EX);
        $changed++;
    }
}

echo "Scanned: $scanned, changed: $changed\n";
