Index: inline.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/inline/inline.module,v retrieving revision 1.19 diff -u -r1.19 inline.module --- inline.module 4 Feb 2007 10:05:52 -0000 1.19 +++ inline.module 5 Feb 2007 01:44:42 -0000 @@ -130,18 +130,28 @@ } function inline_nodeapi(&$node, $op, $arg) { - if(is_array($node->files) && $op == 'alter') { - //only nodes with our inline filter in the format may be altered - foreach (filter_list_format($node->format) as $filter) { - if ($filter->module == 'inline') { - $node->teaser = _inline_substitute_tags($node, 'teaser'); - $node->body = _inline_substitute_tags($node, 'body'); - break; - } - } - if (variable_get('upload_inline_'. $node->type, 0)) { - $node = _inline_auto_add($node); - } + if(!is_array($node->files)) { + return; + } + switch ($op) { + case 'alter': + // only nodes with our inline filter in the format may be altered + foreach (filter_list_format($node->format) as $filter) { + if ($filter->module == 'inline') { + $node->teaser = _inline_substitute_tags($node, 'teaser'); + $node->body = _inline_substitute_tags($node, 'body'); + break; + } + } + if (variable_get('upload_inline_'. $node->type, 0)) { + $node = _inline_auto_add($node); + } + return; + case 'prepare': + case 'submit': + $node->teaser = _inline_replace_numbers($node, 'teaser'); + $node->body = _inline_replace_numbers($node, 'body'); + return; } } @@ -291,6 +301,35 @@ } /** + * Replaces numeric file references with their respective file names. + * @param &$node The node object to process. + * @param $field Field of node to process. + * @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)) { + foreach ($matches as $match) { + // file uploads are stored with their database 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); + } + } + } + return $node->$field; +} + +/** * Decides if a tag (<img>) or a link to a file should be rendered * @param $file a file object * @return TRUE in case an img tag should be generated