### Eclipse Workspace Patch 1.0 #P drupal6 Index: sites/all/modules/flag/theme/flag.tpl.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flag/theme/Attic/flag.tpl.php,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 flag.tpl.php --- sites/all/modules/flag/theme/flag.tpl.php 5 Sep 2008 15:36:11 -0000 1.1.2.2 +++ sites/all/modules/flag/theme/flag.tpl.php 5 Sep 2008 22:33:48 -0000 @@ -35,11 +35,13 @@ */ ?> Index: sites/all/modules/flag/flag.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.views.inc,v retrieving revision 1.6.2.11 diff -u -r1.6.2.11 flag.views.inc --- sites/all/modules/flag/flag.views.inc 3 Sep 2008 15:20:08 -0000 1.6.2.11 +++ sites/all/modules/flag/flag.views.inc 5 Sep 2008 22:33:48 -0000 @@ -334,6 +334,28 @@ } } + function option_definition() { + $options = parent::option_definition(); + $options['link_type'] = array('default' => 'toggle'); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['link_type'] = array( + '#type' => 'radios', + '#title' => t('Link type'), + '#options' => array( + 'toggle' => t('JavaScript toggle'), + 'normal' => t('Normal link'), + 'confirm' => t('Require confirmation'), + ), + '#default_value' => $this->options['link_type'], + ); + } + /** * Override base ::query(). The purpose here is to make it possible for the * render() method to know two things: what's the content ID, and whether @@ -410,7 +432,8 @@ // Flag does not apply to this content. return; } - + + $flag->link_type = $this->options['link_type']; return $flag->theme($is_flagged ? 'unflag' : 'flag', $content_id); } } Index: sites/all/modules/flag/flag.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v retrieving revision 1.11.2.33 diff -u -r1.11.2.33 flag.module --- sites/all/modules/flag/flag.module 5 Sep 2008 17:38:06 -0000 1.11.2.33 +++ sites/all/modules/flag/flag.module 5 Sep 2008 22:33:48 -0000 @@ -55,6 +55,14 @@ 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); + $items['flag/confirm'] = array( + 'title' => 'Flag confirm', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('flag_confirm'), + 'access callback' => 'user_access', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); return $items; } @@ -606,6 +614,45 @@ } /** + * Form for confirming the (un)flagging of a piece of content. + */ +function flag_confirm(&$form_state, $action = 'flag', $flag_name, $content_id = '') { + $form = array(); + + $form['action'] = array( + '#type' => 'value', + '#value' => $action, + ); + $form['flag_name'] = array( + '#type' => 'value', + '#value' => $flag_name, + ); + $form['content_id'] = array( + '#type' => 'value', + '#value' => $content_id, + ); + + $flag = flag_get_flag($flag_name); + $object = $flag->load_content($content_id); + $replacements = array('%content_title' => $flag->get_content_title($object), '%flag_title' => $flag->get_title($content_id)); + + if ($action == 'flag') { + $question = t('Are you sure you want to flag %content_title as %flag_title?', $replacements); + } + else { + $question = t('Are you sure you want to remove the %flag_title flag from %content_title?', $replacements); + } + $path = isset($_GET['destination']) ? $_GET['destination'] : ''; + $yes = $flag->get_label($action .'_short', $content_id); + + return confirm_form($form, $question, $path, '', $yes); +} + +function flag_confirm_submit(&$form, &$form_state) { + flag_page($form_state['values']['action'], $form_state['values']['flag_name'], $form_state['values']['content_id']); +} + +/** * Action for flagging or unflagging a piece of content. * * @return @@ -780,7 +827,8 @@ $variables['setup'] = $first_time; $first_time = FALSE; - $variables['link_href'] = check_url(url("flag/$action/$flag->name/$content_id", array('query' => drupal_get_destination()))); + $variables['js'] = $flag->link_type == 'toggle'; + $variables['link_href'] = check_url(url("flag/". ($flag->link_type == 'confirm' ? 'confirm/' : '') ."$action/$flag->name/$content_id", array('query' => drupal_get_destination()))); $variables['link_text'] = strip_tags($flag->get_label($action . '_short', $content_id), ''); $variables['link_title'] = strip_tags($flag->get_label($action . '_long', $content_id)); $variables['flag_name_css'] = str_replace('_', '-', $flag->name); Index: sites/all/modules/flag/flag.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v retrieving revision 1.1.2.11 diff -u -r1.1.2.11 flag.inc --- sites/all/modules/flag/flag.inc 5 Sep 2008 17:38:06 -0000 1.1.2.11 +++ sites/all/modules/flag/flag.inc 5 Sep 2008 22:33:47 -0000 @@ -172,6 +172,7 @@ */ function default_options() { return array( + 'link_type' => 'toggle', ); } @@ -181,6 +182,17 @@ * Derived classes should want to override this. */ function options_form(&$form) { + $form['display']['link_type'] = array( + '#type' => 'radios', + '#title' => t('Link type'), + '#options' => array( + 'toggle' => t('JavaScript toggle'), + 'normal' => t('Normal link'), + 'confirm' => t('Require confirmation'), + ), + '#default_value' => $this->link_type, + '#weight' => 2, + ); } /** @@ -272,6 +284,16 @@ } /** + * Given a content object, returns its title. + * Derived classes must implement this. + * + * @abstract + */ + function get_content_title($content) { + return NULL; + } + + /** * Returns TRUE if the flag is configured to show the flag-link using hook_link. * Derived classes are likely to implement this. */ @@ -597,7 +619,7 @@ */ class flag_node extends flag_flag { function default_options() { - return array( + return parent::default_options() + array( 'show_on_page' => TRUE, 'show_on_teaser' => TRUE, 'show_on_form' => FALSE, @@ -640,6 +662,10 @@ return $node->nid; } + function get_content_title($node) { + return $node->title; + } + function uses_hook_link($teaser) { if ($teaser && $this->show_on_teaser || !$teaser && $this->show_on_page) { return TRUE; @@ -705,7 +731,7 @@ */ class flag_comment extends flag_flag { function default_options() { - return array( + return parent::default_options() + array( 'show_on_comment' => TRUE, ); } @@ -740,6 +766,10 @@ return $comment->cid; } + function get_content_title($comment) { + return $comment->title; + } + function uses_hook_link($teaser) { return $this->show_on_comment; } @@ -794,7 +824,7 @@ */ class flag_user extends flag_flag { function default_options() { - return array( + return parent::default_options() + array( 'show_on_profile' => TRUE, ); } @@ -836,6 +866,10 @@ return $user->uid; } + function get_content_title($user) { + return $user->name; + } + function uses_hook_link($teaser) { return FALSE; }