Index: service_links.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/service_links/service_links.install,v
retrieving revision 1.2
diff -u -r1.2 service_links.install
--- service_links.install	11 Oct 2007 17:31:37 -0000	1.2
+++ service_links.install	22 Oct 2007 19:03:02 -0000
@@ -5,7 +5,33 @@
  * Implementation of hook_uninstall().
  */
 function service_links_uninstall() {
+  variable_del('service_links');
   variable_del('service_links_node_types');
+  variable_del('service_links_show_pubsub');
+  variable_del('service_links_in_links');
+  variable_del('service_links_in_node');
+  variable_del('service_links_style');
+  variable_del('service_links_agg2_link');
+}
+
+/**
+ * Update: Store service link state in a single setting.
+ */
+function service_links_update_1() {
+  variable_set('service_links', array(
+    'delicious' => variable_get('service_links_show_delicious', 1),
+    'digg' => variable_get('service_links_show_digg', 1),
+    'stumbleupon' => variable_get('service_links_show_stumbleupon', 1),
+    'vigillar' => variable_get('service_links_show_vigillar', 1),
+    'reddit' => variable_get('service_links_show_reddit', 1),
+    'magnoliacom' => variable_get('service_links_show_magnoliacom', 1),
+    'newsvine' => variable_get('service_links_show_newsvine', 1),
+    'furl' => variable_get('service_links_show_furl', 1),
+    'google' => variable_get('service_links_show_google', 1),
+    'yahoo' => variable_get('service_links_show_yahoo', 1),
+    'technorati' => variable_get('service_links_show_technorati', 1),
+    'icerocket' => variable_get('service_links_show_icerocket', 1),
+  ));
   variable_del('service_links_show_delicious');
   variable_del('service_links_show_digg');
   variable_del('service_links_show_stumbleupon');
@@ -18,9 +44,4 @@
   variable_del('service_links_show_yahoo');
   variable_del('service_links_show_technorati');
   variable_del('service_links_show_icerocket');
-  variable_del('service_links_show_pubsub');
-  variable_del('service_links_in_links');
-  variable_del('service_links_in_node');
-  variable_del('service_links_style');
-  variable_del('service_links_agg2_link');
 }
Index: service_links.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/service_links/service_links.module,v
retrieving revision 1.22
diff -u -r1.22 service_links.module
--- service_links.module	11 Oct 2007 17:24:08 -0000	1.22
+++ service_links.module	22 Oct 2007 19:55:44 -0000
@@ -26,6 +26,108 @@
 }
 
 /**
+ * Implementation of hook_service_links().
+ */
+function service_links_service_links() {
+  $path = base_path() . drupal_get_path('module', 'service_links') .'/';
+  return array(
+    'delicious' => array(
+      'title' => t('Delicious'),
+      'link' => 'http://del.icio.us/post?url=%url&title=%title',
+      'text' => t('Bookmark this post on del.icio.us.'),
+      'icon' => $path .'delicious.png',
+      'type' => 'bookmark',
+    ),
+    'digg' => array(
+      'title' => t('Digg'),
+      'link' => 'http://digg.com/submit?phase=2&url=%url&title=%title',
+      'text' => t('Digg this post on digg.com.'),
+      'icon' => $path .'digg.png',
+      'type' => 'bookmark',
+    ),
+    'stumbleupon' => array(
+      'title' => t('StumbleUpon'),
+      'link' => 'http://www.stumbleupon.com/submit?url=%url&title=%title',
+      'text' => t('Thumb this up at StumbleUpon.'),
+      'icon' => $path .'stumbleit.png',
+      'type' => 'bookmark',
+    ),
+/*
+    'vigillar' => array(
+      'title' => t('Add new commentigillar'),
+      'link' => 'http://vigillar.se/submit?edit[url]=%url&edit[title]=%title',
+      'text' => t('Submit this post on vigillar.se.'),
+      'icon' => $path .'vigillar.png',
+      'type' => 'bookmark',
+    ),
+*/
+    'reddit' => array(
+      'title' => t('Reddit'),
+      'link' => 'http://reddit.com/submit?url=%url&title=%title',
+      'text' => t('Submit this post on reddit.com.'),
+      'icon' => $path .'reddit.png',
+      'type' => 'bookmark',
+    ),
+    'magnoliacom' => array(
+      'title' => t('Magnoliacom'),
+      'link' => 'http://ma.gnolia.com/bookmarklet/add?url=%url&title=%title',
+      'text' => t('Submit this post on ma.gnolia.com.'),
+      'icon' => $path .'magnoliacom.png',
+      'type' => 'bookmark',
+    ),
+    'newsvine' => array(
+      'title' => t('Newsvine'),
+      'link' => 'http://www.newsvine.com/_tools/seed&save?u=%url&h=%title',
+      'text' => t('Submit this post on newsvine.com.'),
+      'icon' => $path .'newsvine.png',
+      'type' => 'bookmark',
+    ),
+    'furl' => array(
+      'title' => t('Furl'),
+      'link' => 'http://www.furl.net/storeIt.jsp?u=%url&t=%title',
+      'text' => t('Submit this post on furl.net.'),
+      'icon' => $path .'furl.png',
+      'type' => 'bookmark',
+    ),
+    'facebook' => array(
+      'title' => t('Facebook'),
+      'link' => 'http://www.facebook.com/sharer.php?u=%url&t=%title',
+      'text' => t('Share on Facebook.'),
+      'icon' => $path .'facebook.png',
+      'type' => 'bookmark',
+    ),
+    'google' => array(
+      'title' => t('Google'),
+      'link' => 'http://www.google.com/bookmarks/mark?op=add&bkmk=%url&title=%title',
+      'text' => t('Bookmark this post on Google.'),
+      'icon' => $path .'google.png',
+      'type' => 'bookmark',
+    ),
+    'yahoo' => array(
+      'title' => t('Yahoo'),
+      'link' => 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=%url&t=%title',
+      'text' => t('Bookmark this post on Yahoo.'),
+      'icon' => $path .'yahoo.png',
+      'type' => 'bookmark',
+    ),
+    'technorati' => array(
+      'title' => t('Technorati'),
+      'link' => 'http://technorati.com/cosmos/search.html?url=%url',
+      'text' => t('Search Technorati for links to this post.'),
+      'icon' => $path .'technorati.png',
+      'type' => 'search',
+    ),
+    'icerocket' => array(
+      'title' => t('Icerocket'),
+      'link' => 'http://blogs.icerocket.com/search?q=%url',
+      'text' => t('Search IceRocket for links to this post.'),
+      'icon' => $path .'icerocket.png',
+      'type' => 'search',
+    ),
+  );
+}
+
+/**
  * Implementation of hook_settings().
  */
 function service_links_admin_settings() {
@@ -51,93 +153,26 @@
     );
   }
 
-  $form['what_links_to_show'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('What bookmark links to show'),
-  );
-  $form['what_links_to_show']['service_links_show_delicious'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show del.icio.us link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_delicious', 1),
-  );
-  $form['what_links_to_show']['service_links_show_digg'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Digg link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_digg', 1),
-  );
-  $form['what_links_to_show']['service_links_show_stumbleupon'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show StumbleUpon link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_stumbleupon', 0),
-  );
-  /* $form['what_links_to_show']['service_links_show_vigillar'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show vigillar.se link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_vigillar', 0),
-  ); */
-  $form['what_links_to_show']['service_links_show_reddit'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Reddit link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_reddit', 0),
-  );
-  $form['what_links_to_show']['service_links_show_magnoliacom'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show ma.gnolia.com link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_magnoliacom', 0),
-  );
-  $form['what_links_to_show']['service_links_show_newsvine'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Newsvine link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_newsvine', 0),
-  );
-  $form['what_links_to_show']['service_links_show_furl'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Furl link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_furl', 0),
-  );
-  $form['what_links_to_show']['service_links_show_facebook'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Facebook link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_facebook', 0),
-  );
-  $form['what_links_to_show']['service_links_show_google'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Google link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_google', 0),
-  );
-  $form['what_links_to_show']['service_links_show_yahoo'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Yahoo link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_yahoo', 0),
-  );
+  $links = module_invoke_all('service_links');
 
-  $form['what_links2_to_show'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('What search links to show'),
-  );
-  $form['what_links2_to_show']['service_links_show_technorati'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show Technorati link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_technorati', 1),
-  );
-  $form['what_links2_to_show']['service_links_show_icerocket'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show IceRocket link'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('service_links_show_icerocket', 0),
-  );
+  $form['service_links'] = array();
+  $defaults = variable_get('service_links', array());
+  foreach ($links as $name => $link) {
+    if (!isset($form['service_links'][$link['type']])) {
+      $form['service_links'][$link['type']] = array(
+        '#type' => 'fieldset',
+        '#title' => t('What %type links to show', array('%type' => $link['type'])),
+        '#parents' => array('service_links'),
+        '#tree' => TRUE,
+      );
+    }
+    $form['service_links'][$link['type']][$name] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show %name link', array('%name' => t($link['title']))),
+      '#return_value' => 1,
+      '#default_value' => isset($defaults[$name]) ? $defaults[$name] : 1,
+    );
+  }
 
   $form['how_to_show_the_links'] = array(
     '#type' => 'fieldset',
@@ -204,7 +239,7 @@
 /**
  * Implementation of hook_nodeapi().
  */
-function service_links_nodeapi(&$node, $op, $teaser, $page) {
+function service_links_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   switch ($op) {
     case 'view':
       $links_show = _service_links_show($node->type, $node->nid);
@@ -318,51 +353,16 @@
   }
 
   $url = urlencode($url);
-  $title = urlencode($node->title);
-
-  if (variable_get('service_links_show_delicious', 0)) {
-    $links['service_links_delicious'] = theme('service_links_build_link', t('Delicious'), "http://del.icio.us/post?url=$url&title=$title", t('Bookmark this post on del.icio.us.'), 'delicious.png', $nodelink);
-  }
-  if (variable_get('service_links_show_digg', 0)) {
-    $links['service_links_digg'] = theme('service_links_build_link', t('Digg'), "http://digg.com/submit?phase=2&url=$url&title=$title", t('Digg this post on digg.com.'), 'digg.png', $nodelink);
-  }
-  if (variable_get('service_links_show_stumbleupon', 0)) {
-    $links['service_links_stumbleupon'] = theme('service_links_build_link', t('StumbleUpon'), "http://www.stumbleupon.com/submit?url=$url&title=$title", t('Thumb this up at StumbleUpon.'), 'stumbleit.png', $nodelink);
-  }
-  /* if (variable_get('service_links_show_vigillar', 0)) {
-    $links['service_links_vigillar'] = theme('service_links_build_link', t('Add new commentigillar'), "http://vigillar.se/submit?edit[url]=$url&edit[title]=$title", t('Submit this post on vigillar.se.'), 'vigillar.png', $nodelink);
-  } */
-  if (variable_get('service_links_show_reddit', 0)) {
-    $links['service_links_reddit'] = theme('service_links_build_link', t('Reddit'), "http://reddit.com/submit?url=$url&title=$title", t('Submit this post on reddit.com.'), 'reddit.png', $nodelink);
-  }
-  if (variable_get('service_links_show_magnoliacom', 0)) {
-    $links['service_links_magnoliacom'] = theme('service_links_build_link', t('Magnoliacom'), "http://ma.gnolia.com/bookmarklet/add?url=$url&title=$title", t('Submit this post on ma.gnolia.com.'), 'magnoliacom.png', $nodelink);
-  }
-  if (variable_get('service_links_show_newsvine', 0)) {
-    $links['service_links_newsvine'] = theme('service_links_build_link', t('Newsvine'), "http://www.newsvine.com/_tools/seed&save?u=$url&h=$title", t('Submit this post on newsvine.com.'), 'newsvine.png', $nodelink);
-  }
-  if (variable_get('service_links_show_furl', 0)) {
-    $links['service_links_furl'] = theme('service_links_build_link', t('Furl'), "http://www.furl.net/storeIt.jsp?u=$url&t=$title", t('Submit this post on furl.net.'), 'furl.png', $nodelink);
-  }
-  if (variable_get('service_links_show_facebook', 0)) {
-    $links['service_links_facebook'] = theme('service_links_build_link', t('Facebook'), "http://www.facebook.com/sharer.php?u=$url&t=$title", t('Share on Facebook.'), 'facebook.png', $nodelink);
-  }
-  if (variable_get('service_links_show_google', 0)) {
-    $links['service_links_google'] = theme('service_links_build_link', t('Google'), "http://www.google.com/bookmarks/mark?op=add&bkmk=$url&title=$title", t('Bookmark this post on Google.'), 'google.png', $nodelink);
-  }
-  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.'), 'yahoo.png', $nodelink);
-  }
-  if (variable_get('service_links_show_technorati', 0)) {
-    $links['service_links_technorati'] = theme('service_links_build_link', t('Technorati'), "http://technorati.com/cosmos/search.html?url=$url", t('Search Technorati for links to this post.'), 'technorati.png', $nodelink);
-  }
-  if (variable_get('service_links_show_icerocket', 0)) {
-    $links['service_links_icerocket'] = theme('service_links_build_link', t('Icerocket'), "http://blogs.icerocket.com/search?q=$url", t('Search IceRocket for links to this post.'), 'icerocket.png', $nodelink);
-  }
+  $title = urlencode(check_plain($node->title));
 
-  // Add your own link by modifing the link below and uncomment it.
-  //$links['service_links_delicious'] = theme('service_links_build_link', t('Delicious'), "http://del.icio.us/post?url=$url&title=$title", t('Bookmark this post on del.icio.us.'), 'delicious.png', $nodelink);
+  $states = variable_get('service_links', array());
+  $services = module_invoke_all('service_links');
 
+  foreach($services as $name => $service) {
+    if (!isset($states[$name]) || $states[$name] == 1) {
+      $links['service_links_'. $name] = theme('service_links_build_link', $service['title'], str_replace(array('%title', '%url'), array($title, $url), $service['link']), $service['text'], $service['icon'], $nodelink);
+    }
+  }
   return $links;
 }
 
@@ -380,7 +380,7 @@
         break;
       case 2:
         $link = array(
-          'title' => '<img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" />',
+          'title' => '<img src="'. $image .'" alt="'. $text .'" />',
           'href' => $url,
           'attributes' => array('title' => $title, 'rel' => 'nofollow'),
           'html' => TRUE
@@ -388,7 +388,7 @@
         break;
       case 3:
         $link = array(
-          'title' => '<img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /> '. $text,
+          'title' => '<img src="'. $image .'" alt="'. $text .'" /> '. $text,
           'href' => $url,
           'attributes' => array('title' => $title, 'rel' => 'nofollow'),
           'html' => TRUE
@@ -402,10 +402,10 @@
         $link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow">'. $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"><img src="'. $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"><img src="'. $image .'" alt="'. $text .'" /> '. $text .'</a>';
         break;
     }
   }

