This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
functions.php
63 lines (58 loc) · 1.77 KB
/
functions.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
<?php
function convertHtml2Confluence($html)
{
//fix links to other issues
$html = preg_replace_callback(
'#/youtrack/issue/([a-z]+-[0-9]+)#',
function($matches) {
return strtoupper($matches[1]);
},
$html
);
$file = tempnam('/tmp', 'youtrack-export-');
file_put_contents($file, $html);
exec('ruby html2confluence/convert.rb ' . escapeshellarg($file), $output, $ret);
unlink($file);
if ($ret !== 0) {
file_put_contents('php://stderr', "Error converting HTML to confluence\n");
exit(5);
}
return trim(implode("\n", $output));
}
function login()
{
global $username, $password, $url;
$cookiefile = __DIR__ . '/restdata/cookie.txt';
if (file_exists($cookiefile)) {
return file_get_contents($cookiefile);
}
$context = stream_context_create(
[
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query(
[
'login' => $username,
'password' => $password
]
)
]
]
);
$response = file_get_contents($url . 'rest/user/login', false, $context);
if ($response === false) {
file_put_contents('php://stderr', "failed to login\n");
exit(1);
}
$cookies = array();
foreach ($http_response_header as $header) {
if (substr(strtolower($header), 0, 11) == 'set-cookie:') {
list($cookies[]) = explode(';', substr($header, 11));
}
}
$cookieheader = 'Cookie: ' . implode(';', $cookies);
file_put_contents($cookiefile, $cookieheader);
return $cookieheader;
}
?>