/[drupal]/contributions/modules/fasttoggle/fasttoggle.module
ViewVC logotype

Diff of /contributions/modules/fasttoggle/fasttoggle.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.8.2.5, Sat Nov 8 10:02:54 2008 UTC revision 1.8.2.6, Sat Nov 8 11:09:20 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: fasttoggle.module,v 1.8.2.4 2008/04/19 19:35:36 timcn Exp $  // $Id: fasttoggle.module,v 1.8.2.5 2008/11/08 10:02:54 timcn Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 123  function fasttoggle_help($path, $arg) { Line 123  function fasttoggle_help($path, $arg) {
123   *   (optional; defaults to an empty string) Provide a salt for the token   *   (optional; defaults to an empty string) Provide a salt for the token
124   *   authentification added to each toggle link. If the string is empty, the   *   authentification added to each toggle link. If the string is empty, the
125   *   generic token for the user on this site is used.   *   generic token for the user on this site is used.
126     * @param $class
127     *   (optional; defaults to an empty string) Add a class name to the link so
128     *   that it can be styled with CSS.
129   *   *
130   * @return   * @return
131   *   Either a complete HTML link or a link array structure for use in hook_link.   *   Either a complete HTML link or a link array structure for use in hook_link.
132   */   */
133  function fasttoggle($title, $callback, $html = TRUE, $token = '') {  function fasttoggle($title, $callback, $html = TRUE, $token = '', $class = '') {
134    static $sent = false;    static $sent = false;
135    
136    // Only include the support files once.    // Only include the support files once.
# Line 136  function fasttoggle($title, $callback, $ Line 139  function fasttoggle($title, $callback, $
139      drupal_add_js(drupal_get_path('module', 'fasttoggle') .'/fasttoggle.js');      drupal_add_js(drupal_get_path('module', 'fasttoggle') .'/fasttoggle.js');
140      drupal_add_css(drupal_get_path('module', 'fasttoggle') .'/fasttoggle.css', 'module', 'all', FALSE);      drupal_add_css(drupal_get_path('module', 'fasttoggle') .'/fasttoggle.css', 'module', 'all', FALSE);
141    }    }
142    $attributes = array('class' => 'fasttoggle', 'title' => t('Toggle this setting'));    $attributes = array('class' => 'fasttoggle' . (!empty($class) ? ' '. $class : ''), 'title' => t('Toggle this setting'));
143    $query = drupal_get_destination() .'&token='. drupal_get_token($token);    $query = drupal_get_destination() .'&token='. drupal_get_token($token);
144    
145    if ($html) {    if ($html) {
# Line 233  function fasttoggle_fasttoggle_options($ Line 236  function fasttoggle_fasttoggle_options($
236   */   */
237  function fasttoggle_form_alter(&$form, $form_state, $form_id) {  function fasttoggle_form_alter(&$form, $form_state, $form_id) {
238    switch ($form_id) {    switch ($form_id) {
239      case 'node_admin_nodes':      case 'node_admin_content':
240        // Add published/unpublished toggle links to the node overview page.        // Add published/unpublished toggle links to the node overview page.
241        if (isset($form['status'])) {        if (isset($form['admin']['status'])) {
242          foreach ($form['status'] as $key => $status) {          $labels = _fasttoggle_get_label('node_status');
243            $form['status'][$key]['#value'] = fasttoggle($status['#value'], 'node/'. $key .'/toggle/status', true, 'status_'. $key);  
244            foreach ($form['admin']['status'] as $key => $status) {
245              $status = intval($status['#value'] == t('published'));
246              $form['admin']['status'][$key]['#value'] = fasttoggle($labels[$status], 'node/'. $key .'/toggle/status', true, 'status_'. $key, 'fasttoggle-status-node-status-'. $status);
247          }          }
248        }        }
249        break;        break;
250      case 'user_admin_account':      case 'user_admin_account':
251        // Add blocked/unblocked toggle links to the user overview page.        // Add blocked/unblocked toggle links to the user overview page.
252        if (isset($form['status'])) {        if (isset($form['status'])) {
253            $labels = _fasttoggle_get_label('user_status');
254    
255          foreach ($form['status'] as $key => $status) {          foreach ($form['status'] as $key => $status) {
256            $form['status'][$key]['#value'] = fasttoggle($status['#value'], 'admin/user/'. $key .'/toggle/status', true, 'status_'. $key);            $status = intval($status['#value'] == t('active'));
257              $form['status'][$key]['#value'] = fasttoggle($labels[$status], 'user/'. $key .'/toggle/status', true, 'status_'. $key, 'fasttoggle-status-user-status-'. $status);
258          }          }
259        }        }
260        break;        break;
# Line 264  function fasttoggle_link($type, $obj = n Line 273  function fasttoggle_link($type, $obj = n
273      switch ($type) {      switch ($type) {
274        case 'node':        case 'node':
275          foreach (array_keys($options) as $key) {          foreach (array_keys($options) as $key) {
276            $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($obj->$key)], 'node/'. $obj->nid .'/toggle/'. $key, false, $key .'_'. $obj->nid);            $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($obj->$key)], 'node/'. $obj->nid .'/toggle/'. $key, false, $key .'_'. $obj->nid, 'fasttoggle-status-node-'. $key .'-'. intval($obj->$key));
277          }          }
278          break;          break;
279        case 'comment':        case 'comment':
280          fasttoggle_load_comment($obj);          fasttoggle_load_comment($obj);
281          foreach (array_keys($options) as $key) {          foreach (array_keys($options) as $key) {
282            $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($obj->$key)], 'comment/toggle/'. $obj->cid .'/'. $key, false, $key .'_'. $obj->cid);            $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($obj->$key)], 'comment/toggle/'. $obj->cid .'/'. $key, false, $key .'_'. $obj->cid,  'fasttoggle-status-comment-'. $key .'-'. (1 - intval($obj->$key)));
283          }          }
284          break;          break;
285        // User is not one of the standard types for hook_link(). This        // User is not one of the standard types for hook_link(). This
286        // use enables adding of user links to a user profile.        // use enables adding of user links to a user profile.
287        case 'user':        case 'user':
288          foreach (array_keys($options) as $key) {          foreach (array_keys($options) as $key) {
289            $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($obj->$key)], 'user/'. $obj->uid .'/toggle/'. $key, false, $key .'_'. $obj->uid);            $links['fasttoggle_'. $key] = fasttoggle($options[$key][intval($obj->$key)], 'user/'. $obj->uid .'/toggle/'. $key, false, $key .'_'. $obj->uid, 'fasttoggle-status-user-'. $key .'-'. $obj->$key);
290          }          }
291          break;          break;
292      }      }

Legend:
Removed from v.1.8.2.5  
changed lines
  Added in v.1.8.2.6

  ViewVC Help
Powered by ViewVC 1.1.2