add $uid argument to favorite_nodes_add($nid) function, for better flexibility

yaron24 - July 18, 2009 - 01:58
Project:Favorite Nodes
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

add $uid argument to favorite_nodes_add($nid) function, for better flexibility
default will be the currently login user, but this function could be called with a different user.
this is the changed function: (sorry i didn't patch it)

<?php
/**
* Add a favorite node.
*/
function favorite_nodes_add($nid,$uid) {
 
  if (empty(
$uid)) {
    global
$user;
  }
  else if  {
   
$user = user_load('uid'=>$uid);
    if (!
$user->uid) {
      return
FALSE;
    }
  }

 
$node = node_load($nid);
  if (!
$node->nid) {
    return
FALSE;
  }

 
db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $nid, $user->uid);
 
db_query("INSERT INTO {favorite_nodes} (nid, uid, last) VALUES (%d, %d, %d)", $nid, $user->uid, time());

 
/**
   * Invoke hook_favorite_nodes(), which has the following parameters:
   * @param op
   * The operation being performed. Can be either 'add' or 'delete'.
   * @param node
   * The node object being added or deleted.
   */
 
module_invoke_all('favorite_nodes', 'add', $node);
  return
TRUE;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.