-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandle-share-topic.php
49 lines (38 loc) · 1.46 KB
/
handle-share-topic.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
<?php
try {
require_once('Sprinkles.php');
$sprink = new Sprinkles();
$id = request_param('id');
$topic = $sprink->topic($id);
$topic = $topic['replies'][0];
$from = request_param('from_email');
$from = preg_replace('/\n.*$/', ' ', $from); # Sanitizes $from; it'll go verbatim in the SMTP headers
$user_fn = request_param('sender_name');
if (!$user_fn) {
$user = $sprink->current_user();
$user_fn = $user['fn'];
}
$personal_message = request_param('personal_message');
$message = $user_fn . " thinks you might be interested in this discussion from Get Satisfaction:\n\n" .
"\"" . $topic['title'] . "\n\n" .
$topic['content'] . "\"\n\n" .
$topic['author']['fn'] . " asked this on " . $topic['published_formatted'] .
(!$personal_message ? '' :
"\n\n" . $user_fn . " says: \n\n" . $personal_message
);
$subject = "'" . $topic['title'] . "' on Get Satisfaction!";
$to = request_param('to_email'); # TBD: handle more than one address
if (preg_match('/,/', $to))
die("Sharing with more than one recipient is not yet implemented. :-("); # FIXME: not graceful.
$result = mail($to, $subject, $message, "From: $from");
if ($result) {
redirect('topic.php?id=' . $id . '&shared_with=' . urlencode($to));
} else {
redirect('topic.php?id=' . $id . '&share_failed=true');
}
exit(0);
} catch (Exception $e) {
error_log("Exception thrown while preparing page: " . $e->getMessage());
$smarty->display('error.t');
}
?>