The first quote works fine, with and without preview.
However, when you click quote again and such produce a double quote and put some text after it, with every Preview click not only the double quote appear once more in the Preview, they are also DUPLICATED in the comment. It's not just a display/css problem.

An uninstall of the two modules "Better Formats" and "Advanced Forum" (which I had in my project) has not solved the problem. The editor is WYSIWYG module with TinyMCE.

See attachment for the result after a few preview clicks.

Thx for your work!

Comments

Golem07’s picture

I can confirm this behaviour with WYSIWYG and Tinymce: The quotes are doubled in I preview a comments that holds quoted messages.

samuelsov’s picture

Status: Active » Needs work
StatusFileSize
new772 bytes

I have made a patch but i'm not sure it's the best way to do this.
Please comment.

itsnotme’s picture

First of all, the patch works fine here on my local machine :) Which makes me very happy.

As an almost-not-coder, the underlying problem seemed to be a double run of the text processing function when doing a preview(?), so your solution looks good for me.

Will test and implement it on my server tomorrow. Thank you!

morbiD’s picture

Version: 6.x-1.1-beta2 » 6.x-1.x-dev
StatusFileSize
new1.01 KB

I've just run into this problem myself.

Looking at the code, the module inserts the quote when the page URL contains ?quote=1. The problem is that, as a result of clicking the "Quote" link, the action attribute of form#comment-form (and hence the target of the preview button) always includes ?quote=1 so the quote is inserted again every time the preview button is clicked.

Therefore, would a more logical solution be to remove the ?quote=1 from the form action, rather than just checking $form_state every time a comment is previewed?

I made an alternative patch that kind of shows what I mean. It would be better done using a regex to match the right URL parameter if there is more than one but I didn't have time to figure it out so don't use the patch for anything other than testing.

simon georges’s picture

Hi.

I confim the behaviour with WYSIWYG and ckEditor (but I guess the behaviour is here, whatever editor you use).
The patck worked fine as the problem is corrected, I just wonder if this is the best way to correct it. i'll still take it, it works really well ;)

Best Regards,

StudioARE’s picture

Just to include another editor, same with bueditor.
Could someone upload the patched module? I don't manage to get patch files working.

Just me or does it looks like development of this module has stalled?

drupalfan2’s picture

Priority: Normal » Major
Status: Needs work » Active

Both of above patches do not work.

Can you help please?

Sarenc’s picture

The patch in #4 works for comments but not for node_comments. You need to add the same lines below

if (!empty($_GET['quote']) && isset($form['type']) && isset($form['type']['#value'])) {
    if ($form['type']['#value'] .'_node_form' == $form_id) {

Making the entire function look like:

function quote_form_alter(&$form, &$form_state, $form_id) {
  // The explanation for the $_POST check is further below.
  if ($form_id == 'comment_form' && (isset($_POST['quote']) || isset($_GET['quote']) && $_GET['quote'])) {
    // Remove "quote=1" from the form action to stop the preview button running
    // the subsequent code every time it is clicked. Prevents the quote getting
    // inserted multiple times before the content is finally saved.
    $form['#action'] = str_replace('quote=1&', '', $form['#action']);
    $form['#action'] = str_replace('quote=1', '', $form['#action']);
    $form['#action'] = rtrim($form['#action'], '?');

    $nid = arg(2);
    $cid = arg(3);

    if ($cid) {
      $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0', $cid));

      if ($comment->uid) {
        $author = $comment->registered_name;
      }
      else {
        $author = (!empty($comment->name)) ? $comment->name : variable_get('anonymous', 'Anonymous');
      }
      $quote = $comment->comment;
    }
    elseif ($nid && _quote_variable_get('node_link_display')) {
      $node = node_load(array('nid' => $nid));
      if (in_array($node->type, _quote_variable_get('node_types'))) {
        $quote = $node->body;
        $author = !empty($node->name) ? $node->name : variable_get('anonymous', 'Anonymous');
      }
      else {
        return;
      }
    }
    else {
      return;
    }

    // Add quoted text and preserve existing content (signature etc.).
    $form['comment_filter']['comment']['#default_value'] = '[quote='. $author .']'. trim($quote) ."[/quote]\n". $form['comment_filter']['comment']['#default_value'];

    if (_quote_variable_get('subject_required')) {
      $form['subject']['#required'] = TRUE;
    }

    // The Form API, by default, drops name-value pairs from the form's action
    // URL (besides ?q=). Manually adding it back in as a hidden element.
    $form['quote'] = array(
      '#type' => 'hidden',
      '#value' => 1
    );
  }

  if (!empty($_GET['quote']) && isset($form['type']) && isset($form['type']['#value'])) {
    if ($form['type']['#value'] .'_node_form' == $form_id) {
      // Remove "quote=1" from the form action to stop the preview button running
      // the subsequent code every time it is clicked. Prevents the quote getting
      // inserted multiple times before the content is finally saved.
      $form['#action'] = str_replace('quote=1&', '', $form['#action']);
      $form['#action'] = str_replace('quote=1', '', $form['#action']);
      $form['#action'] = rtrim($form['#action'], '?');
    
      $node = &$form['#node'];
      $nid = arg(3);
      $cid = arg(4);

      if ($cid) {
        $parent = node_load($cid);
      }
      elseif ($nid && _quote_variable_get('node_link_display')) {
        $parent = node_load($nid);
      }

      if ($parent) {
        $quote = $parent->body;
        $author = !empty($parent->name) ? $parent->name : variable_get('anonymous', 'Anonymous');
        // Add quoted text and preserve existing content (signature etc.).
        $form['body_field']['body']['#default_value'] = '[quote='. $author .']'. trim($quote) ."[/quote]\n". $form['body_field']['body']['#default_value'];
      }
    }
  }
}
Zen’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not able to duplicate this with the latest stables of CKEditor, TinyMCE and WYSIWYG. Nested quotes, and lots of preview clicks give me the correct output.

Please confirm if this is still occurring.

Thank you,
-K

Zen’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)