load->model('UserModel', '', TRUE); $this->load->model('PostsModel', '', TRUE); } public function index() { if (isset($_SESSION['user']) && !empty($_SESSION['user'])) redirect(base_url('posts/feed')); redirect(base_url('posts/popular')); } public function feed() { if (!isset($_SESSION['user']) || empty($_SESSION['user'])) redirect(base_url('posts')); $this->load->view('header', ['active' => 'feed', 'title' => 'Dein Feed', 'additionalStyles' => ['posts_list.css']]); $this->load->view('network/posts/posts_list', ['active', 'feed']); $this->load->view('footer', ['additionalScripts' => ['post_feed.js', 'post_search.js']]); } public function getFeedPosts() { if (!isset($_SESSION['user']) || empty($_SESSION['user'])) redirect(base_url('posts')); $amount = (int)$this->input->get('amount'); $offset = (int)$this->input->get('offset') * $amount; $posts = $this->PostsModel->getFeedPosts($_SESSION['user']['ID'], $amount, $offset); foreach ($posts as $post) { $this->load->view('network/posts/post_item', $post); } } public function popular() { $this->load->view('header', ['active' => 'popular', 'title' => 'Beliebte Posts', 'additionalStyles' => ['posts_list.css']]); $this->load->view('network/posts/posts_list', ['active' => 'popular']); $this->load->view('footer', ['additionalScripts' => ['post_feed.js', 'post_search.js']]); } public function getPopularPosts() { $amount = (int)$this->input->get('amount'); $offset = (int)$this->input->get('offset') * $amount; $posts = $this->PostsModel->getPopularPosts($amount, $offset); foreach ($posts as $post) { $this->load->view('network/posts/post_item', $post); } } public function addPostLike() { header('Content-Type: application/json'); if (!isset($_SESSION['user']) || empty($_SESSION['user'])) { echo json_encode([ 'success' => false, 'message' => lang('post_like_account_missing') ]); exit; } $postUUID = $this->input->post('postUUID'); $isLiked = $this->PostsModel->addPostLikeByUUID($postUUID, $_SESSION['user']['ID']); $likeCount = $this->PostsModel->getPostLikeCountByUUID($postUUID); echo json_encode([ 'success' => true, 'message' => 'Du hast den Post erfolgreich bewertet.', 'isLiked' => $isLiked, 'likeCount' => $likeCount ]); } public function search() { $type = $this->input->get('type'); $query = $this->input->get('q'); $rank = $this->input->get('rank'); $this->load->view('header', ['active' => 'search', 'title' => 'Suche', 'additionalStyles' => ['posts_list.css']]); $this->load->view('network/posts/posts_list', ['active' => 'search', 'search' => ['query' => $query, 'type' => $type, 'rank' => $rank]]); $this->load->view('footer', ['additionalScripts' => ['post_search.js']]); } public function getSearchPosts() { $type = $this->input->get('type'); $query = $this->input->get('query'); $rank = $type == 'type-users' ? $this->input->get('rank') : ''; $lang = $type == 'type-users' ? $this->input->get('lang') : ''; $country = $type == 'type-users' ? $this->input->get('country') : ''; $amount = (int)$this->input->get('amount'); $offset = (int)$this->input->get('offset') * $amount; if ($type !== 'type-users' && $rank !== '' && $lang !== '' && strlen($query) < 4) { exit; } if (($type == 'type-all' && $offset == 0) || $type == 'type-users') { $userAmount = $type == 'type-users' ? $amount : 3; $userOffset = $type == 'type-users' ? $offset : 0; $users = $this->UserModel->searchUsers($query, $rank, $country, $lang, $userAmount, $userOffset); if (!empty($users)) { if($offset == 0) { echo '