summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-06-30 20:23:33 +0000
committerDries Buytaert <dries@buytaert.net>2001-06-30 20:23:33 +0000
commit87575929a5a540b7085d3376fb34548cba130bdd (patch)
treefacd2c1d316c0f7d532e8ba983f5782f0befc87a
parenteacfc0425d8e6905e048f3ab934e4baa00b0abb3 (diff)
downloadbrdo-87575929a5a540b7085d3376fb34548cba130bdd.tar.gz
brdo-87575929a5a540b7085d3376fb34548cba130bdd.tar.bz2
- Introduced caching support.
-rw-r--r--includes/comment.inc3
-rw-r--r--includes/common.inc39
-rw-r--r--modules/box.module4
-rw-r--r--modules/system.module15
-rw-r--r--modules/system/system.module15
-rw-r--r--updates/2.00-to-x.xx.sql7
6 files changed, 73 insertions, 10 deletions
diff --git a/includes/comment.inc b/includes/comment.inc
index d5ccda112..428245a02 100644
--- a/includes/comment.inc
+++ b/includes/comment.inc
@@ -126,6 +126,9 @@ function comment_post($edit) {
// add comment to database:
db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('". check_input($edit[id]) ."', '". check_input($edit[pid]) ."', '$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[comment]) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')");
+
+ // clear cache:
+ cache_clear();
}
}
}
diff --git a/includes/common.inc b/includes/common.inc
index a5cbba931..c21036961 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -87,6 +87,34 @@ function format_plural($count, $singular, $plural) {
return ($count == 1) ? "$count ". t($singular) : "$count ". t($plural);
}
+function cache_clear($interval = 0) {
+ db_query("DELETE FROM cache WHERE ". time() ." - timestamp > $interval");
+}
+
+function cache_get() {
+ global $user, $REQUEST_URI, $REQUEST_METHOD;
+
+ if ($user->id || $REQUEST_METHOD != "GET") {
+ return 0;
+ }
+
+ if ($cache = db_fetch_object(db_query("SELECT * FROM cache WHERE url = '". check_input($REQUEST_URI) ."'"))) {
+ cache_clear(variable_get("cache_clear", 30));
+
+ return $cache->data;
+ }
+
+ ob_start();
+
+ return 0;
+}
+
+function cache_set() {
+ global $REQUEST_URI;
+
+ db_query("INSERT INTO cache (url, data, timestamp) VALUES('". check_input($REQUEST_URI) ."', '". check_code(ob_get_contents()) ."', '". time() ."')");
+}
+
function format_interval($timestamp) {
$units = array("year|years" => 31536000, "week|weeks" => 604800, "day|days" => 86400, "hour|hours" => 3600, "min|min" => 60, "sec|sec" => 1);
foreach ($units as $key=>$value) {
@@ -245,12 +273,23 @@ function page_header() {
if (variable_get("dev_timer", 0)) {
timer_start();
}
+
+ if (variable_get("cache", 0)) {
+ if ($data = cache_get()) {
+ print $data;
+ exit();
+ }
+ }
}
function page_footer() {
if (variable_get("dev_timer", 0)) {
timer_print();
}
+
+ if (variable_get("cache", 0)) {
+ cache_set();
+ }
}
$conf = conf_init();
diff --git a/modules/box.module b/modules/box.module
index c34ddaf87..9d8c5bc83 100644
--- a/modules/box.module
+++ b/modules/box.module
@@ -79,7 +79,7 @@ function box_save($edit) {
db_query("UPDATE boxes SET title = '". check_input($edit[title]) ."', body = '". check_input($edit[body]) ."', info = '". check_input($edit[info]) ."', link = '". check_input($edit[link]) ."', type = '". check_input($edit[type]) ."' WHERE bid = '". check_input($edit[bid]) ."'");
}
else if ($edit[bid]) {
- db_query("DELETE FROM boxes WHERE bid = '". check_input($edit[bid]) ."'");
+ db_query("DELETE FROM boxes WHERE bid = '". check_input($edit[bid]) ."'");
}
else {
db_query("INSERT INTO boxes (title, body, info, link, type) VALUES ('". check_input($edit[title]) ."', '". check_input($edit[body]) ."', '". check_input($edit[info]) ."', '". check_input($link) ."', '". check_input($edit[type]) ."')");
@@ -132,7 +132,7 @@ function box_admin() {
// fall through:
case "Submit":
print status(box_save($edit));
- // fall through:
+ // fall through:
default:
print box_display();
}
diff --git a/modules/system.module b/modules/system.module
index b31a9dcad..1b459c87f 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -13,12 +13,12 @@ function system_help() {
}
function system_perm() {
- return array("administer site options");
+ return array("administer system settings");
}
function system_link($type) {
- if ($type == "admin" && user_access("administer site options")) {
- $links[] = "<a href=\"admin.php?mod=system\">configuration options</a>";
+ if ($type == "admin" && user_access("administer system settings")) {
+ $links[] = "<a href=\"admin.php?mod=system\">system settings</a>";
}
return $links ? $links : array();
@@ -36,6 +36,13 @@ function system_view_options() {
$output .= form_textfield(t("Anonymous user"), "anonymous", variable_get("anonymous", "Anonymous"), 30, 55, t("The name used to indicate anonymous users."));
$output .= "<HR>\n";
+ // caching:
+ $output .= "<H3>Cache settings</H3>\n";
+ $period = array(10 => format_interval(10), 20 => format_interval(20), 30 => format_interval(30), 40 => format_interval(40), 50 => format_interval(50), 50 => format_interval(50), 60 => format_interval(60), 90 => format_interval(90), 120 => format_interval(120), 150 => format_interval(150), 180 => format_interval(180), 210 => format_interval(210), 240 => format_interval(240), 270 => format_interval(270), 300 => format_interval(300), 360 => format_interval(360), 420 => format_interval(420), 480 => format_interval(480), 540 => format_interval(540), 600 => format_interval(600), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200));
+ $output .= form_select(t("Cache support"), "cache", variable_get("cache", 0), array("Disabled", "Enabled"), t("Enable or disable the caching of pages."));
+ $output .= form_select(t("Discard cached pages older than"), "cache_clear", variable_get("cache_clear", 30), $period, t("The time cached pages should be kept. Older pages are automatically refreshed."));
+ $output .= "<HR>\n";
+
// submission settings:
$output .= "<H3>Submission settings</H3>\n";
$size = array(1000 => "1.000 characters", 5000 => "5.000 characters", 10000 => "10.000 characters", 15000 => "15.000 characters", 30.000 => "30.000 characters", 50000 => "50.000 characters", 100000 => "100.000 characters");
@@ -122,7 +129,7 @@ function system_modules() {
function system_admin() {
global $edit, $op, $type;
- if (user_access("administer site options")) {
+ if (user_access("administer system settings")) {
print "<SMALL><A HREF=\"admin.php?mod=system&type=options\">site settings</A> | <A HREF=\"admin.php?mod=system&type=filter\">content filters</A> | <A HREF=\"admin.php?mod=system&op=modules\">modules</A> | <A HREF=\"admin.php?mod=system&op=help\">help</A></SMALL><HR>\n";
diff --git a/modules/system/system.module b/modules/system/system.module
index b31a9dcad..1b459c87f 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -13,12 +13,12 @@ function system_help() {
}
function system_perm() {
- return array("administer site options");
+ return array("administer system settings");
}
function system_link($type) {
- if ($type == "admin" && user_access("administer site options")) {
- $links[] = "<a href=\"admin.php?mod=system\">configuration options</a>";
+ if ($type == "admin" && user_access("administer system settings")) {
+ $links[] = "<a href=\"admin.php?mod=system\">system settings</a>";
}
return $links ? $links : array();
@@ -36,6 +36,13 @@ function system_view_options() {
$output .= form_textfield(t("Anonymous user"), "anonymous", variable_get("anonymous", "Anonymous"), 30, 55, t("The name used to indicate anonymous users."));
$output .= "<HR>\n";
+ // caching:
+ $output .= "<H3>Cache settings</H3>\n";
+ $period = array(10 => format_interval(10), 20 => format_interval(20), 30 => format_interval(30), 40 => format_interval(40), 50 => format_interval(50), 50 => format_interval(50), 60 => format_interval(60), 90 => format_interval(90), 120 => format_interval(120), 150 => format_interval(150), 180 => format_interval(180), 210 => format_interval(210), 240 => format_interval(240), 270 => format_interval(270), 300 => format_interval(300), 360 => format_interval(360), 420 => format_interval(420), 480 => format_interval(480), 540 => format_interval(540), 600 => format_interval(600), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200));
+ $output .= form_select(t("Cache support"), "cache", variable_get("cache", 0), array("Disabled", "Enabled"), t("Enable or disable the caching of pages."));
+ $output .= form_select(t("Discard cached pages older than"), "cache_clear", variable_get("cache_clear", 30), $period, t("The time cached pages should be kept. Older pages are automatically refreshed."));
+ $output .= "<HR>\n";
+
// submission settings:
$output .= "<H3>Submission settings</H3>\n";
$size = array(1000 => "1.000 characters", 5000 => "5.000 characters", 10000 => "10.000 characters", 15000 => "15.000 characters", 30.000 => "30.000 characters", 50000 => "50.000 characters", 100000 => "100.000 characters");
@@ -122,7 +129,7 @@ function system_modules() {
function system_admin() {
global $edit, $op, $type;
- if (user_access("administer site options")) {
+ if (user_access("administer system settings")) {
print "<SMALL><A HREF=\"admin.php?mod=system&type=options\">site settings</A> | <A HREF=\"admin.php?mod=system&type=filter\">content filters</A> | <A HREF=\"admin.php?mod=system&op=modules\">modules</A> | <A HREF=\"admin.php?mod=system&op=help\">help</A></SMALL><HR>\n";
diff --git a/updates/2.00-to-x.xx.sql b/updates/2.00-to-x.xx.sql
index c1babf411..346ad8d05 100644
--- a/updates/2.00-to-x.xx.sql
+++ b/updates/2.00-to-x.xx.sql
@@ -292,3 +292,10 @@ CREATE TABLE referer (
ALTER TABLE boxes CHANGE subject title varchar(64) DEFAULT '' NOT NULL;
ALTER TABLE boxes CHANGE content body TEXT;
ALTER TABLE boxes CHANGE id bid tinyint(4) DEFAULT '0' NOT NULL auto_increment;
+
+CREATE TABLE cache (
+ url varchar(255) DEFAULT '' NOT NULL,
+ data text NOT NULL,
+ timestamp int(11) NOT NULL,
+ PRIMARY KEY (url)
+);