Index: rules/modules/system.rules.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/rules/rules/modules/Attic/system.rules.inc,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 system.rules.inc
--- rules/modules/system.rules.inc	20 Jul 2009 16:22:24 -0000	1.1.2.17
+++ rules/modules/system.rules.inc	5 Aug 2009 01:09:20 -0000
@@ -9,6 +9,40 @@
  * @{
  */
 
+define('RULES_FILE_LOAD', 'SELECT fid,uid,filename,filepath,filemime,filesize,status,timestamp FROM {files} WHERE fid = %d');
+
+/**
+ * Returns some arguments suitable for using it with a file
+ */
+function rules_events_file_arguments($file_label, $author_label, $update = FALSE) {
+  $args = array(
+    'file' => array(
+      'type' => 'file',
+      'label' => $file_label,
+    ),
+    'author' => array(
+      'type' => 'user',
+      'label' => $author_label,
+      'handler' => 'rules_events_argument_file_author',
+    ),
+  );
+  if ($update) {
+    $args += array(
+      'file_unchanged' => array(
+        'type' => 'file',
+        'label' => t('unchanged file'),
+        'handler' => 'rules_events_argument_file_unchanged',
+      ),
+      'author_unchanged' => array(
+        'type' => 'user',
+        'label' => t("unchanged file's author"),
+        'handler' => 'rules_events_argument_unchanged_file_author',
+      ),
+    );
+  }
+  return $args + rules_events_global_user_argument();
+}
+
 /**
  * Implementation of hook_rules_event_info().
  */
@@ -72,9 +106,98 @@ function system_rules_action_info() {
       'module' => 'System',
       'eval input' => array('type', 'message', 'link'),
     ),
+    'rules_action_file_set_author' => array(
+      'label' => t('Set the file author'),
+      'arguments' => array(
+        'file' => array('type' => 'file', 'label' => t('File')),
+        'author' => array('type' => 'user', 'label' => t('User, who is set as author')),
+      ),
+      'module' => 'System',
+    ),
+    'rules_action_file_load_author' => array(
+      'label' => t('Load the file author'),
+      'arguments' => array(
+        'file' => array('type' => 'file', 'label' => t('File')),
+      ),
+      'new variables' => array(
+        'author' => array(
+          'type' => 'user',
+          'label' => t('File author'),
+          'label callback' => 'rules_action_file_load_author_variable_label',
+        ),
+      ),
+      'module' => 'System',
+    ),
+    'rules_action_load_file' => array(
+      'label' => t('Load file by id'),
+      'arguments' => array(
+        'fid' => array('type' => 'number', 'label' => t('File ID')),
+      ),
+      'new variables' => array(
+        'file_loaded' => array(
+          'type' => 'file',
+          'label' => t('Loaded file'),
+          'label callback' => 'rules_action_load_file_variable_label',
+        ),
+      ),
+      'module' => 'System',
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_rules_condition_info()
+ */
+function system_rules_condition_info() {
+  $items = array();
+  $defaults = array(
+    'arguments' => array(
+      'file' => array('type' => 'file', 'label' => t('File')),
+    ),
+    'module' => 'System',
+  );
+  $items['rules_condition_file_is_type'] = $defaults + array(
+    'label' => t('File has type'),
+    'help' => t('Evaluates to TRUE, if the given file has one of the selected file types.'),
+  );
+  return $items;
+}
+
+/**
+ * Implementation of hook_rules_data_type_info()
+ */
+function system_rules_data_type_info() {
+  return array(
+    'file' => array(
+      'label' => t('File'),
+      'class' => 'rules_data_type_file',
+      'savable' => TRUE,
+      'identifiable' => TRUE,
+    ),
   );
 }
 
+/**
+ * Defines the file type
+ */
+class rules_data_type_file extends rules_data_type {
+  function save() {
+    $file = &$this->get();
+    drupal_write_record('files', $file);
+    return TRUE;
+  }
+
+  function load($fid) {
+    return db_fetch_object(db_query(RULES_FILE_LOAD, $fid));
+  }
+
+  function get_identifier() {
+    $file = &$this->get();
+    return $file->fid;
+  }
+}
+
+
 function rules_action_drupal_message($settings) {
   drupal_set_message($settings['message'], $settings['error'] ? 'error' : 'status');
 }
@@ -119,6 +242,39 @@ function rules_action_mail_to_user($user
 }
 
 /**
+ * Gets the author's account of a file
+ */
+function rules_events_argument_file_author($file) {
+  return user_load(array('uid' => $file->uid));
+}
+
+/**
+ * Gets the file object, that doesn't contain the modified changes
+ */
+function rules_events_argument_file_unchanged($file) {
+  return $file->fid ? db_fetch_object(db_query(RULES_FILE_LOAD, $file->fid)) : $file;
+}
+
+/**
+ * Gets the author of the unchanged file object
+ */
+function rules_events_argument_unchanged_file_author($file) {
+  return rules_events_argument_file_author(rules_events_argument_file_unchanged($file));
+}
+
+/**
+ * Condition: Check for selected file types
+ */
+function rules_condition_file_is_type(&$file, $settings) {
+  static $regexps;
+
+  if (!isset($regexps[$settings['filemime']])) {
+    $regexps[$settings['filemime']] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/'), array('|', '.*'), preg_quote($settings['filemime'], '/')) .')$/';
+  }
+  return preg_match($regexps[$settings['filemime']], $file->filemime);
+}
+
+/**
  * Implementation of hook_mail().
  *
  * Set's the message subject and body as configured in the $settings of the action.
@@ -218,5 +374,27 @@ function rules_action_watchdog($settings
 }
 
 /**
+ * Modifies a file as configured
+ */
+function rules_action_file_set_author($file, $author) {
+  $file->uid = $author->uid;
+  return array('file' => $file);
+}
+
+/**
+ * Loads the file author
+ */
+function rules_action_file_load_author($file) {
+  return array('author' => user_load($file->uid));
+}
+
+/**
+ * Loads a file
+ */
+function rules_action_load_file($fid) {
+  return array('file_loaded' => db_fetch_object(db_query(RULES_FILE_LOAD, $fid)));
+}
+
+/**
  * @}
  */
Index: rules/modules/system.rules_forms.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/rules/rules/modules/Attic/system.rules_forms.inc,v
retrieving revision 1.1.2.11
diff -u -p -r1.1.2.11 system.rules_forms.inc
--- rules/modules/system.rules_forms.inc	31 Jul 2009 10:21:43 -0000	1.1.2.11
+++ rules/modules/system.rules_forms.inc	5 Aug 2009 01:09:21 -0000
@@ -194,5 +194,18 @@ function rules_action_watchdog_form($set
 }
 
 /**
+ * Condition: Check for content types - Configuration form
+ */
+function rules_condition_file_is_type_form($settings, &$form) {
+  $form['settings']['filemime'] = array(
+    '#type' => 'textarea',
+    '#title' => t('MIME types'),
+    '#default_value' => $settings['filemime'],
+    '#description' =>  t("Enter one MIME type per line. The '*' character is a wildcard. Example MIME types are %image for all images and %pdf for a PDF file.", array('%image' => 'image/*', '%pdf' => 'application/pdf')),
+    '#required' => TRUE,
+  );
+}
+
+/**
  * @}
  */
