? service_links-yahoo-buzz-265391-17.patch.patch
? service_links-yahoo-buzz-265391-19.patch
? service_links-yahoo-buzz-265391-9.patch
? images/yahoo-buzz.png
Index: service_links.js
===================================================================
RCS file: service_links.js
diff -N service_links.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ service_links.js	24 Sep 2008 00:14:30 -0000
@@ -0,0 +1,40 @@
+/* $Id$ */
+
+/**
+ * Click handler for Yahoo Buzz links.
+ *
+ * Yahoo Buzz requires submissions be sent via POST request. Because JavaScript
+ * cannot submit POST request across domains, we need to build an actual form
+ * in HTML, set the proper values in it, then submit it.
+ *
+ * This form is not printed directly in the HTML to save redundant code for
+ * every Buzz link on the page.
+ */
+function serviceLinksBuzzClick() {
+  var id = $(this).attr('class').match(/(yahoo-buzz-[0-9]+)/)[1];
+  var settings = Drupal.settings.serviceLinks.links[id];
+  // For reasons unknown, Buzz double-encodes URLs.
+  var encodedUrl = encodeURIComponent(encodeURIComponent(settings.url));
+
+  var form = '';
+  form += '<form action="http://buzz.yahoo.com/vote/" method="POST">';
+  form += '<input type="hidden" name="votetype" value="1" />';
+  form += '<input type="hidden" name="loc" value="' + Drupal.settings.serviceLinks.loc + '" />';
+  form += '<input type="hidden" name=".done" value="/article/pub/' + encodedUrl + '" />';
+  form += '<input type="hidden" name="headline" value="' + settings.title.replace('"', '\"') + '" />';
+  form += '<input type="hidden" name="guid" value="' + settings.url + '" />';
+  form += '<input type="hidden" name="publisherurn" value="pub" />';
+  form += '<input type="hidden" name="assettype" value="article" />';
+  form += '<input type="hidden" name="from" value="pub" />';
+  form += '<input type="submit" value="Submit" />';
+  form += '</form>';
+
+  // Create a new form, submit it, then remove it.
+  $(form).appendTo('body').submit().remove();
+
+  return false;
+}
+
+Drupal.behaviors.serviceLinksBuzz = function(context) {
+  $('a.yahoo-buzz', context).click(serviceLinksBuzzClick);
+}
Index: service_links.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/service_links/service_links.module,v
retrieving revision 1.26.2.1
diff -u -p -r1.26.2.1 service_links.module
--- service_links.module	25 May 2008 14:48:00 -0000	1.26.2.1
+++ service_links.module	24 Sep 2008 00:14:30 -0000
@@ -121,6 +121,12 @@ function service_links_admin_settings() 
     '#return_value' => 1,
     '#default_value' => variable_get('service_links_show_yahoo', 0),
   );
+  $form['what_links_to_show']['service_links_show_yahoo_buzz'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show Yahoo! Buzz link'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('service_links_show_yahoo_buzz', 0),
+  );
 
   $form['what_links2_to_show'] = array(
     '#type' => 'fieldset',
@@ -317,6 +323,9 @@ function service_links_theme() {
     'service_links_block_format' => array(
       'arguments' => array('items' => NULL),
     ),
+    'service_links_yahoo_buzz_javascript' => array(
+      'arguments' => array('id' => NULL, 'url' => NULL, 'title' => NULL),
+    ),
   );
 }
 
@@ -328,16 +337,16 @@ function service_links_render($node, $no
   $links = array();
 
   if (variable_get('service_links_agg2_link', 0) && $node->link) {
-    $url = ($node->source_link ? $node->source_link : $node->link);
+    $original_url = ($node->source_link ? $node->source_link : $node->link);
   }
   else if (!empty($node)) {
-    $url = url("node/$node->nid", array('absolute' => TRUE));
+    $original_url = url("node/$node->nid", array('absolute' => TRUE));
   }
   else {
-    $url = url($_GET['q'], array('absolute' => TRUE));
+    $original_url = url($_GET['q'], array('absolute' => TRUE));
   }
 
-  $url = urlencode($url);
+  $url = urlencode($original_url);
   $title = urlencode($node->title);
 
   if (variable_get('service_links_show_delicious', 0)) {
@@ -373,6 +382,10 @@ function service_links_render($node, $no
   if (variable_get('service_links_show_yahoo', 0)) {
     $links['service_links_yahoo'] = theme('service_links_build_link', t('Yahoo'), "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=$url&t=$title", t('Bookmark this post on Yahoo.'), 'images/yahoo.png', $nodelink);
   }
+  if (variable_get('service_links_show_yahoo_buzz', 0)) {
+    theme('service_links_yahoo_buzz_javascript', $node->nid, $original_url, $node->title);
+    $links['service_links_yahoo_buzz'] = theme('service_links_build_link', t('Yahoo! Buzz'), "http://buzz.yahoo.com/submit", t('Bookmark this post on Yahoo! Buzz.'), 'images/yahoo-buzz.png', $nodelink, array('class' => 'yahoo-buzz yahoo-buzz-'. $node->nid));
+  }
   if (variable_get('service_links_show_technorati', 0)) {
     $links['service_links_technorati'] = theme('service_links_build_link', t('Technorati'), "http://technorati.com/search/$url", t('Search Technorati for links to this post.'), 'images/technorati.png', $nodelink);
   }
@@ -386,7 +399,7 @@ function service_links_render($node, $no
   return $links;
 }
 
-function theme_service_links_build_link($text, $url, $title, $image, $nodelink) {
+function theme_service_links_build_link($text, $url, $title, $image, $nodelink, $attributes = array()) {
   global $base_path;
 
   if ($nodelink) {
@@ -415,17 +428,19 @@ function theme_service_links_build_link(
         );
         break;
     }
+    $link['attributes'] = array_merge($link['attributes'], $attributes);
   }
   else {
+    $attributes = drupal_attributes($attributes);
     switch (variable_get('service_links_style', 1)) {
       case 1:
-        $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow">'. $text .'</a>';
+        $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow"'. $attributes .'>'. $text .'</a>';
         break;
       case 2:
-        $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow"><img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /></a>';
+        $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow"'. $attributes .'><img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /></a>';
         break;
       case 3:
-        $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow"><img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /> '. $text .'</a>';
+        $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow"'. $attributes .'><img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /> '. $text .'</a>';
         break;
     }
   }
@@ -441,6 +456,24 @@ function theme_service_links_block_forma
   return '<div class="service-links">'. theme('item_list', $items) .'</div>';
 }
 
+function theme_service_links_yahoo_buzz_javascript($nid, $url, $title) {
+  static $js_added;
+
+  if (!isset($js_added)) {
+    drupal_add_js(drupal_get_path('module', 'service_links') .'/service_links.js');
+    drupal_add_js(array('serviceLinks' => array('loc' => $_SERVER['HTTP_HOST'])), 'setting');
+    $js_added = array();
+  }
+
+  $id = 'yahoo-buzz-'. $nid;
+  if (!isset($js_added[$id])) {
+    drupal_add_js(array('serviceLinks' => array('links' => array($id => array('url' => $url, 'title' => $title)))), 'setting');
+    $js_added[$id] = TRUE;
+  }
+
+  return '';
+}
+
 /**
  * Build an array of all taxonomy terms.
  */
