You are here

function xmlsitemap_sitemap_list_form in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap.admin.inc \xmlsitemap_sitemap_list_form()

Render a tableselect list of XML sitemaps for the main admin page.

1 string reference to 'xmlsitemap_sitemap_list_form'
xmlsitemap_menu in ./xmlsitemap.module
Implements hook_menu().

File

./xmlsitemap.admin.inc, line 18
Administrative page callbacks for the xmlsitemap module.

Code

function xmlsitemap_sitemap_list_form() {
  xmlsitemap_load_all_includes();
  $destination = drupal_get_destination();

  // Add the local actions.
  $form['actions'] = array(
    '#type' => 'markup',
    '#value' => theme('links', xmlsitemap_sitemap_list_form_local_actions(), array(
      'class' => 'item-list action-links',
    )),
  );

  // Build the 'Update options' form.
  $form['#operations'] = module_invoke_all('xmlsitemap_sitemap_operations');
  $operations = array();
  foreach ($form['#operations'] as $operation => $operation_info) {
    $operations[$operation] = $operation_info['label'];
  }
  asort($operations);
  $form['operations'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
    '#access' => module_exists('elements'),
  );
  $form['operations']['operation'] = array(
    '#type' => 'select',
    '#options' => $operations,
    '#default_value' => 'update',
  );
  $form['operations']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $contexts = xmlsitemap_get_context_info();
  $header = array();
  $header['url'] = array(
    'data' => t('URL'),
  );
  foreach ($contexts as $context_key => $context_info) {
    if (!empty($context_info['summary callback'])) {
      $header['context_' . $context_key] = $context_info['label'];
    }
  }
  $header['updated'] = array(
    'data' => t('Last updated'),
    'field' => 'updated',
    'sort' => 'asc',
  );
  $header['links'] = array(
    'data' => t('Links'),
    'field' => 'links',
  );
  $header['chunks'] = array(
    'data' => t('Pages'),
    'field' => 'chunks',
  );
  $header['operations'] = array(
    'data' => t('Operations'),
  );
  $query = db_query("SELECT smid FROM {xmlsitemap_sitemap}" . tablesort_sql($header));
  $smids = xmlsitemap_db_fetch_col($query);
  $sitemaps = !empty($smids) ? xmlsitemap_sitemap_load_multiple($smids) : array();
  $options = array();
  foreach ($sitemaps as $smid => $sitemap) {
    $sitemap->url = url($sitemap->uri['path'], $sitemap->uri['options']);
    $options[$smid]['url'] = array(
      'data' => l($sitemap->url, $sitemap->url),
    );
    foreach ($contexts as $context_key => $context_info) {
      if (!empty($context_info['summary callback'])) {
        $options[$smid]['context_' . $context_key] = _xmlsitemap_sitemap_context_summary($sitemap, $context_key, $context_info);
      }
    }
    $options[$smid]['updated'] = $sitemap->updated ? format_date($sitemap->updated, 'short') : t('Never');
    $options[$smid]['links'] = $sitemap->updated ? $sitemap->links : '-';
    $options[$smid]['chunks'] = $sitemap->updated ? $sitemap->chunks : '-';

    // @todo Highlight sitemaps that need updating.

    //$options[$smid]['#attributes']['class'] = 'warning';
    $operations = array();
    $operations['edit'] = xmlsitemap_get_operation_link('admin/settings/xmlsitemap/edit/' . $smid, array(
      'title' => t('Edit'),
      'modal' => TRUE,
    ));
    $operations['delete'] = xmlsitemap_get_operation_link('admin/settings/xmlsitemap/delete/' . $smid, array(
      'title' => t('Delete'),
      'modal' => TRUE,
    ));
    if ($operations) {
      $options[$smid]['operations'] = array(
        'data' => theme('links', $operations, array(
          'class' => 'links inline',
        )),
      );
    }
    else {
      $options[$smid]['operations'] = t('None (sitemap locked)');
    }
  }
  if (module_exists('elements')) {
    $form['sitemaps'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#empty' => t('No XML sitemaps available.') . ' ' . l('Add a new XML sitemap', 'admin/settings/xmlsitemap/add'),
    );
  }
  else {
    if (empty($options)) {
      $options[] = array(
        array(
          'data' => t('No XML sitemaps available.') . ' ' . l('Add a new XML sitemap', 'admin/settings/xmlsitemap/add'),
          'colspan' => count($header),
          'class' => 'empty',
        ),
      );
    }
    $form['sitemaps'] = array(
      '#type' => 'markup',
      '#value' => theme('table', $header, $options),
    );
  }
  return $form;
}