Yesterday I posted a reminder that ColdFusion 11 developers can stop using the old "CFCs for Tags" feature that provided support for certain things in script. I mentioned that everything could be used in cfscript now and that the old CFCs were (sometimes, not always) a bit buggy.
Brad Wood suggested I actually provide an example of this and I thought it was a good idea. I wrote up two quick demos that demonstrate the new syntax. This isn't super deep or anything, but hopefully it gives you a basic idea of how this new syntax looks. First, an example of a few different tags:
cfhttp(url="http://www.cnn.com",result="cnnReq");
writeDump(cnnReq.responseHeader);
cfhttp(url="http://www.cnn.com",result="cnnReq",method="post") {
cfhttpparam(type="formfield",name="something",value=createUUID());
}
writeDump(cnnReq.responseHeader);
cfsearch(collection="test1", criteria="cat", name="searchResults");
writeDump(searchResults);
cffeed(action="read", source="http://feeds.feedburner.com/raymondcamdensblog", query="feed");
writeDump(feed);
Make note of how you can't use a result (ie, foo = goo()) in any of these calls and instead use an argument. That could be easily fixed and should be. Second, note how child tags are handled in the second cfhttp call. I don't have anything to add to it, but as I said, just note the syntax.
For the heck of it, I then wrote a second demo. This one takes an array of RSS URLs and uses cfthread to fetch them in parallel. It then merges the resultant queries and sorts them. A mini-aggregator if you will.
feeds = ["http://feeds.feedburner.com/raymondcamdensblog","http://www.cflib.org/rss","http://feeds.feedburner.com/ColdfusionbloggersorgFeed"];
threads = [];
//for each feed, use a thread to fetch rss
feeds.each(function(f,x) {
var name = "get_#x#";
threads.append(name);
cfthread(name=name,feed=f) {
cffeed(action="read", source=attributes.feed, query="feed");
thread.feed = feed;
}
});
cfthread(action="join",name=threads.toList());
//copy thread queries out and create sql merge statement
sql = "";
feeds.each(function(f,x) {
variables["feed#x#"] = cfthread["get_#x#"].feed;
if(x > 1) {
sql &= " union ";
}
sql &= "select * from feed#x#";
});
merged = queryExecute(sql,{},{dbtype:"query"});
//credit Vince Collins: https://vincentcollins.wordpress.com/2008/02/22/cffeed-dont-forget-you-can-cast-the-resulting-query-column/
merged = queryExecute("select content, title, rsslink, cast(publisheddate as date) as publisheddate from merged order by publisheddate desc", {}, {dbtype:"query"});
writedump(var=merged,top=20);
I hope this helps!
Archived Comments
What are you using here a function? I am trying to understand the syntax. Your syntax is: cffeed(action="read", source="http://feeds.feedburner.com...", query="feed");
writeDump(feed);
Mine: feedservice = new feed();
myFeed = feedservice.read(source='http://www.linkworxseo.word..., query='rssFeed');
Is your syntax because Railo, Ruby, Lucee or because it is CF!! or function?
I tried doing it with your syntax by placing the action, source, query but get no output. When I try using my method it actually works without errors but if I add the query attribute it does not produce results when doing a WriteDump(rssFeed);
Guess I am trying to understand why my syntax does not work properly since the example shows it as the proper way to set the query string.
Help!!!! :)
I already figured out what it was lacking. The .Query appended to the end of the variable.
feedservice = new feed();
rssFeed = feedservice.read(source='http://www.linkworxseo.word..., query='rssFeed').Query;
Although I am still wanting to know about what your syntax is about?
Link, the syntax, x = new feed(), comes from the fact that Adobe built CFCs to do Feed, Queries, HTTP, and something else too, I can't remember. This was done *before* they built a solution to allow all tags to be used in script. It is the old solution, and was pretty buggy. Hence me saying you should be used the tags as function stuff now. I believe Lucee supports this too.
If you tried my cffeed call and got not output, that's expected. cffeed doesn't generate output - it generates variables. Try dumping feed.
Again - see my other note. You should move away from this feature as soon as possible.
Okay, right now I got past that portion of it, but I now have been using a do while loop to fetch the category label column and trying to find a way to loop through the items which are a complex string. I am trying to create a separate link for each category in the list.
I managed to find a way to get any category/tag from the fourth column, but I need it to be able to get each one from the column in a loop method without manually coding it to listGetAt() for each one.
I can get the entire list of the categories, but I need those to be separate because they need to be a separate link for each one so the user can select the link to the blog by category/tag.
Any suggestions?
I honestly can't tell what you are asking now. Are you asking how to loop over a list? Because that's pretty simple, right?
No, looping a list is not the problem. As long as I have been doing this, you should know that by now. I am trying to fetch each label from the categorylabel column for an RSS Feed. Each label has to be separate so it can be established as a href link.
Ok, so what does categorylabel look like? Give me an example.
This is the output for the column categorylabel:
BLOGGING,blogging,review,seo,stats,wordpress
Each one of these needs to be a single entity to be placed as a link. Another words each one would need to be queried separately for purpose of making each one a link.
Ouch - I asked you to tell me just the one thing - not share all that code. ;) Please rephrase this into something simpler and one line. I want you to show me what the value of categorylabel is (one sample value) and explain what you want to do with it.
Here is what I can come up with after talking to you and finding a different form of loop to dot it. Except each one would be set separately. I would have to manually code each one. So if there were more than the number of records/labels on the blog post, those would not get displayed/output because the count would not match.
catQuery = queryNew("category");
queryAddRow(catQuery);
querySetCell(catQuery, 'category', '#ListGetAt(rssFeed.CATEGORYLABEL[1],1)#');
queryAddRow(catQuery);
querySetCell(catQuery, 'category', '#ListGetAt(rssFeed.CATEGORYLABEL[2],1)#');
queryAddRow(catQuery);
querySetCell(catQuery, 'category', '#ListGetAt(rssFeed.CATEGORYLABEL[3],1)#');
for ( row in catQuery ) {
writeOutput("a itemprop='url' href='#metadata.link#/category/#lCase(ReReplace(row.category, ' ', '-', 'all'))#' title='#lCase(row.category)#' class='feedBlock'>#lCase(row.category)# a>");
}
So is it working then? I keep asking you to show me an example of the data and what you want to do with it but you don't want to do that I think. :)
I get it, you want a link to what is going on?
http://www.linkworxseo.info
Yes, I managed to get it with the method shown in the previous post.
If you got it working - then I'm good. :)
Yes, after four day's I got it finished. You always seem to spark some kind of programming idea when I start to ask you for help. Not sure what it is, but on just about every occasion I start to request help from you I end up coming to an answer and or solution. It must just be from inspiration and I know your style fairly well along with the fact the more I write about it the better. Writing it out seems to help usually. :) Big Smiles - Thank you.
Glad to have been a help!