asgarosforum = $object;
add_action('asgarosforum_wp_head', array($this, 'add_feed_link'));
add_action('asgarosforum_bottom_navigation', array($this, 'show_feed_navigation'), 20, 1);
add_action('asgarosforum_prepare_topic', array($this, 'render_feed'));
add_action('asgarosforum_prepare_forum', array($this, 'render_feed'));
}
public function is_feed_enabled() {
$is_feed_enabled = false;
// Return false, if the functionality is disabled.
if ($this->asgarosforum->options['enable_rss'] === true) {
$is_feed_enabled = true;
}
$is_feed_enabled = apply_filters('asgarosforum_overwrite_is_feed_enabled', $is_feed_enabled);
return $is_feed_enabled;
}
public function add_feed_link() {
if ($this->is_feed_enabled()) {
switch ($this->asgarosforum->current_view) {
case 'topic':
$title = $this->asgarosforum->current_topic_name.' – '.$this->asgarosforum->options['forum_title'];
$link = $this->asgarosforum->rewrite->get_link('topic', $this->asgarosforum->current_topic, array('showfeed' => 'rss2'));
echo ''.PHP_EOL;
break;
case 'forum':
$title = $this->asgarosforum->current_forum_name.' – '.$this->asgarosforum->options['forum_title'];
$link = $this->asgarosforum->rewrite->get_link('forum', $this->asgarosforum->current_forum, array('showfeed' => 'rss2'));
echo ''.PHP_EOL;
break;
}
}
}
public function show_feed_navigation($current_view) {
if ($this->is_feed_enabled()) {
switch ($current_view) {
case 'topic':
$link = $this->asgarosforum->rewrite->get_link('topic', $this->asgarosforum->current_topic, array('showfeed' => 'rss2'));
echo '';
echo ''.esc_html__('RSS Feed', 'asgaros-forum').'';
break;
case 'forum':
$link = $this->asgarosforum->rewrite->get_link('forum', $this->asgarosforum->current_forum, array('showfeed' => 'rss2'));
echo '';
echo ''.esc_html__('RSS Feed', 'asgaros-forum').'';
break;
}
}
}
public function render_feed() {
if ($this->is_feed_enabled() && !empty($_GET['showfeed'])) {
// Abort feed creation when an error occured.
if ($this->asgarosforum->error !== false) {
return;
}
header('Content-Type: '.feed_content_type('rss2').'; charset='.get_option('blog_charset'), true);
echo ''.PHP_EOL;
echo ''.PHP_EOL;
echo ''.PHP_EOL;
if ($this->asgarosforum->current_view === 'forum') {
echo ''.esc_html(stripslashes($this->asgarosforum->current_forum_name)).''.PHP_EOL;
echo ''.esc_url($this->asgarosforum->rewrite->get_link('forum', absint($this->asgarosforum->current_forum))).''.PHP_EOL;
} else if ($this->asgarosforum->current_view === 'topic') {
echo ''.esc_html(stripslashes($this->asgarosforum->current_topic_name)).''.PHP_EOL;
echo ''.esc_url($this->asgarosforum->rewrite->get_link('topic', absint($this->asgarosforum->current_topic))).''.PHP_EOL;
}
echo ''.esc_html($this->asgarosforum->current_description).''.PHP_EOL;
echo ''.esc_html(get_bloginfo('language')).''.PHP_EOL;
echo ''.esc_html(mysql2date('D, d M Y H:i:s +0000', gmdate('Y-m-d H:i:s'), false)).''.PHP_EOL;
echo 'Asgaros Forum'.PHP_EOL;
echo '60'.PHP_EOL;
echo ''.PHP_EOL;
$feed_data = false;
if ($this->asgarosforum->current_view === 'forum') {
$query_post_content = "SELECT p.text FROM {$this->asgarosforum->tables->posts} AS p WHERE p.parent_id = t.id ORDER BY p.id ASC LIMIT 1";
$query_post_date = "SELECT p.date FROM {$this->asgarosforum->tables->posts} AS p WHERE p.parent_id = t.id ORDER BY p.id ASC LIMIT 1";
$feed_data = $this->asgarosforum->db->get_results("SELECT t.id, t.name, ({$query_post_content}) AS text, ({$query_post_date}) AS date, t.author_id FROM {$this->asgarosforum->tables->topics} AS t WHERE t.parent_id = {$this->asgarosforum->current_forum} AND t.approved = 1 ORDER BY t.id DESC LIMIT 0, 50;");
} else if ($this->asgarosforum->current_view === 'topic') {
$feed_data = $this->asgarosforum->db->get_results("SELECT p.id, p.parent_id, t.name, p.date, p.text, p.author_id FROM {$this->asgarosforum->tables->posts} AS p, {$this->asgarosforum->tables->topics} AS t WHERE p.parent_id = {$this->asgarosforum->current_topic} AND t.id = p.parent_id ORDER BY p.id DESC LIMIT 0, 50;");
}
if (!empty($feed_data)) {
foreach ($feed_data as $element) {
echo '- '.PHP_EOL;
echo ''.esc_html(stripslashes($element->name)).''.PHP_EOL;
if ($this->asgarosforum->current_view === 'forum') {
echo ''.esc_url($this->asgarosforum->rewrite->get_link('topic', absint($element->id))).''.PHP_EOL;
} else if ($this->asgarosforum->current_view === 'topic') {
echo ''.esc_url($this->asgarosforum->rewrite->get_post_link($element->id, absint($element->parent_id))).''.PHP_EOL;
}
echo ''.esc_html(mysql2date('D, d M Y H:i:s +0000', $element->date, false)).''.PHP_EOL;
echo 'text)).']]>'.PHP_EOL;
echo ''.esc_html($this->asgarosforum->get_plain_username($element->author_id)).''.PHP_EOL;
if ($this->asgarosforum->current_view === 'forum') {
echo ''.esc_url($this->asgarosforum->rewrite->get_link('topic', absint($element->id))).''.PHP_EOL;
} else if ($this->asgarosforum->current_view === 'topic') {
echo ''.esc_url($this->asgarosforum->rewrite->get_post_link($element->id, $element->parent_id)).''.PHP_EOL;
}
echo '
'.PHP_EOL;
}
}
echo ''.PHP_EOL;
echo ''.PHP_EOL;
exit;
}
}
}