bin
3 years ago
lazy
3 years ago
src
3 years ago
extension.neon
3 years ago
sponsors.php
3 years ago
sponsors.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED; |
| 4 | |
| 5 | /** |
| 6 | * This file is part of the Carbon package. |
| 7 | * |
| 8 | * (c) Brian Nesbitt <brian@nesbot.com> |
| 9 | * |
| 10 | * For the full copyright and license information, please view the LICENSE |
| 11 | * file that was distributed with this source code. |
| 12 | */ |
| 13 | use IAWP_SCOPED\Carbon\CarbonImmutable; |
| 14 | require_once __DIR__ . '/vendor/autoload.php'; |
| 15 | function getOpenCollectiveSponsors() : string |
| 16 | { |
| 17 | $members = \json_decode(\file_get_contents('https://opencollective.com/carbon/members/all.json'), \true); |
| 18 | $sixMonthsAgo = CarbonImmutable::parse('now - 6 months')->format('Y-m-d h:i'); |
| 19 | $list = \array_filter($members, static function ($member) use($sixMonthsAgo) { |
| 20 | return ($member['lastTransactionAmount'] > 3 || $member['isActive']) && $member['role'] === 'BACKER' && $member['type'] !== 'USER' && ($member['totalAmountDonated'] > 100 || $member['lastTransactionAt'] > $sixMonthsAgo || $member['isActive'] && $member['lastTransactionAmount'] >= 30); |
| 21 | }); |
| 22 | $list = \array_map(static function (array $member) { |
| 23 | $createdAt = CarbonImmutable::parse($member['createdAt']); |
| 24 | $monthlyContribution = (float) ($member['totalAmountDonated'] / (1 + $createdAt->diffInMonths())); |
| 25 | if (CarbonImmutable::parse($member['lastTransactionAt'])->isAfter('last month') && $member['lastTransactionAmount'] > $monthlyContribution) { |
| 26 | $monthlyContribution = (float) $member['lastTransactionAmount']; |
| 27 | } |
| 28 | $yearlyContribution = (float) ($member['totalAmountDonated'] / \max(1, $createdAt->floatDiffInYears())); |
| 29 | $status = null; |
| 30 | if ($monthlyContribution > 29) { |
| 31 | $status = 'sponsor'; |
| 32 | } elseif ($monthlyContribution > 3 || $yearlyContribution > 20) { |
| 33 | $status = 'backer'; |
| 34 | } elseif ($member['totalAmountDonated'] > 0) { |
| 35 | $status = 'helper'; |
| 36 | } |
| 37 | return \array_merge($member, ['star' => $monthlyContribution > 98 || $yearlyContribution > 500, 'status' => $status, 'monthlyContribution' => $monthlyContribution, 'yearlyContribution' => $yearlyContribution]); |
| 38 | }, $list); |
| 39 | \usort($list, static function (array $a, array $b) { |
| 40 | return $b['monthlyContribution'] <=> $a['monthlyContribution'] ?: $b['totalAmountDonated'] <=> $a['totalAmountDonated']; |
| 41 | }); |
| 42 | return \implode('', \array_map(static function (array $member) { |
| 43 | $href = \htmlspecialchars($member['website'] ?? $member['profile']); |
| 44 | $src = $member['image'] ?? \strtr($member['profile'], ['https://opencollective.com/' => 'https://images.opencollective.com/']) . '/avatar/256.png'; |
| 45 | [$x, $y] = @\getimagesize($src) ?: [0, 0]; |
| 46 | $validImage = $x && $y; |
| 47 | $src = $validImage ? \htmlspecialchars($src) : 'https://opencollective.com/static/images/default-guest-logo.svg'; |
| 48 | $height = 64; |
| 49 | $width = $validImage ? \round($x * $height / $y) : $height; |
| 50 | $href .= (\strpos($href, '?') === \false ? '?' : '&') . 'utm_source=opencollective&utm_medium=github&utm_campaign=Carbon'; |
| 51 | $title = \htmlspecialchars($member['description'] ?? null ?: $member['name']); |
| 52 | $alt = \htmlspecialchars($member['name']); |
| 53 | return "\n" . '<a title="' . $title . '" href="' . $href . '" target="_blank" rel="sponsored">' . '<img alt="' . $alt . '" src="' . $src . '" width="' . $width . '" height="' . $height . '">' . '</a>'; |
| 54 | }, $list)) . "\n"; |
| 55 | } |
| 56 | \file_put_contents('readme.md', \preg_replace_callback('/(<!-- <open-collective-sponsors> -->)[\\s\\S]+(<!-- <\\/open-collective-sponsors> -->)/', static function (array $match) { |
| 57 | return $match[1] . getOpenCollectiveSponsors() . $match[2]; |
| 58 | }, \file_get_contents('readme.md'))); |
| 59 |