condition('uid', 1, '>')->execute(); drupal_set_message(t('Users deleted.')); } // Determine if we should create user pictures. $pic_config = FALSE; module_load_include('inc', 'system', 'image.gd'); if (variable_get('user_pictures', 0) && function_exists('image_gd_check_settings') && image_gd_check_settings()) { $pic_config['path'] = variable_get('user_picture_path', 'pictures'); list($pic_config['width'], $pic_config['height']) = explode('x', variable_get('user_picture_dimensions', '85x85')); } if ($num > 0) { $names = array(); while (count($names) < $num) { $name = devel_generate_word(mt_rand(6, 12)); $names[$name] = ''; } foreach ($names as $name => $value) { $edit = array( 'name' => $name, 'pass' => user_password(), 'mail' => $name . '@' . $url['host'], 'status' => 1, 'created' => REQUEST_TIME - mt_rand(0, $age), 'roles' => drupal_map_assoc($roles), ); $account = user_save(NULL, $edit); if ($pic_config) { // Since the image.module should scale the picture just pick an // arbitrary size that it's too big for our font. $im = imagecreatetruecolor(200, 200); // Randomize the foreground using the md5 of the user id, then invert it // for the background color so there's enough contrast to read the text. $parts = array_map('hexdec', str_split(md5($account->uid), 2)); $fg = imagecolorallocate($im, $parts[1], $parts[3], $parts[5]); $bg = imagecolorallocate($im, 255 - $parts[0], 255 - $parts[1], 255 - $parts[2]); // Fill the background then print their user info. imagefill($im, 0, 0, $bg); imagestring($im, 5, 5, 5, "#" . $account->uid, $fg); imagestring($im, 5, 5, 25, $account->name, $fg); // Create an empty, managed file where we want the user's picture to // be so we can have GD overwrite it with the image. $picture_directory = variable_get('file_default_scheme', 'public') . '://' . variable_get('user_picture_path', 'pictures'); $destination = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $account->uid . '.png'); $file = file_save_data('', $destination); // GD doesn't like stream wrapped paths so convert the URI to a normal // file system path. if (isset($file) && $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri)) { imagepng($im, $wrapper->realpath()); } imagedestroy($im); // Clear the cached filesize, set the owner and MIME-type then re-save // the file. clearstatcache(); $file->uid = $account->uid; $file->filemime = 'image/png'; $file = file_save($file); // Save the user record with the new picture. $edit = (array) $account; $edit['picture'] = $file; user_save($account, $edit); } } } drupal_set_message(t('!num_users created.', array('!num_users' => format_plural($num, '1 user', '@count users')))); } /** * The main API function for creating content. * * See devel_generate_content_form() for the supported keys in $form_state['values']. * Other modules may participate by form_alter() on that form and then handling their data during hook_nodeapi('pre_save') or in own submit handler for the form. * * @param string $form_state * @return void */ function devel_generate_content($form_state) { if (!empty($form_state['values']['kill_content'])) { devel_generate_content_kill($form_state['values']); } if (count($form_state['values']['node_types'])) { // Generate nodes. devel_generate_content_pre_node($form_state['values']); for ($i = 1; $i <= $form_state['values']['num_nodes']; $i ++) { devel_generate_content_add_node($form_state['values']); } } drupal_set_message(format_plural($form_state['values']['num_nodes'], '1 node created.', '@count nodes created')); } function devel_generate_add_comments($node, $users, $max_comments, $title_length = 8) { $num_comments = mt_rand(1, $max_comments); for ($i = 1; $i <= $num_comments; $i++) { $comment->nid = $node->nid; $comment->cid = NULL; $comment->name = 'devel generate'; $comment->mail = 'devel_generate@example.com'; $comment->timestamp = mt_rand($node->created, REQUEST_TIME); switch ($i % 3) { case 1: $comment->pid = db_query_range("SELECT cid FROM {comment} WHERE pid = 0 AND nid = :nid ORDER BY RAND()", 0, 1, array(':nid' => $comment->nid))->fetchField(); break; case 2: $comment->pid = db_query_range("SELECT cid FROM {comment} WHERE pid > 0 AND nid = :nid ORDER BY RAND()", 0, 1, array(':nid' => $comment->nid))->fetchField(); break; default: $comment->pid = 0; } $comment->subject = devel_create_greeking(mt_rand(1, $title_length), TRUE); $comment->uid = $users[array_rand($users)]; $comment->language = LANGUAGE_NONE; // Populate all core fields on behalf of field.module module_load_include('inc', 'devel_generate', 'devel_generate.fields'); cck_generate_fields($comment, 'comment', 'comment_node_' . $node->type); comment_save($comment); } } function devel_generate_vocabs($records, $maxlength = 12, $types = array('page', 'article')) { $vocs = array(); // Insert new data: for ($i = 1; $i <= $records; $i++) { $voc = new stdClass(); $voc->name = devel_generate_word(mt_rand(2, $maxlength)); $voc->machine_name = drupal_strtolower($voc->name); $voc->description = "description of ". $voc->name; // TODO: not working $voc->nodes = array_flip(array($types[array_rand($types)])); foreach ($voc->nodes as $key => $value) { $voc->nodes[$key] = $key; } $voc->multiple = 1; $voc->required = 0; $voc->relations = 1; $voc->hierarchy = 1; $voc->weight = mt_rand(0,10); taxonomy_vocabulary_save($voc); $vocs[] = $voc->name; unset($voc); } return $vocs; } function devel_generate_terms($records, $vocs, $maxlength = 12) { $terms = array(); // Insert new data: for ($i = 1; $i <= $records; $i++) { $term = new stdClass(); switch ($i % 2) { case 1: $term->vid = $vocs[array_rand($vocs)]; // dont set a parent. handled by taxonomy_save_term() // $term->parent = 0; break; case 2: default: $parent = db_query_range("SELECT t.tid, v.vid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid ORDER BY RAND()", 0, 1)->fetchObject(); $term->parent = array($parent->tid); $term->vid = $parent->vid; break; } $term->name = devel_generate_word(mt_rand(2, $maxlength)); $term->description = "description of ". $term->name; $term->weight = mt_rand(0,10); $status = taxonomy_term_save($term); $output = NULL; if ($status) { $terms[] = $term->name; } unset($term); } return $terms; } function devel_generate_get_vocabs() { $vocs = array(); return db_query("SELECT vid FROM {taxonomy_vocabulary}")->fetchCol(); } function devel_generate_taxonomy_data($num_vocab, $num_terms, $title_length, $kill) { if ($kill) { foreach (taxonomy_get_vocabularies() as $vid => $vocab) { taxonomy_vocabulary_delete($vid); } drupal_set_message(t('Deleted existing vocabularies and terms.')); } $new_vocs = devel_generate_vocabs($num_vocab, $title_length); if (!empty($new_vocs)) { drupal_set_message(t('Created the following new vocabularies: !vocs', array('!vocs' => theme('item_list', array('items' => $new_vocs))))); } $vocs = devel_generate_get_vocabs(); $new_terms = devel_generate_terms($num_terms, $vocs, $title_length); if (!empty($new_terms)) { drupal_set_message(t('Created the following new terms: !terms', array('!terms' => theme('item_list', array('items' => $new_terms))))); } } function devel_generate_word($length){ mt_srand((double)microtime()*1000000); $vowels = array("a", "e", "i", "o", "u"); $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl", "sh"); $num_vowels = count($vowels); $num_cons = count($cons); $word = ''; while(strlen($word) < $length){ $word .= $cons[mt_rand(0, $num_cons - 1)] . $vowels[mt_rand(0, $num_vowels - 1)]; } return substr($word, 0, $length); } function devel_create_content($type = NULL) { $nparas = mt_rand(1,12); $type = empty($type) ? mt_rand(0,3) : $type; $output = ""; switch($type % 3) { case 1: // html for ($i = 1; $i <= $nparas; $i++) { $output .= devel_create_para(mt_rand(10,60),1); } break; case 2: // brs only for ($i = 1; $i <= $nparas; $i++) { $output .= devel_create_para(mt_rand(10,60),2); } break; default: // plain text for ($i = 1; $i <= $nparas; $i++) { $output .= devel_create_para(mt_rand(10,60)) ."\n\n"; } } return $output; } function devel_create_para($words, $type = 0) { $output = ""; switch ($type) { case 1: $output .= "
"; $output .= devel_create_greeking($words); $output = trim($output) ."
"; break; case 2: $output .= devel_create_greeking($words); $output = trim($output) ."