You are here

function _googlenews_getgooglenews in Google News sitemap 6

Same name and namespace in other branches
  1. 5 googlenews.module \_googlenews_getgooglenews()

Generate the news feed.

1 string reference to '_googlenews_getgooglenews'
googlenews_menu in ./googlenews.module
Implementation of hook_menu().

File

./googlenews.module, line 40
Provides a Google News sitemap within your site using the url: http://www.yoursite.com/googlenews.xml

Code

function _googlenews_getgooglenews() {
  global $language;
  $content = '<?xml version="1.0" encoding="UTF-8"?>';
  $content .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
  $content .= '  xmlns:n="http://www.google.com/schemas/sitemap-news/0.9">';
  $node_types = variable_get('googlenews_node_types', array_keys(node_get_types()));
  $args = array_merge($node_types, array(
    time() - 172800,
  ));
  $sql = "SELECT n.nid, n.created, n.title FROM {node} n WHERE n.type IN (" . db_placeholders($node_types, 'varchar') . ") AND n.status = 1 AND n.created >= %d ORDER BY n.created DESC";
  $query = db_query_range(db_rewrite_sql($sql), $args, 0, 1000);
  while ($node = db_fetch_object($query)) {
    $content .= '<url>';
    $content .= '<loc>' . url('node/' . $node->nid, array(
      'absolute' => TRUE,
    )) . '</loc>';
    $content .= '<n:news>';
    $content .= '<n:publication>';
    $content .= '<n:name>' . variable_get('site_name', 'Drupal') . '</n:name>';
    $content .= '<n:language>' . check_plain($language->language) . '</n:language>';
    $content .= '</n:publication>';
    $content .= '<n:title>' . check_plain($node->title) . '</n:title>';
    $content .= '<n:publication_date>' . gmdate(DATE_W3C, $node->created) . '</n:publication_date>';
    $content .= '</n:news>';
    $content .= '</url>';
  }
  $content .= '</urlset>';
  drupal_set_header('Content-Type: text/xml');
  print $content;
}