|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Member Avatar & Status [MAS]. An extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2018-forever, Dark❶ [dark1] |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0-only) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace dark1\memberavatarstatus\event; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @ignore |
|
15
|
|
|
*/ |
|
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
17
|
|
|
use dark1\memberavatarstatus\core\avatar; |
|
18
|
|
|
use dark1\memberavatarstatus\core\status; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Member Avatar & Status Event listener. |
|
22
|
|
|
*/ |
|
23
|
|
|
class search_listener implements EventSubscriberInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var avatar*/ |
|
26
|
|
|
protected $avatar; |
|
27
|
|
|
|
|
28
|
|
|
/** @var status*/ |
|
29
|
|
|
protected $status; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor for listener |
|
33
|
|
|
* |
|
34
|
|
|
* @param avatar $avatar dark1 avatar |
|
35
|
|
|
* @param status $status dark1 status |
|
36
|
|
|
* @access public |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(avatar $avatar, status $status) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->avatar = $avatar; |
|
41
|
|
|
$this->status = $status; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Assign functions defined in this class to event listeners in the core |
|
46
|
|
|
* |
|
47
|
|
|
* @return array |
|
48
|
|
|
* @static |
|
49
|
|
|
* @access public |
|
50
|
|
|
*/ |
|
51
|
|
|
static public function getSubscribedEvents() |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
'core.search_modify_tpl_ary' => 'mas_search_template', |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* MAS Search Topic Template Setup |
|
62
|
|
|
* |
|
63
|
|
|
* @param object $event The event object |
|
64
|
|
|
* @return null |
|
65
|
|
|
* @access public |
|
66
|
|
|
*/ |
|
67
|
|
|
public function mas_search_template($event) |
|
68
|
|
|
{ |
|
69
|
|
|
// Get Event Array `row` & `tpl_ary` |
|
70
|
|
|
$row = $event['row']; |
|
71
|
|
|
$tpl_ary = $event['tpl_ary']; |
|
72
|
|
|
|
|
73
|
|
|
if ($event['show_results'] == 'topics') |
|
74
|
|
|
{ |
|
75
|
|
|
// Get Both Avatar |
|
76
|
|
|
$avatar_first_poster = $this->avatar->mas_get_avatar('dark1_mas_sh_fp', $row['topic_poster']); |
|
77
|
|
|
$avatar_last_poster = $this->avatar->mas_get_avatar('dark1_mas_sh_lp', $row['topic_last_poster_id']); |
|
78
|
|
|
|
|
79
|
|
|
// Get Both Online Status |
|
80
|
|
|
$online_first_poster = $this->status->mas_get_online('dark1_mas_sh_fp', $row['topic_poster']); |
|
81
|
|
|
$online_last_poster = $this->status->mas_get_online('dark1_mas_sh_lp', $row['topic_last_poster_id']); |
|
82
|
|
|
|
|
83
|
|
|
// Add Both of Avatar & Online Status to tpl_ary |
|
84
|
|
|
$tpl_ary = array_merge($tpl_ary, [ |
|
85
|
|
|
'TOPIC_AUTHOR_AVATAR_IMG' => $avatar_first_poster, |
|
86
|
|
|
'TOPIC_AUTHOR_S_ONLINE' => $online_first_poster, |
|
87
|
|
|
'LAST_POST_AUTHOR_AVATAR_IMG' => $avatar_last_poster, |
|
88
|
|
|
'LAST_POST_AUTHOR_S_ONLINE' => $online_last_poster, |
|
89
|
|
|
]); |
|
90
|
|
|
} |
|
91
|
|
|
else |
|
92
|
|
|
{ |
|
93
|
|
|
// Get Avatar |
|
94
|
|
|
$avatar = $this->avatar->mas_get_avatar('dark1_mas_sh_up', $row['poster_id']); |
|
95
|
|
|
|
|
96
|
|
|
// Get Online Status |
|
97
|
|
|
$online = $this->status->mas_get_online('dark1_mas_sh_up', $row['poster_id']); |
|
98
|
|
|
|
|
99
|
|
|
// Add Avatar & Online Status to tpl_ary |
|
100
|
|
|
$tpl_ary = array_merge($tpl_ary, [ |
|
101
|
|
|
'POST_AUTHOR_AVATAR_IMG' => $avatar, |
|
102
|
|
|
'POST_AUTHOR_S_ONLINE' => $online, |
|
103
|
|
|
]); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// Assign tpl_ary to event -> tpl_ary |
|
107
|
|
|
$event['tpl_ary'] = $tpl_ary; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|