function subscriptions_get_user in Subscriptions 5
Returns all subscriptions, and displayed metadata, for a given user. (uses caching)
3 calls to subscriptions_get_user()
- subscriptions_feed in ./
subscriptions.module - generates rss feed for subscriptions @account is $user object
- subscriptions_form_alter in ./
subscriptions.module - Implementation of hook_form_alter().
- subscriptions_link in ./
subscriptions.module - Implementation of hook_link().
File
- ./
subscriptions.module, line 404
Code
function subscriptions_get_user($account = NULL) {
global $user;
static $subscriptions;
if (is_null($account)) {
$account = $user;
}
if (is_null($subscriptions[$account->uid])) {
// query string for node subscriptions
$queryn = 'SELECT td.tid, td.name, n.nid, n.title, s.stype, s.sid FROM ';
$queryn .= '(({subscriptions} s LEFT JOIN {node} n ON n.nid = s.sid) ';
$queryn .= 'LEFT JOIN {term_node} tn ON tn.nid = s.sid) ';
$queryn .= 'LEFT JOIN {term_data} td ON td.tid = tn.tid ';
$queryn .= 'WHERE n.status = 1 AND s.uid = %d AND s.stype = \'node\'';
// query string for blog subscriptions (by blog owner)
$queryb = 'SELECT u.uid, u.name, s.stype, s.sid FROM ';
$queryb .= '({subscriptions} s LEFT JOIN {users} u ON u.uid = s.sid) ';
$queryb .= 'WHERE u.status = 1 AND s.uid = %d AND s.stype = \'blog\'';
// query string for category subscriptions
$queryt = 'SELECT td.tid, td.name FROM ';
$queryt .= '{subscriptions} s INNER JOIN {term_data} td ON td.tid = s.sid ';
$queryt .= 'WHERE s.uid = %d AND s.stype = \'taxa\'';
$resultn = db_query($queryn, $account->uid);
$resultb = db_query($queryb, $account->uid);
$resultt = db_query($queryt, $account->uid);
$subscriptions[$account->uid]['node'] = $subscriptions[$account->uid]['taxa'] = $subscriptions[$account->uid]['blog'] = array();
while ($nsub = db_fetch_object($resultn)) {
$subscriptions[$account->uid]['node'][$nsub->nid] = $nsub;
}
while ($bsub = db_fetch_object($resultb)) {
$subscriptions[$account->uid]['blog'][$bsub->uid] = $bsub;
}
while ($tsub = db_fetch_object($resultt)) {
$subscriptions[$account->uid]['taxa'][$tsub->tid] = $tsub;
}
}
return $subscriptions[$account->uid];
}