function _linkchecker_link_comment_ids in Link checker 7
Same name and namespace in other branches
- 6.2 linkchecker.module \_linkchecker_link_comment_ids()
Returns IDs of comments that contain a link which the current user is allowed to view.
Parameters
object $link: An object representing the link to check.
object $comment_author_account: (optional) If a user account object is provided, the returned comments will additionally be restricted to only those owned by this account. Otherwise, comments owned by any user account may be returned.
Return value
array An array of comment IDs that contain the provided link and that the current user is allowed to view.
2 calls to _linkchecker_link_comment_ids()
- _linkchecker_link_access in ./
linkchecker.module - Determines if the current user has access to view a link.
- _linkchecker_report_page in ./
linkchecker.pages.inc - Builds the HTML report page table with pager.
File
- ./
linkchecker.module, line 369 - This module periodically check links in given node types, blocks etc.
Code
function _linkchecker_link_comment_ids($link, $comment_author_account = NULL) {
// Exit if comments are disabled or if the user cannot access comments, there
// is no need to check further.
$comment_types = linkchecker_scan_comment_types();
if (empty($comment_types) || !user_access('access comments')) {
return array();
}
// Get a list of comments containing the link, using addTag('node_access') to
// allow comment access modules to exclude comments that the current user
// does not have access to view.
if (!empty($comment_author_account)) {
$query = db_select('comment', 'c');
$query
->addMetaData('base_table', 'comment');
$query
->addTag('node_access');
$query
->innerJoin('linkchecker_comment', 'lc', 'lc.cid = c.cid');
$query
->condition('lc.lid', $link->lid);
$query
->condition('c.uid', $comment_author_account->uid);
$query
->fields('c', array(
'cid',
));
}
else {
$query = db_select('comment', 'c');
$query
->addMetaData('base_table', 'comment');
$query
->addTag('node_access');
$query
->innerJoin('linkchecker_comment', 'lc', 'lc.cid = c.cid');
$query
->condition('lc.lid', $link->lid);
$query
->fields('c', array(
'cid',
));
}
$cids = $query
->execute()
->fetchCol();
// Return the array of comment IDs.
return $cids;
}