| 1 | <cfcomponent output="false" displayName="Slideshow"> |
|---|
| 2 | |
|---|
| 3 | <cfset variables.slideshowdir = ""> |
|---|
| 4 | |
|---|
| 5 | <cffunction name="init" access="public" returnType="slideshow" output="false"> |
|---|
| 6 | <cfargument name="dir" type="string" required="true"> |
|---|
| 7 | |
|---|
| 8 | <cfset variables.slideshowdir = arguments.dir> |
|---|
| 9 | <cfreturn this> |
|---|
| 10 | </cffunction> |
|---|
| 11 | |
|---|
| 12 | <cffunction name="getImages" access="public" returnType="query" output="false" hint="Gets gifs/jpgs"> |
|---|
| 13 | <cfargument name="directory" type="string" required="true"> |
|---|
| 14 | <cfset var images = ""> |
|---|
| 15 | |
|---|
| 16 | <cfdirectory directory="#arguments.directory#" name="images"> |
|---|
| 17 | |
|---|
| 18 | <cfquery name="images" dbtype="query"> |
|---|
| 19 | select name |
|---|
| 20 | from images |
|---|
| 21 | where lower(name) like '%.jpg' |
|---|
| 22 | or lower(name) like '%.gif' |
|---|
| 23 | </cfquery> |
|---|
| 24 | |
|---|
| 25 | <cfreturn images> |
|---|
| 26 | </cffunction> |
|---|
| 27 | |
|---|
| 28 | <cffunction name="getInfo" access="public" returnType="struct" output="false" hint="Try to find an xml file and parse it."> |
|---|
| 29 | <cfargument name="directory" type="string" required="true"> |
|---|
| 30 | <cfset var result = structNew()> |
|---|
| 31 | <cfset var xmlFile = arguments.directory & "/metadata.xml"> |
|---|
| 32 | <cfset var xmlPacket = ""> |
|---|
| 33 | <cfset var x = ""> |
|---|
| 34 | <cfset var image = structNew()> |
|---|
| 35 | <cfset var imageNode = ""> |
|---|
| 36 | |
|---|
| 37 | <cfset result.name = ""> |
|---|
| 38 | <cfset result.formalname = ""> |
|---|
| 39 | <cfset result.images = structNew()> |
|---|
| 40 | |
|---|
| 41 | <cfif not directoryExists(arguments.directory) or not fileExists(xmlFile)> |
|---|
| 42 | <cfreturn result> |
|---|
| 43 | </cfif> |
|---|
| 44 | |
|---|
| 45 | <cfset result.name = listLast(arguments.directory, "/\")> |
|---|
| 46 | |
|---|
| 47 | <cffile action="read" file="#xmlFile#" variable="xmlPacket"> |
|---|
| 48 | <cfset xmlPacket = xmlParse(xmlPacket)> |
|---|
| 49 | |
|---|
| 50 | <cfif not structKeyExists(xmlPacket, "slideshow")> |
|---|
| 51 | <cfreturn result> |
|---|
| 52 | </cfif> |
|---|
| 53 | |
|---|
| 54 | <cfif structKeyExists(xmlPacket.slideshow, "formalname")> |
|---|
| 55 | <cfset result.formalname = xmlPacket.slideshow.formalname.xmlText> |
|---|
| 56 | </cfif> |
|---|
| 57 | |
|---|
| 58 | <cfif structKeyExists(xmlPacket.slideshow, "captions") and arrayLen(xmlPacket.slideshow.captions.xmlChildren)> |
|---|
| 59 | <cfloop index="x" from="1" to="#arrayLen(xmlPacket.slideshow.captions.xmlChildren)#"> |
|---|
| 60 | <cfset imageNode = xmlPacket.slideshow.captions.xmlChildren[x]> |
|---|
| 61 | <cfif structKeyExists(imageNode.xmlAttributes, "name") and structKeyExists(imageNode.xmlAttributes, "caption")> |
|---|
| 62 | <cfset image.filename = imageNode.xmlAttributes.name> |
|---|
| 63 | <cfset image.caption = imageNode.xmlAttributes.caption> |
|---|
| 64 | <cfset result.images[image.filename] = image.caption> |
|---|
| 65 | </cfif> |
|---|
| 66 | </cfloop> |
|---|
| 67 | </cfif> |
|---|
| 68 | |
|---|
| 69 | <cfreturn result> |
|---|
| 70 | </cffunction> |
|---|
| 71 | |
|---|
| 72 | <cffunction name="getSlideShowDir" access="public" returnType="string" output="false" hint="Returns the slideshow directory."> |
|---|
| 73 | <cfreturn variables.slideshowdir> |
|---|
| 74 | </cffunction> |
|---|
| 75 | |
|---|
| 76 | <cffunction name="updateInfo" access="public" returnType="void" output="false" hint="Updates the XML packet."> |
|---|
| 77 | <cfargument name="directory" type="string" required="true"> |
|---|
| 78 | <cfargument name="md" type="struct" required="true"> |
|---|
| 79 | <cfset var xmlFile = arguments.directory & "/metadata.xml"> |
|---|
| 80 | <cfset var packet = ""> |
|---|
| 81 | <cfset var image = ""> |
|---|
| 82 | |
|---|
| 83 | <cfxml variable="packet"> |
|---|
| 84 | <cfoutput> |
|---|
| 85 | <slideshow> |
|---|
| 86 | <formalname>#md.formalname#</formalname> |
|---|
| 87 | <captions> |
|---|
| 88 | <cfloop item="image" collection="#arguments.md.images#"> |
|---|
| 89 | <image name="#image#" caption="#arguments.md.images[image]#" /> |
|---|
| 90 | </cfloop> |
|---|
| 91 | </captions> |
|---|
| 92 | </slideshow> |
|---|
| 93 | </cfoutput> |
|---|
| 94 | </cfxml> |
|---|
| 95 | |
|---|
| 96 | <cffile action="write" file="#xmlFile#" output="#toString(packet)#"> |
|---|
| 97 | </cffunction> |
|---|
| 98 | |
|---|
| 99 | </cfcomponent> |
|---|