Commit 87575929 authored by Dries's avatar Dries

- Introduced caching support.
parent eacfc042
......@@ -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();
}
}
}
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -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";
......
......@@ -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";
......
......@@ -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)
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment