function _linkchecker_link_comment_ids in Link checker 6.2
Same name and namespace in other branches
- 7 linkchecker.module \_linkchecker_link_comment_ids()
Returns IDs of comments that contain a link which the current user is allowed to view.
Parameters
$link: An object representing the link to check.
$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
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 includes/
linkchecker.pages.inc
File
- ./
linkchecker.module, line 270 - This module periodically check links in given node types, blocks, cck fields, 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.
if (!module_exists('comment') || !variable_get('linkchecker_scan_comments', 0) || !user_access('access comments')) {
return array();
}
// Get a list of comments containing the link, using db_rewrite_sql() to
// allow comment access modules to exclude comments that the current user
// does not have access to view.
if (!empty($comment_author_account)) {
$comments = db_query(db_rewrite_sql('SELECT c.cid
FROM {comments} c
INNER JOIN {linkchecker_comments} lc ON lc.cid = c.cid
WHERE lc.lid = %d AND c.uid = %d', 'c', 'cid'), $link->lid, $comment_author_account->uid);
}
else {
$comments = db_query(db_rewrite_sql('SELECT c.cid
FROM {comments} c
INNER JOIN {linkchecker_comments} lc ON lc.cid = c.cid
WHERE lc.lid = %d', 'c', 'cid'), $link->lid);
}
// Return the array of comment IDs.
$cids = array();
while ($comment = db_fetch_object($comments)) {
$cids[] = $comment->cid;
}
return $cids;
}