-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathchangelog.php
More file actions
108 lines (90 loc) · 2.44 KB
/
changelog.php
File metadata and controls
108 lines (90 loc) · 2.44 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/* static settings */
$plugin = 'Overlay';
$cache_path = $_SERVER['DOCUMENT_ROOT'].'/github_cache/';
$cache_file = $plugin.'-github.txt';
$github_json = get_repo_json($cache_path.$cache_file,$plugin);
//echo get_content_from_github('https://api.github.com/repos/frostover/cokemusic/commits/master');
//echo get_content_from_github('https://api.github.com/repos/frostover/cokemusic/commits?sha=master');
function get_content_from_github($url) {
$request_headers = array();
$request_headers[] = 'User-Agent: frostover';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD,"frostover:Hurricane1002");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
function get_repo_json($file, $plugin) {
//decisions, decisions
if(file_exists($file)) {
//vars
$current_time = time(); $expire_time = 24 * 60 * 60; $file_time = filemtime($file);
if(($current_time - $expire_time < $file_time)) {
//echo 'returning from cached file';
return file_get_contents($file);
} else {
return fetch_github_info($file, $plugin);
}
}
else {
return fetch_github_info($file, $plugin);
}
}
function fetch_github_info($file, $plugin) {
$content = get_content_from_github('https://api.github.com/repos/frostover/cokemusic/commits?sha=master');
$json = $content;
file_put_contents($file, $json);
return $json;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>CokePhase Changelog</title>
<style type="text/css">
body {
font-size: 16px;
}
table td:first-child {
min-width: 200px;
}
table tr:nth-child(even) td {
background-color: #EDEDED;
}
table td {
vertical-align: top;
padding: 11px 0;
}
table {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<h3>Most Recent Updates</h3>
<h4>Not all updates seen here are on the live site</h4>
<?php
if($github_json) {
$content = json_decode($github_json);
// var_dump($content);
echo '<table cellspacing="0">';
foreach ($content as $record) {
// echo '<pre>';
// var_dump($record);
// echo '</pre>';
//Remove any frostover links
$message = str_replace('frostover', '', $record->commit->message);
$message = '<td>' . date('F jS Y', strtotime($record->commit->author->date)) . '</td><td>' . $message . '</td>';
echo '<tr>' . $message . '</tr>';
}
echo '</table>';
}
?>
</body>
</html>