function _subscriptions_content_load in Subscriptions 5.2
Same name and namespace in other branches
- 6 subscriptions_content.module \_subscriptions_content_load()
- 7 subscriptions_content.notify.inc \_subscriptions_content_load()
- 2.0.x subscriptions_content/subscriptions_content.notify.inc \_subscriptions_content_load()
Returns a node if published, including any comments that are still queued, but limited by the given subscriptions queue ID.
2 calls to _subscriptions_content_load()
- subscriptions_content_comment_load in ./
subscriptions_content.module - Custom function for loading comments.
- subscriptions_content_node_load in ./
subscriptions_content.module - Custom function for loading nodes. Loads not only the node but also any attached comments that are in the queue.
File
- ./
subscriptions_content.module, line 830 - Subscriptions to content events
Code
function _subscriptions_content_load($nid, $comment_load_sqid) {
global $user;
$node = node_load($nid, NULL, TRUE);
// Note: we must not cache across users (access checking), and we take care
// not to process the same node more than once (except for multiple batches
// of comments), so we don't gain from caching nodes; on the contrary: we
// might run out of memory!
if (!empty($node) && module_exists('comment')) {
$published_comments_only = $limit_sqids = '';
if (!user_access('administer comments')) {
$published_comments_only = 'AND c.status = ' . COMMENT_PUBLISHED;
}
if (!empty($comment_load_sqid)) {
// check for a later queued update notification (don't send comments past that one because it will go out as node/type with its own comments later!)
if ($cutoff_sqid = db_result(db_query_range("SELECT sqid FROM {subscriptions_queue} WHERE module = 'node' AND field = 'nid' AND value = '%s' AND uid = %d AND load_function = 'subscriptions_content_node_load' AND sqid > %d", array(
$nid,
$user->uid,
$comment_load_sqid,
), 0, 1))) {
$limit_sqids = 'AND q.sqid < ' . (int) $cutoff_sqid;
}
}
$sql = "\n SELECT q.sqid AS _subscriptions_sqid, q.is_new AS _subscriptions_is_new, c.* \n FROM {comments} c \n INNER JOIN {subscriptions_queue} q ON " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "c.cid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " = q.load_args AND q.uid = %d AND q.load_function = '%s' \n WHERE c.nid = %d " . $published_comments_only . ' ' . $limit_sqids;
$sql = db_rewrite_sql($sql, 'c', 'cid');
$result = db_query($sql, $user->uid, 'subscriptions_content_comment_load', $nid);
$sqids = $placeholders = array();
while ($comment = db_fetch_object($result)) {
comment_invoke_comment($comment, 'view');
if ($comment && user_access('access comments') && !isset($node->_subscriptions_comments[$comment->cid])) {
$node->_subscriptions_comments[$comment->cid] = $comment;
}
$sqids[] = $comment->_subscriptions_sqid;
$placeholders[] = '%d';
}
if ($sqids) {
db_query('DELETE FROM {subscriptions_queue} WHERE sqid IN (' . implode(',', $placeholders) . ')', $sqids);
}
}
return empty($node) ? NULL : $node;
}