Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfscript>
- /* ********************************************************************************
- Use feed to Read a Wordpress blog feed and return a Query object
- */
- try {
- f = new feed();
- rsBlog = f.read(source="path.to/feed").Query;
- }
- catch (any excpt) {
- // Create an Empty Query object
- rsBlog = QueryNew("
- ID, IDPermaLink, RSSLink, PublishedDate, Title, Content,
- Body, Source, Link, UpdatedDate, CategoryLabel
- ");
- }
- /* ********************************************************************************
- Execute an SQL Query to get recent News Stories from a MySQL database
- */
- try {
- // Create new Query Object, add the datasource
- query = new Query();
- query.setDataSource(APPLICATION.DSN);
- // SQL
- query.setSQL("
- SELECT CONCAT('http://path.to/news.cfm?ID=', CAST(ID AS CHAR)) AS ID,
- 0 AS IDPermaLink, CONCAT('http://path.to/news.cfm?ID=',
- CAST(ID AS CHAR)) AS RSSLink,
- CreatedTime AS PublishedDate, Title, Summary AS Content,
- Body, Source, Link, ModifiedTime AS UpdatedDate,
- 'Trade News' AS CategoryLabel
- FROM News
- ORDER BY CreatedTime DESC
- LIMIT 30
- ");
- // Execute SQL command and get the Resulting Query object
- rsNews = query.Execute().getResult();
- }
- catch (any excpt) {
- // Create an Empty Query object
- rsNews = QueryNew("
- ID, IDPermaLink, RSSLink, PublishedDate, Title, Content,
- Body, Source, Link, UpdatedDate, CategoryLabel
- ");
- }
- /* ********************************************************************************
- Query of Queries - Union of rsBlog and rsNews
- */
- try {
- // Create new Query Object, add the datasource, add parameter(s)
- query = new Query();
- // Add queries to support Query of Queries
- query.setAttributes(rsNews = rsNews);
- query.setAttributes(rsBlog = rsBlog);
- query.setAttributes(dbtype = "query");
- // SQL
- query.setSQL("
- SELECT CAST(ID AS varchar) AS ID,
- CAST(IDPermaLink AS varchar) AS IDPermaLink,
- CAST(RSSLink AS varchar) AS RSSLink,
- CAST(PublishedDate AS timestamp) AS PublishedDate,
- CAST(Title AS varchar) AS Title,
- CAST(Content AS varchar) AS Content,
- CAST(CategoryLabel AS varchar) AS CategoryLabel
- FROM rsBlog
- UNION
- SELECT CAST(ID AS varchar) AS ID,
- CAST(IDPermaLink AS varchar) AS IDPermaLink,
- CAST(RSSLink AS varchar) AS RSSLink,
- CAST(PublishedDate AS timestamp) AS PublishedDate,
- CAST(Title AS varchar) AS Title,
- CAST(Content AS varchar) AS Content,
- CAST(CategoryLabel AS varchar) AS CategoryLabel
- FROM rsNews
- ORDER By PublishedDate DESC
- ");
- // Execute SQL command and get the Resulting Query object
- rsUnion = query.Execute().getResult();
- }
- catch (any excpt) {
- // Create an Empty Query object
- rsUnion = QueryNew("
- ID, IDPermaLink, RSSLink, PublishedDate, Title, Content,
- Body, Source, Link, UpdatedDate, CategoryLabel
- ");
- }
- /* ********************************************************************************
- Setup Structs for RSS Feed Creation
- */
- myStruct = StructNew();
- mystruct.link = "http://path.to/";
- myStruct.title = "Combined Trade News Feed";
- mystruct.description = "Trade news stories of interest.";
- mystruct.pubDate = Now();
- mystruct.version = "rss_2.0";
- // Map the data query column names to the feed query column names.
- columnMapStruct = StructNew();
- columnMapStruct.id = "ID";
- columnMapStruct.idpermalink = "IDPermaLink";
- columnMapStruct.rsslink = "RSSLink";
- columnMapStruct.publisheddate = "PublishedDate";
- columnMapStruct.title = "Title";
- columnMapStruct.content = "Content";
- columnMapStruct.categorylabel = "CategoryLabel";
- /* ********************************************************************************
- Create RSS Feed
- */
- try {
- f = new feed();
- f.setAttributes(query = rsUnion);
- f.setAttributes(properties = myStruct);
- f.setAttributes(columnMap = columnMapStruct);
- f.setAttributes(outputfile = ExpandPath("TradeNews.xml"));
- f.setAttributes(overwrite = "yes");
- NewsRSS = f.create(); // create the RSS feed and assign it to a variable
- }
- catch (any excpt) {
- NewsRSS = xmlNew();
- }
- // Specify the MIME Type and write out the news feed
- getpagecontext().getresponse().setcontenttype('application/xml');
- writeoutput(NewsRSS);
- </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement