Index: views_calc_field_handler.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/views_calc/views_calc_field_handler.inc,v
retrieving revision 1.3
diff -u -r1.3 views_calc_field_handler.inc
--- views_calc_field_handler.inc	21 Apr 2009 12:15:28 -0000	1.3
+++ views_calc_field_handler.inc	18 Oct 2010 18:29:03 -0000
@@ -80,18 +80,22 @@
     $value = $values->$field_alias;
     $formats = _views_calc_format_options();
     $format = $formats[$this->definition['format']];
-    $tmp = explode(':', $format);
-    $function = trim($tmp[0]);
-    $vars     = count($tmp) == 2 ? $tmp[1] : '';
-    if ($function == 'custom') {
-      $tmp = explode(':', $this->definition['custom']);
-      $function = trim($tmp[0]);
-      $vars     = count($tmp) == 2 ? $tmp[1] : '';
+    $vars = explode(':', $format);
+    $function = trim($vars[0]);
+    $vars[0]  = $value;
+    if ($this->definition['format'] == 'php'){
+      $raw = _views_calc_render_php($value, $this->definition['custom']);
+    } else {
+      if ($this->definition['format'] == 'custom') {
+        $vars = explode(':', $this->definition['custom']);
+        $function = trim($vars[0]);
+        $vars[0]  = $value;
+      }
+      if (empty($function) || $function == 'none') {
+        $function = 'check_plain';
+      }
+      $raw = call_user_func_array($function, $vars);
     }
-    if (empty($function) || $function == 'none') {
-      $function = 'check_plain';
-    }
-    $raw = $function($value, $vars);
 
     // This needs to be set for the $this->render_link() to work. It would
     // have been set in the query, if we hadn't bypassed the normal query.
@@ -100,4 +104,14 @@
 
     return $this->render_link($raw, $values);
   }
+}
+
+/**
+ * Executes php $code and returns the new $value.
+ * It's defined outside the class in order to avoid access to $this.
+ * Only $value and $code (and global/superglobal variables...) are available in $code
+ */
+function _views_calc_render_php($value, $code){
+  eval($code);
+  return $value;
 }
\ No newline at end of file
Index: views_calc.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/views_calc/views_calc.module,v
retrieving revision 1.14
diff -u -r1.14 views_calc.module
--- views_calc.module	13 Jun 2009 12:57:40 -0000	1.14
+++ views_calc.module	18 Oct 2010 18:29:03 -0000
@@ -71,6 +71,7 @@
     'mediumdate' => 'format_date',
     'longdate' => 'format_date:large',
     'custom' => '',
+    'php' => '',
     );
   return $options;
 }
@@ -260,10 +261,10 @@
     '#description' => t('The format of the result of this calculation.'),
     );
   $form['group'][$i]['custom'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Custom function'),
+    '#type' => 'textarea',
+    '#title' => t('Custom function or code'),
     '#default_value' => $field['custom'],
-    '#description' => t('The function to call for a custom format.'),
+    '#description' => t('The function to call for a custom format, or the php code to execute. For "custom", use the format "function_name:param1:param2..." and it will call "function_name($value,param1,param2...)". For "php", use variable "$value" to get and update the field content. Please note that the limit is 255 characters.'),
     );
   return $form;
 }
