" /> Notebook: February 2004 Archives

« January 2004 | Main | March 2004 »

February 27, 2004

cool fire(bird|fox) extension

well, since i have a list of to-dos about 93,000,000 miles long, I never got around to fixing a problem that i find frustrating. Namely, I find it frustrating when people or websites don't put anchor tags around a URL. This means that you have to copy and paste the URL into the address bar to go there. Kinda defeats the purpose.

Anyway, some kind sould make the Select Search browser extension for firefox and firebird. This does exactly what i want. I can highlight a URL and right click to point my web browser to that URL. Nice. It even defaults to opening the URL in a new tab that does not have the focus. Very sweet.

February 13, 2004

MTRecentImages update (enough already, with the updates!)

So I have added many requested features (limiting by category or size, exluding by category) and incorporated Ari's contributions to MTRecentImages. Read the docs, install and enjoy!
I should have updated the file with the newer version number (1.0), but i forgot. I will do that later.

February 12, 2004

MTRecentImages extended + New Features coming this weekend.

I received a nice note this afternoon from Ari Paparo regarding my new MTRecentImages plugin. He has added a tag that will return the permalink for the entry containing the image (an excellent addition). Thanks, Ari!
Ari Paparo Dot Com: Image Archives and Image-Only RSS in Movable Type
As for new features, I am in the process of adding features to show only images that match (or don't match) a certain category, plus matches for width, height and file type of your site's images. Should make this quite a bit more useful.
Does anyone have any other requests?

February 8, 2004

Movable Type Plugins Page

I have made a new Movable Type Plugins page to house info about my whopping ONE plugin (although there shall be more to come. There shall!

You can download the MTRecentImages plugin there, plus browse its documenation. I submitted this to mt-plugins.org, so hopefully it gets picked up in a day or two.

February 4, 2004

Recent Images Update

Check out the new Recent Images link, built using my new and improved recent images plugin. I need to submit this to the mt-plugins.org repository. I need to clean up the code, add some POD and put it on it's own nice little page (along with my javascript syndication template).

RecentImages plugin

Excellent.
After some trial and error, I have v1 of my RecentImages plugin for MT available.
Basically, this just loops through your entries until it finds
num_images
worth of images, and will print the ALT text and the link to the image. Use it like so:
<MTRecentImages num_images="10">
   <a href="<$MTRecentImageUrl$>"><$MTRecentImageName$></a><br/>
</MTRecentImages>

To install it, simply make a file called recent_images.pl in your mt plugins directory and copy the following code into it.
#!/usr/bin/perl -w
use strict;
use lib '../lib';
use MT::Entry;
use MT::Template::Context;
use vars qw( $error );

use constant NUM_IMAGES => 10;

BEGIN {
        eval {
                require HTML::TokeParser;
        };
        $error = $@;
}

MT::Template::Context->add_container_tag(RecentImages => \&images);
MT::Template::Context->add_tag(RecentImageUrl => sub { shift->stash('image_url') });
MT::Template::Context->add_tag(RecentImageName => sub { shift->stash('image_name') });

sub images {

        my ($ctx, $args) = @_;

        if ($error) {
                return $ctx->error('Error with : required modules not installed');
        }

        my $num_images = $args->{num_images} || NUM_IMAGES;
        my $blog_id = $ctx->stash('blog_id');

        my $iter = MT::Entry->load_iter(
                        { blog_id => $blog_id }, { sort => 'created_on', direction => 'descend' }
                );

        my @images;

        while (my $entry = $iter->()) {
                push @images, extract_images($entry->text);
#               push @images, { image_url => 'asdf', image_name => 'foobar' };
                last if @images >= $num_images;
        }

        my $res = '';
        my $builder = $ctx->stash('builder');
        my $tokens = $ctx->stash('tokens');

        foreach my $image (splice @images, 0, $num_images) {
                $ctx->stash('image_url',  $image->{image_url} );
                $ctx->stash('image_name', $image->{image_name} );

                # defined (my $out = $builder->build($ctx, $tokens))
            # or return $ctx->error($ctx->errstr);
                my $out = $builder->build($ctx, $tokens);

                $res .= $out;

        }

        return $res;

}

sub extract_images {
  my $content = shift;

  return unless $content;

  my @found_images;

  my $stream = HTML::TokeParser->new( \$content );

  while (my $token = $stream->get_token ) {
    if ( $token->[0] eq 'S' and lc($token->[1]) eq "img" ) {
        my $img_attr = $token->[2]; # the attributes for this image tag.

        push @found_images, { image_name => $img_attr->{'alt'}, image_url => $img_attr->{'src'} };
    }

  }

  return @found_images;
}