-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendthread.php
189 lines (157 loc) · 4.77 KB
/
sendthread.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
<?php
/**
* MyBB 1.6
* Copyright 2010 MyBB Group, All Rights Reserved
*
* Website: http://mybb.com
* License: http://mybb.com/about/license
*
* $Id$
*/
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'sendthread.php');
$templatelist = "sendthread,forumdisplay_password_wrongpass,forumdisplay_password";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
// Load global language phrases
$lang->load("sendthread");
// Get thread info
$tid = intval($mybb->input['tid']);
$thread = get_thread($tid);
// Get thread prefix
$breadcrumbprefix = '';
if($thread['prefix'])
{
$threadprefix = build_prefixes($thread['prefix']);
if(isset($threadprefix['displaystyle']))
{
$breadcrumbprefix = $threadprefix['displaystyle'].' ';
}
}
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
// Invalid thread
if(!$thread['tid'])
{
error($lang->error_invalidthread);
}
// Guests cannot use this feature
if(!$mybb->user['uid'])
{
error_no_permission();
}
$fid = $thread['fid'];
// Make navigation
build_forum_breadcrumb($thread['fid']);
add_breadcrumb($breadcrumbprefix.$thread['subject'], get_thread_link($thread['tid']));
add_breadcrumb($lang->nav_sendthread);
// Get forum info
$forum = get_forum($thread['fid']);
$forumpermissions = forum_permissions($forum['fid']);
// Invalid forum?
if(!$forum['fid'] || $forum['type'] != "f")
{
error($lang->error_invalidforum);
}
// This user can't view this forum or this thread
if($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || ($forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']))
{
error_no_permission();
}
// Check if this forum is password protected and we have a valid password
check_forum_password($forum['fid']);
if($mybb->usergroup['cansendemail'] == 0)
{
error_no_permission();
}
// Check group limits
if($mybb->usergroup['maxemails'] > 0)
{
$query = $db->simple_select("maillogs", "COUNT(*) AS sent_count", "fromuid='{$mybb->user['uid']}' AND dateline >= '".(TIME_NOW - (60*60*24))."'");
$sent_count = $db->fetch_field($query, "sent_count");
if($sent_count >= $mybb->usergroup['maxemails'])
{
$lang->error_max_emails_day = $lang->sprintf($lang->error_max_emails_day, $mybb->usergroup['maxemails']);
error($lang->error_max_emails_day);
}
}
if($mybb->input['action'] == "do_sendtofriend" && $mybb->request_method == "post")
{
// Verify incoming POST request
verify_post_check($mybb->input['my_post_key']);
$plugins->run_hooks("sendthread_do_sendtofriend_start");
if(!validate_email_format($mybb->input['email']))
{
$errors[] = $lang->error_invalidemail;
}
if(empty($mybb->input['subject']))
{
$errors[] = $lang->error_nosubject;
}
if(empty($mybb->input['message']))
{
$errors[] = $lang->error_nomessage;
}
// No errors detected
if(count($errors) == 0)
{
if($mybb->settings['mail_handler'] == 'smtp')
{
$from = $mybb->user['email'];
}
else
{
$from = "{$mybb->user['username']} <{$mybb->user['email']}>";
}
$threadlink = get_thread_link($thread['tid']);
$message = $lang->sprintf($lang->email_sendtofriend, $mybb->user['username'], $mybb->settings['bbname'], $mybb->settings['bburl']."/".$threadlink, $mybb->input['message']);
// Send the actual message
my_mail($mybb->input['email'], $mybb->input['subject'], $message, $from, "", "", false, "text", "", $mybb->user['email']);
if($mybb->settings['mail_logging'] > 0)
{
// Log the message
$log_entry = array(
"subject" => $db->escape_string($mybb->input['subject']),
"message" => $db->escape_string($message),
"dateline" => TIME_NOW,
"fromuid" => $mybb->user['uid'],
"fromemail" => $db->escape_string($mybb->user['email']),
"touid" => 0,
"toemail" => $db->escape_string($mybb->input['email']),
"tid" => $thread['tid'],
"ipaddress" => $db->escape_string($session->ipaddress)
);
$db->insert_query("maillogs", $log_entry);
}
$plugins->run_hooks("sendthread_do_sendtofriend_end");
redirect(get_thread_link($thread['tid']), $lang->redirect_emailsent);
}
else
{
$mybb->input['action'] = '';
}
}
if(!$mybb->input['action'])
{
$plugins->run_hooks("sendthread_start");
// Do we have some errors?
if(count($errors) >= 1)
{
$errors = inline_error($errors);
$email = htmlspecialchars_uni($mybb->input['email']);
$subject = htmlspecialchars_uni($mybb->input['subject']);
$message = htmlspecialchars_uni($mybb->input['message']);
}
else
{
$errors = '';
$email = '';
$subject = $lang->sprintf($lang->emailsubject_sendtofriend, $mybb->settings['bbname']);
$message = '';
}
$plugins->run_hooks("sendthread_end");
eval("\$sendtofriend = \"".$templates->get("sendthread")."\";");
output_page($sendtofriend);
}
?>