Beiträge von LJay
-
-
Hi.
Als Entwickler von ML Multilingual würde mich interessieren, was euch an diesem PlugIn noch nicht gefällt.
Ohne Feedback, kann ich es nicht ggf. optimieren.
Für meine Zwecke ist es seit Version 0.9.5 ausreichend aber trotzdem ist es bereits bei 0.9.9 angelangt. -
Auflistung der posts geht nun geändert.
Wie kann man die der pages beeinflussen ohne Hack?push:
-
jadmanx
Entspricht das so deinen Bedürfnissen?Nen Feedback wäre super.
-
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'); ?> -
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. ;) )
-
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. -
Das kommt durch das kopieren des Quelltextes aus dem Forum.
Komischer Weise macht er am Ende des Quelltextes noch ein Leerzeichen ran.Das führt zu einer Ausgae im Browser und dann zum Fehler.
Einfach alle Leerzeichen am Ende der Scripte direkt nach("?>") entfernen.
Dann sollte das auch alles gehen.
Wegen der Comments. Ich muss gestehe; ich kann zwar schon PlugIns coden ;) aber das Theme bekomm ich nicht ordentlich zu laufen.
Comments sind überall on, nur auf der Startseite funzt das komischer Weise nicht.
Ruf ich die Startseite (ist mit StaticFrontPage PlugIn) mit "http://ml_multilingual.code-in-design.de/home/" auf, kann ich auch Kommentare posten... hmmKennt jemand Abhilfe oder Ursache?
-
Für das PlugIn hier suche ich noch ein paar Teste, die mir auf der PlugIn Website ein Feedback geben...
Bitte tragt dazu bei, das PlugIn zu optimieren! Wäre schade, wenn ich das wirklich nur, für mich programmiert hätte... -
beim copy&paste aus dem fenster hier is am ende ein leerzeichen.
Entferne das einfach und es geht.Zeile 270 im Script hinterm "?>"
-
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'); ?> -
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
-
hmmm muss ich dich erstmal vertrösten... dazu müsste ich mich auch erst reinlesen und ich will jetzt pennen... sry
Aber schau mal einfach in die DOC http://codex.wordpress.org/Main_Page
-
ich kann das grad nicht nachpüfen da die CODEX Site offline ist, aber ich bin der festen Meinung das du die Auflistung zwar leicht ändern kannst, aber ohne weiteres nicht nach Anzahl der Comments.
Ggf. geht das mit einem eigenem query im template, vor der Auflistung.
Sobald codex wieder online ist schau ich mal nach...
-
also egal ob mitoder ohne permalink, ab einer bestimmten "Zeit" Programstelle, steht dir die ID in des aktuellen Posts als Object zur Verfügung.
Allerdings musst du nun einen geeigneten Filter/Action finden...
Schreibst du das einfach so ins Script ohne Funktion, wird die Stelle zu früh vom Server aufgerufen und es existiert das Objekt "$post" noch nicht.Es wäre also ein Filter notwendig, der das aufruft am besten bevor noch der Text ausgegeben wird.
Da "CODEX" gerade mal wieder zur passenden Zeit (meist abends) offline ist, kann ich grad keinen filter suchen der geeignet ist.
-
wie "startet" dein PlguIn?
Was ist das erste was ausgeführt wird und wann/wo ?!
Über welchen Filter? -
ich hab da ne Funktion in meinem PlugIn, die hier ggf. weiterhelfen kann.
dauert kurz... -
ml_multilingual-v0.9.6
habe gerade ne neue Version online gestellt:
http://ml_multilingual.code-in-design.de/
latest version:ml_multilingual-v0.9.6.rar (17.859 Bytes)
* main changes to 0.9.2
o Bei ersten Besuch wird Sprache aus dem Browser ausgelesen und verwendet
o für Adminbereich und Frontend können verschiedene Sprachen ausgewählt werden
o Admin kann Sprache im Adminbereich nicht mehr ändern, wenn er nicht das nötige Level hat (vorher war es mit URL-Manipulation möglich)
o Bei Aufruf des Blogs mit einer ungültigen Spracheauswahl, wird die Default-Sprache benutzt
o Es werden überall nur posts aus der gewählten Kategorie und Unterkategorien angezeigt. (auch im Archiv)
o "flags" Ordner mit den Flaggen der Länder wurde in eigenen Unterordner gepackt sowie Auslagerung von 2 Scripten (liegt nun in /wp-content/plugins/ml_multilingual/)default_theme_for_ml_v0.9.6.rar (18.766 Bytes)
* default WP Theme - optimized for ML (dieses wird auch auf dieser Site benutzt)
* enthält entsprechenden ML Code um die Anzeigen an die Sprachen anzuzeigen.
* Erklärungen/Doku usw. folgt nach Fertigstellung der ersten Vollversion.
* Themeanpassungen sollen später weitestgehend unnötig gemacht werden, bisher aber erforderlich -
kann dies bestätigen.
Auf meinen Server mit PHP5 trat der fehler auch auf mit WP1.5.2 .Der o.g. php-code fixed das Problem wunderbar.
-
ins unreine gesprochen.. versuche beim auflisten/anzeigen eines post mit der post_ID das tracking zu bewerkstelligen.
Verlasse dich niemals auf post_name/nicenames, die sind nicht eindeutig.
Im Loop steht zu jedem angezeigten Post die ID zur Verfügung, die könnte man tracken und ggf. den Titel oder postname dazu ermitteln.WP wandelt intern (durch htaccess) ja jede permalink struktur in IDs um, also kann du genau dort ansetzen um den aktuellen post genau zuzuordnen.
PS: Das nicenames/post_names nicht unique sind, ist ein bekannter "Bug" in WP. Für WP2.x gibt es bereits einen BugFix. Konnte bisher noch nicht prüfen, ob er in der neuen WP2.0.1 auch enthalten ist.
Ich hoffe, ich konnte irgendwie weiterhelfen...