Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function get_actual_last_post()
- {
- $cid = 'lastpost_forum_' . $this->data['fid'];
- if(cache::exists($cid))
- {
- return cache::get($cid);
- }
- // now get the last post for this forum
- $lastpost = db::prepexec('SELECT MAX(p.pid) pid, t.tid, d.did
- FROM post p
- JOIN discussion d ON (p.discussion = d.did)
- JOIN thread t ON (t.discussion = d.did)
- WHERE t.forum = ?
- AND p.deleted = 0
- AND t.deleted = 0
- GROUP BY tid, did
- ORDER BY pid DESC
- LIMIT 1',
- array(
- $this->data['fid']
- )
- )->fetch();
- if(!$lastpost)
- {
- $lastpost = null;
- }
- cache::set($cid, $lastpost);
- return $lastpost;
- }
- // A test function to get the last post in a different way
- public function get_last_post(user $user)
- {
- // if the user can not see all posts, then we don't want to show a last
- // post.
- if(!allowed::userCanSeeAllPosts($this, $user))
- {
- return null;
- }
- // get all direct children
- $tree = self::getTree(self::getAll());
- $forumid = $this->data['fid'];
- $subforums = array();
- $lastposts = array();
- if(array_key_exists($forumid, $tree))
- {
- $subforums = $tree[ $forumid ];
- foreach($subforums as $subforum)
- {
- $forum = forum::fromId( $subforum );
- if($forum !== null)
- {
- $lp = $forum->get_last_post($user);
- if($lp !== null)
- {
- $lastposts[] = $lp;
- }
- }
- }
- }
- $lastpost = $this->get_actual_last_post();
- if($lastpost !== null)
- {
- $lastposts[] = $lastpost;
- }
- $highest = null;
- if($lastposts)
- {
- foreach($lastposts as $lastpost)
- {
- if((!$highest) || $highest['pid'] < $lastpost['pid'])
- {
- $highest = $lastpost;
- }
- }
- }
- return $highest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement