function extrastats($source, $gnulinux, $win, $mac, $total){ //If print is false, don't give any output. //$handle = fopen($timeFile, 'r'); $data = file('counters/downloadstats.stat'); //Origin time, hourstamp, daystamp, weekstamp, monthstamp, yearstamp, dl's the past hour, dl's the past day, dl's the past week, dl's the past month, dl's the past year. foreach($data as $data){ trim($data); settype($data, "integer"); } $date = date("F j, Y", $data[0]); //settype($count, "integer"); //$timeOffset = time() - $data[1]; //$elapsedHours = $timeOffset / 60 / 60; if(time() - $data[5] > 31556926){ $data = resetyear($data); }else if(time() - $data[4] > 2629744){ $data = resetmonth($data); }else if(time() - $data[3] > 604800){ $data = resetweek($data); }else if(time() - $data[2] > 86400){ $data = resetday($data); }else if(time() - $data[1] > 3600){ $data[1] += 3600; $data[6] = 0; } for($i = 6; $i < 11; $i++){ $data[$i]; } if(isset($_GET["extrastats"])){ echo "There have been: ".$total." total downloads since ".$date.".
\n\t\t"; echo "".$source." were Source, ".$gnulinux." were GNU/Linux, ".$win." were Windows and ".$mac." were Mac OS X.
\n\t\t"; echo "Downloads in the last... Hour: ".$data[6].", Day: ".$data[7].", Week: ".$data[8].", Month: ".$data[9].", Year: ".$data[10]; }else echo "Total Downloads: ".$total; $toWrite = implode("\n", $data); $handle = fopen("counters/downloadstats.stat", 'r+'); rewind($handle); fwrite($handle, $toWrite); fclose($handle); } function resetyear($data){ for($i = 1; $i < 6; $i++){ $data[$i] = $data[5] + 31556926; } for($i = 6; $i < 11; $i++){ $data[$i] = 0; } return $data; } function resetmonth($data){ for($i = 1; $i < 5; $i++){ $data[$i] = $data[4] + 2629744; } for($i = 6; $i < 10; $i++){ $data[$i] = 0; } return $data; } function resetweek($data){ for($i = 1; $i < 4; $i++){ $data[$i] = $data[3] + 604800; } for($i = 6; $i < 9; $i++){ $data[$i] = 0; } return $data; } function resetday($data){ for($i = 1; $i < 3; $i++){ $data[$i] = $data[2] + 86400; } for($i = 6; $i < 8; $i++){ $data[$i] = 0; } return $data; }