spacer
spacer
spacer
Using FuseTalk's XML Functionality
Platform: ColdFusion

XML took the internet by brute force and it's being used more and more every day. Realizing the ubiquity of XML, some XML information gateways were built into the FuseTalk product. By using XML, you can retrieve Categories, Topics, Messages and post Topics and Messages into the forums. There are a few files that make up the XML core of FuseTalk: xmlcats.cfm, xmltopics.cfm and xmlreceive.cfm. Below, we'll go through each of these templates and demonstrate how to retrieve categories, topics and post topics and messages.

Getting a category listing for a forum
To retrieve a category listing, open the samplecats.cfm file in the samples/xml directory from your FuseTalk folder. This file contains the code necessary to retrieve a category listing. The main functionality of the template is at the top. The first call is an HTTP call to get the XML document. You need to pass your login, forumid and password to this template. Note that the password has to be hashed for security purposes. After getting the XML document, parse the XML and use the XMLSearch function to get the rows of data that you want.

<!--- GET THE TOPICS NOTE ALL THE URL VARS PASSED ARE REQUIRED --->
<cfhttp url="http://** YOUR URL TO THE FORUMS **/forum/xmlcats.cfm?xmlun=Administrator&xmlpw=#Hash("yourpassword")#&forumid=1&outexport=yes" method="GET" resolveUrl="false"/>

<!--- CONVERT THE CONTENT TO XML --->
<cfset FTVAR_CONVERTEDXML = XMLParse(cfhttp.filecontent)>

<!--- GET THE ELEMENTS YOU WANT TO OUTPUT --->
<cfset FTVAR_XMLELEMENTS = XMLSearch(FTVAR_CONVERTEDXML, "/categories/row")>

Getting a topic listing for a category
To retrieve a topic/thread listing, open the sampletopics.cfm file in the samples/xml directory from your FuseTalk folder. This template is very much the same as the samplecats.cfm template. It does an HTTP call to the forum, and it requires a Forum ID, category ID, username and password to return a XMLDocument, after which we parse it.

<!--- GET THE TOPICS NOTE ALL THE URL VARS PASSED ARE REQUIRED --->
<cfhttp url="** YOUR URL TO THE FORUMS **/forum/xmlexport.cfm?xmlun=Administrator&xmlpw=#Hash("yourpassword")#&FTVAR_CATIDFRM=3&forumid=1&outexport=yes" method="GET" resolveUrl="false"/>

<!--- CONVERT THE CONTENT TO XML --->
<cfset FTVAR_CONVERTEDXML = XMLParse(cfhttp.filecontent)>

<!--- GET THE ELEMENTS YOU WANT TO OUTPUT --->
<cfset FTVAR_XMLELEMENTS = XMLSearch(FTVAR_CONVERTEDXML, "/threads/row")>

Getting messages for a specified topic
Retrieving a message listing for a topic is shown in the samplemessage.cfm. Again, we make an HTTP call to the xmlexport.cfm template, and an XML document is returned and then we parse it. To get a message listing, we pass forumid, categoryid, topicid and a username and password (remember that the password has to be hashed).

<!--- GET THE TOPICS NOTE ALL THE URL VARS PASSED ARE REQUIRED --->
<cfhttp url="http://** YOUR URL TO THE FORUMS **/forum/xmlexport.cfm?xmlun=Administrator&xmlpw=#Hash("yourpassword")#&FTVAR_CATIDFRM=3&forumid=1&outexport=yes&FTVAR_THREADID=35" method="GET" resolveUrl="false"/>

<!--- CONVERT THE CONTENT TO XML --->
<cfset FTVAR_CONVERTEDXML = XMLParse(cfhttp.filecontent)>

Posting a message to FuseTalk
To post a message to FuseTalk, we call the xmlreceive.cfm file and pass it an XML Document which represents the message. View the samplepost.cfm file below to see an example on constructing the xml message document and sending it to FuseTalk.

<!--- CREATE THE MESSAGE WITH XML AS BELOW NOTE USER PASSWORD IS HASHED ALWAYS --->
<cfxml variable="ftPostXML">
<message>
<username>jclark</username>
<password><cfoutput>#hash("asdf")#</cfoutput></password>
<messagetitle>testing 1-2-3</messagetitle>
<messagetext>123</messagetext>
<categoryid>3</categoryid>
<forumid>1</forumid>
<messagesummary>Summary</messagesummary>
<action>post</action>
<threadid>0</threadid>
<parentid>0</parentid>
</message>
</cfxml>

<!--- CALLS XMLRECEIVE IN THE FORUM DIRECTORY AND PASSES THE XML AS A PARAM USER IS AUTHED WITH THE PARAMS PASSED IN THE URL PARAM --->
<cfhttp url="** YOUR URL TO THE FORUMS **/forum/xmlreceive.cfm?forumid=1&xmlun=avalidusername&xmlpw=#hash("yourpassword")#" method="POST" resolveUrl="false">
    <cfhttpparam name="body" type="XML" value="#ToString(ftPostXML)#">
</cfhttp>

In this tutorial, we've retrieved core content out of FuseTalk using XML. There are many uses for displaying this content on your website, such as the latest posts in X category. You can even take this as far as writing your own mini-forum interface around the content. If you have feedback about the XML functionality in fusetalk, please post it here: (http://www.fusetalk.com/suggestions.cfm)