Title: [PHP] analytics.php Author: Twilypastes Pastebin link: http://pastebin.com/v3GKeue3 First Edit: Saturday 21st of March 2015 08:14:29 PM CDT Last Edit: Last edit on: Saturday 25th of April 2015 04:05:07 PM CDT |\n      *      *  Example (analytics.log):      *      ...      *      1425943113|firefox-css      *      1425943138|4chan-css      *      1425943190|homepage      *      ...      */       $file   ="./analytics.log";     $tNow   =time();       //$cDate =filectime($file);     $cDate  =1425945438;     $age    =$tNow-$cDate;       if($age<=86400) {                       // <= 24 hours         $aText=" hour";         $age=floor($age/60/60);     } elseif($age>86400 && $age<=588000) {  // <=  7 days         $aText=" day";         $age=floor($age/60/60/24);     } else {                                // >   7 days         $aText=" week";         $age=floor($age/60/60/24/7);     }     $aText .=($age<>1)?'s':'';       // Offset declarations     $tHour  =$tNow-(60*60);     $tDay   =$tNow-(60*60*24);     $tWeek  =$tNow-(60*60*24*7);     $tMonth =$tNow-(60*60*24*30);     $tYear  =$tNow-(60*60*24*365);       $tToday =strtotime('00:00:00');       // Read log line by line into multidimensional f(ull)Arr(ay)     $fArr=array();     $i=0;     $fh=fopen($file,'r') or die("Failed to read log file");     if($fh) {         while(!feof($fh)) {             $buffer=explode('|',fgets($fh,4096));               if($buffer[0]>=$tWeek) { // Maximum time frame                 $fArr[$i]['time']=$buffer[0];                 $fArr[$i]['name']=substr($buffer[1],0,-1);                   $i++;             }         }           fclose($fh);     }       // Calculate activity/hour between offset and now     function activity($offset) {         global $fArr,$max;           unset($rArr);         $rArr=array();           $max=1;         for($i=0;$i=$offset) {                 $dt=new DateTime('@'.$fArr[$i]['time']);                 $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));                 $hour=intval($dt->format('H'));                   // The index of the r(elevant)Arr(ay) is equal to the current hour of the timestamps day                 $rArr[$hour]+=1;                   // Set highest number of hits                 $max=($max<$rArr[$hour])?$rArr[$hour]:$max;             }         }           return $rArr;     }       // Calculate hits/file between offset and now     function hitcount($offset) {         global $fArr,$max;           unset($rArr);         $rArr=array();           for($i=0;$i=$offset) array_push($rArr,$fArr[$i]['name']);         }           // Sort alphabetically         // !!(Required for counting the number of repeating equal files in array)!!         sort($rArr);           // Calculate hits/file in h(its)Arr(ay)         unset($hArr);         $hArr=array();           $max=1; $j=-1;         for($i=0;$i1)?' hits':' hit';         $percent=floor($hits*100/$max);           $rowStr ="    
";         $rowStr.="
".$name."
";         $rowStr.="
".$hits.$hText."
";         $rowStr.="
\n";           return $rowStr;     } ?> twily.info :: analytics      
Top 10 Last 60 Minutes
       
 
Top 10 Last 24 Hours
         
 
Top 10 Last 7 Days
           
 
 
Activity/Hour Last 7 Days
     
=6 && $i<18)?"☀":"☾")); ?>
 
Analytics started ago.