load->model('UserModel', '', TRUE); $this->load->model('PostsModel', '', TRUE); $this->load->model('FileModel', '', TRUE); } public function index($user = "") { if ($user == "") { $title = "Error - Profile"; $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; } else { $userData = $this->UserModel->getUser($user); $userExists = !empty($userData); if ($userExists) { $userData = $userData[0]; $userStats = $this->UserModel->getUserStats($userData['ID']); $userPosts = $this->PostsModel->getUserPosts($userData['ID'], 3, 0, 192); $userComments = $this->UserModel->getUserComments($userData['ID'], 3, 0); $userBlogPosts = $this->UserModel->getUserBlogPosts($userData['ID'], 3, 0); $dateCreated = strtotime($userData['dateCreated']); $userData['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']); $title = $userData['displayname'] . " - Profile"; $isCurrentUserFollowing = false; if (isset($_SESSION['user']['ID'])) $isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $userData['ID']); $_SESSION['currentProfilePage'] = $userData['ID']; } else { $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; $title = "Error - Profile"; } } $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]); if (isset($message)) { $this->load->view('network/message', $message); } if (isset($userData) && isset($userStats) && isset($userPosts) && isset($userComments) && isset($userBlogPosts)) { $this->load->view('network/user/profile_page', ['data' => $userData, 'stats' => $userStats, 'posts' => $userPosts, 'comments' => $userComments, 'blog_posts' => $userBlogPosts, 'isCurrentUserFollowing' => $isCurrentUserFollowing]); } $this->load->view('footer', ['additionalScripts' => ['profile_page.js', 'comment-item.js']]); } public function comments($user = "") { if ($user == "") { $title = "Error - Profile"; $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; } $user_data = $this->UserModel->getUser($user); $user_exists = !empty($user_data); if ($user_exists) { $user_data = $user_data[0]; $dateCreated = strtotime($user_data['dateCreated']); $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']); $user_stats = $this->UserModel->getUserStats($user_data['ID']); $title = $user_data['displayname'] . " - Blog-Kommentare"; $isCurrentUserFollowing = false; if (isset($_SESSION['user']['ID'])) $isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $user_data['ID']); $_SESSION['currentProfilePage'] = $user_data['ID']; } else { $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; $title = "Error - Profile"; } $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]); if (isset($message)) { $this->load->view('network/message', $message); } if ($user_exists) { $this->load->view('network/blog/user_comments', ['data' => $user_data, 'stats' => $user_stats, 'isCurrentUserFollowing' => $isCurrentUserFollowing]); } $this->load->view('footer', ['additionalScripts' => ['profile_page.js', 'comment-item.js']]); $this->load->view('network/blog/user_comments_end', ['data' => $user_data]); } public function getComments() { $user = (int)$this->input->get('user'); $amount = (int)$this->input->get('amount'); $offset = (int)$this->input->get('offset') * $amount; $user_comments = $this->UserModel->getUserComments($user, $amount, $offset); $comment_user = $this->UserModel->getUserByID($user)[0]; foreach ($user_comments as $comment) { $this->load->view('network/blog/comment_item', ['data' => $comment_user, 'c' => $comment]); } } public function posts($user = "") { if ($user == "") { redirect(base_url('user')); } $user_data = $this->UserModel->getUser($user); $user_exists = !empty($user_data); if ($user_exists) { $user_data = $user_data[0]; $dateCreated = strtotime($user_data['dateCreated']); $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']); $user_stats = $this->UserModel->getUserStats($user_data['ID']); $title = $user_data['displayname'] . " - Posts"; $isCurrentUserFollowing = false; if (isset($_SESSION['user']['ID'])) $isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $user_data['ID']); $_SESSION['currentProfilePage'] = $user_data['ID']; } else { $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; $title = "Error - Profile"; } $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]); if (isset($message)) { $this->load->view('network/message', $message); } if ($user_exists) { $this->load->view('network/user/user_posts', ['data' => $user_data, 'stats' => $user_stats, 'isCurrentUserFollowing' => $isCurrentUserFollowing]); } $this->load->view('footer', ['additionalScripts' => ['profile_page.js']]); $this->load->view('network/user/user_posts_end', ['data' => $user_data]); } public function getPosts() { $user = (int)$this->input->get('user'); $amount = (int)$this->input->get('amount'); $offset = (int)$this->input->get('offset') * $amount; $user_posts = $this->PostsModel->getUserPosts($user, $amount, $offset); foreach ($user_posts as $post) { $this->load->view('network/posts/post_item', $post); } } public function blogposts($user = "") { if ($user == "") { redirect(base_url('user')); } $user_data = $this->UserModel->getUser($user); $user_exists = !empty($user_data); if ($user_exists) { $user_data = $user_data[0]; $dateCreated = strtotime($user_data['dateCreated']); $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']); $user_stats = $this->UserModel->getUserStats($user_data['ID']); $title = $user_data['displayname'] . " - Posts"; $isCurrentUserFollowing = false; if (isset($_SESSION['user']['ID'])) $isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $user_data['ID']); $_SESSION['currentProfilePage'] = $user_data['ID']; } else { $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; $title = "Error - Profile"; } $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]); if (isset($message)) { $this->load->view('network/message', $message); } if ($user_exists) { $this->load->view('network/blog/user_blog_posts', ['data' => $user_data, 'stats' => $user_stats, 'isCurrentUserFollowing' => $isCurrentUserFollowing]); } $this->load->view('footer', ['additionalScripts' => ['profile_page.js']]); $this->load->view('network/blog/user_blog_posts_end', ['data' => $user_data]); } public function getBlogPosts() { $user = (int)$this->input->get('user'); $amount = (int)$this->input->get('amount'); $offset = (int)$this->input->get('offset') * $amount; $user_posts = $this->UserModel->getUserBlogPosts($user, $amount, $offset); $post_user = $this->UserModel->getUserByID($user)[0]; foreach ($user_posts as $post) { $this->load->view('network/blog/blog_post_item', ['data' => $post_user, 'post' => $post]); } } public function uploadPostMedia() { if (!isset($_SESSION['user']) || empty($_SESSION['user'])) redirect(base_url()); if (empty($_FILES) || !isset($_FILES['postMedia'])) redirect(base_url()); header('Content-Type: application/json'); $file = $_FILES['postMedia']; list('name' => $name, 'type' => $type) = $file; switch (explode('/', $type)[0]) { case 'video': $path = $this->FileModel->uploadVideo('postMedia', 0, $name, 1920, $_SESSION['user']['username']); $mediaType = 'video'; break; case 'image': $path = $this->FileModel->uploadImage('postMedia', 0, $name, 1920, $_SESSION['user']['username']); $mediaType = 'image'; break; default: exit; break; } echo json_encode(['success' => true, 'type' => $mediaType, 'path' => $path]); } public function deletePostMedia() { if (!isset($_SESSION['user']) || empty($_SESSION['user'])) redirect(base_url()); if (empty($_POST) || !isset($_POST['path'])) redirect(base_url()); $url = $_POST['path']; $filePath = $this->FileModel->getFilePath(substr($url, 3), $_SESSION['user']['ID']); if ($filePath != null) unlink($filePath); } public function publishPost() { header('Content-Type: application/json'); if (!isset($_SESSION['user']) || empty($_SESSION['user'])) { echo json_encode(['success' => false, 'title' => lang('post_error_login_title'), 'message' => lang('post_error_login_lines') ]); exit; } $content = $this->input->post('content'); $content = trim($content); if (strlen($content) >= 10000) { echo json_encode(['success' => false, 'title' => lang('post_error_too_long_title'), 'message' => lang('post_error_too_long_lines') ]); exit; } if (strlen($content) == 0 && empty($media)) { echo json_encode(['success' => false, 'title' => lang('post_error_no_content_title'), 'message' => lang('post_error_no_content_lines') ]); exit; } $replyTo = $this->input->post('replyTo'); if ($replyTo !== "-1" && !$this->PostsModel->isHashIDValid($replyTo)) { echo json_encode(['success' => false, 'title' => lang('post_error_reply_title'), 'message' => lang('post_error_reply_lines') ]); exit; } if ($replyTo !== "-1") { $postID = $this->PostsModel->addReply($_SESSION['user']['ID'], $content, $replyTo); } else { $postID = $this->PostsModel->addPost($_SESSION['user']['ID'], $content); } $media = $this->input->post('postMedia'); if (!empty($media)) { $allowedMedia = []; foreach ($media as $entry) { $name = substr($entry['path'], 3); $file = $this->FileModel->getFileID($name, $_SESSION['user']['ID']); if (empty($file)) { continue; } $fileID = $file[0]['ID']; if ($entry['type'] === 'video' || $entry['type'] === 'audio') { $allowedMedia = [ [ 'type' => $entry['type'], 'fileID' => $fileID ] ]; break; } if (sizeof($allowedMedia) < 4) { $allowedMedia[] = [ 'type' => $entry['type'], 'fileID' => $fileID ]; } else { break; } } foreach ($allowedMedia as $entry) { $this->PostsModel->addMediaToPost($postID, $entry['type'], $entry['fileID']); } } echo json_encode(['success' => true, 'title' => lang('post_success_title'), 'message' => lang('post_success_lines'), 'buttons' => [ [ 'type' => 'default', 'text' => lang('post_success_no') ], [ 'type' => 'primary', 'action' => base_url('user/' . $_SESSION['user']['username'] . '/posts'), 'text' => lang('post_success_yes') ] ] ]); } public function followers($user = "") { if ($user == "") { $title = "Error - Profile"; $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; } $user_data = $this->UserModel->getUser($user); $user_exists = !empty($user_data); if ($user_exists) { $user_data = $user_data[0]; $dateCreated = strtotime($user_data['dateCreated']); $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']); $user_stats = $this->UserModel->getUserStats($user_data['ID']); $followers = $this->UserModel->getFollowers($user_data['ID']); $title = $user_data['displayname'] . " - Follower"; $isCurrentUserFollowing = false; if (isset($_SESSION['user']['ID'])) $isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $user_data['ID']); $_SESSION['currentProfilePage'] = $user_data['ID']; } else { $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; $title = "Error - Profile"; } $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]); if (isset($message)) { $this->load->view('network/message', $message); } if ($user_exists) { $this->load->view('network/user/user_followers', ['data' => $user_data, 'active' => 'followers', 'stats' => $user_stats, 'isCurrentUserFollowing' => $isCurrentUserFollowing, 'followers' => $followers]); } $this->load->view('footer', ['additionalScripts' => ['profile_page.js']]); } public function following($user = "") { if ($user == "") { $title = "Error - Profile"; $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; } $user_data = $this->UserModel->getUser($user); $user_exists = !empty($user_data); if ($user_exists) { $user_data = $user_data[0]; $dateCreated = strtotime($user_data['dateCreated']); $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']); $user_stats = $this->UserModel->getUserStats($user_data['ID']); $following = $this->UserModel->getFollowing($user_data['ID']); $title = $user_data['displayname'] . " - Follower"; $isCurrentUserFollowing = false; if (isset($_SESSION['user']['ID'])) $isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $user_data['ID']); $_SESSION['currentProfilePage'] = $user_data['ID']; } else { $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; $title = "Error - Profile"; } $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]); if (isset($message)) { $this->load->view('network/message', $message); } if ($user_exists) { $this->load->view('network/user/user_followers', ['data' => $user_data, 'active' => 'following', 'stats' => $user_stats, 'isCurrentUserFollowing' => $isCurrentUserFollowing, 'followers' => $following]); } $this->load->view('footer', ['additionalScripts' => ['profile_page.js']]); } public function switchFollowing() { header('Content-Type: application/json'); if (!isset($_SESSION['currentProfilePage'])) { $response = ['type' => 'error', 'code' => -1]; echo json_encode($response); exit; } $followedUser = $_SESSION['currentProfilePage']; // code 0: not logged in // code 1: same user // code 10: unfollowed // code 11: now following if (!isset($_SESSION['user']['username'])) { $response = ['type' => 'error', 'code' => 0]; echo json_encode($response); exit; } $follower = $_SESSION['user']['ID']; if ($follower == $followedUser) { $response = ['type' => 'error', 'code' => 1]; echo json_encode($response); exit; } if ($this->UserModel->isFollowing($follower, $followedUser)) { $this->UserModel->unfollow($follower, $followedUser); $response = ['type' => 'success', 'code' => 10]; echo json_encode($response); exit; } $this->UserModel->follow($follower, $followedUser); $response = ['type' => 'success', 'code' => 11]; echo json_encode($response); exit; } public function edit($user = "") { if ($user == "") { redirect(base_url('user')); } $user_data = $this->UserModel->getUser($user); $user_exists = !empty($user_data); if ($user_exists) { $user_data = $user_data[0]; // Update Settings $newData = []; // TODO: Error messages foreach ($_POST as $key => $item) { if (isset($user_data[$key]) && $user_data[$key] == $item) { unset($_POST[$key]); } } // Username if (isset($_POST['username'])) { if (!preg_match('/[^A-Za-z0-9._]/', $_POST['username'])) { if ($this->LoginModel->isAvailable($_POST['username'])) { if (strlen($_POST['username']) >= 4) { $newData['username'] = strtolower($_POST['username']); $newData['displayname'] = $_POST['username']; } else { $_SESSION['profileEditNotification'] .= "