// Public S3 Download versuchen function try_download_public_s3($image_url, $header_text, $attempt) { require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); // Verschiedene Download-Strategien für Public S3 $strategies = [ 'wp_remote' => function($url) { return wp_remote_get($url, [ 'timeout' => 60, 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'sslverify' => false, 'headers' => [ 'Accept' => 'image/*,*/*;q=0.8', 'Accept-Language' => 'en-US,en;q=0.5', 'Cache-Control' => 'no-cache' ] ]); }, 'download_url' => function($url) { return download_url($url, 60); }, 'curl' => function($url) { if (!function_exists('curl_init')) return false; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; WordPress/' . get_bloginfo('version') . ')', CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 3 ]); $data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ($http_code === 200 && $data) ? $data : false; } ]; // Strategie basierend auf Versuch wählen $strategy_names = array_keys($strategies); $strategy_name = $strategy_names[($attempt - 1) % count($strategy_names)]; $strategy = $strategies[$strategy_name]; write_abschnitte_log_unique('DEBUG', "[RSS-CRAWLER] Public Download Strategie: {$strategy_name}"); $result = $strategy($image_url); if (is_wp_error($result)) { write_abschnitte_log_unique('ERROR', "[RSS-CRAWLER] {$strategy_name} Fehler: " . $result->get_error_message()); return false; } // Daten extrahieren $image_data = null; if ($strategy_name === 'wp_remote' && !is_wp_error($result)) { if (wp_remote_retrieve_response_code($result) === 200) { $image_data = wp_remote_retrieve_body($result); } } elseif ($strategy_name === 'download_url' && !is_wp_error($result)) { $image_data = file_get_contents($result); unlink($result); // Temp-Datei löschen } elseif ($strategy_name === 'curl') { $image_data = $result; } if (!$image_data || strlen($image_data) < 1000) { write_abschnitte_log_unique('ERROR', "[RSS-CRAWLER] {$strategy_name}: Keine/unvollständige Daten"); return false; } // Bild verarbeiten return process_image_data_bulletproof($image_data, $header_text, $image_url); } // Private S3 Bild generieren function generate_private_s3_image($prompt, $api_keys) { $enhanced_prompt = "The ultra-realistic UHD photo captures " . substr($prompt, 0, 300); write_abschnitte_log_unique('INFO', "[RSS-CRAWLER] 🔒 Private S3 Bildgenerierung für: " . substr($prompt, 0, 50)); $payload = [ "key" => $api_keys['BILDIMPORT_API_KEY'], "prompt" => $enhanced_prompt, "width" => "200", "height" => "200", "samples" => "1", "num_inference_steps" => "31", "guidance_scale" => "3.5", "enhance_prompt" => true, "safety_checker" => false, "webhook" => null, "track_id" => null, // Private S3 Parameter "s3_bucket" => $api_keys['MODELSLAB_S3_BUCKET'], "s3_key" => $api_keys['AWS_ACCESS_KEY_ID'], "s3_secret" => $api_keys['AWS_SECRET_ACCESS_KEY'] ]; write_abschnitte_log_unique('INFO', "[RSS-CRAWLER] 📦 Private S3 API-Aufruf mit eigenen Credentials"); $response = wp_remote_post('https://modelslab.com/api/v1/enterprise/flux/text2img', [ 'headers' => [ 'Content-Type' => 'application/json', 'User-Agent' => 'WordPress/' . get_bloginfo('version'), 'Accept' => 'application/json' ], 'body' => json_encode($payload), 'timeout' => 120, 'sslverify' => false ]); if (is_wp_error($response)) { write_abschnitte_log_unique('ERROR', "[RSS-CRAWLER] Private S3 API Fehler: " . $response->get_error_message()); return false; } $data = json_decode(wp_remote_retrieve_body($response), true); if (!$data || $data['status'] !== 'success' || empty($data['output'][0])) { write_abschnitte_log_unique('ERROR', "[RSS-CRAWLER] Private S3 API Response ungültig"); return false; } $private_url = $data['output'][0]; write_abschnitte_log_unique('SUCCESS', "[RSS-CRAWLER] ✅ Private S3 Bild generiert: " . $private_url); // Prüfen ob wirklich Private S3 URL if (strpos($private_url, $api_keys['MODELSLAB_S3_BUCKET']) !== false) { write_abschnitte_log_unique('SUCCESS', "[RSS-CRAWLER] ✅ Bestätigt: Private S3 URL mit eigenem Bucket"); } else { write_abschnitte_log_unique('WARNING', "[RSS-CRAWLER] ⚠️ Private S3 Request, aber Public URL erhalten"); } return $private_url; } // Private S3 Download (sollte immer funktionieren) function try_download_private_s3($image_url, $header_text) { require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); write_abschnitte_log_unique('INFO', "[RSS-CRAWLER] 🔒 Private S3 Download (sollte garantiert funktionieren)"); // Private S3 URLs sollten standard download_url() unterstützen $temp_file = download_url($image_url, 120); if (is_wp_error($temp_file)) { write_abschnitte_log_unique('ERROR', "[RSS-CRAWLER] Private S3 Download Fehler: " . $temp_file->get_error_message()); return false; } $file_array = [ 'name' => 'private_s3_' . time() . '_' . mt_rand(1000, 9999) . '.jpg', 'tmp_name' => $temp_file ]; $attach_id = media_handle_sideload($file_array, 0); if (is_wp_error($attach_id)) { unlink($temp_file); write_abschnitte_log_unique('ERROR', "[RSS-CRAWLER] Private S3 Media Handle Fehler: " . $attach_id->get_error_message()); return false; } // Meta-Daten setzen if ($header_text) { update_post_meta($attach_id, '_wp_attachment_image_alt', $header_text); wp_update_post(['ID' => $attach_id, 'post_title' => $header_text]); } update_post_meta($attach_id, '_rss_crawler_image', true); update_post_meta($attach_id, '_source_url', $image_url); update_post_meta($attach_id, '_private_s3', true); write_abschnitte_log_unique('SUCCESS', "[RSS-CRAWLER] ✅ Private S3 Download erfolgreich (ID: {$attach_id})"); return $attach_id; } // BULLETPROOF Bildverarbeitung (bereits vorhanden, aber optimiert) function process_image_data_bulletproof($image_data, $header_text, $image_url) { $temp_file = wp_tempnam('rss_image_bulletproof'); if (!$temp_file || file_put_contents($temp_file, $image_data) === false) { write_abschnitte_log_unique('ERROR', '[RSS-CRAWLER] Temp-Datei konnte nicht erstellt werden'); return false; } $file_array = [ 'name' => 'rss_bulletproof_' . time() . '_' . mt_rand(10000, 99999) . '.jpg', 'tmp_name' => $temp_file ]; $attach_id = media_handle_sideload($file_array, 0); if (is_wp_error($attach_id)) { unlink($temp_file); write_abschnitte_log_unique('ERROR', '[RSS-CRAWLER] Media Handle Fehler: ' . $attach_id->get_error_message()); return false; } // Meta-Daten setzen if ($header_text) { update_post_meta($attach_id, '_wp_attachment_image_alt', $header_text); wp_update_post($attach_id, 'post_title', $header_text); } update_post_meta($attach_id, '_rss_crawler_image', true); update_post_meta($attach_id, '_source_url', $image_url); update_post_meta($attach_id, '_public_s3_fallback', true); write_abschnitte_log_unique('SUCCESS', '[RSS-CRAWLER] ✅ BULLETPROOF Bild erfolgreich (ID: ' . $attach_id . ')'); return $attach_id; }
Warning: Cannot modify header information - headers already sent by (output started at /var/customers/webs/Muhsin/muhsin.de/wp-content/plugins/bildimportabschnitte/bildimportabschnitte.php:1) in /var/customers/webs/Muhsin/muhsin.de/wp-includes/pluggable.php on line 1450

Warning: Cannot modify header information - headers already sent by (output started at /var/customers/webs/Muhsin/muhsin.de/wp-content/plugins/bildimportabschnitte/bildimportabschnitte.php:1) in /var/customers/webs/Muhsin/muhsin.de/wp-includes/pluggable.php on line 1453