Skip to content
Snippets Groups Projects
milliways.php 3.46 KiB
Newer Older
  • Learn to ignore specific revisions
  • function parseIdleTime($idletime) {
    	$idlearray = preg_split("/[hms]/",$idletime);
    
    		$hours = $idlearray[0];
    		$minutes = $idlearray[1];
    		$seconds = 0;
    
    		$hours = 0;
    		$minutes = $idlearray[0];
    		$seconds = $idlearray[1];
    	} else {
    		$hours = 0;
    		$minutes = 0;
    		$seconds = $idlearray[0];
    	}
    
    
    	return (intval($hours * 3600)) + (intval($minutes) * 60) + intval($seconds);
    
    
    }
    
    function compare_idletime($a, $b) {
    	return strnatcmp($a['idleseconds'], $b['idleseconds']);
    }
    
    
    Justin Mitchell's avatar
    Justin Mitchell committed
    $mwpath = array_search("Milliways", $pathlist);
    
    $newpath = $baseurl;
    for($i=0;$i<=$mwpath;$i++) {
    	if ($i!=0) $newpath .= "/";
    	$newpath .= $pathlist[$i];
    }
    $smarty->assign("mwpath", $newpath);
    
    if (strtolower($pathlist[$mwpath+1]) == "uri") {
    	$today = FALSE;
    	if (isset($pathlist[$mwpath+2]))
    		$today = strtotime($pathlist[$mwpath+2]);
    	if ($today === FALSE)
    		$today = time();
    
    	$smarty->assign("extra_scripts", array(
    		'<meta name="ROBOTS" content="NOINDEX" />',
    		'<meta name="ROBOTS" content="NOFOLLOW" />'));
    
    	$mwdb = new PDO('sqlite:/var/lib/mw/mwuri.db');
    	$res = $mwdb->prepare("select *, time(added) as hour, date(added) as day from mwuri where date(added)=? order by added desc");
    	$res->execute(array(date("Y-m-d",$today)));
    	$data = $res->fetchAll(PDO::FETCH_ASSOC);
    	foreach($data as $k => $row)
    	{
    		if ($row['tags']) {
    			$json = json_decode($row['tags'], TRUE);
    			$data[$k]['taglist'] = $json[0]['top_tags'];
    		}
    	}
    	$smarty->assign("urilist", $data);
    
    	$res = $mwdb->prepare("select distinct strftime('%Y',added) from mwuri");
    	$res->execute();
    	$yearlist = $res->fetchAll(PDO::FETCH_COLUMN,0);
    	$smarty->assign("yearlist",$yearlist);
    
    	$res= $mwdb->prepare("select distinct strftime('%m',added) from mwuri where strftime('%Y',added) = ?");
    	$res->execute(array(date("Y",$today)));
    	$monthlist = $res->fetchAll(PDO::FETCH_COLUMN,0);
    	$smarty->assign("monthlist",$monthlist);
    
    	$res= $mwdb->prepare("select distinct strftime('%d',added) from mwuri where strftime('%Y-%m',added) = ?");
    	$res->execute(array(date("Y-m",$today)));
    	$daylist = $res->fetchAll(PDO::FETCH_COLUMN,0);
    	$smarty->assign("daylist",$daylist);
    
    	$smarty->assign("thisyear", date("Y",$today));
    	$smarty->assign("thismonth", date("m",$today));
    	$smarty->assign("thisday", date("d",$today));
    
    	$output = $smarty->fetch($base."templates/milliways_uri.tpl");
    	$smarty->assign("title", "Milliways URI");
    	$smarty->assign("body", $output);
    	$smarty->assign("extra_styles", "/css/milliways.css");
    	$smarty->assign("refresh", 120);
    	return;
    }
    
    
    exec("/usr/bin/mw -who", $wholist, $ret);
    $people = array();
    
    foreach ($wholist as $person) {
        $pid = strtok($person, " ");
        if ($pid == "" || $pid == "Name" || substr($pid,0,5)=="-----") continue;
    
    	"username" => trim(substr($person, 1, 16)),
    	"idle"     => trim(substr($person, 18, 6)),
    
    	"idleseconds" => parseIdleTime(trim(substr($person, 18, 6))),
    
    	"what"     => substr($person,25));
    
    	if ($person['idleseconds'] > 10800) {
    
    		$idlers[] = $person;
    	} else {
    		$people[] = $person;
    	}
    
    usort($people, 'compare_idletime');
    usort($idlers, 'compare_idletime');
    
    
    Justin Mitchell's avatar
    Justin Mitchell committed
    $output .= print_r($pathlist, true);
    
    $smarty->assign("people",$people);
    
    $smarty->assign("idlers",$idlers);
    
    $output = $smarty->fetch($base."templates/milliways.tpl");
    $smarty->assign("title", "Milliways");
    
    $smarty->assign("body", file_get_contents($base."static/fragments/Milliways.txt"));
    $smarty->assign("secondary", $output);
    
    $smarty->assign("refresh", 120);
    ?>