function fasttoggle_comment_option in Fasttoggle 5
Same name and namespace in other branches
- 6 fasttoggle.toggle.inc \fasttoggle_comment_option()
Menu callback. Toggle options for a comment if the action is confirmed via POST. Otherwise, display a confirmation form.
1 string reference to 'fasttoggle_comment_option'
- fasttoggle_menu in ./
fasttoggle.module - Implementation of hook_menu().
File
- ./
fasttoggle.module, line 509 - Enables fast toggling of binary or not so binary settings
Code
function fasttoggle_comment_option($comment, $option) {
$options = fasttoggle_get_options('comment', $comment);
// Check if the action is valid. This is essential to ensure the user has
// access to the action.
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option . '_' . $comment->cid, true)) {
// The action is confirmed: either via form submit or via AJAX/POST
if (isset($_POST['confirm']) && $_POST['confirm']) {
$comment->{$option} = !$comment->{$option};
comment_save((array) $comment);
// Output the new status for the updated link text on AJAX changes
if (isset($_POST['javascript']) && $_POST['javascript']) {
drupal_set_header('Content-Type: text/javascript; charset=utf-8');
echo drupal_to_js(array(
'text' => $options[$option][intval($comment->{$option})],
'callback' => 'comment',
'option' => $option,
'status' => $comment->{$option},
));
exit;
}
else {
drupal_goto();
}
}
else {
// The action is not confirmed. The user came here through a regular link;
// no AJAX was involved. That means, we need a confirmation form so that
// we get a POST form.
return drupal_get_form('fasttoggle_comment_option_confirm', $comment, $options[$option][intval(!$comment->{$option})]);
}
}
else {
return MENU_NOT_FOUND;
}
}