From 89bced737a58b8839fc7bc273d6f08ab3c263783 Mon Sep 17 00:00:00 2001
From: Benjamin Johnson <ben@isengard.(none)>
Date: Wed, 27 May 2009 22:37:36 +0100
Subject: [PATCH] fix addthis to only insert one script tag

---
 httpdocs/sites/all/modules/addthis/addthis.module |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/httpdocs/sites/all/modules/addthis/addthis.module b/httpdocs/sites/all/modules/addthis/addthis.module
index 1237a6e..6b5a019 100644
--- a/httpdocs/sites/all/modules/addthis/addthis.module
+++ b/httpdocs/sites/all/modules/addthis/addthis.module
@@ -132,6 +132,7 @@ function _addthis_create_button($node=NULL, $teaser = FALSE) {
  * Theme the AddThis button.
  */
 function theme_addthis_button($node, $teaser) {
+  static $has_script = FALSE;
   if (variable_get('addthis_dropdown_disabled', '0')) {
     return ( sprintf('
       <a href="http://www.addthis.com/bookmark.php"
@@ -145,20 +146,23 @@ function theme_addthis_button($node, $teaser) {
     ));
   }
   else {
-    return ( sprintf('
+    if($has_script == FALSE)
+    {
+        $url = ($_SERVER['HTTPS'] == 'on' ? 'https://secure.addthis.com' : 'http://s7.addthis.com') . '/js/' . variable_get('addthis_widget_version', '152') . '/addthis_widget.js';
+        drupal_add_js('document.write(unescape("%3Cscript src=\''. $url .'\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline','header');
+        $has_script = TRUE;
+    }
+    return sprintf('
       <a href="http://www.addthis.com/bookmark.php"
         onmouseover="return addthis_open(this, \'\', \'%s\', \'%s\')"
         onmouseout="addthis_close()"
-        onclick="return addthis_sendto()"><img src="%s" width="%d" height="%d" %s /></a>
-      <script type="text/javascript" src="%s/js/' . variable_get('addthis_widget_version', '152') . '/addthis_widget.js"></script>
-      ',
+        onclick="return addthis_sendto()"><img src="%s" width="%d" height="%d" %s /></a>',
       $teaser ? url('node/'. $node->nid, array('absolute' => 1) ) : '[URL]',
       $teaser ? addslashes($node->title) : '[TITLE]',
       $_SERVER['HTTPS'] == 'on' ? addslashes(variable_get('addthis_image_secure', 'https://secure.addthis.com/button1-share.gif')) : addslashes(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif')),
       addslashes(variable_get('addthis_image_width', '125')),
       addslashes(variable_get('addthis_image_height', '16')),
-      variable_get('addthis_image_attributes', 'alt=""'),
-      $_SERVER['HTTPS'] == 'on' ? 'https://secure.addthis.com' : 'http://s7.addthis.com'
-    ));
+      variable_get('addthis_image_attributes', 'alt=""')
+    );
   }
 }
-- 
1.6.0.4

