Index: delicious.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/delicious/delicious.module,v
retrieving revision 1.25.4.6
diff -u -r1.25.4.6 delicious.module
--- delicious.module	20 Nov 2007 16:38:25 -0000	1.25.4.6
+++ delicious.module	26 Nov 2007 16:45:09 -0000
@@ -284,7 +284,7 @@
 // Display delicious overview (a page of all users with delicious tags)
 //
 function delicious_page() {
-  $result = pager_query("SELECT u.name, du.uid, COUNT(dt.uid) AS linkcount FROM {delicious_user} du LEFT JOIN {delicious_tag} dt ON du.uid = dt.uid LEFT JOIN {users} u on du.uid = u.uid GROUP BY dt.uid ORDER BY u.name", 20, $count_query="select count(distinct(uid)) from {delicious_user}");
+  $result = pager_query("SELECT u.name, du.uid, COUNT(dt.uid) AS linkcount FROM {delicious_user} du LEFT JOIN {delicious_tag} dt ON du.uid = dt.uid LEFT JOIN {users} u on du.uid = u.uid GROUP BY dt.uid ORDER BY u.name", 20, $count_query="SELECT COUNT(DISTINCT(uid)) FROM {delicious_user}");
 
   $header = array(t("User"), t("Link Count"));
 
@@ -644,62 +644,65 @@
   db_query("DELETE FROM {delicious_block} WHERE dbid=%d", $block);
 }
 
+/**
+ * hook_delicious
+ *
+ * callback function that module developers can implement to add or remove
+ * items from the users or tags
+ *
+ * @param $op
+ *   'users' or 'tags'
+ * @param $items
+ *   the array of users or tags
+ * @return
+ *   the modified array of users or tags
+ */
+function delicious_delicious($op, $items) {
+  return $items;
+}
+
 //
 // render recent links for _block() hook
 //
 function delicious_recent($id) {
-
+  // retrieve which delicious block to work with
   $block = db_fetch_object(db_query("SELECT * FROM {delicious_block} WHERE dbid=%d", $id));
 
-  if ($block->users) {
-    $ulist = explode(',', $block->users);
-    foreach ($ulist AS $user) {
-      if (!$users) {
-        $users = "u.name in (";
-      } 
-      else {
-        $users .= ", ";
-      }
-      $users .= "'" . db_escape_string(trim($user)) . "'";
-    }
-    $users .= ")";
+  // build the where clause from the users and tags
+  $args = array();
+  $users = module_invoke_all('delicious', 'users', explode(',', $block->users));
+  if ($users) {
+    $placeholders = implode(',', array_fill(0, count($users), "'%s'"));
+    $where .= " AND u.name IN (". $placeholders .")";
+    $args = $users;
   }
-
-  if ($block->tags) {
-    $ulist = explode(',', $block->tags);
-    foreach ($ulist AS $tag) {
-      if (!$tags) {
-        $tags = "dt.name in (";
-      } 
-      else {
-        $tags .= ", ";
-      }
-      $tags .= "'" . db_escape_string(trim($tag)) . "'";
-    }
-    $tags .= ")";
+  $tags = module_invoke_all('delicious', 'tags', explode(',', $block->tags));
+  if ($tags) {
+    $placeholders = implode(',', array_fill(0, count($tags), "'%s'"));
+    $where .= " AND dt.name IN (". $placeholders .")";
+    $args = array_merge($args, $tags);
   }
 
-  if ($users || $tags)
-  {
-    $where = "where ";
-    if ($users)
-      $where .= "$users ";
-    if ($users && $tags)
-      $where .= "and ";
-    if ($tags)
-      $where .= "$tags ";
+  $result = db_query_range("SELECT DISTINCT(dl.description), dl.href FROM {delicious_link} dl LEFT JOIN {delicious_tag} dt ON dl.lid = dt.lid LEFT JOIN {users} u ON dl.uid = u.uid WHERE (1) $where ORDER BY dl.linktime DESC", $args, 0, intval($block->maxentries));
+
+  $delicious_links = array();
+  while ($delicious_link = db_fetch_object($result)) {
+    $delicious_links[] = $delicious_link;
   }
 
-  $result = db_query_range("SELECT distinct(dl.description), dl.href FROM {delicious_link} dl LEFT JOIN {delicious_tag} dt ON dl.lid = dt.lid LEFT JOIN {users} u ON dl.uid = u.uid $where ORDER BY dl.linktime desc", 0, intval($block->maxentries));
+  return array("content" => theme('delicious_recent', $delicious_links), "subject" => $block->title);
+}
 
-  while ($link = db_fetch_object($result)) {
-    $output .= "<li> " . _delicious_get_link($link) . "</li>";
+function theme_delicious_recent($delicious_links) {
+  $items = array();
+  if (count($delicious_links)) {
+    foreach ($delicious_links as $delicious_link) {
+      $items[] = _delicious_get_link($delicious_link);
+    }
   }
-
-  if ($output) {
-    $output = "<div class=\"item-list\">\n<ul>\n" . $output . "</ul></div>\n";
+  if (count($items)) {
+    return theme('item_list', $items);
   }
-  return array("content" => $output, "subject" => $block->title);
 }
 
 // ----------------------------------------------------------------------------
@@ -855,7 +858,7 @@
       if ($obj)
       {
         db_query("UPDATE {delicious_link} SET synced=1, description='%s', extended='%s', href='%s', linktime='%s' WHERE hash='%s'", $desc, $extended, $href, $time, $hash);
-        foreach($tags AS $tag)
+        foreach ($tags as $tag)
         {
           $tagobj = db_fetch_object(db_query("SELECT * FROM {delicious_tag} WHERE lid=$obj->lid and name='$tag'"));
           if ($tagobj)
@@ -869,7 +872,7 @@
         $lid = db_next_id("{delicious_link}_lid");
         db_query("INSERT INTO {delicious_link} (lid, uid, href, description, extended, linktime, hash, synced) VALUES (%d, %d, '%s', '%s', '%s', %d, '%s', 1)", $lid, $this->uid, $href, $desc, $extended, $time, $hash);
         
-        foreach($tags AS $tag)
+        foreach ($tags as $tag)
         {
           db_query("INSERT INTO {delicious_tag} (lid, uid, name, synced) VALUES (%d, %d, '%s', 1)", $lid, $this->uid, $tag);
         }
@@ -905,7 +908,7 @@
     return $text;
 
   // error, it must start with a tag... :-(
-  foreach ($tags AS $tag) {
+  foreach ($tags as $tag) {
     if (!empty($tag) && $tag != ' ') {
       $path = DELICIOUS_BASE_URL . urlencode($username) . '/' .urlencode($tag);
       $modulepath = drupal_get_path('module', 'delicious');
