Skip to content

Commit 6207eb5

Browse files
committed
Use PHP Curl to fetch GitHub API again...
...now that our server runs TLS~1.3.
1 parent 5b97146 commit 6207eb5

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

src/assets/js/main.js

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// Load objects as variables.
1010

1111
var code = document.querySelectorAll('pre code'),
12-
navmenu = document.getElementById('site-navigation'),
13-
starbubble = document.getElementById('starbubble');
12+
navmenu = document.getElementById('site-navigation');
1413

1514
// Syntax highlighting, via 'Prism'.
1615
// Applies syntax highlighting to `code` HTML elements.
@@ -40,47 +39,4 @@
4039
});
4140
}
4241

43-
// GitHub star count.
44-
45-
if (starbubble) {
46-
var githubStars = function (callback) {
47-
var xmlhttp = new XMLHttpRequest(),
48-
url = ['https://api.github.com/repos/textpattern/textpattern'],
49-
useCallback = (typeof(callback) === 'function');
50-
51-
function countStars(response) {
52-
if (!(response instanceof Array)) {
53-
response = [response];
54-
}
55-
var stars = 0;
56-
for (var i in response) {
57-
if (response.hasOwnProperty(i)) {
58-
stars += parseInt(response[i].stargazers_count);
59-
}
60-
}
61-
return stars;
62-
}
63-
64-
if (useCallback) {
65-
xmlhttp.onreadystatechange = function() {
66-
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
67-
callback(countStars(JSON.parse(xmlhttp.responseText)));
68-
}
69-
};
70-
}
71-
72-
xmlhttp.open('GET', url, useCallback);
73-
xmlhttp.setRequestHeader('Accept', 'application/vnd.github.v3+json');
74-
xmlhttp.send();
75-
76-
if (!useCallback) {
77-
return countStars(JSON.parse(xmlhttp.responseText));
78-
}
79-
};
80-
81-
githubStars(function(stars) {
82-
starbubble.innerHTML = '<a id="starcount" class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">'+stars+'</a>';
83-
});
84-
}
85-
8642
})();

src/mockups/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ <h1 class="cta"><span>The small content management system that can handle big id
119119
</p>
120120
<p>
121121
<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>
122-
<span id="starbubble"></span>
122+
<a class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">375</a>
123123
</p>
124124

125125
</div><!-- /.container -->

src/templates/pages/default.txp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,28 @@
6767
</p>
6868
<p>
6969
<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>
70-
<span id="starbubble"></span>
70+
<txp:etc_cache id="github-stars" time="-3600">
71+
<txp:php>
72+
$curl1 = curl_init();
73+
74+
curl_setopt_array($curl1, array(
75+
CURLOPT_RETURNTRANSFER => 1,
76+
CURLOPT_URL => 'https://api.github.com/repos/textpattern/textpattern',
77+
CURLOPT_USERAGENT => 'Textpattern CMS',
78+
));
79+
80+
$response1 = curl_exec($curl1);
81+
82+
if (curl_error($curl1)) {
83+
// Do nothing.
84+
} else {
85+
$json = json_decode($response1);
86+
echo '<a class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">'.$json->stargazers_count.'</a>';
87+
}
88+
89+
curl_close($curl1);
90+
</txp:php>
91+
</txp:etc_cache>
7192
</p>
7293
</div>
7394
</div>

0 commit comments

Comments
 (0)