<cfinclude template="config.cfm">

<cfset flickr = createobject("component", "CFlickr.Flickr")>
<cfset flickr.init(apikey, secret, token)>
<cfset bi = flickr.getBlogsInterface()>
<cfset pi = flickr.getPhotosInterface()>

<cfif isdefined('url.blog_id') AND isdefined('url.photo_id') AND isdefined('url.redirect')>
	<cfset photo = pi.getInfo(url.photo_id)>
	<cfset bi.postPhoto(url.blog_id, url.photo_id, photo.gettitle(), photo.getDescription())>
	<cflocation url="#url.redirect#" addtoken="no">
</cfif>

<cfset blogs = bi.getList()>
<cfset photolist = pi.getRecent(per_page=1,page=1)>
<cfset photos = photolist.getPhotos()>
<cfset photo = photos[1]>

<cfinclude template="header.cfm">

<cfoutput>

	<h1>Example 2</h1>

	<p><img src="#photo.getPhotoUrl(photo.SIZE_SMALL_SQUARE)#" align="left" > Heres a random image i've picked from flickr (refresh for a different one).  
	If you have any blogs configured on your flickr acocunt, you can click the link below to publish this photo to your blog.  
	You'll be sent directly to your blogs homepage, but you may need to refresh the page as some blog sites take a few seconds to publish the new content.</p>	

	<br clear="all">

	<cfif arraylen(blogs)>
		<h3>Your Blogs</h3>
		<cfloop from="1" to="#arraylen(blogs)#" index="i">
		<a href="#blogs[i].getUrl()#">#blogs[i].getName()#</a> <a href="../_Examples/?blog_id=#blogs[i].getId()#&amp;photo_id=#photo.getId()#&amp;redirect=#urlencodedformat(blogs[i].getUrl())#">Publish Photo</a>
		</cfloop>
	<cfelse>
		You have no blogs configured on Flickr
	</cfif>

</cfoutput>