<?php
/*
Plugin Name: Add Link Attribute
Plugin URI: http://guff.szub.net/add-link-attribute
Description: Insert HTML tag attributes into WP function-generated links (optionally, img tags as well).
Version: 0.3
Author: Kaf Oseo
Author URI: http://szub.net

Usage:
<?php add_link_attr('function', 'arguments', 'attribute(s)', imgtag); ?>

Examples: 
<?php add_link_attr('get_calendar', '2', 'target="content_frame" style="font-weight: bold;"'); ?>
<?php add_link_attr('get_linksbyname', 'Blogs, <li>, </li>, <br />, FALSE, name, TRUE', 'onclick="window.open(this.href,\'_blank\');return false;"'); ?>
<?php add_link_attr('the_content', 'Read on...', 'class="post-links"'); ?>
<?php add_link_attr('get_links_list', '', 'width="30" height="20"', TRUE); ?>

~Change log:
0.3 (27-Mar-2005)
Corrected handling of multiple PHP-function style arguments
(parameters); added array check in case arguments passed as 
an array by the user. 

0.2 (30-Jan-2005)
Added the 'imgtag' parameter to optionally pass image (img)
tag attributes.
*/

function add_link_attr($func=''$args=''$attr=''$imgtag=false) {

    
$tag = ($imgtag) ?  "<img " "<a ";
    
$tag_attr $tag $attr ' ';

    
$func_args = array();
    if(!
is_array($args)) {
        
$args_array preg_split('/[\,]+/',$args);
        foreach (
$args_array as $arg_array) {    
            
array_push($func_args$arg_array);
        }
    } else {
        
$func_args $args;
    }        

    if(
$func) {
        
$func_args array_map('trim'$func_args);

        
ob_start();
        
call_user_func_array($func$func_args);
        
$input = array(ob_get_contents());
        
ob_end_clean();

        foreach(
$input as $line) {
            
$output .= preg_replace("/$tag/"$tag_attr$line);
        }
        echo 
$output;
    }
}
?>