/** * Creates a forum post object, forum object, and all related data from a * single forum post ID. Intended when entering a page which uses post ID * as a parameter. * @param int $id ID of forum post * @param int $cloneid If this is in a shared forum, must be the id of the * clone forum currently in use, or CLONE_DIRECT; otherwise must be 0 * @param bool $wholediscussion If true, retrieves entire discussion * instead of just this single post * @param bool $usecache True to use cache when retrieving the discussion * @param int $userid User ID to get post on behalf of (controls flag data * retrieved) * @return forum_post Post object */ public static function get_from_id($id, $cloneid, $wholediscussion = false, $usecache = false, $userid = 0) { if ($wholediscussion) { $discussion = forum_discussion::get_from_post_id($id, $cloneid, $usecache, $usecache); $root = $discussion->get_root_post(); return $root->find_child($id); } else { // Get post data (including extra data such as ratings and flags) $records = self::query_posts('fp.id=' . $id, 'fp.id', true, true, false, $userid); if (count($records) != 1) { throw new forum_exception("Invalid post ID {$id}"); } $postfields = reset($records); $discussion = forum_discussion::get_from_id($postfields->discussionid, $cloneid); $newpost = new forum_post($discussion, $postfields); return $newpost; } }