You are here

domain_xmlsitemap.module in Domain XML sitemap 6

Same filename and directory in other branches
  1. 7 domain_xmlsitemap.module

File

domain_xmlsitemap.module
View source
<?php

/**
 * Implements hook_xmlsitemap_context_info().
 */
function domain_xmlsitemap_xmlsitemap_context_info() {
  $context['domain'] = array(
    'label' => t('Domain'),
    'default' => 0,
  );
  return $context;
}

/**
 * Implements hook_xmlsitemap_context().
 */
function domain_xmlsitemap_xmlsitemap_context() {
  $domain = domain_get_domain();
  $context['domain'] = (string) $domain['domain_id'];
  return $context;
}

/**
 * Implements hook_xmlsitemap_context_url_options().
 */
function domain_xmlsitemap_xmlsitemap_context_url_options(array $context) {
  $options = array();
  if (isset($context['domain']) && ($domain = domain_load($context['domain']))) {
    $options['base_url'] = rtrim($domain['path'], '/');
  }
  return $options;
}

/**
 * Implements hook_node_grants_alter().
 */
function domain_xmlsitemap_node_grants_alter(&$grants, $account, $op) {
  if (!empty($account->xmlsitemap_node_access)) {
    unset($grants['domain_site']);
    unset($grants['domain_id']);
    $grants['domain_all'] = array(
      0,
    );
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function domain_xmlsitemap_form_xmlsitemap_sitemap_edit_form_alter(&$form, $form_state) {
  $domains = domain_domains();
  $options = array();
  foreach ($domains as $domain) {
    $options[$domain['domain_id']] = $domain['path'];
  }
  $form['context']['domain'] = array(
    '#type' => 'select',
    '#title' => t('Domain'),
    '#options' => $options,
    '#default_value' => isset($form['#sitemap']->context['domain']) ? $form['#sitemap']->context['domain'] : '',
    '#access' => !empty($options),
  );
}

/**
 * Implements hook_query_xmlsitemap_generate_alter().
 */
function domain_xmlsitemap_query_xmlsitemap_generate_alter(array &$query, array &$args, stdClass $sitemap) {
  if (!isset($sitemap->context['domain'])) {
    return;
  }
  $query['FROM'] .= " LEFT JOIN {domain_access} da ON x.type = 'node' AND x.id = da.nid";
  $query['WHERE'] .= " AND (da.gid IS NULL OR (da.gid = 0 AND da.realm = 'domain_site') OR (da.gid = %d AND da.realm = 'domain_id'))";
  $args[] = $sitemap->context['domain'];

  // If the domain source module is enabled, we need to add a check against
  // the {domain_source} table as well.
  if (module_exists('domain_source')) {
    $query['FROM'] .= " LEFT JOIN {domain_source} ds ON x.type = 'node' AND x.id = ds.nid";
    $query['WHERE'] .= " AND (ds.domain_id IS NULL OR ds.domain_id IN (%d, %d))";
    $args[] = DOMAIN_SOURCE_USE_ACTIVE;
    $args[] = $sitemap->context['domain'];
  }
}

/**
 * Implements hook_domainupdate().
 */
function domain_xmlsitemap_domainupdate($op, $domain, $form_state = array()) {
  if ($op == 'update') {

    // If domain was changed, flag sitemap for updating.
  }
  elseif ($op == 'delete') {

    // Delete any sitemaps with this domain in its context.
  }
}