[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/devel/ -> devel_generate.module (source)

   1  <?php
   2  // $Id: devel_generate.module,v 1.11.2.16 2010/12/06 15:27:22 weitzman Exp $
   3  
   4  require_once ('devel_generate_batch.inc');
   5  
   6  /**
   7   * Implementation of hook_menu().
   8   */
   9  function devel_generate_menu() {
  10    $items = array();
  11  
  12    // Admin user pages
  13    $items['admin/generate'] = array(
  14      'title' => 'Generate items',
  15      'description' => 'Populate your database with dummy items.',
  16      'position' => 'left',
  17      'page callback' => 'system_admin_menu_block_page',
  18      'access arguments' => array('administer site configuration'),
  19      'file' => 'system.admin.inc',
  20      'file path' => drupal_get_path('module', 'system'),
  21    );
  22    $items['admin/generate/user'] = array(
  23      'title' => 'Generate users',
  24      'description' => 'Generate a given number of users. Optionally delete current users.',
  25      'page callback' => 'drupal_get_form',
  26      'page arguments' => array('devel_generate_users_form'),
  27      'access arguments' => array('administer users'),
  28    );
  29    $items['admin/generate/content'] = array(
  30      'title' => 'Generate content',
  31      'description' => 'Generate a given number of nodes and comments. Optionally delete current items.',
  32      'page callback' => 'drupal_get_form',
  33      'page arguments' => array('devel_generate_content_form'),
  34      'access arguments' => array('administer nodes'),
  35    );
  36    if (module_exists('taxonomy')) {
  37      $items['admin/generate/taxonomy'] = array(
  38        'title' => 'Generate categories',
  39        'description' => 'Generate a given number of vocabularies and terms. Optionally delete current categories.',
  40        'page callback' => 'drupal_get_form',
  41        'page arguments' => array('devel_generate_taxonomy_form'),
  42        'access arguments' => array('administer nodes'),
  43      );
  44    }
  45  
  46    return $items;
  47  }
  48  
  49  function devel_generate_users_form() {
  50    $form['num'] = array(
  51      '#type' => 'textfield',
  52      '#title' => t('How many users would you like to generate?'),
  53      '#default_value' => 50,
  54      '#size' => 10,
  55    );
  56    $form['kill_users'] = array(
  57      '#type' => 'checkbox',
  58      '#title' => t('Delete all users (except user id 1) before generating new users.'),
  59      '#default_value' => FALSE,
  60    );
  61  
  62    $options = array(1 => t('Now'));
  63    foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
  64      $options[$interval] = format_interval($interval, 1) . ' ' . t('ago');
  65    }
  66    $form['time_range'] = array(
  67      '#type' => 'select',
  68      '#title' => t('How old should user accounts be?'),
  69      '#description' => t('User ages will be distributed randomly from the current time, back to the selected time.'),
  70      '#options' => $options,
  71      '#default_value' => 604800,
  72    );
  73  
  74    $form['submit'] = array(
  75      '#type' => 'submit',
  76      '#value' => t('Do it!'),
  77    );
  78    return $form;
  79  }
  80  
  81  function devel_generate_users_form_submit($form_id, &$form_state) {
  82    module_load_include('inc', 'devel_generate');
  83    devel_create_users($form_state['values']['num'], $form_state['values']['kill_users'], $form_state['values']['time_range']);
  84  }
  85  
  86  function devel_generate_content_form() {
  87    require_once ('devel_generate.inc');
  88    $options = devel_generate_content_types();
  89  
  90    if (empty($options)) {
  91      drupal_set_message(t('You do not have any content types that can be generated. <a href="@create-type">Go create a new content type</a> already!</a>', array('@create-type' => url('admin/content/types/add'))), 'error', FALSE);
  92      return;
  93    }
  94  
  95    $form['node_types'] = array(
  96      '#type' => 'checkboxes',
  97      '#title' => t('Which node types do you want to create?'),
  98      '#options' => $options,
  99      '#default_value' => array_keys($options),
 100    );
 101    if (module_exists('checkall')) $form['node_types']['#checkall'] = TRUE;
 102    $form['kill_content'] = array(
 103      '#type' => 'checkbox',
 104      '#title' => t('<strong>Delete all content</strong> in these node types before generating new content.'),
 105      '#default_value' => FALSE,
 106    );
 107    $form['num_nodes'] = array(
 108      '#type' => 'textfield',
 109      '#title' => t('How many nodes would you like to generate?'),
 110      '#default_value' => 50,
 111      '#size' => 10,
 112    );
 113    
 114    $options = array(1 => t('Now'));
 115    foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
 116      $options[$interval] = format_interval($interval, 1) . ' ' . t('ago');
 117    }
 118    $form['time_range'] = array(
 119      '#type' => 'select',
 120      '#title' => t('How far back in time should the nodes be dated?'),
 121      '#description' => t('Node creation dates will be distributed randomly from the current time, back to the selected time.'),
 122      '#options' => $options,
 123      '#default_value' => 604800,
 124    );
 125    
 126    $form['max_comments'] = array(
 127      '#type' => 'textfield',
 128      '#title' => t('Maximum number of generated comments per node'),
 129      '#description' => t('You must also enable comments for the node types you are generating.'),
 130      '#default_value' => 0,
 131      '#size' => 3,
 132      '#access' => module_exists('comment'),
 133    );
 134    $form['title_length'] = array(
 135      '#type' => 'textfield',
 136      '#title' => t('Max word length of titles'),
 137      '#default_value' => 8,
 138      '#size' => 10,
 139    );
 140    $form['add_upload'] = array(
 141      '#type' =>  'checkbox',
 142      '#disabled' => !module_exists('upload'),
 143      '#description' => t('Requires upload.module'),
 144      '#title' => t('Add an upload to each node'),
 145      '#default_value' => FALSE,
 146    );
 147    $form['add_terms'] = array(
 148      '#disabled' => !module_exists('taxonomy'),
 149      '#description' => t('Requires taxonomy.module'),
 150      '#type' => 'checkbox',
 151      '#title' => t('Add taxonomy terms to each node.'),
 152      '#default_value' => FALSE,
 153    );
 154    $form['add_alias'] = array(
 155      '#type' => 'checkbox',
 156      '#disabled' => !module_exists('path'),
 157      '#description' => t('Requires path.module'),
 158      '#title' => t('Add an url alias for each node.'),
 159      '#default_value' => FALSE,
 160    );
 161    $form['add_statistics'] = array(
 162      '#type' => 'checkbox',
 163      '#title' => t('Generate node view statistics (node_counter table).'),
 164      '#default_value' => TRUE,
 165      '#access' => module_exists('statistics'),
 166    );
 167    if (module_exists('locale')) {
 168      $form['add_language'] = array(
 169        '#type' => 'select',
 170        '#title' => t('Set language on nodes'),
 171        '#multiple' => TRUE,
 172        '#description' => t('Requires locale.module'),
 173        '#options' => array_merge(array('' => t('Language neutral')), locale_language_list()),
 174        '#default_value' => '',
 175      );
 176    }
 177    $form['submit'] = array(
 178      '#type' => 'submit',
 179      '#value' => t('Do it!'),
 180    );
 181    $form['#redirect'] = FALSE;
 182  
 183    return $form;
 184  }
 185  
 186  function devel_generate_content_form_submit($form_id, &$form_state) {
 187    $form_state['values']['node_types'] = array_filter($form_state['values']['node_types']);
 188    if (!$form_state['values']['kill_content'] && $form_state['values']['num_nodes'] <= 50 && $form_state['values']['max_comments'] <= 10) {
 189      require_once ('devel_generate.inc');
 190      devel_generate_content($form_state);
 191    }
 192    else {
 193      devel_batch_generate_content($form_state);
 194    }
 195  }
 196  
 197  function devel_generate_taxonomy_form() {
 198    $form['num_vocab'] = array(
 199      '#type' => 'textfield',
 200      '#title' => t('How many vocabularies would you like to generate?'),
 201      '#default_value' => 3,
 202      '#size' => 10,
 203    );
 204    $form['num_terms'] = array(
 205      '#type' => 'textfield',
 206      '#title' => t('How many terms would you like to generate?'),
 207      '#default_value' => 50,
 208      '#size' => 10,
 209    );
 210    $form['title_length'] = array(
 211      '#type' => 'textfield',
 212      '#title' => t('Max word length of term/vocab names'),
 213      '#default_value' => 12,
 214      '#size' => 10,
 215    );
 216    $form['kill_taxonomy'] = array(
 217      '#type' => 'checkbox',
 218      '#title' => t('Delete existing terms and vocabularies before generating new content.'),
 219      '#default_value' => FALSE,
 220    );
 221    $form['submit'] = array(
 222      '#type' => 'submit',
 223      '#value' => t('Do it!'),
 224    );
 225    return $form;
 226  }
 227  
 228  function devel_generate_taxonomy_form_submit($form_id, &$form_state) {
 229    require_once ('devel_generate.inc');
 230    devel_generate_taxonomy_data($form_state['values']['num_vocab'], $form_state['values']['num_terms'], $form_state['values']['title_length'], $form_state['values']['kill_taxonomy']);
 231  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7