aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/common.php3
-rw-r--r--phpBB/includes/acm/acm_db.php173
-rw-r--r--phpBB/install/schemas/firebird_schema.sql8
-rw-r--r--phpBB/install/schemas/mysql_schema.sql8
-rw-r--r--phpBB/install/schemas/sqlite_schema.sql8
5 files changed, 199 insertions, 1 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index f4e0ff0c2a..bd0b843673 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -139,6 +139,7 @@ define('ACL_USERS_TABLE', $table_prefix.'auth_users');
define('ATTACHMENTS_TABLE', $table_prefix.'attachments');
define('ATTACHMENTS_DESC_TABLE', $table_prefix.'attach_desc');
define('BANLIST_TABLE', $table_prefix.'banlist');
+define('CACHE_TABLE', $table_prefix.'cache');
define('CONFIG_TABLE', $table_prefix.'config');
define('CONFIRM_TABLE', $table_prefix.'confirm');
define('DISALLOW_TABLE', $table_prefix.'disallow'); //
@@ -188,9 +189,9 @@ set_error_handler('msg_handler');
// Instantiate some basic classes
$user = new user();
$auth = new auth();
-$cache = new acm();
$template = new template();
$db = new sql_db();
+$cache = new acm($db);
// Connect to DB
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
diff --git a/phpBB/includes/acm/acm_db.php b/phpBB/includes/acm/acm_db.php
new file mode 100644
index 0000000000..08972c8d20
--- /dev/null
+++ b/phpBB/includes/acm/acm_db.php
@@ -0,0 +1,173 @@
+<?php
+/***************************************************************************
+ * acm_db.php
+ * -------------------
+ * begin : Saturday, Feb 13, 2001
+ * copyright : (C) 2001 The phpBB Group
+ * email : support@phpbb.com
+ *
+ * $Id$
+ *
+ ***************************************************************************/
+
+/***************************************************************************
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ ***************************************************************************/
+
+class acm
+{
+ var $db;
+ var $is_modified = FALSE;
+ var $vars = '';
+ var $sql_enabled = FALSE;
+
+ function acm(&$db)
+ {
+ $this->db =& $db;
+ }
+
+ function load($var_names = '')
+ {
+ $this->vars = array();
+
+ $sql = 'SELECT var_name, var_ts, var_data
+ FROM ' . CACHE_TABLE;
+
+ if (!empty($var_names))
+ {
+ $sql .= " WHERE var_name IN ('" . implode("', '", $var_names) . "')";
+ }
+
+ $result = $this->db->sql_query($sql);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->vars[$row['var_name']] = array(
+ 'data' => unserialize($row['var_data']),
+ 'ts' => intval($row['var_ts'])
+ );
+ }
+ }
+
+ function unload()
+ {
+ $this->save();
+ unset($this->vars);
+ }
+
+ function save()
+ {
+ if (!$this->is_modified)
+ {
+ return;
+ }
+
+ $delete = $insert = array();
+ foreach ($this->vars as $var_name => $var_ary)
+ {
+ if (!empty($var_ary['is_modified']))
+ {
+ if (!empty($var_ary['delete']))
+ {
+ $delete[] = $var_name;
+ }
+ else
+ {
+ $delete[] = $var_name;
+ $insert[] = "'$var_name', " . time() . ", '" . $this->db->sql_escape(serialize($var_ary['data'])) . "'";
+ }
+
+ $this->db->sql_query($sql);
+ }
+ }
+
+ if (count($delete))
+ {
+ $sql = 'DELETE FROM ' . CACHE_TABLE . "
+ WHERE var_name IN ('" . implode("', '", $delete) . "')";
+ $this->db->sql_query($sql);
+ }
+ if (count($insert))
+ {
+ switch (SQL_LAYER)
+ {
+ case 'mysql':
+ $sql = 'INSERT INTO ' . CACHE_TABLE . ' (var_name, var_ts, var_data)
+ VALUES (' . implode('), (', $insert) . ')';
+ $this->db->sql_query($sql);
+ break;
+
+ default:
+ foreach ($insert as $values)
+ {
+ $sql = 'INSERT INTO ' . CACHE_TABLE . " (var_name, var_ts, var_data)
+ VALUES ($values)";
+ $this->db->sql_query($sql);
+ }
+ }
+ }
+
+ $this->is_modified = FALSE;
+ }
+
+ function tidy($max_age = 0)
+ {
+ $sql = 'DELETE FROM ' . CACHE_TABLE . '
+ WHERE var_ts < ' . (time() - $max_age);
+ $this->db->sql_query($sql);
+ }
+
+ function get($var_name, $max_age = 0)
+ {
+ return ($this->exists($var_name, $max_age)) ? $this->vars[$var_name]['data'] : NULL;
+ }
+
+ function put($var_name, $var_data)
+ {
+ $this->vars[$var_name] = array(
+ 'data' => $var_data,
+ 'ts' => time(),
+ 'is_modified' => TRUE
+ );
+
+ $this->is_modified = TRUE;
+ }
+
+ function destroy($var_name)
+ {
+ if (isset($this->vars[$var_name]))
+ {
+ $this->is_modified = TRUE;
+
+ $this->vars[$var_name] = array(
+ 'is_modified' => TRUE,
+ 'delete' => TRUE
+ );
+ }
+ }
+
+ function exists($var_name, $max_age = 0)
+ {
+ if (!is_array($this->vars))
+ {
+ $this->load();
+ }
+
+ if ($max_age > 0 && isset($this->vars[$var_name]))
+ {
+ if ($this->vars[$var_name]['ts'] + $max_age > time())
+ {
+ $this->destroy($var_name);
+ return FALSE;
+ }
+ }
+
+ return isset($this->vars[$var_name]);
+ }
+}
+?> \ No newline at end of file
diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql
index 99b1a7667e..0e1c82d18b 100644
--- a/phpBB/install/schemas/firebird_schema.sql
+++ b/phpBB/install/schemas/firebird_schema.sql
@@ -131,6 +131,14 @@ CREATE TRIGGER phpbb_banlist_trig
NEW.ban_id = GEN_ID(phpbb_banlist_gen, 1)|
END;
+# Table: 'phpbb_cache'
+CREATE TABLE phpbb_cache (
+ var_name VARCHAR(255) NOT NULL,
+ var_ts INTEGER DEFAULT 0 NOT NULL,
+ var_data TEXT DEFAULT '' NOT NULL,
+ PRIMARY KEY (var_name)
+);
+
# Table: 'phpbb_config'
CREATE TABLE phpbb_config (
config_name VARCHAR(50) NOT NULL,
diff --git a/phpBB/install/schemas/mysql_schema.sql b/phpBB/install/schemas/mysql_schema.sql
index deb4790f72..6e8c78107d 100644
--- a/phpBB/install/schemas/mysql_schema.sql
+++ b/phpBB/install/schemas/mysql_schema.sql
@@ -88,6 +88,14 @@ CREATE TABLE phpbb_banlist (
PRIMARY KEY (ban_id)
);
+# Table: 'phpbb_cache'
+CREATE TABLE phpbb_cache (
+ var_name varchar(255) DEFAULT '' NOT NULL,
+ var_ts int(10) UNSIGNED DEFAULT '0' NOT NULL,
+ var_data text NOT NULL,
+ PRIMARY KEY (var_name)
+);
+
# Table: 'phpbb_config'
CREATE TABLE phpbb_config (
config_name varchar(255) NOT NULL,
diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql
index c1a8675a8f..92b5359f94 100644
--- a/phpBB/install/schemas/sqlite_schema.sql
+++ b/phpBB/install/schemas/sqlite_schema.sql
@@ -78,6 +78,14 @@ CREATE TABLE phpbb_banlist (
PRIMARY KEY (ban_id)
);
+-- Table: 'phpbb_cache'
+CREATE TABLE phpbb_cache (
+ var_name VARCHAR(255) NOT NULL,
+ var_ts INTEGER DEFAULT 0 NOT NULL,
+ var_data TEXT DEFAULT '' NOT NULL,
+ PRIMARY KEY (var_name)
+);
+
-- Table: 'phpbb_config'
CREATE TABLE phpbb_config (
config_name VARCHAR(50) NOT NULL,