You are here

function xmlsitemap_sitemap_list_form in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.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 13
Administrative page callbacks for the xmlsitemap module.

Code

function xmlsitemap_sitemap_list_form() {

  // 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>',
  );
  $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_select('xmlsitemap_sitemap');
  $query
    ->fields('xmlsitemap_sitemap', array(
    'smid',
  ));
  $query
    ->extend('TableSort')
    ->orderByHeader($header);
  $smids = $query
    ->execute()
    ->fetchCol();
  $sitemaps = $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' => array(
        '#type' => 'link',
        '#title' => $sitemap->url,
        '#href' => $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/config/search/xmlsitemap/edit/' . $smid, array(
      'title' => t('Edit'),
      'modal' => TRUE,
    ));
    $operations['delete'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/delete/' . $smid, array(
      'title' => t('Delete'),
      'modal' => TRUE,
    ));
    if ($operations) {
      $options[$smid]['operations'] = array(
        'data' => array(
          '#theme' => 'links',
          '#links' => $operations,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        ),
      );
    }
    else {
      $options[$smid]['operations'] = t('None (sitemap locked)');
    }
  }
  $form['sitemaps'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No XML sitemaps available.') . ' ' . l(t('Add a new XML sitemap'), 'admin/config/search/xmlsitemap/add'),
  );
  return $form;
}