How about adding an RSS feed which users can subscribe to. This will be a subset of the 'all blogs' feed. Here is the function. Not sure where the link should be displayed.


function buddylist_feed() {
  global $user;
  $buddies = implode(',' $_SESSION['buddylist']);
  $result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid     FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status   = 1 AND n.uid IN ($buddies) ORDER BY n.nid DESC", 0, 30);
  $channel["title"] = t("%name buddy blogs", array ('%name' => $user->name));
  $channel["link"] = url("buddylist/feed");
  $channel["description"] = '';
  node_feed($result, $channel);
}

P.S. Something is changing the square brackets into slashes, or stripping them entirely in the code above. Grrr.

CommentFileSizeAuthor
#1 buddylist.patch212.24 KBjavanaut

Comments

javanaut’s picture

Assigned: Unassigned » javanaut
StatusFileSize
new12.24 KB

Greetings weitzman,

It looks to me like that feed would only work if you were logged in. Most of the RSS readers that I use don't behave as though you were logged in, nor do they give you any way of sending arbitrary authentication data. One option would be to accept an optional uid as a parameter, then pull the data from the DB instead of the session. The code could look something like:

WARNING: all square brackets appear to have been removed from the preview screen in the following code.

  // prints out an xml feed of all of a given users' buddies' blog entries
  function buddylist_feed($uid=0) {
    global $user;
  
    if(!$uid) {
      $acct = $user;
      $use_sess = true;
    }
    else {
      $acct = user_load(array('uid' => $uid));
      $use_sess = false;
    }
  
    if($use_sess) {
      
      // perhaps your session expired, or you think you should have buddies
      if (!isset($_SESSION['buddylist']) || sizeof($_SESSION['buddylist']) == 0) {
        buddylist_update_session();
      }

      // MySQL doesn't like empty $buddies lists
      if(sizeof($_SESSION['buddylist']) > 0) {
        $buddies = implode(',', $_SESSION['buddylist']);
        $result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid     FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status   = 1 AND n.uid IN ($buddies) ORDER BY n.nid DESC", 0, 30);
      }
      else {
        $err_title = t("No buddies found for you.  Please verify that you are logged in and have buddies.");
      }
    }
    elseif(is_object($acct)) {
      $result = db_query_range("SELECT distinct n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM buddylist b, node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 AND n.uid=b.buddy AND b.uid=$acct->uid ORDER BY n.nid DESC", 0, 30);
    }
    else {
      // user was not found
      $err_title = t("User ($uid) not found, check url");
    }
  
    if($err_title){
      $channel["title"] = $err_title;
    }
    else {
      $channel["title"] = t("%name's buddies' blogs", array ('%name' => $acct->name));
    }
    $channel["link"] = url("buddylist/view/$acct->uid", null, null, 1); // use absolute urls
    $channel["description"] = '';
    node_feed($result, $channel);
  }

I tested the code above on my CVS setup and it appears to work. I also added a menu() call in the buddylist_links() function:

      menu("buddylist/feed/$user->uid", t("xml feed"), "buddylist_page", 2, MENU_SHOW);

..and I made the channel link point to the new buddy list page that I previously submitted.

I fixed some deprecated calls to session_register() and session_is_registered().

I added a "maintain buddy list" permission:

  function buddylist_perm() {
    return array("maintain buddy list");
  }

For simplicity, I have attached a patch against the same CVS version that my previous patch was against (all previous additions/mods are relatively untouched, but nonetheless also included).

drumm’s picture

I believe this functionality made it into CVS.

Anonymous’s picture