<?php
/*
Plugin Name: Next-Previous Post IMG
Version: R1.1
Plugin URI: http://guff.szub.net/next-previous-post-img
Description: Use images for next/previous post links; has two function tags: next_post_img() and previous_post_img().
Author: Kaf Oseo
Author URI: http://szub.net
*/

/*
Copyright (c) 2005
Released under the GPL license
http://www.gnu.org/licenses/gpl.txt

    This is a WordPress plugin (http://wordpress.org).

    WordPress is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License,
    or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.

    For a copy of the GNU General Public License, write to:

    Free Software Foundation, Inc.
    59 Temple Place, Suite 330
    Boston, MA  02111-1307
    USA

    You can also view a copy of the HTML version of the GNU General
    Public License at http://www.gnu.org/copyleft/gpl.html
*/

function next_post_img($next_img=''$nonext_img=''$width=''$height=''$next='Next post: '$format='%'$title=true) {
    global 
$tableposts$posts_per_page$post$wpdb$single;
    if(
== $posts_per_page || == $single) {

        
$current_post_date $post->post_date;
        
$current_category $post->post_category;

        
$now current_time('mysql');

        
$sitepath get_settings('siteurl');
        if (
preg_match('%^http://%'$next_img)) {
            
$nextimage $next_img;
        } else {
            
$nextimage $sitepath.$next_img;
        }
        list(
$nextwidth$nextheight) = getimagesize($nextimage);
        if (empty(
$width)) {
            
$width $nextwidth;
        }
        if (empty(
$height)) {
            
$height $nextheight;
        }

        
$nextpost = @$wpdb->get_row("SELECT ID, post_title FROM $tableposts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' AND ID != $post->ID ORDER BY post_date ASC LIMIT 0,1");
        if (
$nextpost) {
            
$string '<a href="'.get_permalink($nextpost->ID).'">';
            if (
$title) {
                
$img_title wptexturize(stripslashes($nextpost->post_title));
            }
            if (empty(
$next_img)) {
                if (
$title) {
                    
$string .= $img_title;
                } else {
                    
$string .= $next;
                }
            } else {
                
$string .= '<img src="'.$next_img.'" width="'.$width.'" height="'.$height.'" alt="'.$next.$img_title.'" title="'.$next.$img_title.'" />';
            }
            
$string .= '</a>';
            
$format str_replace('%'$string$format);
        } else {
            
$format '<img src="';
            if (!empty(
$nonext_img)) {
                
$format .= $nonext_img;
            } else {
                
$format .= $next_img;
            }
            
$format .= '" width="'.$width.'" height="'.$height.'" alt="" title="" />';
        }
        echo 
$format;
    }
}

function 
previous_post_img($previous_img=''$noprevious_img=''$width=''$height=''$previous='Previous post: '$format='%'$title=true) {
    global 
$tableposts$posts_per_page$post$wpdb$single;
    if((
$p) || ($posts_per_page == 1) || == $single) {

        
$current_post_date $post->post_date;
        
$current_category $post->post_category;

        
$sitepath get_settings('siteurl');
        if (
preg_match('%^http://%'$previous_img)) {
            
$previousimage $previous_img;
        } else {
            
$previousimage $sitepath.$previous_img;
        }
        list(
$previouswidth$previousheight) = getimagesize($previousimage);
        if (empty(
$width)) {
            
$width $previouswidth;
        }
        if (empty(
$height)) {
            
$height $previousheight;
        }

        
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $tableposts WHERE post_date < '$current_post_date' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 0, 1");
        if (
$lastpost) {
            
$string '<a href="'.get_permalink($lastpost->ID).'">';
            if (
$title) {
                
$img_title wptexturize(stripslashes($lastpost->post_title));
            }
            if (empty(
$previous_img)) {
                if (
$title) {
                    
$string .= $img_title;
                } else {
                    
$string .= $previous;
                }
            } else {
                
$string .= '<img src="'.$previous_img.'" width="'.$width.'" height="'.$height.'" alt="'.$previous.$img_title.'" title="'.$previous.$img_title.'" />';
            }
            
$string .= '</a>';
            
$format str_replace('%'$string$format);
        } else {
            
$format '<img src="';
            if (!empty(
$noprevious_img)) {
                
$format .= $noprevious_img;
            } else {
                
$format .= $previous_img;
            }
            
$format .= '" width="'.$width.'" height="'.$height.'" alt="" title="" />';
        }
        echo 
$format;
    }
}
?>