Commit 1ae2d059 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Fixed engine sitemap operations.

parent 7f1363c5
......@@ -360,6 +360,10 @@ function xmlsitemap_generate_index(array $sitemap, $handle, &$status) {
/**
* Batch information callback for regenerating the sitemap files.
*
* @param $smids
* An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps.
*/
function xmlsitemap_regenerate_batch(array $smids = array()) {
if (empty($smids)) {
......
......@@ -119,12 +119,17 @@ function xmlsitemap_permission() {
);
}
function xmlsitemap_sitemap_load($smid) {
$sitemap = db_query_range("SELECT * FROM {xmlsitemap_sitemap} WHERE smid = :smid", 0, 1, array(':smid' => $smid))->fetchAssoc();
if ($sitemap) {
$sitemap['context'] = unserialize($sitemap['context']);
function xmlsitemap_sitemap_load_multiple(array $smids) {
$sitemaps = db_query("SELECT * FROM {xmlsitemap_sitemap} WHERE smid IN (:smids)", array(':smids' => $smids))->fetchAllAssoc('smid', PDO::FETCH_ASSOC);
foreach ($sitemaps as $smid => $sitemap) {
$sitemaps[$smid]['context'] = unserialize($sitemap['context']);
}
return $sitemap;
return $sitemaps;
}
function xmlsitemap_sitemap_load($smid) {
$sitemap = xmlsitemap_sitemap_load_multiple(array($smid));
return $sitemap ? reset($sitemap) : FALSE;
}
function xmlsitemap_sitemap_load_by_context(array $context = NULL) {
......
<?php
// $Id$
/**
* Implements hook_hook_info().
*/
function xmlsitemap_engines_hook_info() {
$hooks['xmlsitemap_engine_info'] = array(
'group' => 'xmlsitemap',
);
$hooks['xmlsitemap_engine_info_alter'] = array(
'group' => 'xmlsitemap',
);
return $hooks;
}
/**
* Implements hook_help().
*/
......@@ -47,13 +60,25 @@ function xmlsitemap_engines_cron() {
}
}
function xmlsitemap_engines_submit_access() {
function xmlsitemap_engines_can_submit() {
// Skip if the site is offline since search engines will not be able to
// access the site's content.
if (variable_get('site_offline', 0)) {
return FALSE;
}
if (!variable_get('xmlsitemap_engines_engines', array()) && !variable_get('xmlsitemap_engines_custom_urls', '')) {
return FALSE;
}
return TRUE;
}
function xmlsitemap_engines_submit_access() {
if (!xmlsitemap_engines_can_submit()) {
return FALSE;
}
// Allow manual submissions to run.
//if ($_GET['q'] == 'admin/config/search/xmlsitemap/engines/submit' && user_access('administer xmlsitemap')) {
// return TRUE;
......@@ -78,9 +103,17 @@ function xmlsitemap_engines_submit_access() {
/**
* Submit the sitemaps to all the specified search engines.
*
* @param $smids
* An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps.
*/
function xmlsitemap_engines_submit_engines() {
$sitemaps = xmlsitemap_get_sitemaps();
function xmlsitemap_engines_submit_engines(array $smids = array()) {
if (empty($smids)) {
$smids = db_query("SELECT smid FROM {xmlsitemap_sitemap}")->fetchCol();
}
$sitemaps = xmlsitemap_sitemap_load_multiple($smids);
$engines = variable_get('xmlsitemap_engines_engines', array());
$engine_info = xmlsitemap_engines_get_engine_info();
......@@ -105,7 +138,7 @@ function xmlsitemap_engines_submit_engines() {
* @param $sitemaps
* An array of URLs of the sitemaps to submit.
*/
function xmlsitemap_engines_submit_sitemaps($url, $sitemaps = array()) {
function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps = array()) {
foreach ($sitemaps as $sitemap) {
$submit_url = xmlsitemap_engines_prepare_url($url, $sitemap);
$request = drupal_http_request($submit_url);
......@@ -209,14 +242,16 @@ function xmlsitemap_engines_variables() {
return $variables;
}
/**
* Implements hook_xmlsitemap_sitemap_operations().
*/
function xmlsitemap_engines_xmlsitemap_sitemap_operations() {
$operations['xmlsitemap_engines_submit'] = array(
'label' => t('Submit to search engines'),
'callback' => 'xmlsitemap_engines_sitemap_multiple_submit',
);
return $operations;
}
function xmlsitemap_engines_sitemap_multiple_submit(array $sitemaps) {
if (xmlsitemap_engines_can_submit()) {
$operations['xmlsitemap_engines_submit'] = array(
'label' => t('Submit to search engines'),
'action past' => t('Submitted'),
'callback' => 'xmlsitemap_engines_submit_engines',
);
return $operations;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment