array( 'menu', 'theme', 'flush_caches', ), 'reorder' => TRUE, 'source' => '@^(.*)\.module$@', 'target' => '@name.registry.inc', 'header' => ' array( '[^(]*action[^(]*', 'mail', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.actions.inc', 'header' => ' array( 'perm', 'user_after_update', 'user_cancel', 'user_categories', 'user_form', 'user_login', 'user_insert', 'user_operations[^(]*', 'user_register', 'user_submit', 'user_update', 'user_timezone', # system only 'user_validate', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.user.inc', 'header' => ' array( 'block_list', 'block_configure', 'block_save', ), 'reorder' => TRUE, 'source' => '@^(.*)\.module$@', 'target' => '@name.block.inc', 'header' => ' array( 'node_access_records', 'node_delete', 'node_delete_revision', 'node_insert', 'node_prepare', 'node_presave', 'node_type', 'node_update', 'node_validate', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.node.inc', 'header' => ' array( 'comment_delete', 'comment_insert', 'comment_publish', 'comment_unpublish', 'comment_update', 'comment_validate', 'comment_view', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.comment.inc', 'header' => ' array( 'taxonomy', // @todo Lonely left over. 'taxonomy_term_insert', 'taxonomy_term_update', 'taxonomy_term_delete', 'taxonomy_vocabulary_insert', 'taxonomy_vocabulary_update', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.taxonomy.inc', 'header' => ' array( 'node_update_index', 'ranking', 'search', 'search_preprocess', 'search_page', 'update_index', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.search.inc', 'header' => ' array( 'cron', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.cron.inc', 'header' => ' array( 'xmlrpc', // Blog API 'blogger_[^(]*', 'metaweblog_[^(]*', 'mt_[^(]*', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.xmlrpc.inc', 'header' => ' array( 'form_[^(]*_alter', ), 'source' => '@^(.*)\.module$@', 'target' => '@name.form.inc', 'header' => ' array( // 'form', // 'form_(?!alter)[^(]*', // ), // 'source' => '@^(comment)\.module$@', // 'target' => '@name.form.inc', // 'header' => 'filename); // Skip error_test.module due to hard-coded line numbers for expected // exceptions. if ($module == 'error_test') { continue; } $newfile = (object) array( 'filepath' => dirname($file->filepath) . '/' . strtr($rewrite['target'], array('@name' => $module)), 'filename' => strtr($rewrite['target'], array('@name' => $module)), ); echo "$file->filepath => $newfile->filepath\n"; // Fetch the source file content. $content = file_get_contents($file->filepath); // Retrieve code to move. $remove = array(); if (empty($rewrite['reorder'])) { $rewrite['hooks'] = array(implode('|', $rewrite['hooks'])); } foreach ($rewrite['hooks'] as $hook) { // Dunno why, but this only matches 1 function. Who cares, while() helps. 21/05/2009 sun $s = '@ (?:^/\*\*(?:(?!\*\*).)+?\*/\s+)? # Optional PHPDoc ^function\ ' . $module . '_(?:' . $hook . ')\(.*?\) # Function name + arguments (?:(?!^\}).)+? # Function body ^\} # Closing function body \s+ # White-space to next function @smx'; while (preg_match($s, $content, $matches) && !empty($matches[0])) { $remove[] = $matches[0]; $content = str_replace($matches[0], '', $content); } } if (!empty($remove)) { // Write target file. $newcontent = ''; if (file_exists($newfile->filepath)) { $flags = FILE_APPEND; } else { $flags = 0; $newcontent = strtr($rewrite['header'], array('@title' => ucfirst($module))); } $newcontent .= implode('', $remove); file_put_contents($newfile->filepath, $newcontent, $flags); // Remove code from source file. file_put_contents($file->filepath, $content); // Add target file to .info file. $infofile = dirname($file->filepath) . '/' . $module . '.info'; if (file_exists($infofile)) { $info_content = file_get_contents($infofile); if (strpos($info_content, $newfile->filename) === FALSE) { file_put_contents($infofile, 'files[] = ' . $newfile->filename . "\n", FILE_APPEND); } } // Add target file to CVS. $CVS = dirname($file->filepath) . '/CVS/Entries'; if (file_exists($CVS)) { $CVS_content = file_get_contents($CVS); if (strpos($CVS_content, $newfile->filename) === FALSE) { file_put_contents($CVS, '/' . $newfile->filename . "/0/Initial import.//\n", FILE_APPEND); } } } } }