-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
executable file
·80 lines (61 loc) · 2.32 KB
/
post.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
<?php
/**
issues/post.php
Creates an issue. Works great.
*/
if (!isset($_POST['body'])
|| (!isset($_POST['id'])
&& !isset($_POST['title'])))
die('Missing a field. One of body, id, or title missing.');
require_once('../forums/SSI.php');
if (!$context['user']['is_logged'])
die('Not logged in.');
if (FALSE) {
echo '<!-- ';
var_dump($context);
echo '-->';
}
require_once('config.php');
require_once('labels.php');
$body = '(Posted by [' . $context['user']['username'] . '](' . $forum_url . '?action=profile;u=' . $context['user']['id'] . ') on ' . $forum_name . ')' . "\n\n" . $_POST['body'];
//echo 'ERROR: Ticket creation and commenting is currently under construction. Please either use github or try again tomorrow. Sorry for the inconvenience.<hr />';
if (isset($_POST['id'])) {
$url = $repo . '/issues/' . $_POST['id'] . '/comments';
$json['body'] = $body;
$data = json_encode($json);
} else {
$url = $repo . '/issues';
$title = $_POST['title'] . ' [u' . $context['user']['id'] . ']';
// Handle labels--don't create a thousand labels.
$labels = explode(',',$_POST['labels']);
for ($i = 0; $i < count($labels); $i++) {
$labels[$i] = trim($labels[$i]);
}
$valid_labels = get_all_labels();
$labels = array_filter($labels, function($label) use (&$valid_labels) {
return array_key_exists(strtolower($label), $valid_labels);
});
$json['title'] = $title;
$json['body'] = $body;
$json['labels'] = $labels;
$data = json_encode($json);
}
// echo $url . '<hr />';
// echo '<textarea rows="10" cols="100">' . $data . '</textarea>';
// Prevent further execution (which actually posts)
// die();
$result = getPage($url,$data);
//echo $result . "<br />\n<br />\n";
$js = json_decode($result);
if (count($js) == 1 && isset($js->message)) {
include('common.php');
die('<div id="down">Post failed because the GitHub API is a cryptic assault on the mind. Reason for failure:<br/>' . $js->message . '</div>'
. '<br/>Dump of post text, in case you miss it:<br/><textarea cols="96" rows="7">' . htmlspecialchars($_POST['body']) . '</textarea>'
. '<br/><br/>Additional info: Post to url "' . $url . '" failed.<br/><br/>Sent:<br/>' . $data . '<br/><br/>Received:<br/>' . $result);
}
if (isset($_POST['id']))
$num = $_POST['id'];
else
$num = $js->number;
header('Location: ' . $tracker_url . '?id=' . $num);
?>