add_filter('Inhalt_vor_speichern', 'Bild_automatisch_speichern'); Funktion auto_save_image($content) { $upload_pfad = "; $upload_url_path = get_bloginfo('url'); //Upload-Verzeichnis wenn (($var = get_option('upload_path')) != "){ $uploadpfad = $var; } anders { $upload_pfad = "wp-content/uploads"; } if(get_option('uploads_use_yearmonth_folders')) { $upload_path .= '/'.date("Y",Zeit()).'/'.date("m",Zeit()); } //Dateiadresse wenn(($var = get_option('upload_url_path')) != '') { $upload_url_pfad = $var; } anders { $upload_url_path = bloginfo('url'); } if(get_option('uploads_use_yearmonth_folders')) { $upload_url_path .= '/'.date("Y",Zeit()).'/'.date("m",Zeit()); } require_once("../wp-includes/class-snoopy.php"); $snoopy_Auto_Save_Image = neuer Snoopy; $img = Array(); //Verwende den Titel des Artikels als Titel des Bildes wenn ( !empty( $_REQUEST['post_title'] ) ) $post_title = wp_specialchars(stripslashes( $_REQUEST['post_title'] )); $text = Streifen/Schrägstriche($inhalt); wenn (get_magic_quotes_gpc()) $text = stripslashes($text); preg_match_all(“/ src=("|'){0,}(http://(.+?))("|'|s)/ist”,$text,$img); $img = array_unique(dhtmlspecialchars($img[2])); foreach ($img als $Schlüssel => $Wert){ set_time_limit(180); //Die maximal zulässige Downloadzeit für jedes Bild in Sekunden wenn(str_replace(get_bloginfo('url'),"",$value)==$value&&str_replace(get_bloginfo('home'),"",$value)==$value){ // Beurteilen Sie, ob es sich um ein lokales Bild handelt. Wenn nicht, speichern Sie es auf dem Server. $fileext = substr(strrchr($wert,'.'),1); : $fileext = strtolower($fileext); wenn($fileext==""||strlen($fileext)>4) $fileext = "jpg"; $savefiletype = Array('jpg','gif','png','bmp'); wenn (in_array($fileext, $savefiletype)){ wenn($snoopy_Auto_Save_Image->fetch($value)){ $get_file = $snoopy_Auto_Save_Image->Ergebnisse; }anders{ echo "Fehler beim Abrufen der Datei: ".$snoopy_Auto_Save_Image->error.""; echo „Fehler-URL: „.$value; sterben(); } $filetime = Zeit(); $filepath = "/".$upload_path; //Pfadverzeichnis, in dem das Bild gespeichert ist !is_dir("..".$Dateipfad) ? mkdirs("..".$Dateipfad) : null; //$filename = date("Sein",$filetime).random(3); $Dateiname = substr($Wert,strrpos($Wert,'/'),strrpos($Wert,'.')-strrpos($Wert,'/')); //$e = '../'.$Dateipfad.$Dateiname.'.'.$fileext; //wenn(!ist_datei($e)) { // kopieren(htmlspecialchars_decode($value),$e); //} $fp = @fopen(".."$Dateipfad.$Dateiname."".$Dateierweiterung,"w"); @fwrite($fp,$get_file); fclose($fp); $wp_filetype = wp_check_filetype( $filename."".$fileext, false ); $typ = $wp_filetype['Typ']; $post_id = (int)$_POST['temp_ID2']; $title = $post_title; $url = $upload_url_pfad.$dateiname."".$fileext; $file = $_SERVER['DOCUMENT_ROOT'].$Dateipfad.$Dateiname."".$fileext; //Datenbankeintrag hinzufügen $Anhang = Array( 'post_type' => 'Anhang', 'post_mime_type' => $Typ, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $Titel, 'post_content' => ', ); : $id = wp_insert_attachment($attachment, $datei, $post_parent); $text = str_replace($value,$url,$text); //Ersetze die Bildadresse im Artikel } } } $Inhalt = AddSlashes($Text); Filter entfernen('Inhalt_vor_speichern', 'Bild_automatisch_speichern'); gib $content zurück; } Funktion mkdirs($dir) { if(!is_dir($dir)) { mkdirs(dirname($dir)); mkdir($dir); } zurückkehren ; } Funktion dhtmlspecialchars($string) { wenn(ist_array($string)) { foreach($string als $key => $val) { $string[$key] = dhtmlspecialchars($val); } }anders{ : $string = str_replace('&', '&', $string); : $string = str_replace('"', '"', $string); $string = str_replace(”, $string); $string = preg_replace('/&(#\d;)/', '&\1', $string); } gibt $string zurück; } Fügen Sie es einfach zur Datei functions.php des Themes oder zur Importdatei von functions.php hinzu. Wenn Sie einen Artikel in WordPress veröffentlichen und der Artikel externe Linkbilder enthält, wird er automatisch lokalisiert. Das ist sehr praktisch und erfordert keine Einstellungen. über: http://y-cy.cn/86.html |