package MT::Plugin::PicasaView; ######################################################## # PicasaView plugin # # Version: 0.1 # # Author: Dieter Leibold http://www.softcoded.net/ # # # # Special Thanks: # # Rachel Freedenberg # ######################################################## ######################################################## # CHANGE THE LINE BELOW TO POINT TO YOUR GALLERY URL # ######################################################## my $GALLERY_PATH = "/plugins/picasa/"; my $GALLERY_URL = "http://softcoded.net/MT/plugins/picasa/"; ######################################################## # CHANGE THE LINE ABOVE TO POINT TO YOUR GALLERY URL # ######################################################## use MT::Template::Context; use XML::Simple; use Data::Dumper; use Cwd; my $dir = getcwd; ######################################################## # Associate tags with functions ######################################################## MT::Template::Context->add_tag(PicasaView => \&picasa_view); ######################################################## # The function for MtGalleryLink ######################################################## sub picasa_view() { my $ctx = shift; my $args = shift; my $album = $args->{album}; return get_gallery($album); } ######################################################## # A utility function to generate the HTML ######################################################## sub get_gallery() { my $album = shift; # create object $xml = new XML::Simple; # read XML file $data = $xml->XMLin($dir . $GALLERY_PATH . $album ."/index.xml"); # access appropriate image data from XML file $Image_data = $data->{images}; # Structure used to store HTML String which is returned to MT $return_data = ""; # Run through all images in gallery foreach $e (@{$Image_data->{image}}){ $return_data .= " {itemName}); $return_data .= "\" title=\"". trim($e->{itemCaption}) ."\"\>"; $return_data .= " {itemName}); $return_data .= "\" border=0 alt=\"". trim($e->{itemCaption}) ."\">\n"; } return $return_data; } ######################################################## # A utility function to strip out whitespace from variables ######################################################## sub trim { my $string = shift; for ($string) { s/^\s+//; s/\s+$//; } return $string; }