? plus1-7.patch Index: jquery.plus1.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/plus1/jquery.plus1.js,v retrieving revision 1.1.4.4 diff -u -p -r1.1.4.4 jquery.plus1.js --- jquery.plus1.js 18 Mar 2009 05:04:42 -0000 1.1.4.4 +++ jquery.plus1.js 27 Jan 2010 20:37:37 -0000 @@ -2,20 +2,21 @@ * @author Caroline Schnapp */ // $Id: jquery.plus1.js,v 1.1.4.4 2009/03/18 05:04:42 chill35 Exp $ -// Global killswitch: only run if we are in a supported browser. -if (Drupal.jsEnabled) { +(function ($) { // Documentation on Drupal JavaScript behaviors can be found here: http://drupal.org/node/114774#javascript-behaviors - Drupal.behaviors.plus1 = function(context){ - jQuery('.'+ Drupal.settings.plus1.widget_class +':not(.plus1-processed)', context).addClass('plus1-processed').each(function(){ - var plus1_widget = jQuery(this); - plus1_widget.find('.'+ Drupal.settings.plus1.link_class).attr('href', function(){ return jQuery(this).attr('href') + '&json=true'; }).click(function(){ - jQuery.getJSON(jQuery(this).attr('href'), function(json){ - plus1_widget.find('.'+ Drupal.settings.plus1.score_class).hide().fadeIn('slow').html(json.score); - plus1_widget.find('.'+ Drupal.settings.plus1.message_class).html(json.voted); + Drupal.behaviors.plus1 = { + attach: function(context){ + jQuery('.'+ Drupal.settings.plus1.widget_class +':not(.plus1-processed)', context).addClass('plus1-processed').each(function(){ + var plus1_widget = jQuery(this); + plus1_widget.find('.'+ Drupal.settings.plus1.link_class).attr('href', function(){ return jQuery(this).attr('href') + '&json=true'; }).click(function(){ + jQuery.getJSON(jQuery(this).attr('href'), function(json){ + plus1_widget.find('.'+ Drupal.settings.plus1.score_class).hide().fadeIn('slow').html(json.score); + plus1_widget.find('.'+ Drupal.settings.plus1.message_class).html(json.voted); + }); + // Preventing the /plus1/vote/ target from being triggered. + return false; }); - // Preventing the /plus1/vote/ target from being triggered. - return false; }); - }); + } }; -} +})(jQuery) \ No newline at end of file Index: plus1.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/plus1/plus1.info,v retrieving revision 1.1.4.1 diff -u -p -r1.1.4.1 plus1.info --- plus1.info 7 Sep 2008 22:14:32 -0000 1.1.4.1 +++ plus1.info 27 Jan 2010 20:37:37 -0000 @@ -3,4 +3,7 @@ name = Plus 1 description = "A +1 voting widget for nodes." package = Voting dependencies[] = votingapi -core = 6.x \ No newline at end of file +core = 7.x + +files[] = plus1.module +files[] = plus1.install \ No newline at end of file Index: plus1.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/plus1/plus1.module,v retrieving revision 1.1.4.8 diff -u -p -r1.1.4.8 plus1.module --- plus1.module 18 Mar 2009 05:04:42 -0000 1.1.4.8 +++ plus1.module 27 Jan 2010 20:37:38 -0000 @@ -8,8 +8,17 @@ /** * Implementation of hook_perm(). */ -function plus1_perm() { - return array('vote on content', 'administer the voting widget'); +function plus1_permission() { + return array( + 'vote on content' => array( + 'title' => t('Vote on content'), + 'description' => t('Cast votes on site content using the Plus1 voting widget.'), + ), + 'administer the voting widget' => array( + 'title' => t('Administer the voting widget'), + 'description' => t('Make configuration changes to the Plus1 voting widget.'), + ), + ); } /** @@ -18,7 +27,7 @@ function plus1_perm() { function plus1_menu() { $items['plus1/vote/%'] = array( - 'title' => t('Vote'), + 'title' => 'Vote', 'page callback' => 'plus1_vote', 'page arguments' => array(2), 'access arguments' => array('vote on content'), @@ -26,8 +35,8 @@ function plus1_menu() { ); $items['admin/settings/plus1'] = array( - 'title' => t('Plus 1'), - 'description' => t('Allows readers to vote on content.'), + 'title' => 'Plus 1', + 'description' => 'Allows readers to vote on content.', 'page callback' => 'drupal_get_form', 'page arguments' => array('plus1_settings'), 'access arguments' => array('administer the voting widget'), @@ -56,7 +65,7 @@ function plus1_settings() { $form['plus1_nodetypes_fieldset']['plus1_nodetypes'] = array( '#type' => 'checkboxes', - '#options' => node_get_types('names'), + '#options' => node_type_get_names(), '#default_value' => variable_get('plus1_nodetypes', array('story')), ); @@ -128,25 +137,23 @@ function plus1_vote($nid) { // If the voter has not already voted. if (!$voted) { $votes[] = array( - 'content_id' => $nid, + 'entity_id' => $nid, 'value_type' => 'points', 'value' => 1, ); votingapi_set_votes($votes); $criteria = array( - 'content_id' => $nid, + 'entity_id' => $nid, 'function' => 'sum', ); $results = votingapi_select_results($criteria); if ($json == 'json') { - // This print statement will return results to jQuery's request. - print drupal_json(array('score' => $results[0]['value'], 'voted' => check_plain(variable_get('plus1_you_voted', t('You voted'))))); - // printf('{"score": "%s", "voted": "%s"}', $results[0]['value'], check_plain(variable_get('plus1_you_voted', t('You voted')))); + drupal_json_output(array('score' => $results[0]['value'], 'voted' => check_plain(variable_get('plus1_you_voted', t('You voted'))))); } else { // Go to the full node view. drupal_set_message(t('Thank you for your vote.')); - drupal_goto('node/'. $nid); + drupal_goto('node/' . $nid); } } } @@ -162,7 +169,7 @@ function plus1_vote($nid) { * Number of votes the user has cast on this node. */ function plus1_get_votes($nid, $uid) { - $criteria['content_id'] = $nid; + $criteria['entity_id'] = $nid; $criteria['value_type'] = 'points'; if ($uid == 0) { $criteria['vote_source'] = ip_address(); @@ -183,7 +190,7 @@ function plus1_get_votes($nid, $uid) { * The score. */ function plus1_get_score($nid) { - $criteria['content_id'] = $nid; + $criteria['entity_id'] = $nid; $criteria['value_type'] = 'points'; $criteria['function'] = 'sum'; $results = votingapi_select_results($criteria); @@ -211,41 +218,50 @@ function plus1_jquery_widget($node, $tea $is_author = ($node->uid == $user->uid)? TRUE : FALSE; } $voted = plus1_get_votes($node->nid, $user->uid); - return theme('plus1_widget', $node, $score, $logged_in, $is_author, $voted, $teaser, $page); + return theme('plus1_widget', array('node' => $node, 'score' => $score, 'logged_in' => $logged_in, 'is_author' => $is_author, 'voted' => $voted, 'teaser' => $teaser, 'page' => $page)); } /** -* Implementation of hook_nodeapi(). +* Implementation of hook_nodeapi_view(). */ -function plus1_nodeapi(&$node, $op, $teaser, $page) { - switch ($op) { - case 'view': - // Only show the voting widget in allowed content types. - if (in_array($node->type, variable_get('plus1_nodetypes', array('story')))) { - // Show the widget. - if (($teaser && variable_get('plus1_in_teaser', 0)) || (!$teaser && variable_get('plus1_in_full_view', 1))) { - $node->content['plus1_widget'] = array( - '#value' => plus1_jquery_widget($node, $teaser, $page), - '#weight' => (int) variable_get('plus1_weight', '100'), - ); - } - } - break; - case 'delete': - $criteria['content_id'] = $node->nid; - $votes = votingapi_select_votes($criteria); - votingapi_delete_votes($votes); - break; +function plus1_node_view(&$node, $build_mode) { + // Only show the voting widget in allowed content types. + if (in_array($node->type, variable_get('plus1_nodetypes', array('story')))) { + // Show the widget. + if (($build_mode == 'teaser' && variable_get('plus1_in_teaser', 0)) || ($build_mode == 'full' && variable_get('plus1_in_full_view', 1))) { + $node->content['plus1_widget'] = array( + '#markup' => plus1_jquery_widget($node, ($build_mode == 'teaser'), FALSE), + '#weight' => (int) variable_get('plus1_weight', '100'), + ); + } } } /** +* Implementation of hook_nodeapi_delete(). +*/ +function plus1_node_delete(&$node) { + $criteria['entity_id'] = $node->nid; + $votes = votingapi_select_votes($criteria); + votingapi_delete_votes($votes); + break; +} + +/** * Implementation of hook_theme(). */ function plus1_theme() { return array( 'plus1_widget' => array( - 'arguments' => array('node', 'score', 'logged_in', 'is_author', 'voted', 'teaser', 'page'), + 'variables' => array( + 'node' => NULL, + 'score' => 0, + 'logged_in' => FALSE, + 'is_author' => FALSE, + 'voted' => FALSE, + 'teaser' => TRUE, + 'page' => FALSE + ), ), ); } @@ -271,12 +287,13 @@ function plus1_theme() { * The JavaScript adds presentation, ie: fade in. * */ -function theme_plus1_widget($node, $score, $logged_in, $is_author, $voted, $teaser, $page) { +function theme_plus1_widget($variables) { + extract($variables); // Load the JavaScript and CSS files. // You are free to load your own JavaScript files in your theming function to override. - drupal_add_js(drupal_get_path('module', 'plus1') .'/jquery.plus1.js'); - drupal_add_css(drupal_get_path('module', 'plus1') .'/plus1.css'); + drupal_add_js(drupal_get_path('module', 'plus1') . '/jquery.plus1.js'); + drupal_add_css(drupal_get_path('module', 'plus1') . '/plus1.css'); // Defining CSS hooks to be used in the JavaScript. $widget_class = 'plus1-widget'; @@ -292,24 +309,24 @@ function theme_plus1_widget($node, $scor } // And now we output the HTML. - $output = '
'; + $output = '
'; if (!$logged_in || user_access('vote on content')) { - $output .= '
'; + $output .= '
'; if (!$logged_in && !user_access('vote on content')) { - $output .= ''. l(t('Log in
to vote'), 'user', array('html' => TRUE)) .'
'; + $output .= '' . l(t('Log in
to vote'), 'user', array('html' => TRUE)) . '
'; } - else if ($voted) { // User already voted. + elseif ($voted) { // User already voted. $output .= check_plain(variable_get('plus1_you_voted', t('You voted'))); } - else if (user_access('vote on content')) { + elseif (user_access('vote on content')) { // User is eligible to vote. // The class name provided by Drupal.settings.plus1.link_class what we will search for in our jQuery later. $output .= '
' . l(t('Vote'), 'plus1/vote/' . $node->nid, - array('query' => 'token=' . drupal_get_token($node->nid), 'attributes' => array('class' => $link_class))) . '
'; + array('query' => array('token' => drupal_get_token($node->nid)), 'attributes' => array('class' => $link_class))) . '
'; } $output .= '
'; } - $output .= '
'; + $output .= '
'; $output .= $score; $output .= '
'; $output .= '
';