| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /proc/3951573/cwd/tmp/ |
Upload File : |
<?php
define('WP_USE_THEMES', false);
require '/var/www/clients/client2/web20/web/wp-load.php';
$APPLY = ( isset($argv[1]) && $argv[1] === '--apply' );
$bkdir = '/var/www/clients/client2/web20/private/blog-content-backup-' . trim(file_get_contents('/tmp/dgt_backup_ts.txt'));
@mkdir($bkdir, 0755, true);
function dgt_strip_images($html) {
$orig = $html;
// 1) [caption]...[/caption] komplett (enthält Bild + Bildunterschrift)
$html = preg_replace('/\[caption[^\]]*\].*?\[\/caption\]/is', '', $html);
// 2) <figure>…<img>…</figure> (Gutenberg/Bildblock inkl. optionalem Link/Caption)
$html = preg_replace('/<figure[^>]*>\s*(?:<a[^>]*>)?\s*<img[^>]*>\s*(?:<\/a>)?\s*(?:<figcaption[^>]*>.*?<\/figcaption>)?\s*<\/figure>/is', '', $html);
// 3) <a><img></a> (verlinktes Bild → ganzer Link weg)
$html = preg_replace('/<a[^>]*>\s*<img[^>]*>\s*<\/a>/is', '', $html);
// 4) übrige <img>
$html = preg_replace('/<img[^>]*\/?>/i', '', $html);
// 5) leere Hüllen aufräumen
$html = preg_replace('/<p>\s*(?: )?\s*<\/p>/i', '', $html);
$html = preg_replace('/\n{3,}/', "\n\n", $html);
return array($html, $orig);
}
$q = new WP_Query(array(
'post_type' => 'post', 'post_status' => 'publish',
'posts_per_page' => -1, 'no_found_rows' => true,
's' => '', // alle
));
$posts = get_posts(array('post_type'=>'post','post_status'=>'publish','numberposts'=>-1));
$total_imgs = 0; $changed = 0; $example_shown = false;
echo $APPLY ? "=== MODUS: ANWENDEN (schreibt) ===\n" : "=== MODUS: DRY-RUN (kein Schreiben) ===\n";
foreach ($posts as $p) {
$cnt = preg_match_all('/<img[^>]*>/i', $p->post_content);
if ($cnt < 1) continue;
list($new, $orig) = dgt_strip_images($p->post_content);
// Einzel-Backup
file_put_contents($bkdir . '/post-' . $p->ID . '.json', json_encode(array(
'ID'=>$p->ID, 'title'=>$p->post_title, 'content'=>$orig
), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
$total_imgs += $cnt; $changed++;
printf("#%-5d %-50s Bilder: %d %d -> %d Zeichen\n", $p->ID, mb_substr($p->post_title,0,48), $cnt, mb_strlen($orig), mb_strlen($new));
if (!$example_shown) {
$example_shown = true;
echo "\n--- BEISPIEL (Beitrag #{$p->ID}) ---\n";
// zeige eine Zeile mit <img> vorher und die bereinigte Stelle
if (preg_match('/.{0,60}<img[^>]*>.{0,40}/is', $orig, $m)) {
echo "VORHER: ..." . trim(preg_replace('/\s+/',' ',$m[0])) . "...\n";
}
echo "NACHHER: (Bild an dieser Stelle entfernt, Text bleibt erhalten)\n\n";
}
if ($APPLY) {
$r = wp_update_post(array('ID'=>$p->ID, 'post_content'=>$new), true);
if (is_wp_error($r)) echo " FEHLER beim Speichern: ".$r->get_error_message()."\n";
}
}
echo "\nBetroffene Beiträge: $changed | Bilder gesamt: $total_imgs\n";
echo "Einzel-Backups: $bkdir\n";