From 774dbc3388570794f6b74143cf18f34bf880b51e Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 27 Oct 2018 12:08:54 +0200 Subject: [PATCH] Holiday changes ;) --- application/controllers/File.php | 4 +- application/controllers/User.php | 1105 ++++---- application/controllers/admin/Projects.php | 11 +- application/models/DatabaseModel.php | 952 +++++-- application/models/FileModel.php | 76 +- application/models/LoginModel.php | 14 + application/models/PostsModel.php | 16 +- application/models/ProjectsModel.php | 374 +-- application/views/admin/footer.php | 6 +- application/views/admin/project_edit.php | 18 +- application/views/admin/projects.php | 7 +- application/views/footer.php | 6 +- application/views/header.php | 8 +- application/views/home.php | 82 +- application/views/network/posts/post_item.php | 6 +- .../views/network/posts/user_post_content.php | 13 +- .../views/network/user/profile_edit.php | 2371 ++++++++--------- .../network/user/profile_page_header.php | 40 +- assets/css/fonts.css | 41 + assets/css/home.css | 3 +- assets/css/lib/bootstrap.min.css | 2 +- assets/css/main.css | 54 +- assets/css/profile_page.css | 4 +- assets/fonts/Roboto/Roboto-Black.ttf | Bin 0 -> 171480 bytes assets/fonts/Roboto/Roboto-BlackItalic.ttf | Bin 0 -> 177552 bytes assets/fonts/Roboto/Roboto-Bold.ttf | Bin 0 -> 170760 bytes assets/fonts/Roboto/Roboto-BoldItalic.ttf | Bin 0 -> 174952 bytes assets/fonts/Roboto/Roboto-Italic.ttf | Bin 0 -> 173932 bytes assets/fonts/Roboto/Roboto-Light.ttf | Bin 0 -> 170420 bytes assets/fonts/Roboto/Roboto-LightItalic.ttf | Bin 0 -> 176616 bytes assets/fonts/Roboto/Roboto-Medium.ttf | Bin 0 -> 172064 bytes assets/fonts/Roboto/Roboto-MediumItalic.ttf | Bin 0 -> 176864 bytes assets/fonts/Roboto/Roboto-Regular.ttf | Bin 0 -> 171676 bytes assets/fonts/Roboto/Roboto-Thin.ttf | Bin 0 -> 171904 bytes assets/fonts/Roboto/Roboto-ThinItalic.ttf | Bin 0 -> 176300 bytes assets/js/custom.js | 1 - assets/js/main.js | 12 + assets/js/profile_edit.js | 36 +- assets/js/profile_page.js | 1 + 39 files changed, 2931 insertions(+), 2332 deletions(-) create mode 100644 assets/css/fonts.css create mode 100644 assets/fonts/Roboto/Roboto-Black.ttf create mode 100644 assets/fonts/Roboto/Roboto-BlackItalic.ttf create mode 100644 assets/fonts/Roboto/Roboto-Bold.ttf create mode 100644 assets/fonts/Roboto/Roboto-BoldItalic.ttf create mode 100644 assets/fonts/Roboto/Roboto-Italic.ttf create mode 100644 assets/fonts/Roboto/Roboto-Light.ttf create mode 100644 assets/fonts/Roboto/Roboto-LightItalic.ttf create mode 100644 assets/fonts/Roboto/Roboto-Medium.ttf create mode 100644 assets/fonts/Roboto/Roboto-MediumItalic.ttf create mode 100644 assets/fonts/Roboto/Roboto-Regular.ttf create mode 100644 assets/fonts/Roboto/Roboto-Thin.ttf create mode 100644 assets/fonts/Roboto/Roboto-ThinItalic.ttf diff --git a/application/controllers/File.php b/application/controllers/File.php index f36a846..4ba96fc 100644 --- a/application/controllers/File.php +++ b/application/controllers/File.php @@ -14,7 +14,7 @@ class File extends MY_Controller if ($title == null) { redirect(base_url()); } else { - $file = $this->db->query('SELECT name, type, path FROM files WHERE name = ?', [urldecode($title)])->result_array(); + $file = $this->db->query('SELECT name, type, path, isUserData FROM files WHERE name = ?', [urldecode($title)])->result_array(); if (!empty($file)) { $file = $file[0]; @@ -25,7 +25,7 @@ class File extends MY_Controller header("Content-Disposition: attachment; filename=" . $file['name'] . '.' . explode('/', $file['type'])[1]); } - $imagePath = 'files/' . (isset($_GET['w']) || isset($_GET['h']) ? 'thumbs/' : '') . $file['name'] . (isset($_GET['w']) ? '_w' . $_GET['w'] : '') . (isset($_GET['h']) ? '_h' . $_GET['h'] : '') . '.' . explode('.', $file['path'])[1]; + $imagePath = 'files/' . ($file['isUserData'] ? 'userContent/' : '') . (isset($_GET['w']) || isset($_GET['h']) ? 'thumbs/' : '') . $file['name'] . (isset($_GET['w']) ? '_w' . $_GET['w'] : '') . (isset($_GET['h']) ? '_h' . $_GET['h'] : '') . '.' . explode('.', $file['path'])[1]; if (!file_exists($imagePath)) { $config['image_library'] = 'gd2'; diff --git a/application/controllers/User.php b/application/controllers/User.php index e2d5426..75833e0 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -1,74 +1,38 @@ load->model('UserModel', '', TRUE); + $this->load->model('PostsModel', '', TRUE); + $this->load->model('FileModel', '', TRUE); + } - 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."]; - } - + 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]; - $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"; + + $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']); @@ -78,539 +42,582 @@ $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]); } - 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]; + $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']]); + } - foreach ($user_comments as $comment) { - $this->load->view('network/blog/comment_item', ['data' => $comment_user, 'c' => $comment]); - } + public function comments($user = "") + { + if ($user == "") { + $title = "Error - Profile"; + $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; } - 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['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']); - $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]); + $_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"; } - 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); - } + $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')); } - 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['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']); - $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]); + $_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"; } - 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]; + $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]); + } - foreach ($user_posts as $post) { - $this->load->view('network/blog/blog_post_item', ['data' => $post_user, 'post' => $post]); - } + 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')); } - public function publishPost() - { - if (!isset($_SESSION['user']) || empty($_SESSION['user'])) { - ?> - - input->post('content'); - if (strlen($content) >= 10000) { - ?> - - input->post('replyTo'); - if ($replyTo !== "-1" && !$this->PostsModel->isUUIDValid($replyTo)) { - ?> - - PostsModel->addReply($_SESSION['user']['ID'], $content, $replyTo); - } else { - $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); - - $fileUrl = $this->FileModel->uploadFileByContent($image, $entry['name'], $entry['type'], $entry['size']); - - $this->PostsModel->addImageToPost($postID, $fileUrl); - } - - ?> - - "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Der angegebene Nutzername konnte nicht gefunden werden."]; + $title = "Error - Profile"; } - public function followers($user = "") - { - if ($user == "") { - $title = "Error - Profile"; - $message = ["type" => "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; - } + $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]); + } - $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 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]; - $_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"; - } + foreach ($user_posts as $post) { + $this->load->view('network/blog/blog_post_item', ['data' => $post_user, 'post' => $post]); + } + } - $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 publishPost() + { + if (!isset($_SESSION['user']) || empty($_SESSION['user'])) { + ?> + + "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']); - $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']]); + $content = $this->input->post('content'); + if (strlen($content) >= 10000) { + ?> + + 'error', 'code' => -1]; - echo json_encode($response); - exit; + $replyTo = $this->input->post('replyTo'); + if ($replyTo !== "-1" && !$this->PostsModel->isUUIDValid($replyTo)) { + ?> + + PostsModel->addReply($_SESSION['user']['ID'], $content, $replyTo); + } else { + $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); + + $fileUrl = $this->FileModel->uploadFileByContent($image, $entry['name'], $entry['type'], $entry['size']); + + $this->PostsModel->addImageToPost($postID, $fileUrl); } - $followedUser = $_SESSION['currentProfilePage']; + ?> + + "danger", "message1" => "Dieser Nutzer existiert nicht!", "message2" => "Es wurde kein Nutzername angegeben."]; + } - if (!isset($_SESSION['user']['username'])) { - $response = ['type' => 'error', 'code' => 0]; - echo json_encode($response); - exit; - } + $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']); - $follower = $_SESSION['user']['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"; + } - if ($follower == $followedUser) { - $response = ['type' => 'error', 'code' => 1]; - 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' => 'followers', 'stats' => $user_stats, 'isCurrentUserFollowing' => $isCurrentUserFollowing, 'followers' => $followers]); + } + $this->load->view('footer', ['additionalScripts' => ['profile_page.js']]); + } - if ($this->UserModel->isFollowing($follower, $followedUser)) { - $this->UserModel->unfollow($follower, $followedUser); - $response = ['type' => 'success', 'code' => 10]; - 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."]; + } - $this->UserModel->follow($follower, $followedUser); - $response = ['type' => 'success', 'code' => 11]; + $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']]); + } + + public function switchFollowing() + { + header('Content-Type: application/json'); + if (!isset($_SESSION['currentProfilePage'])) { + $response = ['type' => 'error', 'code' => -1]; echo json_encode($response); exit; } - public function edit($user = "") - { - if ($user == "") { - redirect(base_url('user')); - } + $followedUser = $_SESSION['currentProfilePage']; - $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'] .= ""; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } - // 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'])) { + // code 0: not logged in + // code 1: same user + // code 10: unfollowed + // code 11: now following - } - // 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->uploadImage('avatar', 4096, $_FILES['avatar']['name'], 200); - if ($image != null) - $newData['profile_picture'] = $image; - unset($_FILES['avatar']); - } - // Header - if (isset($_FILES['header'])) { -// var_dump($_FILES['header']); - $image = $this->FileModel->uploadImage('header', 4096, $_FILES['header']['name'], 1920); -// var_dump($image); - 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'] .= ""; - } 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'] .= ""; - } else { - $_SESSION['profileEditNotification'] .= $trashMail; - } - } else { - $_SESSION['profileEditNotification'] .= $isRegistered; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } - // 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'] .= ""; - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } - if (isset($_POST['showAds'])) { - if (isset($_SESSION['user']) && $_SESSION['user']['rank'] >= 2) { - $newData['showAds'] = filter_var($_POST['email-notifications'], FILTER_VALIDATE_BOOLEAN); - } else { - $_SESSION['profileEditNotification'] .= ""; - } - } - if (!empty($newData)) { - // Add entry to history - $this->UserModel->insertIntoHistory($user_data); - // Update profile - $this->UserModel->updateProfile($newData, $user_data['ID']); -// redirect(base_url(uri_string())); - } - - $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', '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', 'profile_page.js', 'profile_edit.js']]); + if (!isset($_SESSION['user']['username'])) { + $response = ['type' => 'error', 'code' => 0]; + echo json_encode($response); + exit; } - 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)); - } + $follower = $_SESSION['user']['ID']; - $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 ($follower == $followedUser) { + $response = ['type' => 'error', 'code' => 1]; + echo json_encode($response); + exit; } - public function single_post_data($username = null, $uuid = null) - { - $message = ""; - $post = []; - $replies = []; - if ($username == null) { - $message .= ''; - goto display; - } - if ($uuid == null) { - $message .= ''; - goto display; - } - - $user = $this->UserModel->getUser($username); - if (empty($user)) { - $message .= ''; - goto display; - } - $user = $user[0]; - - $post = $this->PostsModel->getPostDetails($user['ID'], $uuid); - if (empty($post)) { - $message .= ''; - 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]); - + 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'] .= ""; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } + // 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'] .= ""; + } 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'] .= ""; + } else { + $_SESSION['profileEditNotification'] .= $trashMail; + } + } else { + $_SESSION['profileEditNotification'] .= $isRegistered; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } + // 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'] .= ""; + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } + if (isset($_POST['showAds'])) { + if (isset($_SESSION['user']) && $_SESSION['user']['rank'] >= 2) { + $newData['showAds'] = filter_var($_POST['email-notifications'], FILTER_VALIDATE_BOOLEAN); + } else { + $_SESSION['profileEditNotification'] .= ""; + } + } + 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'; + } + + $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']]); + } + + 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 .= ''; + goto display; + } + if ($uuid == null) { + $message .= ''; + goto display; + } + + $user = $this->UserModel->getUser($username); + if (empty($user)) { + $message .= ''; + goto display; + } + $user = $user[0]; + + $post = $this->PostsModel->getPostDetails($user['ID'], $uuid); + if (empty($post)) { + $message .= ''; + 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/controllers/admin/Projects.php b/application/controllers/admin/Projects.php index d42391d..878074b 100644 --- a/application/controllers/admin/Projects.php +++ b/application/controllers/admin/Projects.php @@ -32,7 +32,8 @@ if ($edit) { if ($this->ProjectsModel->checkIfExists($id)) { - $content = $this->ProjectsModel->getEntry($id)[0]; + $content = $this->ProjectsModel->getEntry($id); + $content = $this->ProjectsModel->mergeFullTranslationData($content)[0]; $projectCategories = $this->ProjectsModel->getEntryCategories($id); } else { redirect(base_url('admin/projects/edit')); @@ -42,7 +43,7 @@ $categories = $this->ProjectsModel->getCategories(); $this->load->view('admin/sidebar', ['title' => 'Projekt erstellen', 'additionalStyles' => ['lib/content-tools/content-tools.min.css', 'project-edit.css']]); - $this->load->view('admin/project_edit', ['edit' => -1, 'categories' => $categories, 'content' => $content, 'pCategories' => $projectCategories]); + $this->load->view('admin/project_edit', ['edit' => $id === NULL ? -1 : $id, 'categories' => $categories, 'content' => $content, 'pCategories' => $projectCategories]); $this->load->view('admin/footer', ['additionalScripts' => ['lib/content-tools/content-tools.min.js', 'project-edit.js']]); } @@ -58,6 +59,12 @@ $translations['de']['title'] = $this->input->post('titleDE'); $translations['de']['description'] = $this->input->post('headlineDE'); $translations['de']['content'] = $this->input->post('contentDE'); + $translations['en']['title'] = $this->input->post('titleEN'); + $translations['en']['description'] = $this->input->post('headlineEN'); + $translations['en']['content'] = $this->input->post('contentEN'); + $translations['fr']['title'] = $this->input->post('titleFR'); + $translations['fr']['description'] = $this->input->post('headlineFR'); + $translations['fr']['content'] = $this->input->post('contentFR'); $url = $this->input->post('url'); diff --git a/application/models/DatabaseModel.php b/application/models/DatabaseModel.php index 428ef70..6b138dc 100644 --- a/application/models/DatabaseModel.php +++ b/application/models/DatabaseModel.php @@ -6,288 +6,663 @@ class DatabaseModel extends CI_Model public function __construct() { parent::__construct(); - $this->createMissingDatbases(); + $this->createMissingDatabases(); } - public function createMissingDatbases() { - $this->createDatabases(); + public function createMissingDatabases() + { + //$this->createDatabases(); $this->createTables(); - $this->fillBlogDb(); - $this->fillMainDb(); - $this->fillPortfolioDb(); + //$this->addIndices(); + //$this->addAutoIncrements(); + //$this->addConstraints(); + + $this->fillBlogTables(); + $this->fillFeedbackTable(); + $this->fillMainTable(); + $this->fillProjectsTable(); } - public function createDatabases() { + private function createDatabases() + { // $this->db->query('CREATE DATABASE IF NOT EXISTS `blog` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci'); // $this->db->query('CREATE DATABASE IF NOT EXISTS `kingofdog` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci'); // $this->db->query('CREATE DATABASE IF NOT EXISTS `portfolio` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci'); // $this->db->query('CREATE DATABASE IF NOT EXISTS `social_media` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci'); - } - + $this->db->query('SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; - public function createTables() + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */;'); + } + + private function createTables() { - // Calendar Table - $this->db->query('CREATE TABLE IF NOT EXISTS `calendar` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `title` VARCHAR(300) NOT NULL, - `allDay` TINYINT(1) NOT NULL, - `start` VARCHAR(20) NOT NULL, - `end` VARCHAR(20) NOT NULL, - `url` TEXT NOT NULL, - `overlap` TINYINT(1) NOT NULL, - `color` TEXT NOT NULL, - `textColor` TEXT NOT NULL, - `description` TEXT NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1'); - // Feedback Table - $this->db->query('CREATE TABLE IF NOT EXISTS `feedback` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `page` VARCHAR(100) DEFAULT NULL, - `message` TEXT, - `datetime` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `anonymous` TINYINT(1) DEFAULT \'1\', - `userID` INT(11) DEFAULT NULL, - `email` VARCHAR(50) DEFAULT NULL, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1'); - // Files Table - $this->db->query('CREATE TABLE IF NOT EXISTS `files` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(50) NOT NULL, - `original_name` VARCHAR(50) NOT NULL, - `type` VARCHAR(30) NOT NULL, - `size` INT(11) NOT NULL, - `path` VARCHAR(300) NOT NULL, - `uploadDate` DATETIME DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=latin1'); - // Redirects Table - $this->db->query('CREATE TABLE IF NOT EXISTS `redirects` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `redirect` TEXT NOT NULL, - `url` TEXT NOT NULL, - `temporary` TINYINT(1) NOT NULL, - `expireDate` DATETIME DEFAULT NULL, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=220 DEFAULT CHARSET=latin1'); - // User Followers Table - $this->db->query('CREATE TABLE IF NOT EXISTS `user_followers` ( - `followedUserID` INT(11) NOT NULL, - `followerUserID` INT(11) NOT NULL, - `followedSince` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=latin1'); - // User Posts Table - $this->db->query('CREATE TABLE IF NOT EXISTS `user_posts` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `user_id` INT(11) DEFAULT NULL, - `title` VARCHAR(150) NOT NULL, - `content` TEXT, - `date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `reply_to` INT(11) DEFAULT NULL, - PRIMARY KEY (`ID`), - UNIQUE KEY `user_posts_ID_uindex` (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=145 DEFAULT CHARSET=latin1'); - // User Posts Likes Table - $this->db->query('CREATE TABLE IF NOT EXISTS `user_posts_likes` ( - `postID` INT(11) NOT NULL, - `likedUserID` INT(11) NOT NULL, - `likerUserID` INT(11) NOT NULL, - UNIQUE KEY `likerUserID` (`likerUserID`), - UNIQUE KEY `postID` (`postID`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1'); - // Users Table - $this->db->query('CREATE TABLE IF NOT EXISTS `users` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `original_name` VARCHAR(25) NOT NULL, - `username` VARCHAR(25) NOT NULL, - `displayname` VARCHAR(25) NOT NULL, - `login_method` INT(11) DEFAULT \'0\', - `password` TEXT, - `email` TEXT NOT NULL, - `rank` TEXT NOT NULL, - `profile_picture` TEXT NOT NULL, - `header_image` TEXT, - `social_networks` TEXT, - `is_activated` TINYINT(1) NOT NULL, - `activation_key` VARCHAR(256) DEFAULT NULL, - `showAds` TINYINT(1) NOT NULL DEFAULT \'1\', - `date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `isCurrentlyOnline` TINYINT(1) DEFAULT \'0\', - `about` TEXT NOT NULL, - `lastLogin` DATETIME NOT NULL, - `language` VARCHAR(10) DEFAULT \'DE\', - `country` VARCHAR(2) DEFAULT NULL, - `gender` VARCHAR(10) DEFAULT NULL, - `receiveEmails` TINYINT(1) NOT NULL DEFAULT \'1\', - `receiveNewsletter` TINYINT(1) NOT NULL DEFAULT \'1\', - `forget_password_key` VARCHAR(256) DEFAULT NULL, - `isDeleted` TINYINT(1) DEFAULT \'0\', - UNIQUE KEY `id` (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1'); - // Users History Table - $this->db->query('CREATE TABLE IF NOT EXISTS `users_history` ( - `changeID` INT(11) NOT NULL AUTO_INCREMENT, - `changeDate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `ID` INT(11) NOT NULL, - `username` VARCHAR(25) NOT NULL, - `displayname` VARCHAR(25) NOT NULL, - `email` TEXT NOT NULL, - `rank` INT(11) NOT NULL, - `profile_picture` TEXT NOT NULL, - `header_image` TEXT, - `social_networks` TEXT, - `showAds` TINYINT(1) NOT NULL DEFAULT \'1\', - `about` TEXT NOT NULL, - `language` VARCHAR(10) DEFAULT \'DE\', - `country` VARCHAR(2) DEFAULT NULL, - `gender` VARCHAR(10) DEFAULT NULL, - `receiveEmails` TINYINT(1) NOT NULL DEFAULT \'1\', - `receiveNewsletter` TINYINT(1) NOT NULL DEFAULT \'1\', - UNIQUE KEY `changeID` (`changeID`) -) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1'); - // Blog Categories Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_categories` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(25) NOT NULL, - `display_name` VARCHAR(50) NOT NULL, - PRIMARY KEY (`ID`), - UNIQUE KEY `blog_categories_name_display_name_uindex` (`name`,`display_name`) -) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1'); - // Blog Comments Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_comments` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `post_id` INT(11) NOT NULL, - `user_id` INT(11) NOT NULL, - `comment` TEXT NOT NULL, - `date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `like_count` INT(11) NOT NULL, - `reply` TINYINT(1) NOT NULL DEFAULT \'0\', - `replyTo_id` INT(11) DEFAULT NULL, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1'); - // Blog Content Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_content` ( - `contentID` INT(11) NOT NULL AUTO_INCREMENT, - `postID` INT(11) NOT NULL, - `contentDate` DATETIME NOT NULL, - `content` MEDIUMTEXT NOT NULL, - `contentAuthorID` INT(11) DEFAULT NULL, - `isNativePost` TINYINT(1) NOT NULL, - `isActive` TINYINT(1) NOT NULL, - `versionMessage` VARCHAR(300) NOT NULL, - `language` VARCHAR(10) DEFAULT NULL, - PRIMARY KEY (`contentID`) -) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=latin1'); - // Blog Posts Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_posts` ( - `postID` INT(11) NOT NULL AUTO_INCREMENT, - `postUrl` VARCHAR(300) NOT NULL, - `postTitle` VARCHAR(255) DEFAULT NULL, - `postDesc` TEXT, - `postPublishDate` DATETIME DEFAULT NULL, - `postLastEdit` DATETIME DEFAULT NULL, - `postAuthorID` INT(11) DEFAULT NULL, - `postImage` TEXT NOT NULL, - `postState` VARCHAR(50) NOT NULL, - `postViews` INT(11) NOT NULL DEFAULT \'0\', - `postCategoryID` INT(11) NOT NULL, - `postIsDeleted` TINYINT(1) NOT NULL DEFAULT \'0\', - `postDeletedDate` DATETIME DEFAULT NULL, - PRIMARY KEY (`postID`) -) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=latin1'); - // Blog Post Likes Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_post_likes` ( - `post_id` int(11) NOT NULL, - `user_id` int(11) NOT NULL, - PRIMARY KEY (`post_id`,`user_id`), - KEY `fk_post_likes_user` (`user_id`), - CONSTRAINT `fk_post_likes_post` FOREIGN KEY (`post_id`) REFERENCES `blog_posts` (`postID`), - CONSTRAINT `fk_post_likes_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`ID`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1'); - // Blog Post Tags Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_post_tags` ( - `post_id` INT(11) NOT NULL, - `tag_id` INT(11) NOT NULL, - PRIMARY KEY (`post_id`,`tag_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1'); - // Blog States Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_states` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(15) NOT NULL, - `display_name` VARCHAR(15) NOT NULL, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1'); - // Blog Tags Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_tags` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(25) NOT NULL, - `display_name` VARCHAR(50) NOT NULL, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=latin1'); - // Blog Translations Table - $this->db->query('CREATE TABLE IF NOT EXISTS `blog_translations` ( - `postID` INT(11) DEFAULT NULL, - `language` VARCHAR(10) DEFAULT \'en\', - `postTitle` VARCHAR(255) DEFAULT NULL, - `postDesc` TEXT, - UNIQUE KEY `blog_translations_language_uindex` (`language`), - UNIQUE KEY `blog_translations_postID_uindex` (`postID`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1'); - // Collections Table - $this->db->query('CREATE TABLE IF NOT EXISTS `collections` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `collection` TEXT NOT NULL, - `displayname` TEXT NOT NULL, - `displaynameEnglish` TEXT NOT NULL, - `displaynameFrench` TEXT NOT NULL, - PRIMARY KEY (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1'); - // Portfolio Table - $this->db->query('CREATE TABLE IF NOT EXISTS `portfolio` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255) NOT NULL, - `datetime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `source` TEXT NOT NULL, - `isDownloadable` TINYINT(1) NOT NULL DEFAULT \'0\', - `isOpenSource` TINYINT(1) NOT NULL DEFAULT \'0\', - `title` TEXT NOT NULL, - `titleEnglish` TEXT NOT NULL, - `titleFrench` TEXT NOT NULL, - `headline` TEXT NOT NULL, - `headlineEnglish` TEXT NOT NULL, - `headlineFrench` TEXT NOT NULL, - `description` TEXT NOT NULL, - `descriptionEnglish` TEXT NOT NULL, - `descriptionFrench` TEXT NOT NULL, - PRIMARY KEY (`ID`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=latin1'); - // Project Categories Table - $this->db->query('CREATE TABLE IF NOT EXISTS `project_categories` ( - `projectID` INT(11) NOT NULL, - `categoryID` INT(11) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=latin1'); - // Social Posts Table - $this->db->query('CREATE TABLE IF NOT EXISTS `social_posts` ( - `post_id` INT(11) NOT NULL AUTO_INCREMENT, - `post_plattform` VARCHAR(20) NOT NULL, - `post_content` TEXT NOT NULL, - `post_url` VARCHAR(75) NOT NULL, - `post_author` VARCHAR(20) NOT NULL, - `post_author_url` TEXT NOT NULL, - `post_date` INT(11) NOT NULL, - `post_img_source` TEXT, - `post_original_id` BIGINT(20) NOT NULL, - PRIMARY KEY (`post_id`), - UNIQUE KEY `post_url` (`post_url`) -) ENGINE=InnoDB AUTO_INCREMENT=5474 DEFAULT CHARSET=latin1'); + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_categories` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(25) NOT NULL, + `display_name` varchar(50) NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `blog_categories_name_display_name_uindex` (`name`, `display_name`) +) ENGINE = InnoDB DEFAULT CHARSET = latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_comments` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `post_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `comment` text NOT NULL, + `date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `like_count` int(11) NOT NULL, + `reply` tinyint(1) NOT NULL DEFAULT '0', + `replyTo_id` int(11) DEFAULT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_content` ( + `contentID` int(11) NOT NULL AUTO_INCREMENT, + `postID` int(11) NOT NULL, + `contentDate` datetime NOT NULL, + `content` mediumtext COLLATE utf8mb4_bin NOT NULL, + `contentAuthorID` int(11) DEFAULT NULL, + `isNativePost` tinyint(1) NOT NULL, + `isActive` tinyint(1) NOT NULL, + `versionMessage` varchar(300) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `language` varchar(10) CHARACTER SET latin1 DEFAULT NULL, + `wordCount` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`contentID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_posts` ( + `postID` int(11) NOT NULL AUTO_INCREMENT, + `postUrl` varchar(300) CHARACTER SET latin1 DEFAULT NULL, + `postPublishDate` datetime DEFAULT NULL, + `postLastEdit` datetime DEFAULT NULL, + `postAuthorID` int(11) DEFAULT NULL, + `postImage` text CHARACTER SET latin1, + `postState` varchar(50) CHARACTER SET latin1 NOT NULL, + `postViews` int(11) NOT NULL DEFAULT '0', + `postCategoryID` int(11) NOT NULL, + `postIsDeleted` tinyint(1) NOT NULL DEFAULT '0', + `postDeletedDate` datetime DEFAULT NULL, + PRIMARY KEY (`postID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_post_likes` ( + `post_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + PRIMARY KEY (`post_id`, `user_id`), + KEY `fk_post_likes_user` (`user_id`), + CONSTRAINT `fk_post_likes_post` FOREIGN KEY (`post_id`) REFERENCES `blog_posts` (`postID`), + CONSTRAINT `fk_post_likes_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_post_tags` ( + `post_id` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + PRIMARY KEY (`post_id`, `tag_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_states` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(15) NOT NULL, + `display_name` varchar(15) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_tags` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(25) NOT NULL, + `display_name` varchar(50) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `blog_translations` ( + `postTranslationID` int(11) NOT NULL AUTO_INCREMENT, + `postID` int(11) NOT NULL, + `language` varchar(5) COLLATE utf8mb4_bin NOT NULL DEFAULT 'de', + `postTitle` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL, + `postDesc` text COLLATE utf8mb4_bin, + PRIMARY KEY (`postTranslationID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `calendar` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `title` varchar(300) NOT NULL, + `allDay` tinyint(1) NOT NULL, + `start` varchar(20) NOT NULL, + `end` varchar(20) NOT NULL, + `url` text NOT NULL, + `overlap` tinyint(1) NOT NULL, + `color` text NOT NULL, + `textColor` text NOT NULL, + `description` text NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `feedback` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `page` varchar(100) CHARACTER SET latin1 DEFAULT NULL, + `message` text COLLATE utf8mb4_bin, + `datetime` datetime DEFAULT CURRENT_TIMESTAMP, + `anonymous` tinyint(1) DEFAULT '1', + `userID` int(11) DEFAULT NULL, + `email` varchar(50) CHARACTER SET latin1 DEFAULT NULL, + `feedbackState` int(11) NOT NULL DEFAULT '0', + `lastStateUpdate` datetime DEFAULT NULL, + `feedbackStatusMessage` text COLLATE utf8mb4_bin, + `supporterID` int(11) DEFAULT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `feedback_archive` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `page` varchar(100) CHARACTER SET latin1 DEFAULT NULL, + `message` text COLLATE utf8mb4_bin, + `datetime` datetime DEFAULT CURRENT_TIMESTAMP, + `anonymous` tinyint(1) DEFAULT '1', + `userID` int(11) DEFAULT NULL, + `email` varchar(50) CHARACTER SET latin1 DEFAULT NULL, + `feedbackState` int(11) NOT NULL DEFAULT '0', + `feedbackStatusMessage` text COLLATE utf8mb4_bin, + `supporterID` int(11) DEFAULT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `feedback_states` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `displayname` text NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `files` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `original_name` varchar(50) NOT NULL, + `type` varchar(30) NOT NULL, + `size` int(11) NOT NULL, + `path` varchar(300) NOT NULL, + `uploadDate` datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `notifications` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `recipientID` int(11) NOT NULL, + `senderID` int(11) NOT NULL, + `unread` tinyint(1) NOT NULL, + `type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + `referenceID` int(11) NOT NULL, + `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `parameters` text COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `projects` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET latin1 DEFAULT NULL, + `datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `source` text CHARACTER SET latin1, + `isDownloadable` tinyint(1) NOT NULL DEFAULT '0', + `downloadLink` text COLLATE utf8mb4_bin, + `isOpenSource` tinyint(1) NOT NULL DEFAULT '0', + `openSourceLink` text COLLATE utf8mb4_bin, + `customLink` text COLLATE utf8mb4_bin, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `projects_categories` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `collection` text NOT NULL, + `displayname` text NOT NULL, + `displaynameEnglish` text NOT NULL, + `displaynameFrench` text NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `projects_entry_categories` ( + `projectID` int(11) NOT NULL, + `categoryID` int(11) NOT NULL, + PRIMARY KEY (`projectID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `projects_entry_votes` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `projectID` int(11) NOT NULL, + `userID` int(11) NOT NULL, + `type` int(11) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `projects_translations` ( + `translationID` int(11) NOT NULL AUTO_INCREMENT, + `projectID` int(11) NOT NULL, + `title` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `description` text COLLATE utf8mb4_unicode_ci, + `content` text COLLATE utf8mb4_unicode_ci, + `downloadName` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `openSourceName` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `customLinkName` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `lang` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`translationID`), + UNIQUE KEY `projectID` (`projectID`, `lang`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `redirects` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `redirect` text NOT NULL, + `url` text NOT NULL, + `temporary` tinyint(1) NOT NULL, + `expireDate` datetime DEFAULT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `social_posts` ( + `post_id` int(11) NOT NULL AUTO_INCREMENT, + `post_plattform` varchar(20) CHARACTER SET latin1 NOT NULL, + `post_content` text COLLATE utf8mb4_bin NOT NULL, + `post_url` varchar(75) CHARACTER SET latin1 NOT NULL, + `post_author` varchar(20) CHARACTER SET latin1 NOT NULL, + `post_author_url` text CHARACTER SET latin1 NOT NULL, + `post_date` int(11) NOT NULL, + `post_img_source` text CHARACTER SET latin1, + `post_original_id` bigint(20) NOT NULL, + PRIMARY KEY (`post_id`), + UNIQUE KEY `post_url` (`post_url`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `users` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `original_name` varchar(25) COLLATE utf8mb4_bin NOT NULL, + `username` varchar(25) COLLATE utf8mb4_bin NOT NULL, + `displayname` varchar(25) COLLATE utf8mb4_bin NOT NULL, + `login_method` int(11) DEFAULT '0', + `password` mediumtext COLLATE utf8mb4_bin, + `email` mediumtext COLLATE utf8mb4_bin NOT NULL, + `rank` mediumtext COLLATE utf8mb4_bin NOT NULL, + `profile_picture` mediumtext COLLATE utf8mb4_bin NOT NULL, + `header_image` mediumtext COLLATE utf8mb4_bin, + `social_networks` mediumtext COLLATE utf8mb4_bin, + `is_activated` tinyint(1) NOT NULL, + `activation_key` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL, + `showAds` tinyint(1) NOT NULL DEFAULT '1', + `date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `isCurrentlyOnline` tinyint(1) DEFAULT '0', + `lastOnlineUpdate` datetime DEFAULT NULL, + `about` mediumtext COLLATE utf8mb4_bin NOT NULL, + `lastLogin` datetime NOT NULL, + `language` varchar(10) COLLATE utf8mb4_bin DEFAULT 'DE', + `country` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL, + `gender` varchar(10) COLLATE utf8mb4_bin DEFAULT NULL, + `birthdate` mediumtext COLLATE utf8mb4_bin, + `birthyear` int(11) DEFAULT NULL, + `receiveEmails` tinyint(1) NOT NULL DEFAULT '1', + `receiveNewsletter` tinyint(1) NOT NULL DEFAULT '1', + `forget_password_key` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL, + `isDeleted` tinyint(1) DEFAULT '0', + UNIQUE KEY `id` (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `users_history` ( + `changeID` int(11) NOT NULL AUTO_INCREMENT, + `changeDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `ID` int(11) NOT NULL, + `username` varchar(25) NOT NULL, + `displayname` varchar(25) NOT NULL, + `email` text NOT NULL, + `rank` int(11) NOT NULL, + `profile_picture` text NOT NULL, + `header_image` text, + `social_networks` text, + `showAds` tinyint(1) NOT NULL DEFAULT '1', + `about` text NOT NULL, + `language` varchar(10) DEFAULT 'DE', + `country` varchar(2) DEFAULT NULL, + `gender` varchar(10) DEFAULT NULL, + `birthdate` text, + `birthyear` int(11) DEFAULT NULL, + `receiveEmails` tinyint(1) NOT NULL DEFAULT '1', + `receiveNewsletter` tinyint(1) NOT NULL DEFAULT '1', + UNIQUE KEY `changeID` (`changeID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_followers` ( + `followedUserID` int(11) NOT NULL, + `followerUserID` int(11) NOT NULL, + `followedSince` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_posts` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `uuid` varchar(32) CHARACTER SET latin1 NOT NULL, + `user_id` int(11) DEFAULT NULL, + `content` text CHARACTER SET utf8 COLLATE utf8_bin, + `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `lastEditDate` datetime DEFAULT NULL, + `reply_to` int(11) DEFAULT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `user_posts_ID_uindex` (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_posts_hashtags` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `userID` int(11) NOT NULL, + `postID` int(11) NOT NULL, + `hashtag` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + `position` int(11) NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `user_posts_hashtags_ID_uindex` (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_posts_likes` ( + `postID` int(11) NOT NULL, + `likedUserID` int(11) NOT NULL, + `likerUserID` int(11) NOT NULL, + PRIMARY KEY (`postID`,`likerUserID`), + UNIQUE KEY `postID_2` (`postID`,`likerUserID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_posts_media` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `postID` int(11) NOT NULL, + `mediaType` varchar(50) NOT NULL, + `mediaUrl` text NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_posts_mentions` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `userID` int(11) NOT NULL, + `postID` int(11) NOT NULL, + `mentionedUserID` int(11) NOT NULL, + `position` int(11) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `user_posts_reports` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `postID` int(11) NOT NULL, + `reason` varchar(255) NOT NULL, + `reasonText` text NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); } - public function fillBlogDb() { - if($this->db->query('SELECT COUNT(*) count FROM blog_categories')->result_array()[0]['count'] == 0) { + private function addIndices() { + + $this->db->query("ALTER TABLE `blog_comments` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `blog_content` + ADD PRIMARY KEY (`contentID`);"); + + $this->db->query("ALTER TABLE `blog_posts` + ADD PRIMARY KEY (`postID`);"); + + $this->db->query("ALTER TABLE `blog_post_likes` + ADD PRIMARY KEY (`post_id`,`user_id`), + ADD KEY `fk_post_likes_user` (`user_id`);"); + + $this->db->query("ALTER TABLE `blog_post_tags` + ADD PRIMARY KEY (`post_id`,`tag_id`);"); + + $this->db->query("ALTER TABLE `blog_states` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `blog_tags` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `blog_translations` + ADD PRIMARY KEY (`postTranslationID`);"); + + $this->db->query("ALTER TABLE `calendar` + ADD PRIMARY KEY (`id`);"); + + $this->db->query("ALTER TABLE `feedback` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `feedback_archive` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `feedback_states` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `files` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `notifications` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects_categories` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects_entry_votes` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects_translations` + ADD PRIMARY KEY (`translationID`), + ADD UNIQUE KEY `projectID` (`projectID`,`lang`);"); + + $this->db->query("ALTER TABLE `redirects` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `social_posts` + ADD PRIMARY KEY (`post_id`), + ADD UNIQUE KEY `post_url` (`post_url`);"); + + $this->db->query("ALTER TABLE `users` + ADD UNIQUE KEY `id` (`ID`);"); + + $this->db->query("ALTER TABLE `users_history` + ADD UNIQUE KEY `changeID` (`changeID`);"); + + $this->db->query("ALTER TABLE `user_posts` + ADD PRIMARY KEY (`ID`), + ADD UNIQUE KEY `user_posts_ID_uindex` (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_hashtags` + ADD PRIMARY KEY (`ID`), + ADD UNIQUE KEY `user_posts_hashtags_ID_uindex` (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_likes` + ADD PRIMARY KEY (`postID`,`likerUserID`), + ADD UNIQUE KEY `postID_2` (`postID`,`likerUserID`);"); + + $this->db->query("ALTER TABLE `user_posts_media` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_mentions` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_reports` + ADD PRIMARY KEY (`ID`);");$this->db->query("ALTER TABLE `blog_categories` + ADD PRIMARY KEY (`ID`), + ADD UNIQUE KEY `blog_categories_name_display_name_uindex` (`name`,`display_name`);"); + + $this->db->query("ALTER TABLE `blog_comments` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `blog_content` + ADD PRIMARY KEY (`contentID`);"); + + $this->db->query("ALTER TABLE `blog_posts` + ADD PRIMARY KEY (`postID`);"); + + $this->db->query("ALTER TABLE `blog_post_likes` + ADD PRIMARY KEY (`post_id`,`user_id`), + ADD KEY `fk_post_likes_user` (`user_id`);"); + + $this->db->query("ALTER TABLE `blog_post_tags` + ADD PRIMARY KEY (`post_id`,`tag_id`);"); + + $this->db->query("ALTER TABLE `blog_states` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `blog_tags` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `blog_translations` + ADD PRIMARY KEY (`postTranslationID`);"); + + $this->db->query("ALTER TABLE `calendar` + ADD PRIMARY KEY (`id`);"); + + $this->db->query("ALTER TABLE `feedback` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `feedback_archive` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `feedback_states` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `files` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `notifications` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects_categories` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects_entry_votes` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `projects_translations` + ADD PRIMARY KEY (`translationID`), + ADD UNIQUE KEY `projectID` (`projectID`,`lang`);"); + + $this->db->query("ALTER TABLE `redirects` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `social_posts` + ADD PRIMARY KEY (`post_id`), + ADD UNIQUE KEY `post_url` (`post_url`);"); + + $this->db->query("ALTER TABLE `users` + ADD UNIQUE KEY `id` (`ID`);"); + + $this->db->query("ALTER TABLE `users_history` + ADD UNIQUE KEY `changeID` (`changeID`);"); + + $this->db->query("ALTER TABLE `user_posts` + ADD PRIMARY KEY (`ID`), + ADD UNIQUE KEY `user_posts_ID_uindex` (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_hashtags` + ADD PRIMARY KEY (`ID`), + ADD UNIQUE KEY `user_posts_hashtags_ID_uindex` (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_likes` + ADD PRIMARY KEY (`postID`,`likerUserID`), + ADD UNIQUE KEY `postID_2` (`postID`,`likerUserID`);"); + + $this->db->query("ALTER TABLE `user_posts_media` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_mentions` + ADD PRIMARY KEY (`ID`);"); + + $this->db->query("ALTER TABLE `user_posts_reports` + ADD PRIMARY KEY (`ID`);"); + } + + private function addAutoIncrements() { + $this->db->query("ALTER TABLE `blog_categories` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;"); + + $this->db->query("ALTER TABLE `blog_comments` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;"); + + $this->db->query("ALTER TABLE `blog_content` + MODIFY `contentID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=89;"); + + $this->db->query("ALTER TABLE `blog_posts` + MODIFY `postID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=98;"); + + $this->db->query("ALTER TABLE `blog_states` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;"); + + $this->db->query("ALTER TABLE `blog_tags` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=61;"); + + $this->db->query("ALTER TABLE `blog_translations` + MODIFY `postTranslationID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=34;"); + + $this->db->query("ALTER TABLE `calendar` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;"); + + $this->db->query("ALTER TABLE `feedback` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;"); + + $this->db->query("ALTER TABLE `feedback_archive` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;"); + + $this->db->query("ALTER TABLE `files` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=125;"); + + $this->db->query("ALTER TABLE `notifications` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=74;"); + + $this->db->query("ALTER TABLE `projects` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=64;"); + + $this->db->query("ALTER TABLE `projects_categories` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;"); + + $this->db->query("ALTER TABLE `projects_entry_votes` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=260;"); + + $this->db->query("ALTER TABLE `projects_translations` + MODIFY `translationID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36;"); + + $this->db->query("ALTER TABLE `redirects` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=47;"); + + $this->db->query("ALTER TABLE `social_posts` + MODIFY `post_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=484298;"); + + $this->db->query("ALTER TABLE `users` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;"); + + $this->db->query("ALTER TABLE `users_history` + MODIFY `changeID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35;"); + + $this->db->query("ALTER TABLE `user_posts` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=209;"); + + $this->db->query("ALTER TABLE `user_posts_hashtags` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;"); + + $this->db->query("ALTER TABLE `user_posts_media` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;"); + + $this->db->query("ALTER TABLE `user_posts_mentions` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;"); + + $this->db->query("ALTER TABLE `user_posts_reports` + MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;"); + } + + private function addConstraints() { + $this->db->query("ALTER TABLE `blog_post_likes` + ADD CONSTRAINT `fk_post_likes_post` FOREIGN KEY (`post_id`) REFERENCES `blog_posts` (`postID`), + ADD CONSTRAINT `fk_post_likes_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`ID`);"); + } + + private function fillBlogTables() + { + if ($this->db->query('SELECT COUNT(*) count FROM blog_categories')->result_array()[0]['count'] == 0) { $this->db->query("INSERT INTO `blog_categories` (`ID`, `name`, `display_name`) VALUES (1, 'design', 'Design'), (2, 'development', 'Entwicklung & Programmierung'), @@ -297,14 +672,14 @@ class DatabaseModel extends CI_Model (6, 'technic', 'Technik'), (7, 'youtube', 'YouTube')"); } - if($this->db->query('SELECT COUNT(*) count FROM blog_states')->result_array()[0]['count'] == 0) { + if ($this->db->query('SELECT COUNT(*) count FROM blog_states')->result_array()[0]['count'] == 0) { $this->db->query("INSERT INTO `blog_states` (`ID`, `name`, `display_name`) VALUES (1, 'published', 'Veröffentlicht'), (2, 'draft', 'Entwurf'), (3, 'pending', 'Geplant'), (4, 'trashbin', 'Im Papierkorb')"); } - if($this->db->query('SELECT COUNT(*) count FROM blog_tags')->result_array()[0]['count'] == 0) { + if ($this->db->query('SELECT COUNT(*) count FROM blog_tags')->result_array()[0]['count'] == 0) { $this->db->query("INSERT INTO `blog_tags` (`ID`, `name`, `display_name`) VALUES (1, 'youtube', 'YouTube'), (2, 'twitter', 'Twitter'), @@ -323,12 +698,6 @@ class DatabaseModel extends CI_Model (15, 'photography', 'Fotografie'), (16, 'videos', 'Videos & Filmen'), (17, 'learning', 'Lernen'), -(28, '', ''), -(29, 'test', 'test'), -(30, 'kacke', 'kacke'), -(31, 'asdfla', 'asdfla'), -(32, 'admin', 'Admin'), -(33, 'tset', 'tset'), (34, 'programmiersprachen', 'Programmiersprachen'), (35, 'sprachen', 'Sprachen'), (36, 'serie', 'Serie'), @@ -337,18 +706,26 @@ class DatabaseModel extends CI_Model (39, 'kingofdog', 'KingOfDog'), (40, 'entwicklung', 'Entwicklung'), (41, 'programmierung', 'Programmierung'), -(42, 'webseite', 'Webseite'), -(43, 'posts', 'Posts'), -(44, 'post', 'Post'), -(45, 'system', 'System'), -(46, 'nutzer', 'Nutzer'), -(47, 'user', 'User'), -(48, 'php', 'PHP')"); +(42, 'webseite', 'Webseite')"); } } - public function fillMainDb() { + private function fillFeedbackTable() { if($this->db->query('SELECT COUNT(*) count FROM redirects')->result_array()[0]['count'] == 0) { + $this->db->query("INSERT INTO `feedback_states` (`ID`, `name`, `displayname`) VALUES +(0, 'new', 'ungelesen'), +(1, 'read', 'gelesen'), +(2, 'question', 'Rückfrage'), +(5, 'fixing', 'in Bearbeitung'), +(7, 'paused', 'pausiert'), +(10, 'closed', 'geschlossen'), +(15, 'fixed', 'geschlossen & gelöst');"); + } + } + + private function fillMainTable() + { + if ($this->db->query('SELECT COUNT(*) count FROM redirects')->result_array()[0]['count'] == 0) { $this->db->query("INSERT INTO `redirects` (`ID`, `date`, `redirect`, `url`, `temporary`, `expireDate`) VALUES (1, '2016-10-15 18:09:51', 'yt', 'http://youtube.com/KingOfDog', 0, '0000-00-00 00:00:00'), (2, '2016-10-15 18:10:13', 'youtube', 'http://youtube.com/KingOfDog', 0, '0000-00-00 00:00:00'), @@ -357,8 +734,9 @@ class DatabaseModel extends CI_Model } } - public function fillPortfolioDb() { - if($this->db->query('SELECT COUNT(*) count FROM projects_categories')->result_array()[0]['count'] == 0) { + private function fillProjectsTable() + { + if ($this->db->query('SELECT COUNT(*) count FROM projects_categories')->result_array()[0]['count'] == 0) { $this->db->query("INSERT INTO `projects_categories` (`ID`, `collection`, `displayname`, `displaynameEnglish`, `displaynameFrench`) VALUES (1, 'banner', 'Banner', 'Banner', 'Bannière'), (2, 'fotografie', 'Fotografie', 'Photography', 'Photographie'), diff --git a/application/models/FileModel.php b/application/models/FileModel.php index 2c8022a..7fdfde8 100644 --- a/application/models/FileModel.php +++ b/application/models/FileModel.php @@ -11,9 +11,13 @@ class FileModel extends CI_Model parent::__construct(); } - public function uploadFile($original_name, $tmpname, $size, $type) + private function getPath($fileName, $userContent) { + return 'files/' . ($userContent ? 'userContent/' : '') . $fileName; + } + + public function uploadFile($original_name, $tmpname, $size, $type, $userContent = true) { - $target_dir = "files" . DIRECTORY_SEPARATOR; + $target_dir = "files" . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : ''); $filetype = pathinfo(basename($original_name), PATHINFO_EXTENSION); $target_file = $target_dir . $this->generateName() . '.' . $filetype; $name = explode('.' . $filetype, explode(DIRECTORY_SEPARATOR, $target_file)[1])[0]; @@ -22,13 +26,13 @@ class FileModel extends CI_Model die('File couldn\'t be uploaded!'); } - $this->db->query('INSERT INTO files (name, original_name, type, size, path) VALUES (?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file]); + $this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file, $userContent]); - return "/file/open/" . $name; + return "/f/" . $name; } - public function uploadImage($name, $max_size, $originalname, $max_width) { - $config['upload_path'] = './files/'; + public function uploadImage($name, $max_size, $originalname, $max_width, $userContent = true) { + $config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : ''); $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = $max_size; $config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalname), PATHINFO_EXTENSION); @@ -50,13 +54,65 @@ class FileModel extends CI_Model $this->image_lib->resize(); - $this->db->query('INSERT INTO files (name, original_name, type, size, path) VALUES (?, ?, ?, ?, ?)', [$data['raw_name'], $originalname, $data['file_type'], $data['file_size'] * 1024, 'files/' . $data['file_name']]); + $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]); return '/f/' . $data['raw_name']; } } - public function uploadFileByContent($content, $original_name, $fullType, $fileSize) { - $target_dir = "files" . DIRECTORY_SEPARATOR; + public function uploadCroppedImage($name, $max_size, $originalname, $width, $height, $userContent = true) { + $config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : ''); + $config['allowed_types'] = 'gif|jpg|png'; + $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(); + + // Resize + $config['image_library'] = 'gd2'; + $config['source_image'] = $data['full_path']; + $config['maintain_ratio'] = TRUE; + + $size = getimagesize($data['full_path']); + + if($size[0] > $size[1]) { + $config['height'] = $height; + } else { + $config['width'] = $width; + } + + $this->load->library('image_lib'); + $this->image_lib->initialize($config); + $this->image_lib->resize(); + + $config['source_image'] = $config['upload_path'] . $config['file_name']; + $config['maintain_ratio'] = FALSE; + $config['height'] = $height; + $config['width'] = $width; + + $size = getimagesize($config['source_image']); + + if($size[0] > $size[1]) { + $config['x_axis'] = ($size[0] - $width) / 2; + } else { + $config['y_axis'] = ($size[1] - $height) / 2; + } + + $this->image_lib->clear(); + $this->image_lib->initialize($config); + $this->image_lib->crop(); + + $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]); + return '/f/' . $data['raw_name']; + } + } + + public function uploadFileByContent($content, $original_name, $fullType, $fileSize, $userContent = true) { + $target_dir = "files" . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : ''); $filetype = pathinfo(basename($original_name), PATHINFO_EXTENSION); $target_file = $target_dir . $this->generateName() . '.' . $filetype; $name = explode('.' . $filetype, explode(DIRECTORY_SEPARATOR, $target_file)[1])[0]; @@ -65,7 +121,7 @@ class FileModel extends CI_Model fwrite($fp, $content); fclose($fp); - $this->db->query('INSERT INTO files (name, original_name, type, size, path) VALUES (?, ?, ?, ?, ?)', [$name, $original_name, $fullType, $fileSize, $target_file]); + $this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $fullType, $fileSize, $target_file, $userContent]); return '/f/' . $name; } diff --git a/application/models/LoginModel.php b/application/models/LoginModel.php index 3dcfb25..9fa9b26 100644 --- a/application/models/LoginModel.php +++ b/application/models/LoginModel.php @@ -69,6 +69,20 @@ class LoginModel extends CI_Model } } + public function reloadLoginSession($logindata) { + $_SESSION['user']['displayname'] = $logindata['displayname']; + $_SESSION['user']['username'] = $logindata['username']; + $_SESSION['user']['rank'] = $logindata['rank']; + $_SESSION['user']['ID'] = $logindata['ID']; + $_SESSION['user']['ads'] = $logindata['showAds']; + $profilePic = $logindata['profile_picture']; + if (empty($profilePic)) { + $_SESSION['user']['profilePic'] = '/assets/images/steam.jpg'; + } else { + $_SESSION['user']['profilePic'] = $profilePic; + } + } + public function getUserHash($username, $password, $email, $id) { $hash = hash('sha256', $id . '//' . $username . '//' . substr($password, 0, 5) . '//' . substr($email, 0, 5)); diff --git a/application/models/PostsModel.php b/application/models/PostsModel.php index c614d04..ba38ffa 100644 --- a/application/models/PostsModel.php +++ b/application/models/PostsModel.php @@ -229,10 +229,18 @@ } private function mergeReplyData($post) { - $data = $this->db->query('SELECT uuid, username, displayname FROM user_posts LEFT JOIN users ON users.ID = user_posts.user_id WHERE user_posts.ID = ?', [$post['reply_to']])->result_array(); - $post['replyToUuid'] = $data[0]['uuid']; - $post['replyToUsername'] = $data[0]['username']; - $post['replyToDisplayname'] = $data[0]['displayname']; + $data = $this->db->query('SELECT p.*, username, displayname FROM user_posts p LEFT JOIN users ON users.ID = p.user_id WHERE p.ID = ?', [$post['reply_to']])->result_array(); + $data = $this->preparePostList($data); + if(!empty($data)) { + $post['replyToPost'] = $data[0]; + } else { + $post['replyToPost'] = [ + 'username' => '', + 'displayname' => '', + 'content' => 'Nicht existent', + 'date' => '', + ]; + } return $post; } diff --git a/application/models/ProjectsModel.php b/application/models/ProjectsModel.php index 2365921..a8ac722 100644 --- a/application/models/ProjectsModel.php +++ b/application/models/ProjectsModel.php @@ -1,207 +1,243 @@ load->model('projectsModel', '', TRUE); - } - - public function getEntries($category) { - if($category !== 'all') { - $content = $this->db->query('SELECT *, (SELECT (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = 1) - (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = -1)) voteCount FROM projects p WHERE ID IN (SELECT projectID FROM projects_entry_categories WHERE categoryID = ?) ORDER BY datetime DESC', [$category])->result_array(); - } else { - $content = $this->db->query('SELECT *, (SELECT (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = 1) - (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = -1)) voteCount FROM projects p ORDER BY datetime DESC')->result_array(); + public function __construct() + { + parent::__construct(); + $this->load->model('projectsModel', '', TRUE); } - $content = $this->mergeTranslationData($content, $_SESSION['site_lang']); + public function getEntries($category) + { + if ($category !== 'all') { + $content = $this->db->query('SELECT *, (SELECT (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = 1) - (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = -1)) voteCount FROM projects p WHERE ID IN (SELECT projectID FROM projects_entry_categories WHERE categoryID = ?) ORDER BY datetime DESC', [$category])->result_array(); + } else { + $content = $this->db->query('SELECT *, (SELECT (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = 1) - (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = p.ID AND type = -1)) voteCount FROM projects p ORDER BY datetime DESC')->result_array(); + } - return $content; - } + $content = $this->mergeTranslationData($content, $_SESSION['site_lang']); - public function getCategories() { - $collections = $this->db->query('SELECT c.*, count(p.projectID) count FROM projects_categories c LEFT JOIN projects_entry_categories p ON c.ID = p.categoryID GROUP BY c.ID ORDER BY c.collection')->result_array(); - return $collections; - } - - public function editEntry($data, $id) { - $this->db->update('projects', $data, ['id' => $id]); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - $this->db->cache_delete('admin', 'projects'); - } - - public function addEntry($data) { - $this->db->insert('projects', $data); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('admin', 'projects'); - } - - public function delete($id) { - $this->db->query('DELETE FROM projects WHERE ID = ? LIMIT 1', [$id]); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - $this->db->cache_delete('admin', 'projects'); - } - - public function deleteCategory($id) { - $this->db->query('DELETE FROM projects_entry_categories WHERE categoryID = ?', [$id]); - $this->db->query('DELETE FROM projects_categories WHERE ID = ? LIMIT 1', [$id]); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - $this->db->cache_delete('admin', 'projects'); - } - - public function checkIfExists($id) { - $result = $this->db->query('SELECT ID FROM projects WHERE ID = ? LIMIT 1', [$id])->result_array(); - if(!empty($result)) { - return true; - } else { - return false; + return $content; } - } - public function checkIfNameExists($name) { - $result = $this->db->query('SELECT ID FROM projects WHERE name = ? LIMIT 1', [$name])->result_array(); - if(!empty($result)) { - return true; - } else { - return false; + public function mergeTranslationData($postList, $lang = 'de') + { + foreach ($postList as $i => $post) { + $data = $this->db->query('SELECT * FROM projects_translations WHERE projectID = ? AND (lang = ? OR lang = ?) ORDER BY lang', [$post['ID'], 'de', $lang])->result_array(); + if (sizeof($data) == 1) { + $postList[$i] = array_merge($post, $data[0]); + continue; + } + + $merged = []; + foreach ($data[0] as $key => $value) { + if (($value == NULL && $data[1][$key] == NULL) || ($value != NULL && $data[1][$key] == NULL)) { + $merged[$key] = $value; + } else { + $merged[$key] = $data[1][$key]; + } + } + + $postList[$i] = array_merge($post, $merged); + } + return $postList; } - } - public function getEntry($id) { - return $this->db->query('SELECT * FROM projects WHERE ID = ? LIMIT 1', [$id])->result_array(); - } - - public function getEntryByName($name, $lang = 'de') { - $result = $this->db->query('SELECT * FROM projects WHERE name = ? LIMIT 1', [$name])->result_array(); - - $result = $this->mergeTranslationData($result, $lang); - - return !empty($result) ? $result[0] : null; - } - - public function getEntryCategories($id) { - return $this->db->query('SELECT * FROM projects_categories WHERE ID IN (SELECT categoryID FROM projects_entry_categories WHERE projectID = ?)', [$id])->result_array(); - } - - public function resetEntryCategories($postID) { - $this->db->query('DELETE FROM projects_entry_categories WHERE projectID = ?', $postID); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - $this->db->cache_delete('admin', 'projects'); - } - - public function addCategoryToEntryID($postID, $categoryID) { - $this->db->query('INSERT INTO projects_entry_categories (projectID, categoryID) VALUES (?, ?)', [$postID, $categoryID]); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - $this->db->cache_delete('admin', 'projects'); - } - - public function updateCategories($postID, $categories) { - $this->resetEntryCategories($postID); - foreach ($categories as $category) { - $this->addCategoryToEntryID($postID, $category); + public function getCategories() + { + $collections = $this->db->query('SELECT c.*, count(p.projectID) count FROM projects_categories c LEFT JOIN projects_entry_categories p ON c.ID = p.categoryID GROUP BY c.ID ORDER BY c.collection')->result_array(); + return $collections; } - } - public function addCategoryToEntryName($name, $categoryID) { - $id = $this->db->query('SELECT ID FROM projects WHERE name = ? LIMIT 1', [$name])->result_array()[0]; - $this->addCategoryToEntryID(intval($id['ID']), $categoryID); - } + public function editEntry($data, $id) + { + $this->db->update('projects', $data, ['id' => $id]); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); + $this->db->cache_delete('admin', 'projects'); + } - public function getPrevProject($id) { - $result = $this->db->query('SELECT * FROM projects WHERE datetime < (SELECT datetime FROM projects WHERE ID = ?) ORDER BY datetime DESC LIMIT 1', [$id])->result_array(); + public function addEntry($data) + { + $this->db->insert('projects', $data); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('admin', 'projects'); + } - $result = $this->mergeTranslationData($result, $_SESSION['site_lang']); + public function delete($id) + { + $this->db->query('DELETE FROM projects WHERE ID = ? LIMIT 1', [$id]); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); + $this->db->cache_delete('admin', 'projects'); + } - return $result; - } + public function deleteCategory($id) + { + $this->db->query('DELETE FROM projects_entry_categories WHERE categoryID = ?', [$id]); + $this->db->query('DELETE FROM projects_categories WHERE ID = ? LIMIT 1', [$id]); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); + $this->db->cache_delete('admin', 'projects'); + } - public function getNextProject($id) { - $result = $this->db->query('SELECT * FROM projects WHERE datetime > (SELECT datetime FROM projects WHERE ID = ?) ORDER BY datetime ASC LIMIT 1', [$id])->result_array(); + public function checkIfExists($id) + { + $result = $this->db->query('SELECT ID FROM projects WHERE ID = ? LIMIT 1', [$id])->result_array(); + if (!empty($result)) { + return true; + } else { + return false; + } + } - $result = $this->mergeTranslationData($result, $_SESSION['site_lang']); + public function checkIfNameExists($name) + { + $result = $this->db->query('SELECT ID FROM projects WHERE name = ? LIMIT 1', [$name])->result_array(); + if (!empty($result)) { + return true; + } else { + return false; + } + } - return $result; - } + public function getEntry($id) + { + return $this->db->query('SELECT * FROM projects WHERE ID = ? LIMIT 1', [$id])->result_array(); + } - public function addVote($projectID, $userID, $voteType) { - $this->db->query('DELETE FROM projects_entry_votes WHERE projectID = ? AND userID = ?', [$projectID, $userID]); - $this->db->query('INSERT INTO projects_entry_votes (projectID, userID, type) VALUES (?, ?, ?)', [$projectID, $userID, $voteType]); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - $this->db->cache_delete('projects', 'addVote'); - $this->db->cache_delete('admin', 'projects'); - } + public function getEntryByName($name, $lang = 'de') + { + $result = $this->db->query('SELECT * FROM projects WHERE name = ? LIMIT 1', [$name])->result_array(); - public function getVoteCount($projectID) { - $result = $this->db->query('SELECT (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = ? AND type = 1) - (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = ? AND type = -1) voteCount', [$projectID, $projectID])->result_array(); - return $result[0]['voteCount']; - } + $result = $this->mergeTranslationData($result, $lang); - public function getUserVoteType($projectID, $userID) { - $result = $this->db->query('SELECT type FROM projects_entry_votes WHERE projectID = ? AND userID = ?', [$projectID, $userID])->result_array(); - if(empty($result)) - return 0; - return $result[0]['type']; - } + return !empty($result) ? $result[0] : null; + } - public function createNewProjectDraft() { - $this->db->query('INSERT INTO projects () VALUES ()'); + public function getEntryCategories($id) + { + return $this->db->query('SELECT * FROM projects_categories WHERE ID IN (SELECT categoryID FROM projects_entry_categories WHERE projectID = ?)', [$id])->result_array(); + } - $this->db->cache_delete('admin', 'projects'); + public function updateCategories($postID, $categories) + { + $this->resetEntryCategories($postID); + foreach ($categories as $category) { + $this->addCategoryToEntryID($postID, $category); + } + } - $data = $this->db->query('SELECT ID FROM projects ORDER BY ID DESC LIMIT 1')->result_array(); - return $data[0]['ID']; - } + public function resetEntryCategories($postID) + { + $this->db->query('DELETE FROM projects_entry_categories WHERE projectID = ?', $postID); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); + $this->db->cache_delete('admin', 'projects'); + } - public function updateProject($id, $translations, $url, $download, $openSource, $customLink, $date, $image) { - $this->db->query('UPDATE projects SET name = ?, isDownloadable = ?, downloadLink = ?, isOpenSource = ?, openSourceLink = ?, customLink = ?, datetime = ?, source = ? WHERE ID = ?', [$url, $download['available'], $download['link'], $openSource['available'], $openSource['link'], $customLink['link'], $date, $image, $id]); + public function addCategoryToEntryID($postID, $categoryID) + { + $this->db->query('INSERT INTO projects_entry_categories (projectID, categoryID) VALUES (?, ?)', [$postID, $categoryID]); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); + $this->db->cache_delete('admin', 'projects'); + } - $this->db->cache_off(); - foreach($translations as $lang => $translation) { - $data = $this->db->query('SELECT translationID FROM projects_translations WHERE projectID = ? AND lang = ?', [$id, $lang])->result_array(); + public function addCategoryToEntryName($name, $categoryID) + { + $id = $this->db->query('SELECT ID FROM projects WHERE name = ? LIMIT 1', [$name])->result_array()[0]; + $this->addCategoryToEntryID(intval($id['ID']), $categoryID); + } - if(empty($data)) { - $this->db->query('INSERT INTO projects_translations (projectID, lang) VALUES (?, ?)', [$id, $lang]); + public function getPrevProject($id) + { + $result = $this->db->query('SELECT * FROM projects WHERE datetime < (SELECT datetime FROM projects WHERE ID = ?) ORDER BY datetime DESC LIMIT 1', [$id])->result_array(); + $result = $this->mergeTranslationData($result, $_SESSION['site_lang']); + + return $result; + } + + public function getNextProject($id) + { + $result = $this->db->query('SELECT * FROM projects WHERE datetime > (SELECT datetime FROM projects WHERE ID = ?) ORDER BY datetime ASC LIMIT 1', [$id])->result_array(); + + $result = $this->mergeTranslationData($result, $_SESSION['site_lang']); + + return $result; + } + + public function addVote($projectID, $userID, $voteType) + { + $this->db->query('DELETE FROM projects_entry_votes WHERE projectID = ? AND userID = ?', [$projectID, $userID]); + $this->db->query('INSERT INTO projects_entry_votes (projectID, userID, type) VALUES (?, ?, ?)', [$projectID, $userID, $voteType]); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); + $this->db->cache_delete('projects', 'addVote'); + $this->db->cache_delete('admin', 'projects'); + } + + public function getVoteCount($projectID) + { + $result = $this->db->query('SELECT (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = ? AND type = 1) - (SELECT COUNT(*) FROM projects_entry_votes WHERE projectID = ? AND type = -1) voteCount', [$projectID, $projectID])->result_array(); + return $result[0]['voteCount']; + } + + public function getUserVoteType($projectID, $userID) + { + $result = $this->db->query('SELECT type FROM projects_entry_votes WHERE projectID = ? AND userID = ?', [$projectID, $userID])->result_array(); + if (empty($result)) + return 0; + return $result[0]['type']; + } + + public function createNewProjectDraft() + { + $this->db->query('INSERT INTO projects () VALUES ()'); + + $this->db->cache_delete('admin', 'projects'); + + $data = $this->db->query('SELECT ID FROM projects ORDER BY ID DESC LIMIT 1')->result_array(); + return $data[0]['ID']; + } + + public function updateProject($id, $translations, $url, $download, $openSource, $customLink, $date, $image) + { + $this->db->query('UPDATE projects SET name = ?, isDownloadable = ?, downloadLink = ?, isOpenSource = ?, openSourceLink = ?, customLink = ?, datetime = ?, source = ? WHERE ID = ?', [$url, $download['available'], $download['link'], $openSource['available'], $openSource['link'], $customLink['link'], $date, $image, $id]); + + $this->db->cache_off(); + foreach ($translations as $lang => $translation) { $data = $this->db->query('SELECT translationID FROM projects_translations WHERE projectID = ? AND lang = ?', [$id, $lang])->result_array(); + + if (empty($data)) { + $this->db->query('INSERT INTO projects_translations (projectID, lang) VALUES (?, ?)', [$id, $lang]); + + $data = $this->db->query('SELECT translationID FROM projects_translations WHERE projectID = ? AND lang = ?', [$id, $lang])->result_array(); + } + + $translationID = $data[0]['translationID']; + + $this->db->query('UPDATE projects_translations SET title = ?, description = ?, content = ?, downloadName = ?, openSourceName = ?, customLinkName = ? WHERE translationID = ?', array_merge($translation, [$download['name'], $openSource['name'], $customLink['name'], $translationID])); } + $this->db->cache_on(); - $translationID = $data[0]['translationID']; - - $this->db->query('UPDATE projects_translations SET title = ?, description = ?, content = ?, downloadName = ?, openSourceName = ?, customLinkName = ? WHERE translationID = ?', array_merge($translation, [$download['name'], $openSource['name'], $customLink['name'], $translationID])); + $this->db->cache_delete('admin', 'projects'); + $this->db->cache_delete('projects', 'index'); + $this->db->cache_delete('projects', 'entry'); } - $this->db->cache_on(); - $this->db->cache_delete('admin', 'projects'); - $this->db->cache_delete('projects', 'index'); - $this->db->cache_delete('projects', 'entry'); - } - - public function mergeTranslationData($postList, $lang = 'de') { - foreach ($postList as $i => $post) { - $data = $this->db->query('SELECT * FROM projects_translations WHERE projectID = ? AND (lang = ? OR lang = ?) ORDER BY lang', [$post['ID'], 'de', $lang])->result_array(); - if(sizeof($data) == 1) { - $postList[$i] = array_merge($post, $data[0]); - continue; - } - - $merged = []; - foreach ($data[0] as $key => $value) { - if(($value == NULL && $data[1][$key] == NULL) || ($value != NULL && $data[1][$key] == NULL)) { - $merged[$key] = $value; - } else { - $merged[$key] = $data[1][$key]; + public function mergeFullTranslationData($postList) + { + foreach ($postList as $i => $post) { + $data = $this->db->query('SELECT * FROM projects_translations WHERE projectID = ? ORDER BY lang', [$post['ID']])->result_array(); + foreach ($data as $lang) { + $postList[$i]['translations'][$lang['lang']] = $lang; } } - - $postList[$i] = array_merge($post, $merged); + return $postList; } - return $postList; } -} diff --git a/application/views/admin/footer.php b/application/views/admin/footer.php index ab2bdb6..af8c476 100644 --- a/application/views/admin/footer.php +++ b/application/views/admin/footer.php @@ -12,10 +12,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); + + + + required value="">
@@ -162,13 +162,13 @@ + required>
- +
@@ -177,20 +177,20 @@
+ value="">
+ class="form-control">
- +
@@ -199,20 +199,20 @@
+ value="">
+ class="form-control">
- +
diff --git a/application/views/admin/projects.php b/application/views/admin/projects.php index ad4eac5..9adb8f4 100644 --- a/application/views/admin/projects.php +++ b/application/views/admin/projects.php @@ -117,8 +117,8 @@ - + diff --git a/application/views/footer.php b/application/views/footer.php index a121f15..dfd0d03 100644 --- a/application/views/footer.php +++ b/application/views/footer.php @@ -102,12 +102,10 @@ - - - - "> -