From 78dc766e64e3fe8b6cd13eeeb53cf6091a1cbb75 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Fri, 22 Apr 2011 01:48:12 +0200 Subject: [PATCH 1/3] Rename session userdata 'id' to 'user_id' --- application/models/user.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/models/user.php b/application/models/user.php index 1d73ed3..b019b64 100644 --- a/application/models/user.php +++ b/application/models/user.php @@ -274,7 +274,6 @@ class User extends CI_Model { $session_data = array( 'username' => $result->username, - 'id' => $result->id, // kept for backwards compatibility 'user_id' => $result->id, 'group_id' => $result->group_id, 'group' => $group->name From ad2adc97422b9bc7115f98fbe240f6d870d4286f Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Fri, 22 Apr 2011 02:09:36 +0200 Subject: [PATCH 2/3] Begin implementing a custom session class --- application/libraries/MY_Session.php | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 application/libraries/MY_Session.php diff --git a/application/libraries/MY_Session.php b/application/libraries/MY_Session.php new file mode 100644 index 0000000..58c9f97 --- /dev/null +++ b/application/libraries/MY_Session.php @@ -0,0 +1,84 @@ +CI->input->ip_address(), true)); + } + + /** + * Creates a new session. + */ + public function sess_create() { + $this->userdata = array( + 'session_id' => $this->generateHash(), + 'ip_address' => $this->CI->input->ip_address(), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), + 'last_activity' => $this->now + ); + + // save data to the DB if needed + if ($this->sess_use_database === true) { + $this->CI->db->insert($this->sess_table_name, $this->userdata); + } + + // write the cookie + $this->_set_cookie(); + } + + /** + * Updates an existing session. + */ + public function sess_update() { + if ($this->userdata['last_activity'] + $this->sess_time_to_update >= $this->now) { + return; + } + + $oldSessionID = $this->userdata['session_id']; + $newSessionID = $this->generateHash(); + + $this->userdata['session_id'] = $newSessionID; + $this->userdata['last_activity'] = $this->now; + + $cookieData = null; + + // update the DB if needed + if ($this->sess_use_database === true) { + // set cookie explicitly to only have our session data + $cookieData = array(); + foreach (array('session_id', 'user_id', 'ip_address', 'user_agent', 'last_activity') as $val) { + $cookieData[$val] = $this->userdata[$val]; + } + + $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->now, 'user_id' => $this->userdata['user_id'], 'session_id' => $newSessionID), array('session_id' => $oldSessionID)); + + // update users table if user is logged in + if (array_key_exists('user_id', $this->userdata) && $this->userdata['user_id'] > 0) { + $this->CI->db->update('users', array('last_activity' => $this->now), array('id' => $this->userdata['user_id'])); + } + } + + // write the cookie + $this->_set_cookie($cookieData); + } +} + +/* End of file MY_Session.php */ +/* Location: ./application/libraries/MY_Session.php */ From 2ee4d42d7cad7a6b4bc8702cb2e13c6f1f483539 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Fri, 22 Apr 2011 02:38:25 +0200 Subject: [PATCH 3/3] Implement URI language detection --- application/config/routes.php | 3 +++ application/libraries/Lang_detect.php | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/application/config/routes.php b/application/config/routes.php index 47a4a68..08648da 100755 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -41,6 +41,9 @@ $route['default_controller'] = "auth"; $route['404_override'] = ''; +$route['(\w{2})/(.*)'] = '$2'; +$route['(\w{2})'] = $route['default_controller']; + /* End of file routes.php */ /* Location: ./application/config/routes.php */ \ No newline at end of file diff --git a/application/libraries/Lang_detect.php b/application/libraries/Lang_detect.php index 4a9563f..7f2b3ae 100644 --- a/application/libraries/Lang_detect.php +++ b/application/libraries/Lang_detect.php @@ -128,9 +128,8 @@ class Lang_detect { for ($i = $this->CI->uri->total_segments(); $i > 0; $i--) { $segment = $this->CI->uri->segment($i); // the uri segment with the language code has the prefix 'l_' - if (!empty($segment) && (strpos($segment, 'l_') === 0)) { - // extract the language code - return substr($segment, 2); + if (strlen($segment) == 2 && array_key_exists($segment, $this->languages)) { + return $segment; } } return false;