ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/deliantra/www/src/content/recent.content.php
Revision: 1.2
Committed: Sat Apr 3 00:56:45 2010 UTC (16 years, 7 months ago) by sf-dustfinger
Branch: MAIN
Changes since 1.1: +24 -6 lines
Log Message:
Made a minor change to the CSS to make the table slightly darker against the lighter page background.  I also made a change to the table building code so that players who are online have their row shown in light green.  This provides a more convenient visual cue to show that they are online.

File Contents

# User Rev Content
1 sf-dustfinger 1.1 <div id="content">
2     <h2>Recent Deliantra Players</h2>
3    
4     <p>
5     This list is updated every ten minutes to show who is online.
6     </p>
7    
8     <?php
9    
10     /**
11     * array timeDiff(int $t1, int $t2)
12     * $t1 and $t2 must be UNIX timestamp integers, order does not matter
13     * returns array broken down into years/months/weeks/etc.
14     */
15     function timeDiff($t1, $t2)
16     {
17     if($t1 > $t2)
18     {
19     $time1 = $t2;
20     $time2 = $t1;
21     }
22     else
23     {
24     $time1 = $t1;
25     $time2 = $t2;
26     }
27     $diff = array(
28     'years' => 0,
29     'months' => 0,
30     'weeks' => 0,
31     'days' => 0,
32     'hours' => 0,
33     'minutes' => 0,
34     'seconds' =>0
35     );
36    
37     foreach(array('years','months','weeks','days','hours','minutes','seconds')
38     as $unit)
39     {
40     while(TRUE)
41     {
42     $next = strtotime("+1 $unit", $time1);
43     if($next < $time2)
44     {
45     $time1 = $next;
46     $diff[$unit]++;
47     }
48     else
49     {
50     break;
51     }
52     }
53     }
54     return($diff);
55     }
56    
57     function timeDifferenceText($pastDate)
58     {
59     $rightNow = time();
60     $difference = timeDiff($rightNow,$pastDate);
61    
62     if($difference['years']>0)
63     {
64     if($difference['years']==1)
65     {
66     $difference = " 1 year ago";
67     }
68     else
69     {
70     $difference = $difference['years'] . " years ago";
71     }
72     }
73     else if($difference['months']>0)
74     {
75     if($difference['months']==1)
76     {
77     $difference = " 1 month ago";
78     }
79     else
80     {
81     $difference = $difference['months'] . " months ago";
82     }
83     }
84     else if($difference['weeks']>0)
85     {
86     if($difference['weeks']==1)
87     {
88     $difference = " 1 week ago";
89     }
90     else
91     {
92     $difference = $difference['weeks'] . " weeks ago";
93     }
94     }
95     else if($difference['days']>0)
96     {
97     if($difference['days']==1)
98     {
99     $difference = "1 day ago";
100     }
101     else
102     {
103     $difference = $difference['days'] . " days ago";
104     }
105     }
106     else if($difference['hours']>0)
107     {
108     if($difference['hours']==1)
109     {
110     $difference = " 1 hour ago";
111     }
112     else
113     {
114     $difference = $difference['hours'] . " hours ago";
115     }
116     }
117     else if($difference['minutes'])
118     {
119     if($difference['minutes']==1)
120     {
121     $difference = " 1 minute ago";
122     }
123     else
124     {
125     $difference = $difference['minutes'] . " minutes ago";
126     }
127     }
128     else
129     {
130     $difference = " Just now";
131     }
132    
133     return $difference;
134     }
135    
136     //Generate the highscore table. Note: JSON data was already loaded in links.php when we had
137     //to load the recent player list to figure out how many were online.
138    
139     echo "<table style='width: 100%'>\n";
140     echo "<tr><th>Player Name</th><th>Last Login</th><th>Last Logout</th><th>Birthdate</th><th>Logins</th><th>Deaths</th><th>OS</th><th>Go</th></tr>";
141    
142     $number = 0;
143     $size = 100;
144     foreach($players as $player)
145     {
146     echo "<tr style='font-size: $size%'>";
147     $number++;
148    
149     if($number>50 & $size>=50)
150     {
151     $size -= .5; //Decrease the font size.
152     }
153    
154     $name = $player[0];
155     $birthdate = $player[1];
156     $lastLogin = $player[2];
157     $loginCount = $player[3];
158     $lastLogout = $player[4];
159     $client = $player[5];
160     $deaths = $player[6];
161     $location = $player[7];
162    
163     /*
164     //A quick PHP side filter. If needed uncomment.
165    
166     $ancientTest = timeDiff(time(),$lastLogin);
167    
168     if($ancientTest['months']>0)
169     {
170     break; //Haven't logged in for a month.... they aren't exactly recent or online.
171     }
172     */
173    
174     if($deaths==="?")
175     {
176     $deaths = 0;
177     }
178    
179     $loginDifference = timeDifferenceText($lastLogin);
180     if($lastLogout==null)
181     {
182     $logoutDifference = "Currently online";
183     }
184     else
185     {
186     $logoutDifference = timeDifferenceText($lastLogout);
187     }
188     if($birthdate==null)
189     {
190     $birthdateDifference = "Always existed";
191     }
192     else
193     {
194     $birthdateDifference = timeDifferenceText($birthdate);
195     }
196    
197     if(stripos($client,"darwin")!==FALSE)
198     {
199     $operatingSystem = "mac";
200     }
201     else if(stripos($client,"unix")!==FALSE)
202     {
203     $operatingSystem = "mac";
204     }
205     else if(stripos($client,"MSWin32")!==FALSE)
206     {
207     $operatingSystem = "win";
208     }
209     else if(stripos($client,"linux")!==FALSE)
210     {
211     $operatingSystem = "lin";
212     }
213    
214 sf-dustfinger 1.2 if($logoutDifference==="Currently online")
215 sf-dustfinger 1.1 {
216 sf-dustfinger 1.2 $loggedInColor = "#96FFB2";
217     echo "<td style='background-color: $loggedInColor;'>$name</td><td style='background-color: $loggedInColor;'>$loginDifference</td><td style='background-color: $loggedInColor;'>$logoutDifference</td><td style='background-color: $loggedInColor;'>$birthdateDifference</td><td style='background-color: $loggedInColor;'>$loginCount</td><td style='background-color: $loggedInColor;'>$deaths</td>\n";
218     echo "<td style='background-color: $loggedInColor;'><img title='$client' style='width: 20px; height: 20px;' src='images/$operatingSystem.png' /></td>\n";
219    
220     if(stripos($location,"~")!==FALSE or stripos($location,"?random")!==FALSE)
221     {
222     echo "<td align='center' style='background-color: $loggedInColor;'><img title='$name is on a map you can not see: $location' style='width: 20px; height: 20px;' src='images/no.png' /></a></td>\n";
223     }
224     else
225     {
226     echo "<td align='center' style='background-color: $loggedInColor;'><a href='http://maps.deliantra.net$location'><img title='$location' style='width: 20px; height: 20px;' src='images/arrow.png' /></a></td>\n";
227     }
228 sf-dustfinger 1.1 }
229     else
230     {
231 sf-dustfinger 1.2 echo "<td>$name</td><td>$loginDifference</td><td>$logoutDifference</td><td>$birthdateDifference</td><td>$loginCount</td><td>$deaths</td>\n";
232     echo "<td><img title='$client' style='width: 20px; height: 20px;' src='images/$operatingSystem.png' /></td>\n";
233    
234     if(stripos($location,"~")!==FALSE or stripos($location,"?random")!==FALSE)
235     {
236     echo "<td align='center'><img title='$name is on a map you can not see: $location' style='width: 20px; height: 20px;' src='images/no.png' /></a></td>\n";
237     }
238     else
239     {
240     echo "<td align='center'><a href='http://maps.deliantra.net$location'><img title='$location' style='width: 20px; height: 20px;' src='images/arrow.png' /></a></td>\n";
241     }
242 sf-dustfinger 1.1 }
243    
244     echo "</tr>\n";
245     }
246    
247     echo "</table>\n";
248     ?>
249    
250     </div>
251    
252