68
68
<a class="button" rel="external" href="https://github.com/textpattern/textpattern/" title="Stars on GitHub"><span class="ui-icon ui-extra-icon-github">GitHub</span> <strong>Stars</strong></a>
69
69
<txp:etc_cache id="github-stars" time="-3600">
70
70
<txp:php>
71
+ global $variable;
72
+
73
+ $query = <<<'GRAPHQL'
74
+ query {
75
+ repository(owner:textpattern, name:textpattern) {
76
+ stargazers {
77
+ totalCount
78
+ }
79
+ }
80
+ }
81
+ GRAPHQL;
82
+
83
+ $json = json_encode(['query' => $query]);
71
84
$curl = curl_init();
72
85
73
86
curl_setopt_array($curl, [
74
87
CURLOPT_RETURNTRANSFER => true,
75
- CURLOPT_URL => 'https://api.github.com/repos/textpattern/textpattern',
76
- CURLOPT_USERAGENT => 'Textpattern CMS',
88
+ CURLOPT_URL => 'https://api.github.com/graphql',
77
89
CURLOPT_FAILONERROR => true,
90
+ CURLOPT_POSTFIELDS => $json,
91
+ CURLOPT_HTTPHEADER => array(
92
+ 'User-Agent: Textpattern CMS',
93
+ 'Content-Type: application/json;charset=utf-8',
94
+ 'Authorization: bearer '.$variable['github-api-key']
95
+ ),
78
96
]);
79
97
80
98
$response = curl_exec($curl);
@@ -89,7 +107,7 @@ if (!($json = json_decode($response))) {
89
107
return;
90
108
}
91
109
92
- echo '<a class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">'.intval($json->stargazers_count ).'</a>';
110
+ echo '<a class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">'.intval($json->data->repository->stargazers->totalCount ).'</a>';
93
111
</txp:php>
94
112
</txp:etc_cache>
95
113
</p>
0 commit comments