Skip to content

Instantly share code, notes, and snippets.

/flickr.cfc Secret

Created December 3, 2010 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2f9c691f92a1c40850f1 to your computer and use it in GitHub Desktop.
Save anonymous/2f9c691f92a1c40850f1 to your computer and use it in GitHub Desktop.
Flickr Collections integration for the XML Flash Slideshow v4 from DWUser.com.
<!---
READ THE DOCUMENTATION FOR INFORMATION ABOUT THIS CODE: http://www.dwuser.com/flashslideshow/v4/help/advanced_topics/integrating_flickr_collections.html
This script is used to integrate Flickr collections with the XML Flash Slideshow v4 from DWUser.com. See the above URL to learn
more about this integration.
Original Author : Roben Rajan
Date : 30 Nov 2010
Powered By : Exalt Integral Solution
*** Note that this version has been modified slightly from the original.
--->
<cfcomponent displayname="flickr" output="false" hint="Component for Flickr Collection">
<cffunction name="init" access="public" returntype="string" output="false">
<cfargument name="userID" type="string" required="yes" default="">
<cfargument name="apiKey" type="string" required="yes" default="">
<cfargument name="collectionID" type="string" required="yes" default="">
<cfset this.userID = arguments.userID>
<cfset this.apiKey = arguments.apiKey>
<cfset this.collectionID = arguments.collectionID>
<cfset this.thumbSize = 's'><!---thumbSize can be 's' or 't'--->
</cffunction>
<cffunction name="getPhotos" access="remote" returntype="string" output="false">
<!---<cfsetting enablecfoutputonly="true">--->
<!---<cfcontent type="text/xml" reset="yes">--->
<!---<cfset init(userID = "PLACE_USER_ID_HERE", apiKey = "PLACE_API_KEY_HERE", collectionID = "PLACE_COLLECTION_ID_HERE")>--->
<cfset init(userID = arguments.userID, apiKey = arguments.apiKey, collectionID = arguments.collectionID)>
<cfset output = getFlickrCollectionSourceString()>
<!---<cfset output = XMLParse(getPage(output))>--->
<cfreturn output>
</cffunction>
<cffunction name="getFlickrCollectionSourceString" access="public" hint="The public function for calling the flick Collection" output="false">
<!---Get all photosets, so we have the thumb, title and desc for each "gallery"--->
<cfset variables.url = "http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=#this.apiKey#&user_id=#this.userID#">
<cfset xml = getPage(variables.url)>
<cfset xmlobj = xmlParse(xml)>
<cfloop from="1" to="#ArrayLen(xmlobj.rsp.photosets.xmlchildren)#" index="i">
<cfset attr = xmlobj.rsp.photosets.photoset[i].xmlattributes>
<cfset id = attr.id>
<cfset thumb = "http://farm#attr.farm#.static.flickr.com/#attr.server#/#attr.primary#_#attr.secret#_#this.thumbSize#.jpg">
<cfset title = xmlobj.rsp.photosets.photoset[i].title.xmltext>
<cfset description = xmlobj.rsp.photosets.photoset[i].description.xmltext>
<cfset photosetInfo[id] = structnew()>
<cfset photosetInfo[id].thumb = thumb>
<cfset photosetInfo[id].title = title>
<cfset photosetInfo[id].description = description>
</cfloop>
<!---Get the photos--->
<cfset variables.url = 'http://api.flickr.com/services/rest/?method=flickr.collections.getTree&api_key=#this.apiKey#&collection_id=#this.collectionID#&user_id=#this.userID#'>
<cfset xml = getPage(variables.url)>
<cfset xmlobj = xmlParse(xml)>
<cfset sources = arraynew(1)>
<cfloop from="1" to="#ArrayLen(xmlobj.rsp.collections.collection.xmlchildren)#" index="i">
<cfset attr = xmlobj.rsp.collections.collection.xmlchildren>
<cfset set = attr[i].xmlattributes>
<cfset sourceURL = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=#this.apiKey#&photoset_id=#set.id#'><!---Build Flickr photoset API URL--->
<!---Append the special information strings--->
<cfset info = evaluate("photosetInfo.#set.id#")>
<cfset sourceURL = sourceURL & '&xfs4t=#URLEncodedFormat(info.thumb)#&xfs4ti=#URLEncodedFormat(info.title)#&xfs4d=#URLEncodedFormat(info.description)#'>
<cfset ArrayAppend(sources,sourceURL)>
</cfloop>
<cfreturn arraytolist(sources,",")>
</cffunction>
<cffunction name="getPage" access="private" hint="Get the Flickr page as XML" output="false">
<cfargument name="url" type="string" required="yes" hint="url string">
<cfhttp url="#arguments.url#">
<cfreturn cfhttp.filecontent>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment