diff options
author | Freya Murphy <freya@freyacat.org> | 2024-03-30 16:36:54 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-03-30 16:36:54 -0400 |
commit | 1f647374a8cdf3bc5c2d29ff8be277b027925c8c (patch) | |
tree | 9fdf42d250edb941de13ecd1aab9185ba2b30b00 /web/_controller/apps | |
parent | rename views to _views (diff) | |
download | xssbook2-1f647374a8cdf3bc5c2d29ff8be277b027925c8c.tar.gz xssbook2-1f647374a8cdf3bc5c2d29ff8be277b027925c8c.tar.bz2 xssbook2-1f647374a8cdf3bc5c2d29ff8be277b027925c8c.zip |
post comments, refactor post loading, hide load more btn
Diffstat (limited to 'web/_controller/apps')
-rw-r--r-- | web/_controller/apps/home.php | 70 |
1 files changed, 3 insertions, 67 deletions
diff --git a/web/_controller/apps/home.php b/web/_controller/apps/home.php index 25c8c4e..edf7e2b 100644 --- a/web/_controller/apps/home.php +++ b/web/_controller/apps/home.php @@ -4,17 +4,13 @@ class Home_controller extends Controller { // the home model private $home_model; - // the request model - private $request_model; - - // the caceh model - private $cache_model; + // the post controller + protected $post_controller; function __construct($load) { parent::__construct($load); $this->home_model = $this->load->model('apps/home'); - $this->request_model = $this->load->model('request'); - $this->cache_model = $this->load->model('cache'); + $this->post_controller = $this->load->controller('_util/post'); } public function index(): void { @@ -24,66 +20,6 @@ class Home_controller extends Controller { $this->view('apps/home/main', $data); } - public function posts(): void { - $page = $this->request_model->get_int('page', 0); - $page_size = 20; - $offset = $page * $page_size; - - $user = $this->main->user(); - - $query = $this->db; - - if ($user) { - $query = $query->select('p.*, l.post_id IS NOT NULL as liked'); - } else { - $query = $query->select('p.*, FALSE as liked'); - } - - $query = $query->from('api.post p'); - - if ($user) { - $query = $query->join('admin.like l', 'p.id = l.post_id') - ->where('l.user_id')->eq($user['id']) - ->or()->where('l.user_id IS NULL'); - } - - $posts = $query->limit($page_size) - ->offset($offset) - ->rows(); - - $users = $this->cache_model->get_users($posts); - - foreach ($posts as $post) { - $data = array(); - $data['user'] = $users[$post['user_id']]; - $data['post'] = $post; - $this->view('template/post', $data); - } - } - - public function comments(): void { - $page = $this->request_model->get_int('page', 0); - $id = $this->request_model->get_int('id'); - $page_size = 20; - $offset = $page * $page_size; - - $comments = $this->db - ->select('*') - ->from('admin.comment') - ->limit($page_size) - ->offset($offset) - ->rows(); - - $users = $this->cache_model->get_users($comments); - - foreach ($comments as $comment) { - $data = array(); - $data['user'] = $users[$comment['user_id']]; - $data['comment'] = $comment; - $this->view('template/comment', $data); - } - } - } ?> |