feed_format = 'atom1.0'; } else { $this->feed_format = 'rss2.0'; } } /** * Sets the channel information for the RSS feed. * * @param array The channel information */ function set_channel($channel) { $this->channel = $channel; } /** * Adds an item to the RSS feed. * * @param array The item. */ function add_item($item) { $this->items[] = $item; } /** * Generate and echo XML for the feed. * */ function generate_feed() { global $lang; // First, add the feed metadata. switch($this->feed_format) { // Ouput an Atom 1.0 formatted feed. case "atom1.0": $this->channel['date'] = gmdate("Y-m-d\TH:i:s\Z", $this->channel['date']); $this->xml .= "settings['charset']}\"?>\n"; $this->xml .= "\n"; $this->xml .= "\t<![CDATA[".$this->sanitize_content($this->channel['title'])."]]>\n"; $this->xml .= "\tsanitize_content($this->channel['description'])."]]>\n"; $this->xml .= "\tchannel['link']}syndication.php\"/>\n"; $this->xml .= "\t{$this->channel['link']}\n"; $this->xml .= "\tchannel['link']}\"/>\n"; $this->xml .= "\t{$this->channel['date']}\n"; $this->xml .= "\tMyBB\n"; break; // The default is the RSS 2.0 format. default: $this->channel['date'] = gmdate("D, d M Y H:i:s O", $this->channel['date']); $this->xml .= "settings['charset']}\"?>\n"; $this->xml .= "\n"; $this->xml .= "\t\n"; $this->xml .= "\t\t<![CDATA[".$this->sanitize_content($this->channel['title'])."]]>\n"; $this->xml .= "\t\t".$this->channel['link']."\n"; $this->xml .= "\t\tsanitize_content($this->channel['description'])."]]>\n"; $this->xml .= "\t\t".$this->channel['date']."\n"; $this->xml .= "\t\tMyBB\n"; } // Now loop through all of the items and add them to the feed XML. foreach($this->items as $item) { if(!$item['date']) { $item['date'] = TIME_NOW; } switch($this->feed_format) { // Output Atom 1.0 format feed. case "atom1.0": $item['date'] = date("Y-m-d\TH:i:s\Z", $item['date']); $this->xml .= "\t\n"; if(!empty($item['author'])) { $this->xml .= "\t\t\n"; $this->xml .= "\t\t\tsanitize_content($item['author'])."]]>\n"; $this->xml .= "\t\t\n"; } $this->xml .= "\t\t{$item['date']}\n"; if(empty($item['updated'])) { $item['updated'] = $item['date']; } else { $item['updated'] = date("Y-m-d\TH:i:s\Z", $item['updated']); } $this->xml .= "\t\t{$item['updated']}\n"; $this->xml .= "\t\t\n"; $this->xml .= "\t\t{$item['link']}\n"; $this->xml .= "\t\t<![CDATA[".$this->sanitize_content($item['title'])."]]>\n"; $this->xml .= "\t\tsanitize_content($item['description'])."]]>\n"; $this->xml .= "\t\tfalse\n"; $this->xml .= "\t\n"; break; // The default is the RSS 2.0 format. default: $item['date'] = date("D, d M Y H:i:s O", $item['date']); $this->xml .= "\t\t\n"; $this->xml .= "\t\t\t<![CDATA[".$this->sanitize_content($item['title'])."]]>\n"; $this->xml .= "\t\t\t".$item['link']."\n"; $this->xml .= "\t\t\t".$item['date']."\n"; if($item['author']) { $this->xml .= "\t\t\tsanitize_content($item['author'])."]]>\n"; } $this->xml .= "\t\t\t".$item['link']."\n"; $this->xml .= "\t\t\t\n"; $this->xml .= "\t\t\t\n"; $this->xml .= "\t\t\n"; break; } } // Now, neatly end the feed XML. switch($this->feed_format) { case "atom1.0": $this->xml .= ""; break; default: $this->xml .= "\t\n"; $this->xml .= ""; } } /** * Sanitize content suitable for RSS feeds. * * @param string The string we wish to sanitize. * @return string The cleaned string. */ function sanitize_content($content) { $content = preg_replace("#&[^\s]([^\#])(?![a-z1-4]{1,10});#i", "&$1", $content); $content = str_replace("]]>", "]]]]>", $content); return $content; } /** * Output the feed XML. */ function output_feed() { global $lang; // Send an appropriate header to the browser. switch($this->feed_format) { case "atom1.0": header("Content-Type: application/atom+xml; charset=\"{$lang->settings['charset']}\""); break; default: header("Content-Type: text/xml; charset=\"{$lang->settings['charset']}\""); } // Output the feed XML. If the feed hasn't been generated, do so. if($this->xml) { echo $this->xml; } else { $this->generate_feed(); echo $this->xml; } } } ?>