Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <cfscript>
  2. /* ********************************************************************************
  3.     Use feed to Read a Wordpress blog feed and return a Query object
  4. */
  5. try {
  6.     f = new feed();
  7.     rsBlog = f.read(source="path.to/feed").Query;
  8. }
  9. catch (any excpt) {
  10.     // Create an Empty Query object
  11.     rsBlog = QueryNew("
  12.         ID, IDPermaLink, RSSLink, PublishedDate, Title, Content,
  13.         Body, Source, Link, UpdatedDate, CategoryLabel
  14.     ");
  15. }
  16.  
  17. /* ********************************************************************************
  18.     Execute an SQL Query to get recent News Stories from a MySQL database
  19. */
  20. try {
  21.     // Create new Query Object, add the datasource
  22.     query = new Query();
  23.     query.setDataSource(APPLICATION.DSN);
  24.     // SQL
  25.     query.setSQL("
  26.         SELECT CONCAT('http://path.to/news.cfm?ID=', CAST(ID AS CHAR)) AS ID,
  27.             0 AS IDPermaLink, CONCAT('http://path.to/news.cfm?ID=',
  28.             CAST(ID AS CHAR)) AS RSSLink,
  29.             CreatedTime AS PublishedDate, Title, Summary AS Content,
  30.             Body, Source, Link, ModifiedTime AS UpdatedDate,
  31.             'Trade News' AS CategoryLabel
  32.         FROM News
  33.         ORDER BY CreatedTime DESC
  34.         LIMIT 30
  35.     ");
  36.     // Execute SQL command and get the Resulting Query object
  37.     rsNews = query.Execute().getResult();
  38. }
  39. catch (any excpt) {
  40.     // Create an Empty Query object
  41.     rsNews = QueryNew("
  42.         ID, IDPermaLink, RSSLink, PublishedDate, Title, Content,
  43.         Body, Source, Link, UpdatedDate, CategoryLabel
  44.     ");
  45.  
  46. }
  47. /* ********************************************************************************
  48.     Query of Queries - Union of rsBlog and rsNews
  49. */
  50. try {
  51.     // Create new Query Object, add the datasource, add parameter(s)
  52.     query = new Query();
  53.     // Add queries to support Query of Queries
  54.     query.setAttributes(rsNews = rsNews);
  55.     query.setAttributes(rsBlog = rsBlog);
  56.     query.setAttributes(dbtype = "query");
  57.     // SQL
  58.     query.setSQL("
  59.         SELECT CAST(ID AS varchar) AS ID,
  60.             CAST(IDPermaLink AS varchar) AS IDPermaLink,
  61.             CAST(RSSLink AS varchar) AS RSSLink,
  62.             CAST(PublishedDate AS timestamp) AS PublishedDate,
  63.             CAST(Title AS varchar) AS Title,
  64.             CAST(Content AS varchar) AS Content,
  65.             CAST(CategoryLabel AS varchar) AS CategoryLabel
  66.         FROM rsBlog
  67.         UNION
  68.         SELECT CAST(ID AS varchar) AS ID,
  69.             CAST(IDPermaLink AS varchar) AS IDPermaLink,
  70.             CAST(RSSLink AS varchar) AS RSSLink,
  71.             CAST(PublishedDate AS timestamp) AS PublishedDate,
  72.             CAST(Title AS varchar) AS Title,
  73.             CAST(Content AS varchar) AS Content,
  74.             CAST(CategoryLabel AS varchar) AS CategoryLabel
  75.         FROM rsNews
  76.         ORDER By PublishedDate DESC
  77.     ");
  78.     // Execute SQL command and get the Resulting Query object
  79.     rsUnion = query.Execute().getResult();
  80. }
  81. catch (any excpt) {
  82.     // Create an Empty Query object
  83.     rsUnion = QueryNew("
  84.         ID, IDPermaLink, RSSLink, PublishedDate, Title, Content,
  85.         Body, Source, Link, UpdatedDate, CategoryLabel
  86.     ");
  87.  
  88. }
  89.  
  90. /* ********************************************************************************
  91.     Setup Structs for RSS Feed Creation
  92. */
  93.     myStruct = StructNew();
  94.     mystruct.link = "http://path.to/";
  95.     myStruct.title = "Combined Trade News Feed";
  96.     mystruct.description = "Trade news stories of interest.";
  97.     mystruct.pubDate = Now();
  98.     mystruct.version = "rss_2.0";
  99.    
  100.     // Map the data query column names to the feed query column names.
  101.     columnMapStruct = StructNew();
  102.     columnMapStruct.id = "ID";
  103.     columnMapStruct.idpermalink = "IDPermaLink";
  104.     columnMapStruct.rsslink = "RSSLink";
  105.     columnMapStruct.publisheddate = "PublishedDate";
  106.     columnMapStruct.title = "Title";
  107.     columnMapStruct.content = "Content";
  108.     columnMapStruct.categorylabel = "CategoryLabel";
  109.    
  110. /* ********************************************************************************
  111.     Create RSS Feed
  112. */
  113. try {
  114.     f = new feed();
  115.     f.setAttributes(query = rsUnion);
  116.     f.setAttributes(properties = myStruct);
  117.     f.setAttributes(columnMap = columnMapStruct);
  118.     f.setAttributes(outputfile = ExpandPath("TradeNews.xml"));
  119.     f.setAttributes(overwrite = "yes");
  120.     NewsRSS = f.create(); // create the RSS feed and assign it to a variable
  121. }
  122. catch (any excpt) {
  123.     NewsRSS = xmlNew();
  124. }
  125. // Specify the MIME Type and write out the news feed
  126. getpagecontext().getresponse().setcontenttype('application/xml');
  127. writeoutput(NewsRSS);
  128. </cfscript>