phpBB
Statistics
| Revision:

root / trunk / phpBB / feed.php

History | View | Annotate | Download (36.4 kB)

1 9575 acydburn
<?php
2 9575 acydburn
/**
3 9575 acydburn
* @package phpBB3
4 9575 acydburn
* @copyright (c) 2009 phpBB Group
5 11653 git-gate
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
6 9575 acydburn
*
7 9575 acydburn
* Idea and original RSS Feed 2.0 MOD (Version 1.0.8/9) by leviatan21
8 9575 acydburn
* Original MOD: http://www.phpbb.com/community/viewtopic.php?f=69&t=1214645
9 9575 acydburn
* MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763
10 9575 acydburn
* MOD Author Homepage: http://www.mssti.com/phpbb3/
11 9575 acydburn
*
12 9575 acydburn
**/
13 9575 acydburn
14 9575 acydburn
/**
15 9575 acydburn
* @ignore
16 9575 acydburn
**/
17 9575 acydburn
define('IN_PHPBB', true);
18 9575 acydburn
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
19 9575 acydburn
$phpEx = substr(strrchr(__FILE__, '.'), 1);
20 9575 acydburn
include($phpbb_root_path . 'common.' . $phpEx);
21 9575 acydburn
22 9575 acydburn
if (!$config['feed_enable'])
23 9575 acydburn
{
24 9575 acydburn
        trigger_error('NO_FEED_ENABLED');
25 9575 acydburn
}
26 9575 acydburn
27 9575 acydburn
// Start session
28 9575 acydburn
$user->session_begin();
29 10558 git-gate
30 10558 git-gate
if (!empty($config['feed_http_auth']) && request_var('auth', '') == 'http')
31 10558 git-gate
{
32 10558 git-gate
        phpbb_http_login(array(
33 10558 git-gate
                'auth_message'        => 'Feed',
34 10558 git-gate
                'viewonline'        => request_var('viewonline', true),
35 10558 git-gate
        ));
36 10558 git-gate
}
37 10558 git-gate
38 9575 acydburn
$auth->acl($user->data);
39 9575 acydburn
$user->setup();
40 9575 acydburn
41 9575 acydburn
// Initial var setup
42 9575 acydburn
$forum_id        = request_var('f', 0);
43 9575 acydburn
$topic_id        = request_var('t', 0);
44 9575 acydburn
$mode                = request_var('mode', '');
45 9575 acydburn
46 9575 acydburn
// We do not use a template, therefore we simply define the global template variables here
47 9575 acydburn
$global_vars = $item_vars = array();
48 10342 acydburn
$feed_updated_time = 0;
49 9575 acydburn
50 9575 acydburn
// Generate params array for use in append_sid() to correctly link back to this page
51 10342 acydburn
$params = false;
52 9575 acydburn
if ($forum_id || $topic_id || $mode)
53 9575 acydburn
{
54 9575 acydburn
        $params = array(
55 9575 acydburn
                'f'                => ($forum_id) ? $forum_id : NULL,
56 9575 acydburn
                't'                => ($topic_id) ? $topic_id : NULL,
57 9575 acydburn
                'mode'        => ($mode) ? $mode : NULL,
58 9575 acydburn
        );
59 9575 acydburn
}
60 9575 acydburn
61 9575 acydburn
// This boards URL
62 9575 acydburn
$board_url = generate_board_url();
63 9575 acydburn
64 9575 acydburn
// Get correct feed object
65 9575 acydburn
$feed = phpbb_feed_factory::init($mode, $forum_id, $topic_id);
66 9575 acydburn
67 9575 acydburn
// No feed found
68 9575 acydburn
if ($feed === false)
69 9575 acydburn
{
70 9575 acydburn
        trigger_error('NO_FEED');
71 9575 acydburn
}
72 9575 acydburn
73 9575 acydburn
// Open Feed
74 9575 acydburn
$feed->open();
75 9575 acydburn
76 9575 acydburn
// Iterate through items
77 9575 acydburn
while ($row = $feed->get_item())
78 9575 acydburn
{
79 9575 acydburn
        // BBCode options to correctly disable urls, smilies, bbcode...
80 9575 acydburn
        if ($feed->get('options') === NULL)
81 9575 acydburn
        {
82 9575 acydburn
                // Allow all combinations
83 9575 acydburn
                $options = 7;
84 9575 acydburn
85 9575 acydburn
                if ($feed->get('enable_bbcode') !== NULL && $feed->get('enable_smilies') !== NULL && $feed->get('enable_magic_url') !== NULL)
86 9575 acydburn
                {
87 9575 acydburn
                        $options = (($row[$feed->get('enable_bbcode')]) ? OPTION_FLAG_BBCODE : 0) + (($row[$feed->get('enable_smilies')]) ? OPTION_FLAG_SMILIES : 0) + (($row[$feed->get('enable_magic_url')]) ? OPTION_FLAG_LINKS : 0);
88 9575 acydburn
                }
89 9575 acydburn
        }
90 9575 acydburn
        else
91 9575 acydburn
        {
92 9575 acydburn
                $options = $row[$feed->get('options')];
93 9575 acydburn
        }
94 9575 acydburn
95 10342 acydburn
        $title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : '');
96 9575 acydburn
97 11002 git-gate
        $published = ($feed->get('published') !== NULL) ? (int) $row[$feed->get('published')] : 0;
98 11002 git-gate
        $updated = ($feed->get('updated') !== NULL) ? (int) $row[$feed->get('updated')] : 0;
99 10342 acydburn
100 9575 acydburn
        $item_row = array(
101 9575 acydburn
                'author'                => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '',
102 11002 git-gate
                'published'                => ($published > 0) ? feed_format_date($published) : '',
103 11002 git-gate
                'updated'                => ($updated > 0) ? feed_format_date($updated) : '',
104 9575 acydburn
                'link'                        => '',
105 9575 acydburn
                'title'                        => censor_text($title),
106 10558 git-gate
                'category'                => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
107 10558 git-gate
                'category_name'        => ($config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '',
108 9575 acydburn
                'description'        => censor_text(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)),
109 9575 acydburn
                'statistics'        => '',
110 9575 acydburn
        );
111 9575 acydburn
112 9575 acydburn
        // Adjust items, fill link, etc.
113 9575 acydburn
        $feed->adjust_item($item_row, $row);
114 9575 acydburn
115 9575 acydburn
        $item_vars[] = $item_row;
116 10342 acydburn
117 11002 git-gate
        $feed_updated_time = max($feed_updated_time, $published, $updated);
118 9575 acydburn
}
119 9575 acydburn
120 10342 acydburn
// If we do not have any items at all, sending the current time is better than sending no time.
121 10342 acydburn
if (!$feed_updated_time)
122 10342 acydburn
{
123 10342 acydburn
        $feed_updated_time = time();
124 10342 acydburn
}
125 10342 acydburn
126 10342 acydburn
// Some default assignments
127 10342 acydburn
// FEED_IMAGE is not used (atom)
128 10342 acydburn
$global_vars = array_merge($global_vars, array(
129 11429 git-gate
        'FEED_IMAGE'                        => '',
130 10342 acydburn
        'SELF_LINK'                                => feed_append_sid('/feed.' . $phpEx, $params),
131 10342 acydburn
        'FEED_LINK'                                => $board_url . '/index.' . $phpEx,
132 10342 acydburn
        'FEED_TITLE'                        => $config['sitename'],
133 10342 acydburn
        'FEED_SUBTITLE'                        => $config['site_desc'],
134 10342 acydburn
        'FEED_UPDATED'                        => feed_format_date($feed_updated_time),
135 10342 acydburn
        'FEED_LANG'                                => $user->lang['USER_LANG'],
136 10342 acydburn
        'FEED_AUTHOR'                        => $config['sitename'],
137 10342 acydburn
));
138 10342 acydburn
139 9575 acydburn
$feed->close();
140 9575 acydburn
141 9575 acydburn
// Output page
142 9575 acydburn
143 9575 acydburn
// gzip_compression
144 9575 acydburn
if ($config['gzip_compress'])
145 9575 acydburn
{
146 9575 acydburn
        if (@extension_loaded('zlib') && !headers_sent())
147 9575 acydburn
        {
148 9575 acydburn
                ob_start('ob_gzhandler');
149 9575 acydburn
        }
150 9575 acydburn
}
151 9575 acydburn
152 9575 acydburn
// IF debug extra is enabled and admin want to "explain" the page we need to set other headers...
153 10342 acydburn
if (defined('DEBUG_EXTRA') && request_var('explain', 0) && $auth->acl_get('a_'))
154 9575 acydburn
{
155 9575 acydburn
        header('Content-type: text/html; charset=UTF-8');
156 9575 acydburn
        header('Cache-Control: private, no-cache="set-cookie"');
157 9575 acydburn
        header('Expires: 0');
158 9575 acydburn
        header('Pragma: no-cache');
159 9575 acydburn
160 9575 acydburn
        $mtime = explode(' ', microtime());
161 9575 acydburn
        $totaltime = $mtime[0] + $mtime[1] - $starttime;
162 9575 acydburn
163 9575 acydburn
        if (method_exists($db, 'sql_report'))
164 9575 acydburn
        {
165 9575 acydburn
                $db->sql_report('display');
166 9575 acydburn
        }
167 9575 acydburn
168 9575 acydburn
        garbage_collection();
169 9575 acydburn
        exit_handler();
170 9575 acydburn
}
171 9575 acydburn
172 10342 acydburn
header("Content-Type: application/atom+xml; charset=UTF-8");
173 10342 acydburn
header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT');
174 10342 acydburn
175 11386 git-gate
if (!empty($user->data['is_bot']))
176 11386 git-gate
{
177 11386 git-gate
        // Let reverse proxies know we detected a bot.
178 11386 git-gate
        header('X-PHPBB-IS-BOT: yes');
179 11386 git-gate
}
180 11386 git-gate
181 9575 acydburn
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
182 9721 acydburn
echo '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="' . $global_vars['FEED_LANG'] . '">' . "\n";
183 9721 acydburn
echo '<link rel="self" type="application/atom+xml" href="' . $global_vars['SELF_LINK'] . '" />' . "\n\n";
184 9575 acydburn
185 9721 acydburn
echo (!empty($global_vars['FEED_TITLE'])) ? '<title>' . $global_vars['FEED_TITLE'] . '</title>' . "\n" : '';
186 9721 acydburn
echo (!empty($global_vars['FEED_SUBTITLE'])) ? '<subtitle>' . $global_vars['FEED_SUBTITLE'] . '</subtitle>' . "\n" : '';
187 9721 acydburn
echo (!empty($global_vars['FEED_LINK'])) ? '<link href="' . $global_vars['FEED_LINK'] .'" />' . "\n" : '';
188 9721 acydburn
echo '<updated>' . $global_vars['FEED_UPDATED'] . '</updated>' . "\n\n";
189 9575 acydburn
190 9721 acydburn
echo '<author><name><![CDATA[' . $global_vars['FEED_AUTHOR'] . ']]></name></author>' . "\n";
191 9721 acydburn
echo '<id>' . $global_vars['SELF_LINK'] . '</id>' . "\n";
192 9575 acydburn
193 9575 acydburn
foreach ($item_vars as $row)
194 9575 acydburn
{
195 9721 acydburn
        echo '<entry>' . "\n";
196 9575 acydburn
197 9575 acydburn
        if (!empty($row['author']))
198 9575 acydburn
        {
199 9721 acydburn
                echo '<author><name><![CDATA[' . $row['author'] . ']]></name></author>' . "\n";
200 9575 acydburn
        }
201 9575 acydburn
202 11002 git-gate
        echo '<updated>' . ((!empty($row['updated'])) ? $row['updated'] : $row['published']) . '</updated>' . "\n";
203 11002 git-gate
204 11002 git-gate
        if (!empty($row['published']))
205 11002 git-gate
        {
206 11002 git-gate
                echo '<published>' . $row['published'] . '</published>' . "\n";
207 11002 git-gate
        }
208 11002 git-gate
209 9721 acydburn
        echo '<id>' . $row['link'] . '</id>' . "\n";
210 9721 acydburn
        echo '<link href="' . $row['link'] . '"/>' . "\n";
211 9721 acydburn
        echo '<title type="html"><![CDATA[' . $row['title'] . ']]></title>' . "\n\n";
212 9575 acydburn
213 10558 git-gate
        if (!empty($row['category']) && isset($row['category_name']) && $row['category_name'] !== '')
214 9575 acydburn
        {
215 9721 acydburn
                echo '<category term="' . $row['category_name'] . '" scheme="' . $row['category'] . '" label="' . $row['category_name'] . '"/>' . "\n";
216 9575 acydburn
        }
217 9575 acydburn
218 9721 acydburn
        echo '<content type="html" xml:base="' . $row['link'] . '"><![CDATA[' . "\n";
219 9575 acydburn
        echo $row['description'];
220 9575 acydburn
221 9575 acydburn
        if (!empty($row['statistics']))
222 9575 acydburn
        {
223 9575 acydburn
                echo '<p>' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '</p>';
224 9575 acydburn
        }
225 9575 acydburn
226 10342 acydburn
        echo '<hr />' . "\n" . ']]></content>' . "\n";
227 9721 acydburn
        echo '</entry>' . "\n";
228 9575 acydburn
}
229 9575 acydburn
230 9721 acydburn
echo '</feed>';
231 9575 acydburn
232 9575 acydburn
garbage_collection();
233 9575 acydburn
exit_handler();
234 9575 acydburn
235 9575 acydburn
/**
236 9575 acydburn
* Run links through append_sid(), prepend generate_board_url() and remove session id
237 9575 acydburn
**/
238 9575 acydburn
function feed_append_sid($url, $params)
239 9575 acydburn
{
240 9575 acydburn
        global $board_url;
241 9575 acydburn
242 10342 acydburn
        return append_sid($board_url . $url, $params, true, '');
243 10342 acydburn
}
244 9575 acydburn
245 10342 acydburn
/**
246 10342 acydburn
* Generate ISO 8601 date string (RFC 3339)
247 10342 acydburn
**/
248 10342 acydburn
function feed_format_date($time)
249 10342 acydburn
{
250 10342 acydburn
        static $zone_offset;
251 10342 acydburn
        static $offset_string;
252 9663 acydburn
253 10342 acydburn
        if (empty($offset_string))
254 10342 acydburn
        {
255 10342 acydburn
                global $user;
256 9663 acydburn
257 10342 acydburn
                $zone_offset = (int) $user->timezone + (int) $user->dst;
258 10342 acydburn
259 10342 acydburn
                $sign = ($zone_offset < 0) ? '-' : '+';
260 10342 acydburn
                $time_offset = abs($zone_offset);
261 10342 acydburn
262 10342 acydburn
                $offset_seconds        = $time_offset % 3600;
263 10342 acydburn
                $offset_minutes        = $offset_seconds / 60;
264 10342 acydburn
                $offset_hours        = ($time_offset - $offset_seconds) / 3600;
265 10342 acydburn
266 10342 acydburn
                $offset_string        = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes);
267 10342 acydburn
        }
268 10342 acydburn
269 10342 acydburn
        return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string;
270 9575 acydburn
}
271 9575 acydburn
272 9575 acydburn
/**
273 9575 acydburn
* Generate text content
274 9575 acydburn
**/
275 9575 acydburn
function feed_generate_content($content, $uid, $bitfield, $options)
276 9575 acydburn
{
277 9575 acydburn
        global $user, $config, $phpbb_root_path, $phpEx, $board_url;
278 9575 acydburn
279 9575 acydburn
        if (empty($content))
280 9575 acydburn
        {
281 9575 acydburn
                return '';
282 9575 acydburn
        }
283 9575 acydburn
284 9575 acydburn
        // Prepare some bbcodes for better parsing
285 9575 acydburn
        $content        = preg_replace("#\[quote(=&quot;.*?&quot;)?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content);
286 9575 acydburn
287 9575 acydburn
        $content = generate_text_for_display($content, $uid, $bitfield, $options);
288 9575 acydburn
289 9663 acydburn
        // Add newlines
290 9663 acydburn
        $content = str_replace('<br />', '<br />' . "\n", $content);
291 9663 acydburn
292 10751 git-gate
        // Convert smiley Relative paths to Absolute path, Windows style
293 10751 git-gate
        $content = str_replace($phpbb_root_path . $config['smilies_path'], $board_url . '/' . $config['smilies_path'], $content);
294 9575 acydburn
295 9575 acydburn
        // Remove "Select all" link and mouse events
296 10202 bantu
        $content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $user->lang['SELECT_ALL_CODE'] . '</a>', '', $content);
297 9575 acydburn
        $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
298 9575 acydburn
299 9721 acydburn
        // Firefox does not support CSS for feeds, though
300 9721 acydburn
301 9575 acydburn
        // Remove font sizes
302 9721 acydburn
//        $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content);
303 9575 acydburn
304 9575 acydburn
        // Make text strong :P
305 9721 acydburn
//        $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content);
306 9575 acydburn
307 9575 acydburn
        // Italic
308 9721 acydburn
//        $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content);
309 9575 acydburn
310 9575 acydburn
        // Underline
311 9721 acydburn
//        $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content);
312 9575 acydburn
313 9575 acydburn
        // Remove embed Windows Media Streams
314 9575 acydburn
        $content        = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--<!\[endif\]-->#si', '', $content);
315 9575 acydburn
316 9575 acydburn
        // Do not use &lt; and &gt;, because we want to retain code contained in [code][/code]
317 9575 acydburn
318 9575 acydburn
        // Remove embed and objects
319 9575 acydburn
        $content        = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' <a href=$4 target="_blank"><strong>$1</strong></a> ',$content);
320 9575 acydburn
321 9575 acydburn
        // Remove some specials html tag, because somewhere there are a mod to allow html tags ;)
322 9575 acydburn
        $content        = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
323 9575 acydburn
324 9575 acydburn
        // Remove Comments from inline attachments [ia]
325 9575 acydburn
        $content        = preg_replace('#<div class="(inline-attachment|attachtitle)">(.*?)<!-- ia(.*?) -->(.*?)<!-- ia(.*?) -->(.*?)</div>#si','$4',$content);
326 9575 acydburn
327 9575 acydburn
        // Replace some entities with their unicode counterpart
328 9575 acydburn
        $entities = array(
329 9870 bantu
                '&nbsp;'        => "\xC2\xA0",
330 9870 bantu
                '&bull;'        => "\xE2\x80\xA2",
331 9870 bantu
                '&middot;'        => "\xC2\xB7",
332 9870 bantu
                '&copy;'        => "\xC2\xA9",
333 9575 acydburn
        );
334 9575 acydburn
335 9575 acydburn
        $content = str_replace(array_keys($entities), array_values($entities), $content);
336 9575 acydburn
337 9721 acydburn
        // Remove CDATA blocks. ;)
338 9721 acydburn
        $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content);
339 9721 acydburn
340 9575 acydburn
        // Other control characters
341 10558 git-gate
        $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content);
342 9575 acydburn
343 9575 acydburn
        return $content;
344 9575 acydburn
}
345 9575 acydburn
346 9575 acydburn
/**
347 9575 acydburn
* Factory class to return correct object
348 9575 acydburn
* @package phpBB3
349 9575 acydburn
*/
350 9575 acydburn
class phpbb_feed_factory
351 9575 acydburn
{
352 9575 acydburn
        /**
353 9575 acydburn
        * Return correct object for specified mode
354 9575 acydburn
        *
355 9575 acydburn
        * @param string        $mode                The feeds mode.
356 9575 acydburn
        * @param int        $forum_id        Forum id specified by the script if forum feed provided.
357 9575 acydburn
        * @param int        $topic_id        Topic id specified by the script if topic feed provided.
358 9575 acydburn
        *
359 9575 acydburn
        * @return object        Returns correct feeds object for specified mode.
360 9575 acydburn
        */
361 9575 acydburn
        function init($mode, $forum_id, $topic_id)
362 9575 acydburn
        {
363 9575 acydburn
                global $config;
364 9575 acydburn
365 9575 acydburn
                switch ($mode)
366 9575 acydburn
                {
367 9575 acydburn
                        case 'forums':
368 9575 acydburn
                                if (!$config['feed_overall_forums'])
369 9575 acydburn
                                {
370 9575 acydburn
                                        return false;
371 9575 acydburn
                                }
372 9575 acydburn
373 9575 acydburn
                                return new phpbb_feed_forums();
374 9575 acydburn
                        break;
375 9575 acydburn
376 9575 acydburn
                        case 'topics':
377 10558 git-gate
                        case 'topics_new':
378 10558 git-gate
                                if (!$config['feed_topics_new'])
379 9575 acydburn
                                {
380 9575 acydburn
                                        return false;
381 9575 acydburn
                                }
382 9575 acydburn
383 9575 acydburn
                                return new phpbb_feed_topics();
384 9575 acydburn
                        break;
385 9575 acydburn
386 10558 git-gate
                        case 'topics_active':
387 10558 git-gate
                                if (!$config['feed_topics_active'])
388 10558 git-gate
                                {
389 10558 git-gate
                                        return false;
390 10558 git-gate
                                }
391 10558 git-gate
392 10558 git-gate
                                return new phpbb_feed_topics_active();
393 10558 git-gate
                        break;
394 10558 git-gate
395 9575 acydburn
                        case 'news':
396 9965 acydburn
                                global $db;
397 9965 acydburn
398 9965 acydburn
                                // Get at least one news forum
399 9965 acydburn
                                $sql = 'SELECT forum_id
400 9965 acydburn
                                        FROM ' . FORUMS_TABLE . '
401 9965 acydburn
                                        WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
402 9965 acydburn
                                $result = $db->sql_query_limit($sql, 1, 0, 600);
403 9965 acydburn
                                $s_feed_news = (int) $db->sql_fetchfield('forum_id');
404 9965 acydburn
                                $db->sql_freeresult($result);
405 9965 acydburn
406 9965 acydburn
                                if (!$s_feed_news)
407 9575 acydburn
                                {
408 9575 acydburn
                                        return false;
409 9575 acydburn
                                }
410 9575 acydburn
411 9575 acydburn
                                return new phpbb_feed_news();
412 9575 acydburn
                        break;
413 9575 acydburn
414 9575 acydburn
                        default:
415 10558 git-gate
                                if ($topic_id && $config['feed_topic'])
416 9575 acydburn
                                {
417 10558 git-gate
                                        return new phpbb_feed_topic($topic_id);
418 9575 acydburn
                                }
419 10558 git-gate
                                else if ($forum_id && $config['feed_forum'])
420 9575 acydburn
                                {
421 10558 git-gate
                                        return new phpbb_feed_forum($forum_id);
422 9575 acydburn
                                }
423 10558 git-gate
                                else if ($config['feed_overall'])
424 10558 git-gate
                                {
425 10558 git-gate
                                        return new phpbb_feed_overall();
426 10558 git-gate
                                }
427 9575 acydburn
428 10558 git-gate
                                return false;
429 9575 acydburn
                        break;
430 9575 acydburn
                }
431 9575 acydburn
        }
432 9575 acydburn
}
433 9575 acydburn
434 9575 acydburn
/**
435 10342 acydburn
* Base class with some generic functions and settings.
436 10342 acydburn
*
437 9575 acydburn
* @package phpBB3
438 9575 acydburn
*/
439 10342 acydburn
class phpbb_feed_base
440 9575 acydburn
{
441 9575 acydburn
        /**
442 9575 acydburn
        * SQL Query to be executed to get feed items
443 9575 acydburn
        */
444 10342 acydburn
        var $sql = array();
445 9575 acydburn
446 9575 acydburn
        /**
447 9575 acydburn
        * Keys specified for retrieval of title, content, etc.
448 9575 acydburn
        */
449 9575 acydburn
        var $keys = array();
450 9575 acydburn
451 9575 acydburn
        /**
452 10342 acydburn
        * Number of items to fetch. Usually overwritten by $config['feed_something']
453 9575 acydburn
        */
454 10342 acydburn
        var $num_items = 15;
455 9575 acydburn
456 9575 acydburn
        /**
457 9663 acydburn
        * Separator for title elements to separate items (for example forum / topic)
458 9663 acydburn
        */
459 9870 bantu
        var $separator = "\xE2\x80\xA2"; // &bull;
460 9663 acydburn
461 9663 acydburn
        /**
462 10342 acydburn
        * Separator for the statistics row (Posted by, post date, replies, etc.)
463 9575 acydburn
        */
464 10342 acydburn
        var $separator_stats = "\xE2\x80\x94"; // &mdash;
465 10342 acydburn
466 10342 acydburn
        /**
467 10342 acydburn
        * Constructor
468 10342 acydburn
        */
469 10342 acydburn
        function phpbb_feed_base()
470 9575 acydburn
        {
471 10558 git-gate
                global $config;
472 9575 acydburn
473 10558 git-gate
                $this->set_keys();
474 10558 git-gate
475 10558 git-gate
                // Allow num_items to be string
476 10558 git-gate
                if (is_string($this->num_items))
477 10342 acydburn
                {
478 10558 git-gate
                        $this->num_items = (int) $config[$this->num_items];
479 10558 git-gate
480 10558 git-gate
                        // A precaution
481 10558 git-gate
                        if (!$this->num_items)
482 10558 git-gate
                        {
483 10558 git-gate
                                $this->num_items = 10;
484 10558 git-gate
                        }
485 10342 acydburn
                }
486 9575 acydburn
        }
487 9575 acydburn
488 10342 acydburn
        /**
489 10342 acydburn
        * Set keys.
490 10342 acydburn
        */
491 9575 acydburn
        function set_keys()
492 9575 acydburn
        {
493 9575 acydburn
        }
494 9575 acydburn
495 10342 acydburn
        /**
496 10342 acydburn
        * Open feed
497 10342 acydburn
        */
498 9575 acydburn
        function open()
499 9575 acydburn
        {
500 9575 acydburn
        }
501 9575 acydburn
502 10342 acydburn
        /**
503 10342 acydburn
        * Close feed
504 10342 acydburn
        */
505 9575 acydburn
        function close()
506 9575 acydburn
        {
507 10342 acydburn
                global $db;
508 10342 acydburn
509 9575 acydburn
                if (!empty($this->result))
510 9575 acydburn
                {
511 9575 acydburn
                        $db->sql_freeresult($this->result);
512 9575 acydburn
                }
513 9575 acydburn
        }
514 9575 acydburn
515 9575 acydburn
        /**
516 9575 acydburn
        * Set key
517 9575 acydburn
        */
518 9575 acydburn
        function set($key, $value)
519 9575 acydburn
        {
520 9575 acydburn
                $this->keys[$key] = $value;
521 9575 acydburn
        }
522 9575 acydburn
523 9575 acydburn
        /**
524 9575 acydburn
        * Get key
525 9575 acydburn
        */
526 9575 acydburn
        function get($key)
527 9575 acydburn
        {
528 9575 acydburn
                return (isset($this->keys[$key])) ? $this->keys[$key] : NULL;
529 9575 acydburn
        }
530 9575 acydburn
531 10558 git-gate
        function get_readable_forums()
532 9575 acydburn
        {
533 10558 git-gate
                global $auth;
534 10558 git-gate
                static $forum_ids;
535 10558 git-gate
536 10558 git-gate
                if (!isset($forum_ids))
537 9575 acydburn
                {
538 10559 git-gate
                        $forum_ids = array_keys($auth->acl_getf('f_read', true));
539 9575 acydburn
                }
540 9575 acydburn
541 10558 git-gate
                return $forum_ids;
542 10558 git-gate
        }
543 9575 acydburn
544 10558 git-gate
        function get_moderator_approve_forums()
545 10558 git-gate
        {
546 10558 git-gate
                global $auth;
547 10558 git-gate
                static $forum_ids;
548 9575 acydburn
549 10558 git-gate
                if (!isset($forum_ids))
550 10558 git-gate
                {
551 10633 git-gate
                        $forum_ids = array_keys($auth->acl_getf('m_approve', true));
552 10558 git-gate
                }
553 10342 acydburn
554 10558 git-gate
                return $forum_ids;
555 10558 git-gate
        }
556 9965 acydburn
557 10633 git-gate
        function is_moderator_approve_forum($forum_id)
558 10633 git-gate
        {
559 10633 git-gate
                static $forum_ids;
560 10633 git-gate
561 10633 git-gate
                if (!isset($forum_ids))
562 10633 git-gate
                {
563 10633 git-gate
                        $forum_ids = array_flip($this->get_moderator_approve_forums());
564 10633 git-gate
                }
565 10633 git-gate
566 10633 git-gate
                if (!$forum_id)
567 10633 git-gate
                {
568 10633 git-gate
                        // Global announcement, your a moderator in any forum than it's okay.
569 10633 git-gate
                        return (!empty($forum_ids)) ? true : false;
570 10633 git-gate
                }
571 10633 git-gate
572 10633 git-gate
                return (isset($forum_ids[$forum_id])) ? true : false;
573 10633 git-gate
        }
574 10633 git-gate
575 10558 git-gate
        function get_excluded_forums()
576 10558 git-gate
        {
577 10558 git-gate
                global $db, $cache;
578 10558 git-gate
                static $forum_ids;
579 10558 git-gate
580 10558 git-gate
                // Matches acp/acp_board.php
581 10558 git-gate
                $cache_name        = 'feed_excluded_forum_ids';
582 10558 git-gate
583 10558 git-gate
                if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false)
584 9965 acydburn
                {
585 10558 git-gate
                        $sql = 'SELECT forum_id
586 10558 git-gate
                                FROM ' . FORUMS_TABLE . '
587 10558 git-gate
                                WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0');
588 10558 git-gate
                        $result = $db->sql_query($sql);
589 10558 git-gate
590 10558 git-gate
                        $forum_ids = array();
591 10558 git-gate
                        while ($forum_id = (int) $db->sql_fetchfield('forum_id'))
592 10558 git-gate
                        {
593 10558 git-gate
                                $forum_ids[$forum_id] = $forum_id;
594 10558 git-gate
                        }
595 10558 git-gate
                        $db->sql_freeresult($result);
596 10558 git-gate
597 10558 git-gate
                        $cache->put('_' . $cache_name, $forum_ids);
598 9965 acydburn
                }
599 9965 acydburn
600 10558 git-gate
                return $forum_ids;
601 10558 git-gate
        }
602 9575 acydburn
603 10558 git-gate
        function is_excluded_forum($forum_id)
604 10558 git-gate
        {
605 10558 git-gate
                $forum_ids = $this->get_excluded_forums();
606 10558 git-gate
607 10558 git-gate
                return isset($forum_ids[$forum_id]) ? true : false;
608 10342 acydburn
        }
609 9575 acydburn
610 10342 acydburn
        function get_passworded_forums()
611 10342 acydburn
        {
612 11383 git-gate
                global $user;
613 10342 acydburn
614 11383 git-gate
                return $user->get_passworded_forums();
615 10342 acydburn
        }
616 10342 acydburn
617 10342 acydburn
        function get_item()
618 10342 acydburn
        {
619 10342 acydburn
                global $db, $cache;
620 10558 git-gate
                static $result;
621 10342 acydburn
622 10558 git-gate
                if (!isset($result))
623 10342 acydburn
                {
624 10558 git-gate
                        if (!$this->get_sql())
625 9575 acydburn
                        {
626 10558 git-gate
                                return false;
627 9575 acydburn
                        }
628 10342 acydburn
629 10558 git-gate
                        // Query database
630 10558 git-gate
                        $sql = $db->sql_build_query('SELECT', $this->sql);
631 10558 git-gate
                        $result = $db->sql_query_limit($sql, $this->num_items);
632 10342 acydburn
                }
633 10342 acydburn
634 10558 git-gate
                return $db->sql_fetchrow($result);
635 10558 git-gate
        }
636 10342 acydburn
637 10558 git-gate
        function user_viewprofile($row)
638 10558 git-gate
        {
639 10558 git-gate
                global $phpEx, $user;
640 10342 acydburn
641 10558 git-gate
                $author_id = (int) $row[$this->get('author_id')];
642 10342 acydburn
643 10558 git-gate
                if ($author_id == ANONYMOUS)
644 10558 git-gate
                {
645 10558 git-gate
                        // Since we cannot link to a profile, we just return GUEST
646 10558 git-gate
                        // instead of $row['username']
647 10558 git-gate
                        return $user->lang['GUEST'];
648 10558 git-gate
                }
649 10342 acydburn
650 10558 git-gate
                return '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&amp;u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
651 10342 acydburn
        }
652 10342 acydburn
}
653 9575 acydburn
654 10342 acydburn
/**
655 10558 git-gate
* Abstract class for post based feeds
656 10342 acydburn
*
657 10342 acydburn
* @package phpBB3
658 10342 acydburn
*/
659 10558 git-gate
class phpbb_feed_post_base extends phpbb_feed_base
660 10342 acydburn
{
661 10558 git-gate
        var $num_items = 'feed_limit_post';
662 10342 acydburn
663 10558 git-gate
        function set_keys()
664 10342 acydburn
        {
665 10558 git-gate
                $this->set('title',                'post_subject');
666 10558 git-gate
                $this->set('title2',        'topic_title');
667 10342 acydburn
668 10558 git-gate
                $this->set('author_id',        'user_id');
669 10558 git-gate
                $this->set('creator',        'username');
670 11002 git-gate
                $this->set('published',        'post_time');
671 11002 git-gate
                $this->set('updated',        'post_edit_time');
672 10558 git-gate
                $this->set('text',                'post_text');
673 10342 acydburn
674 10558 git-gate
                $this->set('bitfield',        'bbcode_bitfield');
675 10558 git-gate
                $this->set('bbcode_uid','bbcode_uid');
676 10342 acydburn
677 10558 git-gate
                $this->set('enable_bbcode',                'enable_bbcode');
678 10558 git-gate
                $this->set('enable_smilies',        'enable_smilies');
679 10558 git-gate
                $this->set('enable_magic_url',        'enable_magic_url');
680 9575 acydburn
        }
681 9575 acydburn
682 10558 git-gate
        function adjust_item(&$item_row, &$row)
683 10558 git-gate
        {
684 10558 git-gate
                global $phpEx, $config, $user;
685 10558 git-gate
686 10558 git-gate
                $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}");
687 10558 git-gate
688 10558 git-gate
                if ($config['feed_item_statistics'])
689 10558 git-gate
                {
690 10558 git-gate
                        $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
691 11002 git-gate
                                . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')])
692 10633 git-gate
                                . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : '');
693 10558 git-gate
                }
694 10558 git-gate
        }
695 10558 git-gate
}
696 10558 git-gate
697 10558 git-gate
/**
698 10558 git-gate
* Abstract class for topic based feeds
699 10558 git-gate
*
700 10558 git-gate
* @package phpBB3
701 10558 git-gate
*/
702 10558 git-gate
class phpbb_feed_topic_base extends phpbb_feed_base
703 10558 git-gate
{
704 10558 git-gate
        var $num_items = 'feed_limit_topic';
705 10558 git-gate
706 10342 acydburn
        function set_keys()
707 10342 acydburn
        {
708 10558 git-gate
                $this->set('title',                'topic_title');
709 10558 git-gate
                $this->set('title2',        'forum_name');
710 10342 acydburn
711 10558 git-gate
                $this->set('author_id',        'topic_poster');
712 10558 git-gate
                $this->set('creator',        'topic_first_poster_name');
713 11002 git-gate
                $this->set('published',        'post_time');
714 11002 git-gate
                $this->set('updated',        'post_edit_time');
715 10342 acydburn
                $this->set('text',                'post_text');
716 10558 git-gate
717 10342 acydburn
                $this->set('bitfield',        'bbcode_bitfield');
718 10342 acydburn
                $this->set('bbcode_uid','bbcode_uid');
719 10342 acydburn
720 10342 acydburn
                $this->set('enable_bbcode',                'enable_bbcode');
721 10342 acydburn
                $this->set('enable_smilies',        'enable_smilies');
722 10342 acydburn
                $this->set('enable_magic_url',        'enable_magic_url');
723 10558 git-gate
        }
724 10342 acydburn
725 10558 git-gate
        function adjust_item(&$item_row, &$row)
726 10558 git-gate
        {
727 10558 git-gate
                global $phpEx, $config, $user;
728 10558 git-gate
729 10558 git-gate
                $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&amp;p=' . $row['post_id'] . '#p' . $row['post_id']);
730 10558 git-gate
731 10558 git-gate
                if ($config['feed_item_statistics'])
732 10558 git-gate
                {
733 10558 git-gate
                        $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
734 11002 git-gate
                                . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')])
735 10633 git-gate
                                . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'])
736 10633 git-gate
                                . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']
737 10633 git-gate
                                . (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : '');
738 10558 git-gate
                }
739 10342 acydburn
        }
740 10558 git-gate
}
741 10342 acydburn
742 10558 git-gate
/**
743 10558 git-gate
* Board wide feed (aka overall feed)
744 10558 git-gate
*
745 10558 git-gate
* This will give you the newest {$this->num_items} posts
746 10558 git-gate
* from the whole board.
747 10558 git-gate
*
748 10558 git-gate
* @package phpBB3
749 10558 git-gate
*/
750 10558 git-gate
class phpbb_feed_overall extends phpbb_feed_post_base
751 10558 git-gate
{
752 10558 git-gate
        function get_sql()
753 10558 git-gate
        {
754 10558 git-gate
                global $auth, $db;
755 10558 git-gate
756 10558 git-gate
                $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums());
757 10558 git-gate
                if (empty($forum_ids))
758 10558 git-gate
                {
759 10558 git-gate
                        return false;
760 10558 git-gate
                }
761 10558 git-gate
762 10558 git-gate
                // m_approve forums
763 10558 git-gate
                $fid_m_approve = $this->get_moderator_approve_forums();
764 10558 git-gate
                $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', $fid_m_approve) : '';
765 10558 git-gate
766 10558 git-gate
                // Determine topics with recent activity
767 10558 git-gate
                $sql = 'SELECT topic_id, topic_last_post_time
768 10558 git-gate
                        FROM ' . TOPICS_TABLE . '
769 10558 git-gate
                        WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
770 10558 git-gate
                                AND topic_moved_id = 0
771 10558 git-gate
                                AND (topic_approved = 1
772 10558 git-gate
                                        ' . $sql_m_approve . ')
773 10558 git-gate
                        ORDER BY topic_last_post_time DESC';
774 10558 git-gate
                $result = $db->sql_query_limit($sql, $this->num_items);
775 10558 git-gate
776 10558 git-gate
                $topic_ids = array();
777 10558 git-gate
                $min_post_time = 0;
778 10558 git-gate
                while ($row = $db->sql_fetchrow())
779 10558 git-gate
                {
780 10558 git-gate
                        $topic_ids[] = (int) $row['topic_id'];
781 10558 git-gate
782 10558 git-gate
                        $min_post_time = (int) $row['topic_last_post_time'];
783 10558 git-gate
                }
784 10558 git-gate
                $db->sql_freeresult($result);
785 10558 git-gate
786 10558 git-gate
                if (empty($topic_ids))
787 10558 git-gate
                {
788 10558 git-gate
                        return false;
789 10558 git-gate
                }
790 10558 git-gate
791 10558 git-gate
                // Get the actual data
792 10558 git-gate
                $this->sql = array(
793 10558 git-gate
                        'SELECT'        =>        'f.forum_id, f.forum_name, ' .
794 11002 git-gate
                                                        'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
795 10558 git-gate
                                                        'u.username, u.user_id',
796 10558 git-gate
                        'FROM'                => array(
797 10632 git-gate
                                USERS_TABLE                => 'u',
798 10558 git-gate
                                POSTS_TABLE                => 'p',
799 10558 git-gate
                        ),
800 10558 git-gate
                        'LEFT_JOIN'        => array(
801 10558 git-gate
                                array(
802 10558 git-gate
                                        'FROM'        => array(FORUMS_TABLE        => 'f'),
803 10558 git-gate
                                        'ON'        => 'f.forum_id = p.forum_id',
804 10558 git-gate
                                ),
805 10558 git-gate
                        ),
806 10558 git-gate
                        'WHERE'                => $db->sql_in_set('p.topic_id', $topic_ids) . '
807 10558 git-gate
                                                        AND (p.post_approved = 1
808 10558 git-gate
                                                                ' . str_replace('forum_id', 'p.forum_id', $sql_m_approve) . ')
809 10558 git-gate
                                                        AND p.post_time >= ' . $min_post_time . '
810 10558 git-gate
                                                        AND u.user_id = p.poster_id',
811 10558 git-gate
                        'ORDER_BY'        => 'p.post_time DESC',
812 10558 git-gate
                );
813 10558 git-gate
814 10558 git-gate
                return true;
815 10558 git-gate
        }
816 10558 git-gate
817 10558 git-gate
        function adjust_item(&$item_row, &$row)
818 10558 git-gate
        {
819 10558 git-gate
                parent::adjust_item($item_row, $row);
820 10558 git-gate
821 10558 git-gate
                $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
822 10558 git-gate
        }
823 10558 git-gate
}
824 10558 git-gate
825 10558 git-gate
/**
826 10558 git-gate
* Forum feed
827 10558 git-gate
*
828 10558 git-gate
* This will give you the last {$this->num_items} posts made
829 10558 git-gate
* within a specific forum.
830 10558 git-gate
*
831 10558 git-gate
* @package phpBB3
832 10558 git-gate
*/
833 10558 git-gate
class phpbb_feed_forum extends phpbb_feed_post_base
834 10558 git-gate
{
835 10558 git-gate
        var $forum_id                = 0;
836 10558 git-gate
        var $forum_data                = array();
837 10558 git-gate
838 10558 git-gate
        function phpbb_feed_forum($forum_id)
839 10558 git-gate
        {
840 10558 git-gate
                parent::phpbb_feed_base();
841 10558 git-gate
842 10558 git-gate
                $this->forum_id = (int) $forum_id;
843 10558 git-gate
        }
844 10558 git-gate
845 10342 acydburn
        function open()
846 10342 acydburn
        {
847 10558 git-gate
                global $db, $auth;
848 10342 acydburn
849 10558 git-gate
                // Check if forum exists
850 10558 git-gate
                $sql = 'SELECT forum_id, forum_name, forum_password, forum_type, forum_options
851 10558 git-gate
                        FROM ' . FORUMS_TABLE . '
852 10558 git-gate
                        WHERE forum_id = ' . $this->forum_id;
853 10558 git-gate
                $result = $db->sql_query($sql);
854 10558 git-gate
                $this->forum_data = $db->sql_fetchrow($result);
855 10558 git-gate
                $db->sql_freeresult($result);
856 10558 git-gate
857 10558 git-gate
                if (empty($this->forum_data))
858 10342 acydburn
                {
859 10558 git-gate
                        trigger_error('NO_FORUM');
860 10558 git-gate
                }
861 10342 acydburn
862 10558 git-gate
                // Forum needs to be postable
863 10558 git-gate
                if ($this->forum_data['forum_type'] != FORUM_POST)
864 10558 git-gate
                {
865 10558 git-gate
                        trigger_error('NO_FEED');
866 10558 git-gate
                }
867 10342 acydburn
868 10558 git-gate
                // Make sure forum is not excluded from feed
869 10558 git-gate
                if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->forum_data['forum_options']))
870 10558 git-gate
                {
871 10558 git-gate
                        trigger_error('NO_FEED');
872 10558 git-gate
                }
873 10342 acydburn
874 10558 git-gate
                // Make sure we can read this forum
875 10558 git-gate
                if (!$auth->acl_get('f_read', $this->forum_id))
876 10558 git-gate
                {
877 10558 git-gate
                        trigger_error('SORRY_AUTH_READ');
878 10558 git-gate
                }
879 10342 acydburn
880 10558 git-gate
                // Make sure forum is not passworded or user is authed
881 10558 git-gate
                if ($this->forum_data['forum_password'])
882 10558 git-gate
                {
883 10558 git-gate
                        $forum_ids_passworded = $this->get_passworded_forums();
884 10342 acydburn
885 10558 git-gate
                        if (isset($forum_ids_passworded[$this->forum_id]))
886 10342 acydburn
                        {
887 10342 acydburn
                                trigger_error('SORRY_AUTH_READ');
888 10342 acydburn
                        }
889 10342 acydburn
890 10558 git-gate
                        unset($forum_ids_passworded);
891 10342 acydburn
                }
892 10342 acydburn
        }
893 10342 acydburn
894 9575 acydburn
        function get_sql()
895 9575 acydburn
        {
896 10558 git-gate
                global $auth, $db;
897 9575 acydburn
898 10558 git-gate
                $m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false;
899 9575 acydburn
900 10558 git-gate
                // Determine topics with recent activity
901 10558 git-gate
                $sql = 'SELECT topic_id, topic_last_post_time
902 10558 git-gate
                        FROM ' . TOPICS_TABLE . '
903 11100 git-gate
                        WHERE forum_id = ' . $this->forum_id . '
904 10558 git-gate
                                AND topic_moved_id = 0
905 10558 git-gate
                                ' . ((!$m_approve) ? 'AND topic_approved = 1' : '') . '
906 10558 git-gate
                        ORDER BY topic_last_post_time DESC';
907 10558 git-gate
                $result = $db->sql_query_limit($sql, $this->num_items);
908 9575 acydburn
909 10558 git-gate
                $topic_ids = array();
910 10558 git-gate
                $min_post_time = 0;
911 10558 git-gate
                while ($row = $db->sql_fetchrow())
912 9575 acydburn
                {
913 10558 git-gate
                        $topic_ids[] = (int) $row['topic_id'];
914 9575 acydburn
915 10558 git-gate
                        $min_post_time = (int) $row['topic_last_post_time'];
916 10558 git-gate
                }
917 10558 git-gate
                $db->sql_freeresult($result);
918 9575 acydburn
919 10558 git-gate
                if (empty($topic_ids))
920 10558 git-gate
                {
921 10558 git-gate
                        return false;
922 9575 acydburn
                }
923 10558 git-gate
924 10558 git-gate
                $this->sql = array(
925 11002 git-gate
                        'SELECT'        =>        'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
926 10558 git-gate
                                                        'u.username, u.user_id',
927 10558 git-gate
                        'FROM'                => array(
928 10558 git-gate
                                POSTS_TABLE                => 'p',
929 10558 git-gate
                                USERS_TABLE                => 'u',
930 10558 git-gate
                        ),
931 10558 git-gate
                        'WHERE'                => $db->sql_in_set('p.topic_id', $topic_ids) . '
932 10558 git-gate
                                                        ' . ((!$m_approve) ? 'AND p.post_approved = 1' : '') . '
933 10558 git-gate
                                                        AND p.post_time >= ' . $min_post_time . '
934 10558 git-gate
                                                        AND p.poster_id = u.user_id',
935 10558 git-gate
                        'ORDER_BY'        => 'p.post_time DESC',
936 10558 git-gate
                );
937 10558 git-gate
938 10558 git-gate
                return true;
939 10558 git-gate
        }
940 10558 git-gate
941 10558 git-gate
        function adjust_item(&$item_row, &$row)
942 10558 git-gate
        {
943 10558 git-gate
                parent::adjust_item($item_row, $row);
944 10558 git-gate
945 10558 git-gate
                $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
946 10558 git-gate
        }
947 10558 git-gate
948 10558 git-gate
        function get_item()
949 10558 git-gate
        {
950 10558 git-gate
                return ($row = parent::get_item()) ? array_merge($this->forum_data, $row) : $row;
951 10558 git-gate
        }
952 10558 git-gate
}
953 10558 git-gate
954 10558 git-gate
/**
955 10558 git-gate
* Topic feed for a specific topic
956 10558 git-gate
*
957 10558 git-gate
* This will give you the last {$this->num_items} posts made within this topic.
958 10558 git-gate
*
959 10558 git-gate
* @package phpBB3
960 10558 git-gate
*/
961 10558 git-gate
class phpbb_feed_topic extends phpbb_feed_post_base
962 10558 git-gate
{
963 10558 git-gate
        var $topic_id                = 0;
964 10558 git-gate
        var $forum_id                = 0;
965 10558 git-gate
        var $topic_data                = array();
966 10558 git-gate
967 10558 git-gate
        function phpbb_feed_topic($topic_id)
968 10558 git-gate
        {
969 10558 git-gate
                parent::phpbb_feed_base();
970 10558 git-gate
971 10558 git-gate
                $this->topic_id = (int) $topic_id;
972 10558 git-gate
        }
973 10558 git-gate
974 10558 git-gate
        function open()
975 10558 git-gate
        {
976 10558 git-gate
                global $auth, $db, $user;
977 10558 git-gate
978 10558 git-gate
                $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_approved, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type
979 10558 git-gate
                        FROM ' . TOPICS_TABLE . ' t
980 10558 git-gate
                        LEFT JOIN ' . FORUMS_TABLE . ' f
981 10558 git-gate
                                ON (f.forum_id = t.forum_id)
982 10558 git-gate
                        WHERE t.topic_id = ' . $this->topic_id;
983 10558 git-gate
                $result = $db->sql_query($sql);
984 10558 git-gate
                $this->topic_data = $db->sql_fetchrow($result);
985 10558 git-gate
                $db->sql_freeresult($result);
986 10558 git-gate
987 10558 git-gate
                if (empty($this->topic_data))
988 9575 acydburn
                {
989 10558 git-gate
                        trigger_error('NO_TOPIC');
990 10558 git-gate
                }
991 10558 git-gate
992 11100 git-gate
                $this->forum_id = (int) $this->topic_data['forum_id'];
993 11100 git-gate
994 11100 git-gate
                // Make sure topic is either approved or user authed
995 11100 git-gate
                if (!$this->topic_data['topic_approved'] && !$auth->acl_get('m_approve', $this->forum_id))
996 10558 git-gate
                {
997 11100 git-gate
                        trigger_error('SORRY_AUTH_READ');
998 11100 git-gate
                }
999 10558 git-gate
1000 11100 git-gate
                // Make sure forum is not excluded from feed
1001 11100 git-gate
                if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->topic_data['forum_options']))
1002 11100 git-gate
                {
1003 11100 git-gate
                        trigger_error('NO_FEED');
1004 11100 git-gate
                }
1005 9575 acydburn
1006 11100 git-gate
                // Make sure we can read this forum
1007 11100 git-gate
                if (!$auth->acl_get('f_read', $this->forum_id))
1008 11100 git-gate
                {
1009 11100 git-gate
                        trigger_error('SORRY_AUTH_READ');
1010 9575 acydburn
                }
1011 11100 git-gate
1012 11100 git-gate
                // Make sure forum is not passworded or user is authed
1013 11100 git-gate
                if ($this->topic_data['forum_password'])
1014 9575 acydburn
                {
1015 11100 git-gate
                        $forum_ids_passworded = $this->get_passworded_forums();
1016 10558 git-gate
1017 11100 git-gate
                        if (isset($forum_ids_passworded[$this->forum_id]))
1018 9575 acydburn
                        {
1019 10558 git-gate
                                trigger_error('SORRY_AUTH_READ');
1020 9575 acydburn
                        }
1021 9575 acydburn
1022 11100 git-gate
                        unset($forum_ids_passworded);
1023 9575 acydburn
                }
1024 10558 git-gate
        }
1025 9575 acydburn
1026 10558 git-gate
        function get_sql()
1027 10558 git-gate
        {
1028 10558 git-gate
                global $auth, $db;
1029 10558 git-gate
1030 9575 acydburn
                $this->sql = array(
1031 11002 git-gate
                        'SELECT'        =>        'p.post_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
1032 10342 acydburn
                                                        'u.username, u.user_id',
1033 9575 acydburn
                        'FROM'                => array(
1034 9575 acydburn
                                POSTS_TABLE                => 'p',
1035 9575 acydburn
                                USERS_TABLE                => 'u',
1036 9575 acydburn
                        ),
1037 10558 git-gate
                        'WHERE'                => 'p.topic_id = ' . $this->topic_id . '
1038 10558 git-gate
                                                                ' . ($this->forum_id && !$auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . '
1039 10558 git-gate
                                                                AND p.poster_id = u.user_id',
1040 9575 acydburn
                        'ORDER_BY'        => 'p.post_time DESC',
1041 9575 acydburn
                );
1042 9575 acydburn
1043 9575 acydburn
                return true;
1044 9575 acydburn
        }
1045 9575 acydburn
1046 10558 git-gate
        function get_item()
1047 9575 acydburn
        {
1048 10558 git-gate
                return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row;
1049 9575 acydburn
        }
1050 9575 acydburn
}
1051 9575 acydburn
1052 10558 git-gate
/**
1053 10558 git-gate
* 'All Forums' feed
1054 10558 git-gate
*
1055 10558 git-gate
* This will give you a list of all postable forums where feeds are enabled
1056 10558 git-gate
* including forum description, topic stats and post stats
1057 10558 git-gate
*
1058 10558 git-gate
* @package phpBB3
1059 10558 git-gate
*/
1060 10342 acydburn
class phpbb_feed_forums extends phpbb_feed_base
1061 9575 acydburn
{
1062 10558 git-gate
        var $num_items        = 0;
1063 10558 git-gate
1064 9575 acydburn
        function set_keys()
1065 9575 acydburn
        {
1066 9575 acydburn
                $this->set('title',                'forum_name');
1067 9575 acydburn
                $this->set('text',                'forum_desc');
1068 9575 acydburn
                $this->set('bitfield',        'forum_desc_bitfield');
1069 9575 acydburn
                $this->set('bbcode_uid','forum_desc_uid');
1070 11002 git-gate
                $this->set('updated',        'forum_last_post_time');
1071 9575 acydburn
                $this->set('options',        'forum_desc_options');
1072 9575 acydburn
        }
1073 9575 acydburn
1074 9575 acydburn
        function get_sql()
1075 9575 acydburn
        {
1076 10558 git-gate
                global $auth, $db;
1077 9575 acydburn
1078 10558 git-gate
                $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums());
1079 10558 git-gate
                if (empty($in_fid_ary))
1080 10558 git-gate
                {
1081 10558 git-gate
                        return false;
1082 10558 git-gate
                }
1083 9575 acydburn
1084 9575 acydburn
                // Build SQL Query
1085 9575 acydburn
                $this->sql = array(
1086 10558 git-gate
                        'SELECT'        => 'f.forum_id, f.left_id, f.forum_name, f.forum_last_post_time,
1087 10558 git-gate
                                                        f.forum_desc, f.forum_desc_bitfield, f.forum_desc_uid, f.forum_desc_options,
1088 10558 git-gate
                                                        f.forum_topics, f.forum_posts',
1089 9575 acydburn
                        'FROM'                => array(FORUMS_TABLE => 'f'),
1090 9575 acydburn
                        'WHERE'                => 'f.forum_type = ' . FORUM_POST . '
1091 10558 git-gate
                                                        AND ' . $db->sql_in_set('f.forum_id', $in_fid_ary),
1092 10558 git-gate
                        'ORDER_BY'        => 'f.left_id ASC',
1093 9575 acydburn
                );
1094 9575 acydburn
1095 9575 acydburn
                return true;
1096 9575 acydburn
        }
1097 9575 acydburn
1098 9575 acydburn
        function adjust_item(&$item_row, &$row)
1099 9575 acydburn
        {
1100 9575 acydburn
                global $phpEx, $config;
1101 9575 acydburn
1102 9575 acydburn
                $item_row['link'] = feed_append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']);
1103 9575 acydburn
1104 9575 acydburn
                if ($config['feed_item_statistics'])
1105 9575 acydburn
                {
1106 9575 acydburn
                        global $user;
1107 9575 acydburn
1108 11603 git-gate
                        $item_row['statistics'] = $user->lang('TOTAL_TOPICS', (int) $row['forum_topics'])
1109 11603 git-gate
                                . ' ' . $this->separator_stats . ' ' . $user->lang('TOTAL_POSTS_OTHER', (int) $row['forum_posts']);
1110 9575 acydburn
                }
1111 9575 acydburn
        }
1112 9575 acydburn
}
1113 9575 acydburn
1114 10558 git-gate
/**
1115 10558 git-gate
* News feed
1116 10558 git-gate
*
1117 10558 git-gate
* This will give you {$this->num_items} first posts
1118 10558 git-gate
* of all topics in the selected news forums.
1119 10558 git-gate
*
1120 10558 git-gate
* @package phpBB3
1121 10558 git-gate
*/
1122 10558 git-gate
class phpbb_feed_news extends phpbb_feed_topic_base
1123 9575 acydburn
{
1124 10558 git-gate
        function get_news_forums()
1125 9575 acydburn
        {
1126 10558 git-gate
                global $db, $cache;
1127 10558 git-gate
                static $forum_ids;
1128 9575 acydburn
1129 10558 git-gate
                // Matches acp/acp_board.php
1130 10558 git-gate
                $cache_name        = 'feed_news_forum_ids';
1131 9575 acydburn
1132 10558 git-gate
                if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false)
1133 10558 git-gate
                {
1134 10558 git-gate
                        $sql = 'SELECT forum_id
1135 10558 git-gate
                                FROM ' . FORUMS_TABLE . '
1136 10558 git-gate
                                WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
1137 10558 git-gate
                        $result = $db->sql_query($sql);
1138 9575 acydburn
1139 10558 git-gate
                        $forum_ids = array();
1140 10558 git-gate
                        while ($forum_id = (int) $db->sql_fetchfield('forum_id'))
1141 10558 git-gate
                        {
1142 10558 git-gate
                                $forum_ids[$forum_id] = $forum_id;
1143 10558 git-gate
                        }
1144 10558 git-gate
                        $db->sql_freeresult($result);
1145 10558 git-gate
1146 10558 git-gate
                        $cache->put('_' . $cache_name, $forum_ids);
1147 10558 git-gate
                }
1148 10558 git-gate
1149 10558 git-gate
                return $forum_ids;
1150 9575 acydburn
        }
1151 9575 acydburn
1152 10342 acydburn
        function get_sql()
1153 9575 acydburn
        {
1154 10342 acydburn
                global $auth, $config, $db;
1155 9575 acydburn
1156 10558 git-gate
                // Determine forum ids
1157 10558 git-gate
                $in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums());
1158 10558 git-gate
                if (empty($in_fid_ary))
1159 10558 git-gate
                {
1160 10558 git-gate
                        return false;
1161 10558 git-gate
                }
1162 9575 acydburn
1163 10558 git-gate
                $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums());
1164 10558 git-gate
                if (empty($in_fid_ary))
1165 9965 acydburn
                {
1166 10558 git-gate
                        return false;
1167 10558 git-gate
                }
1168 10342 acydburn
1169 10558 git-gate
                // We really have to get the post ids first!
1170 10558 git-gate
                $sql = 'SELECT topic_first_post_id, topic_time
1171 10558 git-gate
                        FROM ' . TOPICS_TABLE . '
1172 10558 git-gate
                        WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . '
1173 10558 git-gate
                                AND topic_moved_id = 0
1174 10558 git-gate
                                AND topic_approved = 1
1175 10558 git-gate
                        ORDER BY topic_time DESC';
1176 10558 git-gate
                $result = $db->sql_query_limit($sql, $this->num_items);
1177 10342 acydburn
1178 10558 git-gate
                $post_ids = array();
1179 10558 git-gate
                while ($row = $db->sql_fetchrow($result))
1180 10558 git-gate
                {
1181 10558 git-gate
                        $post_ids[] = (int) $row['topic_first_post_id'];
1182 9965 acydburn
                }
1183 9965 acydburn
                $db->sql_freeresult($result);
1184 9965 acydburn
1185 10558 git-gate
                if (empty($post_ids))
1186 9575 acydburn
                {
1187 9575 acydburn
                        return false;
1188 9575 acydburn
                }
1189 9575 acydburn
1190 9575 acydburn
                $this->sql = array(
1191 10558 git-gate
                        'SELECT'        => 'f.forum_id, f.forum_name,
1192 11002 git-gate
                                                        t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time,
1193 11002 git-gate
                                                        p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
1194 9575 acydburn
                        'FROM'                => array(
1195 9575 acydburn
                                TOPICS_TABLE        => 't',
1196 9575 acydburn
                                POSTS_TABLE                => 'p',
1197 9575 acydburn
                        ),
1198 10558 git-gate
                        'LEFT_JOIN'        => array(
1199 10558 git-gate
                                array(
1200 10558 git-gate
                                        'FROM'        => array(FORUMS_TABLE => 'f'),
1201 10558 git-gate
                                        'ON'        => 'p.forum_id = f.forum_id',
1202 10558 git-gate
                                ),
1203 10558 git-gate
                        ),
1204 10558 git-gate
                        'WHERE'                => 'p.topic_id = t.topic_id
1205 10558 git-gate
                                                        AND ' . $db->sql_in_set('p.post_id', $post_ids),
1206 10558 git-gate
                        'ORDER_BY'        => 'p.post_time DESC',
1207 9575 acydburn
                );
1208 9575 acydburn
1209 9575 acydburn
                return true;
1210 9575 acydburn
        }
1211 10558 git-gate
}
1212 9575 acydburn
1213 10558 git-gate
/**
1214 10558 git-gate
* New Topics feed
1215 10558 git-gate
*
1216 10558 git-gate
* This will give you the last {$this->num_items} created topics
1217 10558 git-gate
* including the first post.
1218 10558 git-gate
*
1219 10558 git-gate
* @package phpBB3
1220 10558 git-gate
*/
1221 10558 git-gate
class phpbb_feed_topics extends phpbb_feed_topic_base
1222 10558 git-gate
{
1223 10558 git-gate
        function get_sql()
1224 9575 acydburn
        {
1225 10558 git-gate
                global $db, $config;
1226 9575 acydburn
1227 10558 git-gate
                $forum_ids_read = $this->get_readable_forums();
1228 10558 git-gate
                if (empty($forum_ids_read))
1229 10558 git-gate
                {
1230 10558 git-gate
                        return false;
1231 10558 git-gate
                }
1232 9575 acydburn
1233 10558 git-gate
                $in_fid_ary = array_diff($forum_ids_read, $this->get_excluded_forums(), $this->get_passworded_forums());
1234 10558 git-gate
                if (empty($in_fid_ary))
1235 9575 acydburn
                {
1236 10558 git-gate
                        return false;
1237 10558 git-gate
                }
1238 9575 acydburn
1239 10558 git-gate
                // We really have to get the post ids first!
1240 10558 git-gate
                $sql = 'SELECT topic_first_post_id, topic_time
1241 10558 git-gate
                        FROM ' . TOPICS_TABLE . '
1242 10558 git-gate
                        WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . '
1243 10558 git-gate
                                AND topic_moved_id = 0
1244 10558 git-gate
                                AND topic_approved = 1
1245 10558 git-gate
                        ORDER BY topic_time DESC';
1246 10558 git-gate
                $result = $db->sql_query_limit($sql, $this->num_items);
1247 10558 git-gate
1248 10558 git-gate
                $post_ids = array();
1249 10558 git-gate
                while ($row = $db->sql_fetchrow($result))
1250 10558 git-gate
                {
1251 10558 git-gate
                        $post_ids[] = (int) $row['topic_first_post_id'];
1252 9575 acydburn
                }
1253 10558 git-gate
                $db->sql_freeresult($result);
1254 10558 git-gate
1255 10558 git-gate
                if (empty($post_ids))
1256 10558 git-gate
                {
1257 10558 git-gate
                        return false;
1258 10558 git-gate
                }
1259 10558 git-gate
1260 10558 git-gate
                $this->sql = array(
1261 10558 git-gate
                        'SELECT'        => 'f.forum_id, f.forum_name,
1262 11002 git-gate
                                                        t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time,
1263 11002 git-gate
                                                        p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
1264 10558 git-gate
                        'FROM'                => array(
1265 10558 git-gate
                                TOPICS_TABLE        => 't',
1266 10558 git-gate
                                POSTS_TABLE                => 'p',
1267 10558 git-gate
                        ),
1268 10558 git-gate
                        'LEFT_JOIN'        => array(
1269 10558 git-gate
                                array(
1270 10558 git-gate
                                        'FROM'        => array(FORUMS_TABLE => 'f'),
1271 10558 git-gate
                                        'ON'        => 'p.forum_id = f.forum_id',
1272 10558 git-gate
                                ),
1273 10558 git-gate
                        ),
1274 10558 git-gate
                        'WHERE'                => 'p.topic_id = t.topic_id
1275 10558 git-gate
                                                        AND ' . $db->sql_in_set('p.post_id', $post_ids),
1276 10558 git-gate
                        'ORDER_BY'        => 'p.post_time DESC',
1277 10558 git-gate
                );
1278 10558 git-gate
1279 10558 git-gate
                return true;
1280 9575 acydburn
        }
1281 10558 git-gate
1282 10558 git-gate
        function adjust_item(&$item_row, &$row)
1283 10558 git-gate
        {
1284 10558 git-gate
                parent::adjust_item($item_row, $row);
1285 10558 git-gate
1286 10558 git-gate
                $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
1287 10558 git-gate
        }
1288 9575 acydburn
}
1289 9575 acydburn
1290 10558 git-gate
/**
1291 10558 git-gate
* Active Topics feed
1292 10558 git-gate
*
1293 10558 git-gate
* This will give you the last {$this->num_items} topics
1294 10558 git-gate
* with replies made withing the last {$this->sort_days} days
1295 10558 git-gate
* including the last post.
1296 10558 git-gate
*
1297 10558 git-gate
* @package phpBB3
1298 10558 git-gate
*/
1299 10558 git-gate
class phpbb_feed_topics_active extends phpbb_feed_topic_base
1300 9575 acydburn
{
1301 10558 git-gate
        var $sort_days = 7;
1302 10558 git-gate
1303 9575 acydburn
        function set_keys()
1304 9575 acydburn
        {
1305 10558 git-gate
                parent::set_keys();
1306 9575 acydburn
1307 10558 git-gate
                $this->set('author_id',        'topic_last_poster_id');
1308 10558 git-gate
                $this->set('creator',        'topic_last_poster_name');
1309 9575 acydburn
        }
1310 9575 acydburn
1311 9575 acydburn
        function get_sql()
1312 9575 acydburn
        {
1313 9575 acydburn
                global $db, $config;
1314 9575 acydburn
1315 10558 git-gate
                $forum_ids_read = $this->get_readable_forums();
1316 10558 git-gate
                if (empty($forum_ids_read))
1317 10558 git-gate
                {
1318 10558 git-gate
                        return false;
1319 10558 git-gate
                }
1320 9575 acydburn
1321 10558 git-gate
                $in_fid_ary = array_intersect($forum_ids_read, $this->get_forum_ids());
1322 10558 git-gate
                $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums());
1323 10558 git-gate
                if (empty($in_fid_ary))
1324 10558 git-gate
                {
1325 10558 git-gate
                        return false;
1326 10558 git-gate
                }
1327 9575 acydburn
1328 10558 git-gate
                // Search for topics in last X days
1329 10558 git-gate
                $last_post_time_sql = ($this->sort_days) ? ' AND topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : '';
1330 10558 git-gate
1331 10558 git-gate
                // We really have to get the post ids first!
1332 10558 git-gate
                $sql = 'SELECT topic_last_post_id, topic_last_post_time
1333 10558 git-gate
                        FROM ' . TOPICS_TABLE . '
1334 10558 git-gate
                        WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . '
1335 10558 git-gate
                                AND topic_moved_id = 0
1336 10558 git-gate
                                AND topic_approved = 1
1337 10558 git-gate
                                ' . $last_post_time_sql . '
1338 10558 git-gate
                        ORDER BY topic_last_post_time DESC';
1339 9575 acydburn
                $result = $db->sql_query_limit($sql, $this->num_items);
1340 9575 acydburn
1341 10558 git-gate
                $post_ids = array();
1342 9575 acydburn
                while ($row = $db->sql_fetchrow($result))
1343 9575 acydburn
                {
1344 10558 git-gate
                        $post_ids[] = (int) $row['topic_last_post_id'];
1345 9575 acydburn
                }
1346 9575 acydburn
                $db->sql_freeresult($result);
1347 9575 acydburn
1348 10558 git-gate
                if (empty($post_ids))
1349 9575 acydburn
                {
1350 9575 acydburn
                        return false;
1351 9575 acydburn
                }
1352 9575 acydburn
1353 9575 acydburn
                $this->sql = array(
1354 10558 git-gate
                        'SELECT'        => 'f.forum_id, f.forum_name,
1355 10633 git-gate
                                                        t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_views,
1356 10558 git-gate
                                                        t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time,
1357 11002 git-gate
                                                        p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
1358 9575 acydburn
                        'FROM'                => array(
1359 9575 acydburn
                                TOPICS_TABLE        => 't',
1360 9575 acydburn
                                POSTS_TABLE                => 'p',
1361 9575 acydburn
                        ),
1362 10558 git-gate
                        'LEFT_JOIN'        => array(
1363 10558 git-gate
                                array(
1364 10558 git-gate
                                        'FROM'        => array(FORUMS_TABLE => 'f'),
1365 10558 git-gate
                                        'ON'        => 'p.forum_id = f.forum_id',
1366 10558 git-gate
                                ),
1367 10558 git-gate
                        ),
1368 10558 git-gate
                        'WHERE'                => 'p.topic_id = t.topic_id
1369 10558 git-gate
                                                        AND ' . $db->sql_in_set('p.post_id', $post_ids),
1370 10558 git-gate
                        'ORDER_BY'        => 'p.post_time DESC',
1371 9575 acydburn
                );
1372 9575 acydburn
1373 9575 acydburn
                return true;
1374 9575 acydburn
        }
1375 9575 acydburn
1376 10558 git-gate
        function get_forum_ids()
1377 9575 acydburn
        {
1378 10558 git-gate
                global $db, $cache;
1379 10558 git-gate
                static $forum_ids;
1380 9575 acydburn
1381 10558 git-gate
                $cache_name        = 'feed_topic_active_forum_ids';
1382 9575 acydburn
1383 10558 git-gate
                if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false)
1384 9575 acydburn
                {
1385 10558 git-gate
                        $sql = 'SELECT forum_id
1386 10558 git-gate
                                FROM ' . FORUMS_TABLE . '
1387 10558 git-gate
                                WHERE forum_type = ' . FORUM_POST . '
1388 10558 git-gate
                                        AND ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . '
1389 10558 git-gate
                                        AND ' . $db->sql_bit_and('forum_flags', log(FORUM_FLAG_ACTIVE_TOPICS, 2), '<> 0');
1390 10558 git-gate
                        $result = $db->sql_query($sql);
1391 9575 acydburn
1392 10558 git-gate
                        $forum_ids = array();
1393 10558 git-gate
                        while ($forum_id = (int) $db->sql_fetchfield('forum_id'))
1394 10558 git-gate
                        {
1395 10558 git-gate
                                $forum_ids[$forum_id] = $forum_id;
1396 10558 git-gate
                        }
1397 10558 git-gate
                        $db->sql_freeresult($result);
1398 9575 acydburn
1399 10558 git-gate
                        $cache->put('_' . $cache_name, $forum_ids, 180);
1400 9575 acydburn
                }
1401 10558 git-gate
1402 10558 git-gate
                return $forum_ids;
1403 9575 acydburn
        }
1404 10558 git-gate
1405 10558 git-gate
        function adjust_item(&$item_row, &$row)
1406 10558 git-gate
        {
1407 10558 git-gate
                parent::adjust_item($item_row, $row);
1408 10558 git-gate
1409 10558 git-gate
                $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
1410 10558 git-gate
        }
1411 9575 acydburn
}