Underneath is the source code of the ShowTweets plugin.
<cfset request.timerStart = getTickCount() /> <cfparam name ="url.q" default="from:frinky OR to:frinky OR @frinky" /> <cfparam name="url.nr" default="50" /> <cfparam name="url.style" default="" /> <!---just to be sure, clean the query ---> <cfset url.q = rereplaceNoCase(url.q, "[<>\t\r\n]+", "", "all") /> <!---number between 1 and 100 ---> <cfif not isNumeric(url.nr) or refind("[^0-9]", url.nr) or url.nr lt 1 or url.nr gt 100> <cfif not find("from:frinky", url.q) or url.nr gt 500> <cfset url.nr = 50 /> </cfif> </cfif> <cfset url.style = left(rereplace(url.style, "[<>]+", "", "all"), 1000) /> <!--- avoid javascript injection ---> <cfset url.style = replaceNoCase(url.style, "expression", "expre-not-allowed-ssion", "ALL") /> <!--- get all search strings already in DB ---> <cftry> <cfif not structKeyExists(application, "searchStrings") or structKeyExists(url, 'init')> <cfquery name="temp" datasource="#application.dbs#"> SELECT twearch_q, twearch_id FROM twearch </cfquery> <cfset searches = structNew() /> <cfloop query="temp"> <cfset structInsert(searches, twearch_q, twearch_id, true) /> </cfloop> <cfset structInsert(application, "searchStrings", searches, true) /> </cfif> <cfif not structKeyExists(application.searchStrings, url.q)> <cfquery name="temp" datasource="#application.dbs#"> INSERT INTO twearch (twearch_q) VALUES (<cfqueryparam value="#url.q#" cfsqltype="cf_sql_varchar" />); SELECT twearch_id FROM twearch WHERE twearch_q = <cfqueryparam value="#url.q#" cfsqltype="cf_sql_varchar" />; </cfquery> <cfset structInsert(application.searchStrings, url.q, temp.twearch_id, true) /> </cfif> <cfcatch><cfoutput><!-- error caught: #cfcatch.Message# #cfcatch.detail# --></cfoutput> <cfif not structKeyExists(application, "searchStrings")> <cfset application.searchStrings = {} /> </cfif> <cfrethrow /><cfabort /> </cfcatch> </cftry> <cfcontent reset="yes" type="text/html; charset=UTF-8" /><!--- ---><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <cfoutput><title>ShowTweets - #url.q# -- by ongevraagdadvies.nl</title></cfoutput> <style type="text/css"> html, body { padding: 0px; margin: 0px; background-color: #fff; } body, td, a { font-size: 12px; color: #000; font-family: Arial, Helvetica, sans-serif; } a { color: #009; } a:hover { color: #f00; } a:visited { color: #006; } /* the search api we're using highlights the searchword by using <b>. We don't need to show the search word like that. */ b { font-weight: normal; } img, a img { border: 1px solid #000; } table { border-collapse: collapse; border: 0; width: 100%; } td { padding: 2px 4px; vertical-align: top; } td.img { width: 50px; } td.img img { width: 48px; height: 48px; } tr.row0 td { border-top: 1px solid #999; background-color: #ddd; } tr.row1 td { border-top: 1px solid #666; background-color: #eee; } span.date { color: gray; font-style: italic; padding-left: 10px; font-size: 11px; /* shown on new line, aligned right display: block; clear: both; padding-top: 3px; text-align:right; */ } span.date a { text-decoration: none; color: gray; } span.postername a { text-decoration: none; color: #003; } /* your css can be here by setting it in the url like this: &style=... */ <cfoutput>#url.style#</cfoutput> </style> <base target="_top" /> </head> <body> <table id="tbl"><cfoutput> <cftry> <cfset request.apiTimerStart = getTickCount() /> <cfhttp url="http://search.twitter.com/search.atom?q=#URLEncodedFormat(url.q)#&rpp=#url.nr#" useragent="Showtweets-plugin/1.1 Mozilla/5.0 (Windows; U; Windows NT 7.0; en) (http://www.ongevraagdadvies.nl/showtweets-plugin/)"> <cfhttpparam type="cgi" encoded="no" name="Referer" value="http://www.ongevraagdadvies.nl/showtweets/" /> </cfhttp> <cfset request.apiTimerTime = getTickCount() - request.apiTimerStart /> <!---remove all namespaces and namespace references from xml, cause coldfusion sometimes really really sucks! ---> <cfset twixml = rereplaceNoCase(cfhttp.FileContent, " xmlns[=:][^ >]+", "", "ALL") /> <cfset twixml = rereplaceNoCase(twixml, "<(/?)([a-z0-9_\-]+:)([a-z0-9\-_]+)>", "<\1\3>", "ALL") /> <cfset twixml = xmlParse(twixml) /> <cfset entries = xmlSearch(twixml, '//entry') /> <cfloop from="1" to="#arrayLen(entries)#" index="entryNum"> <!---get the image link ---> <cfset imglink = XMLSearch(entries[entryNum], "link[@rel='image']/") /> <!---get the html content ---> <cfset contentItem = XMLSearch(entries[entryNum], "content[@type='html']/") /> <!---get the publish date, and convert it to a 'x minutes ago' link ---> <cfset pubdate = DateConvertISO8601(entries[entryNum].published.xmlText, 0) /> <cfset minutesAgo = DateDiff('n', pubdate, dateConvert("local2Utc", now())) /> <cfif minutesAgo eq 0> <cfset pub_str = "just now!" /> <cfelseif minutesAgo lt 60> <cfset pub_str = "#minutesAgo# minutes ago" /> <cfelseif minutesAgo lt 60*36> <cfset hrs = round(minutesAgo/60) /> <cfset pub_str = "about #hrs# hours ago" /> <cfelse> <cfset days = round(minutesAgo/(60*24)) /> <cfset pub_str = "about #days# #iif(days eq 1, de('day'), de('days'))# ago" /> </cfif> <tr class="row#entryNum mod 2#"> <td class="img"><cfif arrayLen(imglink)><a href="#entries[entryNum].author.uri.xmlText#" target="_blank"><img src="#imgLink[1].xmlAttributes.href#" alt="#HTMLEditFormat(entries[entryNum].author.name.xmlText)#" title="Go to twitter page of #HTMLEditFormat(entries[entryNum].author.name.xmlText)#" /></a></cfif></td> <td class="txt"><span class="postername"><a href="#entries[entryNum].author.uri.xmlText#">#rereplace(entries[entryNum].author.name.xmlText, " \(.*?\)$", "")#</a>: </span> <span class="msg">#contentItem[1].xmlText#</span> <span class="date">(#pub_str#, via #entries[entryNum].source.xmlText#)</span> </td> </tr> </cfloop> <cfcatch> </td></tr> <tr><td colspan="2" style="padding:5px;color:red;background-color:white;border:2px solid red;"><strong>An error occured :-(<br /></strong><em>#cfcatch.message#<br />#cfcatch.detail#</em> <br />You might want to contact <a href="http://www.ongevraagadvies.nl/contact/">Paul (ongevraagadvies.nl)</a>. </td></tr> </cfcatch> </cftry> <cftry> <cfif arrayLen(entries) lt url.nr> <cfquery name="msgs_qry" datasource="#application.dbs#"> SELECT TOP #url.nr-arrayLen(entries)# twessages_date, twessages_authorlink, twessages_content, twessages_imglink, twessages_authorname, twessages_source FROM twessages WHERE twessages_twearch_ID = <cfqueryparam value="#application.searchStrings[url.q]#" cfsqltype="cf_sql_idstamp" /> ORDER BY twessages_date DESC </cfquery> <cfloop query="msgs_qry"> <!---get the image link ---> <cfset imglink = twessages_imglink /> <!---get the html content ---> <cfset contentItem = twessages_content /> <!---get the publish date, and convert it to a 'x minutes ago' link ---> <cfset pubdate = twessages_date /> <cfset minutesAgo = DateDiff('n', pubdate, dateConvert("local2Utc", now())) /> <cfif minutesAgo eq 0> <cfset pub_str = "just now!" /> <cfelseif minutesAgo lt 60> <cfset pub_str = "#minutesAgo# minutes ago" /> <cfelseif minutesAgo lt 60*36> <cfset hrs = round(minutesAgo/60) /> <cfset pub_str = "about #hrs# hours ago" /> <cfelse> <cfset days = round(minutesAgo/(60*24)) /> <cfset pub_str = "about #days# #iif(days eq 1, de('day'), de('days'))# ago" /> </cfif> <tr class="row#(entryNum+msgs_qry.currentrow) mod 2#"> <td class="img"><cfif len(imglink)><a href="#twessages_authorlink#" target="_blank"><img src="#imglink#" alt="#twessages_authorname#" title="Go to twitter page of #twessages_authorname#" /></a></cfif></td> <td class="txt"><span class="postername"><a href="#twessages_authorlink#">#rereplace(twessages_authorname, " \(.*?\)$", "")#</a>: </span> <span class="msg">#twessages_content#</span> <span class="date">(#pub_str#, via #twessages_source#)</span> </td> </tr> </cfloop> </cfif> <cfcatch><!-- error caught: #cfcatch.Message# #cfcatch.detail# --></cfcatch> </cftry> </cfoutput></table> <a href="http://www.ongevraagdadvies.nl/showtweets-plugin/" style="display:block;visibility:visible;height:auto;width:100%;padding:5px 0px;color:#00f;font-size:11px;text-align:center;">ShowTweets plugin by Ongevraagd Advies</a> </body> </html> <cfoutput><!-- timer total page: #getTickCount() - request.timerStart# msecs. (xmlSearch is soooo slow) timer twitter http call: #request.apiTimerTime# msecs. --></cfoutput> <cfabort /> <cfscript> /** * Convert a date in ISO 8601 format to an ODBC datetime. * * @param ISO8601dateString The ISO8601 date string. (Required) * @param targetZoneOffset The timezone offset. (Required) * @return Returns a datetime. * @author David Satz (david_satz@hyperion.com) * @version 1, September 28, 2004 */ function DateConvertISO8601(ISO8601dateString, targetZoneOffset) { var rawDatetime = left(ISO8601dateString,10) & " " & mid(ISO8601dateString,12,8); // adjust offset based on offset given in date string if (uCase(mid(ISO8601dateString,20,1)) neq "Z") targetZoneOffset = targetZoneOffset - val(mid(ISO8601dateString,20,3)) ; return DateAdd("h", targetZoneOffset, CreateODBCDateTime(rawDatetime)); } </cfscript>