ich brauchte ein plugin das mir alle Bilder eines Artikels auf meinen webspace ladet ...
also nachdem ein Artikel gespost wird werden automatisch alle url Bilder auf den eigenen webspace geladen und die URL im Text anpasst ...
ich hoffe es kann mir jemand helfen
Bild Posting ...
-
-
- Gerade eben
- Anzeige
Hallo!
Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.
- ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
- ✔️ Deutsche Server & DSGVO-konform
- ✔️ Persönlicher Support (kein 0815-Ticket-System)
-
Ich benutze Photopress! Damit kanns du beim Beitrag schreiben Bilder hochladen und die Bild-urls werden auch angepasst!
-
nettes plgu in aber leider macht es nicht das was ich suche ...
-
Zitat von jadmanx
ich brauchte ein plugin das mir alle Bilder eines Artikels auf meinen webspace ladet ...
also nachdem ein Artikel gespost wird werden automatisch alle url Bilder auf den eigenen webspace geladen und die URL im Text anpasst ...
ich hoffe es kann mir jemand helfenMhm, hört sich nach einem Plünder-Plugin an, daß fremde Bilder grabbelt. Oder täusche ich mich da?
-
ja hört sich so an ist aber nicht der Fall...
ich weis schon was Copyright ist ...
wollte nur wissen ob es so was gibt da ich mir sonst jemand suchen muss der mir so was programmiert...
ich nutze das performancing Erweiterung im FireFox zum Beiträge Posten aber leider unterstützt es den bild upload nicht...deswegen suche ich so eine Erweiterung ...
also Programmierer bitte melden zahle gut ... -
Ok, in Zukunft sollte ich die Beiträge mal genauer lesen!
-
Hi.
Wenn du mir eine Auflistung der Anforderungen und Systemdaten per PM schickst mit einer Preisvorstellung, schau ich mir das mal in einer freien Minute an.
Interesse besteht meinerseits.
-
Zitat von jadmanx
ich nutze das performancing Erweiterung im FireFox zum Beiträge Posten aber leider unterstützt es den bild upload nicht...Werfe doch mal einen Blick auf BlogDesk, das erfüllt deine Wünsche in Bezug auf den automatischen Bilder-Upload. In der aktuellen Beta kann der neue ImageWizard sogar automatisch Thumbnails erstellen. Und noch einige andere Sachen mehr.
-
nach langem suchen habe ich ein script gefunden das das ungefähr macht was ich suche .... http://lr2.com/plugins/lr2imagesnag/
wenn man einen Beitrag schreibt sucht es in der ersten Zeile nach einer pic url
und speichert dann das Bild auf dem eigenen Server und konvertiert es...
nun Brauch ich zwei Modifikationen
einmal das das Bild in zwei Versionen abgespeichert wird also groß und klein und wenn man auf das kleine Bild im Beitrag klickt wird es in voller Größe angezeigt...
die zweite Modifikation soll den Dateinamen der Bilder optimieren(google).
im Script werden jetzt Bilder in zahlenformat abgespeichert...
wenn z.b. die url so aussieht
http://www.mypicture.com/pic.jpg?schnecke.jpg
soll er das bild pic.jpg als schnecke.jpg abspeichern...
z.b. schnecke_mini.jpg für das kleine bild und schnecke.jpg für das Gosse bild... -
ach ja es gibt geld für die anpassung *fg :D
-
2. Aufgabe erfüllt.
Hier das modifizierte PlugIn
(1. Aufgabe wird demnächst umgesetzt)Mit der Angabe "http://www.mypicture.com/pic.jpg:schnecke" wird das Bild nun in "schnecke" umbenannt.
Erlaubte Zeichen für den Namen sind 0-9, a-z, A-Z sowie "-" und "_"PHP
Alles anzeigen<?php /* Plugin Name: lr2ImageSnag Plugin URI: http://lr2.com/plugins/lr2ImageSnag/ Description: Snags an image from the web and adds it to the text when posting. Instructions: Paste the URL of an image (not image tag) on the first line of the content. Submit as normal and the plugin will do the rest. Author: Anton Olsen, Jens Lojek Author URI: http://anton.lr2.com/ Version: 0.3.1 JLo: Update 2006-02-09 : simple modification to rename the images using:http://mydomain.tld/image.png:the_new_image_name to rename the image in the_new_image_name.png (allowed are '0-9', 'a-z', 'A-Z' and '_' and '-' */ $lr2CONFIG['snag'] = true; // Indicate snag is installed if other lr2 plugins care. $lr2CONFIG['snag_log'] = true; // Log things to the error_log. $lr2CONFIG['snag_tmp'] = '/tmp/'; // Directory to put curled files. *Writable by webserver. $lr2CONFIG['snag_path'] = '/imageSnag/'; // Directory to put images relative to wordpress dir. *Writable by webserver. // I haven't found an easy way to get the dir that WP is installed in, so we'll create it from what we do know. $lr2CONFIG['snag_siteurl'] = get_settings('siteurl'); // http://blog.addr/path/to/imageSnag/ $lr2CONFIG['snag_snagurl'] = $lr2CONFIG['snag_siteurl'].$lr2CONFIG['snag_path']; // /path/to/document/root/[blogdir/]imageSnag/ $lr2CONFIG['snag_dir'] = $_SERVER['DOCUMENT_ROOT'].preg_replace( '/[^\/]*\/\/[^\/]*/','',$lr2CONFIG['snag_siteurl']).$lr2CONFIG['snag_path']; function lr2ImageSnag_log( $string ) { global $lr2CONFIG; if ($lr2CONFIG['snag_log']) { error_log('imageSnag: '.$string); } } // given an url, go fetch it and put it in the temp directory. // function lr2ImageSnag_get( $url ) { global $lr2CONFIG; $tmpFile = $lr2CONFIG['snag_tmp'].uniqid('imageSnag'); // -e "url" sends a referer header pointing at the same URL. // This is usually enough to satisfy the anti-hotlink mod_rewrites. // -sS supresses nomal output (-s), but shows errors (-S). $command = 'curl -sS -o '.$tmpFile.' -e "'.$url.'" "'.$url.'"'; exec( $command, $output, $return ); // Show the errors in the error_log for anyone who cares. if (count($output)) { lr2ImageSnag_log(implode("\n", $output)); } // Easy test to see if curl suceeded. if (file_exists($tmpFile)) { return $tmpFile; } else { lr2ImageSnag_log('Error fetching the image: '.$url); return false; } } // given a tempfile, and a post id, convert the fetched image into the inageSnag dir. // //function lr2ImageSnag_convert( $tmpFile, $post_ID ) function lr2ImageSnag_convert( $tmpFile, $image_name ) { global $lr2CONFIG; global $_SERVER; // should be something like /path/to/document/root/[path_to_wp/]imageSnag/123.png //$newFile = $lr2CONFIG['snag_dir'].$post_ID.'.png'; $newFile = $lr2CONFIG['snag_dir'].$image_name.'.png'; // Scale the image to a max of 100x100 and use only the first frame if it's animated. $command = 'convert -scale 100x100 '.$tmpFile.'[0] '.$newFile; exec( $command ); unlink($tmpFile); // Simple check to see if convert suceeded. if (file_exists($newFile)) { return $newFile; } else { lr2ImageSnag_log('Error converting the image: '.$command); return false; } } // Where it all starts. // function lr2ImageSnag($post_ID) { global $lr2CONFIG; global $_SERVER; global $_POST; global $wpdb, $tableposts; lr2ImageSnag_log('Starting imageSnag for '.$post_ID); // Error handling, make sure we'll be able to write files before continuing. if (!is_writable($lr2CONFIG['snag_tmp'])) { lr2ImageSnag_log('Temp dir is not writable: '.$lr2CONFIG['snag_tmp']); return false; } if (!is_writable($lr2CONFIG['snag_dir'])) { lr2ImageSnag_log('Snag dir is not writable: '.$lr2CONFIG['snag_dir']); return false; } // We should have a post_ID handed to us, if not, try to find it. if (!$post_ID) { // Try the one posted by the form. $post_ID = $_POST['post_ID']; } // Grab the first line from the content. $content = $wpdb->get_var("SELECT post_content FROM $tableposts WHERE id = $post_ID"); list($line) = explode("\r", $content); if (!$line) { // didn't get anything splitting on \r, try \n instead. list($line) = explode("\n", $content); } // Look to see if the first line is an URL. if (ereg('^http://(.+)$', $line, $regs)) { //JLo Jens Lojek jl@code-in-design.de if(ereg('^http://(.+):([0-9a-zA-Z\_\-]*)', $line, $regs)){ $url = 'http://' . $regs[1]; $image_name = $regs[2]; }else{ $url = $line; $image_name = $post_ID; } //end JLo // Get the image using curl. if ($tmpFile = lr2ImageSnag_get( $url )) { // Convert the file to the thumbnail. //if ($newurl = lr2ImageSnag_convert( $tmpFile, $post_ID )) if ($newurl = lr2ImageSnag_convert( $tmpFile, $image_name )) { $imageurl = $lr2CONFIG['snag_snagurl'].$image_name.'.png'; $image = '<img src="'.$imageurl.'" style="'.$lr2CONFIG['snag_style'].'" class="lr2ImageSnag">'; //$content = ereg_replace( $url, $image, $content ); $content = ereg_replace( $line, $image, $content ); $sql = 'UPDATE '.$tableposts.' SET post_content=\''.ereg_replace("'", "''", $content).'\' WHERE id='.$post_ID; $result = $wpdb->query($sql); } } } else { lr2ImageSnag_log('First line is not an URL.'); } lr2ImageSnag_log('lr2ImageSnag: done.'); } function lr2ImageSnag_checkdir() { global $lr2CONFIG; // Check to see if the dirs are there and try to create them if they aren't. if (!is_dir($lr2CONFIG['snag_tmp'])) { mkdir( $lr2CONFIG['snag_tmp'], 0777, 1 ); } if (!is_dir($lr2CONFIG['snag_dir'])) { mkdir( $lr2CONFIG['snag_dir'], 0777, 1 ); } // Now check to see if all the dirs exist and we can use them. $error = array(); if (!is_dir($lr2CONFIG['snag_tmp'])) { $error[] = '<li>Temp dir does not exist: '.$lr2CONFIG['snag_tmp'].'</li>'; } if (!is_writable($lr2CONFIG['snag_tmp'])) { $error[] = '<li>Temp dir is not writable by the web server: '.$lr2CONFIG['snag_tmp'].'</li>'; } if (!is_dir($lr2CONFIG['snag_dir'])) { $error[] = '<li>Snag dir does not exist: '.$lr2CONFIG['snag_dir'].'</li>'; } if (!is_writable($lr2CONFIG['snag_dir'])) { $error[] = '<li>Snag dir is not writable by the web server: '.$lr2CONFIG['snag_dir'].'</li>'; } // Do curl and convert exist? $command = 'which curl 2>/dev/null'; exec($command, $output); if (count($output)<1) { $error[] = '<li>Unable to find curl command. Please install <a href="http://curl.haxx.se/">curl</a>.</li>'; } $command = 'which convert 2>/dev/null'; exec($command, $output); if (count($output)<1) { $error[] = '<li>Unable to find convert command. Please install <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a>.</li>'; } $output = array(); $output[] = '<fieldset>'; $output[] = '<legend><a href="http://lr2.com/pluginis/lr2ImageSnag/">lr2ImageSnag</a></legend>'; $output[] = '<div style="margin: 5px; padding: 2px;">'; $output[] = 'The lr2ImageSnag plugin is active.<br />'; if (count($error)) { $output[] = 'The following problems were encountered:<br />'; $output[] = '<ul>'.implode('', $error).'</ul>'; } else { $output[] = 'Paste an image url as the first line of the post to create a thumbnail in your post.'; } $output[] = '</div>'; $output[] = '</fieldset>'; echo implode("\n", $output); } // TODO Move the style into the options table when we get an lr2 plugin admin page. function lr2ImageSnag_style() { global $lr2CONFIG; echo "\n<style type=\"text/css\" media=\"screen\">\n"; echo ".lr2ImageSnag { margin: 5px; float:right; }\n"; echo "</style>\n"; global $_REQUEST; if ($_REQUEST['popupurl'] && $_REQUEST['content']) { $_REQUEST['content'] = "\n\n\n<blockquote>\n".$_REQUEST['content']."\n</blockquote>\n"; } } add_action('wp_head', 'lr2ImageSnag_style'); add_action('edit_form_advanced', 'lr2ImageSnag_checkdir'); add_action('simple_edit_form', 'lr2ImageSnag_checkdir'); add_action('edit_post', 'lr2ImageSnag'); add_action('save_post', 'lr2ImageSnag'); ?>PS: Da es nur ne simple und schnelle Anpassung war, ist das gratis*. :D
-
1.Aufgabe hab ich aktuell anders umgesetzt:
Das Link wird mit dem Orginalbild verlinkt.
Morgen werd ich das aber umbauen, so dass es 2 bilder auf dem server abspeichert und nur diese verwendet.PHP
Alles anzeigen<?php /* Plugin Name: lr2ImageSnag Plugin URI: http://lr2.com/plugins/lr2ImageSnag/ Description: Snags an image from the web and adds it to the text when posting. Instructions: Paste the URL of an image (not image tag) on the first line of the content. Submit as normal and the plugin will do the rest. Author: Anton Olsen, Jens Lojek Author URI: http://anton.lr2.com/ Version: 0.3.2 JLo: Update 2006-02-09 : simple modification to rename the images using:http://mydomain.tld/image.png:the_new_image_name to rename the image in the_new_image_name.png (allowed are '0-9', 'a-z', 'A-Z' and '_' and '-' Also implemented: the image tag becomes an link to the origin url (optional) */ $lr2CONFIG['snag'] = true; // Indicate snag is installed if other lr2 plugins care. $lr2CONFIG['snag_log'] = true; // Log things to the error_log. $lr2CONFIG['snag_tmp'] = '/tmp/'; // Directory to put curled files. *Writable by webserver. $lr2CONFIG['snag_path'] = '/imageSnag/'; // Directory to put images relative to wordpress dir. *Writable by webserver. $lr2CONFIG['snag_add_link'] = true; // If true, the image will be linked to the origin url in a new browser by click on the image // I haven't found an easy way to get the dir that WP is installed in, so we'll create it from what we do know. $lr2CONFIG['snag_siteurl'] = get_settings('siteurl'); // http://blog.addr/path/to/imageSnag/ $lr2CONFIG['snag_snagurl'] = $lr2CONFIG['snag_siteurl'].$lr2CONFIG['snag_path']; // /path/to/document/root/[blogdir/]imageSnag/ $lr2CONFIG['snag_dir'] = $_SERVER['DOCUMENT_ROOT'].preg_replace( '/[^\/]*\/\/[^\/]*/','',$lr2CONFIG['snag_siteurl']).$lr2CONFIG['snag_path']; function lr2ImageSnag_log( $string ) { global $lr2CONFIG; if ($lr2CONFIG['snag_log']) { error_log('imageSnag: '.$string); } } // given an url, go fetch it and put it in the temp directory. // function lr2ImageSnag_get( $url ) { global $lr2CONFIG; $tmpFile = $lr2CONFIG['snag_tmp'].uniqid('imageSnag'); // -e "url" sends a referer header pointing at the same URL. // This is usually enough to satisfy the anti-hotlink mod_rewrites. // -sS supresses nomal output (-s), but shows errors (-S). $command = 'curl -sS -o '.$tmpFile.' -e "'.$url.'" "'.$url.'"'; exec( $command, $output, $return ); // Show the errors in the error_log for anyone who cares. if (count($output)) { lr2ImageSnag_log(implode("\n", $output)); } // Easy test to see if curl suceeded. if (file_exists($tmpFile)) { return $tmpFile; } else { lr2ImageSnag_log('Error fetching the image: '.$url); return false; } } // given a tempfile, and a post id, convert the fetched image into the inageSnag dir. // //function lr2ImageSnag_convert( $tmpFile, $post_ID ) function lr2ImageSnag_convert( $tmpFile, $image_name ) { global $lr2CONFIG; global $_SERVER; // should be something like /path/to/document/root/[path_to_wp/]imageSnag/123.png //$newFile = $lr2CONFIG['snag_dir'].$post_ID.'.png'; $newFile = $lr2CONFIG['snag_dir'].$image_name.'.png'; // Scale the image to a max of 100x100 and use only the first frame if it's animated. $command = 'convert -scale 100x100 '.$tmpFile.'[0] '.$newFile; exec( $command ); unlink($tmpFile); // Simple check to see if convert suceeded. if (file_exists($newFile)) { return $newFile; } else { lr2ImageSnag_log('Error converting the image: '.$command); return false; } } // Where it all starts. // function lr2ImageSnag($post_ID) { global $lr2CONFIG; global $_SERVER; global $_POST; global $wpdb, $tableposts; lr2ImageSnag_log('Starting imageSnag for '.$post_ID); // Error handling, make sure we'll be able to write files before continuing. if (!is_writable($lr2CONFIG['snag_tmp'])) { lr2ImageSnag_log('Temp dir is not writable: '.$lr2CONFIG['snag_tmp']); return false; } if (!is_writable($lr2CONFIG['snag_dir'])) { lr2ImageSnag_log('Snag dir is not writable: '.$lr2CONFIG['snag_dir']); return false; } // We should have a post_ID handed to us, if not, try to find it. if (!$post_ID) { // Try the one posted by the form. $post_ID = $_POST['post_ID']; } // Grab the first line from the content. $content = $wpdb->get_var("SELECT post_content FROM $tableposts WHERE id = $post_ID"); list($line) = explode("\r", $content); if (!$line) { // didn't get anything splitting on \r, try \n instead. list($line) = explode("\n", $content); } // Look to see if the first line is an URL. if (ereg('^http://(.+)$', $line, $regs)) { //JLo Jens Lojek jl@code-in-design.de if(ereg('^http://(.+):([0-9a-zA-Z\_\-]*)', $line, $regs)){ $url = 'http://' . $regs[1]; $image_name = $regs[2]; }else{ $url = $line; $image_name = $post_ID; } //end JLo // Get the image using curl. if ($tmpFile = lr2ImageSnag_get( $url )) { // Convert the file to the thumbnail. //if ($newurl = lr2ImageSnag_convert( $tmpFile, $post_ID )) if ($newurl = lr2ImageSnag_convert( $tmpFile, $image_name )) { $imageurl = $lr2CONFIG['snag_snagurl'].$image_name.'.png'; $image = '<img src="'.$imageurl.'" style="'.$lr2CONFIG['snag_style'].'" class="lr2ImageSnag">'; //JLo if($lr2CONFIG['snag_add_link']){ $image = '<a href="'.$url.'" target="_blank" title="click for original image" class="lr2ImageSnag">'.$image.'</a>'; } //$content = ereg_replace( $url, $image, $content ); $content = ereg_replace( $line, $image, $content ); $sql = 'UPDATE '.$tableposts.' SET post_content=\''.ereg_replace("'", "''", $content).'\' WHERE id='.$post_ID; $result = $wpdb->query($sql); } } } else { lr2ImageSnag_log('First line is not an URL.'); } lr2ImageSnag_log('lr2ImageSnag: done.'); } function lr2ImageSnag_checkdir() { global $lr2CONFIG; // Check to see if the dirs are there and try to create them if they aren't. if (!is_dir($lr2CONFIG['snag_tmp'])) { mkdir( $lr2CONFIG['snag_tmp'], 0777, 1 ); } if (!is_dir($lr2CONFIG['snag_dir'])) { mkdir( $lr2CONFIG['snag_dir'], 0777, 1 ); } // Now check to see if all the dirs exist and we can use them. $error = array(); if (!is_dir($lr2CONFIG['snag_tmp'])) { $error[] = '<li>Temp dir does not exist: '.$lr2CONFIG['snag_tmp'].'</li>'; } if (!is_writable($lr2CONFIG['snag_tmp'])) { $error[] = '<li>Temp dir is not writable by the web server: '.$lr2CONFIG['snag_tmp'].'</li>'; } if (!is_dir($lr2CONFIG['snag_dir'])) { $error[] = '<li>Snag dir does not exist: '.$lr2CONFIG['snag_dir'].'</li>'; } if (!is_writable($lr2CONFIG['snag_dir'])) { $error[] = '<li>Snag dir is not writable by the web server: '.$lr2CONFIG['snag_dir'].'</li>'; } // Do curl and convert exist? $command = 'which curl 2>/dev/null'; exec($command, $output); if (count($output)<1) { $error[] = '<li>Unable to find curl command. Please install <a href="http://curl.haxx.se/">curl</a>.</li>'; } $command = 'which convert 2>/dev/null'; exec($command, $output); if (count($output)<1) { $error[] = '<li>Unable to find convert command. Please install <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a>.</li>'; } $output = array(); $output[] = '<fieldset>'; $output[] = '<legend><a href="http://lr2.com/pluginis/lr2ImageSnag/">lr2ImageSnag</a></legend>'; $output[] = '<div style="margin: 5px; padding: 2px;">'; $output[] = 'The lr2ImageSnag plugin is active.<br />'; if (count($error)) { $output[] = 'The following problems were encountered:<br />'; $output[] = '<ul>'.implode('', $error).'</ul>'; } else { $output[] = 'Paste an image url as the first line of the post to create a thumbnail in your post.'; } $output[] = '</div>'; $output[] = '</fieldset>'; echo implode("\n", $output); } // TODO Move the style into the options table when we get an lr2 plugin admin page. function lr2ImageSnag_style() { global $lr2CONFIG; echo "\n<style type=\"text/css\" media=\"screen\">\n"; echo ".lr2ImageSnag { margin: 5px; float:right; }\n"; echo "</style>\n"; global $_REQUEST; if ($_REQUEST['popupurl'] && $_REQUEST['content']) { $_REQUEST['content'] = "\n\n\n<blockquote>\n".$_REQUEST['content']."\n</blockquote>\n"; } } add_action('wp_head', 'lr2ImageSnag_style'); add_action('edit_form_advanced', 'lr2ImageSnag_checkdir'); add_action('simple_edit_form', 'lr2ImageSnag_checkdir'); add_action('edit_post', 'lr2ImageSnag'); add_action('save_post', 'lr2ImageSnag'); ?> -
danke aber geht leider nicht ...
Warning: Cannot modify header information - headers already sent by (output started at wp-content/plugins/lr2ImageSnag.php:270) in wp-admin/plugins.php on line 16
-
beim copy&paste aus dem fenster hier is am ende ein leerzeichen.
Entferne das einfach und es geht.Zeile 270 im Script hinterm "?>"
-
funktioniert schon super :-)
nur ist der text jetzt nicht mehr neben dem bild sondern darunter...
http://www.jacko.blubbs.com/ -
Dann musst du in der CSS-Klasse "lr2ImageSnag" im styles.css festlegen, das es links-bündig sein soll.
Dir sind durch das CSS alles Möglichkeiten offen. -
sooo nun speichert er das Orginal auch ab und verlinkt es optional.
Wichtig:
"true" = Thumbnail wird verlinkt mit grossem Orginalbild oder Quellseite.
"true" = Orginalbild wird in voller grösse auf webspace kopiert.
Wenn snag_add_link true ist, wird das thumbnail mit diesem lokalen Bild verlinkt.
Bei "true" wird das kleine Bild mit der Endung "_tn.png" und das grosse nur mit ".png" abgespeichert. Wenn "false" wird nur das kleine mit Endung ".png" abgespeichert.Einen neuen Namen für das Bild kann man wie auch vorher mit ":neuer_name" hinter der URL angeben.
Test it! Alles auf eigene Gefahr. Ich gehe davon aus, das Benutzer dieses PlugIns die Copyrights der jeweiligen Urheber schützen und beachten.
PS: Beim copy&paste des Quellcodes darauf achten, das hinterm "?>" kein Zeichen/Leerzeichen mehr kommt, sonst gibts nen "Header output" Fehler in Zeile:284
(Quellcode im nächsten Post da max. Zeichenanzahl überschitten. ;) )
-
PHP
Alles anzeigen<?php /* Plugin Name: lr2ImageSnag Plugin URI: http://lr2.com/plugins/lr2ImageSnag/ Description: Snags an image from the web and adds it to the text when posting. Instructions: Paste the URL of an image (not image tag) on the first line of the content. Submit as normal and the plugin will do the rest. Author: Anton Olsen, Jens Lojek Author URI: http://anton.lr2.com/ Version: 0.3.3 JLo: Update 2006-02-20 : simple modification to rename the images using:http://mydomain.tld/image.png:the_new_image_name to rename the image in the_new_image_name.png (allowed are '0-9', 'a-z', 'A-Z' and '_' and '-' Also implemented: the image tag becomes an link to the origin url (optional) */ $lr2CONFIG['snag'] = true; // Indicate snag is installed if other lr2 plugins care. $lr2CONFIG['snag_log'] = true; // Log things to the error_log. $lr2CONFIG['snag_tmp'] = '/tmp/'; // Directory to put curled files. *Writable by webserver. $lr2CONFIG['snag_path'] = '/imageSnag/'; // Directory to put images relative to wordpress dir. *Writable by webserver. $lr2CONFIG['snag_add_link'] = true; // If true, the image will be linked to the origin url in a new browser by click on the image $lr2CONFIG['snag_link2full_img'] = true; // If true, the image will be linked to the origin image located in same directoy like the thumb // I haven't found an easy way to get the dir that WP is installed in, so we'll create it from what we do know. $lr2CONFIG['snag_siteurl'] = get_settings('siteurl'); // http://blog.addr/path/to/imageSnag/ $lr2CONFIG['snag_snagurl'] = $lr2CONFIG['snag_siteurl'].$lr2CONFIG['snag_path']; // /path/to/document/root/[blogdir/]imageSnag/ $lr2CONFIG['snag_dir'] = $_SERVER['DOCUMENT_ROOT'].preg_replace( '/[^\/]*\/\/[^\/]*/','',$lr2CONFIG['snag_siteurl']).$lr2CONFIG['snag_path']; function lr2ImageSnag_log( $string ) { global $lr2CONFIG; if ($lr2CONFIG['snag_log']) { error_log('imageSnag: '.$string); } } // given an url, go fetch it and put it in the temp directory. // function lr2ImageSnag_get( $url ) { global $lr2CONFIG; $tmpFile = $lr2CONFIG['snag_tmp'].uniqid('imageSnag'); // -e "url" sends a referer header pointing at the same URL. // This is usually enough to satisfy the anti-hotlink mod_rewrites. // -sS supresses nomal output (-s), but shows errors (-S). $command = 'curl -sS -o '.$tmpFile.' -e "'.$url.'" "'.$url.'"'; exec( $command, $output, $return ); // Show the errors in the error_log for anyone who cares. if (count($output)) { lr2ImageSnag_log(implode("\n", $output)); } // Easy test to see if curl suceeded. if (file_exists($tmpFile)) { return $tmpFile; } else { lr2ImageSnag_log('Error fetching the image: '.$url); return false; } } // given a tempfile, and a post id, convert the fetched image into the inageSnag dir. // //function lr2ImageSnag_convert( $tmpFile, $post_ID ) function lr2ImageSnag_convert( $tmpFile, $image_name ) { global $lr2CONFIG; global $_SERVER; // should be something like /path/to/document/root/[path_to_wp/]imageSnag/123.png //$newFile = $lr2CONFIG['snag_dir'].$post_ID.'.png'; if($lr2CONFIG['snag_link2full_img']){ $newFile = $lr2CONFIG['snag_dir'].$image_name.'_tn.png'; $fullFile = $lr2CONFIG['snag_dir'].$image_name.'.png'; }else{ $newFile = $lr2CONFIG['snag_dir'].$image_name.'.png'; } // Scale the image to a max of 100x100 and use only the first frame if it's animated. $command = 'convert -scale 100x100 '.$tmpFile.'[0] '.$newFile; exec( $command ); if($lr2CONFIG['snag_link2full_img']){ $command = 'cp '.$tmpFile.' '.$fullFile; exec( $command ); } unlink($tmpFile); // Simple check to see if convert suceeded. if (file_exists($newFile)) { return $newFile; } else { lr2ImageSnag_log('Error converting the image: '.$command); return false; } } // Where it all starts. // function lr2ImageSnag($post_ID) { global $lr2CONFIG; global $_SERVER; global $_POST; global $wpdb, $tableposts; lr2ImageSnag_log('Starting imageSnag for '.$post_ID); // Error handling, make sure we'll be able to write files before continuing. if (!is_writable($lr2CONFIG['snag_tmp'])) { lr2ImageSnag_log('Temp dir is not writable: '.$lr2CONFIG['snag_tmp']); return false; } if (!is_writable($lr2CONFIG['snag_dir'])) { lr2ImageSnag_log('Snag dir is not writable: '.$lr2CONFIG['snag_dir']); return false; } // We should have a post_ID handed to us, if not, try to find it. if (!$post_ID) { // Try the one posted by the form. $post_ID = $_POST['post_ID']; } // Grab the first line from the content. $content = $wpdb->get_var("SELECT post_content FROM $tableposts WHERE id = $post_ID"); list($line) = explode("\r", $content); if (!$line) { // didn't get anything splitting on \r, try \n instead. list($line) = explode("\n", $content); } // Look to see if the first line is an URL. if (ereg('^http://(.+)$', $line, $regs)) { //JLo Jens Lojek jl@code-in-design.de if(ereg('^http://(.+):([0-9a-zA-Z\_\-]*)', $line, $regs)){ $url = 'http://' . $regs[1]; $image_name = $regs[2]; }else{ $url = $line; $image_name = $post_ID; } //end JLo // Get the image using curl. if ($tmpFile = lr2ImageSnag_get( $url )) { // Convert the file to the thumbnail. //if ($newurl = lr2ImageSnag_convert( $tmpFile, $post_ID )) if ($newurl = lr2ImageSnag_convert( $tmpFile, $image_name )){ if($lr2CONFIG['snag_link2full_img']){ $imageurl = $lr2CONFIG['snag_snagurl'].$image_name.'_tn.png'; //thumbnail url $url = $lr2CONFIG['snag_snagurl'].$image_name.'.png'; //url to full image local }else{ $imageurl = $lr2CONFIG['snag_snagurl'].$image_name.'.png'; } $image = '<img src="'.$imageurl.'" style="'.$lr2CONFIG['snag_style'].'" class="lr2ImageSnag">'; if($lr2CONFIG['snag_add_link']){ $image = '<a href="'.$url.'" target="_blank" title="click for original image" class="lr2ImageSnag">'.$image.'</a>'; } //$content = ereg_replace( $url, $image, $content ); $content = ereg_replace( $line, $image, $content ); $sql = 'UPDATE '.$tableposts.' SET post_content=\''.ereg_replace("'", "''", $content).'\' WHERE id='.$post_ID; $result = $wpdb->query($sql); } } } else { lr2ImageSnag_log('First line is not an URL.'); } lr2ImageSnag_log('lr2ImageSnag: done.'); } function lr2ImageSnag_checkdir() { global $lr2CONFIG; // Check to see if the dirs are there and try to create them if they aren't. if (!is_dir($lr2CONFIG['snag_tmp'])) { mkdir( $lr2CONFIG['snag_tmp'], 0777, 1 ); } if (!is_dir($lr2CONFIG['snag_dir'])) { mkdir( $lr2CONFIG['snag_dir'], 0777, 1 ); } // Now check to see if all the dirs exist and we can use them. $error = array(); if (!is_dir($lr2CONFIG['snag_tmp'])) { $error[] = '<li>Temp dir does not exist: '.$lr2CONFIG['snag_tmp'].'</li>'; } if (!is_writable($lr2CONFIG['snag_tmp'])) { $error[] = '<li>Temp dir is not writable by the web server: '.$lr2CONFIG['snag_tmp'].'</li>'; } if (!is_dir($lr2CONFIG['snag_dir'])) { $error[] = '<li>Snag dir does not exist: '.$lr2CONFIG['snag_dir'].'</li>'; } if (!is_writable($lr2CONFIG['snag_dir'])) { $error[] = '<li>Snag dir is not writable by the web server: '.$lr2CONFIG['snag_dir'].'</li>'; } // Do curl and convert exist? $command = 'which curl 2>/dev/null'; exec($command, $output); if (count($output)<1) { $error[] = '<li>Unable to find curl command. Please install <a href="http://curl.haxx.se/">curl</a>.</li>'; } $command = 'which convert 2>/dev/null'; exec($command, $output); if (count($output)<1) { $error[] = '<li>Unable to find convert command. Please install <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a>.</li>'; } $output = array(); $output[] = '<fieldset>'; $output[] = '<legend><a href="http://lr2.com/pluginis/lr2ImageSnag/">lr2ImageSnag</a></legend>'; $output[] = '<div style="margin: 5px; padding: 2px;">'; $output[] = 'The lr2ImageSnag plugin is active.<br />'; if (count($error)) { $output[] = 'The following problems were encountered:<br />'; $output[] = '<ul>'.implode('', $error).'</ul>'; } else { $output[] = 'Paste an image url as the first line of the post to create a thumbnail in your post.'; } $output[] = '</div>'; $output[] = '</fieldset>'; echo implode("\n", $output); } // TODO Move the style into the options table when we get an lr2 plugin admin page. function lr2ImageSnag_style() { global $lr2CONFIG; echo "\n<style type=\"text/css\" media=\"screen\">\n"; echo ".lr2ImageSnag { margin: 5px; float:right; }\n"; echo "</style>\n"; global $_REQUEST; if ($_REQUEST['popupurl'] && $_REQUEST['content']) { $_REQUEST['content'] = "\n\n\n<blockquote>\n".$_REQUEST['content']."\n</blockquote>\n"; } } add_action('wp_head', 'lr2ImageSnag_style'); add_action('edit_form_advanced', 'lr2ImageSnag_checkdir'); add_action('simple_edit_form', 'lr2ImageSnag_checkdir'); add_action('edit_post', 'lr2ImageSnag'); add_action('save_post', 'lr2ImageSnag'); ?> -
jadmanx
Entspricht das so deinen Bedürfnissen?Nen Feedback wäre super.
-
WOW supie genau das habe ich gebraucht :D
danke danke danke !!!wieso sind das eigentlich png dateien ? geht das mit jpg auf ? oder ist das einfach nur der dateiname ?
wie hast du das gemeint mit dem CSS ?
was muss ich da in meine style css reinschreiben ?
Jetzt mitmachen!
Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!