public function editProfile() { $u_id = $this->auth->currentSessionInfo()['uid']; $onlineUsers = new MembersModel(); $username = $onlineUsers->getUserName($u_id); if (sizeof($username) > 0) { if (isset($_POST['submit'])) { if (Csrf::isTokenValid()) { $firstName = strip_tags(Request::post('firstName')); $gender = Request::post('gender') == 'male' ? 'Male' : 'Female'; $website = !filter_var(Request::post('website'), FILTER_VALIDATE_URL) === false ? Request::post('website') : DIR . 'profile/' . $username; $aboutMe = nl2br(strip_tags(Request::post('aboutMe'))); $picture = file_exists($_FILES['profilePic']['tmp_name']) || is_uploaded_file($_FILES['profilePic']['tmp_name']) ? $_FILES['profilePic'] : array(); $userImage = Request::post('oldImg'); if (sizeof($picture) > 0) { $check = getimagesize($picture['tmp_name']); if ($picture['size'] < 1000000 && $check && $check['mime'] == "image/jpeg") { if (!file_exists('images/profile-pics')) { mkdir('images/profile-pics', 0777, true); } $image = new SimpleImage($picture['tmp_name']); $dir = 'images/profile-pics/' . $username[0]->username . '.jpg'; $image->best_fit(400, 300)->save($dir); $userImage = $dir; } } $onlineUsers->updateProfile($u_id, $firstName, $gender, $website, $userImage, $aboutMe); $data['message'] = "Successfully updated profile"; $data['type'] = "success"; } else { $data['message'] = "Error Updating profile"; $data['type'] = "error"; } } $username = $username[0]->username; $profile = $onlineUsers->getUserProfile($username); $data['title'] = $username . "'s Profile"; $data['profile'] = $profile[0]; $data['isLoggedIn'] = $this->auth->isLogged(); $data['csrf_token'] = Csrf::makeToken(); View::renderTemplate('header', $data); View::renderModule('Members/views/edit_profile', $data); View::renderTemplate('footer', $data); } else { Error::error404(); } }
public function newtopic($id) { // Check if user is logged in if ($this->auth->isLoggedIn()) { // Get Current User's ID $u_id = $this->auth->user_info(); } else { //Url::redirect(); } // Output Current User's ID $data['current_userID'] = $u_id; // Get Requested Topic's Title and Description $data['forum_cat'] = $this->model->forum_cat($id); $data['forum_cat_des'] = $this->model->forum_cat_des($id); $data['forum_topics'] = $this->model->forum_topics($id); // Ouput Page Title $data['title'] = "New Topic for " . $data['forum_cat']; // Output Welcome Message $data['welcome_message'] = "Welcome to the new topic page."; // Check to see if current user is a new user $data['is_new_user'] = $this->auth->checkIsNewUser($u_id); // Check to see if user is submitting a new topic if (isset($_POST['submit'])) { // Check to make sure the csrf token is good if (Csrf::isTokenValid()) { // Get data from post $data['forum_title'] = strip_tags(Request::post('forum_title')); $data['forum_content'] = strip_tags(Request::post('forum_content')); // Check to make sure user completed all required fields in form if (empty($data['forum_title'])) { // Username field is empty $error[] = 'Topic Title Field is Blank!'; } if (empty($data['forum_content'])) { // Subject field is empty $error[] = 'Topic Content Field is Blank!'; } // Check for errors before sending message if (count($error) == 0) { // No Errors, lets submit the new topic to db $new_topic = $this->model->sendTopic($u_id, $id, $data['forum_title'], $data['forum_content']); if ($new_topic) { // New Topic Successfully Created Now Check if User is Uploading Image // Check for image upload with this topic $picture = file_exists($_FILES['forumImage']['tmp_name']) || is_uploaded_file($_FILES['forumImage']['tmp_name']) ? $_FILES['forumImage'] : array(); // Make sure image is being uploaded before going further if (sizeof($picture) > 0 && $data['is_new_user'] != true) { // Get image size $check = getimagesize($picture['tmp_name']); // Get file size for db $file_size = $picture['size']; // Make sure image size is not too large if ($picture['size'] < 5000000 && $check && ($check['mime'] == "image/jpeg" || $check['mime'] == "image/png" || $check['mime'] == "image/gif")) { if (!file_exists('images/forum-pics')) { mkdir('images/forum-pics', 0777, true); } // Upload the image to server $image = new SimpleImage($picture['tmp_name']); $new_image_name = "forum-image-topic-uid{$u_id}-fid{$id}-ftid{$new_topic}"; $dir = 'images/forum-pics/' . $new_image_name . '.gif'; $image->best_fit(400, 300)->save($dir); $forumImage = $dir; var_dump($forumImage); // Make sure image was Successfull if ($forumImage) { // Add new image to database if ($this->model->sendNewImage($u_id, $new_image_name, $dir, $file_size, $id, $new_topic)) { $img_success = "<br> Image Successfully Uploaded"; } else { $img_success = "<br> No Image Uploaded"; } } } else { $img_success = "<br> Image was NOT uploaded because the file size was too large!"; } } // Success SuccessHelper::push('You Have Successfully Created a New Topic' . $img_success, 'Topic/' . $new_topic); $data['hide_form'] = "true"; } else { // Fail $error[] = 'New Topic Create Failed'; } } // End Form Complete Check } } // Get Recent Posts List for Sidebar $data['forum_recent_posts'] = $this->model->forum_recent_posts(); // Setup Breadcrumbs $data['breadcrumbs'] = "\n \t\t\t<li><a href='" . DIR . "'>Home</a></li>\n <li><a href='" . DIR . "Forum'>" . $this->forum_title . "</a></li>\n <li><a href='" . DIR . "Topics/{$id}'>" . $data['forum_cat'] . "</a>\n \t\t\t<li class='active'>" . $data['title'] . "</li>\n \t\t"; // Ready the token! $data['csrf_token'] = Csrf::makeToken(); // Send data to view View::renderTemplate('header', $data); View::renderModule('Forum/views/newtopic', $data, $error, $success); View::renderModule('Forum/views/forum_sidebar', $data); View::renderTemplate('footer', $data); }