diff --git a/codepot/src/codepot/controllers/file.php b/codepot/src/codepot/controllers/file.php index 9f0f4d22..7da725bc 100644 --- a/codepot/src/codepot/controllers/file.php +++ b/codepot/src/codepot/controllers/file.php @@ -368,7 +368,7 @@ class File extends Controller if ($this->files->create ($login['id'], $file) === FALSE) { - unlink (CODEPOT_FILE_DIR . "/{$file->encname}"); + @unlink (CODEPOT_FILE_DIR . "/{$file->encname}"); $data['message'] = 'DATABASE ERROR'; $data['file'] = $file; $this->load->view ($this->VIEW_EDIT, $data); diff --git a/codepot/src/codepot/controllers/user.php b/codepot/src/codepot/controllers/user.php index e7981782..e958099a 100644 --- a/codepot/src/codepot/controllers/user.php +++ b/codepot/src/codepot/controllers/user.php @@ -157,13 +157,56 @@ class User extends Controller $data['login'] = $login; $data['message'] = ''; + $icon_fname = FALSE; + $uploaded_fname = FALSE; + if($this->input->post('settings')) { + if (array_key_exists ('icon_img_file_name', $_FILES)) + { + $fname = $_FILES['icon_img_file_name']['name']; + + if (strpos ($fname, ':') !== FALSE) + { + $data['message'] = $this->lang->line ('FILE_MSG_NAME_NO_COLON'); + $data['file'] = $file; + $this->load->view ($this->VIEW_EDIT, $data); + return; + } + + // delete all \" instances ... + $_FILES['icon_img_file_name']['type'] = + str_replace('\"', '', $_FILES['icon_img_file_name']['type']); + // delete all \\ instances ... + $_FILES['icon_img_file_name']['type'] = + str_replace('\\', '', $_FILES['icon_img_file_name']['type']); + + $config['allowed_types'] = 'png'; + $config['upload_path'] = CODEPOT_USERICON_DIR; + $config['max_size'] = CODEPOT_MAX_UPLOAD_SIZE; + $config['max_width'] = 100; // TODO: make it configurable. + $config['max_height'] = 100; + $config['encrypt_name'] = TRUE; + + $this->load->library ('upload'); + $this->upload->initialize ($config); + + if ($this->upload->do_upload ('icon_img_file_name')) + { + $upload = $this->upload->data (); + $uploaded_fname = $upload['file_name']; + $icon_fname = $login['id'] . '.png'; + } + } + $settings->code_hide_line_num = $this->input->post('code_hide_line_num'); $settings->code_hide_details = $this->input->post('code_hide_details'); + $settings->icon_name = $icon_fname; + $settings->uploaded_icon_name = $uploaded_fname; if ($this->users->storeSettings ($login['id'], $settings) === FALSE) { + @unlink (CODEPOT_USERICON_DIR . '/' . $uploaded_fname); $data['message'] = 'DATABASE ERROR'; $data['settings'] = $settings; $this->load->view ($this->VIEW_SETTINGS, $data); @@ -185,6 +228,7 @@ class User extends Controller if ($settings === FALSE) $data['message'] = 'DATABASE ERROR'; $settings->code_hide_line_num = ' '; $settings->code_hide_details = ' '; + $settings->icon_name = ''; } $data['settings'] = $settings; diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index 028f1464..da7bd1b5 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -35,6 +35,7 @@ $lang['Head revision'] = 'Head revision'; $lang['Hide details'] = 'Hide details'; $lang['History'] = 'History'; $lang['Home'] = 'Home'; +$lang['Icon'] = 'Icon'; $lang['ID'] = 'ID'; $lang['Issue'] = 'Issue'; $lang['Issues'] = 'Issues'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index 36201ae2..ce46927d 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -32,6 +32,7 @@ $lang['Full Difference'] = 'FullDiff'; $lang['Head revision'] = 'Kepala revisi'; $lang['History'] = 'Sejarah'; $lang['Home'] = 'Beranda'; +$lang['Icon'] = 'Icon'; $lang['ID'] = 'ID'; $lang['Issue'] = 'Issue'; $lang['Issues'] = 'Issue'; diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index e9d4b3dc..78066c10 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -35,6 +35,7 @@ $lang['Head revision'] = '최신리비전'; $lang['Hide details'] = '상세내역숨김'; $lang['History'] = '변경기록'; $lang['Home'] = '홈'; +$lang['Icon'] = '아이콘'; $lang['ID'] = '아이디'; $lang['Issue'] = '이슈'; $lang['Issues'] = '이슈'; diff --git a/codepot/src/codepot/models/usermodel.php b/codepot/src/codepot/models/usermodel.php index e060fa67..01c3e952 100644 --- a/codepot/src/codepot/models/usermodel.php +++ b/codepot/src/codepot/models/usermodel.php @@ -35,6 +35,8 @@ class UserModel extends Model function storeSettings ($userid, $settings) { + $icon_name_set = strlen($settings->icon_name) > 0; + $this->db->trans_begin (); $this->db->where ('userid', $userid); @@ -52,6 +54,7 @@ class UserModel extends Model $this->db->set ('userid', $userid); $this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); $this->db->set ('code_hide_details', (string)$settings->code_hide_details); + if ($icon_name_set) $this->db->set ('icon_name', (string)$settings->icon_name); $this->db->insert ('user_settings'); } else @@ -59,6 +62,7 @@ class UserModel extends Model $this->db->where ('userid', $userid); $this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); $this->db->set ('code_hide_details', (string)$settings->code_hide_details); + if ($icon_name_set) $this->db->set ('icon_name', (string)$settings->icon_name); $this->db->update ('user_settings'); } @@ -68,6 +72,16 @@ class UserModel extends Model return FALSE; } + if ($icon_name_set) + { + if (@rename (CODEPOT_USERICON_DIR . '/' . $settings->uploaded_icon_name, + CODEPOT_USERICON_DIR . '/' . $settings->icon_name) === FALSE) + { + $this->db->trans_rollback (); + return FALSE; + } + } + $this->db->trans_commit (); return TRUE; @@ -77,6 +91,7 @@ class UserModel extends Model $this->db->where ('userid', $userid); $this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); $this->db->set ('code_hide_details', (string)$settings->code_hide_details); + if (strlen($settings->icon_name) > 0) $this->db->set ('icon_name', (string)$settings->icon_name); $this->db->update ('user_settings'); if ($this->db->trans_status() === FALSE) diff --git a/codepot/src/codepot/views/user_settings.php b/codepot/src/codepot/views/user_settings.php index 6efc3655..984c95d4 100644 --- a/codepot/src/codepot/views/user_settings.php +++ b/codepot/src/codepot/views/user_settings.php @@ -61,7 +61,7 @@ $this->load->view (
- + lang->line('Code'))?> @@ -74,6 +74,15 @@ $this->load->view ( 'Y', $settings->code_hide_details == 'Y') ?> lang->line('USER_MSG_HIDE_DETAILS')?> + +
+ lang->line('Icon').': ', 'icon_img_file_name')?> + + +