## EasyMod 0.3.0 Compatible
##############################################################
## MOD Title: get_db_stat caching
## MOD Author: Huli <
huli0401@gmail.com >
##############################################################
## Author notes:
## I add function to cron to delete this file every 5 minutes.
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
function get_db_stat($mode)
#
#-----[ REPLACE WITH ]------------------------------------------
# Nahradíme celú funkciu get_db_stat#
function get_db_stat($mode)
{
global $db, $phpbb_root_path, $phpEx;
switch( $mode )
{
case 'usercount':
if ( file_exists($phpbb_root_path . 'cache/cache_usercount.'.$phpEx) )
{
include($phpbb_root_path . 'cache/cache_usercount.'.$phpEx);
}
else{
$sql = "SELECT COUNT(user_id) AS total
FROM " . USERS_TABLE . "
WHERE user_id <> " . ANONYMOUS;
if ( !($result = $db->sql_query($sql)) )
{
return false;
}
//$row = $db->sql_fetchrow($result);
$file_data = '<? $row = ' . format_array($db->sql_fetchrow($result)) . '; ?>';
$db->sql_freeresult($result);
$handle = fopen($phpbb_root_path . 'cache/cache_usercount.'.$phpEx, 'w');
@flock($handle, LOCK_EX);
fwrite($handle, $file_data);
@flock($handle, LOCK_UN);
fclose($handle);
include($phpbb_root_path . 'cache/cache_usercount.'.$phpEx);
}
return $row['total'];
break;
case 'newestuser':
if ( file_exists($phpbb_root_path . 'cache/cache_newestuser.' .$phpEx) )
{
include($phpbb_root_path . 'cache/cache_newestuser.' .$phpEx);
}
else{
$sql = "SELECT user_id, username
FROM " . USERS_TABLE . "
WHERE user_id <> " . ANONYMOUS . "
ORDER BY user_id DESC
LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
return false;
}
//$row = $db->sql_fetchrow($result);
$file_data = '<? $row = ' . format_array($db->sql_fetchrow($result)) . '; ?>';
$db->sql_freeresult($result);
$handle = fopen($phpbb_root_path . 'cache/cache_newestuser.'.$phpEx, 'w');
@flock($handle, LOCK_EX);
fwrite($handle, $file_data);
@flock($handle, LOCK_UN);
fclose($handle);
include($phpbb_root_path . 'cache/cache_newestuser.'.$phpEx);
}
return $row;
break;
case 'postcount':
if ( file_exists($phpbb_root_path . 'cache/cache_postcount_topiccount.' .$phpEx) )
{
include($phpbb_root_path . 'cache/cache_postcount_topiccount.' .$phpEx);
}
else{
$sql = "SELECT SUM(forum_posts) AS post_total, SUM(forum_topics) AS topic_total
FROM " . FORUMS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
return false;
}
//$row = $db->sql_fetchrow($result);
$file_data = '<? $row = ' . format_array($db->sql_fetchrow($result)) . '; ?>';
$db->sql_freeresult($result);
$handle = fopen($phpbb_root_path . 'cache/cache_postcount_topiccount.'.$phpEx, 'w');
@flock($handle, LOCK_EX);
fwrite($handle, $file_data);
@flock($handle, LOCK_UN);
fclose($handle);
include($phpbb_root_path . 'cache/cache_postcount_topiccount.'.$phpEx);
}
return $row['post_total'];
break;
case 'topiccount':
if ( file_exists($phpbb_root_path . 'cache/cache_postcount_topiccount.' .$phpEx) )
{
include($phpbb_root_path . 'cache/cache_postcount_topiccount.' .$phpEx);
}
return $row['topic_total'];
break;
}
return false;
}
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
# by Huli <
huli0401@gmail.com >