aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/feed/base.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2013-06-06 20:32:47 +0200
committerJoas Schilling <nickvergessen@gmx.de>2013-06-06 20:32:47 +0200
commit63334514555acea665186f20046a49a5ed41c334 (patch)
tree49fb58d9b8bcde36cab13ddae7cfc6230878d06c /phpBB/includes/feed/base.php
parent3efe0eb24687a0e36e316b60887eff3ed45ae9b4 (diff)
downloadforums-63334514555acea665186f20046a49a5ed41c334.tar
forums-63334514555acea665186f20046a49a5ed41c334.tar.gz
forums-63334514555acea665186f20046a49a5ed41c334.tar.bz2
forums-63334514555acea665186f20046a49a5ed41c334.tar.xz
forums-63334514555acea665186f20046a49a5ed41c334.zip
[ticket/11481] Remove globals and use dependency injection instead
PHPBB3-11481
Diffstat (limited to 'phpBB/includes/feed/base.php')
-rw-r--r--phpBB/includes/feed/base.php78
1 files changed, 48 insertions, 30 deletions
diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php
index 2ffd20d31a..c8015ab916 100644
--- a/phpBB/includes/feed/base.php
+++ b/phpBB/includes/feed/base.php
@@ -28,6 +28,24 @@ abstract class phpbb_feed_base
*/
protected $helper;
+ /** @var phpbb_config */
+ protected $config;
+
+ /** @var phpbb_db_driver */
+ protected $db;
+
+ /** @var phpbb_cache_driver_interface */
+ protected $cache;
+
+ /** @var phpbb_user */
+ protected $user;
+
+ /** @var phpbb_auth */
+ protected $auth;
+
+ /** @var string */
+ protected $phpEx;
+
/**
* SQL Query to be executed to get feed items
*/
@@ -57,18 +75,30 @@ abstract class phpbb_feed_base
* Constructor
*
* @param phpbb_feed_helper $helper Feed helper
+ * @param phpbb_config $config Config object
+ * @param phpbb_db_driver $db Database connection
+ * @param phpbb_cache_driver_interface $cache Cache object
+ * @param phpbb_user $user User object
+ * @param phpbb_auth $auth Auth object
+ * @param string $phpEx php file extension
* @return null
*/
- function __construct(phpbb_feed_helper $helper)
+ function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $phpEx)
{
- global $config;
+ $this->config = $config;
+ $this->helper = $helper;
+ $this->db = $db;
+ $this->cache = $cache;
+ $this->user = $user;
+ $this->auth = $auth;
+ $this->phpEx = $phpEx;
$this->set_keys();
// Allow num_items to be string
if (is_string($this->num_items))
{
- $this->num_items = (int) $config[$this->num_items];
+ $this->num_items = (int) $this->config[$this->num_items];
// A precaution
if (!$this->num_items)
@@ -76,8 +106,6 @@ abstract class phpbb_feed_base
$this->num_items = 10;
}
}
-
- $this->helper = $helper;
}
/**
@@ -99,11 +127,9 @@ abstract class phpbb_feed_base
*/
function close()
{
- global $db;
-
if (!empty($this->result))
{
- $db->sql_freeresult($this->result);
+ $this->db->sql_freeresult($this->result);
}
}
@@ -125,12 +151,11 @@ abstract class phpbb_feed_base
function get_readable_forums()
{
- global $auth;
static $forum_ids;
if (!isset($forum_ids))
{
- $forum_ids = array_keys($auth->acl_getf('f_read', true));
+ $forum_ids = array_keys($this->auth->acl_getf('f_read', true));
}
return $forum_ids;
@@ -138,12 +163,11 @@ abstract class phpbb_feed_base
function get_moderator_approve_forums()
{
- global $auth;
static $forum_ids;
if (!isset($forum_ids))
{
- $forum_ids = array_keys($auth->acl_getf('m_approve', true));
+ $forum_ids = array_keys($this->auth->acl_getf('m_approve', true));
}
return $forum_ids;
@@ -163,27 +187,26 @@ abstract class phpbb_feed_base
function get_excluded_forums()
{
- global $db, $cache;
static $forum_ids;
// Matches acp/acp_board.php
$cache_name = 'feed_excluded_forum_ids';
- if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false)
+ if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false)
{
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
- WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0');
- $result = $db->sql_query($sql);
+ WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0');
+ $result = $this->db->sql_query($sql);
$forum_ids = array();
- while ($forum_id = (int) $db->sql_fetchfield('forum_id'))
+ while ($forum_id = (int) $this->db->sql_fetchfield('forum_id'))
{
$forum_ids[$forum_id] = $forum_id;
}
- $db->sql_freeresult($result);
+ $this->db->sql_freeresult($result);
- $cache->put('_' . $cache_name, $forum_ids);
+ $this->cache->put('_' . $cache_name, $forum_ids);
}
return $forum_ids;
@@ -198,14 +221,11 @@ abstract class phpbb_feed_base
function get_passworded_forums()
{
- global $user;
-
- return $user->get_passworded_forums();
+ return $this->user->get_passworded_forums();
}
function get_item()
{
- global $db, $cache;
static $result;
if (!isset($result))
@@ -216,26 +236,24 @@ abstract class phpbb_feed_base
}
// Query database
- $sql = $db->sql_build_query('SELECT', $this->sql);
- $result = $db->sql_query_limit($sql, $this->num_items);
+ $sql = $this->db->sql_build_query('SELECT', $this->sql);
+ $result = $this->db->sql_query_limit($sql, $this->num_items);
}
- return $db->sql_fetchrow($result);
+ return $this->db->sql_fetchrow($result);
}
function user_viewprofile($row)
{
- global $phpEx, $user;
-
$author_id = (int) $row[$this->get('author_id')];
if ($author_id == ANONYMOUS)
{
// Since we cannot link to a profile, we just return GUEST
// instead of $row['username']
- return $user->lang['GUEST'];
+ return $this->user->lang['GUEST'];
}
- return '<a href="' . $this->helper->append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&amp;u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
+ return '<a href="' . $this->helper->append_sid('/memberlist.' . $this->phpEx, 'mode=viewprofile&amp;u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
}
}