You are here

function googlenews_list_nodes in Google News sitemap 7

Get a list of all nodes to be output in the Google News sitemap.

Return value

array An array of node nid's.

2 calls to googlenews_list_nodes()
googlenews_admin_settings in ./googlenews.admin.inc
Form builder; administration settings.
googlenews_getgooglenews in ./googlenews.sitemap.inc
Generate the news feed.

File

./googlenews.module, line 102
Provides a Google News sitemap within your site using the URL.

Code

function googlenews_list_nodes() {

  // List content using a specific view.
  if (variable_get('googlenews_source', 'manual') == 'views' && module_exists('views')) {
    $view = variable_get('googlenews_view', 'frontpage|default');
    list($view_name, $view_display_id) = explode('|', $view);
    $items = array();
    foreach (views_get_view_result($view_name, $view_display_id) as $item) {
      $new = new StdClass();
      $new->nid = $item->nid;
      $items[] = $new;
    }
    return $items;
  }
  else {
    $time = REQUEST_TIME - intval(variable_get('googlenews_content_hours', 48)) * 3600;
    $content_types = variable_get('googlenews_node_types', array_keys(node_type_get_names()));

    // Only proceed if some content types were enabled.
    if (!empty($content_types)) {
      $query = db_select('node', 'n');
      $query
        ->fields('n', array(
        'nid',
      ));
      $query
        ->condition('n.type', $content_types);
      $query
        ->condition('n.status', NODE_PUBLISHED);
      $query
        ->condition('n.created', $time, '>=');
      $query
        ->addTag('node_access');
      $query
        ->addTag('googlenews_sitemap');
      $query
        ->orderBy('n.created', 'DESC');
      $query
        ->range(0, 1000);
      return $query
        ->execute()
        ->fetchAll();
    }
    else {
      return array();
    }
  }
}