Index: fasttoggle.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fasttoggle/fasttoggle.module,v
retrieving revision 1.4.2.2
diff -u -r1.4.2.2 fasttoggle.module
--- fasttoggle.module	3 Feb 2007 21:26:43 -0000	1.4.2.2
+++ fasttoggle.module	14 Apr 2007 01:36:56 -0000
@@ -14,7 +14,8 @@
   $items = array();
 
   if (!$may_cache) {
-    if (arg(0) == 'node' && is_numeric(arg(1))) {
+    // Add the 
+    if (arg(0) == 'node' && is_numeric(arg(1)) && count(fasttoggle_get_options('node'))) {
       $node = node_load(arg(1));
       if ($node->nid) {
         $items[] = array(
@@ -22,19 +23,19 @@
           'title' => t('toggle'),
           'callback' => 'fasttoggle_node_option',
           'callback arguments' => array($node),
-          'access' => user_access('administer nodes'),
+          'access' => TRUE,
           'type' => MENU_CALLBACK
         );
       }
-    } elseif (arg(0) == 'admin' && arg(1) == 'user' && is_numeric(arg(2))) {
+    } elseif (arg(0) == 'admin' && arg(1) == 'user' && is_numeric(arg(2))  && count(fasttoggle_get_options('user'))) {
       $user = user_load(array('uid' => arg(2)));
       if ($user->uid) {
         $items[] = array(
-          'path' => 'admin/user/'. arg(2) .'/toggle/status', 
+          'path' => 'admin/user/'. arg(2) .'/toggle', 
           'title' => t('status'),
-          'callback' => 'fasttoggle_user_status',
+          'callback' => 'fasttoggle_user_option',
           'callback arguments' => array($user),
-          'access' => user_access('administer users'),
+          'access' => TRUE,
           'type' => MENU_CALLBACK
         );
       }
@@ -119,13 +120,14 @@
  */
 function fasttoggle_link($type, $node = NULL, $teaser = FALSE) {
   $links = array();
+  $options = fasttoggle_get_options('node');
 
-  if ($type == 'node' && user_access('administer nodes')) {
-    $options = fasttoggle_get_node_options();
+  if ($type == 'node' && !empty($options)) {
+
+    foreach (array_keys($options) as $key) {
+      $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($node->$key)], "node/$node->nid/toggle/$key", FALSE, $key .'_'. $node->nid);
+    }
 
-    $links['fasttoggle_status'] = fasttoggle($options['status'][intval($node->status)], "node/$node->nid/toggle/status", FALSE, 'status_'. $node->nid);
-    $links['fasttoggle_sticky'] = fasttoggle($options['sticky'][intval($node->sticky)], "node/$node->nid/toggle/sticky", FALSE, 'sticky_'. $node->nid);
-    $links['fasttoggle_promote'] = fasttoggle($options['promote'][intval($node->promote)], "node/$node->nid/toggle/promote", FALSE, 'promote_'. $node->nid);
   }
   return $links;   
 }
@@ -136,9 +138,10 @@
  * POST. Otherwise, display a confirmation form.
  */
 function fasttoggle_node_option($node, $option) {
-  $options = fasttoggle_get_node_options();
+  $options = fasttoggle_get_options('node');
 
-  // Check if the action is valid
+  // 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 .'_'. $node->nid, TRUE)) {
     // The action is confirmed: either via form submit or via AJAX/POST
     if (isset($_POST['confirm']) && $_POST['confirm']) {
@@ -173,22 +176,43 @@
 /**
  * Confirmation form for the option change of a node.
  */
-function fasttoggle_node_option_confirm($node, $status) {
+function fasttoggle_node_option_confirm($node, $option) {
   return confirm_form(array(),
-    t('Are you sure you want to set %title to %status?', array('%title' => $node->title, '%status' => $status)),
+    t('Are you sure you want to set %title to %option?', array('%title' => $node->title, '%option' => $option)),
     $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid,
     '',
     t('Change'), t('Cancel'));
 }
 
+/**
+ * Return an array of toggleable node options and the name of each state.
+ */
+function fasttoggle_get_options($type) {
+  return module_invoke_all('fasttoggle_options', $type);
+}
 
-// an array of toggleable node options and the name of each state
-function fasttoggle_get_node_options() {
-  return array(
-    'status' => array(0 => t('not published'), 1 => t('published')),
-    'sticky' => array(0 => t('not sticky'), 1 => t('sticky')),
-    'promote' => array(0 => t('not promoted'), 1 => t('promoted')),
-  );
+/**
+ * Implementation of hook_fasttoggle_options().
+ */
+function fasttoggle_fasttoggle_options($type) {
+  switch ($type) {
+    case 'node':
+      if (user_access('administer nodes')) {
+        return array(
+          'status' => array(0 => t('not published'), 1 => t('published')),
+          'sticky' => array(0 => t('not sticky'), 1 => t('sticky')),
+          'promote' => array(0 => t('not promoted'), 1 => t('promoted')),
+        );
+      }
+    case 'user':
+      if (user_access('administer users')) {
+        return array(
+          'status' => array(0 => t('blocked'), 1 => t('active')),
+        );
+      }
+    default:
+      return array();
+  }
 }
 
 
@@ -196,16 +220,22 @@
  * Menu callback. Toggle the status of a user if the action is confirmed via 
  * POST. Otherwise, display a confirmation form.
  */
-function fasttoggle_user_status($user) {
-  if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'status_'. $user->uid, TRUE)) {
+function fasttoggle_user_option($user, $option) {
+  $options = fasttoggle_get_options('user');
+
+  // 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 .'_'. $user->uid, TRUE)) {
     if (isset($_POST['confirm']) && $_POST['confirm']) {
-      $user = user_save($user, array('status' => !$user->status));
 
-      // Output the new status for the updated link text on AJAX changes
+      $array = array($option => !$user->$option);
+      $user = user_save($user, $array);
+
+      // Output the new option 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' => $user->status ? t('active') : t('blocked'),
+          'text' => $options[$option][intval($array[$option])],
         ));
         exit;
       }
@@ -217,7 +247,7 @@
       // 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_user_status_confirm', $user);
+      return drupal_get_form('fasttoggle_user_option_confirm', $user, $options[$option][intval($array[$option])]);
     }
   }
   else {
@@ -229,10 +259,10 @@
 /**
  * Confirmation form for the status change of a user.
  */
-function fasttoggle_user_status_confirm($user) {
+function fasttoggle_user_option_confirm($user, $option) {
   return confirm_form(array(),
-    $status ? t('Are you sure you want to unblock the user %user?', array('%user' => $user->name)) : t('Are you sure you want to block the user %user?', array('%user' => $user->name)),
+    t('Are you sure you want to set %user to %option?', array('%user' => $user->name, '%option' => $option)),
     $_GET['destination'] ? $_GET['destination'] : 'user/'. $user->uid,
     '',
-    $status ? t('Unblock') : t('Block'), t('Cancel'));
+    t('Change'), t('Cancel'));
 }
