function quote_form_alter in Quote 6
Same name and namespace in other branches
- 8.2 quote.module \quote_form_alter()
- 5 quote.module \quote_form_alter()
- 6.2 quote.module \quote_form_alter()
- 7.2 quote.module \quote_form_alter()
- 7 quote.module \quote_form_alter()
Implementation of hook_form_alter().
File
- ./
quote.module, line 87 - The quote module provides a filter and appropriate links that allow users to quote nodes and other comments in their own comments.
Code
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'])) {
$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,
);
}
}