-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.php
91 lines (75 loc) · 2.79 KB
/
utils.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
<?php
require_once('simplehtmldom/simple_html_dom.php');
function fetch_api_data($url)
{
$result = [];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
$content = curl_exec($curl);
$result['code'] = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$result['data'] = substr($content, $headerSize);
curl_close($curl);
return $result;
}
function get_device_data($device_data, $device_codename)
{
$dev_data = array();
$variants = array();
foreach (array_keys($device_data[$device_codename]) as $version) {
$dev_data[$version] = $version;
foreach ($device_data[$device_codename][$version] as $variant) {
array_push($variants, $variant);
}
$dev_data[$version] = array('variants' => $variants);
$variants = array();
}
return json_encode($dev_data);
}
if (isset($_POST['url'])) {
$mirrorsList = array();
$mirrors = file_get_html($_POST['url']);
foreach ($mirrors->find('#mirrorList li') as $mirror) {
foreach ($mirror->find('li') as $mirrorName) {
$mirrorPlace = explode(',', explode('(', $mirrorName->plaintext)[1])[0];
$mirrorsList[$mirrorPlace] = $mirrorName->id;
}
}
echo json_encode($mirrorsList);
$mirrors->clear();
unset($mirrors);
}
function compareByTimeStamp($time1, $time2)
{
if (strtotime($time1) < strtotime($time2))
return 1;
else if (strtotime($time1) > strtotime($time2))
return -1;
else
return 0;
}
function fetch_gerrit_changes($branch) {
$changeLog = array();
$gerritDomain = "https://review.arrowos.net";
$gerritUrl = $gerritDomain . "/changes/?q=status:merged+branch:" . $branch;
$changes = file_get_contents($gerritUrl);
$changes = json_decode(preg_replace('/^.+\n/', '', $changes));
foreach($changes as $change) {
$changeDate = explode(" ", $change->submitted)[0];
$projectName = explode("/", $change->project)[1];
$changeNum = $change->_number;
$changeSubject = $change->subject;
$changeLog[$changeDate][$changeNum] = array();
$changeLog[$changeDate][$changeNum][$projectName] = array();
$changeLog[$changeDate][$changeNum][$projectName] = $changeSubject;
}
krsort($changeLog);
return $changeLog;
}
if (isset($_POST['gerrit_changelog']) && $_POST['gerrit_changelog'] == 'yes'
&& isset($_POST['version']))
exit(json_encode(fetch_gerrit_changes($_POST['version'])));