Just wondering if it is possible to have the comments on a forum automatically fill with RE:

I've been search through the modules for the last couple hours and can't find where to modify this. My PHP is pretty well limited to SMF - I've got almost no CMS experience (unless you count that ordeal with Mambo, but let's not talk about that)... Any ideas? I'm sure I'm not the first person that's asked this.

Comments

ahoeben’s picture

I have written a module that does just that, but am awaiting CVS access so I can post it. I'll likely be granted CVS access this thursday (or so I was told when I subscribed for a CVS account).

sickhippie’s picture

That would be wonderful. I'll just keep my eye on this thread, then.

ahoeben’s picture

Another thursday went by without CVS access :-(, so here's the module for now:


/**
 * Implementation of hook_help().
 */
function comment_subject_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Provides a default comment subject: \'Re: [parent comment/node title]\'.');
  }
}

/**
 * Implementation of hook_form_alter().
 */
function comment_subject_form_alter($form_id, &$form) {
  if ($form_id == 'comment_form') {
    if (arg(0)=='node') {
      $node = node_load(array('nid' => arg(1)));
      $subject = $node->title;
    } 
    else if (arg(0)=='comment' && arg(1)=='reply') {
      if(is_numeric(arg(3))) {
        $comment = _comment_load(arg(3));
        $subject = $comment->subject;
      }
      else {
        $node = node_load(array('nid' => arg(2)));
        $subject = $node->title;
      }
    }
    if(!preg_match('/^re:/i', $subject))
      $subject = 'Re: '.$subject;

    $form['subject']['#default_value'] = $subject;
  }
}

As you can see it's a rather simple module, but it has only been tested with Drupal 4.7.4.

Copy and paste the whole text into a file named 'comment_subject.module' and place that in (a subfolder of) your modules folder.

I'll post to this thread again when I get CVS access and this module gets a proper place and download.

ahoeben’s picture

A project for the module above is now available. If you have any problems with the posted code, please use the project issue tracker instead of posting here...

http://drupal.org/project/comment_subject