You are here

function quote_form_alter in Quote 5

Same name and namespace in other branches
  1. 8.2 quote.module \quote_form_alter()
  2. 6.2 quote.module \quote_form_alter()
  3. 6 quote.module \quote_form_alter()
  4. 7.2 quote.module \quote_form_alter()
  5. 7 quote.module \quote_form_alter()

Implementation of hook_form_alter().

File

./quote.module, line 80

Code

function quote_form_alter($form_id, &$form) {
  if ($form_id == 'comment_form' && isset($_GET['quote']) && $_GET['quote']) {
    $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;
      $subject = $comment->subject;
    }
    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;
    }
  }
}