| 1 | <?php |
| 2 | $githubApi = "https://api.github.com/repos/brainboxdotcc/dpp/releases"; |
| 3 | $json = json_decode( |
| 4 | file_get_contents( |
| 5 | $githubApi, |
| 6 | false, |
| 7 | stream_context_create( |
| 8 | [ |
| 9 | "http" => [ |
| 10 | "method" => "GET", |
| 11 | "header" => "User-Agent: DPP/Website" |
| 12 | ] |
| 13 | ] |
| 14 | ) |
| 15 | ) |
| 16 | ); |
| 17 | $downloads = 0; |
| 18 | foreach ($json as $index => $release) { |
| 19 | $releaseDownloads = 0; |
| 20 | foreach ($release->assets as $asset) { |
| 21 | $releaseDownloads += $asset->download_count; |
| 22 | } |
| 23 | $downloads += $releaseDownloads; |
| 24 | } |
| 25 | |
| 26 | header("Content-Type: image/svg+xml"); |
| 27 | echo <<<IMG |
| 28 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="106" height="20" role="img" aria-label="downloads: {$downloads}"> |
| 29 | <title>downloads: {$downloads}</title> |
| 30 | <linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/> |
| 31 | <stop offset="1" stop-opacity=".1"/> |
| 32 | </linearGradient> |
| 33 | <clipPath id="r"> |
| 34 | <rect width="106" height="20" rx="3" fill="#fff"/> |
| 35 | </clipPath> |
| 36 | <g clip-path="url(#r)"> |
| 37 | <rect width="69" height="20" fill="#555"/><rect x="69" width="37" height="20" fill="#97ca00"/> |
| 38 | <rect width="106" height="20" fill="url(#s)"/> |
| 39 | </g> |
| 40 | <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"> |
| 41 | <text aria-hidden="true" x="355" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="590">downloads</text> |
| 42 | <text x="355" y="140" transform="scale(.1)" fill="#fff" textLength="590">downloads</text> |
| 43 | <text aria-hidden="true" x="865" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">{$downloads}</text> |
| 44 | <text x="865" y="140" transform="scale(.1)" fill="#fff" textLength="270">{$downloads}</text> |
| 45 | </g> |
| 46 | </svg> |
| 47 | IMG; |