1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package Board3 Portal v2.1 |
5
|
|
|
* @copyright (c) 2013 Board3 Group ( www.board3.de ) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace board3\portal\modules; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package Recent |
14
|
|
|
*/ |
15
|
|
|
class recent extends module_base |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Allowed columns: Just sum up your options (Exp: left + right = 10) |
19
|
|
|
* top 1 |
20
|
|
|
* left 2 |
21
|
|
|
* center 4 |
22
|
|
|
* right 8 |
23
|
|
|
* bottom 16 |
24
|
|
|
*/ |
25
|
|
|
public $columns = 21; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Default modulename |
29
|
|
|
*/ |
30
|
|
|
public $name = 'PORTAL_RECENT'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Default module-image: |
34
|
|
|
* file must be in "{T_THEME_PATH}/images/portal/" |
35
|
|
|
*/ |
36
|
|
|
public $image_src = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* module-language file |
40
|
|
|
* file must be in "language/{$user->lang}/mods/portal/" |
41
|
|
|
*/ |
42
|
|
|
public $language = 'portal_recent_module'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* custom acp template |
46
|
|
|
* file must be in "adm/style/portal/" |
47
|
|
|
*/ |
48
|
|
|
public $custom_acp_tpl = ''; |
49
|
|
|
|
50
|
|
|
/** @var \phpbb\auth\auth */ |
51
|
|
|
protected $auth; |
52
|
|
|
|
53
|
|
|
/** @var \phpbb\config\config */ |
54
|
|
|
protected $config; |
55
|
|
|
|
56
|
|
|
/** @var \phpbb\db\driver */ |
57
|
|
|
protected $db; |
58
|
|
|
|
59
|
|
|
/** @var \phpbb\request\request */ |
60
|
|
|
protected $request; |
61
|
|
|
|
62
|
|
|
/** @var \phpbb\template */ |
63
|
|
|
protected $template; |
64
|
|
|
|
65
|
|
|
/** @var string PHP file extension */ |
66
|
|
|
protected $php_ext; |
67
|
|
|
|
68
|
|
|
/** @var string phpBB root path */ |
69
|
|
|
protected $phpbb_root_path; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Construct a recent object |
73
|
|
|
* |
74
|
|
|
* @param \phpbb\auth\auth $auth phpBB auth |
75
|
|
|
* @param \phpbb\config\config $config phpBB config |
76
|
|
|
* @param \phpbb\db\driver $db phpBB db driver |
77
|
|
|
* @param \phpbb\request\request $request phpBB request |
78
|
|
|
* @param \phpbb\template $template phpBB template |
79
|
|
|
* @param string $phpbb_root_path phpBB root path |
80
|
|
|
* @param string $phpEx php file extension |
81
|
|
|
*/ |
82
|
|
View Code Duplication |
public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $phpEx) |
83
|
|
|
{ |
84
|
|
|
$this->auth = $auth; |
85
|
|
|
$this->config = $config; |
86
|
|
|
$this->db = $db; |
87
|
|
|
$this->request = $request; |
88
|
|
|
$this->template = $template; |
89
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
90
|
|
|
$this->php_ext = $phpEx; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function get_template_center($module_id) |
97
|
|
|
{ |
98
|
|
|
// |
99
|
|
|
// Exclude forums |
100
|
|
|
// |
101
|
|
|
$sql_where = ''; |
102
|
|
|
if ($this->config['board3_recent_forum_' . $module_id] > 0) |
103
|
|
|
{ |
104
|
|
|
$exclude_forums = explode(',', $this->config['board3_recent_forum_' . $module_id]); |
105
|
|
|
|
106
|
|
|
$sql_where = ' AND ' . $this->db->sql_in_set('forum_id', array_map('intval', $exclude_forums), ($this->config['board3_recent_exclude_forums_' . $module_id]) ? true : false); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// Get a list of forums the user cannot read |
110
|
|
|
$forum_ary = array_unique(array_keys($this->auth->acl_getf('!f_read', true))); |
111
|
|
|
|
112
|
|
|
// Determine first forum the user is able to read (must not be a category) |
113
|
|
|
$sql = 'SELECT forum_id |
114
|
|
|
FROM ' . FORUMS_TABLE . ' |
115
|
|
|
WHERE forum_type = ' . FORUM_POST; |
116
|
|
|
|
117
|
|
|
$forum_sql = ''; |
118
|
|
|
if (sizeof($forum_ary)) |
119
|
|
|
{ |
120
|
|
|
$sql .= ' AND ' . $this->db->sql_in_set('forum_id', $forum_ary, true); |
121
|
|
|
$forum_sql = ' AND ' . $this->db->sql_in_set('t.forum_id', $forum_ary, true); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$result = $this->db->sql_query_limit($sql, 1, 0, 600); |
125
|
|
|
$g_forum_id = (int) $this->db->sql_fetchfield('forum_id'); |
126
|
|
|
$this->db->sql_freeresult($result); |
127
|
|
|
|
128
|
|
|
// |
129
|
|
|
// Recent announcements |
130
|
|
|
// |
131
|
|
|
$sql = 'SELECT topic_title, forum_id, topic_id |
132
|
|
|
FROM ' . TOPICS_TABLE . ' t |
133
|
|
|
WHERE topic_status <> ' . FORUM_LINK . ' |
134
|
|
|
AND topic_visibility = ' . ITEM_APPROVED . ' |
135
|
|
|
AND (topic_type = ' . POST_ANNOUNCE . ' OR topic_type = ' . POST_GLOBAL . ') |
136
|
|
|
AND topic_moved_id = 0 |
137
|
|
|
' . $sql_where . $forum_sql . ' |
138
|
|
|
ORDER BY topic_time DESC'; |
139
|
|
|
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0 , 30); |
140
|
|
|
|
141
|
|
View Code Duplication |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) |
142
|
|
|
{ |
143
|
|
|
// auto auth |
144
|
|
|
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) |
145
|
|
|
{ |
146
|
|
|
$this->template->assign_block_vars('latest_announcements', array( |
147
|
|
|
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), |
148
|
|
|
'FULL_TITLE' => censor_text($row['topic_title']), |
149
|
|
|
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) |
150
|
|
|
)); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
$this->db->sql_freeresult($result); |
154
|
|
|
|
155
|
|
|
// |
156
|
|
|
// Recent hot topics |
157
|
|
|
// |
158
|
|
|
$sql = 'SELECT topic_title, forum_id, topic_id |
159
|
|
|
FROM ' . TOPICS_TABLE . ' t |
160
|
|
|
WHERE topic_visibility = ' . ITEM_APPROVED . ' |
161
|
|
|
AND topic_posts_approved >' . $this->config['hot_threshold'] . ' |
162
|
|
|
AND topic_moved_id = 0 |
163
|
|
|
' . $sql_where . $forum_sql . ' |
164
|
|
|
ORDER BY topic_time DESC'; |
165
|
|
|
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 30); |
166
|
|
|
|
167
|
|
View Code Duplication |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) |
168
|
|
|
{ |
169
|
|
|
// auto auth |
170
|
|
|
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) |
171
|
|
|
{ |
172
|
|
|
$this->template->assign_block_vars('latest_hot_topics', array( |
173
|
|
|
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), |
174
|
|
|
'FULL_TITLE' => censor_text($row['topic_title']), |
175
|
|
|
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) |
176
|
|
|
)); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
$this->db->sql_freeresult($result); |
180
|
|
|
|
181
|
|
|
// |
182
|
|
|
// Recent topic (only show normal topic) |
183
|
|
|
// |
184
|
|
|
$sql = 'SELECT topic_title, forum_id, topic_id |
185
|
|
|
FROM ' . TOPICS_TABLE . ' t |
186
|
|
|
WHERE topic_status <> ' . ITEM_MOVED . ' |
187
|
|
|
AND topic_visibility = ' . ITEM_APPROVED . ' |
188
|
|
|
AND topic_type = ' . POST_NORMAL . ' |
189
|
|
|
AND topic_moved_id = 0 |
190
|
|
|
' . $sql_where . $forum_sql . ' |
191
|
|
|
ORDER BY topic_time DESC'; |
192
|
|
|
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 30); |
193
|
|
|
|
194
|
|
|
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) |
195
|
|
|
{ |
196
|
|
|
// auto auth |
197
|
|
|
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) |
198
|
|
|
{ |
199
|
|
|
$this->template->assign_block_vars('latest_topics', array( |
200
|
|
|
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), |
201
|
|
|
'FULL_TITLE' => censor_text($row['topic_title']), |
202
|
|
|
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']) |
203
|
|
|
)); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
$this->db->sql_freeresult($result); |
207
|
|
|
|
208
|
|
|
return 'recent_center.html'; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* {@inheritdoc} |
213
|
|
|
*/ |
214
|
|
|
public function get_template_acp($module_id) |
215
|
|
|
{ |
216
|
|
|
return array( |
217
|
|
|
'title' => 'ACP_PORTAL_RECENT_SETTINGS', |
218
|
|
|
'vars' => array( |
219
|
|
|
'legend1' => 'ACP_PORTAL_RECENT_SETTINGS', |
220
|
|
|
'board3_max_topics_' . $module_id => array('lang' => 'PORTAL_MAX_TOPIC', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), |
221
|
|
|
'board3_recent_title_limit_' . $module_id => array('lang' => 'PORTAL_RECENT_TITLE_LIMIT', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), |
222
|
|
|
'board3_recent_forum_' . $module_id => array('lang' => 'PORTAL_RECENT_FORUM', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')), |
223
|
|
|
'board3_recent_exclude_forums_' . $module_id => array('lang' => 'PORTAL_EXCLUDE_FORUM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
224
|
|
|
) |
225
|
|
|
); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* {@inheritdoc} |
230
|
|
|
*/ |
231
|
|
|
public function install($module_id) |
232
|
|
|
{ |
233
|
|
|
$this->config->set('board3_max_topics_' . $module_id, 10); |
234
|
|
|
$this->config->set('board3_recent_title_limit_' . $module_id, 100); |
235
|
|
|
$this->config->set('board3_recent_forum_' . $module_id, ''); |
236
|
|
|
$this->config->set('board3_recent_exclude_forums_' . $module_id, 1); |
237
|
|
|
return true; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* {@inheritdoc} |
242
|
|
|
*/ |
243
|
|
View Code Duplication |
public function uninstall($module_id, $db) |
244
|
|
|
{ |
245
|
|
|
$del_config = array( |
246
|
|
|
'board3_max_topics_' . $module_id, |
247
|
|
|
'board3_recent_title_limit_' . $module_id, |
248
|
|
|
'board3_recent_forum_' . $module_id, |
249
|
|
|
'board3_recent_exclude_forums_' . $module_id, |
250
|
|
|
); |
251
|
|
|
$sql = 'DELETE FROM ' . CONFIG_TABLE . ' |
252
|
|
|
WHERE ' . $db->sql_in_set('config_name', $del_config); |
253
|
|
|
return $db->sql_query($sql); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|