googlenews.module in Google News sitemap 7
Same filename and directory in other branches
Provides a Google News sitemap within your site using the URL.
File
googlenews.moduleView source
<?php
/**
* @file
* Provides a Google News sitemap within your site using the URL.
*
* @see http://www.yoursite.com/googlenews.xml
*/
/**
* Implementation of hook_menu().
*/
function googlenews_menu() {
$items['googlenews.xml'] = array(
'page callback' => 'googlenews_getgooglenews',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'googlenews.sitemap.inc',
);
$items['admin/config/search/googlenews'] = array(
'title' => 'Google News sitemap',
'description' => 'Specify category types for the Google News sitemap.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'googlenews_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'googlenews.admin.inc',
);
return $items;
}
/**
* Provide a list of tags that are available for use in news feeds.
*
* Tags must be in the following format:
* 'tag_name' => array(
* 'title' => t('The tag name'),
* 'description' => t('A full description for the tag, detailing its intended
* usage'),
* // If the tag is to be a selector instead of a text field:
* 'options' => array(
* 'opt1' => t('Option 1'),
* 'opt2' => t('Option 2'),
* 'opt3' => t('Option 3'),
* ),
* // If the selector is to allow multiple items.
* 'multiple' => TRUE,
* ),
*
* @return array
* A nested array of available tags.
*/
function googlenews_tag_list() {
$tags = array(
'access' => array(
'title' => t('Access requirements'),
'description' => t('Describes the accessibility of the article to Google News readers.'),
'options' => array(
'' => t('None (default)'),
'Subscription' => t('Subscription required'),
'Registration' => t('Registration required'),
),
),
'genres' => array(
'title' => t('Genres'),
'description' => t("The character of the article's content. This must be accurate in order to provide a consistent experience for Google News readers. Multiple selections are allowed."),
'options' => array(
'PressRelease' => t('Official press release.'),
'Satire' => t('Satire - ridicules its subject for didactic purposes.'),
'Blog' => t('Blog - article published on a blog or in a blog format.'),
'OpEd' => t("OpEd - opinion-based article which comes specifically from the site's Op-Ed section."),
'Opinion' => t('Opinion - non-OpEd opinion-based article, e.g. reviews, interviews, etc.'),
'UserGenerated' => t('User generated - newsworthy content which has already gone through a formal editorial review process.'),
),
'multiple' => TRUE,
),
'geo_locations' => array(
'title' => t('Geographical locations'),
'description' => t("This tag can help Google News identify the geographic location of the articles. Applying it may be especially useful if there are sections of the site dedicated to coverage of a specific location that differs from the site's main location. List locations from smallest entity to largest, e.g. City, State, Country, or Province, Country."),
),
'keywords' => array(
'title' => t('Keywords'),
'description' => t('A comma-separated list of keywords describing the topic of the article. Keywords may be drawn from, but are not limited to, the <a href="@keywords-url">list of existing Google News keywords</a>.', array(
'@keywords-url' => 'http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=116037',
)),
),
'stock_tickers' => array(
'title' => t('Stock tickers'),
'description' => t('A comma-separated list of up to 5 stock tickers of the companies, mutual funds, or other financial entities that are the main subject of the article. Relevant primarily for business articles. Each ticker must be prefixed by the name of its stock exchange, and must match its entry in <a href="@finance-url">Google Finance</a>. For example, "NASDAQ:AMAT" (but not "NASD:AMAT"), or "BOM:500325" (but not "BOM:RIL").', array(
'@finance-url' => 'http://finance.google.com/',
)),
),
);
// Allow other modules to extend the list.
drupal_alter('googlenews_tags', $tags);
return $tags;
}
/**
* Get a list of all nodes to be output in the Google News sitemap.
*
* @return array
* An array of node nid's.
*/
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();
}
}
}
Functions
Name | Description |
---|---|
googlenews_list_nodes | Get a list of all nodes to be output in the Google News sitemap. |
googlenews_menu | Implementation of hook_menu(). |
googlenews_tag_list | Provide a list of tags that are available for use in news feeds. |