forked from ResponsiveImagesCG/responsiveimages.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.php
119 lines (104 loc) · 2.51 KB
/
issues.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
include_once 'issues-opt.php';
/**
* Return a string stating how long ago something happened.
*
* @param integer $d formatted date stamp
*
* @return string
*/
function days_passed( $d ) {
if( empty( $d ) ) {
return "";
}
@$days = floor( ( time() - strtotime( $d ) ) / 86400 );
switch ( $days ) {
case 0 :
return "Today";
break;
case 1 :
return "Yesterday";
break;
default:
return $days . " days ago";
}
};
/**
* Fetch the issues for a given state.
*
* @param string $state The state of bugs we're interested in.
*
* @return array An array of issues matching the state requested.
*/
function fetch_issues( $state ) {
global $config;
$repos = $config['repos'];
$issues = array();
foreach( $repos as $url ) {
// Initializing curl
$ch = curl_init( $url . ( $state ? '?state=' . $state : '') );
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
);
// Setting curl options
curl_setopt_array( $ch, $options );
$json = curl_exec($ch);
// Getting results
$newiss = json_decode( $json );
$issues = is_array($newiss) ? array_merge( $issues, $newiss ) : $issues;
}
file_put_contents($config["{$state}CacheFile"], serialize($issues));
return $issues;
}
function get_issues( $state ) {
global $config;
$issues = array();
// Check for a cached copy.
if( file_exists($config["{$state}CacheFile"]) ) {
if($issues = unserialize(file_get_contents($config["{$state}CacheFile"]))) {
return $issues;
}
}
return $issues;
}
/**
* Print a table of issues.
*
* @param array $issues An array of issues to display.
*
* @return void
*/
function print_issues($state, $issues)
{
$icount = count($issues);
if( $icount ) {
?><h2 class="issuehed"><?=$icount?> <?=$state?> issue<?=$icount == 1 ? '' : 's'?></h2>
<table>
<thead>
<tr>
<th scope="col">Issue</th>
<th scope="col">Description</th>
<th scope="col">Author</th>
<th scope="col">Last Modified</th>
</tr>
</thead>
<tbody>
<? foreach( $issues as $i ):?>
<tr>
<td><?=$i->number?></td>
<th scope="row">
<a href="<?=$i->html_url?>"><?=$i->title?>
<?if( $i->comments > 0 ):?><b class="comments"><?=$i->comments?> comment<?=$i->comments == 1 ? '' : 's' ?></b><?endif?>
</a>
</th>
<?//<td class="label">Enhancement</td>?>
<td><a href="https://github.com/<?$i->user->login?>"><?=$i->user->login?></a></td>
<td><?=days_passed( $i->updated_at )?></td>
</tr>
<?endforeach;?>
</tbody>
</table>
<?
}
}