atrcode.module

<?php
// $Id: atrcode.module,v 1.1.2.2 2009/08/19 10:42:40 xano Exp $

/**
 * @file
 *   Hook implementations and general funcions.
 */

/**
 * Implementation of hook_atr_source_info().
 */
function atrcode_atr_source_info() {
  return array(
    'atrcode' => t('Drupal code files'),
  );
}

/**
 * Implementation of hook_form_FORM_ID_alter().
 */
function atrcode_form_atr_form_review_alter(&$form, &$form_state) {
  array_unshift($form['#submit'], 'atrcode_atr_form_review_submit');
  $form['atrcode']['settings']['atrcode_files'] = array(
    '#type' => 'atr_file',
    '#title' => t('Files'),
    '#default_value' => NULL,
  );
  $form['atrcode']['settings']['atrcode_api_version'] = array(
    '#type' => 'select',
    '#title' => t('API version'),
    '#options' => array(
      5 => 'Drupal 5',
      6 => 'Drupal 6',
      7 => 'Drupal 7',
    ),
  );
}

/**
 * Form submit handler for atr_form_review().
 */
function atrcode_atr_form_review_submit($form, &$form_state) {
  $values = $form_state['values'];
  if ($values['atrcode_toggle']) {
    module_load_include('inc', 'atrcode', 'includes/atrcode.extract');
    foreach ($values['atrcode_files'] as $path) {
      atrcode_extract($path, $values['atrcode_api_version']);
      atr_rmdir($path);
    }
  }
}