This is an adopted for 4images v1.7 cache feature from 4images v1.7.1
Step 1
Create a new file includes/cache_utils.php[/color]
With this code:<?php
/************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: cache_utils.php *
* Copyright: (C) 2002 Jan Sorgalla *
* Email: jan at 4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7.1 *
* *
* Adopted for 4images v1.7 by V@no *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) fN?r weitere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
if (!defined('ROOT_PATH')) {
die("Security violation");
}
function create_cache_id($group, $params = null){
$cache_id = $group;
if (is_array($params)) {
$cache_id .= '.' . implode('.', $params);
} elseif (is_string($params)) {
$cache_id .= '.' . $params;
}
return $cache_id;
}
function get_cache_file($cache_id, $lifetime = null) {
global $cache_enable, $cache_lifetime, $cache_path;
if (!$cache_enable) {
return false;
}
if (!$lifetime) {
$lifetime = $cache_lifetime;
}
$file = $cache_path . '/' . $cache_id;
if (!@is_readable($file)) {
return false;
}
if ($lifetime == -1 || (filemtime($file) + $lifetime) > time()) {
if (!$fp = @fopen($file, 'rb')) {
return false;
}
$data = @fread($fp, filesize($file));
@fclose($fp);
if (defined('PRINT_CACHE_MESSAGES') && PRINT_CACHE_MESSAGES == 1) {
echo "Cache file '$cache_id' <span style='color:green'>used</span><br>";
}
// Replace session ids
global $site_sess;
$replace = $site_sess->mode == 'cookie' ? '' : '\1\2'.SESSION_NAME.'='.$site_sess->session_id;
$data = preg_replace(
'#([\?|&])+(amp;)?%%%SID%%%#',
$replace,
$data
);
return $data;
}
if (defined('PRINT_CACHE_MESSAGES') && PRINT_CACHE_MESSAGES == 1) {
echo "Cache file '$cache_id' <span style='color:purple'>expired</span><br>";
}
return false;
}
function save_cache_file($cache_id, $data) {
global $cache_enable, $cache_lifetime, $cache_path;
if (!$cache_enable) {
return false;
}
$file = $cache_path . '/' . $cache_id;
if ($fp = @fopen($file, 'wb')) {
// Replace session ids
global $site_sess;
$data = str_replace(
SESSION_NAME.'='.$site_sess->session_id,
'%%%SID%%%',
$data
);
@flock($fp, LOCK_EX);
@fwrite($fp, $data);
@flock($fp, LOCK_UN);
@fclose($fp);
if (defined('PRINT_CACHE_MESSAGES') && PRINT_CACHE_MESSAGES == 1) {
echo "Cache file '$cache_id' <span style='color:red'>stored</span><br>";
}
return true;
}
@fclose($fp);
return false;
}
function delete_cache_file($cache_id) {
global $cache_enable, $cache_lifetime, $cache_path;
if (defined('PRINT_CACHE_MESSAGES') && PRINT_CACHE_MESSAGES == 1) {
echo "Cache file '$cache_id' <span style='color:red'>deleted</span><br>";
}
return @unlink($cache_path . '/' . $cache_id);
}
function delete_cache_group($group) {
global $cache_enable, $cache_lifetime, $cache_path;
$handle = @opendir($cache_path);
while ($file = @readdir($handle)) {
if (is_dir($file) || $file{0} == ".") {
continue;
}
if (strpos($file, $group) === 0) {
unlink($cache_path . '/' . $file);
}
}
if (defined('PRINT_CACHE_MESSAGES') && PRINT_CACHE_MESSAGES == 1) {
echo "Cache group '$group' <span style='color:red'>deleted</span><br>";
}
}
function clear_cache() {
global $cache_enable, $cache_lifetime, $cache_path;
$handle = opendir($cache_path);
while ($file = @readdir($handle)) {
if (is_dir($file) || $file{0} == ".") {
continue;
}
unlink($cache_path . '/' . $file);
}
}
?>
Step 2
Open global.php
Find:@include(ROOT_PATH.'config.php');
Add above://-----------------------------------------------------
//--- Cache -------------------------------------------
//-----------------------------------------------------
include(ROOT_PATH.'includes/cache_utils.php');
// Initialize cache configuration
define('PRINT_CACHE_MESSAGES', 0); //show some debug messages
$cache_enable = 1;
$cache_lifetime = 3600; // 1 hour
$cache_path = ROOT_PATH.'cache';
$cache_page_index = 1; //index.php
$cache_page_categories = 1; //categories.php
$cache_page_top = 1; //top.php
//End Initialize cache configuration
Step 3
Open index.php
Find://-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
Add above:$cache_id = create_cache_id(
'cat.page.index',
array(
$user_info[$user_table_fields['user_id']],
isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0,
$config['template_dir'],
$config['language_dir']
)
);
if (!$cache_page_index || !$content = get_cache_file($cache_id)) {
// Always append session id if cache is enabled
if ($cache_page_index) {
$old_session_mode = $site_sess->mode;
$site_sess->mode = 'get';
}
ob_start();
Step 3.1
Find:$site_template->print_template($site_template->parse_template($main_template));
(if u have more then one instance of this line, then find the last one, close to the end of the file)
Add below:$content = ob_get_contents();
ob_end_clean();
if ($cache_page_index) {
// Reset session mode
$site_sess->mode = $old_session_mode;
save_cache_file($cache_id, $content);
}
} // end if get_cache_file()
echo $content;
Step 4
Open categories.php
Find://-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
Add above:$cache_id = create_cache_id(
'cat.page.categories',
array(
$user_info[$user_table_fields['user_id']],
$cat_id,
$page,
$perpage,
isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0,
$config['template_dir'],
$config['language_dir']
)
);
if (!$cache_page_categories || !$content = get_cache_file($cache_id)) {
// Always append session id if cache is enabled
if ($cache_page_categories) {
$old_session_mode = $site_sess->mode;
$site_sess->mode = 'get';
}
ob_start();
Step 4.1
Find:$site_template->print_template($site_template->parse_template($main_template));
(if u have more then one instance of this line, then find the last one, close to the end of the file)
Add below:$content = ob_get_contents();
ob_end_clean();
if ($cache_page_categories) {
// Reset session mode
$site_sess->mode = $old_session_mode;
save_cache_file($cache_id, $content);
}
} // end if get_cache_file()
echo $content;
Step 5
Open top.php
Find:include(ROOT_PATH.'includes/page_header.php');
Add below:$cache_id = create_cache_id(
'top',
array(
$user_info[$user_table_fields['user_id']],
$cat_id,
$config['template_dir'],
$config['language_dir']
)
);
if (!$cache_page_top || !$content = get_cache_file($cache_id)) {
if ($cache_page_top) {
// Always append session id if cache is enabled
$old_session_mode = $site_sess->mode;
$site_sess->mode = 'get';
}
ob_start();
Step 5.1
Find:$site_template->print_template($site_template->parse_template($main_template));
(if u have more then one instance of this line, then find the last one, close to the end of the file)
Add below:$content = ob_get_contents();
ob_end_clean();
if ($cache_page_top) {
// Reset session mode
$site_sess->mode = $old_session_mode;
save_cache_file($cache_id, $content);
}
} // end if get_cache_file()
echo $content;
Step 6
Create a new folder cache[/color] in your 4images root directory. Make sure its writible (CHMOD 777)
Step 7 (optional)
Create a new file admin/plugins/clear_cache.php (create plugins folder if u dont have it yet) with the folowing code inside:
<?php // PLUGIN_TITLE: Clear Cache
/**************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: clear_cache.php *
* Copyright: (C) 2002 Jan Sorgalla *
* Email: jan@4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7.1 *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) f?tere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
$nozip = 1;
define('IN_CP', 1);
$root_path = "./../../";
define('ROOT_PATH', $root_path);
require(ROOT_PATH.'admin/admin_global.php');
if ($config['language_dir'] == 'deutsch') {
$lang_clear_cache = 'Cache leeren';
$lang_clear_confirm = 'Wollen Sie das Cache-Verzeichnis leeren (%s)?';
$lang_clear_success = 'Cache-Verzeichnis geleert';
} else {
$lang_clear_cache = 'Clear Cache';
$lang_clear_confirm = 'Do you want to clear the cache directory (%s)?';
$lang_clear_success = 'Cache directory cleared';
}
show_admin_header();
if ($action == "clearcache") {
@set_time_limit(0);
clear_cache();
$msg = $lang_clear_success;
}
if ($msg != "") {
printf("<b>%s</b>n", $msg);
}
show_form_header($HTTP_SERVER_VARS['PHP_SELF'], "clearcache");
show_table_header($lang_clear_cache);
show_description_row(sprintf($lang_clear_confirm, realpath($cache_path)));
show_form_footer($lang['submit'], "");
show_admin_footer();
?>