ExportToRSS

The Contact Form DB ExportToRSS class.

Defined (1)

The class is defined in the following location(s).

/ExportToRSS.php  
  1. class ExportToRSS extends ExportBase implements CFDBExport { 
  2.  
  3. public function export($formName, $options = null) { 
  4. $this->setOptions($options); 
  5. $this->setCommonOptions(true); 
  6.  
  7. // Security Check 
  8. if (get_option('CF7DBPlugin_AllowRSS') !== 'true') { 
  9. if (!$this->isAuthorized()) { 
  10. $this->assertSecurityErrorMessage(); 
  11. return; 
  12.  
  13. $contentType = 'Content-Type: application/rss+xml; charset=UTF-8'; 
  14. $this->echoHeaders($contentType); 
  15.  
  16. // Get the data 
  17. $this->setDataIterator($formName); 
  18.  
  19. if ($this->isFromShortCode) { 
  20. ob_start(); 
  21.  
  22. $this->echoRSS($formName); 
  23.  
  24. if ($this->isFromShortCode) { 
  25. // If called from a shortcode, need to return the text,  
  26. // otherwise it can appear out of order on the page 
  27. $output = ob_get_contents(); 
  28. ob_end_clean(); 
  29. return $output; 
  30.  
  31. protected function echoRSS($formName) { 
  32.  
  33. $rssUrl = get_site_url() . $_SERVER['REQUEST_URI']; 
  34. $escapedRssUrl = htmlspecialchars($rssUrl); 
  35. $htmlVersionOfRss = get_site_url() . str_replace('enc=RSS', 'enc=HTML', $_SERVER['REQUEST_URI']); 
  36. $htmlSingleRow = $htmlVersionOfRss; 
  37.  
  38. // Set up $htmlSingleRow to have a "{submit_time}" value to be string replaced later 
  39. if (strpos($htmlSingleRow, 'filter=') === false) { 
  40. $htmlSingleRow .= '&filter=submit_time={submit_time}'; 
  41. else { 
  42. $htmlSingleRow = str_replace('filter=', 'filter=submit_time={submit_time}' . urlencode('&&'), $htmlSingleRow); 
  43.  
  44.  
  45. $this->setTimezone(); 
  46. $dateString = date('r'); 
  47.  
  48. $titleColunm = 'Submitted'; 
  49. if (isset($this->options['itemtitle'])) { 
  50. $titleColunm = $this->options['itemtitle']; 
  51.  
  52. echo '<?xml version="1.0" encoding="UTF-8" ?>'; 
  53. ?> 
  54.  
  55. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
  56. <channel> 
  57. <title><?php echo htmlspecialchars($formName) ?></title> 
  58. <description>Contact Form DB plugin Submissions</description> 
  59. <link><?php echo $escapedRssUrl ?></link> 
  60. <lastBuildDate><?php echo $dateString ?></lastBuildDate> 
  61. <pubDate><?php echo $dateString ?></pubDate> 
  62. <atom:link href="<?php echo $escapedRssUrl; ?>" rel="self" type="application/rss+xml" /> 
  63. <ttl>60</ttl><?php 
  64. while ($this->dataIterator->nextRow()) {?> 
  65.  
  66. <item> 
  67. <title><?php echo $this->dataIterator->row[$titleColunm]; ?></title> 
  68. <description><?php 
  69. $rowUrl = htmlspecialchars(str_replace('{submit_time}', $this->dataIterator->row['submit_time'], $htmlSingleRow)); 
  70. foreach ($this->dataIterator->getDisplayColumns() as $aCol) { 
  71. if ($aCol != 'Submitted') { 
  72. $cell = htmlspecialchars($this->dataIterator->row[$aCol], null, 'UTF-8'); 
  73. echo "$aCol=$cell \n"; 
  74. ?></description> 
  75. <link><?php echo $rowUrl; ?></link> 
  76. <guid><?php echo $rowUrl ?></guid> 
  77. <pubDate><?php echo date('r', $this->dataIterator->row['submit_time']); ?></pubDate> 
  78. </item> 
  79. <?php 
  80. }?> 
  81. </channel> 
  82. </rss> 
  83. <?php 
  84.  
  85. protected function setTimezone() 
  86. if (function_exists('get_option')) { 
  87. $tz = get_option('CF7DBPlugin_Timezone'); // see CFDBPlugin->setTimezone() 
  88. if (!$tz) { 
  89. $tz = get_option('timezone_string'); 
  90. if ($tz) { 
  91. date_default_timezone_set($tz);