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); }
public function edit($id) { $data['title'] = 'Edit Category'; $data['token'] = Csrf::makeToken(); $data['row'] = $this->model->get_category($id); $data['categories'] = $this->model->get_categories(); if (isset($_POST['submit'])) { if ($_POST['token'] != Session::get('token')) { Url::redirect('admin/login'); } $category_name = $_POST['category_name']; $category_id_parent = $_POST['category_id_parent']; $category_description = $_POST['category_description']; if ($category_name == '') { $error[] = 'Name is required'; } if (!$error) { $postdata = array('category_name' => $category_name, 'category_id_parent' => $category_id_parent, 'category_description' => $category_description); $where = array('category_id' => $id); $this->model->update_category($postdata, $where); Session::set('message', 'Category Updated'); Url::redirect('admin/categories/edit/' . $id . ''); } } if (isset($_POST['seo'])) { if ($_POST['token'] != Session::get('token')) { Url::redirect('admin/login'); } $category_title = $_POST['category_title']; $category_meta_desc = $_POST['category_meta_desc']; $category_meta_robots = $_POST['category_meta_robots']; $category_url = $_POST['category_url']; if ($category_url == '') { $error[] = 'Url is required'; } if (!$error) { $postdata = array('category_title' => $category_title, 'category_meta_desc' => $category_meta_desc, 'category_meta_robots' => $category_meta_robots, 'category_url' => Url::generateUrl($category_url)); $where = array('category_id' => $id); $this->model->update_category($postdata, $where); Session::set('message', 'SEO Informations Updated'); Url::redirect('admin/categories/edit/' . $id . ''); } } if (isset($_POST['image'])) { if ($_POST['token'] != Session::get('token')) { Url::redirect('admin/login'); } if ($_FILES['category_image']['size'] > 0) { if (!is_dir('images/categories/' . $id . '')) { mkdir('images/categories/' . $id . ''); } $extension_img = substr($_FILES['category_image']['name'], -4); $name_without_extension = substr($_FILES['category_image']['name'], 0, -4); $image_name = Url::generateUrl($name_without_extension) . $extension_img; //var_dump($_FILES['brand_image']['name']); exit; $file = 'images/categories/' . $id . '/' . $image_name; $file_mini = 'images/categories/' . $id . '/m-' . $image_name; move_uploaded_file($_FILES['category_image']['tmp_name'], $file); move_uploaded_file($_FILES['category_image']['tmp_name'], $file_mini); $img = new SimpleImage($file); $img->save($file, 70); $img_mini = new SimpleImage($file); $img_mini->load($file)->fit_to_width(300)->fit_to_height(300)->save($file_mini); $postdata = array('category_image' => $file); $where = array('category_id' => $id); $this->model->update_category($postdata, $where); Session::set('message', 'Image Updated'); Url::redirect('admin/categories/edit/' . $id . ''); } } View::renderadmintemplate('header', $data); View::render('admin/categories/edit', $data, $error); View::renderadmintemplate('footer', $data); }
public function edit($id) { $data['title'] = 'Edit Post'; $data['token'] = Csrf::makeToken(); $data['row'] = $this->posts->get_post($id); $data['posts'] = $this->posts->get_posts(); $data['categories'] = $this->categories->get_all_categories(); if (isset($_POST['submit'])) { if ($_POST['token'] != Session::get('token')) { Url::redirect('admin/login'); } $post_name = $_POST['post_name']; $post_category_id = $_POST['post_category_id']; $post_short_description = $_POST['post_short_description']; $post_long_description = $_POST['post_long_description']; if ($post_name == '') { $error[] = 'Name is required'; } if (!$error) { $postdata = array('post_name' => $post_name, 'post_category_id' => $post_category_id, 'post_short_description' => $post_short_description, 'post_long_description' => $post_long_description, 'post_modified' => (new \DateTime())->format('Y-m-d H:i:s')); $where = array('post_id' => $id); $this->posts->update_post($postdata, $where); Session::set('message', 'Post Updated'); Url::redirect('admin/posts/edit/' . $id . ''); } } if (isset($_POST['seo'])) { if ($_POST['token'] != Session::get('token')) { Url::redirect('admin/login'); } $post_title = $_POST['post_title']; $post_meta_description = $_POST['post_meta_description']; $post_meta_robots = $_POST['post_meta_robots']; $post_url = $_POST['post_url']; if ($post_url == '') { $error[] = 'Url is required'; } if (!$error) { $postdata = array('post_title' => $post_title, 'post_meta_description' => $post_meta_description, 'post_meta_robots' => $post_meta_robots, 'post_url' => Url::generateUrl($post_url), 'post_modified' => (new \DateTime())->format('Y-m-d H:i:s')); $where = array('post_id' => $id); $this->posts->update_post($postdata, $where); Session::set('message', 'SEO Informations Updated'); Url::redirect('admin/posts/edit/' . $id . ''); } } if (isset($_POST['image'])) { if ($_POST['token'] != Session::get('token')) { Url::redirect('admin/login'); } if ($_FILES['post_image']['size'] > 0) { if (!is_dir('images/posts/' . $id . '')) { mkdir('images/posts/' . $id . ''); } $extension_img = substr($_FILES['post_image']['name'], -4); $name_without_extension = substr($_FILES['post_image']['name'], 0, -4); $image_name = Url::generateUrl($name_without_extension) . $extension_img; //var_dump($_FILES['brand_image']['name']); exit; $file = 'images/posts/' . $id . '/' . $image_name; $file_mini = 'images/posts/' . $id . '/m-' . $image_name; move_uploaded_file($_FILES['post_image']['tmp_name'], $file); move_uploaded_file($_FILES['post_image']['tmp_name'], $file_mini); $img = new SimpleImage($file); $img->save($file, 70); $img_mini = new SimpleImage($file); $img_mini->load($file)->fit_to_width(850)->fit_to_height(355)->save($file_mini); $postdata = array('post_image' => $image_name, 'post_modified' => (new \DateTime())->format('Y-m-d H:i:s')); $where = array('post_id' => $id); $this->posts->update_post($postdata, $where); Session::set('message', 'Image Updated'); Url::redirect('admin/posts/edit/' . $id . ''); } } View::renderadmintemplate('header', $data); View::render('admin/posts/edit', $data, $error); View::renderadmintemplate('footer', $data); }