diff --git a/application/config/routes.php b/application/config/routes.php
index 0d45370..9545bde 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -63,6 +63,8 @@
$route['user/getComments'] = 'user/getComments';
$route['user/getBlogPosts'] = 'user/getBlogPosts';
$route['user/publishPost'] = 'user/publishPost';
+ $route['user/uploadPostMedia'] = 'user/uploadPostMedia';
+ $route['user/deletePostMedia'] = 'user/deletePostMedia';
$route['user/switchFollowing'] = 'user/switchFollowing';
$route['user/getReportModal'] = 'user/getReportModal';
$route['user/(:any)'] = 'user/index/$1';
diff --git a/application/controllers/User.php b/application/controllers/User.php
index eaedef0..b0a079d 100644
--- a/application/controllers/User.php
+++ b/application/controllers/User.php
@@ -1,38 +1,74 @@
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 {
+ public function __construct()
+ {
+ parent::__construct('profile', 'language_names', 'country_names');
+ $this->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 {
+ $user_data = $this->UserModel->getUser($user);
+ $user_exists = !empty($user_data);
+ if ($user_exists) {
+ $user_data = $user_data[0];
+ $user_stats = $this->UserModel->getUserStats($user_data['ID']);
+
+ $user_posts = $this->PostsModel->getUserPosts($user_data['ID'], 3, 0, 192);
+ $user_comments = $this->UserModel->getUserComments($user_data['ID'], 3, 0);
+ $user_blog_posts = $this->UserModel->getUserBlogPosts($user_data['ID'], 3, 0);
+
+ $date_created = strtotime($user_data['date_created']);
+ $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$date_created"), $_SESSION['site_lang']);
+ $title = $user_data['displayname'] . " - Profile";
+ $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 (isset($user_data) && isset($user_stats) && isset($user_posts) && isset($user_comments) && isset($user_blog_posts)) {
+ $this->load->view('network/user/profile_page', ['data' => $user_data, 'stats' => $user_stats, 'posts' => $user_posts, 'comments' => $user_comments, 'blog_posts' => $user_blog_posts, 'isCurrentUserFollowing' => $isCurrentUserFollowing]);
+ }
+ $this->load->view('footer', ['additionalScripts' => ['profile_page.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['date_created']);
+ $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$dateCreated"), $_SESSION['site_lang']);
$user_stats = $this->UserModel->getUserStats($user_data['ID']);
-
- $user_posts = $this->PostsModel->getUserPosts($user_data['ID'], 3, 0, 192);
- $user_comments = $this->UserModel->getUserComments($user_data['ID'], 3, 0);
- $user_blog_posts = $this->UserModel->getUserBlogPosts($user_data['ID'], 3, 0);
-
- $date_created = strtotime($user_data['date_created']);
- $user_data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$date_created"), $_SESSION['site_lang']);
- $title = $user_data['displayname'] . " - Profile";
+ $title = $user_data['displayname'] . " - Blog-Kommentare";
$isCurrentUserFollowing = false;
if (isset($_SESSION['user']['ID']))
$isCurrentUserFollowing = $this->UserModel->isFollowing($_SESSION['user']['ID'], $user_data['ID']);
@@ -42,180 +78,181 @@ class User extends MY_Controller
$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']]);
+ $this->load->view('network/blog/user_comments_end', ['data' => $user_data]);
}
- $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['profile_page.css']]);
- if (isset($message)) {
- $this->load->view('network/message', $message);
- }
- if (isset($user_data) && isset($user_stats) && isset($user_posts) && isset($user_comments) && isset($user_blog_posts)) {
- $this->load->view('network/user/profile_page', ['data' => $user_data, 'stats' => $user_stats, 'posts' => $user_posts, 'comments' => $user_comments, 'blog_posts' => $user_blog_posts, 'isCurrentUserFollowing' => $isCurrentUserFollowing]);
- }
- $this->load->view('footer', ['additionalScripts' => ['profile_page.js']]);
- }
+ 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];
- public function comments($user = "")
- {
- if ($user == "") {
- $title = "Error - Profile";
- $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."];
+ foreach ($user_comments as $comment) {
+ $this->load->view('network/blog/comment_item', ['data' => $comment_user, 'c' => $comment]);
+ }
}
- $user_data = $this->UserModel->getUser($user);
- $user_exists = !empty($user_data);
- if ($user_exists) {
- $user_data = $user_data[0];
- $dateCreated = strtotime($user_data['date_created']);
- $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']);
+ public function posts($user = "")
+ {
+ if ($user == "") {
+ redirect(base_url('user'));
+ }
- $_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";
+ $user_data = $this->UserModel->getUser($user);
+ $user_exists = !empty($user_data);
+ if ($user_exists) {
+ $user_data = $user_data[0];
+ $dateCreated = strtotime($user_data['date_created']);
+ $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);
- $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']]);
- $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'));
+ foreach ($user_posts as $post) {
+ $this->load->view('network/posts/post_item', $post);
+ }
}
- $user_data = $this->UserModel->getUser($user);
- $user_exists = !empty($user_data);
- if ($user_exists) {
- $user_data = $user_data[0];
- $dateCreated = strtotime($user_data['date_created']);
- $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']);
+ public function blogposts($user = "")
+ {
+ if ($user == "") {
+ redirect(base_url('user'));
+ }
- $_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";
+ $user_data = $this->UserModel->getUser($user);
+ $user_exists = !empty($user_data);
+ if ($user_exists) {
+ $user_data = $user_data[0];
+ $dateCreated = strtotime($user_data['date_created']);
+ $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]);
}
- $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 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];
- 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'));
+ foreach ($user_posts as $post) {
+ $this->load->view('network/blog/blog_post_item', ['data' => $post_user, 'post' => $post]);
+ }
}
- $user_data = $this->UserModel->getUser($user);
- $user_exists = !empty($user_data);
- if ($user_exists) {
- $user_data = $user_data[0];
- $dateCreated = strtotime($user_data['date_created']);
- $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']);
+ public function uploadPostMedia()
+ {
+ if (!isset($_SESSION['user']) || empty($_SESSION['user']))
+ redirect(base_url());
- $_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";
+ 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]);
}
- $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 deletePostMedia() {
+ if (!isset($_SESSION['user']) || empty($_SESSION['user']))
+ redirect(base_url());
- 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];
+ if(empty($_POST) || !isset($_POST['path']))
+ redirect(base_url());
- foreach ($user_posts as $post) {
- $this->load->view('network/blog/blog_post_item', ['data' => $post_user, 'post' => $post]);
+ $url = $_POST['path'];
+
+ $filePath = $this->FileModel->getFilePath(substr($url, 3), $_SESSION['user']['ID']);
+
+ if($filePath != null)
+ unlink($filePath);
}
- }
- public function publishPost()
- {
- if (!isset($_SESSION['user']) || empty($_SESSION['user'])) {
- ?>
-
-
Veröffentlichen des Posts fehlgeschlagen!
- Du musst in deinen Account eingeloggt sein, um Posts erstellen zu können.
-
- Bitte erstelle dir entweder
-
kostenlos einen neuen Account
- oder
-
melde dich an
- .
-
- false,
+ 'title' => lang('post_error_login_title'),
+ 'message' => lang('post_error_login_lines')
+ ]);
+ exit;
+ }
$content = $this->input->post('content');
if (strlen($content) >= 10000) {
@@ -247,16 +284,41 @@ class User extends MY_Controller
$postID = $this->PostsModel->addPost($_SESSION['user']['ID'], $content);
}
- $media = $this->input->post('postMedia');
- if (!empty($media)) {
- foreach ($media as $entry) {
- $image = str_replace(' ', '+', $entry['image']);
- $image = substr($image, strpos($image, ',') + 1);
- $image = base64_decode($image);
+ $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']);
- $fileUrl = $this->FileModel->uploadFileByContent($image, $entry['name'], $entry['type'], $entry['size']);
+ if (empty($file)) {
+ continue;
+ }
- $this->PostsModel->addImageToPost($postID, $fileUrl);
+ $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']);
+ }
}
?>
@@ -264,363 +326,363 @@ class User extends MY_Controller
Dein Post wurde erfolgreich veröffentlicht! Möchtest du nun deine Posts ansehen?
Nein
'
- class='btn btn-sm btn-primary'>Ja
+ class='btn btn-sm btn-primary'>Ja
+
"danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."];
+ 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['date_created']);
+ $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']]);
}
- $user_data = $this->UserModel->getUser($user);
- $user_exists = !empty($user_data);
- if ($user_exists) {
- $user_data = $user_data[0];
- $dateCreated = strtotime($user_data['date_created']);
- $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']);
+ public function following($user = "")
+ {
+ if ($user == "") {
+ $title = "Error - Profile";
+ $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."];
+ }
- $_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";
+ $user_data = $this->UserModel->getUser($user);
+ $user_exists = !empty($user_data);
+ if ($user_exists) {
+ $user_data = $user_data[0];
+ $dateCreated = strtotime($user_data['date_created']);
+ $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']]);
}
- $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 switchFollowing()
+ {
+ header('Content-Type: application/json');
+ if (!isset($_SESSION['currentProfilePage'])) {
+ $response = ['type' => 'error', 'code' => -1];
+ echo json_encode($response);
+ exit;
+ }
- public function following($user = "")
- {
- if ($user == "") {
- $title = "Error - Profile";
- $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."];
- }
+ $followedUser = $_SESSION['currentProfilePage'];
- $user_data = $this->UserModel->getUser($user);
- $user_exists = !empty($user_data);
- if ($user_exists) {
- $user_data = $user_data[0];
- $dateCreated = strtotime($user_data['date_created']);
- $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']);
+ // code 0: not logged in
+ // code 1: same user
+ // code 10: unfollowed
+ // code 11: now following
- $_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";
- }
+ if (!isset($_SESSION['user']['username'])) {
+ $response = ['type' => 'error', 'code' => 0];
+ echo json_encode($response);
+ exit;
+ }
- $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']]);
- }
+ $follower = $_SESSION['user']['ID'];
- public function switchFollowing()
- {
- header('Content-Type: application/json');
- if (!isset($_SESSION['currentProfilePage'])) {
- $response = ['type' => 'error', 'code' => -1];
+ 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;
}
- $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
- // 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'] .= "Zu kurzer Nutzername! Dein Name muss 4 Zeichen oder mehr enthalten.
";
- }
- } else {
- $_SESSION['profileEditNotification'] .= "Nutzername bereits vergeben! Ein anderer Nutzer hat anscheinend diesen Namen bereits gewählt.
";
- }
- } else {
- $_SESSION['profileEditNotification'] .= "Ungültiger Nutzername! Dein Name darf nur Groß- (A-Z) und Kleinbuchstaben (a-z), Zahlen (0-9) und Punkte (.) sowie Unterstriche (_).
";
- }
+ public function edit($user = "")
+ {
+ if ($user == "") {
+ redirect(base_url('user'));
}
- // Gender
- if (isset($_POST['gender'])) {
- if ($_POST['gender'] == "male" || $_POST['gender'] == "female" || $_POST['gender'] == 'other') {
- $newData['gender'] = $_POST['gender'];
- }
- }
- // Birth date
- if (isset($_POST['birthdate-day']) && isset($_POST['birthdate-month'])) {
- $day = intval($_POST['birthdate-day']);
- $month = intval($_POST['birthdate-month']);
- if ($month > 0 && $month <= 12) {
- $monthDayCount = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- if ($day <= $monthDayCount[$month - 1]) {
- $newData['birthdate'] = $day . '.' . $month . '.';
- }
- }
- }
- if (isset($_POST['birthdate-year'])) {
- }
- // Language
- if (isset($_POST['language'])) {
- $newData['language'] = $_POST['language'];
- }
- // Country
- if (isset($_POST['country'])) {
- $newData['country'] = $_POST['country'];
- }
- // Biography/About
- if (isset($_POST['biography'])) {
- $newData['about'] = $_POST['biography'];
- }
- // Avatar
- if (isset($_FILES['avatar'])) {
- $image = $this->FileModel->uploadCroppedImage('avatar', 4096, $_FILES['avatar']['name'], 500, 500);
- if ($image != null)
- $newData['profile_picture'] = $image;
- unset($_FILES['avatar']);
- }
- // Header
- if (isset($_FILES['header'])) {
- $image = $this->FileModel->uploadImage('header', 4096, $_FILES['header']['name'], 1920);
- if ($image != null)
- $newData['header_image'] = $image;
- unset($_FILES['header']);
- }
- // Social Networks
- if (isset($_POST['social-networks'])) {
-
- }
- // Profile color
- if (isset($_POST['color'])) {
-
- }
- // E-Mail-Address
- if (isset($_POST['email'])) {
- if (isset($_POST['email-password']) && !empty($_POST['email-password'])) {
- $loginData = $this->LoginModel->getLoginData($_SESSION['user']['username']);
- if (empty($loginData)) {
- $_SESSION['profileEditNotification'] .= "Ungültiger Account Anscheinend versuchst du die E-Mail-Adresse eines nicht existierenden Accounts zu ändern. Sollte es sich um einen Fehler handeln, kontaktiere bitte das Website-Team!
";
- } else {
- $loginData = $loginData[0];
- $encryptedPassword = $this->LoginModel->getPasswordHash($_POST['email-password'], $loginData['original_name']);
- if ($loginData['password'] == $encryptedPassword) {
- $isRegistered = $this->LoginModel->isRegistered($_POST['email']);
- if ($isRegistered == "") {
- $trashMail = $this->LoginModel->isTrashMail($_POST['email']);
- if ($trashMail == '') {
- $this->LoginModel->changeMailAddress($_POST['email'], $loginData['username']);
- $_SESSION['profileEditNotification'] .= "Deine E-Mail-Adresse wurde geändert! Nun musst du nur noch in deinem Postfach vorbeischauen und die neue Adresse aktivieren.
";
- } else {
- $_SESSION['profileEditNotification'] .= $trashMail;
- }
+ $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
+ // 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'] .= $isRegistered;
+ $_SESSION['profileEditNotification'] .= "Zu kurzer Nutzername! Dein Name muss 4 Zeichen oder mehr enthalten.
";
}
} else {
- $_SESSION['profileEditNotification'] .= "Ungültiges Passwort! Es scheint als wäre das eingegebene Passwort nicht mit dem richtigen übereinstimmend.
";
- }
- }
- } else {
- $_SESSION['profileEditNotification'] .= "Bitte gib dein Passwort ein! Das Ändern der E-Mail-Adresse ist ein tiefgreifender Eingriff in den Account. Daher benötigen wir zur Sicherheit nochmal dein Passwort.
";
- }
- }
-
- // Notifications
- if (isset($_POST['email-notifications'])) {
- $newData['receiveEmails'] = filter_var($_POST['email-notifications'], FILTER_VALIDATE_BOOLEAN);
- }
-
- // Newsletter
- if (isset($_POST['newsletter'])) {
- $newData['receiveNewsletter'] = filter_var($_POST['newsletter'], FILTER_VALIDATE_BOOLEAN);
- }
-
- // Password
- if (isset($_POST['passwordNew'])) {
- if (isset($_POST['passwordOld'])) {
- $loginData = $this->LoginModel->getLoginData($_SESSION['user']['username']);
- if (!empty($loginData)) {
- $loginData = $loginData[0];
- $encryptedPassword = $this->LoginModel->getPasswordHash($_POST['passwordOld'], $loginData['original_name']);
- if ($encryptedPassword == $loginData['password']) {
- if ($this->LoginModel->checkPassword($_POST['passwordNew'])) {
- if (isset($_POST['passwordNewRepeat']) && $_POST['passwordNew'] == $_POST['passwordNewRepeat']) {
- $this->LoginModel->changePassword($_POST['passwordNew'], $loginData['original_name']);
- $_SESSION['profileEditNotification'] .= "Dein Passwort wurde geändert! Du kannst dich nun damit einloggen
";
- } else {
- $_SESSION['profileEditNotification'] .= "Wiederholtes Passwort falsch! Das Passwort, das du wiederholt hast, stimmt nicht mit dem eigentlichen überein.
";
- }
- } else {
- $_SESSION['profileEditNotification'] .= "Zu unsicheres Passwort! Dein Passwort sollte mindest 8 Zeichen lang sein und jeweils einen Groß-, einen Kleinbuchstaben, eine Zahl und ein Sonderzeichen enthalten.
";
- }
- } else {
- $_SESSION['profileEditNotification'] .= "Altes Passwort falsch! Dein altes eingegebenes Passwort ist falsch!
";
+ $_SESSION['profileEditNotification'] .= "Nutzername bereits vergeben! Ein anderer Nutzer hat anscheinend diesen Namen bereits gewählt.
";
}
} else {
- $_SESSION['profileEditNotification'] .= "Ungültiger Account Anscheinend versuchst du die E-Mail-Adresse eines nicht existierenden Accounts zu ändern. Sollte es sich um einen Fehler handeln, kontaktiere bitte das Website-Team!
";
+ $_SESSION['profileEditNotification'] .= "Ungültiger Nutzername! Dein Name darf nur Groß- (A-Z) und Kleinbuchstaben (a-z), Zahlen (0-9) und Punkte (.) sowie Unterstriche (_).
";
}
- } else {
- $_SESSION['profileEditNotification'] .= "Altes Passwort fehlend! Bitte gib dein altes Passwort ebenfalls ein!
";
}
- }
- if (isset($_POST['showAds'])) {
- if ($this->hasPermission('user.disableAds')) {
- $newData['showAds'] = filter_var($_POST['email-notifications'], FILTER_VALIDATE_BOOLEAN);
- } else {
- $_SESSION['profileEditNotification'] .= "Du bist dazu nicht berechtigt! Um diese Einstellung zu verändern, musst du mindestens ein Premium-Nutzer oder höher sein!
";
+ // Gender
+ if (isset($_POST['gender'])) {
+ if ($_POST['gender'] == "male" || $_POST['gender'] == "female" || $_POST['gender'] == 'other') {
+ $newData['gender'] = $_POST['gender'];
+ }
}
- }
- if (!empty($newData)) {
- // Add entry to history
- unset($user_data['rankName']);
- unset($_SESSION['user']);
- $this->UserModel->insertIntoHistory($user_data);
- // Update profile
- $this->UserModel->updateProfile($newData, $user_data['ID']);
- $this->db->cache_delete('user', $user_data['username']);
+ // Birth date
+ if (isset($_POST['birthdate-day']) && isset($_POST['birthdate-month'])) {
+ $day = intval($_POST['birthdate-day']);
+ $month = intval($_POST['birthdate-month']);
+ if ($month > 0 && $month <= 12) {
+ $monthDayCount = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+ if ($day <= $monthDayCount[$month - 1]) {
+ $newData['birthdate'] = $day . '.' . $month . '.';
+ }
+ }
+ }
+ if (isset($_POST['birthdate-year'])) {
- $this->LoginModel->reloadLoginSession($user_data);
+ }
+ // Language
+ if (isset($_POST['language'])) {
+ $newData['language'] = $_POST['language'];
+ }
+ // Country
+ if (isset($_POST['country'])) {
+ $newData['country'] = $_POST['country'];
+ }
+ // Biography/About
+ if (isset($_POST['biography'])) {
+ $newData['about'] = $_POST['biography'];
+ }
+ // Avatar
+ if (isset($_FILES['avatar'])) {
+ $image = $this->FileModel->uploadCroppedImage('avatar', 4096, $_FILES['avatar']['name'], 500, 500);
+ if ($image != null)
+ $newData['profile_picture'] = $image;
+ unset($_FILES['avatar']);
+ }
+ // Header
+ if (isset($_FILES['header'])) {
+ $image = $this->FileModel->uploadImage('header', 4096, $_FILES['header']['name'], 1920);
+ if ($image != null)
+ $newData['header_image'] = $image;
+ unset($_FILES['header']);
+ }
+ // Social Networks
+ if (isset($_POST['social-networks'])) {
- redirect(base_url(uri_string()));
+ }
+ // Profile color
+ if (isset($_POST['color'])) {
+
+ }
+ // E-Mail-Address
+ if (isset($_POST['email'])) {
+ if (isset($_POST['email-password']) && !empty($_POST['email-password'])) {
+ $loginData = $this->LoginModel->getLoginData($_SESSION['user']['username']);
+ if (empty($loginData)) {
+ $_SESSION['profileEditNotification'] .= "Ungültiger Account Anscheinend versuchst du die E-Mail-Adresse eines nicht existierenden Accounts zu ändern. Sollte es sich um einen Fehler handeln, kontaktiere bitte das Website-Team!
";
+ } else {
+ $loginData = $loginData[0];
+ $encryptedPassword = $this->LoginModel->getPasswordHash($_POST['email-password'], $loginData['original_name']);
+ if ($loginData['password'] == $encryptedPassword) {
+ $isRegistered = $this->LoginModel->isRegistered($_POST['email']);
+ if ($isRegistered == "") {
+ $trashMail = $this->LoginModel->isTrashMail($_POST['email']);
+ if ($trashMail == '') {
+ $this->LoginModel->changeMailAddress($_POST['email'], $loginData['username']);
+ $_SESSION['profileEditNotification'] .= "Deine E-Mail-Adresse wurde geändert! Nun musst du nur noch in deinem Postfach vorbeischauen und die neue Adresse aktivieren.
";
+ } else {
+ $_SESSION['profileEditNotification'] .= $trashMail;
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= $isRegistered;
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= "Ungültiges Passwort! Es scheint als wäre das eingegebene Passwort nicht mit dem richtigen übereinstimmend.
";
+ }
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= "Bitte gib dein Passwort ein! Das Ändern der E-Mail-Adresse ist ein tiefgreifender Eingriff in den Account. Daher benötigen wir zur Sicherheit nochmal dein Passwort.
";
+ }
+ }
+
+ // Notifications
+ if (isset($_POST['email-notifications'])) {
+ $newData['receiveEmails'] = filter_var($_POST['email-notifications'], FILTER_VALIDATE_BOOLEAN);
+ }
+
+ // Newsletter
+ if (isset($_POST['newsletter'])) {
+ $newData['receiveNewsletter'] = filter_var($_POST['newsletter'], FILTER_VALIDATE_BOOLEAN);
+ }
+
+ // Password
+ if (isset($_POST['passwordNew'])) {
+ if (isset($_POST['passwordOld'])) {
+ $loginData = $this->LoginModel->getLoginData($_SESSION['user']['username']);
+ if (!empty($loginData)) {
+ $loginData = $loginData[0];
+ $encryptedPassword = $this->LoginModel->getPasswordHash($_POST['passwordOld'], $loginData['original_name']);
+ if ($encryptedPassword == $loginData['password']) {
+ if ($this->LoginModel->checkPassword($_POST['passwordNew'])) {
+ if (isset($_POST['passwordNewRepeat']) && $_POST['passwordNew'] == $_POST['passwordNewRepeat']) {
+ $this->LoginModel->changePassword($_POST['passwordNew'], $loginData['original_name']);
+ $_SESSION['profileEditNotification'] .= "Dein Passwort wurde geändert! Du kannst dich nun damit einloggen
";
+ } else {
+ $_SESSION['profileEditNotification'] .= "Wiederholtes Passwort falsch! Das Passwort, das du wiederholt hast, stimmt nicht mit dem eigentlichen überein.
";
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= "Zu unsicheres Passwort! Dein Passwort sollte mindest 8 Zeichen lang sein und jeweils einen Groß-, einen Kleinbuchstaben, eine Zahl und ein Sonderzeichen enthalten.
";
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= "Altes Passwort falsch! Dein altes eingegebenes Passwort ist falsch!
";
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= "Ungültiger Account Anscheinend versuchst du die E-Mail-Adresse eines nicht existierenden Accounts zu ändern. Sollte es sich um einen Fehler handeln, kontaktiere bitte das Website-Team!
";
+ }
+ } else {
+ $_SESSION['profileEditNotification'] .= "Altes Passwort fehlend! Bitte gib dein altes Passwort ebenfalls ein!
";
+ }
+ }
+ if (isset($_POST['showAds'])) {
+ if ($this->hasPermission('user.disableAds')) {
+ $newData['showAds'] = filter_var($_POST['email-notifications'], FILTER_VALIDATE_BOOLEAN);
+ } else {
+ $_SESSION['profileEditNotification'] .= "Du bist dazu nicht berechtigt! Um diese Einstellung zu verändern, musst du mindestens ein Premium-Nutzer oder höher sein!
";
+ }
+ }
+ if (!empty($newData)) {
+ // Add entry to history
+ unset($user_data['rankName']);
+ unset($_SESSION['user']);
+ $this->UserModel->insertIntoHistory($user_data);
+ // Update profile
+ $this->UserModel->updateProfile($newData, $user_data['ID']);
+ $this->db->cache_delete('user', $user_data['username']);
+
+ $this->LoginModel->reloadLoginSession($user_data);
+
+ redirect(base_url(uri_string()));
+ }
+
+ $user_stats = $this->UserModel->getUserStats($user_data['ID']);
+ $title = $user_data['displayname'] . ' - Profil bearbeiten';
}
- $user_stats = $this->UserModel->getUserStats($user_data['ID']);
- $title = $user_data['displayname'] . ' - Profil bearbeiten';
+ $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['lib/selectize.css', 'lib/selectize.bootstrap3.css', 'lib/bootstrap-colorpicker.min.css', 'profile_page.css']]);
+ $editMessage = isset($_SESSION['profileEditNotification']) ? $_SESSION['profileEditNotification'] : "";
+ $_SESSION['profileEditNotification'] = "";
+ if (isset($message)) {
+ $this->load->view('network/message', $message);
+ }
+ if ($user_exists) {
+ $this->load->view('network/user/profile_edit', ['message' => $editMessage, 'data' => $user_data, 'stats' => $user_stats]);
+ }
+ $this->load->view('footer', ['additionalScripts' => ['lib/selectize.js', 'lib/bootstrap-colorpicker.min.js', 'profile_page.js', 'profile_edit.js']]);
}
- $this->load->view('header', ['active' => 'profile', 'title' => $title, 'additionalStyles' => ['lib/selectize.css', 'lib/selectize.bootstrap3.css', 'lib/bootstrap-colorpicker.min.css', 'profile_page.css']]);
- $editMessage = isset($_SESSION['profileEditNotification']) ? $_SESSION['profileEditNotification'] : "";
- $_SESSION['profileEditNotification'] = "";
- if (isset($message)) {
- $this->load->view('network/message', $message);
+ public function single_post($username = null, $uuid = null, $origin = null)
+ {
+ $origin = isset($_GET['o']) ? $_GET['o'] : null;
+ if ($origin == null) {
+ $origin = base_url('user/' . $username);
+ } else {
+ $origin = base64_decode(urldecode($origin));
+ }
+
+ $this->load->view('header', ['active' => 'profile', 'title' => 'Test']);
+ $this->load->view('network/posts/user_post_page', ['origin' => $origin, 'username' => $username, 'uuid' => $uuid]);
+ $this->load->view('footer', ['additionalScripts' => ['single-post-page.js']]);
}
- if ($user_exists) {
- $this->load->view('network/user/profile_edit', ['message' => $editMessage, 'data' => $user_data, 'stats' => $user_stats]);
+
+ public function single_post_data($username = null, $uuid = null)
+ {
+ $message = "";
+ $post = [];
+ $replies = [];
+ if ($username == null) {
+ $message .= 'Es wurde kein Nutzer angegeben! Es können keine Posts von einem undefinierten Nutzer gefunden werden.
';
+ goto display;
+ }
+ if ($uuid == null) {
+ $message .= 'Es wurde keine Post-ID angegeben! Es können keine undefinierten Posts gefunden werden.
';
+ goto display;
+ }
+
+ $user = $this->UserModel->getUser($username);
+ if (empty($user)) {
+ $message .= 'Es wurde kein Nutzer mit dem angegebenen Namen gefunden! Vielleicht kannst du ja diese Lücke füllen?
';
+ goto display;
+ }
+ $user = $user[0];
+
+ $post = $this->PostsModel->getPostDetails($user['ID'], $uuid);
+ if (empty($post)) {
+ $message .= 'Es wurde kein Post mit der angegebenen ID gefunden! Vielleicht kannst du ja diesen neuen Content erschaffen?
';
+ goto display;
+ }
+ $post = $post[0];
+
+ $replies = $this->PostsModel->getPostReplies($post['ID']);
+
+ display:
+ $this->load->view('network/posts/user_post_content', ['message' => $message, 'post' => $post, 'replies' => $replies]);
+
}
- $this->load->view('footer', ['additionalScripts' => ['lib/selectize.js', 'lib/bootstrap-colorpicker.min.js', 'profile_page.js', 'profile_edit.js']]);
}
-
- public function single_post($username = null, $uuid = null, $origin = null)
- {
- $origin = isset($_GET['o']) ? $_GET['o'] : null;
- if ($origin == null) {
- $origin = base_url('user/' . $username);
- } else {
- $origin = base64_decode(urldecode($origin));
- }
-
- $this->load->view('header', ['active' => 'profile', 'title' => 'Test']);
- $this->load->view('network/posts/user_post_page', ['origin' => $origin, 'username' => $username, 'uuid' => $uuid]);
- $this->load->view('footer', ['additionalScripts' => ['single-post-page.js']]);
- }
-
- public function single_post_data($username = null, $uuid = null)
- {
- $message = "";
- $post = [];
- $replies = [];
- if ($username == null) {
- $message .= 'Es wurde kein Nutzer angegeben! Es können keine Posts von einem undefinierten Nutzer gefunden werden.
';
- goto display;
- }
- if ($uuid == null) {
- $message .= 'Es wurde keine Post-ID angegeben! Es können keine undefinierten Posts gefunden werden.
';
- goto display;
- }
-
- $user = $this->UserModel->getUser($username);
- if (empty($user)) {
- $message .= 'Es wurde kein Nutzer mit dem angegebenen Namen gefunden! Vielleicht kannst du ja diese Lücke füllen?
';
- goto display;
- }
- $user = $user[0];
-
- $post = $this->PostsModel->getPostDetails($user['ID'], $uuid);
- if (empty($post)) {
- $message .= 'Es wurde kein Post mit der angegebenen ID gefunden! Vielleicht kannst du ja diesen neuen Content erschaffen?
';
- goto display;
- }
- $post = $post[0];
-
- $replies = $this->PostsModel->getPostReplies($post['ID']);
-
- display:
- $this->load->view('network/posts/user_post_content', ['message' => $message, 'post' => $post, 'replies' => $replies]);
-
- }
-}
diff --git a/application/language/de/header_lang.php b/application/language/de/header_lang.php
index a866b13..7d2fcc2 100644
--- a/application/language/de/header_lang.php
+++ b/application/language/de/header_lang.php
@@ -52,5 +52,5 @@
$lang['header_post'] = 'Post';
$lang['header_post_title'] = 'Post verfassen';
$lang['header_post_content'] = 'Inhalt';
- $lang['header_post_notice'] = 'Es wird an einer Funktion zum Uploaden von Fotos, Videos und anderen Medien gearbeitet. In hoffentlich naher Zukunft wirst du auch die Möglichkeit haben, diese zu deinen Posts hinzuzufügen!';
+ $lang['header_post_notice'] = 'Derzeit arbeiten wir intensiv daran, dir die Möglichkeit zu bieten, neben Bildern und Videos auch Audio-Aufnahmen hinzuzufügen und vor allem mithilfe von unter anderem einer direkten Kamera-Integration das Nutzererlebnis deutlich besser zu gestalten. Auch möchten wir die Text-Eingabe deutlich komfortabler gestalten. Also, stay tuned!';
$lang['header_post_publish'] = 'Veröffentlichen';
diff --git a/application/language/de/profile_lang.php b/application/language/de/profile_lang.php
index b043f22..bc25b90 100644
--- a/application/language/de/profile_lang.php
+++ b/application/language/de/profile_lang.php
@@ -61,3 +61,27 @@
$lang['post_copy_link'] = 'Link zum Post kopieren';
$lang['post_report'] = 'Post melden';
$lang['post_delete'] = 'Post löschen';
+
+ $lang['post_error_login_title'] = 'Veröffentlichung des Posts nicht möglich!';
+ $lang['post_error_login_lines'] = [
+ 'Du musst in deinen Account eingeloggt sein, um Posts erstellen zu können.',
+ 'Bitte erstelle dir entweder kostenlos einen neuen Account oder melde dich an .'
+ ];
+ $lang['post_error_too_long_title'] = 'Veröffentlichung des Posts fehlgeschlagen!';
+ $lang['post_error_too_long_lines'] = [
+ 'Dein Post ist leider zu lang. Er darf maximal 10.000 Zeichen umfassen.',
+ ];
+ $lang['post_error_reply_title'] = 'Veröffentlichung des Posts fehlgeschlagen!';
+ $lang['post_error_reply_lines'] = [
+ 'Der Post, an den du deine Antwort richten willst, existiert nicht (mehr).',
+ 'Solltest du dies für einen Fehler halten, versuche es später erneut oder kontaktiere uns.',
+ ];
+ $lang['post_error_no_conent_title'] = 'Veröffentlichung des Posts nicht möglich!';
+ $lang['post_error_no_conent_lines'] = [
+ 'Du hast uns leider keinen Inhalt angegeben, den wir veröffentlichen können.',
+ 'Sollte es sich dabei um ein Irrtum handeln, so kontaktiere uns bitte über das Kontakt-Formular.',
+ ];
+ $lang['post_success_title'] = '';
+ $lang['post_success_lines'] = [
+ '',
+ ];
diff --git a/application/models/FileModel.php b/application/models/FileModel.php
index dc9b398..3497669 100644
--- a/application/models/FileModel.php
+++ b/application/models/FileModel.php
@@ -11,8 +11,24 @@ class FileModel extends CI_Model
parent::__construct();
}
- private function getPath($fileName, $userContent) {
- return 'files/' . ($userContent ? 'userContent/' : '') . $fileName;
+ private function getPath($fileName, $user) {
+ return 'files/' . ($user != null ? 'userContent/' . $user . '/' : '') . $fileName;
+ }
+
+ private function addToDatabase($name, $originalName, $type, $size, $path, $user) {
+ $userID = NULL;
+ if(is_string($user)) {
+ $user = $this->db->query('SELECT ID FROM users WHERE username = lower(?)', [$user])->result_array();
+ if(!empty($user)) {
+ $userID = $user[0]['ID'];
+ }
+ } else if(is_integer($user)) {
+ $userID = $user;
+ }
+
+ $this->db->query('INSERT INTO files (name, original_name, type, size, path, user) VALUES (?, ?, ?, ?, ?, ?)', [$name, $originalName, $type, $size, $path, $userID]);
+
+ $this->db->cache_delete('admin', 'files');
}
public function uploadFile($original_name, $tmpname, $size, $type, $userContent = true)
@@ -28,20 +44,51 @@ class FileModel extends CI_Model
$target_file = str_replace('\\', '/', $target_file);
- $this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file, $userContent]);
-
- $this->db->cache_delete('admin', 'files');
+ $this->addToDatabase($name, $original_name, $type, $size, $target_file, $userContent);
echo shell_exec('python /var/www/codeigniter/duplicates.py');
return "/f/" . $name;
}
- public function uploadImage($name, $max_size, $originalname, $max_width, $userContent = true) {
- $config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
+ public function uploadVideo($name, $max_size, $originalName, $max_width, $user = null) {
+ $path = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
+ if($user !== null) {
+ $path .= 'userContent' . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR;
+ }
+ $config['upload_path'] = $path;
+
+ if(!file_exists($path)) {
+ mkdir($path, 0777);
+ }
+
+ $config['allowed_types'] = 'mp4';
+ $config['max_size'] = $max_size;
+ $config['file_name'] = $this->generateName() . '.' . pathinfo(basename($originalName), PATHINFO_EXTENSION);
+
+ $this->load->library('upload', $config);
+
+ if(!$this->upload->do_upload($name)) {
+ return null;
+ } else {
+ $data = $this->upload->data();
+
+ $this->upload->display_errors();
+
+ $this->addToDatabase($data['raw_name'], $originalName, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $user), $user);
+
+ return '/f/' . $data['raw_name'];
+ }
+ }
+
+ public function uploadImage($name, $max_size, $originalName, $max_width, $user = null) {
+ $config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
+ if($user != null) {
+ $config['upload_path'] .= 'userContent' . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR;
+ }
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = $max_size;
- $config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalname), PATHINFO_EXTENSION);
+ $config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalName), PATHINFO_EXTENSION);
$this->load->library('upload', $config);
@@ -60,9 +107,7 @@ class FileModel extends CI_Model
$this->image_lib->resize();
- $this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$data['raw_name'], $originalname, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $userContent), $userContent]);
-
- $this->db->cache_delete('admin', 'files');
+ $this->addToDatabase($data['raw_name'], $originalName, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $user), $user);
echo shell_exec('python /var/www/codeigniter/duplicates.py');
@@ -164,6 +209,16 @@ class FileModel extends CI_Model
return $result;
}
+ public function getFileID($name, $userID = null) {
+ $result = $this->db->query('SELECT ID FROM files WHERE name = ? AND user = ?', [$name, $userID])->result_array();
+ return $result;
+ }
+
+ public function getFilePath($name, $userID = null) {
+ $result = $this->db->query('SELECT path FROM files WHERE name = ? AND user = ?', [$name, $userID])->result_array();
+ return !empty($result) ? $result[0]['path'] : null;
+ }
+
public function delete($id) {
$filePath = $this->db->query('SELECT path FROM files WHERE ID = ? LIMIT 1', [$id])->result_array()[0];
unlink($filePath['path']);
diff --git a/application/models/PostsModel.php b/application/models/PostsModel.php
index ba38ffa..b841b06 100644
--- a/application/models/PostsModel.php
+++ b/application/models/PostsModel.php
@@ -48,8 +48,8 @@
$this->db->query('DELETE FROM user_posts_media WHERE postID = ?', [$postID]);
}
- public function addImageToPost($postID, $imageUrl) {
- $this->db->query('INSERT INTO user_posts_media (postID, mediaType, mediaUrl) VALUES (?, ?, ?)', [$postID, 'image', $imageUrl]);
+ public function addMediaToPost($postID, $type, $fileID) {
+ $this->db->query('INSERT INTO user_posts_media (postID, mediaType, fileID) VALUES (?, ?, ?)', [$postID, $type, $fileID]);
}
public function preparePostContent($content)
@@ -149,7 +149,7 @@
}
public function getPostMedia($postID) {
- $result = $this->db->query('SELECT * FROM user_posts_media WHERE postID = ?', [$postID])->result_array();
+ $result = $this->db->query('SELECT m.mediaType type, f.name name FROM user_posts_media m LEFT JOIN files f ON f.ID = m.fileID WHERE postID = ?', [$postID])->result_array();
return $result;
}
diff --git a/application/views/footer.php b/application/views/footer.php
index 862195a..b228caa 100644
--- a/application/views/footer.php
+++ b/application/views/footer.php
@@ -110,7 +110,8 @@
'lib/jquery.PageScroll2id.min.js',
'lib/jquery.mobile.custom.min.js',
'post-create.js',
- 'post-item.js'
+ 'post-item.js',
+ 'video-controls.js',
];
if (isset($additionalScripts)) {
$scripts = array_merge($scripts, $additionalScripts);
diff --git a/application/views/network/posts/post_item.php b/application/views/network/posts/post_item.php
index be78b11..0aa76eb 100644
--- a/application/views/network/posts/post_item.php
+++ b/application/views/network/posts/post_item.php
@@ -35,11 +35,46 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
0:00
+
+
0:00
+
+
+
+
+
+
+
diff --git a/assets/js/post-create.js b/assets/js/post-create.js
index 6a086c6..f08c8ad 100644
--- a/assets/js/post-create.js
+++ b/assets/js/post-create.js
@@ -30,8 +30,6 @@ $('#contentField').on('keyup', function (e) {
return `${match} `;
});
- console.log(html);
-
if (!/ $/.test($(this).html())) {
filter += ' ';
}
@@ -102,7 +100,7 @@ function set_range(start, end, element) {
$.fn.selectRange = function (start, end) {
var e = document.getElementById($(this).attr('id'));
- if (!e) return;
+ if (!e)
else if (e.setSelectionRange) {
e.focus();
e.setSelectionRange(start, end);
@@ -120,12 +118,12 @@ $.fn.selectRange = function (start, end) {
}
};
-let postMedia = {};
+let postMedia = [];
+
function publishPost() {
let isFilled = true;
let content = $('#contentField').text();
- console.log(content);
- if (content === "") {
+ if (postMedia.length === 0 && content === "") {
$('#postModal #content').addClass('has-error');
isFilled = false;
} else {
@@ -135,46 +133,231 @@ function publishPost() {
if (isFilled) {
const replyTo = $('#postModal #replyTo').val();
submitPost(content, replyTo);
+ } else {
+ addSnackbar('primary', 'Wir haben leider noch nicht erlernt, wie man leere Posts veröffentlicht.');
}
}
-$('#postFiles').on('change', function() {
- console.log(this.files);
- const match = ['image/jpeg', 'image/jpg', 'image/png'];
- const mediaCount = Object.keys(postMedia).length;
- if(mediaCount < 4) {
- for (let i = 0; i < this.files.length && i < 4 - mediaCount; i++) {
- const file = this.files[i];
- if (match.indexOf(file.type) === -1)
- continue;
+let uploadingFiles = [];
- const reader = new FileReader();
- reader.addEventListener('load', () => {
- $('.post-images').append(`
`);
- postMedia[mediaCount + i] = {
- image: reader.result,
- type: file.type,
- size: file.size,
- name: file.name
- };
- });
- reader.readAsDataURL(file);
+(function () {
+ // file drag hover
+ function fileDragHover(e) {
+ e.stopPropagation();
+ e.preventDefault();
+ e.target.className = (e.type == "dragover" ? "hover" : "");
+ }
+
+ // file selection
+ function fileSelectHandler(e) {
+
+ // cancel event and hover styling
+ fileDragHover(e);
+
+ // fetch FileList object
+ const files = e.target.files || e.dataTransfer.files;
+
+ // process all File objects
+ let i = 0;
+ for (let f of files) {
+ const generalType = f.type.split('/')[0];
+
+ if (postMedia.length + i > 4 || postMedia.find(media => media.type !== 'image' || media.type !== generalType)) {
+ addSnackbar('warning', 'Du kannst maximal vier Bilder zu einem Post hinzufügen.');
+ continue;
+ }
+
+ parseFile(f);
+ uploadFile(f);
+ i++;
}
}
- if(Object.keys(postMedia).length >= 4) {
- $('.postImageUpload').hide();
- }
-});
-$('#postModal').on('hidden.bs.modal', () => {
- $('#postModal #replyTo').val(-1);
-});
+ // output file information
+ function parseFile(file) {
+ $('#postModalPublish').addClass('disabled').attr('disabled', true);
+ uploadingFiles.push(file);
+
+ const thumbnailEl = $('
');
+ $('.post-images').append(thumbnailEl);
+ switch (file.type.split('/')[0]) {
+ case 'image':
+ const reader = new FileReader();
+ reader.addEventListener('load', () => {
+ thumbnailEl.css('background-image', `url(${reader.result})`);
+ });
+ break;
+
+ if (postMedia.length >= 4)
+ $('.postImageUpload').hide();
+ case 'video':
+ const video = document.createElement('video');
+ video.src = URL.createObjectURL(file);
+
+ video.addEventListener('loadeddata', () => {
+ const width = video.videoWidth;
+ const height = video.videoHeight;
+
+ const canvas = document.createElement('canvas');
+ canvas.width = width;
+ canvas.height = height;
+ canvas.getContext('2d').drawImage(video, 0, 0, width, height);
+
+ thumbnailEl.css('background-image', `url(${canvas.toDataURL()})`);
+ });
+
+ $('.postImageUpload').hide();
+ break;
+ case 'audio':
+ break;
+ }
+ }
+
+ // upload JPEG files
+ function uploadFile(file) {
+ var xhr = new XMLHttpRequest();
+ const allowedTypes = ['image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'video/mp4'];
+ if (xhr.upload && allowedTypes.includes(file.type) && file.size <= 100000000) {
+ const formData = new FormData();
+ formData.append('postMedia', file);
+
+ $.ajax({
+ url: '/user/uploadPostMedia',
+ method: 'POST',
+ data: formData,
+ processData: false,
+ contentType: false,
+ success: (data) => {
+ postMedia.push({
+ type: data.type,
+ path: data.path,
+ });
+
+ uploadingFiles.splice(uploadingFiles.indexOf(file), 1);
+ if(uploadingFiles.length === 0) {
+ $('#postModalPublish').removeClass('disabled').attr('disabled', false);
+ }
+ },
+ });
+
+ }
+
+ }
+
+ // initialize
+ function init() {
+
+ var fileselect = $('#postFiles')[0],
+ filedrag = $('#postFiles')[0];
+ // submitbutton = $id("submitbutton");
+
+ if (!fileselect)
+ return;
+
+ // file select
+ fileselect.addEventListener("change", fileSelectHandler, false);
+
+ // is XHR2 available?
+ var xhr = new XMLHttpRequest();
+ if (xhr.upload) {
+
+ // file drop
+ filedrag.addEventListener("dragover", fileDragHover, false);
+ filedrag.addEventListener("dragleave", fileDragHover, false);
+ filedrag.addEventListener("drop", fileSelectHandler, false);
+ filedrag.style.display = "block";
+ }
+
+ }
+
+ // call initialization file
+ if (window.File && window.FileList && window.FileReader) {
+ init();
+ }
+
+
+})();
+
+$('#postModal')
+ .on('hide.bs.modal', function (e) {
+ if (!this.forceQuit && (postMedia.length > 0 || $('#contentField').text().trim().length > 0)) {
+ e.preventDefault();
+
+ let allowClosing = false;
+ const confirmModal = $(`
+
+ `);
+ confirmModal.modal('show');
+
+ $('.dismiss', confirmModal).click(() => {
+ allowClosing = true;
+
+ this.forceQuit = true;
+ $(this).modal('hide');
+ });
+
+ $('.continue', confirmModal).click(() => {
+ allowClosing = true;
+ });
+
+ confirmModal
+ .on('hide.bs.modal', function (e) {
+ if (!allowClosing)
+ e.preventDefault();
+ })
+ .on('hidden.bs.modal', function () {
+ $(this).remove();
+ });
+ } else {
+ this.forceQuit = false;
+ }
+ })
+ .on('hidden.bs.modal', () => {
+ $('#postModal #replyTo').val(-1);
+
+ if(postMedia.length > 0) {
+ postMedia.forEach(media => {
+ $.ajax({
+ url: '/user/deletePostMedia',
+ method: 'POST',
+ data: {
+ path: media.path
+ }
+ });
+ });
+ }
+ resetPostForm();
+ $('#postModalBody > *:not(#postForm)').remove();
+ $('#postForm').show();
+ $('#postModal .modal-footer').show();
+ });
+
+function resetPostForm() {
+ uploadingFiles = [];
+ postMedia = [];
+ $('.post-images').empty();
+ $('.postImageUpload').show();
+ $('#contentField').text('');
+}
function submitPost(content, replyTo) {
- if(postMedia.length > 4) {
+ if (postMedia.length > 4) {
return;
}
+ const body = $('#postModalBody');
$.ajax({
url: "/user/publishPost",
method: 'POST',
@@ -184,14 +367,15 @@ function submitPost(content, replyTo) {
postMedia
},
beforeSend: function () {
- $('#postModalBody').empty().append(" ");
- $('#postModalPublish').button('loading');
+ body.children().hide().parent().append('
');
+ $('#postModal .modal-footer').hide();
+ resetPostForm();
},
success: function (data) {
- $('#postModalBody').empty().append(data);
+ $('.loadingSpinner', body).remove();
+ body.append(data);
},
error: function (data) {
- console.log(data);
}
});
}
\ No newline at end of file
diff --git a/assets/js/post-item.js b/assets/js/post-item.js
index 5d71adf..c95e556 100644
--- a/assets/js/post-item.js
+++ b/assets/js/post-item.js
@@ -68,7 +68,6 @@ function registerPostEvents() {
$('.action-btn.reply-button').click((e) => {
e.preventDefault();
const target = $(e.currentTarget);
- console.log(target, $('.postFullviewModal'));
$('.postFullviewModal').modal('hide');
$('#postModal #replyTo').val(target.data('uuid'));
$('#postModal').modal('show');
@@ -82,7 +81,7 @@ function registerPostEvents() {
$('.post-item').click(function (e) {
const target = e.target;
- if(target.tagName !== 'A' && target.tagName !== 'IMG' && target.tagName !== 'I' && !target.classList.contains('post-media')) {
+ if(target.tagName !== 'BUTTON' && target.tagName !== 'INPUT' && target.tagName !== 'A' && target.tagName !== 'IMG' && target.tagName !== 'I' && !target.classList.contains('post-media')) {
e.preventDefault();
const uuid = $(this).data('uuid');
const username = $(this).data('username');
@@ -94,6 +93,23 @@ function registerPostEvents() {
$('.post-media').click(function () {
showFullscreenImage($(this).data('full-image'));
});
+
+ addVideoListeners();
+
+ $(window).scroll(() => {
+ const pageOffsetTop = $(window).scrollTop();
+ const pageOffsetBottom = pageOffsetTop + $(window).height();
+ $('.post-media.post-video').each(function () {
+ const elemTop = $(this).offset().top;
+ const elemBottom = elemTop + $(this).height();
+
+ if(elemBottom <= pageOffsetBottom || elemTop >= pageOffsetTop) {
+ $(this)[0].play();
+ } else {
+ $(this)[0].pause();
+ }
+ });
+ });
}
registerPostEvents();
@@ -101,7 +117,6 @@ const pendingRequests = [];
function addPostLike(el) {
const uuid = el.data('uuid');
- console.log(el, uuid);
if(pendingRequests.indexOf(uuid) !== -1)
return;
@@ -115,7 +130,6 @@ function addPostLike(el) {
postUUID: uuid
},
success: (result) => {
- console.log(result);
if(result.success) {
text.text(result.likeCount);
if(result.isLiked) {
@@ -150,7 +164,6 @@ function addPostLike(el) {
icon.toggleClass('far').toggleClass('fas');
icon.parent().toggleClass('active');
},
- error: console.log
});
}
@@ -225,7 +238,6 @@ function submitReportForm(postUuid, reportReason, reportText) {
setTimeout(() => {
$('#postReportBody').find('.fa').fadeOut();
}, 500);
- console.log(data);
if(data.success) {
$('#postReportBody').append(`${data.message}
`);
} else {
@@ -311,4 +323,7 @@ function deletePost(uuid) {
}, 2000);
}
})
+}
+
+function addScrollListener() {
}
\ No newline at end of file
diff --git a/assets/js/video-controls.js b/assets/js/video-controls.js
new file mode 100644
index 0000000..5ec21f8
--- /dev/null
+++ b/assets/js/video-controls.js
@@ -0,0 +1,114 @@
+function getVideo(el) {
+ return $(el).parent().prev('.video')[0];
+}
+
+function updateMuteBtn(video) {
+ const muteBtn = $(video).next('.video-controls').find('.video-mute i.fa');
+ muteBtn.removeClass('fa-volume-up fa-volume-down fa-volume-mute');
+ if (video.muted) {
+ muteBtn.addClass('fa-volume-mute');
+ } else {
+ if (video.volume > .5) {
+ muteBtn.addClass('fa-volume-up');
+ } else {
+ muteBtn.addClass('fa-volume-down');
+ }
+ }
+}
+
+function formatTime(time) {
+ const minutes = Math.floor(time / 60);
+ let seconds = Math.round(time) % 60;
+ if(seconds < 10)
+ seconds = "0" + seconds;
+ return `${minutes}:${seconds}`
+}
+
+function addVideoListeners() {
+ $('.video-controls .video-toggle-play').click(function () {
+ getVideo(this).toggle();
+ });
+
+ $('.video-controls .video-mute').click(function () {
+ const video = getVideo(this);
+ video.toggleMuted();
+
+ updateMuteBtn(video);
+ });
+
+ $('.video-controls .video-volume').change(function () {
+ const video = getVideo(this);
+ video.volume = $(this).val();
+
+ if (video.volume > 0)
+ video.muted = false;
+
+ updateMuteBtn(video);
+ });
+
+ $('.video-seek-bar')
+ .on('mousedown', function () {
+ getVideo(this).pause();
+ })
+ .on('mouseup', function () {
+ getVideo(this).play();
+ })
+ .on('change', function () {
+ const video = getVideo(this);
+ video.currentTime = video.duration * (this.value / 100);
+ });
+
+ $('.video-fullscreen').on('click', function () {
+ const video = getVideo(this);
+
+ if(video.requestFullscreen) {
+ video.requestFullscreen();
+ } else if(video.mozRequestFullScreen) {
+ video.mozRequestFullScreen();
+ } else if(video.webkitRequestFullScreen) {
+ video.webkitRequestFullScreen();
+ }
+ });
+
+ $('.video')
+ .on('loadeddata', function () {
+ const duration = formatTime(this.duration);
+ $(this).next('.video-controls').find('.video-length').text(duration);
+ })
+ .on('play pause', function () {
+ const togglePlay = $(this).next('.video-controls').find('.video-toggle-play').find('i.fa');
+ if (this.paused) {
+ togglePlay.removeClass('fa-pause').addClass('fa-play');
+ } else {
+ togglePlay.removeClass('fa-play').addClass('fa-pause');
+ }
+ })
+ .on('timeupdate', function () {
+ const value = (100 / this.duration) * this.currentTime;
+ $(this).next('.video-controls').find('.video-seek-bar').val(value)
+ .prev('.video-time').text(formatTime(this.currentTime));
+ })
+ .on('click', function () {
+ if(!this.startedManually) {
+ this.play();
+ this.muted = false;
+ updateMuteBtn(this);
+
+ this.startedManually = true;
+ } else {
+ this.toggle();
+ }
+ });
+}
+
+Node.prototype.toggle = function () {
+ if (this.paused)
+ this.play();
+ else
+ this.pause();
+};
+
+Node.prototype.toggleMuted = function () {
+ this.muted = !this.muted;
+};
+