Index: modules/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment.module,v retrieving revision 1.347.2.6 diff -u -r1.347.2.6 comment.module --- modules/comment.module 25 Jul 2005 09:41:20 -0000 1.347.2.6 +++ modules/comment.module 25 Sep 2005 21:17:18 -0000 @@ -383,7 +383,7 @@ print theme('page', comment_post($edit)); return; } - else if ($_POST['op'] == t('Preview comment')) { + else if ($_POST['op'] == t('Preview comment') || $_POST['fileop'] == t('Attach')) { $edit = $_POST['edit']; $edit = comment_validate_form($edit); drupal_set_title(t('Preview comment')); @@ -683,7 +683,8 @@ if (node_comment_mode($comment->nid) == 2) { if (user_access('administer comments') && user_access('access administration pages')) { $links[] = l(t('delete'), "admin/comment/delete/$comment->cid"); - $links[] = l(t('edit'), "admin/comment/edit/$comment->cid"); + $links[] = l(t('edit'), + (comment_access('edit', $comment) ? '' : 'admin/') . "comment/edit/$comment->cid"); $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid"); } else if (user_access('post comments')) { @@ -750,6 +751,9 @@ if ($comment = db_fetch_object($result)) { $comment->name = $comment->uid ? $comment->registered_name : $comment->name; + if (isset($node->comment_files[$comment->cid])) { + $comment->files = $node->comment_files[$comment->cid]; + } $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1))); } @@ -868,6 +872,9 @@ $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->depth = count(explode('.', $comment->thread)) - 1; + if (isset($node->comment_files[$comment->cid])) { + $comment->files = $node->comment_files[$comment->cid]; + } if ($mode == 1) { $output .= theme('comment_flat_collapsed', $comment, $threshold_min); @@ -922,11 +929,15 @@ drupal_goto('admin/comment'); } - // If we're not saving our changes above, we're editing it. - $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid); - $comment = db_fetch_object($result); - $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - $comment = drupal_unpack($comment); + if ($_POST['fileop'] == t('Attach')) { + $comment = array2object($_POST['edit']); + } else { + // If we're not saving our changes above, we're editing it. + $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid); + $comment = db_fetch_object($result); + $comment->name = $comment->uid ? $comment->registered_name : $comment->name; + $comment = drupal_unpack($comment); + } if ($comment) { if (!$comment->uid) { @@ -938,15 +949,22 @@ else { // Otherwise, just display the author's name. $form .= form_item(t('Author'), format_name($comment)); + $form .= form_hidden('uid', $comment->uid); + $form .= form_hidden('name', $comment->name); + $form .= form_hidden('mail', $comment->mail); + $form .= form_hidden('homepage', $comment->homepage); } $form .= form_textfield(t('Subject'), 'subject', $comment->subject, 70, 128); $form .= form_textarea(t('Comment'), 'comment', $comment->comment, 70, 15, ''); + $form .= implode('', module_invoke_all('comment', 'form post', object2array($comment))); $form .= filter_form('format', $comment->format); $form .= form_radios(t('Status'), 'status', $comment->status, array(t('Published'), t('Not published'))); $form .= form_hidden('nid', $comment->nid); $form .= form_hidden('cid', $comment->cid); $form .= form_submit(t('Submit')); - print theme('page', form($form)); + + $param = module_invoke_all('comment', 'form param', object2array($comment)); + print theme('page', form($form, 'post', NULL, $param)); } } @@ -1408,6 +1426,8 @@ // comment field: $form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 70, 10, '', NULL, TRUE); + $form .= implode('', module_invoke_all('comment', 'form post', $edit)); + // format selector $form .= filter_form('format', $edit['format']); @@ -1425,7 +1445,8 @@ $form .= form_submit(t('Post comment')); } - return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid']))); + $param = module_invoke_all('comment', 'form param', $edit); + return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid']), $param)); } function theme_comment_preview($comment, $links = '', $visible = 1) { @@ -1545,6 +1566,7 @@ $output .= '
'. $comment->moderation ."
\n"; $output .= '
'. t('by %a on %b', array('%a' => format_name($comment), '%b' => format_date($comment->timestamp))) ."
\n"; $output .= "
$comment->comment
\n"; + $output .= implode('', module_invoke_all('comment', 'view', $comment)); $output .= "
$links
\n"; $output .= "\n"; return $output; Index: modules/upload.module =================================================================== RCS file: /cvs/drupal/drupal/modules/upload.module,v retrieving revision 1.31.2.5 diff -u -r1.31.2.5 upload.module --- modules/upload.module 25 May 2005 04:28:59 -0000 1.31.2.5 +++ modules/upload.module 25 Sep 2005 21:17:18 -0000 @@ -129,7 +129,11 @@ function upload_nodeapi(&$node, $op, $arg) { switch ($op) { case 'settings': - return form_radios(t('Attachments'), 'upload_'. $node->type, variable_get('upload_'. $node->type, 1), array(t('Disabled'), t('Enabled'))); + $form = form_radios(t('Attachments'), 'upload_'. $node->type, variable_get('upload_'. $node->type, 1), array(t('Disabled'), t('Enabled'))); + if (module_exist('comment')) { + $form .= form_radios(t('Attachments on comments'), 'upload_'. $node->type .'_comment', variable_get('upload_'. $node->type .'_comment', 0), array(0 => t('Disabled'), 1 => t('Enabled'))); + } + return $form; case 'form param': if (variable_get("upload_$node->type", 1) && user_access('upload files')) { @@ -138,7 +142,7 @@ break; case 'validate': - $node->files = upload_load($node); + list ($node->files) = upload_load($node); // Double check existing files: if (is_array($node->list)) { @@ -232,8 +236,16 @@ break; case 'load': - if (variable_get("upload_$node->type", 1) == 1) { - $output['files'] = upload_load($node); + $on = variable_get('upload_'. $node->type, 1) == 1; + $on_comment = variable_get('upload_'. $node->type .'_comment', 0) == 1; + if ($on || $on_comment) { + list ($files, $comment_files) = upload_load($node); + if ($on) { + $output['files'] = $files; + } + if ($on_comment && !empty($comment_files)) { + $output['comment_files'] = $comment_files; + } } break; @@ -334,8 +346,8 @@ // Insert new files: if ($file = file_save_upload($file, $file->filename)) { $fid = db_next_id('{files}_fid'); - db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)", - $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]); + db_query("INSERT INTO {files} (fid, nid, cid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, %d)", + $fid, $node->nid, isset($node->cid) ? $node->cid : 0, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]); } } else { @@ -353,11 +365,18 @@ } function upload_delete($node) { - $node->files = upload_load($node); - foreach ($node->files as $file) { + list ($files, $comment_files) = upload_load($node); + foreach ($comment_files as $list) { + $files = array_merge($files, $list); + } + foreach ($files as $file) { file_delete($file->filepath); } - db_query("DELETE FROM {files} WHERE nid = %d", $node->nid); + if ($node->nid && !$node->is_comment) { + db_query("DELETE FROM {files} WHERE nid = %d", $node->nid); + } else if ($node->cid) { + db_query("DELETE FROM {files} WHERE cid = %d", $node->cid); + } } function upload_form($node) { @@ -387,16 +406,25 @@ } function upload_load($node) { - $files = array(); + $files = $comment_files = array(); - if ($node->nid) { + if ($node->nid && !$node->is_comment) { $result = db_query("SELECT * FROM {files} WHERE nid = %d", $node->nid); while ($file = db_fetch_object($result)) { + if ($file->cid) { + $comment_files[$file->cid][$file->fid] = $file; + } else { + $files[$file->fid] = $file; + } + } + } else if ($node->cid) { + $result = db_query("SELECT * FROM {files} WHERE cid = %d", $node->cid); + while ($file = db_fetch_object($result)) { $files[$file->fid] = $file; } } - return $files; + return array($files, $comment_files); } /** @@ -420,4 +448,40 @@ return $file; } +function upload_comment($op, $comment) { + switch ($op) { + case 'view': + upload_nodeapi($comment, 'view', NULL); + return $comment->body; + + case 'delete': + $comment->is_comment = true; + upload_delete($comment); + break; + } + if (!user_access('upload files') || !isset($comment) || !$comment['nid']) { + return; + } + $comment = array2object($comment); + $comment->is_comment = true; + $node = node_load(array('nid' => $comment->nid)); + if (variable_get('upload_'. $node->type .'_comment', 0) == 0) { + return; + } + switch ($op) { + case 'form post': + upload_nodeapi($comment, 'validate', NULL); + return upload_form($comment); + + case 'form param': + return array('enctype' => 'multipart/form-data'); + + case 'insert': + case 'update': + upload_nodeapi($comment, 'validate', NULL); + upload_save($comment); + break; + } +} + ?> Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.174.2.2 diff -u -r1.174.2.2 database.mysql --- database/database.mysql 3 May 2005 05:20:07 -0000 1.174.2.2 +++ database/database.mysql 25 Sep 2005 21:17:19 -0000 @@ -232,12 +232,15 @@ CREATE TABLE files ( fid int(10) unsigned NOT NULL default '0', nid int(10) unsigned NOT NULL default '0', + cid int(10) unsigned NOT NULL default '0', filename varchar(255) NOT NULL default '', filepath varchar(255) NOT NULL default '', filemime varchar(255) NOT NULL default '', filesize int(10) unsigned NOT NULL default '0', list tinyint(1) unsigned NOT NULL default '0', - PRIMARY KEY (fid) + PRIMARY KEY (fid), + KEY nid (nid), + KEY cid (cid) ) TYPE=MyISAM; -- Index: database/database.pgsql =================================================================== RCS file: /cvs/drupal/drupal/database/database.pgsql,v retrieving revision 1.110.2.4 diff -u -r1.110.2.4 database.pgsql --- database/database.pgsql 27 Jun 2005 04:45:50 -0000 1.110.2.4 +++ database/database.pgsql 25 Sep 2005 21:17:19 -0000 @@ -228,6 +228,7 @@ CREATE TABLE files ( fid SERIAL, nid integer NOT NULL default '0', + cid integer NOT NULL default '0', filename varchar(255) NOT NULL default '', filepath varchar(255) NOT NULL default '', filemime varchar(255) NOT NULL default '', @@ -235,6 +236,8 @@ list smallint NOT NULL default '0', PRIMARY KEY (fid) ); +CREATE INDEX files_nid_idx ON files(nid); +CREATE INDEX files_cid_idx ON files(cid); -- -- Table structure for table 'filter_formats' Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.100.2.5 diff -u -r1.100.2.5 updates.inc --- database/updates.inc 7 May 2005 08:36:24 -0000 1.100.2.5 +++ database/updates.inc 25 Sep 2005 21:17:19 -0000 @@ -107,7 +107,8 @@ "2005-03-21" => "update_128", "2005-04-14" => "update_129", "2005-05-06" => "update_130", - "2005-05-07" => "update_131" + "2005-05-07" => "update_131", + "2005-09-23: first update since Drupal 4.6.0 release" => "update_132" ); function update_32() { @@ -2393,6 +2394,20 @@ return $ret; } +function update_132() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {files} ADD cid int(10) unsigned NOT NULL default '0' AFTER nid, ADD KEY nid (nid), ADD KEY cid (cid)"); + } elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("ALTER TABLE {files} ADD cid integer NOT NULL default '0'"); + $ret[] = update_sql("CREATE INDEX files_nid_idx ON files(nid)"); + $ret[] = update_sql("CREATE INDEX files_cid_idx ON files(cid)"); + } + + return $ret; +} + function update_sql($sql) { $edit = $_POST["edit"]; $result = db_query($sql);