|
67 | 67 | <p> |
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 | | - <txp:php> |
71 | | -$curl1 = curl_init(); |
| 70 | + <txp:php> |
| 71 | +$curl = curl_init(); |
72 | 72 |
|
73 | | -curl_setopt_array($curl1, array( |
74 | | - CURLOPT_RETURNTRANSFER => 1, |
| 73 | +curl_setopt_array($curl, [ |
| 74 | + CURLOPT_RETURNTRANSFER => true, |
75 | 75 | CURLOPT_URL => 'https://api.github.com/repos/textpattern/textpattern', |
76 | 76 | CURLOPT_USERAGENT => 'Textpattern CMS', |
77 | | -)); |
| 77 | + CURLOPT_FAILONERROR => true, |
| 78 | +]); |
78 | 79 |
|
79 | | -$response1 = curl_exec($curl1); |
| 80 | +$response = curl_exec($curl); |
80 | 81 |
|
81 | | -if (curl_error($curl1)) { |
82 | | - // Do nothing. |
83 | | -} else { |
84 | | - $json = json_decode($response1); |
85 | | - echo '<a class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">'.$json->stargazers_count.'</a>'; |
| 82 | +curl_close($curl); |
| 83 | + |
| 84 | +if ($response === false) { |
| 85 | + return; |
| 86 | +} |
| 87 | + |
| 88 | +if (!($json = json_decode($response))) { |
| 89 | + return; |
86 | 90 | } |
87 | 91 |
|
88 | | -curl_close($curl1); |
89 | | - </txp:php> |
90 | | - </txp:etc_cache> |
| 92 | +echo '<a class="count-bubble" rel="external" href="https://github.com/textpattern/textpattern/stargazers" title="Stargazers on GitHub">'.intval($json->stargazers_count).'</a>'; |
| 93 | + </txp:php> |
| 94 | + </txp:etc_cache> |
91 | 95 | </p> |
92 | 96 | </div> |
93 | 97 | </div> |
@@ -199,26 +203,29 @@ curl_close($curl1); |
199 | 203 | <ul class="list--no-bullets ellipsis"> |
200 | 204 | <txp:etc_cache id="forum-feed" time="-900"> |
201 | 205 | <txp:php> |
202 | | -$curl2 = curl_init(); |
| 206 | +$curl = curl_init(); |
203 | 207 |
|
204 | | -curl_setopt_array($curl2, array( |
205 | | - CURLOPT_RETURNTRANSFER => 1, |
206 | | - CURLOPT_URL => 'http://forum.textpattern.com/api/?limit=5&sort=posted', |
207 | | -)); |
| 208 | +curl_setopt_array($curl, [ |
| 209 | + CURLOPT_RETURNTRANSFER => true, |
| 210 | + CURLOPT_URL => 'https://forum.textpattern.io/api/?limit=5&sort=posted', |
| 211 | + CURLOPT_FAILONERROR => true, |
| 212 | +]); |
208 | 213 |
|
209 | | -$response2 = curl_exec($curl2); |
| 214 | +$response = curl_exec($curl); |
210 | 215 |
|
211 | | -if (curl_error($curl2)) { |
212 | | - // Do nothing. |
213 | | -} else { |
214 | | - $xml = json_decode($response2); |
| 216 | +curl_close($curl); |
215 | 217 |
|
216 | | - foreach ($xml->topic as $topicElement) { |
217 | | - echo '<li><a href="'.str_replace('http://', 'https://', $topicElement->link).'">'.htmlspecialchars($topicElement->title).'</a> <small class="block">by '.htmlspecialchars($topicElement->author->name).' on <time datetime="'.$topicElement->postedutc.'">'.$topicElement->posted.'</time></small></li>'; |
218 | | - } |
| 218 | +if ($response === false) { |
| 219 | + return; |
219 | 220 | } |
220 | 221 |
|
221 | | -curl_close($curl2); |
| 222 | +if (!($json = json_decode($response))) { |
| 223 | + return; |
| 224 | +} |
| 225 | + |
| 226 | +foreach ($json->topic as $topic) { |
| 227 | + echo '<li><a href="'.htmlspecialchars($topic->link).'">'.htmlspecialchars($topic->title).'</a> <small class="block">by '.htmlspecialchars($topic->author->name).' on <time datetime="'.htmlspecialchars($topic->postedutc).'">'.htmlspecialchars($topic->posted).'</time></small></li>'; |
| 228 | +} |
222 | 229 | </txp:php> |
223 | 230 | <txp:linklist category="paid-links-content" break="li"><a rel="external" href="<txp:link_url />"><txp:link_name /></a> <small>(Ad)</small></txp:linklist> |
224 | 231 | </txp:etc_cache> |
|
0 commit comments