Skip to content

Instantly share code, notes, and snippets.

@fleeting
Created March 1, 2010 22:23
Show Gist options
  • Save fleeting/318887 to your computer and use it in GitHub Desktop.
Save fleeting/318887 to your computer and use it in GitHub Desktop.
<?php
class admin_disqus extends adminController
{
public $user_api_key = "agsr63Q9NlwKxUsHQSFFolD2gDWTfk7eN1Il0dhbXQH5FLHVy2VEKvvmnJsdNxYs";
public $forum_api_key = null;
public $api_url = "http://disqus.com/api/";
public $api_version = "1.1";
//http://disqus.com/api/get_forum_list?user_api_key=API_KEY_HERE&api_version=1.1
function admin_disqus()
{
parent::adminController();
$this->menuPermission("comments");
}
function index()
{
// get a list of sites
$aForumList = $this->get_forum_list();
// get the comments for a single site
// use the forum id from the first returned forum in get_forum_lists()
$aForumPosts = $this->get_forum_posts($aForumList[0]->id);
// echo "<pre>";
// print_r($aForumPosts);
// echo "</pre>";
foreach ($aForumPosts as $aForumPost)
{
echo '<h2><img src="' . $aForumPost->author->avatar->small . '"> ' . $aForumPost->author->display_name . ' (' . $aForumPost->author->username . ')</h2>';
echo '<small><strong>Status</strong>: ' . $aForumPost->status . '</small>';
echo '<p>' . $aForumPost->message . '</p>';
}
}
function get_forum_list()
{
return $this->apiCall('get_forum_list');
}
function get_forum_posts($forum_id)
{
$arguments['forum_id'] = $forum_id;
return $this->apiCall('get_forum_posts', $arguments);
}
function apiCall($method, $arguments = array())
{
$args = null;
foreach ($arguments as $argument => $value) {
if (!empty($value)) {
$args .= $argument .'='. urlencode($value) .'&';
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->api_url . $method .'/?user_api_key='. $this->user_api_key . '&api_version='. $this->api_version . '&' . $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$disqus = json_decode($data);
if ($info['http_code'] == 200) {
return $disqus->message;
} else {
echo "There was a problem accessing the Disqus API.";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment