<?php
define( "ISCNSTATS", "1" );
error_reporting( E_ALL&~E_NOTICE );
function _cb87d93b()
{
	include dirname( __FILE__ ) . "/includes/functions.php";
	$_ccc52f92 = 0;
	$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "UPDATE " . $STATS_CONF["sqlprefix"] . "rss_rebuild SET last='" . date( "Y-m-d", time()-86400 + $COUNTER["timeoffset"] ) . "';" );
	if ( $_6c09ff9d )if ( $GLOBALS["cnstats_db"]->_0242605c() > 0 ) {
			$_2472e8fa["ignore_errors"] = true;
			@ignore_user_abort( 1 );
			@set_time_limit( 0 );
			$_2472e8fa["ignore_errors"] = false;
			$_6b643b84 = $_f1b0ec09 = Array();
			$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "SELECT d2,d3,d4,d5 FROM " . $STATS_CONF["sqlprefix"] . "data WHERE type=7;" );
			if ( !$_6c09ff9d )return;
			if ( $GLOBALS["cnstats_db"]->_3bf5fd4f( $_6c09ff9d ) == 0 ) {
				print"<div class=\"error_box\">" . $LANG["no data"] . "</div>";
				return;
			} while ( $_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d ) )if ( !empty( $_e8b7be43["d2"] ) && !empty( $_e8b7be43["d3"] ) )$_6b643b84[] = $_e8b7be43;
			$GLOBALS["cnstats_db"]->_d8902be8( $_6c09ff9d );
			$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "SELECT d2,d3,d4 FROM " . $STATS_CONF["sqlprefix"] . "data WHERE type=8;" );
			if ( !$_6c09ff9d )return;
			if ( $GLOBALS["cnstats_db"]->_3bf5fd4f( $_6c09ff9d ) == 0 ) {
				print"<div class=\"error_box\">" . $LANG["no data"] . "</div>";
				return;
			} while ( $_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d ) )if ( !empty( $_e8b7be43["d2"] ) && !empty( $_e8b7be43["d3"] ) )$_f1b0ec09[] = $_e8b7be43;
			$GLOBALS["cnstats_db"]->_d8902be8( $_6c09ff9d );
			if ( count( $_6b643b84 ) < 1 ) {
				print"<div class=\"error_box\">" . $LANG["no data"] . "</div>";
				return;
			} 
			if ( count( $_f1b0ec09 ) < 1 ) {
				print"<div class=\"error_box\">" . $LANG["no data"] . "</div>";
				return;
			} 
			$_5b54ae37 = date( "Y-m-d H:i:s", mktime( 0, 0, 0, date( "m" ), date( "d" )-1, date( "Y" ) )-1 );
			$_c25dff8d = date( "Y-m-d H:i:s", mktime( 23, 59, 59, date( "m" ), date( "d" )-1, date( "Y" ) ) + 1 );
			$_24bdb5eb = "";
			foreach( $_f1b0ec09 as$_960ea0a9 => $_6962ccb5 ) {
				$_e2db199b = $GLOBALS["cnstats_db"]->_25e8b08e( trim( $_6962ccb5["d2"] ) );
				$_e2db199b = str_replace( "%", "", $_e2db199b );
				$_f6da45d4 = $GLOBALS["cnstats_db"]->_25e8b08e( trim( $_6962ccb5["d3"] ) );
				$_24bdb5eb = $_24bdb5eb . "IF(LOCATE('" . $_e2db199b . "',agent)!=0,'" . $_f6da45d4 . "',";
				$_fa6826d7++;
			} 
			$_24bdb5eb = $_24bdb5eb . "'NONE'";
			for( $_e66c3671 = 0;$_e66c3671 < $_fa6826d7;$_e66c3671++ )$_24bdb5eb = $_24bdb5eb . ")";
			$_b1d1cc0b = "IF(SUBSTRING(page,1,13)='http%3A%2F%2F',SUBSTRING(page,14),page)";
			$_b1d1cc0b = "IF(SUBSTRING(page,1,17)='http%3A%2F%2Fwww.',SUBSTRING(page,18),$_b1d1cc0b)";
			$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "select " . $_24bdb5eb . " as reader,LEFT(date,10) as date, " . $_b1d1cc0b . " as page,count(*) as cnt FROM " . $STATS_CONF["sqlprefix"] . "log WHERE unique_host='yes' AND date>'" . $_5b54ae37 . "' AND date<'" . $_c25dff8d . "' AND is404='no' AND isrss='yes' group by reader,page;" );
			if ( $_6c09ff9d )while ( $_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d ) ) {
				if ( $_e8b7be43["reader"] != "NONE" ) {
					$_e8b7be43["page"] = urldecode( $_e8b7be43["page"] );
					if ( substr( $_e8b7be43["page"], -1 ) == "/" )$_e8b7be43["page"] = substr( $_e8b7be43["page"], 0, -1 );
					$_dbd66adf = "DELETE FROM " . $STATS_CONF["sqlprefix"] . "rss_cache WHERE title='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["reader"] ) . "' AND url='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["page"] ) . "' AND date='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["date"] ) . "' AND type='standalone';";
					$GLOBALS["cnstats_db"]->_24bdb5eb( $_dbd66adf );
					$_dbd66adf = "INSERT INTO " . $STATS_CONF["sqlprefix"] . "rss_cache SET title='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["reader"] ) . "', url='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["page"] ) . "', date='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["date"] ) . "', type='standalone', subscribers='" . intval( $_e8b7be43["cnt"] ) . "';";
					$GLOBALS["cnstats_db"]->_24bdb5eb( $_dbd66adf );
					$_ccc52f92 += intval( $_e8b7be43["cnt"] );
				} 
			} 
			$GLOBALS["cnstats_db"]->_d8902be8( $_6c09ff9d );
			$_dbd66adf = "";
			foreach( $_6b643b84 as$_7eb6749a ) {
				$_dbd66adf .= " OR agent like '" . $GLOBALS["cnstats_db"]->_25e8b08e( $_7eb6749a["d2"] ) . "'";
			} 
			$_dbd66adf = substr( $_dbd66adf, 4 );
			$_136ac113 = Array();
			$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "select page, LEFT(date,10) as date, agent FROM " . $STATS_CONF["sqlprefix"] . "log WHERE date>'" . $_5b54ae37 . "' AND date<'" . $_c25dff8d . "' AND is404='no' AND isrss='yes' AND (" . $_dbd66adf . ") group by page,date,agent;" );
			if ( $_6c09ff9d )while ( $_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d ) ) {
				$_e8b7be43["page"] = strtolower( urldecode( $_e8b7be43["page"] ) );
				if ( substr( $_e8b7be43["page"], -1 ) == "/" )$_e8b7be43["page"] = substr( $_e8b7be43["page"], 0, -1 );
				for( $_e66c3671 = 0;$_e66c3671 < count( $_6b643b84 );$_e66c3671++ ) {
					$_e8b7be43["agent"] = trim( $_e8b7be43["agent"] );
					$_82079eb1 = false;
					if ( substr( $_6b643b84[$_e66c3671]["d2"], -1 ) == "%" && substr( $_6b643b84[$_e66c3671]["d2"], 0, 1 ) == "%" )$_82079eb1 = strpos( $_e8b7be43["agent"], substr( $_6b643b84[$_e66c3671]["d2"], 1, -1 ) );
					elseif ( substr( $_6b643b84[$_e66c3671]["d2"], -1 ) == "%" )$_82079eb1 = substr( $_6b643b84[$_e66c3671]["d2"], 0, -1 ) == substr( $_e8b7be43["agent"], 0, strlen( $_6b643b84[$_e66c3671]["d2"] )-1 )?true:false;
					elseif ( substr( $_6b643b84[$_e66c3671]["d2"], 0, 1 ) == "%" )$_82079eb1 = substr( $_6b643b84[$_e66c3671]["d2"], 1 ) == substr( $_e8b7be43["agent"], strlen( $_e8b7be43["agent"] ) - ( strlen( $_6b643b84[$_e66c3671]["d2"] )-1 ) )?true:false;
					if ( $_82079eb1 ) {
						$_8a90aba9 = $_e8b7be43["page"];
						if ( substr( $_8a90aba9, 0, 11 ) == "http://www." )$_8a90aba9 = substr( $_8a90aba9, 11 );
						elseif ( substr( $_8a90aba9, 0, 7 ) == "http://" )$_8a90aba9 = substr( $_8a90aba9, 7 );
						$_e8b7be43["subscribers"] = 0;
						$_b1950f0a = StripSlashes( $_6b643b84[$_e66c3671]["d3"] );
						if ( preg_match( $_b1950f0a, "/" . $_e8b7be43["agent"] . "/", $_79b2da48 ) ) {
							$_e8b7be43["subscribers"] = $_79b2da48[1];
						} 
						$_e8b7be43["title"] = $_6b643b84[$_e66c3671]["d4"];
						$_e8b7be43["url"] = $_6b643b84[$_e66c3671]["d5"];
						unset( $_e8b7be43["agent"] );
						$_aa9e377a = $_e8b7be43["date"];
						$_136ac113[] = $_e8b7be43;
						break;
					} 
				} 
			} 
			$_62d277af = Array();
			foreach( $_136ac113 as$_6b643b84 ) {
				if ( substr( $_6b643b84["page"], 0, 11 ) == "http://www." )$_6b643b84["page"] = substr( $_6b643b84["page"], 11 );
				elseif ( substr( $_6b643b84["page"], 0, 7 ) == "http://" )$_6b643b84["page"] = substr( $_6b643b84["page"], 7 );
				if ( isset( $_62d277af[$_6b643b84["page"]][$_6b643b84["title"]] ) ) {
					if ( $_62d277af[$_6b643b84["page"]][$_6b643b84["title"]] <= $_6b643b84["subscribers"] )$_62d277af[$_6b643b84["page"]][$_6b643b84["title"]] = $_6b643b84["subscribers"];
				} else {
					$_62d277af[$_6b643b84["page"]][$_6b643b84["title"]] = $_6b643b84["subscribers"];
				} 
			} 
			foreach( $_62d277af as$_0862575d => $_6b643b84 ) {
				foreach( $_6b643b84 as$_960ea0a9 => $_6962ccb5 ) {
					$_dbd66adf = "DELETE FROM " . $STATS_CONF["sqlprefix"] . "rss_cache WHERE title='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_960ea0a9 ) . "' AND url='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_0862575d ) . "' AND date='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_aa9e377a ) . "' AND type='online';";
					$GLOBALS["cnstats_db"]->_24bdb5eb( $_dbd66adf );
					$_dbd66adf = "INSERT INTO " . $STATS_CONF["sqlprefix"] . "rss_cache SET title='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_960ea0a9 ) . "', url='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_0862575d ) . "', date='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_aa9e377a ) . "', type='online', subscribers='" . intval( $_6962ccb5 ) . "';";
					$_ccc52f92 += intval( $_6962ccb5 );
					$GLOBALS["cnstats_db"]->_24bdb5eb( $_dbd66adf );
				} 
			} 
			$_24bdb5eb = "";
			$_fa6826d7 = 0;
			$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "SELECT d1,d2 FROM " . $STATS_CONF["sqlprefix"] . "data WHERE type=6 ORDER BY id;" );
			if ( $_6c09ff9d )while ( $_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d ) ) {
				$_e2db199b = $GLOBALS["cnstats_db"]->_25e8b08e( trim( $_e8b7be43["d2"] ) );
				$_f6da45d4 = $GLOBALS["cnstats_db"]->_25e8b08e( trim( $_e8b7be43["d1"] ) );
				$_24bdb5eb = $_24bdb5eb . "IF(LOCATE('" . $_e2db199b . "',agent)!=0,'" . $_f6da45d4 . "',";
				$_fa6826d7++;
			} 
			$_24bdb5eb = $_24bdb5eb . "'OTHER'";
			for( $_e66c3671 = 0;$_e66c3671 < $_fa6826d7;$_e66c3671++ )$_24bdb5eb = $_24bdb5eb . ")";
			$_5b4c7914 = _87690f35( $_7fc45f1d );
			$_5b4c7914 = str_replace( " AND isrss='no'", "", $_5b4c7914 );
			$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "SELECT " . $_24bdb5eb . " as browser, page, count(*) as cnt
				  FROM " . $STATS_CONF["sqlprefix"] . "log
				  WHERE isrss='yes' AND " . $_b3d65ad4 . " date>'" . $_eb9e3126 . "' AND date<'" . $_9174ebfd . "' " . $_5b4c7914 . "
				  GROUP BY " . $_24bdb5eb . "
				  ORDER BY 2 desc;" );
			if ( $_6c09ff9d )while ( $_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d ) ) {
				if ( $_e8b7be43["browser"] == "OTHER" )continue;
				$_f47645ae = urldecode( $_e8b7be43["page"] );
				if ( substr( $_f47645ae, 0, 11 ) == "http://www." )$_f47645ae = substr( $_f47645ae, 11 );
				elseif ( substr( $_f47645ae, 0, 7 ) == "http://" )$_f47645ae = substr( $_f47645ae, 7 );
				if ( substr( $_f47645ae, -1 ) == "/" )$_f47645ae = substr( $_f47645ae, 0, -1 );
				$_dbd66adf = "DELETE FROM " . $STATS_CONF["sqlprefix"] . "rss_cache WHERE title='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["browser"] ) . "' AND url='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_f47645ae ) . "' AND date='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_aa9e377a ) . "' AND type='browser';";
				$GLOBALS["cnstats_db"]->_24bdb5eb( $_dbd66adf );
				$_dbd66adf = "INSERT INTO " . $STATS_CONF["sqlprefix"] . "rss_cache SET title='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_e8b7be43["browser"] ) . "', url='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_f47645ae ) . "', date='" . $GLOBALS["cnstats_db"]->_25e8b08e( $_aa9e377a ) . "', type='browser', subscribers='" . intval( $_e8b7be43["cnt"] ) . "';";
				$GLOBALS["cnstats_db"]->_24bdb5eb( $_dbd66adf );
				$_ccc52f92 += intval( $_e8b7be43["cnt"] );
			} 
			$GLOBALS["cnstats_db"]->_d8902be8( $_6c09ff9d );
		} 
		$GLOBALS["cnstats_db"]->_24bdb5eb( "UPDATE " . $STATS_CONF["sqlprefix"] . "counter_total SET readers='" . $_ccc52f92 . "' WHERE date=DATE_FORMAT('" . $_aa9e377a . "','%Y-%m-%d 00:00:00');" );
	} 
	if ( is_file( "config.php" ) ) {
		include"config.php";
		include dirname( __FILE__ ) . "/includes/db.php";
		$_6c09ff9d = $GLOBALS["cnstats_db"]->_74cff91f( $STATS_CONF["sqlhost"], $STATS_CONF["sqluser"], $STATS_CONF["sqlpassword"], $STATS_CONF["dbname"] );
		if ( !$_6c09ff9d )return;
		if ( empty( $STATS_CONF["sqlprefix"] ) )$STATS_CONF["sqlprefix"] = "cns_";
		$_e8b7be43 = Array();
		$_6c09ff9d = $GLOBALS["cnstats_db"]->_24bdb5eb( "SELECT readers FROM " . $STATS_CONF["sqlprefix"] . "counter_total ORDER BY date DESC LIMIT 1" );
		if ( $_6c09ff9d ) {
			$_e8b7be43 = $GLOBALS["cnstats_db"]->_ef336f8e( $_6c09ff9d );
		} 
		header( "Content-type: image/png" );
		$_c6e5dff4 = ImageCreateFromPng( "button-rss.png" );
		$_8985ba28 = ImageColorAllocate( $_c6e5dff4, 0, 0, 0 );
		$_665648e9 = ImageColorAllocate( $_c6e5dff4, $COUNTER["inkR"], $COUNTER["inkG"], $COUNTER["inkB"] );
		ImageString( $_c6e5dff4, 2, 51-6 * strlen( $_e8b7be43["readers"] ), 1, $_e8b7be43["readers"], $_665648e9 );
		ImagePng( $_c6e5dff4 );
		ImageDestroy( $_c6e5dff4 );
		unset( $_e8b7be43 );
		flush();
		register_shutdown_function( "_cb87d93b" );
	} else {
		header( "Content-type: image/png" );
		$_c6e5dff4 = ImageCreateFromPng( "button-rss.png" );
		$_8985ba28 = ImageColorAllocate( $_c6e5dff4, 0, 0, 0 );
		$_665648e9 = ImageColorAllocate( $_c6e5dff4, $COUNTER["inkR"], $COUNTER["inkG"], $COUNTER["inkB"] );
		ImageString( $_c6e5dff4, 2, 51-6 * 8, 1, "error 13", $_665648e9 );
		ImagePng( $_c6e5dff4 );
		ImageDestroy( $_c6e5dff4 );
	} 

	?>