package MT::Plugin::GalleryLink; ######################################################## # GalleyLink plugin # # Version: 1.1 # # Author: Yuri Takhteyev http://www.freewisdom.org/ # # # # Collaborators: # # Juan Manuel Caicedo http://www.cavorite.com/ # ######################################################## ######################################################## # CHANGE THE LINE BELOW TO POINT TO YOUR GALLERY URL # ######################################################## my $GALLERY_URL = "http://www.yoursite.org/gallery"; my $ALBUMS_URL = "http://www.yoursite.org/albums"; my $PHOTO_LIST_FILE = "/some/path/photos.txt"; ######################################################## # CHANGE THE LINE ABOVE TO POINT TO YOUR GALLERY URL # ######################################################## use MT::Template::Context; ######################################################## # Associate tags with functions ######################################################## MT::Template::Context->add_tag(GalleryLink => \&gallery_link); MT::Template::Context->add_tag(GalleryLinkRandom => \&random_link); ######################################################## # The function for MtGalleryLink ######################################################## sub gallery_link() { my $ctx = shift; my $args = shift; my ($album, $photo) = split /\//, $args->{photo}; my $img_alt = $args->{img_alt}; my $img_class = $args->{img_class}; my $link_title = $args->{img_title}; my $link_class = $args->{link_class}; return get_gallery_link_html($album, $photo,$img_alt,$img_class,$link_title,$link_class); } ######################################################## # The function for MtGalleryLinkRandom ######################################################## sub random_link() { my $album = "a"; my $photo = "a"; my $img_alt = shift; my $img_class = shift; my $link_title = shift; my $link_class = shift; my @photos = (); open (PHOTOS, $PHOTO_LIST_FILE) or die "File not found: " . $PHOTO_LIST_FILE; while () { chomp; push(@photos, $_); } my $record = $photos[rand(@photos)]; my ($album, $photo) = split(/\//, $record); return get_gallery_link_html($album, $photo,$img_alt,$img_class,$link_title,$link_class); } ######################################################## # A utility function to generate the HTML ######################################################## sub get_gallery_link_html() { my $album = shift; my $photo = shift; my $img_alt = shift; my $img_class = shift; my $link_title = shift; my $link_class = shift; $img_alt = ($img_alt) ? " alt=\"$img_alt\" " : ""; $img_class = ($img_class) ? " class=\"$img_class\" " : ""; $link_title = ($link_title) ? " title=\"$link_title\" " : ""; $link_class = ($link_class) ? " class=\"$link_class\" " : ""; return ""; }