-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandle-submit.php
74 lines (62 loc) · 2.23 KB
/
handle-submit.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
<?php
try {
require_once('Sprinkles.php');
$subject = request_param('subject');
$details = request_param('details');
$tags = request_param('tags');
$face = request_param('emoticon');
$emotion = request_param('emotion');
$style = request_param('style');
$products = request_param('products');
$args = 'subject=' . urlencode($subject) .
'&details=' . urlencode($details) .
'&tags=' . urlencode($tags) .
'&emoticon=' . urlencode($face) .
'&emotion=' . urlencode($emotion) .
'&style=' . urlencode($style);
foreach ($products as $product)
$args .= '&product[]=' . urlencode($product);
if ($subject == '') {
redirect('submit.php?' . $args . '&errs[]=subject');
exit(0);
}
if (!$products) $products = array();
$products_commasep = join(',', $products);
$sprink = new Sprinkles();
$creds = $sprink->current_user_session();
if (!$creds) {
$target_page = $preview_after_login # setting in boot.php
? 'submit.php' : 'handle-submit.php';
redirect('user-login.php?return=' .
urlencode($target_page . '?' . $args));
exit(0);
}
$POST_URL = $api_root . 'companies/'. $sprink->company_sfnid .'/topics';
$req = $sprink->oauthed_request('POST', $POST_URL, $creds, null,
array('topic[subject]' => $subject,
'topic[additional_detail]' => $details,
'topic[style]' => $style,
'topic[keywords]' => $tags,
'topic[products]' => $products_commasep,
'topic[emotitag][face]' => $face,
'topic[emotitag][feeling]' => $emotion
));
$response_body = $req->getResponseBody();
try {
$topic_feed = new XML_Feed_Parser($response_body);
} catch (Exception $e) {
error("Failed to post new topic; response was: " . $req->getResponseCode() .
", body: " . $response_body);
throw new Exception($response_body);
}
if ($topic_feed->id()) { # FIXME: better error checking here.
redirect('topic.php?id=' . $topic_feed->id());
exit(0);
} else {
print "An error occured";
}
} catch (Exception $e) {
error_log("Exception thrown while preparing page: " . $e->getMessage());
$smarty->display('error.t');
}
?>