| 1 |
<?php |
<?php |
| 2 |
// $Id: fasttoggle.toggle.inc,v 1.1.2.2 2008/11/08 11:38:19 timcn Exp $ |
// $Id: fasttoggle.toggle.inc,v 1.1.2.3 2009/02/03 20:17:31 timcn Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Handles toggling of options. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
* Menu callback. Toggle options for a node if the action is confirmed via |
* Menu callback. Toggle options for a node if the action is confirmed via |
| 15 |
|
|
| 16 |
// Check if the action is valid. This is essential to ensure the user has |
// Check if the action is valid. This is essential to ensure the user has |
| 17 |
// access to the action. |
// access to the action. |
| 18 |
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option .'_'. $node->nid, true)) { |
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option .'_'. $node->nid, TRUE)) { |
| 19 |
// The action is confirmed: either via form submit or via AJAX/POST |
// The action is confirmed: either via form submit or via AJAX/POST |
| 20 |
if (isset($_POST['confirm']) && $_POST['confirm']) { |
if (isset($_POST['confirm']) && $_POST['confirm']) { |
| 21 |
// Get the next ID. |
// Get the next ID. |
| 25 |
// Save the node. |
// Save the node. |
| 26 |
$node->$option = key($options[$option]); |
$node->$option = key($options[$option]); |
| 27 |
node_save($node); |
node_save($node); |
| 28 |
|
|
| 29 |
// Let other modules respond. |
// Let other modules respond. |
| 30 |
module_invoke_all('fasttoggle_toggle', 'node', $node, $option); |
module_invoke_all('fasttoggle_toggle', 'node', $node, $option); |
| 31 |
|
|
| 81 |
|
|
| 82 |
// Check if the action is valid. This is essential to ensure the user has |
// Check if the action is valid. This is essential to ensure the user has |
| 83 |
// access to the action. |
// access to the action. |
| 84 |
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option .'_'. $user->uid, true)) { |
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option .'_'. $user->uid, TRUE)) { |
| 85 |
if (isset($_POST['confirm']) && $_POST['confirm']) { |
if (isset($_POST['confirm']) && $_POST['confirm']) { |
| 86 |
$array = array($option => !$user->$option); |
$array = array($option => !$user->$option); |
| 87 |
$user = user_save($user, $array); |
$user = user_save($user, $array); |
| 88 |
|
|
| 89 |
// Let other modules respond. |
// Let other modules respond. |
| 90 |
module_invoke_all('fasttoggle_toggle', 'user', $user, $option); |
module_invoke_all('fasttoggle_toggle', 'user', $user, $option); |
| 91 |
|
|
| 138 |
|
|
| 139 |
// Check if the action is valid. This is essential to ensure the user has |
// Check if the action is valid. This is essential to ensure the user has |
| 140 |
// access to the action. |
// access to the action. |
| 141 |
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option .'_'. $comment->cid, true)) { |
if (isset($options[$option]) && isset($_GET['token']) && drupal_valid_token($_GET['token'], $option .'_'. $comment->cid, TRUE)) { |
| 142 |
// The action is confirmed: either via form submit or via AJAX/POST |
// The action is confirmed: either via form submit or via AJAX/POST |
| 143 |
if (isset($_POST['confirm']) && $_POST['confirm']) { |
if (isset($_POST['confirm']) && $_POST['confirm']) { |
| 144 |
$comment->$option = !$comment->$option; |
$comment->$option = !$comment->$option; |
| 145 |
comment_save((array)$comment); |
comment_save((array)$comment); |
| 146 |
|
|
| 147 |
// Let other modules respond. |
// Let other modules respond. |
| 148 |
module_invoke_all('fasttoggle_toggle', 'comment', $comment, $option); |
module_invoke_all('fasttoggle_toggle', 'comment', $comment, $option); |
| 149 |
|
|