|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* @package Anavaro.com PM Admin |
|
6
|
|
|
* @copyright (c) 2014 Lucifer |
|
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace anavaro\pmsearch\event; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Event listener |
|
15
|
|
|
*/ |
|
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class main_listener implements EventSubscriberInterface |
|
19
|
|
|
{ |
|
20
|
1 |
|
static public function getSubscribedEvents() |
|
21
|
|
|
{ |
|
22
|
|
|
return array( |
|
23
|
1 |
|
'core.permissions' => 'acl_perms_add', |
|
24
|
|
|
'core.submit_pm_after' => 'pm_search_main', |
|
25
|
|
|
'core.delete_pm_before' => 'pm_delete_index', |
|
26
|
|
|
'core.memberlist_view_profile' => 'pm_search_with_user', |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
private $config; |
|
31
|
|
|
|
|
32
|
|
|
private $db; |
|
33
|
|
|
|
|
34
|
|
|
private $template; |
|
35
|
|
|
|
|
36
|
|
|
private $search_helper; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Constructor |
|
40
|
|
|
* NOTE: The parameters of this method must match in order and type with |
|
41
|
|
|
* the dependencies defined in the services.yml file for this service. |
|
42
|
|
|
* |
|
43
|
|
|
* @param \phpbb\config|\phpbb\config\config $config Config object |
|
|
|
|
|
|
44
|
|
|
* @param \phpbb\db\driver|\phpbb\db\driver\driver_interface $db Database object |
|
|
|
|
|
|
45
|
|
|
* @param \phpbb\template|\phpbb\template\template $template Template object |
|
|
|
|
|
|
46
|
|
|
* @internal param \phpbb\content_visibility $content_visibility Content visibility object |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, |
|
|
|
|
|
|
49
|
|
|
\phpbb\template\template $template, |
|
|
|
|
|
|
50
|
|
|
\anavaro\pmsearch\helper $search_helper) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->config = $config; |
|
53
|
1 |
|
$this->db = $db; |
|
54
|
1 |
|
$this->template = $template; |
|
55
|
1 |
|
$this->search_helper = $search_helper; |
|
56
|
|
|
|
|
57
|
1 |
|
$error = false; |
|
58
|
1 |
|
$search_types = $this->search_helper->get_search_types(); |
|
59
|
1 |
|
if ($this->search_helper->init_search($search_types[0], $this->fulltext_search, $error)) |
|
60
|
|
|
{ |
|
61
|
|
|
trigger_error($error, E_USER_WARNING); |
|
62
|
|
|
} |
|
63
|
1 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function acl_perms_add($event) |
|
66
|
|
|
{ |
|
67
|
|
|
$permissions = $event['permissions']; |
|
68
|
|
|
$permissions['u_pmsearch'] = array('lang' => 'ACL_U_PMSEARCH', 'cat' => 'misc'); |
|
69
|
|
|
$event['permissions'] = $permissions; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function pm_search_main($event) |
|
73
|
|
|
{ |
|
74
|
|
|
if ($this->config['pmsearch_pm_index']) |
|
75
|
|
|
{ |
|
76
|
|
|
$data = $event['data']; |
|
77
|
|
|
$subject = $event['subject']; |
|
78
|
|
|
$this->fulltext_search->index($event['mode'], (int) $data['msg_id'], $data['message'], $subject, (int) $data['from_user_id']); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
//Let's delete indexes of deleted PM's |
|
83
|
|
|
public function pm_delete_index($event) |
|
84
|
|
|
{ |
|
85
|
|
|
// Get PM Information for later deleting |
|
86
|
|
|
$sql = 'SELECT msg_id, pm_unread, pm_new |
|
87
|
|
|
FROM ' . PRIVMSGS_TO_TABLE . ' |
|
|
|
|
|
|
88
|
|
|
WHERE ' . $this->db->sql_in_set('msg_id', array_map('intval', $event['msg_ids'])) . ' |
|
89
|
|
|
AND folder_id = ' . $event['folder_id'] . ' |
|
90
|
|
|
AND user_id = ' . $event['user_id']; |
|
91
|
|
|
$result = $this->db->sql_query($sql); |
|
92
|
|
|
|
|
93
|
|
|
$delete_rows = array(); |
|
94
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
|
95
|
|
|
{ |
|
96
|
|
|
$delete_rows[$row['msg_id']] = 1; |
|
97
|
|
|
} |
|
98
|
|
|
$this->db->sql_freeresult($result); |
|
99
|
|
|
|
|
100
|
|
|
if (!sizeof($delete_rows)) |
|
101
|
|
|
{ |
|
102
|
|
|
return false; |
|
103
|
|
|
} |
|
104
|
|
|
// If no one has read it (the delete_pm function will delete all data |
|
105
|
|
|
if ($event['folder_id'] == PRIVMSGS_OUTBOX) |
|
|
|
|
|
|
106
|
|
|
{ |
|
107
|
|
|
$this->fulltext_search->index_remove($event['msg_ids']); |
|
108
|
|
|
} |
|
109
|
|
|
else |
|
110
|
|
|
{ |
|
111
|
|
|
$sql = 'SELECT COUNT(msg_id) as count, msg_id |
|
112
|
|
|
FROM ' . PRIVMSGS_TO_TABLE . ' |
|
113
|
|
|
WHERE ' . $this->db->sql_in_set('msg_id', array_keys($delete_rows)) . |
|
114
|
|
|
' GROUP BY msg_id'; |
|
115
|
|
|
$result = $this->db->sql_query($sql); |
|
116
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
|
117
|
|
|
{ |
|
118
|
|
|
if ($row['count'] == 2) |
|
119
|
|
|
{ |
|
120
|
|
|
unset($delete_rows[$row['msg_id']]); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
$this->db->sql_freeresult($result); |
|
124
|
|
|
|
|
125
|
|
|
$delete_ids = array_keys($delete_rows); |
|
126
|
|
|
if (sizeof($delete_ids)) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->fulltext_search->index_remove($delete_ids); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
1 |
|
public function pm_search_with_user($event) |
|
134
|
|
|
{ |
|
135
|
1 |
|
$target = $event['member']['user_id']; |
|
136
|
1 |
|
$url = generate_board_url() . '/ucp.php?i=\anavaro\pmsearch\ucp\ucp_pmsearch_module&mode=search&terms=nick&keywords=' . $target; |
|
|
|
|
|
|
137
|
1 |
|
$this->template->assign_vars(array( |
|
138
|
1 |
|
'S_SEARCH_WITH_USER' => true, |
|
139
|
1 |
|
'U_SEARCH_WITH_USER' => $url |
|
140
|
|
|
)); |
|
141
|
1 |
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths