From ffdb5c9388f345ee63c2df573638b267f091f033 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:05:22 +0200 Subject: [ticket/11481] Move topic feed to own file PHPBB3-11481 --- phpBB/includes/feed/topic.php | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 phpBB/includes/feed/topic.php (limited to 'phpBB/includes/feed/topic.php') diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php new file mode 100644 index 0000000000..eb77eddb5c --- /dev/null +++ b/phpBB/includes/feed/topic.php @@ -0,0 +1,114 @@ +num_items} posts made within this topic. +* +* @package phpBB3 +*/ +class phpbb_feed_topic extends phpbb_feed_post_base +{ + var $topic_id = 0; + var $forum_id = 0; + var $topic_data = array(); + + function __construct($topic_id) + { + parent::__construct(); + + $this->topic_id = (int) $topic_id; + } + + function open() + { + global $auth, $db, $user; + + $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 + FROM ' . TOPICS_TABLE . ' t + LEFT JOIN ' . FORUMS_TABLE . ' f + ON (f.forum_id = t.forum_id) + WHERE t.topic_id = ' . $this->topic_id; + $result = $db->sql_query($sql); + $this->topic_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (empty($this->topic_data)) + { + trigger_error('NO_TOPIC'); + } + + $this->forum_id = (int) $this->topic_data['forum_id']; + + // Make sure topic is either approved or user authed + if (!$this->topic_data['topic_approved'] && !$auth->acl_get('m_approve', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + + // Make sure forum is not excluded from feed + if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->topic_data['forum_options'])) + { + trigger_error('NO_FEED'); + } + + // Make sure we can read this forum + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + + // Make sure forum is not passworded or user is authed + if ($this->topic_data['forum_password']) + { + $forum_ids_passworded = $this->get_passworded_forums(); + + if (isset($forum_ids_passworded[$this->forum_id])) + { + trigger_error('SORRY_AUTH_READ'); + } + + unset($forum_ids_passworded); + } + } + + function get_sql() + { + global $auth, $db; + + $this->sql = array( + '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, ' . + 'u.username, u.user_id', + 'FROM' => array( + POSTS_TABLE => 'p', + USERS_TABLE => 'u', + ), + 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' + ' . ($this->forum_id && !$auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' + AND p.poster_id = u.user_id', + 'ORDER_BY' => 'p.post_time DESC', + ); + + return true; + } + + function get_item() + { + return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row; + } +} -- cgit v1.2.1 From 3efe0eb24687a0e36e316b60887eff3ed45ae9b4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 20:04:23 +0200 Subject: [ticket/11481] Use container for all classes and inject dependencies PHPBB3-11481 --- phpBB/includes/feed/topic.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/feed/topic.php') diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php index eb77eddb5c..e4805e5539 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/includes/feed/topic.php @@ -28,11 +28,17 @@ class phpbb_feed_topic extends phpbb_feed_post_base var $forum_id = 0; var $topic_data = array(); - function __construct($topic_id) + /** + * Set the Topic ID + * + * @param int $topic_id Topic ID + * @return phpbb_feed_topic + */ + public function set_topic_id($topic_id) { - parent::__construct(); - $this->topic_id = (int) $topic_id; + + return $this; } function open() -- cgit v1.2.1 From 63334514555acea665186f20046a49a5ed41c334 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 20:32:47 +0200 Subject: [ticket/11481] Remove globals and use dependency injection instead PHPBB3-11481 --- phpBB/includes/feed/topic.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/feed/topic.php') diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php index e4805e5539..7d9a344982 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/includes/feed/topic.php @@ -43,16 +43,14 @@ class phpbb_feed_topic extends phpbb_feed_post_base function open() { - global $auth, $db, $user; - $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 FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id) WHERE t.topic_id = ' . $this->topic_id; - $result = $db->sql_query($sql); - $this->topic_data = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->topic_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (empty($this->topic_data)) { @@ -62,7 +60,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base $this->forum_id = (int) $this->topic_data['forum_id']; // Make sure topic is either approved or user authed - if (!$this->topic_data['topic_approved'] && !$auth->acl_get('m_approve', $this->forum_id)) + if (!$this->topic_data['topic_approved'] && !$this->auth->acl_get('m_approve', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); } @@ -74,7 +72,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base } // Make sure we can read this forum - if (!$auth->acl_get('f_read', $this->forum_id)) + if (!$this->auth->acl_get('f_read', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); } @@ -95,8 +93,6 @@ class phpbb_feed_topic extends phpbb_feed_post_base function get_sql() { - global $auth, $db; - $this->sql = array( '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, ' . 'u.username, u.user_id', @@ -105,7 +101,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base USERS_TABLE => 'u', ), 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' - ' . ($this->forum_id && !$auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' + ' . ($this->forum_id && !$this->auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', ); -- cgit v1.2.1