t('Custom: Use custom command.'), 'callback' => 'mm_custom_command_action', 'configuration' => 'mm_custom_command_config', ); $items['custom_php_command'] = array( 'description' => t('Custom: Use custom PHP code.'), 'callback' => 'mm_custom_command_php_action', 'configuration' => 'mm_custom_command_php_config', ); //all others needed? return $items; } function mm_custom_command_config($step) { //$verb = $step->settings['verb']; // set title for current action $form = array(); $form['mm_custom_command_conf'] = array( '#type' => 'fieldset', '#title' => 'Custom Command Configuration', '#description' => t('This module runs custom command'), ); $form['mm_custom_command_conf']['output_file'] = array( '#type' => 'textfield', '#title' => t('Output file'), '#description' => t('Define output file.'), '#default_value' => $step->settings['output_file'], ); $form['mm_custom_command_conf']['command'] = array( '#type' => 'textfield', '#title' => t('Command'), '#description' => t("Define command for this action. If you want to use 'Output file' value from previous field use [output_file]."), '#default_value' => $step->settings['command'], ); if (module_exists('token')) { $form['mm_custom_command_conf']['token_help'] = array( '#title' => t('Replacement patterns'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['mm_custom_command_conf']['token_help']['help'] = array( '#value' => theme('token_help', 'mm_file'), ); } return $form; } /** * Configuration for $verb php action */ function mm_custom_command_php_config($step) { $form = array(); $form['mm_custom_command_conf'] = array( '#type' => 'fieldset', '#title' => 'Custom Command Configuration', '#description' => t('This module runs custom command'), ); $form['mm_custom_command_conf']['output_file'] = array( '#type' => 'textfield', '#title' => t('Output file'), '#description' => t('Define output file.'), '#default_value' => $step->settings['output_file'], ); $form['mm_custom_command_conf']['php'] = array( '#type' => 'textarea', '#title' => t('PHP code'), '#description' => t("Define PHP code. Do not use php tags. If you want to use 'Output file' value from previous field use \$output_file. You can also use \$file['harvest_file'], \$file['process_file'], \$file['storage_file']."), '#default_value' => $step->settings['php'], ); if (module_exists('token')) { $form['mm_custom_command_conf']['token_help'] = array( '#title' => t('Replacement patterns'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['mm_custom_command_conf']['token_help']['help'] = array( '#value' => theme('token_help', 'mm_file'), ); } return $form; } /** * Run custom command */ function mm_custom_command_action($step, $file) { // replace tokens $output_file = token_replace($step->settings['output_file'], 'mm_file', $file); $command = token_replace($step->settings['command'], 'mm_file', $file); // change [output_file] to value from $output_file $command = str_replace('[output_file]', $output_file, $command); ob_start(); passthru($command ." 2>&1", $command_return); $command_output = ob_get_contents(); ob_end_clean(); return $output_file; } /** * Run custom command */ function mm_custom_command_php_action($step, $file) { // replace tokens $output_file = token_replace($step->settings['output_file'], 'mm_file', $file); eval($command); return $output_file; }