You are here

function _token_example_get_comment in Examples for Developers 6

Same name and namespace in other branches
  1. 7 token_example/token_example.module \_token_example_get_comment()

Build a list of available comments.

Related topics

File

token_example/token_example.module, line 180
The Token API module.

Code

function _token_example_get_comment() {
  if (!module_exists('comment') || !user_access('access comments') && !user_access('administer comments')) {
    return array();
  }
  $sql = 'SELECT c.cid, c.subject FROM {comments} c WHERE c.status = %d ORDER BY c.timestamp DESC';
  $query = db_query_range(db_rewrite_sql($sql, 'c', 'cid'), COMMENT_PUBLISHED, 0, 10);
  $comments = array();
  while ($result = db_fetch_object($query)) {
    $comments[$result->cid] = $result->subject;
  }
  $comments = array_map('check_plain', $comments);
  return $comments;
}