-
Notifications
You must be signed in to change notification settings - Fork 23
/
viewinbox.php
executable file
·231 lines (166 loc) · 11.5 KB
/
viewinbox.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
<?php
/*
* Copyright (C) 2014-2020 Luna
* Based on work by Adaur (2010), Vincent Garnier, Connorhd and David 'Chacmool' Djurback
* Licensed under GPLv2 (http://getluna.org/license.php)
*/
define('LUNA_ROOT', dirname(__FILE__).'/');
require LUNA_ROOT.'include/common.php';
require LUNA_ROOT.'include/parser.php';
require LUNA_ROOT.'include/me_functions.php';
$inbox = 1;
// No guest here !
if ($luna_user['is_guest'])
message(__('You do not have permission to access this page.', 'luna'));
// User enable PM ?
if (!$luna_user['use_inbox'] == '1')
message(__('You do not have permission to access this page.', 'luna'));
// Are we allowed to use this ?
if (!$luna_config['o_enable_inbox'] =='1' || $luna_user['g_inbox'] == '0')
message(__('You do not have permission to access this page.', 'luna'));
$id = $luna_user['id'];
// User block
$avatar_user_card = draw_user_avatar($luna_user['id']);
// Get the message's and thread's id
$mid = isset($_REQUEST['mid']) ? intval($_REQUEST['mid']) : '0';
$tid = isset($_REQUEST['tid']) ? intval($_REQUEST['tid']) : '0';
$pid = isset($_REQUEST['pid']) ? intval($_REQUEST['pid']) : '0';
$delete_all = '0';
$thread_msg = isset($_REQUEST['all_thread']) ? intval($_REQUEST['all_thread']) : '0';
$delete_all = isset($_POST['delete_all']) ? '1' : '0';
if ($pid) {
$result = $db->query('SELECT shared_id FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to fetch comment info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
$id = $db->result($result);
// Determine on what page the comment is located (depending on $luna_user['disp_comments'])
$result = $db->query('SELECT id FROM '.$db->prefix.'messages WHERE shared_id='.$id.' AND owner='.$luna_user['id'].' ORDER BY commented') or error('Unable to fetch comment info', __FILE__, __LINE__, $db->error());
$num_comments = $db->num_rows($result);
for ($i = 0; $i < $num_comments; ++$i) {
$cur_id = $db->result($result, $i);
if ($cur_id == $pid)
break;
}
++$i; // we started at 0
$_REQUEST['p'] = ceil($i / $luna_user['disp_comments']);
}
// Replace num_replies' feature by a query :-)
$result = $db->query('SELECT COUNT(*) FROM '.$db->prefix.'messages WHERE shared_id='.$tid.' AND owner='.$luna_user['id']) or error('Unable to count the messages', __FILE__, __LINE__, $db->error());
list($num_replies) = $db->fetch_row($result);
// Determine the comment offset (based on $_GET['p'])
$num_pages = ceil($num_replies / $luna_user['disp_comments']);
// Page ?
$page = (!isset($_REQUEST['p']) || $_REQUEST['p'] <= '1') ? '1' : intval($_REQUEST['p']);
$start_from = $luna_user['disp_comments'] * ($page - 1);
// Check that $mid looks good
if ($mid <= 0)
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
// Action ?
$action = ((isset($_REQUEST['action']) && ($_REQUEST['action'] == 'delete')) ? $_REQUEST['action'] : '');
// Delete a single message or a full thread
if ($action == 'delete') {
// Make sure they got here from the site
confirm_referrer('viewinbox.php');
if (isset($_POST['delete_comply'])) {
if ($thread_msg > '1' || $thread_msg < '0')
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
if ($thread_msg == '0') {
if ($luna_user['is_admmod']) {
if ($delete_all == '1') {
$result_msg = $db->query('SELECT message FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to get the informations of the message', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result_msg))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
$delete_msg = $db->fetch_assoc($result_msg);
// To devs: maybe this query is unsafe? Maybe you know how to secure it? I'm open to your suggestions ;) !
$result_ids = $db->query('SELECT id FROM '.$db->prefix.'messages WHERE message=\''.$db->escape($delete_msg).'\'') or error('Unable to get the informations of the message', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result_ids))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
$ids_msg[] = $db->result($result_ids);
// Finally, delete the messages!
$db->query('DELETE FROM '.$db->prefix.'messages WHERE id IN ('.$ids_msg.')') or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
} else
$db->query('DELETE FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
} else {
$result = $db->query('SELECT owner FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
$owner = $db->result($result);
if($owner != $luna_user['id']) // Double check : hackers are everywhere =)
message(__('You do not have permission to access this page.', 'luna'));
$db->query('DELETE FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
}
} else {
if ($luna_user['is_admmod']) {
if ($delete_all == '1') {
$result_ids = $db->query('SELECT DISTINCT owner FROM '.$db->prefix.'messages WHERE shared_id='.$tid) or error('Unable to get the informations of the message', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result_ids))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
while ($user_ids = $db->fetch_assoc($result_ids)) {
$ids_users[] = $user_ids['owner'];
}
$ids_users = implode(',', $ids_users);
$db->query('UPDATE '.$db->prefix.'users SET num_inbox=num_inbox-1 WHERE id IN('.$ids_users.')') or error('Unable to update user', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'messages WHERE shared_id='.$tid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
} else {
$db->query('DELETE FROM '.$db->prefix.'messages WHERE shared_id='.$tid.' AND owner='.$luna_user['id']) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'messages SET receiver=REPLACE(receiver,\''.$db->escape($luna_user['username']).'\',\''.$db->escape($luna_user['username'].' Deleted').'\') WHERE receiver LIKE \'%'.$db->escape($luna_user['username']).'%\' AND shared_id='.$tid) or error('Unable to update private messages', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET num_inbox=num_inbox-1 WHERE id='.$luna_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
}
} else {
$result = $db->query('SELECT owner FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
$owner = $db->result($result);
if($owner != $luna_user['id']) // Double check : hackers are everywhere =)
message(__('You do not have permission to access this page.', 'luna'));
$db->query('DELETE FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET num_inbox=num_inbox-1 WHERE id='.$luna_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
}
}
// Redirect
redirect('inbox.php');
} else {
$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']), __('Delete message', 'luna'));
define('LUNA_ACTIVE_PAGE', 'pm');
include LUNA_ROOT.'header.php';
require load_page('header.php');
// If you're not the owner of the message, you can't delete it.
$result = $db->query('SELECT owner, show_message, commented, sender, message, hide_smilies FROM '.$db->prefix.'messages WHERE id='.$mid) or error('Unable to delete the message', __FILE__, __LINE__, $db->error());
$cur_delete = $db->fetch_assoc($result);
if($cur_delete['owner'] != $luna_user['id'] && !$luna_user['is_admmod'])
message(__('You do not have permission to access this page.', 'luna'));
$cur_delete['message'] = parse_message($cur_delete['message']);
require load_page('inbox-delete-comment.php');
require load_page('footer.php');
}
} else {
// Start building page
$result_receivers = $db->query('SELECT DISTINCT receiver, owner, sender_id FROM '.$db->prefix.'messages WHERE shared_id='.$tid) or error('Unable to get the informations of the message', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result_receivers))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
$owner = array();
while ($receiver = $db->fetch_assoc($result_receivers)) {
$r_usernames = $receiver['receiver'];
$owner[] = $receiver['owner'];
$uid = $receiver['sender_id'];
}
$r_usernames = str_replace('Deleted', __('Deleted', 'luna'), $r_usernames);
$result = $db->query('SELECT subject FROM '.$db->prefix.'messages WHERE shared_id='.$tid.' AND show_message=1') or error('Unable to fetch comment info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
$p_subject = $db->result($result);
$messageh2 = luna_htmlspecialchars($p_subject).' '.__('with', 'luna').' '.luna_htmlspecialchars($r_usernames);
$required_fields = array('req_message' => __('Message', 'luna'));
$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']), __('Private Messages', 'luna'), __('View a private discussion', 'luna'));
define('LUNA_ACTIVE_PAGE', 'pm');
include LUNA_ROOT.'header.php';
require load_page('header.php');
if(!in_array($luna_user['id'], $owner) && !$luna_user['is_admmod'])
message(__('You do not have permission to access this page.', 'luna'));
$comment_count = '0'; // Keep track of comment numbers
$db->query('UPDATE '.$db->prefix.'messages SET showed=1 WHERE shared_id='.$tid.' AND show_message=1 AND owner='.$luna_user['id']) or error('Unable to update the status of the message', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT m.id AS mid, m.shared_id, m.subject, m.sender_ip, m.message, m.hide_smilies, m.commented, m.showed, m.sender, m.sender_id, m.owner, u.id, u.group_id AS g_id, g.g_user_title, u.username, u.registered, u.email, u.title, u.url, u.location, u.email_setting, u.num_comments, u.admin_note, u.signature, u.use_inbox, o.user_id AS is_online FROM '.$db->prefix.'messages AS m, '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.idle=0) LEFT JOIN '.$db->prefix.'groups AS g ON (u.group_id=g.g_id) WHERE u.id=m.sender_id AND m.shared_id='.$tid.' AND m.owner='.$luna_user['id'].' ORDER BY m.commented LIMIT '.$start_from.','.$luna_user['disp_comments']) or error('Unable to get the message and the informations of the user', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'));
$reply_link = '<a href="new_inbox.php?reply='.$tid.'">'.__('Reply', 'luna').'</a>';
$paging_links = paginate($num_pages, $page, 'viewinbox.php?tid='.$tid.'&mid='.$mid);
require load_page('inbox-view.php');
require load_page('footer.php');
}
?>