1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package phpBB Extension - RH Topic Tags |
5
|
|
|
* @copyright (c) 2014 Robet Heim |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace robertheim\topictags\controller; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents a topic. |
14
|
|
|
*/ |
15
|
|
|
class topic |
16
|
|
|
{ |
17
|
|
|
/** @var array */ |
18
|
|
|
private $topic_row; |
19
|
|
|
|
20
|
|
|
/** @var \phpbb\user */ |
21
|
|
|
private $user; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\auth\auth */ |
24
|
|
|
private $auth; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $phpbb_root_path; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
private $php_ext; |
31
|
|
|
|
32
|
|
|
/** @var int */ |
33
|
|
|
private $topic_id; |
34
|
|
|
|
35
|
|
|
// unread_topic should be based on the users topic tracking info |
36
|
|
|
// this wont be supported until phpbb code is less complex |
37
|
|
|
/** @var boolean */ |
38
|
|
|
private $unread_topic = false; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
private $folder_img = ''; |
42
|
|
|
/** @var string */ |
43
|
|
|
private $folder_alt = ''; |
44
|
|
|
/** @var string */ |
45
|
|
|
private $topic_type = ''; |
46
|
|
|
|
47
|
|
|
/** @var int */ |
48
|
|
|
private $forum_id; |
49
|
|
|
|
50
|
|
|
/** @var mixed */ |
51
|
|
|
private $replies; |
52
|
|
|
|
53
|
|
|
/** @var string */ |
54
|
|
|
private $view_topic_url_params; |
55
|
|
|
/** @var string */ |
56
|
|
|
private $view_topic_url; |
57
|
|
|
|
58
|
|
|
/** @var string */ |
59
|
|
|
private $newest_post_url; |
60
|
|
|
/** @var string */ |
61
|
|
|
private $last_post_url; |
62
|
|
|
|
63
|
|
|
/** @var boolean */ |
64
|
|
|
private $topic_unapproved; |
65
|
|
|
/** @var boolean */ |
66
|
|
|
private $posts_unapproved; |
67
|
|
|
/** @var boolean */ |
68
|
|
|
private $topic_deleted; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* |
72
|
|
|
* @param array $topic_row a db topic row |
73
|
|
|
*/ |
74
|
|
|
public function __construct(array $topic_row, |
75
|
|
|
\phpbb\user $user, |
76
|
|
|
\phpbb\auth\auth $auth, |
77
|
|
|
\phpbb\content_visibility $phpbb_content_visibility, |
78
|
|
|
$phpbb_root_path, |
79
|
|
|
$php_ext) |
80
|
|
|
{ |
81
|
|
|
$this->user = $user; |
82
|
|
|
$this->auth = $auth; |
83
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
84
|
|
|
$this->php_ext = $php_ext; |
85
|
|
|
$this->topic_row = $topic_row; |
86
|
|
|
if ($topic_row['topic_status'] == ITEM_MOVED) |
87
|
|
|
{ |
88
|
|
|
$this->topic_id = $topic_row['topic_moved_id']; |
89
|
|
|
} |
90
|
|
|
else |
91
|
|
|
{ |
92
|
|
|
$this->topic_id = $topic_row['topic_id']; |
93
|
|
|
} |
94
|
|
|
$this->forum_id = (int) $this->topic_row['forum_id']; |
95
|
|
|
|
96
|
|
|
$this->view_topic_url_params = 'f=' . $this->forum_id . '&t=' . $this->topic_id; |
97
|
|
|
$this->view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params); |
98
|
|
|
$this->newest_post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&view=unread') . '#unread'; |
99
|
|
|
$this->last_post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&p=' . $topic_row['topic_last_post_id']) . '#p' . $topic_row['topic_last_post_id']; |
100
|
|
|
|
101
|
|
|
$this->replies = $phpbb_content_visibility->get_count('topic_posts', $topic_row, $this->forum_id) - 1; |
102
|
|
|
|
103
|
|
|
if (!function_exists('topic_status')) |
104
|
|
|
{ |
105
|
|
|
include ($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); |
106
|
|
|
} |
107
|
|
|
// Get folder img, topic status/type related information |
108
|
|
|
topic_status($topic_row, $this->replies, $this->unread_topic(), $this->folder_img, $this->folder_alt, $this->topic_type); |
109
|
|
|
|
110
|
|
|
$this->topic_unapproved = (($topic_row['topic_visibility'] == ITEM_UNAPPROVED || $topic_row['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $this->forum_id)); |
111
|
|
|
$this->posts_unapproved = ($topic_row['topic_visibility'] == ITEM_APPROVED && $topic_row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $this->forum_id)); |
112
|
|
|
$this->topic_deleted = $topic_row['topic_visibility'] == ITEM_DELETED; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function user_posted() |
116
|
|
|
{ |
117
|
|
|
return (isset($this->topic_row['topic_posted']) && $this->topic_row['topic_posted']) ? true : false; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function attach_icon_img() |
121
|
|
|
{ |
122
|
|
|
return ($this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $this->topic_row['forum_id']) && $this->topic_row['topic_attachment']) ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : ''; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function topic_reported() |
126
|
|
|
{ |
127
|
|
|
return (!empty($this->topic_row['topic_reported']) && $this->auth->acl_get('m_report', $this->topic_row['forum_id'])) ? true : false; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function u_mcp_queue() |
131
|
|
|
{ |
132
|
|
|
$mode = ''; |
|
|
|
|
133
|
|
|
if ($this->topic_unapproved) |
134
|
|
|
{ |
135
|
|
|
$mode = 'approve_details'; |
136
|
|
|
} |
137
|
|
|
else if ($this->posts_unapproved) |
138
|
|
|
{ |
139
|
|
|
$mode = 'unapproved_posts'; |
140
|
|
|
} |
141
|
|
|
else if ($this->topic_deleted) |
142
|
|
|
{ |
143
|
|
|
$mode = 'deleted_topics'; |
144
|
|
|
} |
145
|
|
|
else |
146
|
|
|
{ |
147
|
|
|
return ''; |
148
|
|
|
} |
149
|
|
|
return append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", "i=queue&mode=$mode&t={$this->topic_id}", true, $this->user->session_id); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function unapproved_img() |
153
|
|
|
{ |
154
|
|
|
return ($this->topic_unapproved || $this->posts_unapproved) ? $this->user->img('icon_topic_unapproved', ($this->topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : ''; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function topic_deleted() |
158
|
|
|
{ |
159
|
|
|
return $this->topic_deleted; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function topic_unapproved() |
163
|
|
|
{ |
164
|
|
|
return $this->topic_unapproved; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function posts_unapproved() |
168
|
|
|
{ |
169
|
|
|
return $this->posts_unapproved; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function replies() |
173
|
|
|
{ |
174
|
|
|
return $this->replies; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function newest_post_url() |
178
|
|
|
{ |
179
|
|
|
return $this->newest_post_url; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function last_post_url() |
183
|
|
|
{ |
184
|
|
|
return $this->last_post_url; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function view_topic_url() |
188
|
|
|
{ |
189
|
|
|
return $this->view_topic_url; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function img_style() |
193
|
|
|
{ |
194
|
|
|
return $this->folder_img; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function folder_img() |
198
|
|
|
{ |
199
|
|
|
return $this->user->img($this->folder_img, $this->folder_alt); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function folder_img_alt() |
203
|
|
|
{ |
204
|
|
|
return $this->user->lang[$this->folder_alt]; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function topic_type() |
208
|
|
|
{ |
209
|
|
|
return $this->topic_type; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function unread_topic() |
213
|
|
|
{ |
214
|
|
|
return $this->unread_topic; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function forum_id() |
218
|
|
|
{ |
219
|
|
|
return $this->forum_id; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function topic_id() |
223
|
|
|
{ |
224
|
|
|
return $this->topic_id; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function has_poll() |
228
|
|
|
{ |
229
|
|
|
return ($this->topic_row['poll_start']) ? true : false; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function post_announce() |
233
|
|
|
{ |
234
|
|
|
return ($this->topic_row['topic_type'] == POST_ANNOUNCE) ? true : false; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function post_global() |
238
|
|
|
{ |
239
|
|
|
return ($this->topic_row['topic_type'] == POST_GLOBAL) ? true : false; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function post_sticky() |
243
|
|
|
{ |
244
|
|
|
return ($this->topic_row['topic_type'] == POST_STICKY) ? true : false; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function locked() |
248
|
|
|
{ |
249
|
|
|
return ($this->topic_row['topic_status'] == ITEM_LOCKED) ? true : false; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function moved() |
253
|
|
|
{ |
254
|
|
|
return ($this->topic_row['topic_status'] == ITEM_MOVED) ? true : false; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
public function last_post_author() |
258
|
|
|
{ |
259
|
|
|
return get_username_string('profile', $this->topic_row['topic_last_poster_id'], $this->topic_row['topic_last_poster_name'], $this->topic_row['topic_last_poster_colour']); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
public function topic_author() |
263
|
|
|
{ |
264
|
|
|
return get_username_string('profile', $this->topic_row['topic_poster'], $this->topic_row['topic_first_poster_name'], $this->topic_row['topic_first_poster_colour']); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
public function mcp_report() |
268
|
|
|
{ |
269
|
|
|
return append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=reports&mode=reports&f=' . $this->forum_id . '&t=' . $this->topic_id, true, $this->user->session_id); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function forum_name() |
273
|
|
|
{ |
274
|
|
|
return (isset($this->topic_row['forum_name'])) ? $this->topic_row['forum_name'] : ''; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function topic_title() |
278
|
|
|
{ |
279
|
|
|
return censor_text($this->topic_row['topic_title']); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function views() |
283
|
|
|
{ |
284
|
|
|
return $this->topic_row['topic_views']; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function author($mode) |
288
|
|
|
{ |
289
|
|
|
return get_username_string($mode, $this->topic_row['topic_poster'], $this->topic_row['topic_first_poster_name'], $this->topic_row['topic_first_poster_colour']); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function last_author($mode) |
293
|
|
|
{ |
294
|
|
|
return get_username_string($mode, $this->topic_row['topic_last_poster_id'], $this->topic_row['topic_last_poster_name'], $this->topic_row['topic_last_poster_colour']); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public function topic_time() |
298
|
|
|
{ |
299
|
|
|
return $this->user->format_date($this->topic_row['topic_time']); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
public function last_post_subject() |
303
|
|
|
{ |
304
|
|
|
return censor_text($this->topic_row['topic_last_post_subject']); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
public function last_post_time() |
308
|
|
|
{ |
309
|
|
|
return $this->user->format_date($this->topic_row['topic_last_post_time']); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
public function last_view_time() |
313
|
|
|
{ |
314
|
|
|
return $this->user->format_date($this->topic_row['topic_last_view_time']); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* This will allow the style designer to output a different header |
319
|
|
|
* or even separate the list of announcements from sticky and normal topics |
320
|
|
|
* @return number |
321
|
|
|
*/ |
322
|
|
|
public function topic_type_switch() |
323
|
|
|
{ |
324
|
|
|
$s_type_switch = 0; |
325
|
|
|
$s_type_switch_test = ($this->topic_row['topic_type'] == POST_ANNOUNCE || $this->topic_row['topic_type'] == POST_GLOBAL) ? 1 : 0; |
326
|
|
|
return ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test; |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.