You are here

function delete_all_content_confirm in Delete all 7

Same name and namespace in other branches
  1. 6 delete_all.module \delete_all_content_confirm()
1 string reference to 'delete_all_content_confirm'
delete_all_menu in ./delete_all.module
@file Delete all 7.x module

File

./delete_all.module, line 172
Delete all 7.x module

Code

function delete_all_content_confirm() {
  $results = $_POST;
  $form = array();
  $form['method'] = array(
    '#type' => 'hidden',
    '#value' => isset($results['method']) ? $results['method'] : '',
  );
  if (!isset($results['all'])) {
    $results['all'] = '';
  }
  if (!isset($results['reset'])) {
    $results['reset'] = '';
  }
  $form['all'] = array(
    '#type' => 'hidden',
    '#value' => isset($results['all']) ? $results['all'] : '',
  );
  if (isset($results['all']) && !isset($results['types'])) {
    if (!empty($results['all'])) {

      // Only carry reset value through if delete all nodes is set
      $form['reset'] = array(
        '#type' => 'hidden',
        '#value' => $results['reset'],
      );
      $form['all_warning'] = array(
        '#markup' => '<p>' . t('All content in all content types will be deleted. Be sure to have a backup of any important data!') . '</p>',
      );
    }
    if (!empty($results['reset'])) {
      if (empty($results['all'])) {
        $form['all_reset'] = array(
          '#markup' => '<p>' . t('Sorry, we can\'t reset the counters because you are not deleting all nodes.') . '</p>',
        );
      }
      else {
        $form['all_reset'] = array(
          '#markup' => '<p>' . t('Node, revision and comment counts will be reset.') . '</p>',
        );
      }
    }
  }
  if (isset($results['types']) && is_array($results['types'])) {
    foreach ($results['types'] as $key_type => $type) {
      $form['type_' . $key_type] = array(
        '#type' => 'hidden',
        '#value' => $type,
      );
      $info = node_type_get_types('type', $type);
      $info = $info[$type];
      $form[$type . '_warning'] = array(
        '#markup' => '<p>' . t('All node content of type %type will be deleted. Be sure to have a backup of any important data!', array(
          '%type' => $info->name,
        )) . '</p>',
      );
    }
  }
  if (module_exists('taxonomy')) {
    $vocabulary_info = array();
    foreach (taxonomy_get_vocabularies() as $vocabulary) {
      $vocabulary_info[$vocabulary->machine_name] = $vocabulary->name;
    }
    if (isset($results['vocabularies'])) {
      if (is_array($results['vocabularies'])) {
        foreach ($results['vocabularies'] as $key_vocabulary => $vocabulary) {
          $form['vocabulary_' . $key_vocabulary] = array(
            '#type' => 'hidden',
            '#value' => $vocabulary,
          );
          $info = $vocabulary_info[$vocabulary];
          $form[$vocabulary . '_warning'] = array(
            '#markup' => '<p>' . t('All taxonomy terms of vocabulary %vocabulary will be deleted. Be sure to have a backup of any important data!', array(
              '%vocabulary' => $info,
            )) . '</p>',
          );
        }
      }
    }
  }
  $keys = array_filter(array_keys($results), "_delete_all_type_keys");
  foreach ($keys as $key) {
    $form[$key] = array(
      '#type' => 'hidden',
      '#value' => $results[$key],
    );
  }
  $vocabulary_keys = array_filter(array_keys($results), "_delete_all_vocabulary_keys");
  foreach ($vocabulary_keys as $vkey) {
    $form[$vkey] = array(
      '#type' => 'hidden',
      '#value' => $results[$vkey],
    );
  }
  return confirm_form($form, t('Are you sure you wish to delete content?'), 'admin/content/delete_content', NULL, t('Delete all content now'), t('Cancel delete of all content'));
}