Saturday, July 04, 2009    
Home My Books Blog ColdFusion About Me Back    

 • ColdFusion
 • Bookshelf
 • Tip-of-the-Day
 • CF ISP's
 • Who's Using CF?
 • CF Links
 • CF Tags
 • CF Resources
 • Mailing List


Sams Teach Yourself Regular Expressions in 10 Minutes

Join my mailing list and find out about new books and other topics of interest.
Tip Syndication

I publish a new tip every day (well, I try to) and now you can too. Syndication is easy, and allows you to host my daily tip on your own site (matching the look and feel of your own site). Using syndication you can post the daily tip, allow users browse through tips, and even perform text searches for specific tips.

Interested? First some rules:

  • Tips remain the property of Ben Forta and this site.
  • No guarantee is made as to the accuracy of any technical content nor to the availability of this service, and no liability is assumed in the event of technical inaccuracy or the service being unavailable.
  • Retrieved data must not be modified and must be displayed as is.
  • The tip structure that you'll receive contains several fields, some of which are required (you must display them) and others are optional. The required fields are: BODY and TITLE (which must link to the URL in field URL). All other fields are optional and may be used and/or displayed if desired.
  • Tips may not be stored to disk, database, or any other storage medium. To improve performance tips may be cached in memory (in an APPLICATION variable, for example). To simplify the aging of cached tips, see the EXPIRES field.
  • Tips from prior days may be requested, but not future tips. If a future tip is requested then the current days tip will be returned.

The Web Service

Tips are made available via a Web Service, and tips can thus be consumed by any language or development platform that can function as a Web Services client (including ColdFusion MX).

The Web Service URL is http://www.forta.com/cf/tips/syndicate.cfc?wsdl (if you are using Dreamweaver MX you may paste this URL directly into the Application window's Web Services option in the Components tab). The Web Service exposes three methods:

  • GET returns the tip for a specific day. It requires that a single argument be passed: DATE is the desired date.
  • BROWSE returns a tip using relative dates, ideal for browsing back and forth through tips. It requires that a single argument be passed: AGE is the desired age (0 for today, 1 for yesterday, and so on).
  • SEARCH performs text searches (on both tip title and body) and returns a recordset containing matches. It requires that a single argument be passed: TEXT is the text to search for.

Returned Data

The results returned by the Web Service vary based on the method used. The following data is returned for METHOD="get" and METHOD="browse":
Field Required Description
TITLE Yes Title text, this must be displayed, and must link to the URL provided in the URL field. TARGET specification is allowed.
URL Yes This field should not be displayed, and should be used as the URL for linking field TITLE.
HEADER No Tip header text. This is a one-liner that describes the tip topic. Ideally you'd want to display this above the tip itself.
BODY Yes The tip body text.
PRODUCT No Product to which the tip relates (e.g. "ColdFusion", "Dreamweaver", "ColdFusion Studio" etc.).
PRODUCT_VERSION No Product version to which the tip relates, or "All".
EXPIRES No Number of minutes until this tip expires. Use this field if you plan to cache the tip locally to improve performance. When the expiration time is reached a new tip will be available.
PREV No Flag indicating if a "previous" tip is available. Use this field if you want to display a relative Previous button (using either age or date). This field will be TRUE if a previous tip is available, and FALSE if not.
NEXT No Flag indicating if a "next" tip is available. Use this field if you want to display a relative Next button (using either age or date). This field will be TRUE if a next Tip is available, FALSE if not.
DATE No Date that the tip originally appeared.
AGE No Relative tip age (useful for browsing back and forth through tips).

The following data is returned for METHOD="search":
Field Required Description
TITLE Yes Tip title text.
DATE No Date that the tip originally appeared, pass to METHOD="get" to retrieve the tip.
AGE No Relative tip age, pass to METHOD="browse" to retrieve tip.

Examples

To help you get up and running, here are some usage examples (which you may copy and paste to use as is, or adapt as needed).

This first example uses the GET method to retrieve today's tip:

<!--- Get tip for today --->
<CFINVOKE WEBSERVICE="http://www.forta.com/cf/tips/syndicate.cfc?wsdl"
          METHOD="Get"
          DATE="#Now()#"
          RETURNVARIABLE="DailyTip">
<!--- Display output --->
<CFOUTPUT>
<TABLE WIDTH="300">
<TR><TH><A HREF="#DailyTip.URL#">#DailyTip.title#</A></TH></TR>
<TR><TD ALIGN="center"><B>#HTMLEditFormat(DailyTip.header)#</B></TD> </TR>
<TR><TD><FONT SIZE="-1">#HTMLEditFormat(DailyTip.body)#</FONT></TD></TR>
</TABLE>
</CFOUTPUT>

This next example uses the BROWSE method to retrieve yesterday's tip:

<!--- Get tip for today --->
<CFINVOKE WEBSERVICE="http://www.forta.com/cf/tips/syndicate.cfc?wsdl"
          METHOD="Browse"
          AGE="1"
          RETURNVARIABLE="DailyTip">
<!--- Display output --->
<CFOUTPUT>
<TABLE WIDTH="300">
<TR><TH><A HREF="#DailyTip.URL#">#DailyTip.title#</A></TH></TR>
<TR><TD ALIGN="center"><B>#HTMLEditFormat(DailyTip.header)#</B></TD> </TR>
<TR><TD><FONT SIZE="-1">#HTMLEditFormat(DailyTip.body)#</FONT></TD></TR>
</TABLE>
</CFOUTPUT>

The final example uses the SEARCH method to search for all tips containing the text "J2EE" (you could, of course, pass variables to TEXT, including FORM fields), results are displayed in an unordered list:

<!--- Get tip for today --->
<CFINVOKE WEBSERVICE="http://www.forta.com/cf/tips/syndicate.cfc?wsdl"
          METHOD="Search"
          TEXT="J2EE"
          RETURNVARIABLE="Tips">
<!--- Display output --->
<UL>
 <CFOUTPUT QUERY="Tips">
  <LI>#title#</LI>
 </CFOUTPUT>
</UL>

These examples do not use all of the returned data, your own code can be far more elaborate if needed.

The WDDX Interface

If you are using an older version of ColdFusion then you can use <CFHTTP> and <CFWDDX> to retrieve the tips. Tips may be requested as needed from http://www.forta.com/cf/tips/syndicate.cfm, you should use <CFHTTP> to retrieve this URL. The data returned using the WDDX interface is the same as is returned by the GET and BROWSE methods above. The WDDX interface does not support the SEARCH method. The same URL is used for both GET and BROWSE, the only difference is the passed parameter, to perform a GET pass a DATE argument, like this:

http://www.forta.com/cf/tips/syndicate.cfm?date=10/1/2002
To perform a BROWSE pass an AGE argument like this:
http://www.forta.com/cf/tips/syndicate.cfm?age=1

Note: The WDDX interface will work with ColdFusion MX too, but for improved performance and simplicity of implementation the Web Service interface is recommend if it can be used.

The following displays today's tip using <CFHTTP> to retrieve the data, and <CFWDDX> to extract it:

<!--- Get Tip --->
<CFHTTP METHOD="GET" URL="http://www.forta.com/cf/tips/syndicate.cfm" TIMEOUT="60">

<!--- Extract data --->
<CFWDDX ACTION="WDDX2CFML" INPUT="#CFHTTP.FileContent#" OUTPUT="DailyTip">

<!--- Display output --->
<CFOUTPUT>
<TABLE WIDTH="300">
 <TR><TH><A HREF="#DailyTip.URL#">#DailyTip.title#</A></TH></TR>
 <TR><TD ALIGN="center"><B>#HTMLEditFormat(DailyTip.header)#</B></TD></TR>
 <TR><TD><FONT SIZE="-1">#HTMLEditFormat(DailyTip.body)#</FONT></TD></TR>
</TABLE>
</CFOUTPUT>

Other Interfaces

Edoardo Zubler created a really nice Flash interface to the Daily Tip. Just drop the SWF in to your page and you'll have complete access to all the tips as well as the search feature (exposed by the Web Service interface). If you'd like a copy, here it is (SWF and FLA files are included).

Another option is to use the "CF Tips Fuselet" (courtesy of Ron Hornbaker and Humankind Systems, Inc.) which allows you to display the Daily Tip (with all sorts of configuration options) using no server-side programming at all. For more information go to http://fuselets.com/cftips/index.html

Sven Slazenger and CFUG Central Europe has started a mailing service for daily tips. You can subscribe to it by sending an empty email to cftip-subscribe@cfug.de.

Enjoy!

And that's all there is to it. If you have comments, questions, suggestions, or want to share tips, drop me a note.

  © Copyright 1997-2009 Ben Forta, All Rights Reserved