1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* @package Anavaro.com PM Search |
6
|
|
|
* @copyright (c) 2013 Lucifer |
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ignore |
13
|
|
|
*/ |
14
|
|
|
namespace anavaro\pmsearch\ucp; |
15
|
|
|
|
16
|
|
|
class ucp_pmsearch_module |
17
|
|
|
{ |
18
|
|
|
var $u_action; |
19
|
|
|
private $search_helper; |
20
|
|
|
private $config; |
21
|
|
|
private $terms_ary = array( |
22
|
|
|
'all' => 1, |
23
|
|
|
'any' => 2, |
24
|
|
|
'nick' => 3, |
25
|
|
|
); |
26
|
|
|
function main($id, $mode) |
27
|
|
|
{ |
28
|
|
|
global $db, $user, $auth, $template, $request, $phpbb_container, $config; |
29
|
|
|
$this->config = $config; |
30
|
|
|
$this->search_helper = $phpbb_container->get('anavaro.pmsearch.search.helper'); |
31
|
|
|
if (!$auth->acl_get('u_pmsearch')) |
32
|
|
|
{ |
33
|
|
|
trigger_error('ACCESS_DENIED'); |
34
|
|
|
} |
35
|
|
|
switch ($mode) |
36
|
|
|
{ |
37
|
|
|
case 'search': |
38
|
|
|
$this->tpl_name = 'ucp_pmsearch'; |
|
|
|
|
39
|
|
|
$template->assign_vars(array( |
40
|
|
|
'S_UCP_ACTION' => append_sid("ucp.php?i=".$id."&mode=".$mode) |
|
|
|
|
41
|
|
|
)); |
42
|
|
|
|
43
|
|
|
$terms = $request->variable('terms', 'any'); |
44
|
|
|
$keywords = utf8_normalize_nfc($request->variable('keywords', '', true)); |
|
|
|
|
45
|
|
|
|
46
|
|
|
if ($keywords) |
47
|
|
|
{ |
48
|
|
|
$this->search = null; |
|
|
|
|
49
|
|
|
$error = false; |
50
|
|
|
$search_types = $this->search_helper->get_search_types(); |
51
|
|
|
if ($this->search_helper->init_search($search_types[0], $this->search, $error)) |
52
|
|
|
{ |
53
|
|
|
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
$search_count = 0; |
56
|
|
|
$startFrom = $request->variable('start', 0); |
57
|
|
|
$id_ary = array(); |
58
|
|
|
$user_id = array( |
59
|
|
|
'' => (int) $user->data['user_id'] |
60
|
|
|
); |
61
|
|
|
//What are we searching for? |
62
|
|
|
if ($terms != 'nick') |
63
|
|
|
{ |
64
|
|
|
$this->search->split_keywords($keywords, $terms); |
|
|
|
|
65
|
|
|
//$search_count = $this->search->keyword_search('norma', 'all', 'all', array('msg_id' => 'a'), 'msg_id', 'd', 0, array($user_id), '', $id_ary, $startFrom, 25); |
66
|
|
|
$search_count = $this->search->keyword_search('norma', 'all', 'all', array('msg_id' => 'a'), 'msg_id', 'd', 0, array(), '', '', $user_id, '', $id_ary, $startFrom, $this->config['search_block_size']); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
else |
70
|
|
|
{ |
71
|
|
|
// So do we have user_id or username? |
72
|
|
|
if (!is_numeric($keywords)) |
73
|
|
|
{ |
74
|
|
|
// It's username ... let's get ID |
75
|
|
|
$sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE username_clean LIKE \'' . utf8_clean_string($keywords) . '\''; |
|
|
|
|
76
|
|
|
$result = $db->sql_query($sql); |
77
|
|
|
$user_id = $db->sql_fetchrow($result); |
78
|
|
|
$keywords = $user_id['user_id']; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$search_count = $this->search->user_search($keywords, $id_ary, $startFrom, $this->config['search_block_size']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($search_count > 0 ) |
85
|
|
|
{ |
86
|
|
|
// Let's get additional info |
87
|
|
|
$page_array = array(); |
88
|
|
|
// As there seems to be some problem with POSTGRES SQL I'll split the info query in two separate queries - one for the message ... |
89
|
|
|
$sql_array = array( |
90
|
|
|
'SELECT' => 'msg.msg_id as msg_id, msg.message_subject as msg_subject, msg.message_time as msg_time, msg.author_id as msg_author, tmsg.msg_id, MAX(tmsg.pm_unread) as unread, MAX(tmsg.pm_replied) as replied', |
91
|
|
|
'FROM' => array( |
92
|
|
|
PRIVMSGS_TABLE => 'msg', |
|
|
|
|
93
|
|
|
PRIVMSGS_TO_TABLE => 'tmsg' |
|
|
|
|
94
|
|
|
), |
95
|
|
|
'WHERE' => 'msg.msg_id = tmsg.msg_id and msg.author_id = tmsg.author_id and ' . $db->sql_in_set('msg.msg_id', $id_ary), |
96
|
|
|
'GROUP_BY' => 'msg.msg_id, tmsg.msg_id', |
97
|
|
|
'ORDER_BY' => 'msg.msg_id DESC' |
98
|
|
|
); |
99
|
|
|
$sql = $db->sql_build_query('SELECT', $sql_array); |
100
|
|
|
//$this->var_display($sql); |
101
|
|
|
$result = $db->sql_query($sql); |
102
|
|
|
// Let's populate template |
103
|
|
|
$author_uid_arrray = array(); |
104
|
|
|
while ($row = $db->sql_fetchrow($result)) |
105
|
|
|
{ |
106
|
|
|
$author_uid_arrray[] = (int) $row['msg_author']; |
107
|
|
|
$page_array[$row['msg_id']] = array( |
108
|
|
|
'msg_id' => $row['msg_id'], |
109
|
|
|
'msg_subject' => $row['msg_subject'], |
110
|
|
|
'msg_author' => $row['msg_author'], |
111
|
|
|
'msg_time' => (int) $row['msg_time'], |
112
|
|
|
'unread' => $row['unread'], |
113
|
|
|
'replied' => $row['replied'] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
if (is_numeric($keywords)) |
117
|
|
|
{ |
118
|
|
|
$author_uid_arrray[] = (int) $keywords; |
119
|
|
|
} |
120
|
|
|
$db->sql_freeresult($result); |
121
|
|
|
// ... one for the authors on this page |
122
|
|
|
$authors_array = array(); |
123
|
|
|
$sql = 'SELECT user_id, username, user_colour FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $author_uid_arrray); |
124
|
|
|
$result = $db->sql_query($sql); |
125
|
|
|
while ($row = $db->sql_fetchrow($result)) |
126
|
|
|
{ |
127
|
|
|
$authors_array[$row['user_id']] = array( |
128
|
|
|
'username' => $row['username'], |
129
|
|
|
'user_colour' => $row['user_colour'] |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
$count = 1; |
133
|
|
|
foreach ($page_array as $VAR) { |
134
|
|
|
$template->assign_block_vars('pm_results', array( |
135
|
|
|
'S_ROW_COUNT' => $count, |
136
|
|
|
'FOLDER_IMG_STYLE' => ($VAR['unread'] ? 'pm_unread' : 'pm_read'), |
137
|
|
|
'PM_CLASS' => ($VAR['replied'] ? 'pm_replied_colour' : ''), |
138
|
|
|
'U_VIEW_PM' => './ucp.php?i=pm&mode=view&p=' . $VAR['msg_id'], |
139
|
|
|
'SUBJECT' => $VAR['msg_subject'], |
140
|
|
|
'SENT_TIME' => $user->format_date($VAR['msg_time']), |
141
|
|
|
'MESSAGE_AUTHOR_FULL' => ($authors_array[$VAR['msg_author']]['user_colour'] ? '<a href="./memberlist.php?mode=viewprofile&u=' . $VAR['msg_author'] . '" class="username-coloured" style="color: #' . $authors_array[$VAR['msg_author']]['user_colour'] . ';">' . $authors_array[$VAR['msg_author']]['username'] . '</a>' : '<a href="./memberlist.php?mode=viewprofile&u=' . $VAR['msg_author'] . '" class="username">' . $authors_array[$VAR['msg_author']]['username'] . '</a>'), |
142
|
|
|
)); |
143
|
|
|
$count ++; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$pagination = $phpbb_container->get('pagination'); |
147
|
|
|
$base_url = append_sid('ucp.php?i=' . $id . '&mode=' . $mode . '&keywords=' . $keywords . '&terms=' . $terms); |
148
|
|
|
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $search_count, $this->config['search_block_size'], $startFrom); |
149
|
|
|
$pageNumber = $pagination->get_on_page($this->config['search_block_size'], $startFrom); |
|
|
|
|
150
|
|
|
if (is_numeric($keywords)) |
151
|
|
|
{ |
152
|
|
|
$template->assign_vars(array( |
153
|
|
|
'S_KEYWORDS' => $authors_array[$keywords]['username'] |
154
|
|
|
)); |
155
|
|
|
} |
156
|
|
|
else |
157
|
|
|
{ |
158
|
|
|
$template->assign_vars(array( |
159
|
|
|
'S_KEYWORDS' => $keywords |
160
|
|
|
)); |
161
|
|
|
} |
162
|
|
|
$template->assign_vars(array( |
163
|
|
|
'PAGE_NUMBER' => $pagination->on_page($search_count, $this->config['search_block_size'], $startFrom), |
164
|
|
|
'TOTAL_MESSAGES' => $search_count, |
165
|
|
|
'HAS_RESULTS' => 1, |
166
|
|
|
)); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
else |
170
|
|
|
{ |
171
|
|
|
trigger_error('NO_RESULTS_FOUND'); |
172
|
|
|
} |
173
|
|
|
// After we got the the search count we go deeper |
174
|
|
|
} |
175
|
|
|
$template->assign_vars(array( |
176
|
|
|
'SEARCH_TEARM_TYPE' => $this->terms_ary[$terms] |
177
|
|
|
)); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|