forked from Kak2X/jul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate.php
242 lines (213 loc) · 7.67 KB
/
private.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
require 'lib/function.php';
$meta['noindex'] = true;
if (!$loguser['id']) {
errorpage("You need to be logged in to read your private messages.", 'login.php', 'log in (then try again)');
}
$_GET['id'] = filter_int($_GET['id']);
$_GET['dir'] = isset($_GET['dir']) ? filter_int($_GET['dir']) : PMFOLDER_ALL;
$_GET['action'] = filter_string($_GET['action']);
// Viewing someone else?
if (!$isadmin || !valid_user($_GET['id'])) {
$u = $loguser['id'];
$_GET['id'] = 0;
} else {
$u = $_GET['user'] = $_GET['id'];
}
$idparam = opt_param(['id']);
$navlink = '&'.opt_param(['dir', 'user']);
if ($u == $loguser['id'] && $_GET['action']) {
check_token($_GET['auth'], TOKEN_MGET);
switch ($_GET['action']) {
case 'markfolderread':
if (!valid_pm_folder($_GET['dir'], $loguser['id'])) {
errorpage("This folder isn't valid.");
}
$sql->query("
DELETE FROM pm_threadsread
WHERE uid = {$loguser['id']} AND tid IN (
SELECT `thread`
FROM `pm_access`
WHERE `user` = '{$loguser['id']}' AND `folder` = '{$_GET['dir']}'
)");
$sql->query("REPLACE INTO pm_foldersread (user, folder, readdate) VALUES ({$loguser['id']}, {$_GET['dir']}, ".ctime().')');
break;
case 'markallfoldersread':
$sql->query("DELETE FROM pm_threadsread WHERE uid = {$loguser['id']}");
$sql->query("
REPLACE INTO pm_foldersread (user, folder, readdate)
SELECT {$loguser['id']}, folder, ".ctime()."
FROM pm_access
WHERE user = {$loguser['id']}
");
break;
}
return header("Location: private.php?dir={$_GET['dir']}");
}
$folderread = $sql->getresultsbykey("SELECT folder, readdate FROM pm_foldersread WHERE user = {$loguser['id']}");
pageheader("Private Messages");
$ppp = get_ppp();
$tpp = get_tpp();
$_GET['page'] = filter_int($_GET['page']);
$min = $_GET['page'] * $tpp;
/*
Get the thread list
*/
switch ($_GET['dir']) {
case PMFOLDER_ALL: // Everything
$qwhere = "";
$nofolder = true;
break;
case PMFOLDER_TO: // All pmthreads in which you've been added
$qwhere = " AND t.user != {$u}";
$nofolder = true;
break;
case PMFOLDER_BY: // All pmthreads from you
$qwhere = " AND t.user = {$u}";
break;
default: // Folders
if (!valid_pm_folder($_GET['dir'], $u)) {
errorpage("Cannot access the folder. It either doesn't exist or it isn't for you.",'private.php','your private message box',0);
}
$qwhere = " AND a.folder = {$_GET['dir']}";
}
// Get the userfields for partecipants in the listed threads
$partecipants = $sql->fetchq("
SELECT a.thread, $userfields
FROM pm_access a
LEFT JOIN users u ON u.id = a.user
INNER JOIN (
SELECT t.id
FROM pm_access a
LEFT JOIN pm_threads t ON a.thread = t.id
WHERE a.user = {$u}{$qwhere}
ORDER BY t.lastpostdate DESC
LIMIT $min,$tpp
) r ON a.thread = r.id
", PDO::FETCH_GROUP, mysql::FETCH_ALL);
// Get threads
$threads = $sql->query("
SELECT t.*, a.folder,
".set_userfields('u1')." uid,
".set_userfields('u2')." uid,
r.read tread, r.time treadtime
FROM pm_access a
LEFT JOIN pm_threads t ON a.thread = t.id
LEFT JOIN users u1 ON t.user = u1.id
LEFT JOIN users u2 ON t.lastposter = u2.id
LEFT JOIN pm_threadsread r ON t.id = r.tid AND r.uid = {$u}
WHERE a.user = {$u}{$qwhere}
ORDER BY t.lastpostdate DESC
LIMIT $min,$tpp
");
$pmcount = $sql->num_rows($threads);
/*
Forum page list at the top & bottom
*/
$pagelinks = "";
if ($pmcount > $tpp) {
$args = "";
if (isset($_GET['ppp'])) $args .= "&ppp={$ppp}";
if (isset($_GET['tpp'])) $args .= "&tpp={$tpp}";
$pagelinks = "<table class='w'><tr><td class='fonts'>".pagelist("?{$idparam}{$args}", $pmcount, $tpp, true)."</td></tr></table>";
}
// For the thread pagelinks
$_GET['page'] = 0; // horrible hack
$maxfromstart = (($loguser['pagestyle']) ? 9 : 4);
$maxfromend = (($loguser['pagestyle']) ? 20 : 10);
$threadlist = "";
if (!$pmcount) {
$threadlist .=
"<tr>
<td class='tdbg1 center' style='font-style:italic' colspan=7>
There are no conversations in this folder.
</td>
</tr>";
} else for ($i = 1; $thread = $sql->fetch($threads, PDO::FETCH_NAMED); ++$i) {
// Thread status
$threadstatus = "";
if ($thread['lastpostdate'] > filter_int($folderread[$thread['folder']]) && !$thread['tread']) {
$threadstatus .= "new";
$newpost = ($thread['treadtime'] ? $thread['treadtime'] : filter_int($folderread[$thread['folder']]));
} else {
$newpost = NULL;
}
if ($thread['closed']) $threadstatus .= "off";
// Thread title column
$threadtitle = "<a href='showprivate.php?id={$thread['id']}{$navlink}'>{$thread['title']}</a>";
$posticon = $thread['icon'] ? "<img src=\"".htmlspecialchars($thread['icon'])."\">" : " ";
$belowtitle = array(); // An extra line below the title in certain circumstances
// Extra pages
$threadlinks = pagelist("showprivate.php?id={$thread['id']}", $thread['replies'] + 1, $ppp, $maxfromstart, $maxfromend);
if($thread['replies'] >= $ppp) {
if ($loguser['pagestyle']) {
$belowtitle[] = $threadlinks;
} else {
$threadtitle .= " <span class='pagelinks fonts'>({$threadlinks})</span>";
}
}
if ($threaddesc = trim($thread['description'])) {
$threadtitle .= "<br><span class='fonts'>".htmlspecialchars($threaddesc)."</span>";
}
if (!empty($belowtitle)) {
$threadtitle .= '<br><span class="fonts" style="position: relative; top: -1px;"> ' . implode(' - ', $belowtitle) . '</span>';
}
$users = "";
foreach ($partecipants[$thread['id']] as $user) {
$users .= ($users ? ", " : "").getuserlink($user);
}
$threadauthor = getuserlink(array_column_by_key($thread, 0), $thread['user']);
$lastposter = getuserlink(array_column_by_key($thread, 1), $thread['lastposter']);
$threadlist .=
"<tr>
<td class='tdbg1 center'>".($threadstatus ? $statusicons[$threadstatus] : " ")."</td>
<td class='tdbg2 center thread-icon-td'>
<div class='thread-icon'>$posticon</div>
</td>
<td class='tdbg2'>
". ($newpost ? "<a href='showprivate.php?id={$thread['id']}{$navlink}&lpt=$newpost'>{$statusicons['getnew']}</a> " : "") ."
{$threadtitle}
</td>
<td class='tdbg2 center'>
{$threadauthor}
<div class='fonts'>on ".printdate($thread['firstpostdate'])."</div>
</td>
<td class='tdbg2 center fonts'>{$users}</td>
<td class='tdbg1 center'>{$thread['replies']}</td>
<td class='tdbg2 center'>
<div class='lastpost'>
".printdate($thread['lastpostdate'])."<br>
by {$lastposter}
<a href='showprivate.php?id={$thread['id']}{$navlink}&end=1'>{$statusicons['getlast']}</a>
</div>
</td>
</tr>";
}
/*
Folder selection & other controls
*/
$users_p = ($u != $loguser['id']) ? htmlspecialchars(load_user($u)['name'])."'s p" : "P";
$links = array(
["{$users_p}rivate messages", NULL],
);
$right = pm_folder_select('dir', $u, $_GET['dir'], PMSELECT_ALL | PMSELECT_JS | PMSELECT_SHOWCNT)." -
<a href='sendprivate.php?dir={$_GET['dir']}'>New conversation</a> -
<a href='privatefolders.php'>Manage folders</a>";
$infotable = dobreadcrumbs($links, $right);
print "
{$infotable}
{$pagelinks}
<table class='table'>
<tr>
<td class='tdbgh center' style='width: 30px'></td>
<td class='tdbgh center' colspan=2>Title</td>
<td class='tdbgh center' style='width: 170px'>Started by</td>
<td class='tdbgh center' style='width: 14%'>Partecipants</td>
<td class='tdbgh center' style='width: 60px'>Replies</td>
<td class='tdbgh center' style='width: 150px'>Last reply</td>
</tr>
{$threadlist}
</table>
{$pagelinks}
";
pagefooter();