1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 201 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\services\forum; |
11
|
|
|
|
12
|
|
|
class tracker |
13
|
|
|
{ |
14
|
|
|
/** @var \phpbb\config\config */ |
15
|
|
|
protected $config; |
16
|
|
|
|
17
|
|
|
/** @var \phpbb\user */ |
18
|
|
|
protected $user; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor |
22
|
|
|
* |
23
|
|
|
* @param \phpbb\config\config $config Config object |
24
|
|
|
* @param \phpbb\user $user User object |
25
|
|
|
*/ |
26
|
5 |
|
public function __construct(\phpbb\config\config $config, \phpbb\user $user) |
27
|
|
|
{ |
28
|
5 |
|
$this->config = $config; |
29
|
5 |
|
$this->user = $user; |
30
|
5 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param array $forums |
34
|
|
|
* @param array $topics |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
5 |
|
public function get_tracking_info(array $forums, array &$topics) |
38
|
|
|
{ |
39
|
5 |
|
$info = array(); |
40
|
5 |
|
if ($this->can_track_by_lastread()) |
41
|
5 |
|
{ |
42
|
4 |
|
$info = $this->build_tracking_info('get_topic_tracking', $forums, $topics); |
43
|
4 |
|
} |
44
|
1 |
|
else if ($this->can_track_anonymous()) |
45
|
1 |
|
{ |
46
|
1 |
|
$info = $this->build_tracking_info('get_complete_topic_tracking', $forums, $topics); |
47
|
1 |
|
} |
48
|
|
|
|
49
|
5 |
|
return $info; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $function |
54
|
|
|
* @param array $forums |
55
|
|
|
* @param array $topics |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
5 |
|
protected function build_tracking_info($function, array $forums, array &$topics) |
59
|
|
|
{ |
60
|
5 |
|
$tracking_info = array(); |
61
|
5 |
|
foreach ($forums as $fid => $forum) |
62
|
|
|
{ |
63
|
5 |
|
$tracking_info[$fid] = call_user_func_array($function, array($fid, $forum['topic_list'], &$topics, array($fid => $forum['mark_time']))); |
64
|
5 |
|
} |
65
|
|
|
|
66
|
5 |
|
return $tracking_info; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
5 |
|
protected function can_track_by_lastread() |
73
|
|
|
{ |
74
|
5 |
|
return ($this->config['load_db_lastread'] && $this->user->data['is_registered']) ? true : false; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
1 |
|
protected function can_track_anonymous() |
81
|
|
|
{ |
82
|
1 |
|
return ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) ? true : false; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|