| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( !defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
class wpForoFeed{ |
| 6 |
|
| 7 |
private $wpforo; |
| 8 |
|
| 9 |
function __construct( $wpForo ){ |
| 10 |
if(!isset($this->wpforo)) $this->wpforo = $wpForo; |
| 11 |
} |
| 12 |
|
| 13 |
function rss2_url(){ |
| 14 |
$url = wpforo_full_url( $echo = true ); |
| 15 |
if(isset($this->wpforo->current_object['forumid'])){ $forumid = $this->wpforo->current_object['forumid']; } |
| 16 |
if(isset($this->wpforo->current_object['topicid'])){ $topicid = $this->wpforo->current_object['topicid']; } |
| 17 |
if(isset($forumid) && isset($topicid)){ |
| 18 |
$rss2 = $url . '?type=rss2&forum=' . intval($forumid) . '&topic=' . intval($topicid); |
| 19 |
} |
| 20 |
elseif(isset($forumid) && !isset($topicid)){ |
| 21 |
$rss2 = $url . '?type=rss2&forum=' . intval($forumid); |
| 22 |
} |
| 23 |
|
| 24 |
$rss2 = esc_url($rss2); |
| 25 |
|
| 26 |
if($echo){ |
| 27 |
echo $rss2; |
| 28 |
} |
| 29 |
else{ |
| 30 |
return $rss2; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
function rss2_forum( $forum = array(), $topics = array() ){ |
| 35 |
if(empty($forum)) return; |
| 36 |
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true); |
| 37 |
echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; |
| 38 |
?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"> |
| 39 |
<channel> |
| 40 |
<title><?php echo esc_html($forum['title']); ?> - <?php echo esc_html($this->wpforo->general_options['title']); ?></title> |
| 41 |
<link><?php echo esc_url($forum['forumurl']); ?></link> |
| 42 |
<description><?php echo esc_html($this->wpforo->general_options['description']); ?></description> |
| 43 |
<language><?php bloginfo_rss( 'language' ); ?></language> |
| 44 |
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', date('Y-m-d H:i:s'), false); ?></lastBuildDate> |
| 45 |
<generator>wpForo</generator> |
| 46 |
<ttl>60</ttl> |
| 47 |
<?php if(!empty($topics)): ?> |
| 48 |
<?php foreach($topics as $topic): ?> |
| 49 |
<item> |
| 50 |
<title><?php echo wpforo_removebb(esc_html($topic['title'])); ?></title> |
| 51 |
<link><?php echo esc_url($topic['topicurl']); ?></link> |
| 52 |
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', $topic['created'], false); ?></pubDate> |
| 53 |
<description><![CDATA[<?php echo wpforo_removebb(esc_html($topic['description'])) ?>]]></description> |
| 54 |
<content:encoded><![CDATA[<?php echo wpforo_removebb(esc_html($topic['content'])) ?>]]></content:encoded> |
| 55 |
<category domain="<?php echo esc_url($forum['forumurl']); ?>"><?php echo esc_html($forum['title']); ?></category> |
| 56 |
<dc:creator><?php echo esc_html($topic['author']); ?></dc:creator> |
| 57 |
<guid isPermaLink="true"><?php echo esc_url($topic['topicurl']); ?></guid> |
| 58 |
</item> |
| 59 |
<?php endforeach; ?> |
| 60 |
<?php endif; ?> |
| 61 |
</channel> |
| 62 |
</rss> |
| 63 |
<?php |
| 64 |
exit(); |
| 65 |
} |
| 66 |
|
| 67 |
function rss2_topic( $forum = array(), $topic = array(), $posts = array() ){ |
| 68 |
if(empty($forum)) return; |
| 69 |
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true); |
| 70 |
echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; |
| 71 |
?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"> |
| 72 |
<channel> |
| 73 |
<title><?php echo esc_html($topic['title']); ?> - <?php echo esc_html($forum['title']); ?></title> |
| 74 |
<link><?php echo esc_url($topic['topicurl']); ?></link> |
| 75 |
<description><?php echo esc_html($this->wpforo->general_options['description']); ?></description> |
| 76 |
<language><?php bloginfo_rss( 'language' ); ?></language> |
| 77 |
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', date('Y-m-d H:i:s'), false); ?></lastBuildDate> |
| 78 |
<generator>wpForo</generator> |
| 79 |
<ttl>60</ttl> |
| 80 |
<?php if(!empty($posts)): ?> |
| 81 |
<?php foreach($posts as $post): ?> |
| 82 |
<item> |
| 83 |
<title><?php echo wpforo_removebb(esc_html($post['title'])); ?></title> |
| 84 |
<link><?php echo esc_url($post['posturl']); ?></link> |
| 85 |
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', $post['created'], false); ?></pubDate> |
| 86 |
<description><![CDATA[<?php echo wpforo_removebb(esc_html($post['description'])) ?>]]></description> |
| 87 |
<content:encoded><![CDATA[<?php echo wpforo_removebb(esc_html($post['content'])) ?>]]></content:encoded> |
| 88 |
<category domain="<?php echo esc_url($forum['forumurl']); ?>"><?php echo esc_html($forum['title']); ?></category> |
| 89 |
<dc:creator><?php echo esc_html($post['author']); ?></dc:creator> |
| 90 |
<guid isPermaLink="true"><?php echo esc_url($post['posturl']); ?></guid> |
| 91 |
</item> |
| 92 |
<?php endforeach; ?> |
| 93 |
<?php endif; ?> |
| 94 |
</channel> |
| 95 |
</rss> |
| 96 |
<?php |
| 97 |
exit(); |
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
?> |