Index: components/system.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/patterns/components/system.inc,v
retrieving revision 1.1.2.2.2.13
diff -u -r1.1.2.2.2.13 system.inc
--- components/system.inc	28 Jul 2009 09:10:06 -0000	1.1.2.2.2.13
+++ components/system.inc	29 Sep 2009 20:48:15 -0000
@@ -6,7 +6,7 @@
   switch($op) {
     // Return the valid tags that this component can prepare and process
     case 'tags':
-      return array('modules', 'form', 'variables', 'variable', 'theme');
+      return array('modules', 'form', 'variables', 'variable', 'theme', 'call_php_func');
     break;
 
     // Return a list of forms/actions this component can handle
@@ -16,7 +16,8 @@
         'variables' => t('System: Set or delete variables'),
         'variable' => t('System: Set or delete variable'),
         'system_themes_form' => t('System: Set active theme'),
-        'form' => t('System: Execute form')
+        'form' => t('System: Execute form'),
+        'call_php_func_form' => t('Call PHP function: Call function'),
       );
     break;
 
@@ -55,6 +56,9 @@
         case 'form':
           return t('Executing form: %name', array('%name' => $data['form_id']));
         break;
+        case 'call_php_func_form':
+          return t('Calling PHP function %func', array('%pattern' => $data['func']));
+        break;
       }
     break;
 
@@ -162,6 +166,8 @@
             }
           }
         break;
+        case 'call_php_func_form':
+        break;
       }
     break;
 
@@ -225,6 +231,20 @@
           return t("Couldn't load the form %form. Check if all required modules are enabled and try to define 'include' or 'module' for this action.", array('%form' => $data['form_id']));
       	}
       }
+      else if ($id == 'call_php_func') {
+        if (empty($data['function'])) {
+          return t("A function is required for this tag");
+        }
+        else if (!empty($data['type']) && empty($data['module'])) {
+          return t("If you specify a type you must specify a module. See the documentation for module_load_include.");
+        }
+        else if (empty($data['type']) && !empty($data['module'])) {
+          return t("If you specify a module you must specify a type. See the documentation for module_load_include.");
+        }
+        else if (!empty($data['filepath']) && !file_exists($data['filepath'])) {
+          return t('The file that you specified does not exist: %file', array('%file' => $data['filepath']));
+        }
+      }
     break;
 
     // Return the form_id('s) for each action
@@ -253,6 +273,9 @@
         }
       	return $data['form_id'];
       }
+      else if ($id == 'call_php_func') {
+        return 'call_php_func_form';
+      }
     break;
 
     // Prepare for valid processing of this type of component
@@ -327,15 +350,38 @@
         }
         return $form_state;
       }
+      else if ($id == 'call_php_func') {
+        $data['type'] = empty($data['type']) ? '' : $data['type'];
+        $data['module'] = empty($data['module']) ? '' : $data['module'];
+        $data['name'] = empty($data['name']) ? '' : $data['name'];
+        $data['filepath'] = empty($data['filepath']) ? '' : $data['filepath'];
+        
+        if (empty($data['arguments'])) {
+          $data['arguments'] = array();
+        }
+        else if (!is_array($data['arguments'])) {
+          $data['arguments'] = array($data['arguments']);
+        }
+      return $data;
+      }
     break;
 
     // Validate the values for an action before running the pattern
     case 'validate':
+      if ($id == 'call_php_func_form') {
+         _call_php_func_include_files($data);
+        if (!is_callable($data['function'])) {
+          return t('The given function %func is not callable', array('%func' => $data['function']));
+        }
+      }
     break;
 
     // Build a patterns actions and parameters
     case 'params':
-      if ($id == $data['form_id'] && isset($data['args'])) {
+      if ($id == 'call_php_func_form') {
+        return array($data['function'], $data['type'], $data['module'], $data['name'], $data['filepath'], $data['arguments']);
+      }
+      else if ($id == $data['form_id'] && isset($data['args'])) {
         $params = $data['args'];
         unset($data['args']);
         return $params;
@@ -350,3 +396,31 @@
     break;
   }
 }
+
+function call_php_func_form($form_state, $func, $type, $module, $name, $filepath, $args) {
+  return array(
+    '#call_php_func' => array(
+      'function' => $func,
+      'type' => $type,
+      'module' => $module,
+      'name' => $name,
+      'filepath' => $filepath,
+      'arguments' => $args,
+    ),
+  );
+}
+
+function call_php_func_form_submit($form, &$form_state) {
+  $values = $form['#call_php_func'];
+  _call_php_func_include_files($values);
+  call_user_func_array($values['function'], $values['arguments']);
+}
+
+function _call_php_func_include_files($values) {
+  if ($values['type'] && $values['module']) {
+    module_load_include($values['type'], $values['module'], $values['name']);
+  }
+  else if($values['filepath']) {
+    require_once($values['filepath']);
+  }
+}
\ No newline at end of file
