public static function commentsGet($status = null, $limit = 30, $offset = 0)
{
// authorize
if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('GET')) {
// redefine
$limit = (int) $limit;
// validate
if ($limit > 10000) {
return BaseAPI::output(BaseAPI::ERROR, array('message' => 'Limit can\'t be larger than 10000.'));
}
// get comments
$comments = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.id, UNIX_TIMESTAMP(i.created_on) AS created_on, i.author, i.email, i.website, i.text, i.type, i.status,
p.id AS post_id, p.title AS post_title, m.url AS post_url, p.language AS post_language
FROM blog_comments AS i
INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
INNER JOIN meta AS m ON p.meta_id = m.id
WHERE p.status = ?
GROUP BY i.id
ORDER BY i.id DESC
LIMIT ?, ?', array('active', (int) $offset, $limit));
$totalCount = (int) BackendModel::getContainer()->get('database')->getVar('SELECT COUNT(i.id)
FROM blog_comments AS i
INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
INNER JOIN meta AS m ON p.meta_id = m.id
WHERE p.status = ?', array('active'));
$return = array('comments' => null, 'total_count' => $totalCount);
// build return array
foreach ($comments as $row) {
// create array
$item['comment'] = array();
// article meta data
$item['comment']['article']['@attributes']['id'] = $row['post_id'];
$item['comment']['article']['@attributes']['lang'] = $row['post_language'];
$item['comment']['article']['title'] = $row['post_title'];
$item['comment']['article']['url'] = SITE_URL . BackendModel::getURLForBlock('Blog', 'Detail', $row['post_language']) . '/' . $row['post_url'];
// set attributes
$item['comment']['@attributes']['id'] = $row['id'];
$item['comment']['@attributes']['created_on'] = date('c', $row['created_on']);
$item['comment']['@attributes']['status'] = $row['status'];
// set content
$item['comment']['text'] = $row['text'];
$item['comment']['url'] = $item['comment']['article']['url'] . '#comment-' . $row['id'];
// author data
$item['comment']['author']['@attributes']['email'] = $row['email'];
$item['comment']['author']['name'] = $row['author'];
$item['comment']['author']['website'] = $row['website'];
// add
$return['comments'][] = $item;
}
return $return;
}
}