Skip to content

Instantly share code, notes, and snippets.

@gwhitcher
Created April 20, 2018 15:37
Show Gist options
  • Save gwhitcher/3615e594e5d578c08cd493c5a488c864 to your computer and use it in GitHub Desktop.
Save gwhitcher/3615e594e5d578c08cd493c5a488c864 to your computer and use it in GitHub Desktop.
<?php
function getRecentForumTopics() {
$communityUrl = 'http://www.domain.com/';
$apiKey = 'API KEY';
$endpoint = '/forums/topics';
$vars = '?sortDir=desc&perPage=4';
$curl = curl_init( $communityUrl . 'api' . $endpoint.$vars );
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "{$apiKey}:"
) );
$response = curl_exec( $curl );
$values = json_decode($response, true);
$data = '';
foreach($values['results'] as $value) {
$data[] = [
'title' => $value['title'],
'url' => $value['firstPost']['url']
];
}
return $data;
}
function getRecentForumPosts() {
$communityUrl = 'http://www.domain.com/';
$apiKey = 'API KEY';
$endpoint = '/forums/posts';
$vars = '?sortDir=desc&perPage=4';
$curl = curl_init( $communityUrl . 'api' . $endpoint.$vars );
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "{$apiKey}:"
) );
$response = curl_exec( $curl );
$values = json_decode($response, true);
$data = '';
foreach($values['results'] as $value) {
$data[] = [
'title' => $value['content'],
'url' => $value['url']
];
}
return $data;
}
echo '<h2>Recent Topics</h2>';
$array = getRecentForumTopics();
echo '<ol>';
foreach($array as $key => $item) {
echo '<li><a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a></li>';
if($key == 4) {
break;
}
}
echo '</ol>';
echo '<h2>Recent Posts</h2>';
$array = getRecentForumPosts();
echo '<ol>';
foreach($array as $key => $item) {
echo '<li><a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a></li>';
if($key == 4) {
break;
}
}
echo '</ol>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment