summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2006-08-31 19:52:39 +0000
committerDries Buytaert <dries@buytaert.net>2006-08-31 19:52:39 +0000
commitcdd120ed20922a3130f108ff60b47a4f2130c44d (patch)
tree588404ad09a0705f50699000ac5f7d1d5fda07c2 /includes
parentc29daaaabb7ddb188ea9030c06049c63529844fa (diff)
downloadbrdo-cdd120ed20922a3130f108ff60b47a4f2130c44d.tar.gz
brdo-cdd120ed20922a3130f108ff60b47a4f2130c44d.tar.bz2
- Patch #77936 by moshe and rdouglass: pluggable session handling.
Diffstat (limited to 'includes')
-rw-r--r--includes/module.inc24
-rw-r--r--includes/session.inc39
2 files changed, 61 insertions, 2 deletions
diff --git a/includes/module.inc b/includes/module.inc
index f25331730..fecb9c68a 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -129,6 +129,30 @@ function module_rebuild_cache() {
}
/**
+ * Parse Drupal meta file format.
+ * Uses ini parser provided by php's parse_ini_file().
+ * You should not use the meta files to store module specific settings:
+ * user <code>variable_get()</code> and <code>variable_set()</code> for those.
+ *
+ * Files should use the ini format to specify values:
+ * key = "value"
+ * key2 = value2
+ *
+ * @param $filename
+ * The file we are parsing. Accepts file with relative or absolute path.
+ * @return
+ * The meta data array.
+ */
+function module_parse_meta_file($filename) {
+ $metadata = array();
+
+ if (file_exists($filename)) {
+ $metadata = parse_ini_file($filename);
+ }
+ return $metadata;
+}
+
+/**
* Determine whether a given module exists.
*
* @param $module
diff --git a/includes/session.inc b/includes/session.inc
index 4e219337e..17815eeb9 100644
--- a/includes/session.inc
+++ b/includes/session.inc
@@ -79,8 +79,43 @@ function sess_write($key, $value) {
return TRUE;
}
-function sess_destroy($key) {
- db_query("DELETE FROM {sessions} WHERE sid = '%s'", $key);
+/**
+ * Called when an anonymous user becomes authenticated or vice-versa.
+ */
+function sess_regenerate() {
+ $old_session_id = session_id();
+ session_regenerate_id();
+ db_query("UPDATE {sessions} SET sid = '%s' WHERE sid = '%s'", session_id(), $old_session_id);
+}
+
+/**
+ * Counts how many users have sessions. Can count either anonymous sessions, authenticated sessions, or both.
+ *
+ * @param int $timestamp
+ * A Unix timestamp representing a point of time in the past.
+ * The default is 0, which counts all existing sessions.
+ * @param int $anonymous
+ * TRUE counts only anonymous users.
+ * FALSE counts only authenticated users.
+ * Any other value will return the count of both authenticated and anonymous users.
+ * @return int
+ * The number of users with sessions.
+ */
+function sess_count($timestamp = 0, $anonymous = true) {
+ $query = $anonymous ? ' AND uid = 0' : ' AND uid > 0';
+ return db_result(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d'. $query, $timestamp));
+}
+
+/**
+ * Called by PHP session handling with the PHP session ID to end a user's session.
+ * Can also be called directly, either with the PHP session ID or another identifier
+ * such as uid to end a specific user's session.
+ *
+ * @param string $uid
+ * the user id
+ */
+function sess_destroy($uid) {
+ db_query('DELETE FROM {sessions} WHERE uid = %d', $uid);
}
function sess_gc($lifetime) {