From 5a2ba9c2e7605bb788bc406184547d22c6436867 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 23 Dec 2024 11:13:27 -0500 Subject: v2.1.0, refactor w/ crimson --- src/web/_controller/_util/post.php | 212 ------------------------------------- 1 file changed, 212 deletions(-) delete mode 100644 src/web/_controller/_util/post.php (limited to 'src/web/_controller/_util') diff --git a/src/web/_controller/_util/post.php b/src/web/_controller/_util/post.php deleted file mode 100644 index 5346497..0000000 --- a/src/web/_controller/_util/post.php +++ /dev/null @@ -1,212 +0,0 @@ -request_model = $this->load->model('request'); - $this->cache_model = $this->load->model('cache'); - $this->page_size = 10; - } - - public function index(): void { - $this->view('template/posts'); - } - - public function post(): void { - $pid = $this->request_model->get_int('id', 0); - - $post = $this->db - ->select('p.*, l.id as like_id') - ->from('api.post p') - ->join('api.like l', 'p.id = l.post_id AND l.user_id') - ->eq($pid) - ->where('p.id') - ->eq($pid) - ->row(); - - if (!$post) { - return; - } - - $users = $this->cache_model->get_users([$post]); - $uid = $post['user_id']; - - if (!array_key_exists($uid, $users)) { - return; - } - - $user = $users[$uid]; - - $data = array( - 'user' => $user, - 'page_size' => $this->page_size, - 'post' => $post - ); - $this->view('template/post', $data); - } - - /** - * @return array - */ - public function posts(): array { - $page = $this->request_model->get_int('page', 0); - $max = $this->request_model->get_int('max'); - $offset = $page * $this->page_size; - $filter_uid = $this->request_model->get_int('user_id', FALSE); - - $user = $this->main->user(); - $uid = isset($user) ? $user['id'] : NULL; - - $query = $this->db; - - $query = $this->db - ->select('p.*, l.id as like_id') - ->from('api.post p') - ->join('api.like l', 'p.id = l.post_id AND l.user_id') - ->eq($uid); - - if ($max) { - $query = $query - ->where('p.id')->le($max); - } - - if ($filter_uid) { - $query = $query - ->where('p.user_id')->eq($filter_uid); - } - - $posts = $query - ->order_by('p.id', 'DESC') - ->limit($this->page_size) - ->offset($offset) - ->rows(); - - $users = $this->cache_model->get_users($posts); - $max = 0; - - foreach ($posts as $post) { - $max = max($max, $post['id']); - $data = array(); - $data['page_size'] = $this->page_size; - $data['user'] = $users[$post['user_id']]; - $data['post'] = $post; - $this->view('template/post', $data); - } - - $query = $this->db - ->select('COUNT(p.id) as pc') - ->from('api.post p'); - - if ($filter_uid) { - $query = $query - ->where('p.user_id')->eq($filter_uid); - } - - $pc = $query - ->row()['pc']; - - return array( - 'loaded' => count($posts), - 'total' => $pc, - 'page_size' => $this->page_size, - 'max' => $max, - 'filter_uid' => $filter_uid - ); - } - - public function comment(): void { - $cid = $this->request_model->get_int('id', 0); - - $comment = $this->db - ->select('*') - ->from('api.comment') - ->where('id') - ->eq($cid) - ->row(); - - if (!$comment) { - return; - } - - $users = $this->cache_model->get_users([$comment]); - $uid = $comment['user_id']; - - if (!array_key_exists($uid, $users)) { - return; - } - - $user = $users[$uid]; - - $data = array( - 'user' => $user, - 'comment' => $comment - ); - $this->view('template/comment', $data); - } - - /** - * @return array - */ - public function comments(): array { - $page = $this->request_model->get_int('page', 0); - $max = $this->request_model->get_int('max'); - $id = $this->request_model->get_int('id', 0); - $offset = $page * $this->page_size; - - $query = $this->db - ->select('*') - ->from('api.comment') - ->where('post_id') - ->eq($id); - - if ($max) { - $query = $query - ->and() - ->where('id') - ->le($max); - } - - $comments = $query - ->order_by('id', 'ASC') - ->limit($this->page_size) - ->offset($offset) - ->rows(); - - $users = $this->cache_model->get_users($comments); - $max = 0; - - // only add this hr when not logged in - // otherwise its added automatically by - // the like and comment buttons - if ( - count($comments) && - $page == 0 && - $this->main->session === NULL - ) { - echo '
'; - } - - foreach ($comments as $comment) { - $max = max($max, $comment['id']); - $data = array(); - $data['user'] = $users[$comment['user_id']]; - $data['comment'] = $comment; - $this->view('template/comment', $data); - } - - return array( - 'loaded' => count($comments), - 'page_size' => $this->page_size, - 'max' => $max, - ); - } -} -- cgit v1.2.3-freya