$current_month && $next_year >= $current_year ) { $next_month = ''; $next_year = ''; } // ditto for prev_month and prev_year $prev_month = $month - 1; $prev_year = $year; if ( $prev_month < 1 ) { $prev_month = 12; $prev_year--; } // prep the webstats directory (make sure it exists) prep_webstats( $domain, $subdomain ); $xmlfile = ""; $cachefile = ""; if ( $subdomain && $subdomain != "www" ) { $xmlfile = $vhosts .'/'.$domain.'/xml/webstats/'.$subdomain.'/'.$year.'/'.substr('00'.$month, -2).'/webstats.xml'; $cachefile = $vhosts .'/'.$domain.'/xml/webstats/'.$subdomain.'/'.$year.'/'.substr('00'.$month, -2).'/webstats.html'; } else { $xmlfile = $vhosts .'/'.$domain.'/xml/webstats/www/'.$year.'/'.substr('00'.$month, -2).'/webstats.xml'; $cachefile = $vhosts .'/'.$domain.'/xml/webstats/www/'.$year.'/'.substr('00'.$month, -2).'/webstats.html'; } // now find the xsl file //if ( $subdomain != "www" ) { // $xslfile = $vhosts .'/'.$subdomain.'.'.$domain.'/xml/webstats/webstats.xsl'; //} else { // $xslfile = $vhosts .'/'.$domain.'/xml/webstats/webstats.xsl'; //} // if this user doesn't have an xsl file of their own, use the global default // this is the most likely item if ( !file_exists( $xslfile ) ) { $xslfile = $WEBSTATS."/webstats.xsl"; } // update forced because xml file doesn't exist if ( !file_exists( $xmlfile )) { update_webstats( $domain, $subdomain, $year, $month ); } else { // check the modification date of the xml file // if the file is older than today, copy a new version // over // also need to see if the xslfile has been modified $today = date('Ymd'); clearstatcache(); $xml_date = date('Ymd', filemtime($xmlfile)); clearstatcache(); $xsl_date = date('Ymd', filemtime($xslfile)); //print "\n\n"; // if xml file or xsl file is newer than the cache file, redo it // if the xml file is older than today (yesterday's file) update it if ( $xml_date < $today ) { update_webstats( $domain, $subdomain, $year, $month ); } } // if we have no data, redirect to the 'no data' xml file so we don't fry the xslt processor // no_data.xml file specific to this user if ( !file_exists( $xmlfile ) ) { $xmlfile = $vhosts .'/'.$domain.'/xml/webstats/nodata.xml'; $cachefile = ""; } // generic no_data.xml file for everyone if ( !file_exists( $xmlfile ) ) { $xmlfile = $WEBSTATS."/nodata.xml"; } // now we decide whether or not to update the cachefile, or just send it out clearstatcache(); if ( file_exists( $cachefile ) ) { $cache_lastmtime = filemtime( $cachefile ); $cache_date = date('Ymd', filemtime($cachefile)); } else { $cache_lastmtime = '0'; $cache_date = '19700101'; } clearstatcache(); $xml_lastmtime = filemtime( $xmlfile ); clearstatcache(); $xsl_lastmtime = filemtime($xslfile); $now = time(); // we already know what today is //print "\n\n"; // if there is no cache file, the cache hasn't been updated today, the xmlfile is newer, or the xsl file is newer // update the stored cache of information if ( !file_exists( $cachefile ) || ( $cache_date < $today ) || $xml_lastmtime > $cache_lastmtime || $xsl_lastmtime > $cache_lastmtime ) { // rebuild our html data from xml/xsl information // build the xml navigation data for this page $xmldata = "\n"; $xmldata .= " \n"; $xmldata .= " " . $xmlfile . "\n"; $xmldata .= " " . $next_month . "\n"; $xmldata .= " " . $next_year . "\n"; $xmldata .= " " . $prev_month . "\n"; $xmldata .= " " . $prev_year . "\n"; $xmldata .= " " . $month . "\n"; $xmldata .= " " . $month_text . "\n"; $xmldata .= " " . $year . "\n"; $xmldata .= " " . $gif_images_url . "\n"; $xmldata .= " " . $gif_color . "\n"; $xmldata .= " ".$domain."\n"; $xmldata .= " " . $domainname . "\n"; $xmldata .= " " . $top_x_items . "\n"; $xmldata .= " \n"; // dump the data out to a log file for debugging //dump_xml( "/var/log/httpd/xml_dump.log", $xmldata ); // parse xml/xsl and send the output to the browser (duh!) //print "\n"; //print "\n"; $sablot = new SablotHack(); $html = $sablot->parse_xml( $xslfile, $xmldata ); // save the cachefile if ( $cachefile ) { $fh = fopen( $cachefile, 'w' ); if ( $fh ) { fputs( $fh, $html ); fclose( $fh ); } } } else { // just spit out the cached html file $html = join( "\n", file( $cachefile ) ); } print $html; exit; // functions (don't bother looking) function get_month_text( $month_int = 0 ) { if ( !$month_int ) { return $month_int; } $months_array = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); $month_text = $months_array[$month_int - 1]; if ( !$month_text ) { $month_text = $month_int; } return $month_text; } function get_top_x_items() { $directory = dirname( __FILE__ ); $css = $directory .'/webstats.css'; if ( !file_exists( $css ) ) { return 5; } $array = file( $css ); foreach ( $array as $line ) { if ( preg_match( '/\