blob: 84b4d5d5606345da0379830cbb5765d0aad8470a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\feed;
/**
* Factory class to return correct object
*/
class factory
{
/**
* Service container object
* @var object
*/
protected $container;
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/**
* Constructor
*
* @param objec $container Container object
* @param \phpbb\config\config $config Config object
* @param \phpbb\db\driver\driver_interface $db Database connection
* @return null
*/
public function __construct($container, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db)
{
$this->container = $container;
$this->config = $config;
$this->db = $db;
}
/**
* Return correct object for specified mode
*
* @param string $mode The feeds mode.
* @param int $forum_id Forum id specified by the script if forum feed provided.
* @param int $topic_id Topic id specified by the script if topic feed provided.
*
* @return object Returns correct feeds object for specified mode.
*/
function get_feed($mode, $forum_id, $topic_id)
{
switch ($mode)
{
case 'forums':
if (!$this->config['feed_overall_forums'])
{
return false;
}
return $this->container->get('feed.forums');
break;
case 'topics':
case 'topics_new':
if (!$this->config['feed_topics_new'])
{
return false;
}
return $this->container->get('feed.topics');
break;
case 'topics_active':
if (!$this->config['feed_topics_active'])
{
return false;
}
return $this->container->get('feed.topics_active');
break;
case 'news':
// Get at least one news forum
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
$result = $this->db->sql_query_limit($sql, 1, 0, 600);
$s_feed_news = (int) $this->db->sql_fetchfield('forum_id');
$this->db->sql_freeresult($result);
if (!$s_feed_news)
{
return false;
}
return $this->container->get('feed.news');
break;
default:
if ($topic_id && $this->config['feed_topic'])
{
return $this->container->get('feed.topic')
->set_topic_id($topic_id);
}
else if ($forum_id && $this->config['feed_forum'])
{
return $this->container->get('feed.forum')
->set_forum_id($forum_id);
}
else if ($this->config['feed_overall'])
{
return $this->container->get('feed.overall');
}
return false;
break;
}
}
}
|