forked from interstar/trustlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
102 lines (83 loc) · 3.16 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
87
88
89
90
91
92
93
94
95
96
97
98
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$user_name = $_GET{"user"};
$list_name = $_GET{"list"};
$recalc = $_GET{"recalc"};
$f_name = $user_name . "." . $list_name;
$userwhite = "/\A([a-zA-Z0-9_]){1,15}\z/";
#This is actually not complete, apparently almost all characters are allowed.
#We can use this more restrictive set though.
$listwhite = "/\A([a-zA-Z0-9-_]){1,25}\z/";
if (!(preg_match($userwhite,$user_name,$matches))) {
exit("<p class=\"error\">Invalid user name</p>");
}
if (!(preg_match($listwhite,$list_name,$matches))) {
exit("<p class=\"error\">Invalid list name</p>");
}
?>
<h1>The Next Edge : TrustNet</h1>
<h2>Who does <?php echo "$user_name trust in the context of <a href='http://wiki.thenextedge.org/doku.php?id=twitter_trustlists'>$list_name</a>?"; ?></h2>
<?php
$com = "python2.4 trustlist.py --seed $user_name --list $list_name -w --dot $f_name.dot --net $f_name.net> $f_name";
if (!(file_exists($f_name))) {
echo "<p class=\"message\">File didn't exist ... Creating Trust Network</p>";
//echo "<div>$com</div>";
shell_exec($com);
echo "<meta http-equiv=\"refresh\" content=\"5\"/>" #autorefresh in 5 seconds
echo "<div><a href='?user=$user_name&list=$list_name'>Reload</a></div>";
} elseif ($recalc=="1") {
echo "<p class=\"message\">Recreating Trust Network</p>";
shell_exec($com);
echo "<meta http-equiv=\"refresh\" content=\"5\"/>" #autorefresh in 5 seconds
echo "<div><a href='?user=$user_name&list=$list_name'>Reload</a></div>";
} else {
echo "<div id='cloud'>";
$lines = file($f_name);
$depth = "-1";
foreach ($lines as $line) {
if ($line[0] == ":") {
$depth = $depth+1;
} else {
if ($depth < 0) { continue; }
$names = split(" ",$line);
foreach ($names as $name) {
echo "<span class='d$depth'><a href='http://twitter.com/#!/$name'>$name</a> </span>";
}
}
}
echo "</div>";
echo "<div><a href='?user=$user_name&list=$list_name&recalc=1'>Reconstruct Network</a></div>";
}
?>
<?php
$dName = $f_name . ".dot";
if (file_exists($dName)) {
echo "<h2>Current Graph</h2>";
$lines=file($dName);
$dot = implode("",$lines);
$high = intval($depth)*200;
echo "<div><img src='http://chart.googleapis.com/chart?cht=gv&chl=$dot'/></div>";
}
$nName = $f_name . ".net";
if (file_exists($nName)) {
echo "<h2>Historical Graph</h2>";
$lines=file($nName);
$dot = implode("",$lines);
$high = intval($depth)*200;
echo "<div><img src='http://chart.googleapis.com/chart?cht=gv&chl=$dot'/></div>";
}
?>
<div id="searchForm">
<h2>Search Again</h2>
<form method="GET" action="/">
<p>User Name : <input type="text" name="user"/></p>
<p>List Name : <input type="text" name="list"/></p>
<input type="submit"/>
</form>
</div>
</body>
</html>