Index: fasttoggle.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fasttoggle/fasttoggle.module,v retrieving revision 1.1 diff -u -F^f -r1.1 fasttoggle.module --- fasttoggle.module 16 Sep 2006 18:37:20 -0000 1.1 +++ fasttoggle.module 21 Jan 2007 05:03:39 -0000 @@ -18,9 +18,9 @@ function fasttoggle_menu($may_cache) { $node = node_load(arg(1)); if ($node->nid) { $items[] = array( - 'path' => 'node/'. arg(1) .'/toggle/status', - 'title' => t('status'), - 'callback' => 'fasttoggle_node_status', + 'path' => 'node/'. arg(1) .'/toggle', + 'title' => t('toggle'), + 'callback' => 'fasttoggle_node_option', 'callback arguments' => array($node), 'access' => node_access('update', $node), 'type' => MENU_CALLBACK @@ -43,15 +43,26 @@ function fasttoggle_menu($may_cache) { return $items; } -function fasttoggle($title, $callback) { + +function fasttoggle($title, $callback, $html = TRUE) { static $sent = FALSE, $destination = NULL; if (!$sent && $sent = TRUE && $destination = drupal_get_destination()) { drupal_add_js(drupal_get_path('module', 'fasttoggle'). '/fasttoggle.js'); drupal_add_css(drupal_get_path('module', 'fasttoggle'). '/fasttoggle.css'); } - - return l($title, $callback, array('class' => 'fasttoggle', title => t('Toggle this setting')), $destination); + $attributes = array('class' => 'fasttoggle', title => t('Toggle this setting')); + if ($html) { + return l($title, $callback, $attributes, $destination); + } + else { + return array( + 'title' => $title, + 'href' => $callback, + 'query' => $destination, + 'attributes' => $attributes, + ); + } } /** @@ -72,13 +83,27 @@ function fasttoggle_form_alter($form_id, } } +/** + * Implementation of hook_link(). + */ +function fasttoggle_link($type, $node = NULL, $teaser = FALSE) { + $options = fasttoggle_get_node_options(); + if ($type == 'node' && node_access('udpate', $node)) { + $links['fasttoogle_status'] = fasttoggle($options['status'][$node->status], "node/$node->nid/toggle/status", FALSE); + $links['fasttoogle_sticky'] = fasttoggle($options['sticky'][$node->sticky], "node/$node->nid/toggle/sticky", FALSE); + $links['fasttoogle_promote'] = fasttoggle($options['promote'][$node->sticky], "node/$node->nid/toggle/promote", FALSE); + } + return $links ? $links : array(); +} -function fasttoggle_node_status($node) { - $node->status = !$node->status; + +function fasttoggle_node_option($node, $option) { + $options = fasttoggle_get_node_options(); + $node->$option = !$node->$option; node_save($node); if (isset($_GET['javascript']) && $_GET['javascript']) { - echo $node->status ? t('published') : t('not published'); + echo $node->$option ? $options[$option][1] : $options[$option][0]; exit; } else { @@ -86,6 +111,15 @@ function fasttoggle_node_status($node) { } } +// an array of toggleable node options and the name of each state +function fasttoggle_get_node_options() { + return array( + 'status' => array(t('not published'), t('published')), + 'sticky' => array(t('not sticky'), t('sticky')), + 'promote' => array(t('not promoted'), t('promoted')), + ); +} + function fasttoggle_user_status($user) { $user = user_save($user, array('status' => (int)$user->status == 0));