You are here

function xmlsitemap_node_comment in XML sitemap 6

Same name and namespace in other branches
  1. 5.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_comment()
  2. 5 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_comment()
  3. 6.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_comment()

Implementation of hook_comment().

File

xmlsitemap_node/xmlsitemap_node.module, line 20
Adds nodes to the sitemap.

Code

function xmlsitemap_node_comment($a1, $op) {
  switch ($op) {
    case 'insert':
    case 'update':
    case 'delete':
    case 'publish':
    case 'unpublish':
      $maxcomments = (int) db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'));
      if ($nid = is_array($a1) ? $a1['nid'] : $a1->nid) {
        if (!($node = node_load($nid))) {
          return;
        }
        $comments = (int) db_result(db_query('SELECT comment_count
          FROM {node_comment_statistics}
          WHERE nid = %d', $nid));
        $query = "SELECT nid, changed, previously_changed, comment_ratio, priority_override\n          FROM {xmlsitemap_node}\n          WHERE nid = %d";
        if (($link = db_fetch_object(db_query($query, $nid))) !== FALSE) {
          $row = $link;
          if ($node->changed > $row->changed) {
            $row->previously_changed = $row->changed;
            $row->changed = $node->changed;
          }
        }
        else {
          $row = new stdClass();
          $row->nid = $nid;
          $row->changed = $node->changed;
          $row->previously_changed = $node->created;
        }
        if ($maxcomments > 1) {
          $row->comment_ratio = $comments / $maxcomments;
        }
        drupal_write_record('xmlsitemap_node', $row, $link !== FALSE ? 'nid' : NULL);
      }
      break;
  }
}