1 token_example.module _token_example_get_comment()

Builds a list of available comments.

Related topics

File

modules/examples/token_example/token_example.module, line 146
Hook implementations for the Token Example module.

Code

function _token_example_get_comment() {
  if (!module_exists('comment') || (!user_access('access comments') && !user_access('administer comments'))) {
    return array();
  }

  $comment_query = db_select('comment', 'c');
  $comment_query->innerJoin('node', 'n', 'n.nid = c.nid');
  $comment_query->fields('c', array('cid', 'subject'));
  $comment_query->condition('n.status', NODE_PUBLISHED);
  $comment_query->condition('c.status', COMMENT_PUBLISHED);
  $comment_query->orderBy('c.created', 'DESC');
  $comment_query->range(0, 10);
  $comment_query->addTag('node_access');
  $comments = $comment_query->execute()->fetchAllKeyed();
  $comments = array_map('check_plain', $comments);
  return $comments;
}