The migration to Gallery 2.0 is now complete. I spent some time over the last couple of days to find ways to integrate Movable Type and Gallery. In both cases, lack of time to delve into APIs forced me to take some shortcuts.
These examples rely on the use of Cold Fusion as a scripting language. They could probably be adapted to PHP instead, but then again, I don’t have much time to learn PHP beyond simple editing of existing code.
Displaying Gallery content from Movable Type
Gallery offers a nice way to embed images from remote pages. By simply looking at the URLs used by the image-block option of Gallery, I came up with the following modules for Movable Type :
<CFOUTPUT>
<CFHTTP url="#gallery2url#?g2_view=imageblock.External&g2_blocks=randomImage" resolveurl="no" />
#CFHTTP.FileContent#
</CFOUTPUT>
This module displays a random image from the Gallery. Change the value of ‘g2block=’ by ‘viewedImage’ to display the most view image. ‘#gallery2url#’ is a cold fusion variable to the URL of the ‘main.php’ page of your gallery.
Posting a Gallery image to Movable Type
The reverse link was a little trickier to figure out. Instead of using a full call to the XML-RPC machanism supported by Movable Type, I adapted the mechanism of Quickposts to provide a simple ‘Post to Blog’ link from the album view of the Gallery.
Edit the ‘album.tpl’ file of your favorite Gallery template and add the following code after ‘{g->block type="core.ItemInfo" (…) }’ :
{if $user.isAdmin}
<A HREF="javascript:d=document;w=window;t=”;
imageSRC='<BR><IMG SRC=\”+'{g->url arg1="view=core.DownloadItem" arg2="itemId=`$child.thumbnail.id`" arg3="serialNumber=`$child.thumbnail.serialNumber`"
}’+’\’ border=0 align=left hspace=10 vspace=10>’;
imageURL=escape(‘{g->url arg1="view=core.ShowItem" arg2="itemId=`$child.id`"
arg3="serialNumber=`$child.serialNumber`"}’);
void(w.open(‘<PATH TO MT CGI>/mt.cgi?__mode=view&_type=entry&bm_show=c%2Ccb%2Ck&is_bm=1
&link_title=’+escape(‘{$child.title|markup}’)+’&link_href=’+imageURL+’
&text=’+escape(imageSRC),
‘_blank’,’scrollbars=yes,width=400,height=610,status=yes,resizable=yes,scrollbars=yes’))">
Post to Blog</A>
{/if}
Don’t forget to replace <PATH TO MT CGI> by the actual path to your ‘mt.cgi’ file.
The result of this code is to add a link under each item in the Gallery which allows the creation of a new Entry in Movable Type, pre-filled with a link to that item and the corresponding thumbnail.
I would be curious to see how both of these links between the two systems would look if anyone had the time or the skill to write them properly using the appropriate mechanisms provided by each application.