Index: mm_custom_command.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mm_custom_command/mm_custom_command.module,v
retrieving revision 1.2
diff -u -p -r1.2 mm_custom_command.module
--- mm_custom_command.module	21 Apr 2009 14:44:46 -0000	1.2
+++ mm_custom_command.module	15 Apr 2010 14:10:49 -0000
@@ -4,6 +4,9 @@
 define(MM_CUSTOM_COMMAND_PROCESS, 1);
 define(MM_CUSTOM_COMMAND_STORAGE, 2);
 define(MM_CUSTOM_COMMAND_COMPLETE, 3);
+define(MM_CUSTOM_COMMAND_PHP_PROCESS, 4);
+define(MM_CUSTOM_COMMAND_PHP_STORAGE, 5);
+define(MM_CUSTOM_COMMAND_PHP_COMPLETE, 6);
 
 /**
  * @file
@@ -25,12 +28,15 @@ function mm_custom_command_media_mover($
       return array(
         'process' => array(
           MM_CUSTOM_COMMAND_PROCESS => t('Use custom command'),
+          MM_CUSTOM_COMMAND_PHP_PROCESS => t('Use custom PHP code'),
         ),
         'storage' => array(
           MM_CUSTOM_COMMAND_STORAGE => t('Use custom command'),
+          MM_CUSTOM_COMMAND_PHP_STORAGE => t('Use custom PHP code'),
         ),
         'complete' => array(
           MM_CUSTOM_COMMAND_COMPLETE => t('Use custom command'),
+          MM_CUSTOM_COMMAND_PHP_COMPLETE => t('Use custom PHP code'),
         ),
       );
     break;
@@ -38,13 +44,14 @@ function mm_custom_command_media_mover($
     case 'config':
       switch ($action) {
         case MM_CUSTOM_COMMAND_PROCESS:
-          return mm_custom_command_config($action, $configuration, 'process');
-        break;
         case MM_CUSTOM_COMMAND_STORAGE:
-          return mm_custom_command_config($action, $configuration, 'storage');
-        break;
         case MM_CUSTOM_COMMAND_COMPLETE:
-          return mm_custom_command_config($action, $configuration, 'complete');
+          return mm_custom_command_config($action, $configuration);
+        break;
+        case MM_CUSTOM_COMMAND_PHP_PROCESS:
+        case MM_CUSTOM_COMMAND_PHP_STORAGE:
+        case MM_CUSTOM_COMMAND_PHP_COMPLETE:
+          return mm_custom_command_php_config($action, $configuration);
         break;
       }
     break;
@@ -53,7 +60,10 @@ function mm_custom_command_media_mover($
     case 'process':
       switch ($action) {
         case MM_CUSTOM_COMMAND_PROCESS:
-          return mm_custom_command_action($action, $configuration, $file, 'process');
+          return mm_custom_command_action($action, $configuration, $file);
+        break;
+        case MM_CUSTOM_COMMAND_PHP_PROCESS:
+          return mm_custom_command_php_action($action, $configuration, $file);
         break;
       }
     break;
@@ -62,7 +72,10 @@ function mm_custom_command_media_mover($
     case 'storage':
       switch ($action) {
         case MM_CUSTOM_COMMAND_STORAGE:
-          return mm_custom_command_action($action, $configuration, $file, 'storage');
+          return mm_custom_command_action($action, $configuration, $file);
+        break;
+        case MM_CUSTOM_COMMAND_PHP_STORAGE:
+          return mm_custom_command_php_action($action, $configuration, $file);
         break;
       }
     break;
@@ -71,7 +84,10 @@ function mm_custom_command_media_mover($
     case 'complete':
       switch ($action) {
         case MM_CUSTOM_COMMAND_COMPLETE:
-          return mm_custom_command_action($action, $configuration, $file, 'complete');
+          return mm_custom_command_action($action, $configuration, $file);
+        break;
+        case MM_CUSTOM_COMMAND_PHP_COMPLETE:
+          return mm_custom_command_php_action($action, $configuration, $file);
         break;
       }
     break;
@@ -82,7 +98,8 @@ function mm_custom_command_media_mover($
 /**
  * Configuration for $verb action
  */
-function mm_custom_command_config($action, $configuration, $verb) {
+function mm_custom_command_config($action, $configuration) {
+  $verb = $configuration['verb'];
   // set title for current action
   $title = array(
     'process' => t('Process Configuration'),
@@ -125,9 +142,55 @@ function mm_custom_command_config($actio
 }
 
 /**
+ * Configuration for $verb php action
+ */
+function mm_custom_command_php_config($action, $configuration) {
+  $verb = $configuration['verb'];
+  // set title for current action
+  $title = array(
+    'process' => t('Process Configuration'),
+    'storage' => t('Storage Configuration'),
+    'complete' => t('Complete Configuration'),
+  );
+
+  $form = array();
+  $form['mm_'. $verb .'_conf'] = array(
+    '#type' => 'fieldset',
+    '#title' => $title[$verb],
+    '#description' => t('This module runs custom command'),
+  );
+
+  $form['mm_'. $verb .'_conf']['output_file'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Output file'),
+    '#description' => t('Define output file.'),
+    '#default_value' => $configuration['output_file'],
+  );
+  $form['mm_'. $verb .'_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' => $configuration['php'],
+  );
+  if (module_exists('token')) {
+    $form['mm_'. $verb .'_conf']['token_help'] = array(
+      '#title' => t('Replacement patterns'),
+      '#type' => 'fieldset',
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['mm_'. $verb .'_conf']['token_help']['help'] = array(
+      '#value' => theme('token_help', 'mm_file'),
+    );
+  }
+
+  return $form;
+}
+
+/**
  * Run custom command
  */
-function mm_custom_command_action($action, $configuration, $file, $verb) {
+function mm_custom_command_action($action, $configuration, $file) {
   // replace tokens
   $output_file = token_replace($configuration['output_file'], 'mm_file', $file);
   $command = token_replace($configuration['command'], 'mm_file', $file);
@@ -141,4 +204,15 @@ function mm_custom_command_action($actio
   ob_end_clean();
 
   return $output_file;
+}
+
+/**
+ * Run custom command
+ */
+function mm_custom_command_php_action($action, $configuration, $file) {
+  // replace tokens
+  $output_file = token_replace($configuration['output_file'], 'mm_file', $file);
+
+  eval($command);
+  return $output_file;
 }
\ No newline at end of file
