function coder_page_form in Coder 5
Same name and namespace in other branches
- 5.2 coder.module \coder_page_form()
- 6.2 coder.module \coder_page_form()
- 6 coder.module \coder_page_form()
1 string reference to 'coder_page_form'
- coder_page in ./
coder.module - Implementation of code review page
File
- ./
coder.module, line 436 - Developer Module that assists with code review and version upgrade that supports a plug-in extensible hook system so contributed modules can define additional review standards.
Code
function coder_page_form() {
// HELP: is there a better way to get these from coder_page_form_submit()???
$form_values = $_POST;
if (isset($form_values['op'])) {
$settings = $form_values;
$settings['coder_modules'] = _coder_settings_array($form_values, 'module');
$settings['coder_themes'] = _coder_settings_array($form_values, 'theme');
drupal_set_title(t('Code review (submitted options)'));
}
else {
$options = arg(1);
$settings = _coder_get_default_settings($options);
if ($options) {
drupal_set_title(t('Code review (@options)', array(
'@options' => isset($options) ? $options : 'default options',
)));
}
}
// get this once - list of the reviews to perform
$reviews = array();
$avail_reviews = _coder_reviews();
$selected_reviews = $settings['coder_reviews'];
foreach ($selected_reviews as $name => $checked) {
if ($checked) {
$reviews[$name] = $avail_reviews[$name];
}
}
if ($coder_form = _coder_settings_form($settings, $system, $files)) {
// add style sheet
$path = drupal_get_path('module', 'coder');
drupal_add_css($path . '/coder.css', 'module');
// code review non-module core files
$module_weight = 0;
if (isset($settings['coder_core']) && $settings['coder_core']) {
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
);
$form['core_php'] = array(
'#type' => 'fieldset',
'#title' => 'core (php)',
'#collapsible' => true,
'#collapsed' => true,
'#weight' => ++$module_weight,
);
$phpfiles = file_scan_directory('.', '.*\\.php', array(
'.',
'..',
'CVS',
), 0, false, 'name', 0);
_coder_page_form_includes($form, $coder_args, 'core_php', $phpfiles, 2);
$form['core_includes'] = array(
'#type' => 'fieldset',
'#title' => 'core (includes)',
'#collapsible' => true,
'#collapsed' => true,
'#weight' => ++$module_weight,
);
$includefiles = drupal_system_listing('.*\\.inc$', 'includes', 'name', 0);
_coder_page_form_includes($form, $coder_args, 'core_includes', $includefiles, 0);
}
// loop through the selected modules and themes
if (isset($system)) {
$dups = array();
// used to avoid duplicate includes
$stats = array();
foreach ($system as $name => $checked) {
if ($checked) {
// process this one file
$filename = $files[$name];
if (!$filename) {
drupal_set_message(t('Code Review file for %module not found', array(
'%module' => $name,
)));
continue;
}
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
'#filename' => $filename,
);
$results = do_coder_reviews($coder_args);
$stats[$filename] = $results['#stats'];
unset($results['#stats']);
// output the results in a collapsible fieldset
$form[$name] = array(
'#type' => 'fieldset',
'#title' => $filename,
'#collapsible' => true,
'#collapsed' => true,
'#weight' => ++$module_weight,
);
if (empty($results)) {
$results[] = t('No Problems Found');
}
else {
$form[$name]['#collapsed'] = false;
}
$form[$name]['output'] = array(
'#value' => theme('coder', $name, $filename, $results),
'#weight' => -1,
);
// process the same directory include files
if ($settings['coder_includes']) {
// NOTE: convert to the realpath here so drupal_system_listing
// doesn't return additional paths (i.e., try "module").
$path = str_replace('\\', '/', dirname(realpath($filename)));
$offset = strpos($path, dirname($filename));
if (!isset($dups[$path])) {
if (substr($filename, -7) == '.module') {
$coder_args['#php_minor'] = 1;
}
$dups[$path] = 1;
$includefiles = drupal_system_listing('.*\\.(inc|php|install|schema)$', $path, 'name', 0);
$stats[$filename]['#includes'] = _coder_page_form_includes($form, $coder_args, $name, $includefiles, $offset);
}
}
}
}
if (count($stats)) {
$summary = array(
'files' => 0,
'minor' => 0,
'normal' => 0,
'critical' => 0,
);
foreach ($stats as $stat) {
if (isset($stat['#includes'])) {
foreach ($stat['#includes'] as $includestat) {
$summary['files']++;
$summary['minor'] += $includestat['minor'];
$summary['normal'] += $includestat['normal'];
$summary['critical'] += $includestat['critical'];
}
}
$summary['files']++;
}
$display = array();
$display[] = t('Coder found @count projects', array(
'@count' => count($stats),
));
$display[] = t('@count files', array(
'@count' => $summary['files'],
));
foreach (array(
'critical',
'normal',
'minor',
) as $severity_name) {
if ($summary[$severity_name] > 0) {
$display[] = t('@count %severity_name warnings', array(
'@count' => $summary[$severity_name],
'%severity_name' => $severity_name,
));
}
}
drupal_set_message(implode(', ', $display));
}
}
// prepend the settings form
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Selection Form'),
'#collapsible' => true,
'#collapsed' => isset($form),
'#weight' => -1,
);
if ($form['settings']['#collapsed']) {
$form['settings']['#prefix'] = t('<div class="coder-settings">Use the Selection Form to select options for this code review, or change the <a href="@settings">Default Settings</a> and use the <a href="@default">Default</a> tab above.</div>', array(
'@settings' => url('admin/settings/coder'),
'@default' => url('coder/default'),
));
}
$form['settings'][] = $coder_form;
$form['settings']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['#action'] = url('coder');
}
return $form;
}