Index: delicious.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/delicious/delicious.module,v
retrieving revision 1.25
diff -u -w -B -F^f -r1.25 delicious.module
--- delicious.module	24 Jul 2006 01:12:36 -0000	1.25
+++ delicious.module	6 Jun 2007 20:53:05 -0000
@@ -1,24 +1,30 @@
 <?php
-// delicious.module for drupal 4.6
-// originally by: Benjamin Grant (bgrant@1361b.net)
-// maintained by: Earl Miles (merlin@logrus.com)
-// $Id
-
-// contributions:
-//
-// patch from mark leicester implementing /delicious module page
-// "smart tagging" ported from jonathan deutsch's wordpress plugin
-//
-// Significant rewrites by Earl Miles (merlinofchaos) to allow multiple
-// users, database the tags, make the code conform to coding conventions
-// and finished a bunch of todo items that were listed in the code.
+// $Id$
+
+/** 
+ * @file
+ *
+ * delicious.module for drupal
+ *
+ * originally by: Benjamin Grant (bgrant@1361b.net)
+ * maintained by: Earl Miles (merlin@logrus.com)
+ *
+ * contributions:
+ *
+ * patch from mark leicester implementing /delicious module page
+ * "smart tagging" ported from jonathan deutsch's wordpress plugin
+ *
+ * Significant rewrites by Earl Miles (merlinofchaos) to allow multiple
+ * users, database the tags, make the code conform to coding conventions
+ * and finished a bunch of todo items that were listed in the code.
+ */
 
 // ----------------------------------------------------------------------------
 // Defines
 
 // 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_API_URL, 'https://api.del.icio.us/v1/');
 define(DELICIOUS_UPDATE_URL, 'posts/update');
 define(DELICIOUS_POSTS_URL, 'posts/all');
 
@@ -29,24 +35,12 @@
 //  _help() hook
 //
 function delicious_help($section = "admin/help#delicious") {
-  $output = "";
-
-  if (substr($section, 0, 4) == 'user' && substr($section, -9) == 'delicious')
-  {
+  if (substr($section, 0, 4) == 'user' && substr($section, -9) == 'delicious') {
       return t('Enabling the delicious module and providing a valid username and password will allow this site to synchronize your del.icio.us bookmarks once an hour (or whenever cron is run).');
   }
-
-  switch ($section) {
-    case 'admin/help#delicious':
-      $output = t("Provides integration with del.icio.us REST web services");
-      break;
-
-    case 'admin/modules#description':
-      $output = t("Provides integration with del.icio.us REST web services");
-      break;
+  if ($section == 'admin/help#delicious') {
+    return t("Provides integration with del.icio.us REST web services");
   }
-
-  return $output;
 }
 
 //
@@ -63,7 +57,7 @@ function delicious_link($type, $node = 0
 
   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>';
+      $links['delicious'] = array('title' => 'find similar content on del.icio.us','href' =>  _delicious_term_link($node)); 
     }
   }
 
@@ -73,10 +67,10 @@ function delicious_link($type, $node = 0
 //
 // _settings() hook
 //
-function delicious_settings() {
+function delicious_admin_settings() {  
 
   // Build a list of node types
-  foreach (node_list() AS $type) {
+    foreach (node_get_types() AS $type => $name) { 
     $node_type = node_invoke($type, 'node_name');
     $nodes[$type] = $node_type ? $node_type : $type;
   }
@@ -101,7 +95,7 @@ function delicious_settings() {
     '#options' => $nodes,
     '#description' => t('SELECT all node types that allow crosslinking and/or smarttagging.'),
   );
-  return $form;
+  return system_settings_form($form);
 }
 
 //
@@ -144,9 +138,12 @@ function delicious_menu($may_cache) {
     $items[] = array(
       'path' => 'admin/settings/delicious',
       'title' => t('delicious settings'),
-      'access' => user_access('administer delicious'),
-      'callback' => 'delicious_settings',
-      'type' => MENU_ITEM
+      'description' => t('Delicious Mmmm.'),
+      'access' => user_access('administer site configuration'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('delicious_admin_settings'),
+      'type' => MENU_NORMAL_ITEM
+
     );
     $items[] = array(
       'path' => 'admin/delicious',
@@ -211,7 +208,7 @@ 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_css($module . '/delicious.css');
 	  drupal_add_js($module . '/delicious.js');
   }
   
@@ -235,8 +232,12 @@ function delicious_nodeapi(&$node, $op, 
           $uname = db_result(db_query("SELECT user FROM {delicious_user} WHERE uid=$node->uid"));
         }
         if ($uname) {
-          $node->body = _delicious_tag_text($node->body, $uname);
-          $node->teaser = _delicious_tag_text($node->teaser, $uname);
+          if ($node->content['teaser']) {
+            $node->content['teaser'] = array('#value' => _delicious_tag_text($node->teaser, $uname), '#weight' => 10);
+          }
+          if ($node->content['body']) {
+            $node->content['body'] = array('#value' => _delicious_tag_text($node->body, $uname), '#weight' => 10 );
+          }
         }
       } 
       break;
@@ -369,7 +370,7 @@ function delicious_page_tag($tag = "", $
     $output = "<p>" . l(t('View "%n" for all users', array('%n' => $tag)), "delicious/tag/$tag") . "</p>";
 
   $output .= theme('table', $header, $rows);
-  $output = "<div class=delicious-tag>$output</div>\n";
+  $output = "<div class=\"delicious-tag\">$output</div>\n";
 
   return $output;
 }
@@ -390,7 +391,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;
 }
 
@@ -467,10 +468,10 @@ function delicious_page_settings_form($u
     );
   }
   
-  return drupal_get_form('delicious_page_settings', $form);
+  return $form ; 
 }
 
-function delicious_page_settings_submit($form_id, $form_values) {
+function delicious_page_settings_form_submit($form_id, $form_values) {
   if ($_POST['op'] == t('Enable')) {
     // create a delicious_user entry
     $result = db_query("INSERT INTO {delicious_user} (uid) VALUES (%d)", $form_values['uid']);
@@ -528,31 +529,43 @@ 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;
 }
 
+
+function delicious_admin_delete_confirm_submit($form_id, $form_values) {
+  if ($form_values['confirm']) {
+    delicious_delete_block($form_values['block']);
+  }
+  return 'admin/delicious';
+}
+
 function delicious_admin_delete($dbid = 0) {
   $block = delicious_load_block($dbid);
   if ($block['title'] == '') {
     return drupal_access_denied();
   }
 
+  return drupal_get_form('delicious_admin_delete_confirm', $dbid);
+}
+
+function delicious_admin_delete_confirm_page() {
+  return drupal_get_form('delicious_admin_delete_confirm', arg(1));
+}
+
+function delicious_admin_delete_confirm($dbid){
+
+
   $form['block'] = array('#type' => 'value', '#value' => $dbid);
-  return confirm_form('delicious_admin_delete_confirm', $form,
+  return confirm_form($form,
     t('Are you sure you want to delete %title?', array('%title' => $block['title'])), 
     $_GET['destination'] ? $_GET['destination'] : 'admin/delicious', 
     t('This action cannot be undone.'),
     t('Delete'), t('Cancel')  
   );
-}
 
-function delicious_admin_delete_confirm_submit($form_id, $form_values) {
-  if ($form_values['confirm']) {
-    delicious_delete_block($form_values['block']);
-  }
-  return 'admin/delicious';
 }
 
 //
@@ -605,13 +618,13 @@ function delicious_block_form($dbid = 0)
     );
   }
 
-  return drupal_get_form('delicious_block_edit', $form);
+  return $form ; 
 }
 
 //
 // save block to db
 //
-function delicious_block_edit_submit($form_id, $form_values) {
+function delicious_block_form_submit($form_id, $form_values) {
   if ($form_values['dbid']) {
     db_query("UPDATE {delicious_block} SET title='%s', users='%s', tags='%s', maxentries=%d WHERE dbid=%d", $form_values['title'], $form_values['users'], $form_values['tags'], $form_values['maxentries'], $form_values['dbid']);
   }
@@ -903,26 +916,14 @@ function _delicious_term_link(&$node) {
 // smart-tagging support
 //
 function _delicious_tag_string($text, $tags, $username) {
-
-  if (!$tags)
-    return $text;
-
-  // error, it must start with a tag... :-(
-  foreach ($tags AS $tag) {
-    if (!empty($tag) && $tag != ' ') {
-      $path = DELICIOUS_BASE_URL . urlencode($username) . '/' .urlencode($tag);
+  // TODO: url checking
+  // TODO: cache this! what about a filter?
       $modulepath = drupal_get_path('module', 'delicious');
-      $deliciousLink = "<a href='$path'><img src='$modulepath/deliciousIcon.gif' class='delicious-icon'></a>";
-      
-      if (!preg_match('/<.+>/',$text)) {
-        $text = preg_replace('/(\b'.$tag.'\b)/i','$1'.$deliciousLink,$text);
-      } else {
-        $text = preg_replace('/(?<=>)([^<]+)?(\b'.$tag.'\b)/i','$1$2'.$deliciousLink,$text);
-      }
-    } 
-  }
-
-  return $text;
+  return preg_replace(
+    '/\b('. implode('|', array_map('preg_quote', $tags)) .')\b/',
+    '<a href="'. DELICIOUS_BASE_URL . $username .'/$1'.'"><img src="'. $modulepath .'/deliciousIcon.gif" class="delicious-icon">$1</a>',
+    $text
+  );
 }
 
 //
@@ -1025,5 +1026,5 @@ function theme_delicious_user($uid) {
 }
 
 function _delicious_get_link($obj) {
-  return "<a href='$obj->href' title='$obj->extended' class='delicious_node'>$obj->description</a>";
+  return l($obj->description, $obj->href, array ('title' => $obj->extended, 'class' => 'delicious_node'), NULL, NULL, TRUE);
 }
Index: delicious.info
===================================================================
RCS file: delicious.info
diff -u -w -B -F^f -N delicious.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ delicious.info	2007-06-03 17:01:53.000000000 +0000
@@ -0,0 +1,4 @@
+; $Id$
+name = delicious
+description = "Provides integration with <a href="http://del.icio.us/help/api/">del.icio.us REST web services</a>"
+version = "$Name$"
