? inline.patch
Index: inline.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inline/inline.module,v
retrieving revision 1.19.2.6
diff -u -p -r1.19.2.6 inline.module
--- inline.module	8 Apr 2007 04:19:03 -0000	1.19.2.6
+++ inline.module	10 Apr 2007 18:29:32 -0000
@@ -377,24 +377,30 @@ function _inline_substitute_tags(&$node,
  *
  * @return Processed $field of $node.
  */
-function _inline_replace_numbers(&$node, $field) {
-  $tag = "/\[(inline|file|attachment):(\d+)[^=\\]]*=?([^\\]]*)?\]/i";
-  // look if there are any numeric inline tags
-  if (preg_match_all($tag, $node->$field, $matches, PREG_SET_ORDER)) {
+function _inline_replace_numbers($node, $field) {
+  $tag = '/\[(inline|file|attachment):(\d+?)(=.+?)?\]/i';
+  // Look if there are any numeric inline tags.
+  preg_match_all($tag, $node->$field, $matches, PREG_SET_ORDER);
+  if (!empty($matches)) {
     foreach ($matches as $match) {
-      // file uploads are stored with their database file ID
+      // Attachment array key is the file ID.
       $filekeys = array_keys($node->files);
-      // if a corresponding file does exist, perform the replacement
-      // node form submit
-      if (isset($node->files[$filekeys[$match[2] - 1]]['filename'])) {
-        $filename = $node->files[$filekeys[$match[2] - 1]]['filename'];
-        $node->$field = preg_replace($tag, '[$1:'. $filename . (!empty($match[3]) ? '=$3' : '') .']', $node->$field, 1);
-      }
-      // node form prepare
-      if (isset($node->files[$filekeys[$match[2] - 1]]->filename)) {
-        $filename = $node->files[$filekeys[$match[2] - 1]]->filename;
-        $node->$field = preg_replace($tag, '[$1:'. $filename . (!empty($match[3]) ? '=$3' : '') .']', $node->$field, 1);
+      $key = $filekeys[$match[2] - 1];
+      // If a corresponding file does exist, perform the replacement.
+      // Because a user starts counting files from 1, we substract 1 here.
+      if (!isset($node->files[$key])) {
+        // If user entered a non-existent number, continue with next tag.
+        continue;
       }
+      if (is_array($node->files[$key])) {
+        // Node form submit
+        $filename = $node->files[$key]['filename'];
+      }
+      else {
+        // Node form prepare
+        $filename = $node->files[$key]->filename;
+      }
+      $node->$field = str_replace($match[0], '['. $match[1] .':'. $filename . $match[3] .']', $node->$field);
     }
   }
   return $node->$field;
