Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.374
diff -u -r1.374 comment.module
--- modules/comment.module 24 Sep 2005 07:53:26 -0000 1.374
+++ modules/comment.module 25 Sep 2005 20:47:53 -0000
@@ -394,7 +394,7 @@
drupal_goto("node/$nid#comment-$cid");
}
}
- else if ($_POST['op'] == t('Preview comment')) {
+ else if ($_POST['op'] == t('Preview comment') || $_POST['fileop'] == t('Attach')) {
$edit = $_POST['edit'];
$edit = comment_validate($edit);
drupal_set_title(t('Preview comment'));
@@ -803,6 +803,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)));
}
@@ -921,6 +924,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);
@@ -1423,6 +1429,8 @@
$form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 60, 15, '', NULL, TRUE);
+ $form .= implode('', module_invoke_all('comment', 'form post', $edit));
+
$form .= filter_form('format', $edit['format']);
$form .= form_hidden('cid', $edit['cid']);
$form .= form_hidden('pid', $edit['pid']);
@@ -1441,7 +1449,8 @@
}
$destination = $_REQUEST['destination'] ? 'destination='. $_REQUEST['destination'] : '';
- return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'], $destination)));
+ $param = module_invoke_all('comment', 'form param', $edit);
+ return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'], $destination), $param));
}
function theme_comment_preview($comment, $links = '', $visible = 1) {
@@ -1539,6 +1548,7 @@
$output .= '
'. $comment->moderation ."
\n";
$output .= ''. t('by %a on %b', array('%a' => theme('username', $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.51
diff -u -r1.51 upload.module
--- modules/upload.module 2 Sep 2005 02:11:41 -0000 1.51
+++ modules/upload.module 25 Sep 2005 20:47:53 -0000
@@ -134,7 +134,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')) {
@@ -143,7 +147,7 @@
break;
case 'validate':
- $node->files = upload_load($node);
+ list ($node->files) = upload_load($node);
// Double check existing files:
if (is_array($node->list)) {
@@ -229,8 +233,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;
@@ -342,8 +354,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, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
- $fid, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
+ db_query("INSERT INTO {files} (fid, nid, vid, cid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d)",
+ $fid, $node->nid, $node->vid, isset($node->cid) ? $node->cid : 0, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
}
}
}
@@ -376,11 +388,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) {
@@ -425,16 +444,25 @@
}
function upload_load($node) {
- $files = array();
+ $files = $comment_files = array();
- if ($node->vid) {
+ if ($node->vid && !$node->is_comment) {
$result = db_query("SELECT * FROM {files} WHERE vid = %d", $node->vid);
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);
}
/**
@@ -471,3 +499,41 @@
print drupal_call_js('window.parent.iframeHandler', $output);
exit;
}
+
+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($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.199
diff -u -r1.199 database.mysql
--- database/database.mysql 18 Sep 2005 17:08:44 -0000 1.199
+++ database/database.mysql 25 Sep 2005 20:47:53 -0000
@@ -246,12 +246,14 @@
fid int(10) unsigned NOT NULL default '0',
nid int(10) unsigned NOT NULL default '0',
vid 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',
KEY vid (vid),
+ KEY cid (cid),
KEY fid (fid)
) TYPE=MyISAM;
Index: database/database.pgsql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.pgsql,v
retrieving revision 1.138
diff -u -r1.138 database.pgsql
--- database/database.pgsql 18 Sep 2005 17:08:44 -0000 1.138
+++ database/database.pgsql 25 Sep 2005 20:47:53 -0000
@@ -242,6 +242,7 @@
fid SERIAL,
nid integer NOT NULL default '0',
vid 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 '',
@@ -250,6 +251,7 @@
);
CREATE INDEX files_fid_idx ON files(fid);
CREATE INDEX files_vid_idx ON files(vid);
+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.137
diff -u -r1.137 updates.inc
--- database/updates.inc 23 Sep 2005 13:13:12 -0000 1.137
+++ database/updates.inc 25 Sep 2005 20:47:53 -0000
@@ -65,7 +65,8 @@
"2005-08-15" => "update_145",
"2005-08-25" => "update_146",
"2005-09-07" => "update_147",
- "2005-09-18" => "update_148"
+ "2005-09-18" => "update_148",
+ "2005-09-23" => "update_149"
);
function update_110() {
@@ -829,6 +830,23 @@
return $ret;
}
+function update_149() {
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql("ALTER TABLE {files} ADD cid int(10) unsigned NOT NULL default '0' AFTER vid, ADD KEY cid (cid)");
+ break;
+ case 'pgsql':
+ $ret[] = update_sql("ALTER TABLE {files} ADD cid integer NOT NULL default '0'");
+ $ret[] = update_sql("CREATE INDEX files_cid_idx ON files(cid)");
+ break;
+ }
+
+ return $ret;
+}
+
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);