nid) { if (!($node = node_load($nid))) { return; } $comments = (integer) 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 FROM {xmlsitemap_node} 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; } } /** * Implementation of hook_cron(). */ function xmlsitemap_node_cron() { if (($limit = variable_get('xmlsitemap_cron_limit', 100)) != -1) { $sql = "SELECT n.* FROM {node} n LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid WHERE xn.nid IS NULL AND n.status = 1"; $result = db_query_range($sql, 0, $limit); $sitemap_changed = FALSE; while ($node = db_fetch_object($result)) { if (module_exists('comment')) { $maxcomments = (integer) db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')); $comments = (integer) db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid) ); } else { $maxcomments = 0; } $row = new stdClass(); $row->nid = $node->nid; $row->changed = $node->changed; $row->previously_changed = $node->created; if ($maxcomments > 1) { $row->comment_ratio = $comments / $maxcomments; } drupal_write_record('xmlsitemap_node', $row); $sitemap_changed = TRUE; } if ($sitemap_changed) { xmlsitemap_flag_sitemap(); } } } /** * Implementation of hook_form_alter(). */ function xmlsitemap_node_form_alter(&$form, &$form_state, $form_id) { if (isset($form['type']) && $form_id == $form['type']['#value'] .'_node_form') { $node = $form['#node']; if (!isset($form['xmlsitemap'])) { $form['xmlsitemap'] = array( '#type' => 'fieldset', '#title' => t('XML sitemap'), '#collapsible' => TRUE, '#access' => user_access('override node settings') || user_access('administer nodes'), '#weight' => 30, ); } $options = xmlsitemap_priority_options('both'); $default = variable_get('xmlsitemap_node_type_priority_'. $node->type, '0.5'); $form['xmlsitemap']['priority_override'] = array( '#type' => 'select', '#title' => t('Priority'), '#description' => t('The default priority is %priority.', array('%priority' => $options[$default])), '#default_value' => isset($node->priority_override) ? $node->priority_override : -2.0, '#options' => $options, '#access' => user_access('override node settings') || user_access('administer nodes'), ); } } /** * Implementation of hook_form_FORM_ID_alter(). */ function xmlsitemap_node_form_node_type_form_alter(&$form, &$from_state) { if (isset($form['identity']['type'])) { if (!isset($form['xmlsitemap'])) { $form['xmlsitemap'] = array( '#type' => 'fieldset', '#title' => t('XML sitemap'), '#collapsible' => TRUE, '#weight' => 30, ); } $form['xmlsitemap']['xmlsitemap_node_type_priority'] = array( '#type' => 'select', '#title' => t('Priority adjustment'), '#description' => t('This number will be added to the priority of this content type.'), '#default_value' => variable_get('xmlsitemap_node_type_priority_'. $form['#node_type']->type, 0.5), '#options' => xmlsitemap_priority_options('exclude'), ); $form['#submit'][] = 'xmlsitemap_node_type_submit'; } } /** * Implementation of hook_form_FORM_ID_alter(). */ function xmlsitemap_node_form_xmlsitemap_settings_alter(&$form, &$from_state) { $options = xmlsitemap_priority_options(); $form['xmlsitemap_node'] = array( '#type' => 'fieldset', '#title' => t('Node settings'), '#description' => t('The settings for the nodes to include in the sitemap.'), '#collapsible' => TRUE, '#weight' => 1, ); $form['xmlsitemap_node']['xmlsitemap_node_promote_priority'] = array( '#type' => 'select', '#title' => t('Promotion priority adjustment'), '#description' => t("This number will be added to the priority of each post that is promoted to the front page. This setting doesn't apply for the nodes for which the priority is overriden."), '#default_value' => variable_get('xmlsitemap_node_promote_priority', 0.3), '#options' => $options, ); $form['xmlsitemap_node']['xmlsitemap_node_comment_priority'] = array( '#type' => 'select', '#title' => t('Comment ratio priority adjustment'), '#description' => t("This number will be added to the priority of the post with the highest number of comments; for the other posts, the number is calculated proportionally to the number of comments. This doesn't apply if the maximum number of comments is one, nor for the nodes for which the priority is overriden."), '#default_value' => variable_get('xmlsitemap_node_comment_priority', 0.2), '#options' => $options, ); } /** * Implementation of hook_node_operations(). */ function xmlsitemap_node_node_operations() { $operations = array( 'xmlsitemap_add_nodes' => array( 'label' => t('Add the selected posts to the XML sitemap'), 'callback' => '_xmlsitemap_node_priority_operations', 'callback arguments' => array('priority' => 0.5), ), 'xmlsitemap_change_nodes_priority' => array( 'label' => t('Change the XML sitemap priority of the selected posts to default'), 'callback' => '_xmlsitemap_node_priority_operations', 'callback arguments' => array('priority' => -2.0), ), 'xmlsitemap_remove_nodes' => array( 'label' => t('Remove the selected posts from the XML sitemap'), 'callback' => '_xmlsitemap_node_priority_operations', 'callback arguments' => array('priority' => -1.0), ), ); return $operations; } /** * Implementation of hook_node_type(). */ function xmlsitemap_node_node_type($op, $info) { if ($op == 'delete') { variable_del('xmlsitemap_node_type_priority_'. $info->type); } elseif ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { variable_set('xmlsitemap_node_type_priority_'. $info->type, variable_get('xmlsitemap_node_type_priority_'. $info->old_type, 0.5)); variable_del('xmlsitemap_node_type_priority_'. $info->old_type); } } /** * Implementation of hook_nodeapi(). */ function xmlsitemap_node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'prepare': if (isset($node->nid)) { $priority_override = db_result(db_query("SELECT priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid) ); $node->priority_override = $priority_override !== FALSE ? $priority_override : -2.0; } break; case 'insert': $row = new stdClass(); $row->nid = $node->nid; $row->changed = $node->changed; $row->previously_changed = $node->created; $row->priority_override = isset($node->priority_override) ? $node->priority_override : -2.0; drupal_write_record('xmlsitemap_node', $row); if ($node->status) { xmlsitemap_flag_sitemap(); } break; case 'update': if (($result = db_fetch_object(db_query("SELECT nid, changed, previously_changed, comment_ratio, priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid))) === FALSE) { $row = new stdClass(); $row->nid = $node->nid; $row->changed = $node->changed; $row->previously_changed = $node->created; $row->priority_override = isset($node->priority_override) ? $node->priority_override : -2.0; } else { $row = $result; $row->previously_changed = $row->changed; $row->changed = $node->changed; if (isset($node->priority_override)) { $row->priority_override = $node->priority_override; } } drupal_write_record('xmlsitemap_node', $row, $result === FALSE ? NULL : 'nid'); xmlsitemap_flag_sitemap(); break; case 'delete': db_query("DELETE FROM {xmlsitemap_node} WHERE nid = %d", $node->nid); db_query("DELETE FROM {xmlsitemap} WHERE type = 'node' AND id = %d", $node->nid); if ($node->status) { xmlsitemap_flag_sitemap(); } break; } } /** * Implementation of hook_xmlsitemap_description(). */ function xmlsitemap_node_xmlsitemap_description() { return '