Просмотр файла system/cache.php

Размер файла: 6.84Kb
<?php

function stats_chat() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/chat.dat') < time()-$config['cache_counters']) {
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `chat`"), 0);
		$total_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `chat` WHERE `time` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($total_new > 0) {
			$new = '<span style="color:green">+'.$total_new.'</span>';
		}
		
		$put = '('.$total.') '.$new;

		file_put_contents(FLEVEL.'inc/temp/chat.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/chat.dat');
}

function stats_online() {
    global $config;
    if (@filemtime(FLEVEL.'inc/temp/online.dat') < TIME - $config['cache_counters']) {
        $query_us = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `online` WHERE `id_user` > 0"), 0);
        $query_all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `online`"), 0);
        
        $put = $query_us.'/'.$query_all;

        file_put_contents(FLEVEL.'inc/temp/online.dat', $put, LOCK_EX);
    } 

    return file_get_contents(FLEVEL.'inc/temp/online.dat');
} 

function stats_book() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/book.dat') < time()-$config['cache_counters']) {
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `book`"), 0);
		$total_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `book` WHERE `time` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($total_new > 0) {
			$new = '<span style="color:green">+'.$total_new.'</span>';
		}
		
		$put = '('.$total.') '.$new;

		file_put_contents(FLEVEL.'inc/temp/book.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/book.dat');
}

function stats_blog() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/blogs.dat') < time()-$config['cache_counters']) {
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs`"), 0);
		$total_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs` WHERE `time` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($total_new > 0) {
			$new = '<span style="color:green">+'.$total_new.'</span>';
		}
		
		$put = '('.$total.') '.$new;
		
		file_put_contents(FLEVEL.'inc/temp/blogs.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/blogs.dat');
}

function stats_photos() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/photos.dat') < time()-$config['cache_counters']) {
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos`"), 0);
		$total_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos` WHERE `time` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($total_new > 0) {
			$new = '<span style="color:green">+'.$total_new.'</span>';
		}
		
		$put = '('.$total.') '.$new;
		
		file_put_contents(FLEVEL.'inc/temp/photos.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/photos.dat');
}

function stats_forum() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/forum.dat') < time()-$config['cache_counters']) {
		$forum_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics`"), 0);
		$forum_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg`"), 0);
		$forum_msg_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `time` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($forum_msg_new > 0) {
			$new = '<span style="color:green">+'.$forum_msg_new.'</span>';
		}
		
		$put = '('.$forum_topics.'/'.$forum_msg.') '.$new;
		
		file_put_contents(FLEVEL.'inc/temp/forum.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/forum.dat');
}

function stats_loads() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/loads.dat') < time()-$config['cache_counters']) {
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `ok` = 1"), 0);
		$total_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `time` > '".(time()-86400)."' and `ok` = 1"), 0);
		
		$new = '';
		if ($total_new > 0) {
			$new = '<span style="color:green">+'.$total_new.'</span>';
		}
		
		$put = '('.$total.') '.$new;
		
		file_put_contents(FLEVEL.'inc/temp/loads.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/loads.dat');
}

function stats_users() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/users.dat') < time()-$config['cache_counters']) {
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users`"), 0);
		$total_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `regtime` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($total_new > 0) {
			$new = '<span style="color:green">+'.$total_new.'</span>';
		}
		
		$put = '('.$total.') '.$new;
		
		file_put_contents(FLEVEL.'inc/temp/users.dat', $put, LOCK_EX);
	} 

	return file_get_contents(FLEVEL.'inc/temp/users.dat');
}

function news_index() {
    global $config;
    if (@filemtime(FLEVEL.'inc/temp/news_index.dat') < time()-$config['cache_counters']) {
        $news_r = mysql_query("SELECT * FROM `news` ORDER BY `time` DESC LIMIT 1");
        $news = mysql_fetch_assoc($news_r);
        if (isset($news['id'])) {
            mb_internal_encoding('UTF-8');
            $comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `news_comm` WHERE `id_news` = '$news[id]'"), 0);
            $put = '<a href="news.php?act=view&amp;id='.$news['id'].'"><b>'.$news['name'].'</b></a>: '.ccdate($news['time'], 0).'<br />'.bb(mb_substr($news['text'], 0, 50)).'...<br /><a href="news.php?act=comm&amp;id='.$news['id'].'">Комментарии</a> ('.$comm.')';
        }

        file_put_contents(FLEVEL.'inc/temp/news_index.dat', $put, LOCK_EX);
    } 

    return file_get_contents(FLEVEL.'inc/temp/news_index.dat');
}

function ftopics_index() {
	global $config;
	if (@filemtime(FLEVEL.'inc/temp/ftopics_index.dat') < time()-$config['cache_counters']) {
		file_put_contents(FLEVEL.'inc/temp/ftopics_index.dat', '', LOCK_EX);
		$ftopic_r = mysql_query("SELECT * FROM `forum_topics` ORDER BY `last_time` DESC LIMIT 4");
		while ($t = mysql_fetch_array($ftopic_r)) {
			$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$t[id]'"), 0);
			$last_page = ceil($t_msg/$config['onpage']);
			$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$t[id_cat]'"));
			$lastuser = mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$t[id]' ORDER BY `time` DESC limit 1"));
			$put = '<a href="forum.php?act=topic&amp;id='.$t['id'].'">'.$t['title'].'</a> ('.login($lastuser['id_user']).' <a href="forum.php?act=topic&amp;id='.$t['id'].'&amp;p='.$last_page.'">&raquo;</a>)<br />';
			file_put_contents(FLEVEL.'inc/temp/ftopics_index.dat', $put, FILE_APPEND | LOCK_EX);
		}
	}
	return file_get_contents(FLEVEL.'inc/temp/ftopics_index.dat');
}

?>