/** * Retrieve a list of threads to which a user is subscribed. The list can be * limited to those threads which did receive contributions recently. * * @param integer $user_id * The id of the user for which to retrieve the subscribed threads. * * @param integer $days * If set to 0 (zero), then all subscriptions will be returned. If set to * a different value, then only threads which have received contributions * within the last $days days will be included in the list. * * @param integer $forum_ids * If this parameter is NULL, then subscriptions from all forums will * be included. This parameter can also be an array of forum_ids, in * which case the search will be limited to the forums in this array. * * @return array $threads * An array of matching threads, indexed by thread id. One special key * "forum_ids" is set too. This one contains an array of all involved * forum_ids. */ function phorum_db_user_list_subscriptions($user_id, $days = 0, $forum_ids = NULL) { $PHORUM = $GLOBALS['PHORUM']; settype($user_id, 'int'); settype($days, 'int'); if ($forum_ids !== NULL) { phorum_db_sanitize_mixed($forums_ids, 'int'); } $time_where = $days > 0 ? " AND (" . time() . " - m.modifystamp) <= ({$days} * 86400)" : ''; $forum_where = ($forum_ids !== NULL and is_array($forum_ids)) ? " AND s.forum_id IN (" . implode(",", $forum_ids) . ")" : ''; // Retrieve all subscribed threads from the database for which the // latest message in the thread was posted within the provided time limit. $threads = phorum_db_interact(DB_RETURN_ASSOCS, "SELECT s.thread AS thread,\n s.forum_id AS forum_id,\n s.sub_type AS sub_type,\n m.subject AS subject,\n m.modifystamp AS modifystamp,\n m.author AS author,\n m.user_id AS user_id,\n m.email AS email,\n m.recent_author AS recent_author,\n m.recent_user_id AS recent_user_id,\n m.meta AS meta\n FROM {$PHORUM['subscribers_table']} AS s,\n {$PHORUM['message_table']} AS m\n WHERE s.user_id = {$user_id} AND\n m.message_id = s.thread AND\n (s.sub_type = " . PHORUM_SUBSCRIPTION_MESSAGE . " OR\n s.sub_type = " . PHORUM_SUBSCRIPTION_BOOKMARK . ")\n {$time_where}\n {$forum_where}\n ORDER BY m.modifystamp DESC", 'thread'); // An array for keeping track of all involved forum ids. $forum_ids = array(); foreach ($threads as $id => $thread) { // Unpack the thread's meta data. $threads[$id]['meta'] = empty($thread['meta']) ? array() : unserialize($thread['meta']); $forum_ids[$thread['forum_id']] = $thread['forum_id']; } // Store the involved forum_ids in the thread array. $threads['forum_ids'] = $forum_ids; return $threads; }
$search_values[] = $group_members; $search_operators[] = '()'; } } if (!empty($_REQUEST["forum_permissions"]) && !empty($_REQUEST["forum_permissions_forums"])) { $forum_permissions = explode(",", $_REQUEST["forum_permissions"]); $or_forum_permissions = ""; foreach ($forum_permissions as $forum_permission) { if (isset($forum_permissions_first)) { $or_forum_permissions .= " OR "; } else { $forum_permissions_first = 1; } $or_forum_permissions .= "(perm.permission>={$forum_permission} AND\n (perm.permission & {$forum_permission}>0))"; } phorum_db_sanitize_mixed($_REQUEST["forum_permissions_forums"], "string"); $db_forum_permissions_users = phorum_db_interact(DB_RETURN_ROWS, "SELECT DISTINCT user.user_id AS user_id\n FROM {$PHORUM['user_table']} AS user\n LEFT JOIN {$PHORUM['user_permissions_table']} AS perm\n ON perm.user_id = user.user_id\n WHERE ({$or_forum_permissions}) AND perm.forum_id IN ({$_REQUEST['forum_permissions_forums']})"); $forum_permissions_users = array(); foreach ($db_forum_permissions_users as $user) { $forum_permissions_users[] = $user[0]; } $search_fields[] = 'user_id'; $search_values[] = $forum_permissions_users; $search_operators[] = '()'; } // Find a list of all matching user_ids. $total = phorum_api_user_search($search_fields, $search_values, $search_operators, TRUE, 'AND', NULL, 0, 0, true); $default_pagelength = 30; settype($_REQUEST["page"], "integer"); settype($_REQUEST["pagelength"], "integer"); // The available page lengths.