Archive for the ‘Plugins’ Category

PHPizer Plugin

August 14th, 2004 by daryl

From time to time, I’ll have occasion to include some PHP code in my entries, and PHP’s a lot easier to read if it’s syntax-highlighted. Many forums allow you to wrap special tags around you code to cause it to be syntax-highlighted, and though I’ve seen some WordPress plugins out there for doing syntax highlighting, they’ve seemed a little more complicated that has seemed quite necessary, or they’ve been dependent upon some library or another being in place. So I rolled my own, which can be downloaded here.

If you want to syntax-highlight a code block, just wrap the tags <php> and </php> (replace angle brackets with square brackets) around it and this plugin filters it through the highlight_string() function. You can also specify a div class name that allows you to define a style for the container div. I’ve chosen to set my code off by putting it in a gray box with some margin and padding and a thin border. The default class name is set to “code”. The code itself for this plugin (to demonstrate the plugin in action, which strikes me as being rather like standing between two mirrors and seeing infinity as they reflect one another’s images recursively) is as follows (note that I had to screw with the code just a smidgin to keep it from parsing the php marker tags in the regular expressions — if you want to use this, download the source from the link, as that’s unscrewed-with, commented code):

[php]
$phpizer_div_class=”code”;

function phpizer($text) {
global $phpizer_div_class;
$parse=0;
$codebuffer=”";
$finaltext=”";
$count=1;

//Get lines into an array so we can iterate over them.
$lines=split(”n”,stripslashes($text));

foreach($lines as $theline){
//If we’re starting a code block, set flag and suppress marker tag display.
if(preg_match(”/[ php]/”,$theline)){
$parse=1;
$theline=”";
}
if(preg_match(”/[ /php]/”,$theline)){
$parse=0;
$finaltext .= “

n” . highlight_string(”< ?phpn" . $codebuffer . "n?>n”,1) . “

n”;
$count++;
$codebuffer=”";
$theline=”n”;
}
//Not code, so just add current line.
if($parse==0){
$finaltext .= $theline;
}
else{
$codebuffer .= $theline;
}
}
return $finaltext;
}

add_filter(’the_content’, ‘phpizer’, 8);
add_filter(’comment_text’, ‘phpizer’, 8);
[/php]

Amazon Wishlist

August 9th, 2004 by daryl

Another Update (Sept. 3, 2004): I’ve added a category for the amazon plugin that’ll list all relevant posts so I don’t have to keep going back and adding these stupid updates. Be sure to read all posts in the category for complete details.

Update (Aug. 16, 2004): I’ve added some functionality and fixed a bug. Check here for details.

I’ve just written my first WordPress plugin. Actually, I had previously modified the acronym plugin to allow me to specify some common words that should always be associated with links (only later did I notice that the author of the original plugin had already done just this). Amazon Wishlist is my first original plugin, though, and even at that, the bulk of the code isn’t mine. I found a fairly concise script that interfaces with the Amazon API and another that actually handles making the connection, and I wrapped some code around the results to make it all into a nice configurable plugin for WordPress. Incidentally, there is another Amazon plugin here that allows you very easily to browse books and insert them into your entries. Very nifty, but it serves a different purpose.

Installation
You have only to download the plugin, stick it in your wp-content/plugins directory, edit a few variables, optionally add some style sheet definitions, and activate the plugin using your control panel. Straight from the code itself:

[php]
$aw_dev_token=”; //Get this from http://www.amazon.com/gp/aws/landing.html.
$aw_associates_id=”; //Optional; set to empty string if not applicable.
$aw_type=’lite’; //could also be heavy, though it doesn’t seem to make a difference in the search results.
$aw_wishlist_id=”; //The id of the wish list you wish to search. Hint: Search for (don’t simply go to) your wish list and copy the id from the end of the URL.

$aw_header=’Amazon Wish List’; //Used to label the box.
$aw_show_author = 1; //Set to 0 to suppress.
$aw_image_size = ‘Medium’; //’Small,’ ‘Medium,’ or ‘Large’
$aw_show_price = 1; //Set to 0 to suppress.
[/php]

Here’s hoping it’s not buggy and that it helps somebody out. You can see it in action in my sidebar.