Index: modules/project/comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/comment.inc,v retrieving revision 1.64 diff -u -F^f -r1.64 comment.inc --- modules/project/comment.inc 24 Apr 2006 14:33:09 -0000 1.64 +++ modules/project/comment.inc 24 Apr 2006 15:28:33 -0000 @@ -6,6 +6,7 @@ function project_comment_page() { if (user_access('create project issues')) { $edit = (object) $_POST['edit']; $node = node_load(array('nid' => arg(3), 'type' => 'project_issue')); + $edit->nid = $node->nid; if ($_POST['op'] == t('Preview') || $_POST['op'] == t('Submit')) { $edit = project_comment_validate($edit); @@ -61,12 +62,15 @@ function project_comment_form(&$edit, &$ if ($edit->cid) { $form['cid']= array('#type' => 'hidden', '#value' => $edit->cid); } + if ($edit->nid) { + $form['nid']= array('#type' => 'hidden', '#value' => $edit->nid); + } $form['preview'] = array('#type' => 'button', '#value' => t('Preview')); if (!form_get_errors()) { $form['submit'] = array('#type' => 'button', '#value' => t('Submit')); } if ($op == t('Preview')) { - $form['#after_build'] = array('node_form_add_preview'); + $form['#after_build'] = array('project_comment_form_add_preview'); } return drupal_get_form('project_comment_form', $form); } @@ -95,6 +99,38 @@ function project_comment_view($node, $ma global $user; $links = array(); $rows = array(); + $result = db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.nid = %d ORDER BY p.created ASC', $node->nid); + if (db_num_rows($result)) { + $i = 0; + while ($comment = db_fetch_object($result)) { + $i++; + $rows = array_merge($rows, _project_comment_view_single($comment, $i)); + } + $output = '
'; + $output .= theme('table', array(), $rows); + $output .= '
'; + + return theme('box', t('Updates'), $output); + } +} + +/** + * Private method to view a single project comment (issue followup). + * + * @param $comment + * An array or object of the comment to view. + * @param $count + * The integer that shows what number of comment this is. + * + * @return + * An array of validated output to theme/display. + * + */ +function _project_comment_view_single($comment, $count) { + $comment = (object)$comment; + $summary = array(); + $rows = array(); + $fields = array( 'title' => 'Title', 'pid' => 'Project', @@ -106,46 +142,61 @@ function project_comment_view($node, $ma 'sid' => 'Status' ); - $result = db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.nid = %d ORDER BY p.created ASC', $node->nid); - if (db_num_rows($result)) { - $i = 0; - while ($comment = db_fetch_object($result)) { - $i++; - $data = unserialize($comment->data); - $summary = array(); - foreach ($fields as $field => $text) { - if (isset($data['old']->$field) && isset($data['new']->$field)) { - $summary[] = array( - t($text) .':', - project_mail_summary($field, $data['old']->$field), - '» '. project_mail_summary($field, $data['new']->$field) - ); - } - } + // If we got this from the DB, we'll have a $data field to unserialize. + $comment = drupal_unpack($comment); - if ($comment->file_path && file_exists($comment->file_path)) { - $summary[] = array(t('Attachment:'), ''. basename($comment->file_path) .' ('. format_size($comment->file_size) .')'); - } + // Print out what changed about the issue with this comment. If the + // comment is in the DB, we'll have 'old' and 'new' fields from the + // 'data' field, which record exactly what changed. If not, we'll + // load the origial node and compare against that. + if (!isset($comment->data)) { + $node = node_load($comment->nid); + } + foreach ($fields as $field => $text) { + if (isset($comment->old->$field) && isset($comment->new->$field)) { + $summary[] = array( + t($text) .':', + project_mail_summary($field, $comment->old->$field), + '» '. project_mail_summary($field, $comment->new->$field) + ); + } + elseif (isset($node->$field) && isset($comment->$field) && $node->$field != $comment->$field ) { + $summary[] = array( + t($text) .':', + project_mail_summary($field, $node->$field), + '» '. project_mail_summary($field, $comment->$field) + ); + } + } + + if ($comment->file_path && file_exists($comment->file_path)) { + $summary[] = array(t('Attachment:'), ''. basename($comment->file_path) .' ('. format_size($comment->file_size) .')'); + } - if ($summary || $comment->body) { - $rows[] = array(array('class' => 'header', 'data' => t('%count submitted by %user on %date', array('%count' => l("#$i", "node/$node->nid", array ('id' => "comment-$comment->cid", 'name' => "comment-$comment->cid"), NULL, "comment-$comment->cid"), '%user' => theme('username', $comment), '%date' => format_date($comment->created))) . theme('mark', node_mark($comment->nid, $comment->changed)))); - if ($summary) { - $rows[] = array(array('class' => 'summary', 'data' => theme('table', array(), $summary))); - } - if ($comment->body) { - $rows[] = array(array('class' => 'content', 'data' => '

'. check_markup($comment->body) .'

')); - } - if ($comment->fid) { - $rows[] = array(l(t('download attachment'), "project/comments/download/$comment->cid")); - } + if ($summary || $comment->body) { + if ($count) { + $rows[] = array(array('class' => 'header', 'data' => t('%count submitted by %user on %date', array('%count' => l("#$count", "node/$node->nid", array ('id' => "comment-$comment->cid", 'name' => "comment-$comment->cid"), NULL, "comment-$comment->cid"), '%user' => theme('username', $comment), '%date' => format_date($comment->created))) . theme('mark', node_mark($comment->nid, $comment->changed)))); + } + if ($summary) { + $rows[] = array(array('class' => 'summary', 'data' => theme('table', array(), $summary))); + } + if ($comment->body) { + if ($comment->format) { + $format = $comment->format; + } + elseif (isset($data['format'])) { + $format = $data['format']; + } + else { + $format = FILTER_FORMAT_DEFAULT; } + $rows[] = array(array('class' => 'content', 'data' => '

'. check_markup($comment->body, $format) .'

')); + } + if ($comment->fid) { + $rows[] = array(l(t('download attachment'), "project/comments/download/$comment->cid")); } - $output = '
'; - $output .= theme('table', array(), $rows); - $output .= '
'; - - return theme('box', t('Updates'), $output); } + return $rows; } function project_comment_load($cid) { @@ -176,6 +227,10 @@ function project_comment_save($edit) { } } + if ($edit->format) { + $data['format'] = $edit->format; + } + watchdog('content', t('project_issue: added comment %title', array('%title' => theme('placeholder', $edit->title))), WATCHDOG_NOTICE, l('view', "node/$node->nid")); $node->changed = time(); db_query("INSERT INTO {project_comments} (cid, nid, uid, created, changed, body, data, file_path, file_mime, file_size) VALUES (%d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', %d)", $edit->cid, $edit->nid, $edit->uid, $node->changed, $node->changed, $edit->body, serialize($data), $file->filepath, $file->filemime, $file->filesize); @@ -189,3 +244,49 @@ function project_comment_save($edit) { return $edit->cid; } + +/** + * Form API callback for previewing a project comment. + * + * @param $form + * The form to add the preview information to. + * @param $edit + * The form values for the comment to preview. + * + * @return + * The modified form to render. + * + * TODO: It'd be nice to put the rest of the node at the bottom of the + * form, but i couldn't get this code working to properly view the + * node as a project_issue. + */ +function project_comment_form_add_preview($form, $edit) { + drupal_set_title(t('Preview comment')); + $edit = project_comment_validate($edit); + + // Preview the comment with security check. + $output = ''; + if (!form_get_errors()) { + $rows = _project_comment_view_single($edit, 0); + $output .= theme('table', array(), $rows); + } + + $form['comment_preview'] = array( + '#value' => $output, + '#weight' => -100, + '#prefix' => '
', + '#suffix' => '
', + ); + +/* + // TODO + $output = ''; + if ($edit['nid']) { + $node = node_load(array('nid' => $edit['nid'], 'type' => 'project_issue')); + $output .= node_view($node); + $form['comment_preview_below'] = array('#value' => $output, '#weight' => 100); + } +*/ + + return $form; +}