public function thumbnail($width, $height = 0) { $thumb_folder = $this->thumb_path(); if (!is_dir($thumb_folder)) { @mkdir($thumb_folder, 0777, true); } $thumb_file = $width . 'x' . $height . '.' . $this->extension; if (!is_file($thumb_folder . $thumb_file)) { $img = image_create_from_file($this->path); $newimg = image_resize_crop($img, $width, $height); image_to_file($newimg, $thumb_folder . $thumb_file); } return is_file($thumb_folder . $thumb_file) ? new self($thumb_folder . $thumb_file) : false; }
public function index() { $result = array(); $result['status_code'] = 403; $result['message'] = "Invalid file namez"; if (!$this->is_ajax_request()) { header('Content-type: text/plain'); } if (!empty($_FILES)) { $config = array(); $config['upload_path'] = './iu-assets/' . $this->user->id . '/'; $config['allowed_types'] = 'gif|jpg|png'; $this->load->library('upload', $config); if (!$this->upload->do_upload('file')) { $result['message'] = $this->upload->display_errors(); } else { $data = $this->upload->data(); if (empty($data['is_image'])) { die(json_encode($result)); } $content_width = $_POST['max_width']; $img_width = $data['image_width']; if ($img_width > $content_width) { $img = image_create_from_file('iu-assets/' . $this->user->id . '/' . $data['file_name']); $img = image_resize($img, $content_width); image_to_file($img, 'iu-assets/' . $this->user->id . '/' . $content_width . '_' . $data['file_name']); $result['url'] = base_url() . 'iu-assets/' . $this->user->id . '/' . $content_width . '_' . $data['file_name']; } else { $result['url'] = base_url() . 'iu-assets/' . $this->user->id . '/' . $data['file_name']; } $result['message'] = 'Success'; $result['status_code'] = 200; } } die(json_encode($result)); }
public function save($id = null) { $this->load->helper('email'); if (!empty($id)) { $id = (int) $id; } if (!$this->user->can('manage_users') && $id !== $this->user->id) { $this->templatemanager->notify_next("You are not allowed to edit users!", 'failure'); redirect('administration/dashboard'); } //get user from db (or instantiate new user obj) if (empty($id)) { $user = new User(); } else { $user = User::factory()->get_by_id($id); } $user->name = $this->input->post('name'); if ($this->user->can('manage_users')) { $user->active = (bool) $this->input->post('active'); } //check name if (empty($user->name) || strlen($user->name) < 5) { $this->templatemanager->notify_next(__("Name can not be empty or shorter than 5 characters."), 'failure'); redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id)); } $role_id = $this->input->post('userrole_id'); //get role if ($this->user->can('manage_users') && !empty($role_id)) { $role = UserRole::factory((int) $role_id); } else { $role = $this->user->userrole->get(); } //other data $email = trim($this->input->post('email')); //check e-mail if (!valid_email($email)) { $this->templatemanager->notify_next(__("Entered e-mail address was not valid."), 'failure'); redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id)); } else { $user->email = $email; } //get, check and update password $password = trim($this->input->post('password')); $password2 = trim($this->input->post('password2')); if (empty($id) && empty($password) && empty($password2)) { $this->templatemanager->notify_next(__("When creating new user you must specify his password!"), 'failure'); redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id)); } if (!empty($password)) { if ($password != $password2) { $this->templatemanager->notify_next(__("Passwords differ!"), 'failure'); redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id)); } else { //if ($user->id != 1) $user->password = $password; //else // $this->templatemanager->notify_next("Changing administrator password is disabled in the demo!", 'information'); } } //prepare for upload $config['upload_path'] = './iu-resources/uploads/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '512'; $config['max_width'] = '1024'; $config['max_height'] = '1024'; $config['encrypt_name'] = true; $this->load->library('upload', $config); //upload profile picture if (!empty($_FILES['picture']['name'])) { if (!$this->upload->do_upload('picture')) { show_error($this->upload->display_errors()); } else { $data = $this->upload->data(); $im = image_create_from_file($config['upload_path'] . $data['file_name']); $im = image_resize($im, 150); image_to_file($im, $config['upload_path'] . $data['file_name']); $user->picture = $data['file_name']; } } //save user $user->save(array($role)); //save user and role //permissions $perms_arr = $this->input->post('permissions'); $perms = Permission::factory()->where_in('id', $perms_arr)->get(); $user->delete(Permission::factory()->get()->all); $user->save($perms->all); //notify user if ($this->user->id != $id) { $this->templatemanager->notify_next(__("User is saved successfully."), "success"); } else { $this->templatemanager->notify_next(__("Profile is updated successfully."), "success"); } if ($this->loginmanager->is_editor()) { redirect('administration/users'); } //go back to previous page if (empty($_SERVER['HTTP_REFERER'])) { redirect('administration/users'); } else { redirect($_SERVER['HTTP_REFERER']); } }
public function get_profile_picture_thumb($width, $height = 0, $template = "iu-resources/uploads/%picture%") { $path = parse_template($template, $this->stored); if ($height > 0 && is_file(str_replace($this->picture, 'thumbs/' . $width . 'x' . $height . '_' . $this->picture, $path))) { return base_url() . str_replace($this->picture, 'thumbs/' . $width . 'x' . $height . '_' . $this->picture, $path) . '?rand=' . rand(1, 99999); } else { $im = image_create_from_file($path); $thumb = image_resize_crop($im, $width, $height); if ($height == 0) { $height = imagesy($thumb); } $th_path = str_replace($this->picture, 'thumbs/' . $width . 'x' . $height . '_' . $this->picture, $path); $ok = image_to_file($thumb, $th_path); if ($ok) { return base_url() . $th_path . '?rand=' . rand(1, 99999); } else { return base_url() . $path . '?rand=' . rand(1, 99999); } } }