Index: delicious.info
===================================================================
RCS file: delicious.info
diff -N delicious.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ delicious.info	1 Nov 2007 17:02:08 -0000
@@ -0,0 +1,3 @@
+; $Id$
+name = Del.icio.us
+description = Provides integration with del.icio.us REST web services
Index: delicious.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/delicious/delicious.install,v
retrieving revision 1.1
diff -u -u -p -r1.1 delicious.install
--- delicious.install	24 Jul 2006 01:12:36 -0000	1.1
+++ delicious.install	1 Nov 2007 17:02:08 -0000
@@ -63,4 +63,13 @@ function delicious_install() {
     case 'pgsql':
       break;
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function delicious_uninstall() {
+  variable_del('delicious_crosslink');
+  variable_del('delicious_tagging');
+  variable_del('delicious_node_types');
+}
Index: delicious.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/delicious/delicious.module,v
retrieving revision 1.25
diff -u -u -p -r1.25 delicious.module
--- delicious.module	24 Jul 2006 01:12:36 -0000	1.25
+++ delicious.module	1 Nov 2007 17:02:08 -0000
@@ -18,9 +18,9 @@
 
 // SET up AS a define because the API docs say this is likely to change at some point.
 define(DELICIOUS_BASE_URL, 'http://del.icio.us/');
-define(DELICIOUS_API_URL, 'http://del.icio.us/api/');
-define(DELICIOUS_UPDATE_URL, 'posts/update');
-define(DELICIOUS_POSTS_URL, 'posts/all');
+define(DELICIOUS_API_URL, 'https://api.del.icio.us/');
+define(DELICIOUS_UPDATE_URL, 'v1/posts/update');
+define(DELICIOUS_POSTS_URL, 'v1/posts/all');
 
 // ----------------------------------------------------------------------------
 // Drupal hooks
@@ -53,33 +53,26 @@ function delicious_help($section = "admi
 // _link() hook
 //
 // Add a link, if necessary, to the links section of a node
-function delicious_link($type, $node = 0, $main) {
-  global $user;
-
-  $links = array();
-
-  if (!$node || !user_access('view delicious links'))
-    return $links;
-
-  if ($type == 'node' && _delicious_nodetype_applicable($node->type)) {
-    if (variable_get("delicious_crosslink", 0)) {
-      $links[] = '<a href="' . _delicious_term_link($node) . 'del.icio.us links</a>';
+function delicious_link($type, $node = NULL, $teaser = FALSE) {
+  if ($node && user_access('view delicious links') && $type == 'node' && _delicious_nodetype_applicable($node->type) && variable_get('delicious_crosslink', 0)) {
+    if ($link = _delicious_term_link($node)) {
+      $links = array();
+      $links[] = array(
+        'href' => $link,
+        'title' => t('del.icio.us links'),
+      );
+      return $links;
     }
   }
-
-  return $links;
 }
 
 //
 // _settings() hook
 //
-function delicious_settings() {
+function delicious_admin_settings_form() {
 
   // Build a list of node types
-  foreach (node_list() AS $type) {
-    $node_type = node_invoke($type, 'node_name');
-    $nodes[$type] = $node_type ? $node_type : $type;
-  }
+  $node_types = drupal_map_assoc(array_keys(node_get_types()));
   $form["delicious_crosslink"] = array(
     '#type' => 'checkbox',
     '#title' => t("Enable del.icio.us related crosslink"),
@@ -98,10 +91,10 @@ function delicious_settings() {
     '#type' => 'checkboxes',
     '#title' => t('Node Types'),
     '#default_value' => variable_get('delicious_node_types', array('blog', 'page', 'story')),
-    '#options' => $nodes,
+    '#options' => $node_types,
     '#description' => t('SELECT all node types that allow crosslinking and/or smarttagging.'),
   );
-  return $form;
+  return system_settings_form($form);
 }
 
 //
@@ -143,9 +136,10 @@ function delicious_menu($may_cache) {
     // administrative items
     $items[] = array(
       'path' => 'admin/settings/delicious',
-      'title' => t('delicious settings'),
+      'title' => t('admin delicious settings'),
       'access' => user_access('administer delicious'),
-      'callback' => 'delicious_settings',
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'delicious_admin_settings_form',
       'type' => MENU_ITEM
     );
     $items[] = array(
@@ -198,7 +192,7 @@ function delicious_menu($may_cache) {
   else {
     // administrators editing arbitrary users is dynamic, and so outside the may_cache line.
     if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != $user->uid) {
-      $targetuser->uid = arg(1);
+      $targetuser = user_load(array('uid' => arg(1)));
       $items[] = array(
         'path' => 'user/' . arg(1) . '/delicious',
         'title' => t('delicious'),
@@ -209,10 +203,10 @@ function delicious_menu($may_cache) {
       );
     }
 
-	  // provide CSS information about actuators (stolen from taxonomy_dhtml basically)
-	  $module = drupal_get_path('module', 'delicious');
-	  theme_add_style($module . '/delicious.css');
-	  drupal_add_js($module . '/delicious.js');
+    // provide CSS information about actuators (stolen from taxonomy_dhtml basically)
+    $module = drupal_get_path('module', 'delicious');
+    drupal_add_css($module .'/delicious.css');
+    drupal_add_js($module . '/delicious.js');
   }
   
   return $items;
@@ -224,7 +218,7 @@ function delicious_menu($may_cache) {
 // Smart-tag nodes if that functionality is turned on.
 function delicious_nodeapi(&$node, $op, $arg = 0) {
   if (!_delicious_nodetype_applicable($node->type))
-	return;
+    return;
 
   switch ($op) {
     // smart-tagging
@@ -390,7 +384,7 @@ function delicious_page_user($uid = 0) {
 //
 function delicious_page_settings() {
   $uid = arg(1);
-  $output = delicious_page_settings_form($uid, $existence);
+  $output = drupal_get_form('delicious_page_settings_form', $uid);
   return $output;
 }
 
@@ -408,13 +402,14 @@ function delicious_page_settings_form($u
   );
 
   if ($userinfo) {
+    $arg = array('@url' => DELICIOUS_BASE_URL);
     $form["user"] = array(
       '#type' => 'textfield',
       '#title' => t("username"),
       '#default_value' => $userinfo->user,
       '#size' => 24,
       '#maxlength' => 24,
-      '#description' => t('Your <a href="' . DELICIOUS_BASE_URL . '">del.icio.us</a> User Name. '),
+      '#description' => t('Your <a href="@url">del.icio.us</a> User Name. ', $arg),
     );
     $form["pass"] = array(
       '#type' => 'password',
@@ -422,7 +417,7 @@ function delicious_page_settings_form($u
       '#default_value' => $userinfo->pass,
       '#size' => 24,
       '#maxlength' => 24,
-      '#description' => t('Your <a href="' . DELICIOUS_BASE_URL . '">del.icio.us</a> Password. '),
+      '#description' => t('Your <a href="@url">del.icio.us</a> Password. ', $arg),
     );
     $form["overview"] = array(
       '#type' => 'checkbox',
@@ -466,21 +461,22 @@ function delicious_page_settings_form($u
       '#value' => t('Enable'),
     );
   }
+  $form['#submit']['delicious_page_settings_submit'] = array();
   
-  return drupal_get_form('delicious_page_settings', $form);
+  return $form;
 }
 
 function delicious_page_settings_submit($form_id, $form_values) {
-  if ($_POST['op'] == t('Enable')) {
+  if ($form_values['op'] == t('Enable')) {
     // create a delicious_user entry
     $result = db_query("INSERT INTO {delicious_user} (uid) VALUES (%d)", $form_values['uid']);
     drupal_set_message(t("Delicious Links have been enabled; please fill out the del.icio.us username and password."));
   }
-  else if ($_POST['op'] == t('Disable')) {
+  else if ($form_values['op'] == t('Disable')) {
     $result = db_query("DELETE FROM {delicious_user} WHERE uid=%d", $form_values['uid']);
     drupal_set_message(t("Delicious Links fetching disabled."));
   }
-  else if ($_POST['op'] == t('Submit')) {
+  else if ($form_values['op'] == t('Submit')) {
     // modify fields
     $result = db_query("UPDATE {delicious_user} SET user='%s', pass='%s', lastcode=0, overview=%d, pagesize=%d WHERE uid=%d", $form_values['user'], $form_values['pass'], $form_values['overview'], $form_values['pagesize'], $form_values['uid']);
     drupal_set_message(t("Settings updated."));
@@ -528,7 +524,7 @@ function delicious_admin_edit($block = 0
     return drupal_access_denied();
   }
 
-  $output = delicious_block_form($block);
+  $output = drupal_get_form('delicious_block_form', $block);
 
   return $output;
 }
@@ -604,8 +600,9 @@ function delicious_block_form($dbid = 0)
       '#value' => $block['dbid'],
     );
   }
+  $form['#submit']['delicious_block_edit_submit'] = array();
 
-  return drupal_get_form('delicious_block_edit', $form);
+  return $form;
 }
 
 //
@@ -720,9 +717,11 @@ function _delicious_make_auth_header($us
 function _delicious_get_page($page, $user, $pass) {
   // Force 1 second throttle.
   global $lastDeliciousHit;
-  if (time() == $lastDeliciousHit)
+  $now = microtime(TRUE);
+  if ($now < $lastDeliciousHit + 1) {
     sleep(1);
-  $lastDeliciousHit = time();
+  }
+  $lastDeliciousHit = $now;
 
   return drupal_http_request(DELICIOUS_API_URL . $page, 
     _delicious_make_auth_header($user, $pass));
@@ -733,9 +732,9 @@ function _delicious_get_page($page, $use
 //
 function _delicious_update_user($user) {
   $resp = _delicious_get_page(DELICIOUS_UPDATE_URL, $user->user, $user->pass);
-  $resp->code = intval($resp->code);
-  if ($resp->code != 200) {
-    db_query("UPDATE {delicious_user} SET lastcode = $resp->code WHERE uid=%d", $user->uid);
+  $code = intval($resp->redirect_code ? $resp->redirect_code : $resp->code);
+  if ($code != 200) {
+    db_query("UPDATE {delicious_user} SET lastcode = %d WHERE uid=%d", $code, $user->uid);
     return 0;
   }
   else if ($resp->error) {
@@ -746,14 +745,14 @@ function _delicious_update_user($user) {
   $lastupdate = $parser->parse($resp->data);
   if ($lastupdate > $user->lastupdate) {
     $resp = _delicious_get_page(DELICIOUS_POSTS_URL, $user->user, $user->pass);
-    if ($resp->code != 200)
-    {
-      db_query("UPDATE {delicious_user} SET lastcode = $resp->code WHERE uid=%d", $user->uid);
+    $code = intval($resp->redirect_code ? $resp->redirect_code : $resp->code);
+    if ($code != 200) {
+      db_query("UPDATE {delicious_user} SET lastcode = %d WHERE uid=%d", $code, $user->uid);
       return 0;
     }
     $parser = new _delicious_post_parser($user->uid);
     $parser->parse($resp->data);
-    db_query("UPDATE {delicious_user} SET lastcode = %d, lastupdate = '%s' WHERE uid=%d", $resp->code, $lastupdate, $user->uid);
+    db_query("UPDATE {delicious_user} SET lastcode = %d, lastupdate = '%s' WHERE uid=%d", $code, $lastupdate, $user->uid);
     return 1;
 
   }
@@ -880,23 +879,11 @@ class _delicious_post_parser {
 //
 function _delicious_term_link(&$node) {
   $terms = taxonomy_node_get_terms($node->nid);
-  $term = $terms[0]->name;
-
-  foreach ($terms AS $term) {
-    $term = $term->name;
-    $words = explode(' ', $term);
-    foreach ($words AS $word) {
-      $tag .= $word;
-    }
-    break;
+  $term = array_shift($terms);
+  if (!empty($term->name)) {
+    $tag = strtolower(str_replace(' ', '', $term->name));
+    return DELICIOUS_BASE_URL . "tag/$tag";
   }
-
-  if (!$tag)
-    return;
-
-  $url = DELICIOUS_BASE_URL . "tag/$tag";
-
-  return $url;
 }
 
 //
@@ -941,10 +928,9 @@ function _delicious_tag_text($text, $nam
 //
 function _delicious_nodetype_applicable($type) {
   $del = variable_get('delicious_node_types', array('blog', 'story', 'page'));
-  if (!is_array($del))
-    return false;
-  else
+  if (is_array($del)) {
     return in_array($type, $del);
+  }
 }
 
 // Translate delicious dates into normal dates
@@ -972,13 +958,13 @@ function theme_delicious_user($uid) {
   drupal_set_title("delicious tags for $user->name");
 
   if ($user->overview) {
-		if ($user->pagesize < 1)
+    if ($user->pagesize < 1)
       $user->pagesize = 25; // Set a default
 
     $result = pager_query("SELECT name, COUNT(name) AS cnt FROM {delicious_tag} WHERE uid=$uid GROUP BY name ORDER BY name ", $user->pagesize, 0, "SELECT COUNT(DISTINCT(name)) FROM {delicious_tag} WHERE uid=$uid");
 
     while ($obj = db_fetch_object($result)) {
-      $list[] = l($obj->name, "delicious/tag/$obj->name/$uid") . " ($obj->cnt)";		
+      $list[] = l($obj->name, "delicious/tag/$obj->name/$uid") . " ($obj->cnt)";    
     }
     if ($list) {
       $output = theme('item_list', $list);
@@ -989,10 +975,10 @@ function theme_delicious_user($uid) {
     } 
   } 
   else {
-	  $result = db_query("SELECT dt.name, dl.description, dl.href, dl.linktime, dl.extended, count(dt2.name) AS linkcount FROM {delicious_tag} dt LEFT JOIN {delicious_link} dl ON dt.lid = dl.lid LEFT JOIN {delicious_tag} dt2 ON dt.name = dt2.name WHERE dt.uid = $uid GROUP BY dl.lid, dt2.name ORDER BY dt.name");
-	
-	  $lastTag = '';
-	  while ($obj = db_fetch_object($result)) {
+    $result = db_query("SELECT dt.name, dl.description, dl.href, dl.linktime, dl.extended, count(dt2.name) AS linkcount FROM {delicious_tag} dt LEFT JOIN {delicious_link} dl ON dt.lid = dl.lid LEFT JOIN {delicious_tag} dt2 ON dt.name = dt2.name WHERE dt.uid = $uid GROUP BY dl.lid, dt2.name ORDER BY dt.name");
+  
+    $lastTag = '';
+    while ($obj = db_fetch_object($result)) {
       if ($lastTag != $obj->name) {
         // new tag
         if ($lastTag)
@@ -1010,15 +996,15 @@ function theme_delicious_user($uid) {
       }
       $link = _delicious_get_link($obj);
       $output .= "<li> $link (" . format_date($obj->linktime, 'medium') . ")</li>\n";
-	  }
-	  if ($output) {
+    }
+    if ($output) {
       // close the last ul
       $output .= "</ul>";
       $output = "<div class='delicious-user'><ul class='delicious_menuList' id='delicious_menu_0'>\n$output</ul>\n</div>";
-	  }
-	  else {
-  		$output = NULL;
-	  }
+    }
+    else {
+      $output = NULL;
+    }
   }
 
   return $output;
