+ public function profile($username, $videos_offset = 0)
+ {
+ // TODO handle user not found
+
+ $user_id = $this->session->userdata('user_id');
+ if ($user_id)
+ {
+ if (intval($user_id) & USER_ROLE_ADMIN)
+ $allow_unactivated = TRUE;
+ else
+ $allow_unactivated = FALSE;
+ }
+ else
+ $allow_unactivated = FALSE;
+
+ $this->load->config('localization');
+ $this->load->helper('date');
+ $this->lang->load('date');
+
+ // **
+ // ** LOADING MODEL
+ // **
+ // Logged in user time zone
+ $time_zone = $this->session->userdata('time_zone');
+
+ // User data
+ $userdata = $this->users_model->get_userdata($username);
+ $userdata['roles'] = Users_model::roles_to_string($userdata['roles']);
+ $country_list = $this->config->item('country_list');
+ $userdata['country_name'] = $country_list[ $userdata['country'] ];
+ $userdata['last_login'] = human_gmt_to_human_local(
+ $userdata['last_login'], $time_zone);
+ $userdata['time_zone'] = $this->lang->line($userdata['time_zone']);
+
+ // User's videos
+ $this->load->model('videos_model');
+ $vs_data['videos'] = $this->videos_model->get_videos_summary(
+ NULL, $username, intval($videos_offset),
+ $this->config->item('videos_per_page'), 'hottest',
+ $allow_unactivated);
+
+ // Pagination
+ $this->load->library('pagination');
+ $pg_config['base_url'] = site_url("user/profile/$username/");
+ $pg_config['uri_segment'] = 4;
+ $pg_config['total_rows'] = $this->videos_model->get_videos_count(
+ NULL, $username, $allow_unactivated);
+ $pg_config['per_page'] = $this->config->item('videos_per_page');
+ $this->pagination->initialize($pg_config);
+ $vs_data['pagination'] = $this->pagination->create_links();
+ $vs_data['title'] = NULL;
+ $vs_data['category_name'] = ''; // TODO videos_summary with AJAX
+
+ $params = array(
+ 'title'=> $this->lang->line('user_appelation').' '.$username
+ .' – '
+ . $this->config->item('site_name'),
+ 'css'=> array('catalog.css')
+ //'metas' => array('description'=>'')
+ );
+ $this->load->library('html_head_params', $params);
+
+ // Current user profile tab
+ $tab = (! $videos_offset ? 0 : 1);
+
+ // **
+ // ** LOADING VIEWS
+ // **
+ $this->load->view('html_begin', $this->html_head_params);
+ $this->load->view('header', array());
+
+ $vs = $this->load->view('catalog/videos_summary_view', $vs_data, TRUE);
+
+ $main_params['content'] = $this->load->view('user/profile_view',
+ array('userdata'=> $userdata, 'videos_summary'=> $vs, 'tab'=>$tab),
+ TRUE);
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+
+ public function activate($user_id, $method='', $activation_code='')
+ {
+ $user_id = intval($user_id);
+ $res_form_validation = FALSE;
+
+ if ($method == 'code')
+ {
+ if (! $activation_code)
+ $res_form_validation = $this->form_validation->run('activate');
+ // Activation code is provided in URL.
+ else
+ {
+ if ($this->_valid_activation_code($activation_code)
+ && $this->users_model->activate_account($user_id,
+ $activation_code))
+ {
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ return;
+ }
+ else
+ {
+ $this->load->helper('message');
+ show_error_msg_page($this,
+ $this->lang->line(
+ 'user_msg_wrong_activation_code'));
+ return;
+ }
+ }
+ }
+ else if ($method == 'resend')
+ {
+ $res_form_validation =
+ $this->form_validation->run('resend_activation');
+ }
+
+ $userdata = $this->users_model->get_userdata($user_id,
+ 'email, a.activation_code');
+ $email = $userdata['email'];
+ $activated_account = ($userdata['activation_code'] == NULL);
+
+ if ($activated_account)
+ {
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ return;
+ }
+
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($res_form_validation === FALSE)
+ {
+ $params = array(
+ 'title'=> $this->lang->line('user_title_activation')
+ .' – '
+ . $this->config->item('site_name'),
+ //'metas' => array('description'=>'')
+ );
+ $this->load->library('html_head_params', $params);
+
+ // **
+ // ** LOADING VIEWS
+ // **
+ $this->load->view('html_begin', $this->html_head_params);
+ $this->load->view('header', array());
+
+ // Show form
+ $main_params['content'] =
+ $this->load->view('user/activate_view',
+ array( 'user_id'=> $user_id,
+ 'email'=> $userdata['email']),
+ TRUE);
+
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+ else
+ {
+ if ($method == 'code')
+ {
+ // A message which tells the user that the
+ // activation was successful.
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ return;
+ }
+ else if ($method == 'resend')
+ {
+ // Redirect to resent message
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activation_resent'),
+ $this->input->post('email')));
+ return;
+ }
+ }
+ }
+
+ public function recover_password()
+ {
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($this->form_validation->run('recover_password') === FALSE)
+ {
+ $params = array( 'title' =>
+ $this->lang->line(
+ 'user_title_password_recovery')
+ .' – '
+ . $this->config->item('site_name'),
+ //'metas' => array('description'=>'')
+ );
+ $this->load->library('html_head_params', $params);
+
+ // **
+ // ** LOADING VIEWS
+ // **
+ $this->load->view('html_begin', $this->html_head_params);
+ $this->load->view('header', array('selected_menu' =>
+ 'recover_password'));
+
+ $main_params['content'] = $this->load->view(
+ 'user/recover_password_view', array(),
+ TRUE);
+
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+ else
+ {
+ // Resent message
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_password_recovery_email_sent'),
+ $this->input->post('username'),
+ $this->input->post('email')));
+ return;
+ }
+ }
+
+ public function _format_message($msg, $val = '', $sub = '%s')
+ {
+ return str_replace($sub, $val, $this->lang->line($msg));
+ }
+
+ public function _update_session_userdata($data)
+ {
+ foreach ($data as $key=> $val)
+ {
+ if ($this->session->userdata($key))
+ $this->session->set_userdata($key, $val);
+ }
+ }
+
+ public function _is_username_unique($username)
+ {
+ if ($this->users_model->get_userdata($username))
+ return FALSE;
+
+ return TRUE;
+ }
+