Newer
Older
function parseIdleTime($idletime) {
$idlearray = preg_split("/[hms]/",$idletime);
Graham Cole
committed
if (strstr($idletime,'h')) {
$hours = $idlearray[0];
$minutes = $idlearray[1];
$seconds = 0;
Graham Cole
committed
} elseif (strstr($idletime,'m')) {
$hours = 0;
$minutes = $idlearray[0];
$seconds = $idlearray[1];
} else {
$hours = 0;
$minutes = 0;
$seconds = $idlearray[0];
}
Graham Cole
committed
return (intval($hours * 3600)) + (intval($minutes) * 60) + intval($seconds);
}
function compare_idletime($a, $b) {
return strnatcmp($a['idleseconds'], $b['idleseconds']);
}
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
$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();
Graham Cole
committed
$idlers = array();
foreach ($wholist as $person) {
$pid = strtok($person, " ");
if ($pid == "" || $pid == "Name" || substr($pid,0,5)=="-----") continue;
$person = array(
"username" => trim(substr($person, 1, 16)),
"idle" => trim(substr($person, 18, 6)),
"idleseconds" => parseIdleTime(trim(substr($person, 18, 6))),
Graham Cole
committed
if ($person['idleseconds'] > 10800) {
$idlers[] = $person;
} else {
$people[] = $person;
}
usort($people, 'compare_idletime');
usort($idlers, 'compare_idletime');
$smarty->assign("idlers",$idlers);
$output = $smarty->fetch($base."templates/milliways.tpl");
$smarty->assign("title", "Milliways");
Graham Cole
committed
$smarty->assign("body", file_get_contents($base."static/fragments/Milliways.txt"));
$smarty->assign("secondary", $output);
$smarty->assign("refresh", 120);
?>