Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| topics_active | |
0.00% |
0 / 59 |
|
0.00% |
0 / 4 |
210 | |
0.00% |
0 / 1 |
| set_keys | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| get_sql | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
42 | |||
| get_forum_ids | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
| adjust_item | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\feed; |
| 15 | |
| 16 | /** |
| 17 | * Active Topics feed |
| 18 | * |
| 19 | * This will give you the last {$this->num_items} topics |
| 20 | * with replies made within the last {$this->sort_days} days |
| 21 | * including the last post. |
| 22 | */ |
| 23 | class topics_active extends topic_base |
| 24 | { |
| 25 | protected $sort_days = 7; |
| 26 | |
| 27 | /** |
| 28 | * {@inheritdoc} |
| 29 | */ |
| 30 | public function set_keys() |
| 31 | { |
| 32 | parent::set_keys(); |
| 33 | |
| 34 | $this->set('author_id', 'topic_last_poster_id'); |
| 35 | $this->set('creator', 'topic_last_poster_name'); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * {@inheritdoc} |
| 40 | */ |
| 41 | protected function get_sql() |
| 42 | { |
| 43 | $forum_ids_read = $this->get_readable_forums(); |
| 44 | if (empty($forum_ids_read)) |
| 45 | { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | $in_fid_ary = array_intersect($forum_ids_read, $this->get_forum_ids()); |
| 50 | $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums()); |
| 51 | if (empty($in_fid_ary)) |
| 52 | { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // Search for topics in last X days |
| 57 | $last_post_time_sql = ($this->sort_days) ? ' AND topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : ''; |
| 58 | |
| 59 | // We really have to get the post ids first! |
| 60 | $sql = 'SELECT topic_last_post_id, topic_last_post_time |
| 61 | FROM ' . TOPICS_TABLE . ' |
| 62 | WHERE topic_moved_id = 0 |
| 63 | AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $in_fid_ary) . ' |
| 64 | ' . $last_post_time_sql . ' |
| 65 | ORDER BY topic_last_post_time DESC, topic_last_post_id DESC'; |
| 66 | $result = $this->db->sql_query_limit($sql, $this->num_items); |
| 67 | |
| 68 | $post_ids = array(); |
| 69 | while ($row = $this->db->sql_fetchrow($result)) |
| 70 | { |
| 71 | $post_ids[] = (int) $row['topic_last_post_id']; |
| 72 | } |
| 73 | $this->db->sql_freeresult($result); |
| 74 | |
| 75 | if (empty($post_ids)) |
| 76 | { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | parent::fetch_attachments($post_ids); |
| 81 | |
| 82 | $this->sql = array( |
| 83 | 'SELECT' => 'f.forum_id, f.forum_name, |
| 84 | t.topic_id, t.topic_title, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views, |
| 85 | t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, |
| 86 | 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, p.post_attachment, t.topic_visibility', |
| 87 | 'FROM' => array( |
| 88 | TOPICS_TABLE => 't', |
| 89 | POSTS_TABLE => 'p', |
| 90 | ), |
| 91 | 'LEFT_JOIN' => array( |
| 92 | array( |
| 93 | 'FROM' => array(FORUMS_TABLE => 'f'), |
| 94 | 'ON' => 'p.forum_id = f.forum_id', |
| 95 | ), |
| 96 | ), |
| 97 | 'WHERE' => 'p.topic_id = t.topic_id |
| 98 | AND ' . $this->db->sql_in_set('p.post_id', $post_ids), |
| 99 | 'ORDER_BY' => 'p.post_time DESC, p.post_id DESC', |
| 100 | ); |
| 101 | |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns the ids of the forums not excluded from the active list |
| 107 | * |
| 108 | * @return int[] |
| 109 | */ |
| 110 | private function get_forum_ids() |
| 111 | { |
| 112 | static $forum_ids; |
| 113 | |
| 114 | $cache_name = 'feed_topic_active_forum_ids'; |
| 115 | |
| 116 | if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false) |
| 117 | { |
| 118 | $sql = 'SELECT forum_id |
| 119 | FROM ' . FORUMS_TABLE . ' |
| 120 | WHERE forum_type = ' . FORUM_POST . ' |
| 121 | AND ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' |
| 122 | AND ' . $this->db->sql_bit_and('forum_flags', (int) round(log(FORUM_FLAG_ACTIVE_TOPICS, 2)), '<> 0'); |
| 123 | $result = $this->db->sql_query($sql); |
| 124 | |
| 125 | $forum_ids = array(); |
| 126 | while ($forum_id = (int) $this->db->sql_fetchfield('forum_id')) |
| 127 | { |
| 128 | $forum_ids[$forum_id] = $forum_id; |
| 129 | } |
| 130 | $this->db->sql_freeresult($result); |
| 131 | |
| 132 | $this->cache->put('_' . $cache_name, $forum_ids, 180); |
| 133 | } |
| 134 | |
| 135 | return $forum_ids; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * {@inheritdoc} |
| 140 | */ |
| 141 | public function adjust_item(&$item_row, &$row) |
| 142 | { |
| 143 | parent::adjust_item($item_row, $row); |
| 144 | |
| 145 | $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; |
| 146 | } |
| 147 | } |