User Tools

Site Tools


res:plugins:nowhereman:extendedimg

Usage

[img=myimg]
my caption
[/img]

all the conventional img attributes should work (scale=nn% etc.)

to link the image to an external resource do not wrap the [img][/img] into a [url][/url] but use instead the url attribute of the extended img tag :

[img=myimg.jpg url=http://example.com]
caption
[/img]

to customize behaviour define .floatright .floatleft .center in your CSS, here's an example

.floatleft
{
float:left;
padding-right:10px;
text-align:left;
}
 
.floatright
{
float:right;
padding-left:10px;
text-align:right;
}
 
.center {
text-align:center; 
}
 
.img-container {
font-size: small;
font-style:italic;
font-family: serif; 
}
 
.img-container p {
	margin-top: 0;
}
 

there is finally an align= attribute which forces the container to left|right|center align the text of the img container

have fun!

Code

<?php
/*
Plugin Name: Extended IMG tag
Version: 1.0
Plugin URI: http://wiki.flatpress.org
Description: Allows using extends [img] tag to allow the syntax [img=myimg] caption [/img] (requires BBCode plugin)
Author: NoWhereMan
Author URI: http://www.flatpress.org
*/
 
 
function plugin_extendedimg_callback($action, $attr, $content, $params, $node_object) {
    if ($action=='validate') {
		return true;
	}
 
	$float = 'center';
	if (@$attr['float']){
		$float = 'float'.$attr['float'];
		unset($attr['float']);
	}
 
	$align = '';
	if (@$attr['align']) {
		$align = ' style="text-align: '.$attr['align'] .'"';
	}
 
	$class = '';
	$url = '';
	if (@$attr['url']) {
		$attr['popup'] = false;
		$url = wp_specialchars($attr['url']) ;
		$class = strpos($url, ':/')!== false ? ' externlink': ' ';
	}
 
	$img = do_bbcode_img($action, $attr, $content, $params, null);
 
	if ($url)	$img = "<a href=\"$url\">$img</a>";
 
	return '<div class="img-container '.$float.$class.'" '.$align.'>' . "<p>$img</p>\n\n{$content}\n\n</div>";
 
}
 
function &plugin_extendedimg_init() {
 
	static $bbcode;
	if ($bbcode) return $bbcode;
 
	$bbcode = new StringParser_BBCode ();
 
	// If you set it to false the case-sensitive will be ignored for all codes
	$bbcode->setGlobalCaseSensitive (false);
	$bbcode->setMixedAttributeTypes(true);
 
   	$bbcode->addCode (
   				'img', 
   				'callback_replace', 
   				'plugin_extendedimg_callback',
   				array ('usecontent_param' => 
   					array ('default', 'float', 'alt', 
   					'popup', 'width', 'height', 'title')
   					),
   				'image', array ('block', 'inline'), 
   				array ());
   	$bbcode->setCodeFlag ('img', 'closetag', BBCODE_CLOSETAG_MUSTEXIST);
 
	return $bbcode;
 
}
 
function plugin_extendedimg_parse($string) {
	$o = plugin_extendedimg_init();
	return $o->parse($string);
}
 
add_filter('the_content', 'plugin_extendedimg_parse', 0);
 
?> 
res/plugins/nowhereman/extendedimg.txt · Last modified: 2008/05/17 15:34 by nowhereman