Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1.     public function get_actual_last_post()
  2.     {
  3.       $cid = 'lastpost_forum_' . $this->data['fid'];
  4.      
  5.       if(cache::exists($cid))
  6.     {
  7.       return cache::get($cid);
  8.     }
  9.    
  10.     // now get the last post for this forum
  11.     $lastpost = db::prepexec('SELECT MAX(p.pid) pid, t.tid, d.did
  12.         FROM post p
  13.         JOIN discussion d ON (p.discussion = d.did)
  14.         JOIN thread t ON (t.discussion = d.did)
  15.         WHERE t.forum = ?
  16.         AND p.deleted = 0
  17.         AND t.deleted = 0
  18.         GROUP BY tid, did
  19.         ORDER BY pid DESC
  20.         LIMIT 1',
  21.         array(
  22.           $this->data['fid']
  23.           )
  24.         )->fetch();
  25.    
  26.     if(!$lastpost)
  27.     {
  28.       $lastpost = null;
  29.     }
  30.     cache::set($cid, $lastpost);
  31.    
  32.     return $lastpost;
  33.     }
  34.    
  35.     // A test function to get the last post in a different way
  36.     public function get_last_post(user $user)
  37.     {
  38.     // if the user can not see all posts, then we don't want to show a last
  39.     // post.
  40.     if(!allowed::userCanSeeAllPosts($this, $user))
  41.     {
  42.       return null;
  43.     }
  44.    
  45.     // get all direct children
  46.     $tree = self::getTree(self::getAll());
  47.     $forumid = $this->data['fid'];
  48.     $subforums = array();
  49.     $lastposts = array();
  50.     if(array_key_exists($forumid, $tree))
  51.     {
  52.         $subforums = $tree[ $forumid ];
  53.         foreach($subforums as $subforum)
  54.         {
  55.             $forum = forum::fromId( $subforum );
  56.             if($forum !== null)
  57.             {
  58.                 $lp = $forum->get_last_post($user);
  59.                 if($lp !== null)
  60.                 {
  61.                     $lastposts[] = $lp;
  62.                 }
  63.             }
  64.         }
  65.     }
  66.    
  67.     $lastpost = $this->get_actual_last_post();
  68.    
  69.     if($lastpost !== null)
  70.     {
  71.         $lastposts[] = $lastpost;
  72.     }
  73.    
  74.     $highest = null;
  75.     if($lastposts)
  76.     {
  77.         foreach($lastposts as $lastpost)
  78.         {
  79.             if((!$highest) || $highest['pid'] < $lastpost['pid'])
  80.             {
  81.                 $highest = $lastpost;
  82.             }
  83.         }
  84.     }
  85.     return $highest;
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement