function _linkchecker_add_comment_links in Link checker 5.2
Same name and namespace in other branches
- 6.2 linkchecker.module \_linkchecker_add_comment_links()
- 7 linkchecker.module \_linkchecker_add_comment_links()
Add comment links to database.
4 calls to _linkchecker_add_comment_links()
- linkchecker_comment in ./
linkchecker.module - _linkchecker_batch_comments_import_op in ./
linkchecker.module - Batch operation: Load all comments, 100 by hundred.
- _linkchecker_batch_import_comments_op in ./
linkchecker.module - Batch operation: Load all boxes, 100 by 100.
- _linkchecker_scan_comment_links in ./
linkchecker.module - Scan specified comment for links. Helper function for job_queue scans.
File
- ./
linkchecker.module, line 1106 - This module periodically check links in given node types, blocks, cck fields, etc.
Code
function _linkchecker_add_comment_links($comment) {
// Create array of comment fields to scan.
$text_items = array();
$text_items[] = _filter_url($comment['subject'], $comment['format']);
$text_items[] = _linkchecker_check_markup($comment['comment'], $comment['format'], FALSE);
// Get the absolute node path for extraction of relative links.
$path = url('node/' . $comment['nid'], NULL, NULL, TRUE);
// Extract all links in a comment.
$links = _linkchecker_extract_links(implode(' ', $text_items), $path);
// Comment have links.
if (!empty($links)) {
// Remove all links from the links array already in the database
// and only add missing links to database.
$missing_links = _linkchecker_comment_links_missing($comment['cid'], $links);
// Add a job for scanning the next 100 links via job_queue module.
$missing_links_count = count($missing_links) - LINKCHECKER_SCAN_MAX_LINKS_PER_RUN;
if (module_exists('job_queue') && $missing_links_count > 0) {
job_queue_add('_linkchecker_scan_comment_links', 'Scan comment ' . $comment['cid'] . ' having ' . $missing_links_count . ' links not yet added to linkchecker_links table.', array(
$comment['cid'],
), '', FALSE);
}
// Only add unique links to database that do not exist.
$i = 0;
foreach ($missing_links as $link) {
$lid = db_result(db_query("SELECT lid FROM {linkchecker_links} WHERE token = '%s'", md5($link)));
if (!$lid) {
$lid = db_next_id('linkchecker_links_lid');
db_query("INSERT INTO {linkchecker_links} (lid, token, url, status) VALUES (%d, '%s', '%s', %d)", $lid, md5($link), $link, _linkchecker_link_check_status_filter($link));
}
db_query("INSERT INTO {linkchecker_comments} (cid, lid) VALUES (%d, %d)", $comment['cid'], $lid);
// Break processing if max links limit per run has been reached.
$i++;
if ($i >= LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
break;
}
}
}
// Remove dead link references for cleanup reasons as very last step.
_linkchecker_cleanup_comment_references($comment['cid'], $links);
}