PluginProbe
wpForo Forum / 2.4.2
wpForo Forum v2.4.2
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / classes / Feed.php

Feed.php in wpForo Forum 2.4.2, at classes/Feed.php

149 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\classes;
4 // Exit if accessed directly
5 if( ! defined( 'ABSPATH' ) ) exit;
6
7 class Feed {
8 function rss2_url( $echo = true, $general = false ) {
9 $url = wpforo_get_request_uri();
10 $url = preg_replace( '|\?.+$|is', '', $url );
11 if( isset( WPF()->current_object['forumid'] ) ) {
12 $forumid = WPF()->current_object['forumid'];
13 }
14 if( isset( WPF()->current_object['topicid'] ) ) {
15 $topicid = WPF()->current_object['topicid'];
16 }
17 if( isset( $forumid ) && isset( $topicid ) ) {
18 $rss2 = $url . '?type=rss2&forum=' . intval( $forumid ) . '&topic=' . intval( $topicid );
19 } elseif( isset( $forumid ) && ! isset( $topicid ) ) {
20 $rss2 = $url . '?type=rss2&forum=' . intval( $forumid );
21 }
22
23 if( $general ) {
24 if( $general == 'topic' ) {
25 $rss2 = $url . '?type=rss2&forum=g&topic=g';
26 } elseif( $general == 'forum' ) {
27 $rss2 = $url . '?type=rss2&forum=g';
28 }
29 }
30
31 $rss2 = esc_url( (string) $rss2 );
32
33 if( $echo ) {
34 echo $rss2;
35 } else {
36 return $rss2;
37 }
38 }
39
40 function rss2_forum( $forum = [], $topics = [] ) {
41 if( empty( $forum ) ) {
42 if( ! wpforo_setting( 'rss', 'feed' ) ) {
43 header( 'HTTP/1.0 404 Not Found', true, 404 );
44 die();
45 } else {
46 return;
47 }
48 }
49 header( "Content-Type: application/xml; charset" . get_option( 'blog_charset' ) );
50 echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
51 ?>
52 <rss version="2.0"
53 xmlns:atom="http://www.w3.org/2005/Atom"
54 xmlns:dc="http://purl.org/dc/elements/1.1/"
55 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
56 xmlns:admin="http://webns.net/mvcb/"
57 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
58 xmlns:content="http://purl.org/rss/1.0/modules/content/">
59 <channel>
60 <title>
61 <?php if( ! isset( $forum['title'] ) || ! $forum['title'] ): ?>
62 <?php echo esc_html( WPF()->board->get_current( 'settings' )['title'] ) . ' - ' . wpforo_phrase( 'Recent Topics', false ) ?>
63 <?php else: ?>
64 <?php echo esc_html( $forum['title'] ); ?> - <?php echo esc_html( WPF()->board->get_current( 'settings' )['title'] ); ?>
65 <?php endif; ?>
66 </title>
67 <link><?php echo esc_url( (string) $forum['forumurl'] ); ?></link>
68 <description><?php echo esc_html( WPF()->board->get_current( 'settings' )['desc'] ); ?></description>
69 <language><?php bloginfo_rss( 'language' ); ?></language>
70 <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', gmdate( 'Y-m-d H:i:s' ), false ); ?></lastBuildDate>
71 <generator>wpForo</generator>
72 <ttl>60</ttl>
73 <?php if( ! empty( $topics ) ): ?>
74 <?php foreach( $topics as $topic ): ?>
75 <item>
76 <title><?php echo wpforo_removebb( esc_html( $topic['title'] ) ); ?></title>
77 <link><?php echo esc_url( (string) $topic['topicurl'] ); ?></link>
78 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', $topic['created'], false ); ?></pubDate>
79 <description><![CDATA[<?php echo wpforo_removebb( esc_html( $topic['description'] ) ) ?>]]></description>
80 <content:encoded><![CDATA[<?php echo wpforo_removebb( $topic['content'] ) ?>]]></content:encoded>
81 <?php if( $forum['forumurl'] != '#' ): ?>
82 <category domain="<?php echo esc_url( (string) $forum['forumurl'] ); ?>"><?php echo esc_html( $forum['title'] ); ?></category><?php endif; ?>
83 <dc:creator><?php echo esc_html( $topic['author'] ); ?></dc:creator>
84 <guid isPermaLink="true"><?php echo esc_url( (string) $topic['topicurl'] ); ?></guid>
85 </item>
86 <?php endforeach; ?>
87 <?php endif; ?>
88 </channel>
89 </rss>
90 <?php
91 exit();
92 }
93
94 function rss2_topic( $forum = [], $topic = [], $posts = [] ) {
95 if( empty( $forum ) ) {
96 if( ! wpforo_setting( 'rss', 'feed' ) ) {
97 header( 'HTTP/1.0 404 Not Found', true, 404 );
98 die();
99 } else {
100 return;
101 }
102 }
103 header( "Content-Type: application/xml; charset" . get_option( 'blog_charset' ) );
104 echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
105 ?>
106 <rss version="2.0"
107 xmlns:atom="http://www.w3.org/2005/Atom"
108 xmlns:dc="http://purl.org/dc/elements/1.1/"
109 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
110 xmlns:admin="http://webns.net/mvcb/"
111 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
112 xmlns:content="http://purl.org/rss/1.0/modules/content/">
113 <channel>
114 <title>
115 <?php if( ! isset( $topic['title'] ) || ! $topic['title'] ): ?>
116 <?php echo esc_html( WPF()->board->get_current( 'settings' )['title'] ) . ' - ' . wpforo_phrase( 'Recent Posts', false ); ?>
117 <?php else: ?>
118 <?php echo esc_html( $topic['title'] ); ?> - <?php echo esc_html( wpfval( $forum, 'title' ) ); ?>
119 <?php endif; ?>
120 </title>
121 <link><?php echo esc_url( (string) $topic['topicurl'] ); ?></link>
122 <description><?php echo esc_html( WPF()->board->get_current( 'settings' )['desc'] ); ?></description>
123 <language><?php bloginfo_rss( 'language' ); ?></language>
124 <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', gmdate( 'Y-m-d H:i:s' ), false ); ?></lastBuildDate>
125 <generator>wpForo</generator>
126 <ttl>60</ttl>
127 <?php if( ! empty( $posts ) ): ?>
128 <?php foreach( $posts as $post ): ?>
129 <item>
130 <title><?php echo wpforo_removebb( esc_html( $post['title'] ) ); ?></title>
131 <link><?php echo esc_url( (string) $post['posturl'] ); ?></link>
132 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', $post['created'], false ); ?></pubDate>
133 <description><![CDATA[<?php echo wpforo_removebb( esc_html( $post['description'] ) ) ?>]]></description>
134 <content:encoded><![CDATA[<?php echo wpforo_removebb( $post['content'] ) ?>]]></content:encoded>
135 <?php if( wpfval( $forum, 'forumurl' ) != '#' ): ?>
136 <category domain="<?php echo esc_url( (string) wpfval( $forum, 'forumurl' ) ); ?>"><?php echo esc_html( wpfval( $forum, 'title' ) ); ?></category><?php endif; ?>
137 <dc:creator><?php echo esc_html( $post['author'] ); ?></dc:creator>
138 <guid isPermaLink="true"><?php echo esc_url( (string) $post['posturl'] ); ?></guid>
139 </item>
140 <?php endforeach; ?>
141 <?php endif; ?>
142 </channel>
143 </rss>
144 <?php
145 exit();
146 }
147
148 }
149