OPEN
serendipity_config.inc.php
FIND
Code: Select all
define('IS_installed', file_exists('serendipity_config_local.inc.php'));
if (IS_installed === true && !defined('IN_serendipity')) {
define('IN_serendipity', true);
}Code: Select all
include(S9Y_INCLUDE_PATH . 'common/cache.php');Code: Select all
<?php
define('CACHE_EXIT_ON_FINISH',0);
define('CACHE_KEY',1);
define('CACHE_TIME',2);
define('CACHE_KEY_ENCODING',3);
define('CACHE_SUFFIX',4);
define('CACHE_LOC',5);
define('CACHE_VERBOSE',6);
define('CACHE_TEST_TIME',7);
define('CACHE_TEST_CALLBACK',8);
define('CACHE_FORCE_NOUSAGE',13);
define('CACHE_FORCE_LAST',14);
define('CACHE_FORCE_REFRESH',15);
define('CACHE_FORCE_USE',16);
define('CACHE_WHOLE_PAGE',19);
define('CACHE_PARTIAL_PAGE',20);
$CACHE_DEFAULTS = array(
);
$cache_registry = array();
function cache_zone_start ($options=NULL) {
global $cache_registry;
cache_test_options($options);
if (cache_resolve_option(CACHE_FORCE_REFRESH,$options,false)) {
$use_cache = false;
$save_this = true;
} else if (cache_resolve_option(CACHE_FORCE_USE,$options,false)) {
$use_cache = true;
$save_this = false;
} else if (cache_resolve_option(CACHE_FORCE_NOUSAGE,$options,false)) {
$use_cache = false;
$save_this = false;
} else if (cache_resolve_option(CACHE_FORCE_LAST,$options,false)) {
$use_cache = true;
$save_this = true;
} else {
if (cache_resolve_option(CACHE_TEST_TIME,$options,true)) {
if ($cache_length = cache_resolve_option(CACHE_TIME,$options,(60*60))) {
$uname = cache_resolve_fname($options);
if (file_exists($uname)) {
if (time() - filemtime($uname) < $cache_length) {
$use_cache = true;
$save_this = false;
} else {
$use_cache = false;
$save_this = true;
}
} else {
$use_cache = false;
$save_this = true;
}
} else {
$use_cache = false;
$save_this = true;
}
}
if (!$use_cache && $func = cache_resolve_option(CACHE_TEST_CALLBACK,$options)) {
$use_cache = $func(&$options);
$save_this = !$use_cache;
}
}
if (!isset($use_cache) || !isset($save_this)) {
$use_cache = false;
$save_this = true;
if (cache_resolve_options(CACHE_VERBOSE,$options)) {
trigger_error('No CACHE_TEST_* or CACHE_FORCE_* method given.',E_WARNING);
}
}
if ($use_cache) {
if (!isset($uname)) {
$uname = cache_resolve_fname($options);
}
if (file_exists($uname)) {
include($uname);
if (cache_resolve_option(CACHE_EXIT_ON_FINISH,$options,true)) {
exit;
}
} else {
$use_cache = false;
$save_this = true;
}
}
ob_start();
$options['using_cache'] = $use_cache;
$options['save_this'] = $save_this;
$cache_registry[] = $options;
return $use_cache;
}
function cache_zone_end() {
global $cache_registry;
$index = count($cache_registry) - 1;
if ($index == -1) {
if (cache_resolve_option(CACHE_VERBOSE,$options)) {
trigger_error("cache_zone_end() called outside of cache zone.",E_WARNING);
}
return -1;
}
$options =& $cache_registry[$index];
if ($options['save_this']) {
$uname = cache_resolve_fname($options);
$cachefile = fopen($uname,'w');
$contents = ob_get_contents();
fwrite($cachefile,$contents);
fclose($cachefile);
ob_end_flush();
} else if ($options['using_cache']) {
ob_end_clean();
if (cache_resolve_option(CACHE_VERBOSE,$options)) {
trigger_error("cache_zone_end() called when a cache was not used.",E_WARNING);
}
} else {
ob_end_flush();
}
unset($cache_registry[$index]);
return $index;
}
function cache_force_refresh($options=NULL) {
cache_test_options($options);
unlink(cache_resolve_fname($options));
}
function cache_set_opt ($option,$value) {
$GLOBALS[$CACHE_DEFAULTS[$option]] = $value;
}
function cache_unset_opt ($option) {
unset($GLOBALS[$CACHE_DEFAULTS[$option]]);
}
function cache_get_opt($option) {
return $GLOBALS[$CACHE_DEFAULTS[$option]];
}
function cache_resolve_fname($options=NULL) {
$key = cache_resolve_option(CACHE_KEY,$options,$REQUEST_URI);
$encoding = cache_resolve_option(CACHE_KEY_ENCODING,$options,'md5');
if (strlen($encoding) > 0) {
$key = $encoding($key);
}
$uname = cache_resolve_option(CACHE_LOC,$options,'cache/') . $key . cache_resolve_option(CACHE_SUFFIX,$options,'.cache');
return $uname;
}
function cache_resolve_option ($key,$options=NULL,$last_resort=NULL) {
global $CACHE_DEFAULTS;
if (is_array($options) && isset($options[$key])) {
return $options[$key];
} else if (isset($CACHE_DEFAULTS[$key])) {
return $CACHE_DEFAULTS[$key];
} else {
return $last_resort;
}
}
function cache_test_options(&$options) {
if (is_array($options)) {
} else if (is_scalar($options)) {
switch ($options) {
case CACHE_WHOLE_PAGE:
$options = array(
CACHE_EXIT_ON_FINISH => true
);
break;
case CACHE_PARTIAL_PAGE:
$options = array(
CACHE_EXIT_ON_FINISH => false
);
break;
default:
if (cache_resolve_option(CACHE_VERBOSE)) {
trigger_error("Passed unknown option. Ignored.",E_WARNING);
}
}
} else if (!isset($options) || is_null($options) || empty($options)) {
$options = array();
} else {
trigger_error("Passed an object or resource. What?");
}
}
?>
