File: /homepages/31/d696029188/htdocs/Neu_GerdGeorge/GerdGeorgeDianaBackup/scan-and-fix-files.php
<?php
/**
* scan-and-fix-files.php — Scan (and optionally fix) file references to localhost/subfolder
* Upload to your WordPress ROOT (same dir as wp-config.php). Run, then DELETE.
*
* Dry run (scan only): https://gerdgeorge.de/scan-and-fix-files.php?token=GG-FILES-20251001
* Apply fixes : https://gerdgeorge.de/scan-and-fix-files.php?token=GG-FILES-20251001&apply=1
*
* It will:
* - scan .php, .html, .css, .js for 'localhost' and '/gerdgeorge' and '/GerdGeorgeDianaBackup'
* - by default, just list matches with file paths and counts
* - with &apply=1, it will replace with https://gerdgeorge.de and make a timestamped .bak copy
*/
ini_set('display_errors', '1');
error_reporting(E_ALL);
header('Content-Type: text/plain; charset=UTF-8');
define('SCAN_TOKEN', 'GG-FILES-20251001');
if (!isset($_GET['token']) || $_GET['token'] !== SCAN_TOKEN) {
http_response_code(403);
exit("Forbidden. Append ?token=GG-FILES-20251001\n");
}
$apply = isset($_GET['apply']) && $_GET['apply'] == '1';
$root = __DIR__;
$target = 'https://gerdgeorge.de';
$extensions = ['php','html','htm','css','js','json','txt'];
$excludeDirs = ['.git','node_modules','vendor','cache','cachestorage','wp-content/cache','wp-content/upgrade'];
$replacements = [
'https://gerdgeorge.de/' => $target.'/',
'https://gerdgeorge.de' => $target,
'https://gerdgeorge.de/' => $target.'/',
'https://gerdgeorge.de' => $target,
'https://gerdgeorge.de/' => $target.'/',
'https://gerdgeorge.de' => $target,
'https://gerdgeorge.de/' => $target.'/',
'https://gerdgeorge.de' => $target,
'https://gerdgeorge.de/' => $target.'/',
'https://gerdgeorge.de' => $target,
'https://gerdgeorge.de/' => $target.'/',
'https://gerdgeorge.de' => $target,
'href="/' => 'href="/',
'src="/' => 'src="/',
'url(/' => 'url(/',
'href="/' => 'href="/',
'src="/' => 'src="/',
'url(/' => 'url(/',
// conservative catch-all (paths only)
'/' => '/',
'/' => '/',
];
function should_skip($path, $excludeDirs) {
foreach ($excludeDirs as $ex) {
if (str_contains($path, $ex)) return true;
}
return false;
}
function iter_files($dir, $extensions, $excludeDirs) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS));
foreach ($rii as $file) {
if ($file->isDir()) continue;
$path = $file->getPathname();
if (should_skip($path, $excludeDirs)) continue;
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (!in_array($ext, $extensions)) continue;
yield $path;
}
}
$totalMatches = 0;
$totalChanged = 0;
$changedFiles = [];
echo "scan-and-fix-files.php (apply=" . ($apply ? '1' : '0') . ")\n";
echo "Root: $root\n\n";
foreach (iter_files($root, $extensions, $excludeDirs) as $file) {
$content = @file_get_contents($file);
if ($content === false) continue;
$orig = $content;
$matchesInFile = 0;
foreach ($replacements as $from => $to) {
$count = 0;
$content = str_replace($from, $to, $content, $count);
$matchesInFile += $count;
}
if ($matchesInFile > 0) {
$totalMatches += $matchesInFile;
echo "[MATCH] $file — replacements (dry): $matchesInFile\n";
if ($apply) {
$backup = $file . '.bak-' . date('Ymd-His');
@copy($file, $backup);
$ok = @file_put_contents($file, $content);
if ($ok !== false) {
$totalChanged += $matchesInFile;
$changedFiles[] = $file;
echo " -> wrote changes, backup: $backup\n";
} else {
echo " !! failed to write changes\n";
}
}
}
}
echo "\nSUMMARY\n";
echo " total matches: $totalMatches\n";
echo " total changed: $totalChanged\n";
echo " files changed: " . count($changedFiles) . "\n";
echo "\nTip: run without &apply=1 first to preview. Then run with &apply=1 to write changes.\n";
echo "Delete this file when finished.\n";