Zeile 18 | Zeile 18 |
---|
public $feed_format = 'rss2.0';
/**
|
public $feed_format = 'rss2.0';
/**
|
* The XML to output.
| * The feed to output.
|
* * @var string */
|
* * @var string */
|
public $xml = "";
| public $feed = "";
|
/** * Array of all of the items
| /** * Array of all of the items
|
Zeile 41 | Zeile 41 |
---|
/** * Set the type of feed to be used. *
|
/** * Set the type of feed to be used. *
|
* @param string The feed type.
| * @param string $feed_format The feed type.
|
*/ function set_feed_format($feed_format) {
|
*/ function set_feed_format($feed_format) {
|
if($feed_format == 'atom1.0')
| if($feed_format == 'json')
|
{
|
{
|
$this->feed_format = 'atom1.0';
| $this->feed_format = 'json'; } elseif($feed_format == 'atom1.0') { $this->feed_format = 'atom1.0';
|
} else {
| } else {
|
Zeile 58 | Zeile 62 |
---|
/** * Sets the channel information for the RSS feed. *
|
/** * Sets the channel information for the RSS feed. *
|
* @param array The channel information
| * @param array $channel The channel information
|
*/ function set_channel($channel)
|
*/ function set_channel($channel)
|
{
| {
|
$this->channel = $channel;
|
$this->channel = $channel;
|
}
/**
| }
/**
|
* Adds an item to the RSS feed. *
|
* Adds an item to the RSS feed. *
|
* @param array The item.
| * @param array $item The item.
|
*/ function add_item($item) { $this->items[] = $item;
|
*/ function add_item($item) { $this->items[] = $item;
|
}
/** * Generate and echo XML for the feed.
| }
/** * Generate the feed.
|
* */ function generate_feed()
| * */ function generate_feed()
|
Zeile 86 | Zeile 90 |
---|
// First, add the feed metadata. switch($this->feed_format) {
|
// First, add the feed metadata. switch($this->feed_format) {
|
// Ouput an Atom 1.0 formatted feed.
| // Ouput JSON formatted feed. case "json": $this->feed .= "{\n\t\"version\": ".json_encode('https://jsonfeed.org/version/1').",\n"; $this->feed .= "\t\"title\": \"".$this->channel['title']."\",\n"; $this->feed .= "\t\"home_page_url\": ".json_encode($this->channel['link']).",\n"; $this->feed .= "\t\"feed_url\": ".json_encode($this->channel['link']."syndication.php").",\n"; $this->feed .= "\t\"description\": ".json_encode($this->channel['description']).",\n"; $this->feed .= "\t\"items\": [\n"; $serial = 0; break; // Ouput Atom 1.0 formatted feed.
|
case "atom1.0": $this->channel['date'] = gmdate("Y-m-d\TH:i:s\Z", $this->channel['date']);
|
case "atom1.0": $this->channel['date'] = gmdate("Y-m-d\TH:i:s\Z", $this->channel['date']);
|
$this->xml .= "<?xml version=\"1.0\" encoding=\"{$lang->settings['charset']}\"?>\n"; $this->xml .= "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; $this->xml .= "\t<title type=\"html\"><![CDATA[".$this->sanitize_content($this->channel['title'])."]]></title>\n"; $this->xml .= "\t<subtitle type=\"html\"><![CDATA[".$this->sanitize_content($this->channel['description'])."]]></subtitle>\n"; $this->xml .= "\t<link rel=\"self\" href=\"{$this->channel['link']}syndication.php\"/>\n"; $this->xml .= "\t<id>{$this->channel['link']}</id>\n"; $this->xml .= "\t<link rel=\"alternate\" type=\"text/html\" href=\"{$this->channel['link']}\"/>\n"; $this->xml .= "\t<updated>{$this->channel['date']}</updated>\n"; $this->xml .= "\t<generator uri=\"http://www.mybb.com\">MyBB</generator>\n";
| $this->feed .= "<?xml version=\"1.0\" encoding=\"{$lang->settings['charset']}\"?>\n"; $this->feed .= "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; $this->feed .= "\t<title type=\"html\"><![CDATA[".$this->sanitize_content($this->channel['title'])."]]></title>\n"; $this->feed .= "\t<subtitle type=\"html\"><![CDATA[".$this->sanitize_content($this->channel['description'])."]]></subtitle>\n"; $this->feed .= "\t<link rel=\"self\" href=\"{$this->channel['link']}syndication.php\"/>\n"; $this->feed .= "\t<id>{$this->channel['link']}</id>\n"; $this->feed .= "\t<link rel=\"alternate\" type=\"text/html\" href=\"{$this->channel['link']}\"/>\n"; $this->feed .= "\t<updated>{$this->channel['date']}</updated>\n"; $this->feed .= "\t<generator uri=\"https://mybb.com\">MyBB</generator>\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']);
|
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 .= "<?xml version=\"1.0\" encoding=\"{$lang->settings['charset']}\"?>\n"; $this->xml .= "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; $this->xml .= "\t<channel>\n"; $this->xml .= "\t\t<title><![CDATA[".$this->sanitize_content($this->channel['title'])."]]></title>\n"; $this->xml .= "\t\t<link>".$this->channel['link']."</link>\n"; $this->xml .= "\t\t<description><![CDATA[".$this->sanitize_content($this->channel['description'])."]]></description>\n"; $this->xml .= "\t\t<pubDate>".$this->channel['date']."</pubDate>\n"; $this->xml .= "\t\t<generator>MyBB</generator>\n";
| $this->feed .= "<?xml version=\"1.0\" encoding=\"{$lang->settings['charset']}\"?>\n"; $this->feed .= "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; $this->feed .= "\t<channel>\n"; $this->feed .= "\t\t<title><![CDATA[".$this->sanitize_content($this->channel['title'])."]]></title>\n"; $this->feed .= "\t\t<link>".$this->channel['link']."</link>\n"; $this->feed .= "\t\t<description><![CDATA[".$this->sanitize_content($this->channel['description'])."]]></description>\n"; $this->feed .= "\t\t<pubDate>".$this->channel['date']."</pubDate>\n"; $this->feed .= "\t\t<generator>MyBB</generator>\n";
|
}
|
}
|
// Now loop through all of the items and add them to the feed XML.
| // Now loop through all of the items and add them to the feed.
|
foreach($this->items as $item) { if(!$item['date'])
| foreach($this->items as $item) { if(!$item['date'])
|
Zeile 121 | Zeile 135 |
---|
} switch($this->feed_format) {
|
} switch($this->feed_format) {
|
// Output Atom 1.0 format feed.
| // Output JSON formatted feed. case "json": ++$serial; $end = $serial < count($this->items) ? "," : ""; $item_id = explode('tid=', $item['link']); if(empty($item['updated'])) { $item['updated'] = $item['date']; } $this->feed .= "\t\t{\n"; $this->feed .= "\t\t\t\"id\": \"".end($item_id)."\",\n"; $this->feed .= "\t\t\t\"url\": ".json_encode($item['link']).",\n"; $this->feed .= "\t\t\t\"title\": ".json_encode($item['title']).",\n"; if(!empty($item['author'])) { $this->feed .= "\t\t\t\"author\": {\n\t\t\t\t\"name\": ".json_encode($item['author']['name']).",\n"; $this->feed .= "\t\t\t\t\"url\": ".json_encode($this->channel['link']."member.php?action=profile&uid=".$item['author']['uid'])."\n"; $this->feed .= "\t\t\t},\n"; } $this->feed .= "\t\t\t\"content_html\": ".json_encode($item['description']).",\n"; $this->feed .= "\t\t\t\"date_published\": \"".date('c', $item['date'])."\",\n"; $this->feed .= "\t\t\t\"date_modified \": \"".date('c', $item['updated'])."\"\n"; $this->feed .= "\t\t}".$end."\n"; break; // Output Atom 1.0 formatted feed.
|
case "atom1.0": $item['date'] = date("Y-m-d\TH:i:s\Z", $item['date']);
|
case "atom1.0": $item['date'] = date("Y-m-d\TH:i:s\Z", $item['date']);
|
$this->xml .= "\t<entry xmlns=\"http://www.w3.org/2005/Atom\">\n";
| $this->feed .= "\t<entry xmlns=\"http://www.w3.org/2005/Atom\">\n";
|
if(!empty($item['author'])) {
|
if(!empty($item['author'])) {
|
$this->xml .= "\t\t<author>\n"; $this->xml .= "\t\t\t<name type=\"html\" xml:space=\"preserve\"><![CDATA[".$this->sanitize_content($item['author'])."]]></name>\n"; $this->xml .= "\t\t</author>\n";
| $author = "<a href=\"".$this->channel['link']."member.php?action=profile&uid=".$item['author']['uid']."\">".$item['author']['name']."</a>"; $this->feed .= "\t\t<author>\n"; $this->feed .= "\t\t\t<name type=\"html\" xml:space=\"preserve\"><![CDATA[".$this->sanitize_content($author)."]]></name>\n"; $this->feed .= "\t\t</author>\n";
|
}
|
}
|
$this->xml .= "\t\t<published>{$item['date']}</published>\n";
| $this->feed .= "\t\t<published>{$item['date']}</published>\n";
|
if(empty($item['updated'])) { $item['updated'] = $item['date'];
| if(empty($item['updated'])) { $item['updated'] = $item['date'];
|
Zeile 139 | Zeile 178 |
---|
else { $item['updated'] = date("Y-m-d\TH:i:s\Z", $item['updated']);
|
else { $item['updated'] = date("Y-m-d\TH:i:s\Z", $item['updated']);
|
} $this->xml .= "\t\t<updated>{$item['updated']}</updated>\n"; $this->xml .= "\t\t<link rel=\"alternate\" type=\"text/html\" href=\"{$item['link']}\" />\n"; $this->xml .= "\t\t<id>{$item['link']}</id>\n"; $this->xml .= "\t\t<title type=\"html\" xml:space=\"preserve\"><![CDATA[".$this->sanitize_content($item['title'])."]]></title>\n"; $this->xml .= "\t\t<content type=\"html\" xml:space=\"preserve\" xml:base=\"{$item['link']}\"><![CDATA[".$this->sanitize_content($item['description'])."]]></content>\n"; $this->xml .= "\t\t<draft xmlns=\"http://purl.org/atom-blog/ns#\">false</draft>\n"; $this->xml .= "\t</entry>\n"; break;
| } $this->feed .= "\t\t<updated>{$item['updated']}</updated>\n"; $this->feed .= "\t\t<link rel=\"alternate\" type=\"text/html\" href=\"{$item['link']}\" />\n"; $this->feed .= "\t\t<id>{$item['link']}</id>\n"; $this->feed .= "\t\t<title xml:space=\"preserve\"><![CDATA[".$this->sanitize_content($item['title'])."]]></title>\n"; $this->feed .= "\t\t<content type=\"html\" xml:space=\"preserve\" xml:base=\"{$item['link']}\"><![CDATA[".$this->sanitize_content($item['description'])."]]></content>\n"; $this->feed .= "\t\t<draft xmlns=\"http://purl.org/atom-blog/ns#\">false</draft>\n"; $this->feed .= "\t</entry>\n"; break;
|
// The default is the RSS 2.0 format. default: $item['date'] = date("D, d M Y H:i:s O", $item['date']);
|
// 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<item>\n"; $this->xml .= "\t\t\t<title><![CDATA[".$this->sanitize_content($item['title'])."]]></title>\n"; $this->xml .= "\t\t\t<link>".$item['link']."</link>\n"; $this->xml .= "\t\t\t<pubDate>".$item['date']."</pubDate>\n";
| $this->feed .= "\t\t<item>\n"; $this->feed .= "\t\t\t<title><![CDATA[".$this->sanitize_content($item['title'])."]]></title>\n"; $this->feed .= "\t\t\t<link>".$item['link']."</link>\n"; $this->feed .= "\t\t\t<pubDate>".$item['date']."</pubDate>\n";
|
if(!empty($item['author'])) {
|
if(!empty($item['author'])) {
|
$this->xml .= "\t\t\t<dc:creator><![CDATA[".$this->sanitize_content($item['author'])."]]></dc:creator>\n";
| $author = "<a href=\"".$this->channel['link']."member.php?action=profile&uid=".$item['author']['uid']."\">".$item['author']['name']."</a>"; $this->feed .= "\t\t\t<dc:creator><![CDATA[".$this->sanitize_content($author)."]]></dc:creator>\n";
|
}
|
}
|
$this->xml .= "\t\t\t<guid isPermaLink=\"false\">".$item['link']."</guid>\n"; $this->xml .= "\t\t\t<description><![CDATA[".$item['description']."]]></description>\n"; $this->xml .= "\t\t\t<content:encoded><![CDATA[".$item['description']."]]></content:encoded>\n"; $this->xml .= "\t\t</item>\n";
| $this->feed .= "\t\t\t<guid isPermaLink=\"false\">".$item['link']."</guid>\n"; $this->feed .= "\t\t\t<description><![CDATA[".$item['description']."]]></description>\n"; $this->feed .= "\t\t\t<content:encoded><![CDATA[".$item['description']."]]></content:encoded>\n"; $this->feed .= "\t\t</item>\n";
|
break; } }
|
break; } }
|
// Now, neatly end the feed XML.
| // Now, neatly end the feed.
|
switch($this->feed_format) {
|
switch($this->feed_format) {
|
| case "json": $this->feed .= "\t]\n}"; break;
|
case "atom1.0":
|
case "atom1.0":
|
$this->xml .= "</feed>";
| $this->feed .= "</feed>";
|
break; default:
|
break; default:
|
$this->xml .= "\t</channel>\n"; $this->xml .= "</rss>";
| $this->feed .= "\t</channel>\n"; $this->feed .= "</rss>";
|
} }
/** * Sanitize content suitable for RSS feeds. *
|
} }
/** * Sanitize content suitable for RSS feeds. *
|
* @param string The string we wish to sanitize.
| * @param string $string The string we wish to sanitize.
|
* @return string The cleaned string. */ function sanitize_content($content)
| * @return string The cleaned string. */ function sanitize_content($content)
|
Zeile 195 | Zeile 238 |
---|
}
/**
|
}
/**
|
* Output the feed XML.
| * Output the feed.
|
*/ function output_feed() {
| */ function output_feed() {
|
Zeile 203 | Zeile 246 |
---|
// Send an appropriate header to the browser. switch($this->feed_format) {
|
// Send an appropriate header to the browser. switch($this->feed_format) {
|
| case "json": header("Content-Type: application/json; charset=\"{$lang->settings['charset']}\""); break;
|
case "atom1.0": header("Content-Type: application/atom+xml; charset=\"{$lang->settings['charset']}\""); break;
| case "atom1.0": header("Content-Type: application/atom+xml; charset=\"{$lang->settings['charset']}\""); break;
|
Zeile 210 | Zeile 256 |
---|
header("Content-Type: text/xml; charset=\"{$lang->settings['charset']}\""); }
|
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)
| // If the feed hasn't been generated, do so. if($this->feed)
|
{
|
{
|
echo $this->xml;
| echo $this->feed;
|
} else { $this->generate_feed();
|
} else { $this->generate_feed();
|
echo $this->xml;
| echo $this->feed;
|
} } }
| } } }
|