@@ -103,6 +103,9 @@ discard block |
||
103 | 103 | |
104 | 104 | // Function prints a description of $table |
105 | 105 | // |
106 | +/** |
|
107 | + * @param integer $which |
|
108 | + */ |
|
106 | 109 | function print_describe_table_onecol($table, $which, $columns) { |
107 | 110 | $db = BoincDb::get(true); |
108 | 111 | $result = $db->do_query("SELECT * from $table LIMIT 1"); |
@@ -262,6 +265,10 @@ discard block |
||
262 | 265 | $this->urlquery .= "&clauses=$clause"; |
263 | 266 | } |
264 | 267 | } |
268 | + |
|
269 | + /** |
|
270 | + * @param string $name |
|
271 | + */ |
|
265 | 272 | function addeq($name) { |
266 | 273 | if (isset($_GET[$name])) { |
267 | 274 | $value = $_GET[$name]; |
@@ -273,6 +280,10 @@ discard block |
||
273 | 280 | $this->urlquery .= "&$name=".urlencode($value); |
274 | 281 | } |
275 | 282 | } |
283 | + |
|
284 | + /** |
|
285 | + * @param string $name |
|
286 | + */ |
|
276 | 287 | function addeq_not_CHOOSE_ALL($name) { |
277 | 288 | if (isset($_GET[$name])) { |
278 | 289 | $value = $_GET[$name]; |
@@ -287,6 +298,10 @@ discard block |
||
287 | 298 | $this->urlquery .= "&$name=".urlencode($value); |
288 | 299 | } |
289 | 300 | } |
301 | + |
|
302 | + /** |
|
303 | + * @param string $name |
|
304 | + */ |
|
290 | 305 | function addgt($name) { |
291 | 306 | if (isset($_GET[$name])) { |
292 | 307 | $value = $_GET[$name]; |
@@ -298,6 +313,11 @@ discard block |
||
298 | 313 | $this->urlquery .= "&$name=".urlencode($value); |
299 | 314 | } |
300 | 315 | } |
316 | + |
|
317 | + /** |
|
318 | + * @param string $name |
|
319 | + * @param string $order |
|
320 | + */ |
|
301 | 321 | function addsort($name, $order) { |
302 | 322 | if (isset($_GET[$name])) { |
303 | 323 | $value = $_GET[$name]; |
@@ -375,6 +395,9 @@ discard block |
||
375 | 395 | } |
376 | 396 | |
377 | 397 | |
398 | +/** |
|
399 | + * @param string $mq |
|
400 | + */ |
|
378 | 401 | function link_results($n, $mq, $query, $clauses) { |
379 | 402 | if ($n == '0') { // intentional compare by string |
380 | 403 | return "0"; |
@@ -824,6 +847,9 @@ discard block |
||
824 | 847 | return number_format($x/86400, 2)." days"; |
825 | 848 | } |
826 | 849 | |
850 | +/** |
|
851 | + * @param integer $x |
|
852 | + */ |
|
827 | 853 | function resource_name($x) { |
828 | 854 | switch ($x) { |
829 | 855 | case 2: return "CPU"; |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | $value=null; |
306 | 306 | } |
307 | 307 | if (isset($_GET[$order])) { |
308 | - $order = $_GET[$order]; |
|
308 | + $order = $_GET[$order]; |
|
309 | 309 | } else { |
310 | - $order = null; |
|
310 | + $order = null; |
|
311 | 311 | } |
312 | 312 | if (strlen($value)) { |
313 | 313 | if ($order == 'asc') { |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | $res = new StdClass; |
576 | 576 | $res->server_state = $ss; |
577 | 577 | row2(result_server_state_string($res), |
578 | - link_results("$server_state[$ss]", $urlquery,"server_state=$ss", '') |
|
578 | + link_results("$server_state[$ss]", $urlquery,"server_state=$ss", '') |
|
579 | 579 | ); |
580 | 580 | } |
581 | 581 | echo "</table></td>"; |
@@ -1026,8 +1026,8 @@ discard block |
||
1026 | 1026 | |
1027 | 1027 | function validate_color($validate_state) { |
1028 | 1028 | switch ($validate_state) { |
1029 | - case 1: return '33cc33'; // valid, green |
|
1030 | - case 2: return 'ffa500'; // invalid result, orange |
|
1029 | + case 1: return '33cc33'; // valid, green |
|
1030 | + case 2: return 'ffa500'; // invalid result, orange |
|
1031 | 1031 | } |
1032 | 1032 | return ''; |
1033 | 1033 | } |
@@ -96,7 +96,9 @@ discard block |
||
96 | 96 | if (!isset($types)) { |
97 | 97 | $types = array(); |
98 | 98 | $constants = get_defined_constants(true); |
99 | - foreach ($constants['mysqli'] as $c => $n) if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) $types[$n] = $m[1]; |
|
99 | + foreach ($constants['mysqli'] as $c => $n) { |
|
100 | + if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) $types[$n] = $m[1]; |
|
101 | + } |
|
100 | 102 | } |
101 | 103 | return array_key_exists($type_id, $types)? strtolower($types[$type_id]) : "unknown"; |
102 | 104 | } |
@@ -376,13 +378,13 @@ discard block |
||
376 | 378 | |
377 | 379 | |
378 | 380 | function link_results($n, $mq, $query, $clauses) { |
379 | - if ($n == '0') { // intentional compare by string |
|
381 | + if ($n == '0') { |
|
382 | +// intentional compare by string |
|
380 | 383 | return "0"; |
381 | 384 | } else { |
382 | 385 | if(strlen($clauses)) { |
383 | 386 | return "<a href=\"db_action.php?table=result&query=$mq&$query&clauses=".urlencode($clauses)."&sort_by=mod_time&detail=low\">$n</a>"; |
384 | - } |
|
385 | - else { |
|
387 | + } else { |
|
386 | 388 | return "<a href=\"db_action.php?table=result&query=$mq&$query&sort_by=mod_time&detail=low\">$n</a>"; |
387 | 389 | } |
388 | 390 | |
@@ -392,7 +394,7 @@ discard block |
||
392 | 394 | // Determines if in stderr_out is an error reported and prints as human readable String |
393 | 395 | // @return String A human readable string if error otherwise FALSE |
394 | 396 | // @param String $stderr_out the stderr_out value to parse |
395 | -function stderr_error_string($stderr_out){ |
|
397 | +function stderr_error_string($stderr_out) { |
|
396 | 398 | $y = parse_element($stderr_out, "<error_code>"); |
397 | 399 | $x = 0; |
398 | 400 | if ($y) { |
@@ -1146,7 +1148,7 @@ discard block |
||
1146 | 1148 | // result has not been received yet, so show report deadline either |
1147 | 1149 | // in green if in the future or in red if in the past. |
1148 | 1150 | $timenow=time(); |
1149 | - if ($result->report_deadline==0) { |
|
1151 | + if ($result->report_deadline==0) { |
|
1150 | 1152 | // not sent -- show create time in purple |
1151 | 1153 | $received = "<font color=\"9900cc\">". time_str($result->create_time) . "</font>"; |
1152 | 1154 | } else if ($result->report_deadline>=$timenow) { |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | $x = (int)$y; |
400 | 400 | } |
401 | 401 | if (0<=$x && $x<=9) { |
402 | - return FALSE; |
|
402 | + return false; |
|
403 | 403 | } else { |
404 | 404 | return "$x ".error_code_str($x); |
405 | 405 | } |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | row("Domain name", $host->domain_name); |
892 | 892 | $x = $host->timezone/3600; |
893 | 893 | if ($x >= 0) $x="+$x"; |
894 | - row("Local Standard Time", "UTC $x hours"); |
|
894 | + row("Local Standard Time", "utc $x hours"); |
|
895 | 895 | row("Number of CPUs", $host->p_ncpus); |
896 | 896 | row("CPU", "$host->p_vendor $host->p_model"); |
897 | 897 | row("GFLOPS", number_format($host->p_fpops/1e9, 2)); |
@@ -40,27 +40,27 @@ discard block |
||
40 | 40 | // @return String A user readable DateTime-String in UTC |
41 | 41 | // @param Integer $x The mysql-Timestamp to convert |
42 | 42 | function mysqltime_str($x) { |
43 | - if(strpos($x,"-")==4) { |
|
43 | + if (strpos($x, "-") == 4) { |
|
44 | 44 | // Syntax of supplied mysql-timestamp is YYYY-MM-DD HH:MM:SS |
45 | - $year = substr($x,0,4); |
|
46 | - $month = substr($x,5,2); |
|
47 | - $day = substr($x,8,2); |
|
48 | - $hour = substr($x,11,2); |
|
49 | - $minute = substr($x,14,2); |
|
50 | - $second = substr($x,17,2); |
|
45 | + $year = substr($x, 0, 4); |
|
46 | + $month = substr($x, 5, 2); |
|
47 | + $day = substr($x, 8, 2); |
|
48 | + $hour = substr($x, 11, 2); |
|
49 | + $minute = substr($x, 14, 2); |
|
50 | + $second = substr($x, 17, 2); |
|
51 | 51 | } else { |
52 | 52 | // Syntax of supplied mysql-timestamp is YYYYMMDDHHMMSS |
53 | - $year = substr($x,0,4); |
|
54 | - $month = substr($x,4,2); |
|
55 | - $day = substr($x,6,2); |
|
56 | - $hour = substr($x,8,2); |
|
57 | - $minute = substr($x,10,2); |
|
58 | - $second = substr($x,12,2); |
|
53 | + $year = substr($x, 0, 4); |
|
54 | + $month = substr($x, 4, 2); |
|
55 | + $day = substr($x, 6, 2); |
|
56 | + $hour = substr($x, 8, 2); |
|
57 | + $minute = substr($x, 10, 2); |
|
58 | + $second = substr($x, 12, 2); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | //make a Unix-Timestamp |
62 | 62 | // echo "Time string is " . "$x"; |
63 | - $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
63 | + $time = mktime($hour, $minute, $second, $month, $day, $year); |
|
64 | 64 | return time_str($time); |
65 | 65 | } |
66 | 66 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $constants = get_defined_constants(true); |
99 | 99 | foreach ($constants['mysqli'] as $c => $n) if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) $types[$n] = $m[1]; |
100 | 100 | } |
101 | - return array_key_exists($type_id, $types)? strtolower($types[$type_id]) : "unknown"; |
|
101 | + return array_key_exists($type_id, $types) ? strtolower($types[$type_id]) : "unknown"; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Function prints a description of $table |
@@ -108,38 +108,38 @@ discard block |
||
108 | 108 | $result = $db->do_query("SELECT * from $table LIMIT 1"); |
109 | 109 | $fields = $result->field_count; |
110 | 110 | |
111 | - $avgnum=(int)($fields/$columns); |
|
112 | - if ($avgnum*$columns<$fields) { |
|
111 | + $avgnum = (int)($fields/$columns); |
|
112 | + if ($avgnum*$columns < $fields) { |
|
113 | 113 | $avgnum++; |
114 | 114 | } |
115 | 115 | |
116 | - $actualcolumns=0; |
|
117 | - while ($avgnum*$actualcolumns<$fields) { |
|
116 | + $actualcolumns = 0; |
|
117 | + while ($avgnum*$actualcolumns < $fields) { |
|
118 | 118 | $actualcolumns++; |
119 | 119 | } |
120 | 120 | |
121 | - if ($which>$actualcolumns) { |
|
121 | + if ($which > $actualcolumns) { |
|
122 | 122 | return 0; |
123 | 123 | } |
124 | 124 | |
125 | - $bot=($which-1)*$avgnum; |
|
126 | - $top=$which*$avgnum; |
|
125 | + $bot = ($which - 1)*$avgnum; |
|
126 | + $top = $which*$avgnum; |
|
127 | 127 | |
128 | - $width=100.0/$actualcolumns; |
|
128 | + $width = 100.0/$actualcolumns; |
|
129 | 129 | |
130 | 130 | // echo "<td><table border='2' width=\"$width%\">\n"; |
131 | 131 | echo "<td><table border=\"1\" width=\"100%\">\n"; |
132 | 132 | echo "<tr><th align=\"left\">NAME</th><th align=\"left\">Type</th><th align=\"left\">Bytes</th>\n"; |
133 | - for ($count=$bot; $count<$top; $count++) { |
|
134 | - if ($count<$fields) { |
|
133 | + for ($count = $bot; $count < $top; $count++) { |
|
134 | + if ($count < $fields) { |
|
135 | 135 | $x = $result->fetch_field_direct($count); |
136 | 136 | $name = $x->name; |
137 | 137 | $type = mysql_fieldtype_str($x->type); |
138 | 138 | $length = $x->length; |
139 | 139 | } else { |
140 | - $name="<br/> "; |
|
141 | - $type="<br/>"; |
|
142 | - $length="<br/>"; |
|
140 | + $name = "<br/> "; |
|
141 | + $type = "<br/>"; |
|
142 | + $length = "<br/>"; |
|
143 | 143 | } |
144 | 144 | echo "\t<tr><td><b>$name</b></td><td>$type</td><td>$length</td></tr>\n"; |
145 | 145 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | // Number of columns for showing table description |
153 | 153 | echo "<h2>Description of <b>$table</b> table fields:</h2>\n"; |
154 | 154 | echo "<table border=\"0\" width=\"100%\">\n\t<tr>"; |
155 | - for ($i=1; $i<=$how_many_columns; $i++) { |
|
155 | + for ($i = 1; $i <= $how_many_columns; $i++) { |
|
156 | 156 | print_describe_table_onecol($table, $i, $how_many_columns); |
157 | 157 | } |
158 | 158 | echo "\t</tr>\n</table>\n"; |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | function print_query_field() { |
173 | - $currenttime=time(); |
|
174 | - $hourago=$currenttime-3600; |
|
175 | - $dayago=$currenttime-24*3600; |
|
176 | - $weekago=$currenttime-7*24*3600; |
|
173 | + $currenttime = time(); |
|
174 | + $hourago = $currenttime - 3600; |
|
175 | + $dayago = $currenttime - 24*3600; |
|
176 | + $weekago = $currenttime - 7*24*3600; |
|
177 | 177 | echo " |
178 | 178 | <tr> |
179 | 179 | <td align=\"right\">Additional clauses</td> |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | -function append_sql_query($original,$addition,$first) { |
|
200 | +function append_sql_query($original, $addition, $first) { |
|
201 | 201 | if ($first == 1) { |
202 | - return $original . " where " . $addition; |
|
202 | + return $original." where ".$addition; |
|
203 | 203 | } else { |
204 | - return $original . " and " . $addition; |
|
204 | + return $original." and ".$addition; |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | if (isset($_GET[$name])) { |
303 | 303 | $value = $_GET[$name]; |
304 | 304 | } else { |
305 | - $value=null; |
|
305 | + $value = null; |
|
306 | 306 | } |
307 | 307 | if (isset($_GET[$order])) { |
308 | 308 | $order = $_GET[$order]; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | function get_url($base = "db_action.php") { |
346 | - $s = $base . "?table=$this->table$this->urlquery"; |
|
346 | + $s = $base."?table=$this->table$this->urlquery"; |
|
347 | 347 | return $s; |
348 | 348 | } |
349 | 349 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | $this->addeq('app_version_id'); |
359 | 359 | $this->addeq('exit_status'); |
360 | 360 | if (isset($_GET['nsecs'])) { |
361 | - $_GET['mod_time'] = date("YmdHis",time() - $_GET['nsecs']); |
|
361 | + $_GET['mod_time'] = date("YmdHis", time() - $_GET['nsecs']); |
|
362 | 362 | } |
363 | 363 | $this->addgt('mod_time'); |
364 | 364 | $this->addeq_not_CHOOSE_ALL('server_state'); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | if ($n == '0') { // intentional compare by string |
380 | 380 | return "0"; |
381 | 381 | } else { |
382 | - if(strlen($clauses)) { |
|
382 | + if (strlen($clauses)) { |
|
383 | 383 | return "<a href=\"db_action.php?table=result&query=$mq&$query&clauses=".urlencode($clauses)."&sort_by=mod_time&detail=low\">$n</a>"; |
384 | 384 | } |
385 | 385 | else { |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | // Determines if in stderr_out is an error reported and prints as human readable String |
393 | 393 | // @return String A human readable string if error otherwise FALSE |
394 | 394 | // @param String $stderr_out the stderr_out value to parse |
395 | -function stderr_error_string($stderr_out){ |
|
395 | +function stderr_error_string($stderr_out) { |
|
396 | 396 | $y = parse_element($stderr_out, "<error_code>"); |
397 | 397 | $x = 0; |
398 | 398 | if ($y) { |
399 | 399 | $x = (int)$y; |
400 | 400 | } |
401 | - if (0<=$x && $x<=9) { |
|
401 | + if (0 <= $x && $x <= 9) { |
|
402 | 402 | return FALSE; |
403 | 403 | } else { |
404 | 404 | return "$x ".error_code_str($x); |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | |
408 | 408 | function show_result_summary() { |
409 | 409 | |
410 | - $ntotal =0; // TODO: how to count $result? |
|
411 | - $nvalid = 0; // for SUCCESS results |
|
410 | + $ntotal = 0; // TODO: how to count $result? |
|
411 | + $nvalid = 0; // for SUCCESS results |
|
412 | 412 | $ninvalid = 0; |
413 | 413 | $nfile_deleted = 0; |
414 | 414 | |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | $outcome = array(); |
417 | 417 | $client_state = array(); |
418 | 418 | |
419 | - for ($ss=1; $ss<6; $ss++) { |
|
419 | + for ($ss = 1; $ss < 6; $ss++) { |
|
420 | 420 | $server_state[$ss] = 0; |
421 | 421 | } |
422 | - for ($ro=0; $ro<8; $ro++) { |
|
422 | + for ($ro = 0; $ro < 8; $ro++) { |
|
423 | 423 | $outcome[$ro] = 0; |
424 | 424 | } |
425 | - for ($cs=1; $cs<7; $cs++) { |
|
425 | + for ($cs = 1; $cs < 7; $cs++) { |
|
426 | 426 | $client_state[$cs] = 0; |
427 | 427 | } |
428 | - for ($fds=0; $fds<4; $fds++) { |
|
428 | + for ($fds = 0; $fds < 4; $fds++) { |
|
429 | 429 | $delete_state[$fds] = 0; |
430 | 430 | } |
431 | - for ($vs=0; $vs<NVALIDATE_STATES; $vs++) { |
|
432 | - $validate_state[$vs]=0; |
|
431 | + for ($vs = 0; $vs < NVALIDATE_STATES; $vs++) { |
|
432 | + $validate_state[$vs] = 0; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $_GET['table'] = 'result'; |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | // |
505 | 505 | $delay = parse_config(get_config(), "<delete_delay_hours>"); |
506 | 506 | if ($delay) { |
507 | - $start2 = $start - $delay*3600;; |
|
507 | + $start2 = $start - $delay*3600; ; |
|
508 | 508 | $main_query .= " and ((file_delete_state>1 and mod_time>FROM_UNIXTIME($start2)) or (mod_time>FROM_UNIXTIME($start)))"; |
509 | 509 | } else { |
510 | 510 | $main_query .= " and mod_time > FROM_UNIXTIME($start)"; |
@@ -563,19 +563,19 @@ discard block |
||
563 | 563 | |
564 | 564 | echo "<table>"; |
565 | 565 | echo "<tr valign=\"top\">"; |
566 | - echo "<td><h2>" . link_results("$ntotal results", $urlquery, '', '') . "</h2></td>"; |
|
567 | - echo "<td><h2>" . link_results("'Over' results", $urlquery, "server_state=5", '') . "</h2></td>"; |
|
568 | - echo "<td><h2>" . link_results("'Success' results", $urlquery, "outcome=1", '') . "</h2></td>"; |
|
569 | - echo "<td><h2>" . link_results("'Client error' results", $urlquery, "outcome=3", '') . "</h2></td>"; |
|
566 | + echo "<td><h2>".link_results("$ntotal results", $urlquery, '', '')."</h2></td>"; |
|
567 | + echo "<td><h2>".link_results("'Over' results", $urlquery, "server_state=5", '')."</h2></td>"; |
|
568 | + echo "<td><h2>".link_results("'Success' results", $urlquery, "outcome=1", '')."</h2></td>"; |
|
569 | + echo "<td><h2>".link_results("'Client error' results", $urlquery, "outcome=3", '')."</h2></td>"; |
|
570 | 570 | echo "</tr>"; |
571 | 571 | echo "<tr valign=\"top\">"; |
572 | 572 | echo "<td><table border=2 cellpadding=4>\n"; |
573 | 573 | echo "<tr><th>Server state</th><th># results</th></tr>\n"; |
574 | - for ($ss=1; $ss<6; $ss++) { |
|
574 | + for ($ss = 1; $ss < 6; $ss++) { |
|
575 | 575 | $res = new StdClass; |
576 | 576 | $res->server_state = $ss; |
577 | 577 | row2(result_server_state_string($res), |
578 | - link_results("$server_state[$ss]", $urlquery,"server_state=$ss", '') |
|
578 | + link_results("$server_state[$ss]", $urlquery, "server_state=$ss", '') |
|
579 | 579 | ); |
580 | 580 | } |
581 | 581 | echo "</table></td>"; |
@@ -583,11 +583,11 @@ discard block |
||
583 | 583 | echo "<td><table border=2 cellpadding=4>\n"; |
584 | 584 | echo "<tr><th>Outcome</th><th># results</th></tr>\n"; |
585 | 585 | |
586 | - for ($ro=0; $ro<8; $ro++) { |
|
586 | + for ($ro = 0; $ro < 8; $ro++) { |
|
587 | 587 | $res = new StdClass; |
588 | 588 | $res->outcome = $ro; |
589 | 589 | $res->exit_status = 0; |
590 | - c_row2($outcome[$ro]?outcome_color($ro):'', result_outcome_string($res), |
|
590 | + c_row2($outcome[$ro] ? outcome_color($ro) : '', result_outcome_string($res), |
|
591 | 591 | link_results("$outcome[$ro]", $urlquery, "outcome=$ro", '') |
592 | 592 | ); |
593 | 593 | } |
@@ -595,18 +595,18 @@ discard block |
||
595 | 595 | |
596 | 596 | echo "<td><table border=2 cellpadding=4>\n"; |
597 | 597 | echo "<tr><th>Validate state</th><th># results</th></tr>\n"; |
598 | - for ($vs=0; $vs<NVALIDATE_STATES; $vs++) { |
|
598 | + for ($vs = 0; $vs < NVALIDATE_STATES; $vs++) { |
|
599 | 599 | $res = new StdClass; |
600 | 600 | $res->validate_state = $vs; |
601 | 601 | $res->exit_status = 0; |
602 | - c_row2($validate_state[$vs]?validate_color($vs):'', validate_state_str($res), |
|
602 | + c_row2($validate_state[$vs] ? validate_color($vs) : '', validate_state_str($res), |
|
603 | 603 | link_results("$validate_state[$vs]", $urlquery, "validate_state=$vs", "outcome=1")); |
604 | 604 | } |
605 | 605 | echo "</table>"; |
606 | 606 | echo "<table border=2 cellpadding=4>\n"; |
607 | 607 | echo "<tr><th>File Delete state</th><th># results</th></tr>\n"; |
608 | 608 | |
609 | - for ($fds=0; $fds<4; $fds++) { |
|
609 | + for ($fds = 0; $fds < 4; $fds++) { |
|
610 | 610 | row2(file_delete_state_str($fds), |
611 | 611 | link_results("$file_delete[$fds]", $urlquery, "outcome=1", "file_delete_state=$fds")); |
612 | 612 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | |
617 | 617 | echo "<td><table border=2 cellpadding=4>\n"; |
618 | 618 | echo "<tr><th>Client state</th><th># results</th></tr>\n"; |
619 | - for ($cs=1; $cs<7; $cs++) { |
|
619 | + for ($cs = 1; $cs < 7; $cs++) { |
|
620 | 620 | $res = new StdClass; |
621 | 621 | $res->client_state = $cs; |
622 | 622 | $res->exit_status = 0; |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | <select name=\"server_state\"> |
635 | 635 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
636 | 636 | "; |
637 | - for ($i=1; $i<6; $i++) { |
|
637 | + for ($i = 1; $i < 6; $i++) { |
|
638 | 638 | $res = new StdClass; |
639 | - $res->server_state=$i; |
|
639 | + $res->server_state = $i; |
|
640 | 640 | echo "<option value=\"$i\"> "."[$i] ".' '.result_server_state_string($res)."</option>\n"; |
641 | 641 | } |
642 | 642 | echo "</select>\n"; |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | <select name=\"outcome\"> |
648 | 648 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
649 | 649 | "; |
650 | - for ($i=0; $i<8; $i++) { |
|
650 | + for ($i = 0; $i < 8; $i++) { |
|
651 | 651 | $res = new StdClass; |
652 | 652 | $res->outcome = $i; |
653 | 653 | $res->exit_status = 0; |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | <select name=\"validate_state\"> |
662 | 662 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
663 | 663 | "; |
664 | - for ($vs=0; $vs<NVALIDATE_STATES; $vs++) { |
|
664 | + for ($vs = 0; $vs < NVALIDATE_STATES; $vs++) { |
|
665 | 665 | $res = new StdClass; |
666 | 666 | $res->validate_state = $vs; |
667 | 667 | $res->exit_status = 0; |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | <select name=\"client_state\"> |
676 | 676 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
677 | 677 | "; |
678 | - for ($i=0; $i<7; $i++) { |
|
678 | + for ($i = 0; $i < 7; $i++) { |
|
679 | 679 | $res = new StdClass; |
680 | 680 | $res->client_state = $i; |
681 | 681 | $res->exit_status = 0; |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | } |
713 | 713 | |
714 | 714 | function table_title($table) { |
715 | - switch($table) { |
|
715 | + switch ($table) { |
|
716 | 716 | case "platform": return "Platforms"; |
717 | 717 | case "app": return "Applications"; |
718 | 718 | case "app_version": return "Application Versions"; |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | row("Created", time_str($platform->create_time)); |
733 | 733 | row("Name", $platform->name); |
734 | 734 | row("User friendly name", $platform->user_friendly_name); |
735 | - row("","<a href=\"db_action.php?table=app_version&platformid=$platform->id\">App versions for this platform</a>"); |
|
735 | + row("", "<a href=\"db_action.php?table=app_version&platformid=$platform->id\">App versions for this platform</a>"); |
|
736 | 736 | end_table(); |
737 | 737 | } |
738 | 738 | |
@@ -744,8 +744,8 @@ discard block |
||
744 | 744 | row("User-friendly name", $app->user_friendly_name); |
745 | 745 | row("Deprecated", $app->deprecated); |
746 | 746 | row("Homogeneous redundancy", $app->homogeneous_redundancy); |
747 | - row("","<a href=\"db_action.php?table=app_version&appid=$app->id\">App Versions for this application</a>"); |
|
748 | - row("","<a href=\"db_action.php?table=workunit&appid=$app->id&detail=low\">Workunits for this application</a>"); |
|
747 | + row("", "<a href=\"db_action.php?table=app_version&appid=$app->id\">App Versions for this application</a>"); |
|
748 | + row("", "<a href=\"db_action.php?table=workunit&appid=$app->id&detail=low\">Workunits for this application</a>"); |
|
749 | 749 | end_table(); |
750 | 750 | } |
751 | 751 | |
@@ -753,9 +753,9 @@ discard block |
||
753 | 753 | start_table(); |
754 | 754 | row("ID", $app_version->id); |
755 | 755 | row("Created", time_str($app_version->create_time)); |
756 | - row("Application", "<a href=\"db_action.php?table=app&id=$app_version->appid\">" . app_name_by_id($app_version->appid) . "</a>"); |
|
756 | + row("Application", "<a href=\"db_action.php?table=app&id=$app_version->appid\">".app_name_by_id($app_version->appid)."</a>"); |
|
757 | 757 | row("Version num", $app_version->version_num); |
758 | - row("Platform", "<a href=\"db_action.php?table=platform&id=$app_version->platformid\">" . platform_name_by_id($app_version->platformid) . "</a>" ); |
|
758 | + row("Platform", "<a href=\"db_action.php?table=platform&id=$app_version->platformid\">".platform_name_by_id($app_version->platformid)."</a>"); |
|
759 | 759 | row("Plan Class", $app_version->plan_class); |
760 | 760 | row("XML doc", "<pre>".htmlspecialchars($app_version->xml_doc)."</pre>"); |
761 | 761 | row("min_core_version", $app_version->min_core_version); |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | row("External IP address", "$host->external_ip_addr<br>"); |
891 | 891 | row("Domain name", $host->domain_name); |
892 | 892 | $x = $host->timezone/3600; |
893 | - if ($x >= 0) $x="+$x"; |
|
893 | + if ($x >= 0) $x = "+$x"; |
|
894 | 894 | row("Local Standard Time", "UTC $x hours"); |
895 | 895 | row("Number of CPUs", $host->p_ncpus); |
896 | 896 | row("CPU", "$host->p_vendor $host->p_model"); |
@@ -938,10 +938,10 @@ discard block |
||
938 | 938 | start_table(); |
939 | 939 | row("Created", time_str($wu->create_time)); |
940 | 940 | row("Transition Time", time_str($wu->transition_time)); |
941 | - row("Last time modified",mysqltime_str($wu->mod_time)); |
|
941 | + row("Last time modified", mysqltime_str($wu->mod_time)); |
|
942 | 942 | row("Name", $wu->name); |
943 | 943 | row("XML doc", "<pre>".htmlspecialchars($wu->xml_doc)."</pre>"); |
944 | - row("Application", "<a href=\"db_action.php?table=app&id=$wu->appid\">" . app_name_by_id($wu->appid) . " [".$wu->appid."]</a>"); |
|
944 | + row("Application", "<a href=\"db_action.php?table=app&id=$wu->appid\">".app_name_by_id($wu->appid)." [".$wu->appid."]</a>"); |
|
945 | 945 | row("Batch", $wu->batch); |
946 | 946 | $x = number_format($wu->rsc_fpops_est/1e9, 2); |
947 | 947 | row("Estimated FP Operations", "$x GFLOPS"); |
@@ -953,12 +953,12 @@ discard block |
||
953 | 953 | $x = $wu->rsc_disk_bound/(1024*1024); |
954 | 954 | $y = number_format($x, 2); |
955 | 955 | row("Max Disk Usage", "$y MB"); |
956 | - row("Need validate?", ($wu->need_validate?"yes [":"no [").$wu->need_validate."]"); |
|
956 | + row("Need validate?", ($wu->need_validate ? "yes [" : "no [").$wu->need_validate."]"); |
|
957 | 957 | row("Canonical resultid", |
958 | 958 | "<a href=\"db_action.php?table=result&id=$wu->canonical_resultid\">".$wu->canonical_resultid."</a>"); |
959 | 959 | row("Canonical credit", $wu->canonical_credit); |
960 | 960 | //row("Timeout check time", time_str($wu->timeout_check_time)); |
961 | - row("Delay bound", "$wu->delay_bound" . " = " . time_diff($wu->delay_bound) ); |
|
961 | + row("Delay bound", "$wu->delay_bound"." = ".time_diff($wu->delay_bound)); |
|
962 | 962 | row("Error mask", wu_error_mask_str($wu->error_mask)); |
963 | 963 | row("File delete state", file_delete_state_str($wu->file_delete_state)." [".$wu->file_delete_state."]"); |
964 | 964 | row("Assimilation state", assimilate_state_str($wu->assimilate_state)." [".$wu->assimilate_state."]"); |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | row("max error results", $wu->max_error_results); |
969 | 969 | row("max total results", $wu->max_total_results); |
970 | 970 | row("max success results", $wu->max_success_results); |
971 | - row("result template file",$wu->result_template_file); |
|
971 | + row("result template file", $wu->result_template_file); |
|
972 | 972 | row("hr_class", $wu->hr_class); |
973 | 973 | row("opaque", $wu->opaque); |
974 | 974 | row("Priority", $wu->priority); |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $cr = "none"; |
999 | 999 | } |
1000 | 1000 | $wu_link = "<a href=\"db_action.php?table=workunit&id=".$wu->id."&detail=high\">".$wu->id."</a>"; |
1001 | - $cr = $cr. " <a href=\"db_action.php?table=result&workunitid=$wu->id&detail=low\">all</a>"; |
|
1001 | + $cr = $cr." <a href=\"db_action.php?table=result&workunitid=$wu->id&detail=low\">all</a>"; |
|
1002 | 1002 | $e = wu_error_mask_str($wu->error_mask); |
1003 | 1003 | $f = file_delete_state_str($wu->file_delete_state); |
1004 | 1004 | $a = assimilate_state_str($wu->assimilate_state); |
@@ -1033,7 +1033,7 @@ discard block |
||
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | function outcome_color($outcome) { |
1036 | - switch($outcome) { |
|
1036 | + switch ($outcome) { |
|
1037 | 1037 | case 0: return '9900cc'; // "Init", purple |
1038 | 1038 | case 1: return '33cc33'; // "Success", green |
1039 | 1039 | case 3: return 'ff3333'; // "Client error", red |
@@ -1060,18 +1060,18 @@ discard block |
||
1060 | 1060 | row("Sent", time_str($result->sent_time)); |
1061 | 1061 | row("Report deadline", time_str($result->report_deadline)); |
1062 | 1062 | row("Received", time_str($result->received_time)); |
1063 | - row("Last time modified",mysqltime_str($result->mod_time)); |
|
1063 | + row("Last time modified", mysqltime_str($result->mod_time)); |
|
1064 | 1064 | row("Name", $result->name); |
1065 | - row("Workunit", "<a href=\"db_action.php?table=workunit&id=$result->workunitid\">" . wu_name_by_id($result->workunitid) . "</a> [$result->workunitid]" ); |
|
1065 | + row("Workunit", "<a href=\"db_action.php?table=workunit&id=$result->workunitid\">".wu_name_by_id($result->workunitid)."</a> [$result->workunitid]"); |
|
1066 | 1066 | row("Server state", result_server_state_string($result)." [$result->server_state]"); |
1067 | 1067 | row("Outcome", result_outcome_string($result)." [$result->outcome]"); |
1068 | 1068 | row("Client state", result_client_state_string($result)." [$result->client_state]"); |
1069 | 1069 | row("Exit status", exit_status_string($result->exit_status)); |
1070 | - row("Host ID", "<a href=\"db_action.php?table=host&id=$result->hostid\">" . host_name_by_id($result->hostid) . "</a> [$result->hostid]"); |
|
1071 | - row("User ID", "<a href=\"db_action.php?table=user&id=$result->userid\">" . user_name_by_id($result->userid) . "</a> [$result->userid]"); |
|
1070 | + row("Host ID", "<a href=\"db_action.php?table=host&id=$result->hostid\">".host_name_by_id($result->hostid)."</a> [$result->hostid]"); |
|
1071 | + row("User ID", "<a href=\"db_action.php?table=user&id=$result->userid\">".user_name_by_id($result->userid)."</a> [$result->userid]"); |
|
1072 | 1072 | row("CPU time", $result->cpu_time); |
1073 | 1073 | row("Elapsed time", $result->elapsed_time); |
1074 | - if($error=stderr_error_string($result->stderr_out)) { |
|
1074 | + if ($error = stderr_error_string($result->stderr_out)) { |
|
1075 | 1075 | row("error in stderr out", $error); |
1076 | 1076 | } |
1077 | 1077 | row("Batch", $result->batch); |
@@ -1088,16 +1088,16 @@ discard block |
||
1088 | 1088 | row("App version", $x1.app_version_string($result).$x2); |
1089 | 1089 | row("App version ID", $result->app_version_id); |
1090 | 1090 | row("Estimated GFLOPS", number_format($result->flops_estimate/1e9, 2)); |
1091 | - row("Random",$result->random); |
|
1092 | - row("Opaque",$result->opaque); |
|
1093 | - row("Teamid",$result->teamid); |
|
1094 | - row("Priority",$result->priority); |
|
1091 | + row("Random", $result->random); |
|
1092 | + row("Opaque", $result->opaque); |
|
1093 | + row("Teamid", $result->teamid); |
|
1094 | + row("Priority", $result->priority); |
|
1095 | 1095 | row("XML doc in", "<pre>".htmlspecialchars($result->xml_doc_in)."</pre>"); |
1096 | 1096 | row("XML doc out", "<pre>".htmlspecialchars($result->xml_doc_out)."</pre>"); |
1097 | 1097 | row("stderr out", "<pre>" |
1098 | 1098 | .htmlspecialchars( |
1099 | 1099 | $result->stderr_out, |
1100 | - ENT_QUOTES | (defined('ENT_SUBSTITUTE')?ENT_SUBSTITUTE:0), |
|
1100 | + ENT_QUOTES|(defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), |
|
1101 | 1101 | 'utf-8' |
1102 | 1102 | ) |
1103 | 1103 | ."</pre>" |
@@ -1145,23 +1145,23 @@ discard block |
||
1145 | 1145 | } else { |
1146 | 1146 | // result has not been received yet, so show report deadline either |
1147 | 1147 | // in green if in the future or in red if in the past. |
1148 | - $timenow=time(); |
|
1149 | - if ($result->report_deadline==0) { |
|
1148 | + $timenow = time(); |
|
1149 | + if ($result->report_deadline == 0) { |
|
1150 | 1150 | // not sent -- show create time in purple |
1151 | - $received = "<font color=\"9900cc\">". time_str($result->create_time) . "</font>"; |
|
1152 | - } else if ($result->report_deadline>=$timenow) { |
|
1151 | + $received = "<font color=\"9900cc\">".time_str($result->create_time)."</font>"; |
|
1152 | + } else if ($result->report_deadline >= $timenow) { |
|
1153 | 1153 | // overdue -- show deadline in red |
1154 | - $received = "<font color=\"#33cc33\">". time_str($result->report_deadline) . "</font>"; |
|
1154 | + $received = "<font color=\"#33cc33\">".time_str($result->report_deadline)."</font>"; |
|
1155 | 1155 | } else { |
1156 | 1156 | // in progress and not overdue -- show deadline in green |
1157 | - $received = "<font color=\"#ff3333\">". time_str($result->report_deadline) . "</font>"; |
|
1157 | + $received = "<font color=\"#ff3333\">".time_str($result->report_deadline)."</font>"; |
|
1158 | 1158 | } |
1159 | 1159 | } |
1160 | 1160 | $version = app_version_string($result)." (<a href=\"db_action.php?table=app_version&id=$result->app_version_id\">$result->app_version_id</a>)"; |
1161 | 1161 | $outcome_color = outcome_color($result->outcome); |
1162 | 1162 | $validate_color = validate_color($result->validate_state); |
1163 | 1163 | $host_user = host_user_link($result->hostid); |
1164 | - $cpu_hours = sprintf("%.1f",$result->cpu_time / 3600); |
|
1164 | + $cpu_hours = sprintf("%.1f", $result->cpu_time/3600); |
|
1165 | 1165 | $granted_credit = "<a href=credit.php?wu_id=$result->workunitid>".credit_str($result->granted_credit)."</a>"; |
1166 | 1166 | $delete_state = file_delete_state_str($result->file_delete_state); |
1167 | 1167 | |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | row("ID", $user->id); |
1190 | 1190 | row("Created", time_str($user->create_time)); |
1191 | 1191 | row("Name", $user->name); |
1192 | - if(!in_rops()) { |
|
1192 | + if (!in_rops()) { |
|
1193 | 1193 | row("Authenticator", $user->authenticator); |
1194 | 1194 | } |
1195 | 1195 | row("Email address", $user->email_addr); |
@@ -1202,7 +1202,7 @@ discard block |
||
1202 | 1202 | row("Default venue", $user->venue); |
1203 | 1203 | row("Hosts", "<a href=\"db_action.php?table=host&userid=$user->id&detail=low\">click</a>"); |
1204 | 1204 | row("Cross project ID", $user->cross_project_id); |
1205 | - if(!in_rops()) { |
|
1205 | + if (!in_rops()) { |
|
1206 | 1206 | row("Password Hash", $user->passwd_hash); |
1207 | 1207 | } |
1208 | 1208 | row("Donated", $user->donated); |
@@ -1253,7 +1253,7 @@ discard block |
||
1253 | 1253 | echo "</table></td>"; |
1254 | 1254 | echo "<td><table border=\"2\">\n"; |
1255 | 1255 | echo "<tr><th>User</th><th># posts</th></tr>\n"; |
1256 | - for ($p=1; $p<=10; $p++) { |
|
1256 | + for ($p = 1; $p <= 10; $p++) { |
|
1257 | 1257 | row2_plain(user_links_ops($top10poster[$p]), $top10poster[$p]->posts); |
1258 | 1258 | } |
1259 | 1259 | echo "</table></td>"; |
@@ -1292,10 +1292,10 @@ discard block |
||
1292 | 1292 | function show_team($team) { |
1293 | 1293 | start_table(); |
1294 | 1294 | row("ID", $team->id); |
1295 | - row("Team Founder", "<a href=\"db_action.php?table=user&id=$team->userid\">" . user_name_by_id($team->userid) . "</a>"); |
|
1295 | + row("Team Founder", "<a href=\"db_action.php?table=user&id=$team->userid\">".user_name_by_id($team->userid)."</a>"); |
|
1296 | 1296 | row("Name", $team->name); |
1297 | - row("Name (HTML Formatted)", "<pre>" . htmlspecialchars($team->name_html) . "</pre>" ); |
|
1298 | - row("Url", "<a href=\"http://$team->url\">" . $team->url . "</a>"); |
|
1297 | + row("Name (HTML Formatted)", "<pre>".htmlspecialchars($team->name_html)."</pre>"); |
|
1298 | + row("Url", "<a href=\"http://$team->url\">".$team->url."</a>"); |
|
1299 | 1299 | row("Type", team_type_string($team->type)); |
1300 | 1300 | row("Description", $team->description); |
1301 | 1301 | row("", "<a href=\"db_action.php?table=user&teamid=$team->id\">List All Members</a>"); |
@@ -1338,7 +1338,7 @@ discard block |
||
1338 | 1338 | if (!strlen($host->domain_name) && !strlen($host->last_ip_addr)) { |
1339 | 1339 | return "(blank)"; |
1340 | 1340 | } else { |
1341 | - return $host->domain_name . " (" . $host->last_ip_addr . ")"; |
|
1341 | + return $host->domain_name." (".$host->last_ip_addr.")"; |
|
1342 | 1342 | } |
1343 | 1343 | } |
1344 | 1344 |
@@ -36,6 +36,9 @@ |
||
36 | 36 | return "$dirpath/$filename"; |
37 | 37 | } |
38 | 38 | |
39 | +/** |
|
40 | + * @param string $base |
|
41 | + */ |
|
39 | 42 | function dir_hier_url($filename, $base, $fanout) { |
40 | 43 | $dir = filename_hash($filename, $fanout); |
41 | 44 | return "$base/$dir/$filename"; |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | $dl_md5_path = "$dl_path.md5"; |
57 | 57 | $have_md5_file = false; |
58 | 58 | $md5 = md5_file($path); |
59 | - if ($md5 === FALSE) { |
|
59 | + if ($md5 === false) { |
|
60 | 60 | return -2; |
61 | 61 | } |
62 | 62 | $size = filesize($path); |
63 | - if ($size === FALSE) { |
|
63 | + if ($size === false) { |
|
64 | 64 | return -2; |
65 | 65 | } |
66 | 66 | |
67 | 67 | if (file_exists($dl_md5_path)) { |
68 | 68 | $x = file_get_contents($dl_md5_path); |
69 | - if ($x === FALSE) { |
|
69 | + if ($x === false) { |
|
70 | 70 | return -2; |
71 | 71 | } |
72 | 72 | $x = explode(" ", $x); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | if (file_exists($dl_path)) { |
79 | 79 | if ($have_md5_file) { |
80 | 80 | $s = filesize($dl_path); |
81 | - if ($s === FALSE) { |
|
81 | + if ($s === false) { |
|
82 | 82 | return -2; |
83 | 83 | } |
84 | 84 | if ($s == $dl_size && $dl_md5 == $md5) { |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | // missing the .md5 file; need to look at the file |
92 | 92 | // |
93 | 93 | $m = md5_file($dl_path); |
94 | - if ($m === FALSE) { |
|
94 | + if ($m === false) { |
|
95 | 95 | return -2; |
96 | 96 | } |
97 | 97 | if ($m == $md5) { |
98 | - if (file_put_contents($dl_md5_path, "$md5 $size\n") === FALSE) { |
|
98 | + if (file_put_contents($dl_md5_path, "$md5 $size\n") === false) { |
|
99 | 99 | return -2; |
100 | 100 | } |
101 | 101 | return 0; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | return -1; |
104 | 104 | } |
105 | 105 | } else { |
106 | - if (file_put_contents($dl_md5_path, "$md5 $size\n") === FALSE) { |
|
106 | + if (file_put_contents($dl_md5_path, "$md5 $size\n") === false) { |
|
107 | 107 | return -2; |
108 | 108 | } |
109 | 109 | return 1; |
@@ -115,6 +115,10 @@ discard block |
||
115 | 115 | $db = BoincDb::get(); |
116 | 116 | return $db->enum('post', 'BoincPost', $clause); |
117 | 117 | } |
118 | + |
|
119 | + /** |
|
120 | + * @param string $query |
|
121 | + */ |
|
118 | 122 | static function enum_general($query) { |
119 | 123 | $db = BoincDb::get(); |
120 | 124 | return $db->enum_general('BoincPost', $query); |
@@ -175,6 +179,10 @@ discard block |
||
175 | 179 | $db = BoincDb::get(); |
176 | 180 | return $db->delete_aux('forum_preferences', "userid=$this->userid"); |
177 | 181 | } |
182 | + |
|
183 | + /** |
|
184 | + * @param string $clause |
|
185 | + */ |
|
178 | 186 | static function enum($clause=null) { |
179 | 187 | $db = BoincDb::get(); |
180 | 188 | return $db->enum('forum_preferences', 'BoincForumPrefs', $clause); |
@@ -290,6 +298,10 @@ discard block |
||
290 | 298 | } |
291 | 299 | |
292 | 300 | class BoincNotify { |
301 | + |
|
302 | + /** |
|
303 | + * @param string $clause |
|
304 | + */ |
|
293 | 305 | static function insert($clause) { |
294 | 306 | $db = BoincDb::get(); |
295 | 307 | $ret = $db->insert('notify', $clause); |
@@ -304,6 +316,10 @@ discard block |
||
304 | 316 | $db = BoincDb::get(); |
305 | 317 | return $db->enum('notify', 'BoincNotify', $clause); |
306 | 318 | } |
319 | + |
|
320 | + /** |
|
321 | + * @param integer $type |
|
322 | + */ |
|
307 | 323 | static function lookup($userid, $type, $opaque) { |
308 | 324 | $db = BoincDb::get(); |
309 | 325 | return $db->lookup('notify', 'BoincNotify', "userid=$userid and type=$type and opaque=$opaque"); |
@@ -316,6 +332,10 @@ discard block |
||
316 | 332 | $db = BoincDb::get(); |
317 | 333 | $db->delete_aux('notify', $clause); |
318 | 334 | } |
335 | + |
|
336 | + /** |
|
337 | + * @param string $query |
|
338 | + */ |
|
319 | 339 | static function enum_general($query) { |
320 | 340 | $db = BoincDb::get(); |
321 | 341 | return $db->enum_general('BoincNotify', $query); |
@@ -164,7 +164,7 @@ |
||
164 | 164 | $user->prefs = $prefs; |
165 | 165 | } |
166 | 166 | function privilege($specialbit) { |
167 | - return (substr($this->special_user, $specialbit,1)==1); |
|
167 | + return (substr($this->special_user, $specialbit,1)==1); |
|
168 | 168 | } |
169 | 169 | function update($clause) { |
170 | 170 | $db = BoincDb::get(); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $db = BoincDb::get(); |
28 | 28 | return $db->lookup('category', 'BoincCategory', $clause); |
29 | 29 | } |
30 | - static function enum($clause=null) { |
|
30 | + static function enum($clause = null) { |
|
31 | 31 | $db = BoincDb::get(); |
32 | 32 | return $db->enum('category', 'BoincCategory', $clause); |
33 | 33 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $db = BoincDb::get(); |
79 | 79 | return $db->update($this, 'thread', $clause); |
80 | 80 | } |
81 | - static function enum($clause="") { |
|
81 | + static function enum($clause = "") { |
|
82 | 82 | $db = BoincDb::get(); |
83 | 83 | return $db->enum('thread', 'BoincThread', $clause); |
84 | 84 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $db = BoincDb::get(); |
143 | 143 | $ret = $db->insert('forum_preferences', $clause); |
144 | 144 | } |
145 | - static function lookup(&$user, $nocache=false) { |
|
145 | + static function lookup(&$user, $nocache = false) { |
|
146 | 146 | if (!$user) return; |
147 | 147 | if (isset($user->prefs)) return; |
148 | 148 | if (!$nocache && isset(self::$cache[$user->id])) { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $user->prefs = $prefs; |
165 | 165 | } |
166 | 166 | function privilege($specialbit) { |
167 | - return (substr($this->special_user, $specialbit,1)==1); |
|
167 | + return (substr($this->special_user, $specialbit, 1) == 1); |
|
168 | 168 | } |
169 | 169 | function update($clause) { |
170 | 170 | $db = BoincDb::get(); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $db = BoincDb::get(); |
176 | 176 | return $db->delete_aux('forum_preferences', "userid=$this->userid"); |
177 | 177 | } |
178 | - static function enum($clause=null) { |
|
178 | + static function enum($clause = null) { |
|
179 | 179 | $db = BoincDb::get(); |
180 | 180 | return $db->enum('forum_preferences', 'BoincForumPrefs', $clause); |
181 | 181 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | // |
216 | 216 | $fl = BoincForumLogging::lookup(0, 0); |
217 | 217 | if ($fl) { |
218 | - if ($fl->timestamp<time()-MAX_FORUM_LOGGING_TIME){ |
|
219 | - BoincForumLogging::delete_aux("timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0"); |
|
218 | + if ($fl->timestamp < time() - MAX_FORUM_LOGGING_TIME) { |
|
219 | + BoincForumLogging::delete_aux("timestamp<'".(time() - MAX_FORUM_LOGGING_TIME)."' and userid != 0"); |
|
220 | 220 | BoincForumLogging::replace(0, 0, time()); |
221 | 221 | } |
222 | 222 | } else { |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | -define ('NOTIFY_FRIEND_REQ', 1); |
|
326 | -define ('NOTIFY_FRIEND_ACCEPT', 2); |
|
327 | -define ('NOTIFY_PM', 3); |
|
328 | -define ('NOTIFY_SUBSCRIBED_POST', 4); |
|
325 | +define('NOTIFY_FRIEND_REQ', 1); |
|
326 | +define('NOTIFY_FRIEND_ACCEPT', 2); |
|
327 | +define('NOTIFY_PM', 3); |
|
328 | +define('NOTIFY_SUBSCRIBED_POST', 4); |
|
329 | 329 | |
330 | 330 | ?> |
@@ -215,7 +215,7 @@ |
||
215 | 215 | // |
216 | 216 | $fl = BoincForumLogging::lookup(0, 0); |
217 | 217 | if ($fl) { |
218 | - if ($fl->timestamp<time()-MAX_FORUM_LOGGING_TIME){ |
|
218 | + if ($fl->timestamp<time()-MAX_FORUM_LOGGING_TIME) { |
|
219 | 219 | BoincForumLogging::delete_aux("timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0"); |
220 | 220 | BoincForumLogging::replace(0, 0, time()); |
221 | 221 | } |
@@ -196,6 +196,10 @@ |
||
196 | 196 | |
197 | 197 | //////////////////// a banishment vote has been started /////////// |
198 | 198 | // |
199 | +/** |
|
200 | + * @param integer $duration |
|
201 | + * @param integer $end_time |
|
202 | + */ |
|
199 | 203 | function send_banish_vote_email($user, $duration, $reason, $end_time) { |
200 | 204 | global $master_url; |
201 | 205 | $now=time(); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $link = secure_url_base() . "forum_thread.php?id=" . $thread->id; |
129 | 129 | $body = "Another " . PROJECT . " user has posted to the thread |
130 | 130 | \"" . $thread->title . "\".\n" |
131 | - ."To view the updated thread, visit:\n$link |
|
131 | + ."To view the updated thread, visit:\n$link |
|
132 | 132 | |
133 | 133 | -------------------------- |
134 | 134 | To change email preferences, visit: |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | //////////////////// a user clicks the red "x" to report a post /////////// |
142 | 142 | // |
143 | 143 | function send_report_post_email($user, $forum, $thread, $post, $message) { |
144 | - global $master_url; |
|
144 | + global $master_url; |
|
145 | 145 | |
146 | 146 | $body = ""; |
147 | 147 | $owner = BoincUser::lookup_id($post->user); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | //////////////////// a banishment vote has been started /////////// |
198 | 198 | // |
199 | 199 | function send_banish_vote_email($user, $duration, $reason, $end_time) { |
200 | - global $master_url; |
|
200 | + global $master_url; |
|
201 | 201 | $now=time(); |
202 | 202 | $subject = PROJECT." banishment vote underway"; |
203 | 203 | $vote_url = $master_url."forum_banishment_vote.php"; |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | pm_send_msg($user, $user, $subject, $body, false); |
220 | 220 | |
221 | 221 | $body .= "\n\n<a href=".$vote_url."?action=yes&userid=" |
222 | - .$user->id |
|
223 | - .">[vote to banish author]</a>\n\n" |
|
224 | - ."<a href=".$vote_url."?action=no&userid=" |
|
225 | - .$user->id |
|
226 | - .">[vote not to banish author]</a>"; |
|
222 | + .$user->id |
|
223 | + .">[vote to banish author]</a>\n\n" |
|
224 | + ."<a href=".$vote_url."?action=no&userid=" |
|
225 | + .$user->id |
|
226 | + .">[vote not to banish author]</a>"; |
|
227 | 227 | |
228 | 228 | $forum = new BoincForum; |
229 | 229 | $forum->parent_type = 0; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | // - project forums: everyone in POST_REPORT_EMAILS |
25 | 25 | // - team message board: team founder and admins |
26 | 26 | // |
27 | -function mail_report_list($forum, $subject, $body, $must_send=false) { |
|
27 | +function mail_report_list($forum, $subject, $body, $must_send = false) { |
|
28 | 28 | $success = true; |
29 | 29 | switch ($forum->parent_type) { |
30 | 30 | case 0: |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | function send_moderation_email($forum, $post, $thread, $explanation, $action) { |
63 | 63 | global $master_url; |
64 | 64 | |
65 | - $moderator=get_logged_in_user(); |
|
65 | + $moderator = get_logged_in_user(); |
|
66 | 66 | $body = ""; |
67 | 67 | $user = BoincUser::lookup_id($post->user); |
68 | 68 | |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | // If a user is subscribed to a thread that is replied to, |
124 | 124 | // send them an email notifying them of the reply. |
125 | 125 | // |
126 | -function send_reply_notification_email($thread, $user){ |
|
127 | - $title = PROJECT . ": A user has posted to '". $thread->title ."'"; |
|
128 | - $link = secure_url_base() . "forum_thread.php?id=" . $thread->id; |
|
129 | - $body = "Another " . PROJECT . " user has posted to the thread |
|
130 | -\"" . $thread->title . "\".\n" |
|
126 | +function send_reply_notification_email($thread, $user) { |
|
127 | + $title = PROJECT.": A user has posted to '".$thread->title."'"; |
|
128 | + $link = secure_url_base()."forum_thread.php?id=".$thread->id; |
|
129 | + $body = "Another ".PROJECT." user has posted to the thread |
|
130 | +\"" . $thread->title."\".\n" |
|
131 | 131 | ."To view the updated thread, visit:\n$link |
132 | 132 | |
133 | 133 | -------------------------- |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | //////////////////// a user clicks the red "x" to report a post /////////// |
142 | 142 | // |
143 | -function send_report_post_email($user, $forum, $thread, $post, $message) { |
|
143 | +function send_report_post_email($user, $forum, $thread, $post, $message) { |
|
144 | 144 | global $master_url; |
145 | 145 | |
146 | 146 | $body = ""; |
@@ -198,16 +198,16 @@ discard block |
||
198 | 198 | // |
199 | 199 | function send_banish_vote_email($user, $duration, $reason, $end_time) { |
200 | 200 | global $master_url; |
201 | - $now=time(); |
|
201 | + $now = time(); |
|
202 | 202 | $subject = PROJECT." banishment vote underway"; |
203 | 203 | $vote_url = $master_url."forum_banishment_vote.php"; |
204 | 204 | $body = " |
205 | 205 | A vote has been started to banish you |
206 | 206 | from the ".PROJECT." message boards until ".date('M j, |
207 | -Y G:i', $duration+$now).", |
|
207 | +Y G:i', $duration + $now).", |
|
208 | 208 | because your postings have not followed our guidelines. |
209 | 209 | |
210 | -This vote will last until ".date('M j, Y G:i',$end_time)." or until a majority |
|
210 | +This vote will last until ".date('M j, Y G:i', $end_time)." or until a majority |
|
211 | 211 | decision has been reached. If the vote does not result in banishment, you will be |
212 | 212 | able to resume posting at that time. |
213 | 213 | "; |
@@ -123,7 +123,7 @@ |
||
123 | 123 | // If a user is subscribed to a thread that is replied to, |
124 | 124 | // send them an email notifying them of the reply. |
125 | 125 | // |
126 | -function send_reply_notification_email($thread, $user){ |
|
126 | +function send_reply_notification_email($thread, $user) { |
|
127 | 127 | $title = PROJECT . ": A user has posted to '". $thread->title ."'"; |
128 | 128 | $link = secure_url_base() . "forum_thread.php?id=" . $thread->id; |
129 | 129 | $body = "Another " . PROJECT . " user has posted to the thread |
@@ -113,7 +113,7 @@ |
||
113 | 113 | |
114 | 114 | For assistance with ".PROJECT." go to ".$master_url; |
115 | 115 | |
116 | - $subject = "THREAD $action REPORT: $thread->title"; |
|
116 | + $subject = "thread $action REPORT: $thread->title"; |
|
117 | 117 | $success = mail_report_list($forum, $subject, $body); |
118 | 118 | $success &= send_email($user, $subject, $body); |
119 | 119 | pm_send_msg($user, $user, $subject, $body, false); |
@@ -29,6 +29,9 @@ |
||
29 | 29 | return false; |
30 | 30 | } |
31 | 31 | |
32 | +/** |
|
33 | + * @param boolean $no_images |
|
34 | + */ |
|
32 | 35 | function show_forum_rss_item($thread, $userid, $threads_only, $no_images) { |
33 | 36 | $unique_url=secure_url_base()."forum_thread.php?id=".$thread->id; |
34 | 37 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | function show_forum_rss_item($thread, $userid, $threads_only, $no_images) { |
33 | - $unique_url=secure_url_base()."forum_thread.php?id=".$thread->id; |
|
33 | + $unique_url = secure_url_base()."forum_thread.php?id=".$thread->id; |
|
34 | 34 | |
35 | 35 | $clause2 = " and hidden=0 "; |
36 | 36 | if ($userid) $clause2 .= "and user=$userid"; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | if (!count($posts)) return; |
43 | 43 | $post = $posts[0]; |
44 | - $post_date = gmdate('D, d M Y H:i:s',$post->timestamp).' GMT'; |
|
44 | + $post_date = gmdate('D, d M Y H:i:s', $post->timestamp).' GMT'; |
|
45 | 45 | $post_user = BOincUser::lookup_id($post->user); |
46 | 46 | BoincForumPrefs::lookup($post_user); |
47 | 47 | $options = new output_options(); |
@@ -84,25 +84,25 @@ discard block |
||
84 | 84 | |
85 | 85 | // Now construct header |
86 | 86 | // |
87 | - header ("Expires: " . gmdate('D, d M Y H:i:s', time()+86400) . " GMT"); |
|
87 | + header("Expires: ".gmdate('D, d M Y H:i:s', time() + 86400)." GMT"); |
|
88 | 88 | if (sizeof($threads)) { |
89 | 89 | $t = $threads[0]; |
90 | - $last_mod_time = $threads_only?$t->create_time:$t->timestamp; |
|
91 | - $create_date = gmdate('D, d M Y H:i:s', $last_mod_time) . ' GMT'; |
|
92 | - header ("Last-Modified: " . $create_date); |
|
90 | + $last_mod_time = $threads_only ? $t->create_time : $t->timestamp; |
|
91 | + $create_date = gmdate('D, d M Y H:i:s', $last_mod_time).' GMT'; |
|
92 | + header("Last-Modified: ".$create_date); |
|
93 | 93 | } else { |
94 | - $create_date = gmdate('D, d M Y H:i:s') . ' GMT'; |
|
94 | + $create_date = gmdate('D, d M Y H:i:s').' GMT'; |
|
95 | 95 | } |
96 | - header ("Content-Type: application/xml"); |
|
96 | + header("Content-Type: application/xml"); |
|
97 | 97 | |
98 | - $forum=BoincForum::lookup_id($forumid); |
|
98 | + $forum = BoincForum::lookup_id($forumid); |
|
99 | 99 | // Create channel header and open XML content |
100 | 100 | // |
101 | 101 | $description = PROJECT.": $forum->title"; |
102 | 102 | if ($userid) { |
103 | 103 | $description .= " (posts by $user->name)"; |
104 | 104 | } |
105 | - $channel_image = secure_url_base() . "rss_image.gif"; |
|
105 | + $channel_image = secure_url_base()."rss_image.gif"; |
|
106 | 106 | $language = "en-us"; |
107 | 107 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> |
108 | 108 | <rss version=\"2.0\"> |
@@ -229,6 +229,9 @@ discard block |
||
229 | 229 | shmop_close ($shmid); |
230 | 230 | } |
231 | 231 | |
232 | +/** |
|
233 | + * @param GeoIP $gi |
|
234 | + */ |
|
232 | 235 | function _setup_segments($gi){ |
233 | 236 | $gi->databaseType = GEOIP_COUNTRY_EDITION; |
234 | 237 | $gi->record_length = STANDARD_RECORD_LENGTH; |
@@ -311,6 +314,10 @@ discard block |
||
311 | 314 | return $gi; |
312 | 315 | } |
313 | 316 | |
317 | +/** |
|
318 | + * @param string $filename |
|
319 | + * @param integer $flags |
|
320 | + */ |
|
314 | 321 | function geoip_open($filename, $flags) { |
315 | 322 | $gi = new GeoIP; |
316 | 323 | $gi->flags = $flags; |
@@ -419,6 +426,9 @@ discard block |
||
419 | 426 | return false; |
420 | 427 | } |
421 | 428 | |
429 | +/** |
|
430 | + * @param integer $ipnum |
|
431 | + */ |
|
422 | 432 | function _get_org($gi,$ipnum){ |
423 | 433 | $seek_org = _geoip_seek_country($gi,$ipnum); |
424 | 434 | if ($seek_org == $gi->databaseSegments) { |
@@ -443,6 +453,9 @@ discard block |
||
443 | 453 | return _get_org($gi, $ipnum); |
444 | 454 | } |
445 | 455 | |
456 | +/** |
|
457 | + * @param integer $ipnum |
|
458 | + */ |
|
446 | 459 | function _get_region($gi,$ipnum){ |
447 | 460 | if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
448 | 461 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
@@ -213,26 +213,26 @@ discard block |
||
213 | 213 | } |
214 | 214 | function geoip_load_shared_mem ($file) { |
215 | 215 | |
216 | - $fp = fopen($file, "rb"); |
|
217 | - if (!$fp) { |
|
216 | + $fp = fopen($file, "rb"); |
|
217 | + if (!$fp) { |
|
218 | 218 | print "error opening $file: $php_errormsg\n"; |
219 | 219 | exit; |
220 | - } |
|
221 | - $s_array = fstat($fp); |
|
222 | - $size = $s_array['size']; |
|
223 | - if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) { |
|
220 | + } |
|
221 | + $s_array = fstat($fp); |
|
222 | + $size = $s_array['size']; |
|
223 | + if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) { |
|
224 | 224 | shmop_delete ($shmid); |
225 | 225 | shmop_close ($shmid); |
226 | - } |
|
227 | - $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | - shmop_write ($shmid, fread($fp, $size), 0); |
|
229 | - shmop_close ($shmid); |
|
226 | + } |
|
227 | + $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | + shmop_write ($shmid, fread($fp, $size), 0); |
|
229 | + shmop_close ($shmid); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | function _setup_segments($gi){ |
233 | - $gi->databaseType = GEOIP_COUNTRY_EDITION; |
|
234 | - $gi->record_length = STANDARD_RECORD_LENGTH; |
|
235 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
233 | + $gi->databaseType = GEOIP_COUNTRY_EDITION; |
|
234 | + $gi->record_length = STANDARD_RECORD_LENGTH; |
|
235 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
236 | 236 | $offset = @shmop_size ($gi->shmid) - 3; |
237 | 237 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
238 | 238 | $delim = @shmop_read ($gi->shmid, $offset, 3); |
@@ -245,19 +245,19 @@ discard block |
||
245 | 245 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
246 | 246 | } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
247 | 247 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
248 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
|
248 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
|
249 | 249 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) |
250 | 250 | || ($gi->databaseType == GEOIP_ORG_EDITION) |
251 | - || ($gi->databaseType == GEOIP_ISP_EDITION) |
|
252 | - || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
251 | + || ($gi->databaseType == GEOIP_ISP_EDITION) |
|
252 | + || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
253 | 253 | $gi->databaseSegments = 0; |
254 | 254 | $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
255 | 255 | for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
256 | 256 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
257 | 257 | } |
258 | - if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
|
259 | - ($gi->databaseType == GEOIP_ISP_EDITION)) { |
|
260 | - $gi->record_length = ORG_RECORD_LENGTH; |
|
258 | + if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
|
259 | + ($gi->databaseType == GEOIP_ISP_EDITION)) { |
|
260 | + $gi->record_length = ORG_RECORD_LENGTH; |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | break; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
271 | 271 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
272 | 272 | } |
273 | - } else { |
|
273 | + } else { |
|
274 | 274 | $filepos = ftell($gi->filehandle); |
275 | 275 | fseek($gi->filehandle, -3, SEEK_END); |
276 | 276 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
282 | 282 | } |
283 | 283 | else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
284 | - $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
|
284 | + $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
|
285 | 285 | } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
286 | 286 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) || |
287 | 287 | ($gi->databaseType == GEOIP_ORG_EDITION) || |
288 | - ($gi->databaseType == GEOIP_ISP_EDITION) || |
|
288 | + ($gi->databaseType == GEOIP_ISP_EDITION) || |
|
289 | 289 | ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
290 | 290 | $gi->databaseSegments = 0; |
291 | 291 | $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH); |
292 | 292 | for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
293 | 293 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
294 | 294 | } |
295 | - if ($gi->databaseType == GEOIP_ORG_EDITION) { |
|
296 | - $gi->record_length = ORG_RECORD_LENGTH; |
|
295 | + if ($gi->databaseType == GEOIP_ORG_EDITION) { |
|
296 | + $gi->record_length = ORG_RECORD_LENGTH; |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | break; |
@@ -304,17 +304,17 @@ discard block |
||
304 | 304 | if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
305 | 305 | ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
306 | 306 | ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
307 | - $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
|
307 | + $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
|
308 | 308 | } |
309 | 309 | fseek($gi->filehandle,$filepos,SEEK_SET); |
310 | - } |
|
311 | - return $gi; |
|
310 | + } |
|
311 | + return $gi; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | function geoip_open($filename, $flags) { |
315 | - $gi = new GeoIP; |
|
316 | - $gi->flags = $flags; |
|
317 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
315 | + $gi = new GeoIP; |
|
316 | + $gi->flags = $flags; |
|
317 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
318 | 318 | $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0); |
319 | 319 | } else { |
320 | 320 | $gi->filehandle = fopen($filename,"rb"); |
@@ -322,174 +322,174 @@ discard block |
||
322 | 322 | $s_array = fstat($gi->filehandle); |
323 | 323 | $gi->memory_buffer = fread($gi->filehandle, $s_array[size]); |
324 | 324 | } |
325 | - } |
|
325 | + } |
|
326 | 326 | |
327 | - $gi = _setup_segments($gi); |
|
328 | - return $gi; |
|
327 | + $gi = _setup_segments($gi); |
|
328 | + return $gi; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | function geoip_close($gi) { |
332 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
332 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
333 | 333 | return true; |
334 | - } |
|
334 | + } |
|
335 | 335 | |
336 | - return fclose($gi->filehandle); |
|
336 | + return fclose($gi->filehandle); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | function geoip_country_id_by_name($gi, $name) { |
340 | - $addr = gethostbyname($name); |
|
341 | - if (!$addr || $addr == $name) { |
|
340 | + $addr = gethostbyname($name); |
|
341 | + if (!$addr || $addr == $name) { |
|
342 | 342 | return false; |
343 | - } |
|
344 | - return geoip_country_id_by_addr($gi, $addr); |
|
343 | + } |
|
344 | + return geoip_country_id_by_addr($gi, $addr); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | function geoip_country_code_by_name($gi, $name) { |
348 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
349 | - if ($country_id !== false) { |
|
348 | + $country_id = geoip_country_id_by_name($gi,$name); |
|
349 | + if ($country_id !== false) { |
|
350 | 350 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
351 | - } |
|
352 | - return false; |
|
351 | + } |
|
352 | + return false; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | function geoip_country_name_by_name($gi, $name) { |
356 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
357 | - if ($country_id !== false) { |
|
356 | + $country_id = geoip_country_id_by_name($gi,$name); |
|
357 | + if ($country_id !== false) { |
|
358 | 358 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
359 | - } |
|
360 | - return false; |
|
359 | + } |
|
360 | + return false; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | function geoip_country_id_by_addr($gi, $addr) { |
364 | - $ipnum = ip2long($addr); |
|
365 | - return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; |
|
364 | + $ipnum = ip2long($addr); |
|
365 | + return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | function geoip_country_code_by_addr($gi, $addr) { |
369 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
370 | - if ($country_id !== false) { |
|
369 | + $country_id = geoip_country_id_by_addr($gi,$addr); |
|
370 | + if ($country_id !== false) { |
|
371 | 371 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
372 | - } |
|
373 | - return false; |
|
372 | + } |
|
373 | + return false; |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | function geoip_country_name_by_addr($gi, $addr) { |
377 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
378 | - if ($country_id !== false) { |
|
377 | + $country_id = geoip_country_id_by_addr($gi,$addr); |
|
378 | + if ($country_id !== false) { |
|
379 | 379 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
380 | - } |
|
381 | - return false; |
|
380 | + } |
|
381 | + return false; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | function _geoip_seek_country($gi, $ipnum) { |
385 | - $offset = 0; |
|
386 | - for ($depth = 31; $depth >= 0; --$depth) { |
|
385 | + $offset = 0; |
|
386 | + for ($depth = 31; $depth >= 0; --$depth) { |
|
387 | 387 | if ($gi->flags & GEOIP_MEMORY_CACHE) { |
388 | - $buf = substr($gi->memory_buffer, |
|
388 | + $buf = substr($gi->memory_buffer, |
|
389 | 389 | 2 * $gi->record_length * $offset, |
390 | 390 | 2 * $gi->record_length); |
391 | 391 | } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { |
392 | - $buf = @shmop_read ($gi->shmid, |
|
392 | + $buf = @shmop_read ($gi->shmid, |
|
393 | 393 | 2 * $gi->record_length * $offset, |
394 | 394 | 2 * $gi->record_length ); |
395 | 395 | } else { |
396 | - fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 |
|
396 | + fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 |
|
397 | 397 | or die("fseek failed"); |
398 | - $buf = fread($gi->filehandle, 2 * $gi->record_length); |
|
398 | + $buf = fread($gi->filehandle, 2 * $gi->record_length); |
|
399 | 399 | } |
400 | 400 | $x = array(0,0); |
401 | 401 | for ($i = 0; $i < 2; ++$i) { |
402 | - for ($j = 0; $j < $gi->record_length; ++$j) { |
|
402 | + for ($j = 0; $j < $gi->record_length; ++$j) { |
|
403 | 403 | $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8); |
404 | - } |
|
404 | + } |
|
405 | 405 | } |
406 | 406 | if ($ipnum & (1 << $depth)) { |
407 | - if ($x[1] >= $gi->databaseSegments) { |
|
407 | + if ($x[1] >= $gi->databaseSegments) { |
|
408 | 408 | return $x[1]; |
409 | - } |
|
410 | - $offset = $x[1]; |
|
409 | + } |
|
410 | + $offset = $x[1]; |
|
411 | 411 | } else { |
412 | - if ($x[0] >= $gi->databaseSegments) { |
|
412 | + if ($x[0] >= $gi->databaseSegments) { |
|
413 | 413 | return $x[0]; |
414 | - } |
|
415 | - $offset = $x[0]; |
|
414 | + } |
|
415 | + $offset = $x[0]; |
|
416 | + } |
|
416 | 417 | } |
417 | - } |
|
418 | - trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR); |
|
419 | - return false; |
|
418 | + trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR); |
|
419 | + return false; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | function _get_org($gi,$ipnum){ |
423 | - $seek_org = _geoip_seek_country($gi,$ipnum); |
|
424 | - if ($seek_org == $gi->databaseSegments) { |
|
423 | + $seek_org = _geoip_seek_country($gi,$ipnum); |
|
424 | + if ($seek_org == $gi->databaseSegments) { |
|
425 | 425 | return NULL; |
426 | - } |
|
427 | - $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
|
428 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
426 | + } |
|
427 | + $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
|
428 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
429 | 429 | $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
430 | 430 | } else { |
431 | 431 | fseek($gi->filehandle, $record_pointer, SEEK_SET); |
432 | 432 | $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH); |
433 | - } |
|
434 | - $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); |
|
435 | - return $org_buf; |
|
433 | + } |
|
434 | + $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); |
|
435 | + return $org_buf; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | function geoip_org_by_addr ($gi,$addr) { |
439 | - if ($addr == NULL) { |
|
439 | + if ($addr == NULL) { |
|
440 | 440 | return 0; |
441 | - } |
|
442 | - $ipnum = ip2long($addr); |
|
443 | - return _get_org($gi, $ipnum); |
|
441 | + } |
|
442 | + $ipnum = ip2long($addr); |
|
443 | + return _get_org($gi, $ipnum); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | function _get_region($gi,$ipnum){ |
447 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
447 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
448 | 448 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
449 | 449 | if ($seek_region >= 1000){ |
450 | - $country_code = "US"; |
|
451 | - $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
|
450 | + $country_code = "US"; |
|
451 | + $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
|
452 | 452 | } else { |
453 | 453 | $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region]; |
454 | - $region = ""; |
|
454 | + $region = ""; |
|
455 | 455 | } |
456 | - return array ($country_code,$region); |
|
456 | + return array ($country_code,$region); |
|
457 | 457 | } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
458 | 458 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1; |
459 | 459 | //print $seek_region; |
460 | 460 | if ($seek_region < US_OFFSET){ |
461 | - $country_code = ""; |
|
462 | - $region = ""; |
|
461 | + $country_code = ""; |
|
462 | + $region = ""; |
|
463 | 463 | } else if ($seek_region < CANADA_OFFSET) { |
464 | - $country_code = "US"; |
|
465 | - $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65); |
|
464 | + $country_code = "US"; |
|
465 | + $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65); |
|
466 | 466 | } else if ($seek_region < WORLD_OFFSET) { |
467 | - $country_code = "CA"; |
|
468 | - $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
467 | + $country_code = "CA"; |
|
468 | + $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
469 | 469 | } else { |
470 | 470 | $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE]; |
471 | - $region = ""; |
|
471 | + $region = ""; |
|
472 | + } |
|
473 | + return array ($country_code,$region); |
|
472 | 474 | } |
473 | - return array ($country_code,$region); |
|
474 | - } |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | function geoip_region_by_addr ($gi,$addr) { |
478 | - if ($addr == NULL) { |
|
478 | + if ($addr == NULL) { |
|
479 | 479 | return 0; |
480 | - } |
|
481 | - $ipnum = ip2long($addr); |
|
482 | - return _get_region($gi, $ipnum); |
|
480 | + } |
|
481 | + $ipnum = ip2long($addr); |
|
482 | + return _get_region($gi, $ipnum); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | function getdnsattributes ($l,$ip){ |
486 | - $r = new Net_DNS_Resolver(); |
|
487 | - $r->nameservers = array("ws1.maxmind.com"); |
|
488 | - $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
|
489 | - $str = is_object($p->answer[0])?$p->answer[0]->string():''; |
|
490 | - ereg("\"(.*)\"",$str,$regs); |
|
491 | - $str = $regs[1]; |
|
492 | - return $str; |
|
486 | + $r = new Net_DNS_Resolver(); |
|
487 | + $r->nameservers = array("ws1.maxmind.com"); |
|
488 | + $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
|
489 | + $str = is_object($p->answer[0])?$p->answer[0]->string():''; |
|
490 | + ereg("\"(.*)\"",$str,$regs); |
|
491 | + $str = $regs[1]; |
|
492 | + return $str; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | ?> |
@@ -138,25 +138,25 @@ discard block |
||
138 | 138 | "VU", "WF", "WS", "YE", "YT", "CS", "ZA", "ZM", "ZR", "ZW", "A1", "A2", "O1" |
139 | 139 | ); |
140 | 140 | var $GEOIP_COUNTRY_CODES3 = array( |
141 | -"","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","AQ","ARG", |
|
142 | -"ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI", |
|
143 | -"BEN","BMU","BRN","BOL","BRA","BHS","BTN","BV","BWA","BLR","BLZ","CAN","CC", |
|
144 | -"COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV", |
|
145 | -"CX","CYP","CZE","DEU","DJI","DNK","DMA","DOM","DZA","ECU","EST","EGY","ESH", |
|
146 | -"ERI","ESP","ETH","FIN","FJI","FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD", |
|
147 | -"GEO","GUF","GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","GS","GTM","GUM", |
|
148 | -"GNB","GUY","HKG","HM","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IO", |
|
149 | -"IRQ","IRN","ISL","ITA","JAM","JOR","JPN","KEN","KGZ","KHM","KIR","COM","KNA", |
|
150 | -"PRK","KOR","KWT","CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU", |
|
151 | -"LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI","MMR","MNG","MAC", |
|
152 | -"MNP","MTQ","MRT","MSR","MLT","MUS","MDV","MWI","MEX","MYS","MOZ","NAM","NCL", |
|
153 | -"NER","NFK","NGA","NIC","NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER", |
|
154 | -"PYF","PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW","PRY","QAT", |
|
155 | -"REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN","SWE","SGP","SHN","SVN","SJM", |
|
156 | -"SVK","SLE","SMR","SEN","SOM","SUR","STP","SLV","SYR","SWZ","TCA","TCD","TF", |
|
157 | -"TGO","THA","TJK","TKL","TLS","TKM","TUN","TON","TUR","TTO","TUV","TWN","TZA", |
|
158 | -"UKR","UGA","UM","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT", |
|
159 | - "WLF","WSM","YEM","YT","SCG","ZAF","ZMB","ZR","ZWE","A1","A2","O1" |
|
141 | +"", "AP", "EU", "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", "ANT", "AGO", "AQ", "ARG", |
|
142 | +"ASM", "AUT", "AUS", "ABW", "AZE", "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", |
|
143 | +"BEN", "BMU", "BRN", "BOL", "BRA", "BHS", "BTN", "BV", "BWA", "BLR", "BLZ", "CAN", "CC", |
|
144 | +"COD", "CAF", "COG", "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", "CUB", "CPV", |
|
145 | +"CX", "CYP", "CZE", "DEU", "DJI", "DNK", "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", |
|
146 | +"ERI", "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", "FX", "GAB", "GBR", "GRD", |
|
147 | +"GEO", "GUF", "GHA", "GIB", "GRL", "GMB", "GIN", "GLP", "GNQ", "GRC", "GS", "GTM", "GUM", |
|
148 | +"GNB", "GUY", "HKG", "HM", "HND", "HRV", "HTI", "HUN", "IDN", "IRL", "ISR", "IND", "IO", |
|
149 | +"IRQ", "IRN", "ISL", "ITA", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", "COM", "KNA", |
|
150 | +"PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", |
|
151 | +"LUX", "LVA", "LBY", "MAR", "MCO", "MDA", "MDG", "MHL", "MKD", "MLI", "MMR", "MNG", "MAC", |
|
152 | +"MNP", "MTQ", "MRT", "MSR", "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", "NCL", |
|
153 | +"NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", "NRU", "NIU", "NZL", "OMN", "PAN", "PER", |
|
154 | +"PYF", "PNG", "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", "PLW", "PRY", "QAT", |
|
155 | +"REU", "ROU", "RUS", "RWA", "SAU", "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", |
|
156 | +"SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "STP", "SLV", "SYR", "SWZ", "TCA", "TCD", "TF", |
|
157 | +"TGO", "THA", "TJK", "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", "TWN", "TZA", |
|
158 | +"UKR", "UGA", "UM", "USA", "URY", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", |
|
159 | + "WLF", "WSM", "YEM", "YT", "SCG", "ZAF", "ZMB", "ZR", "ZWE", "A1", "A2", "O1" |
|
160 | 160 | ); |
161 | 161 | var $GEOIP_COUNTRY_NAMES = array( |
162 | 162 | "", "Asia/Pacific Region", "Europe", "Andorra", "United Arab Emirates", |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | Grenadines", "Venezuela", "Virgin Islands, British", "Virgin Islands, U.S.", |
209 | 209 | "Vietnam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte", |
210 | 210 | "Serbia and Montenegro", "South Africa", "Zambia", "Zaire", "Zimbabwe", |
211 | -"Anonymous Proxy","Satellite Provider","Other" |
|
211 | +"Anonymous Proxy", "Satellite Provider", "Other" |
|
212 | 212 | ); |
213 | 213 | } |
214 | -function geoip_load_shared_mem ($file) { |
|
214 | +function geoip_load_shared_mem($file) { |
|
215 | 215 | |
216 | 216 | $fp = fopen($file, "rb"); |
217 | 217 | if (!$fp) { |
@@ -220,42 +220,42 @@ discard block |
||
220 | 220 | } |
221 | 221 | $s_array = fstat($fp); |
222 | 222 | $size = $s_array['size']; |
223 | - if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) { |
|
224 | - shmop_delete ($shmid); |
|
225 | - shmop_close ($shmid); |
|
223 | + if ($shmid = @shmop_open(GEOIP_SHM_KEY, "w", 0, 0)) { |
|
224 | + shmop_delete($shmid); |
|
225 | + shmop_close($shmid); |
|
226 | 226 | } |
227 | - $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | - shmop_write ($shmid, fread($fp, $size), 0); |
|
229 | - shmop_close ($shmid); |
|
227 | + $shmid = shmop_open(GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | + shmop_write($shmid, fread($fp, $size), 0); |
|
229 | + shmop_close($shmid); |
|
230 | 230 | } |
231 | 231 | |
232 | -function _setup_segments($gi){ |
|
232 | +function _setup_segments($gi) { |
|
233 | 233 | $gi->databaseType = GEOIP_COUNTRY_EDITION; |
234 | 234 | $gi->record_length = STANDARD_RECORD_LENGTH; |
235 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
236 | - $offset = @shmop_size ($gi->shmid) - 3; |
|
235 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
236 | + $offset = @shmop_size($gi->shmid) - 3; |
|
237 | 237 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
238 | - $delim = @shmop_read ($gi->shmid, $offset, 3); |
|
238 | + $delim = @shmop_read($gi->shmid, $offset, 3); |
|
239 | 239 | $offset += 3; |
240 | 240 | if ($delim == (chr(255).chr(255).chr(255))) { |
241 | - $gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1)); |
|
241 | + $gi->databaseType = ord(@shmop_read($gi->shmid, $offset, 1)); |
|
242 | 242 | $offset++; |
243 | 243 | |
244 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
244 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
245 | 245 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
246 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
246 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
247 | 247 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
248 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
|
248 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
249 | 249 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) |
250 | 250 | || ($gi->databaseType == GEOIP_ORG_EDITION) |
251 | 251 | || ($gi->databaseType == GEOIP_ISP_EDITION) |
252 | - || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
252 | + || ($gi->databaseType == GEOIP_ASNUM_EDITION)) { |
|
253 | 253 | $gi->databaseSegments = 0; |
254 | - $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
|
255 | - for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
|
256 | - $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
|
254 | + $buf = @shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
|
255 | + for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { |
|
256 | + $gi->databaseSegments += (ord($buf[$j]) << ($j*8)); |
|
257 | 257 | } |
258 | - if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
|
258 | + if (($gi->databaseType == GEOIP_ORG_EDITION) || |
|
259 | 259 | ($gi->databaseType == GEOIP_ISP_EDITION)) { |
260 | 260 | $gi->record_length = ORG_RECORD_LENGTH; |
261 | 261 | } |
@@ -265,32 +265,32 @@ discard block |
||
265 | 265 | $offset -= 4; |
266 | 266 | } |
267 | 267 | } |
268 | - if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
|
269 | - ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
|
270 | - ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
|
268 | + if (($gi->databaseType == GEOIP_COUNTRY_EDITION) || |
|
269 | + ($gi->databaseType == GEOIP_PROXY_EDITION) || |
|
270 | + ($gi->databaseType == GEOIP_NETSPEED_EDITION)) { |
|
271 | 271 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
272 | 272 | } |
273 | 273 | } else { |
274 | 274 | $filepos = ftell($gi->filehandle); |
275 | 275 | fseek($gi->filehandle, -3, SEEK_END); |
276 | 276 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
277 | - $delim = fread($gi->filehandle,3); |
|
278 | - if ($delim == (chr(255).chr(255).chr(255))){ |
|
279 | - $gi->databaseType = ord(fread($gi->filehandle,1)); |
|
280 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
277 | + $delim = fread($gi->filehandle, 3); |
|
278 | + if ($delim == (chr(255).chr(255).chr(255))) { |
|
279 | + $gi->databaseType = ord(fread($gi->filehandle, 1)); |
|
280 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
281 | 281 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
282 | 282 | } |
283 | - else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
283 | + else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
284 | 284 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
285 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
285 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
286 | 286 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) || |
287 | 287 | ($gi->databaseType == GEOIP_ORG_EDITION) || |
288 | 288 | ($gi->databaseType == GEOIP_ISP_EDITION) || |
289 | - ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
289 | + ($gi->databaseType == GEOIP_ASNUM_EDITION)) { |
|
290 | 290 | $gi->databaseSegments = 0; |
291 | - $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH); |
|
292 | - for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
|
293 | - $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
|
291 | + $buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH); |
|
292 | + for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { |
|
293 | + $gi->databaseSegments += (ord($buf[$j]) << ($j*8)); |
|
294 | 294 | } |
295 | 295 | if ($gi->databaseType == GEOIP_ORG_EDITION) { |
296 | 296 | $gi->record_length = ORG_RECORD_LENGTH; |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | fseek($gi->filehandle, -4, SEEK_CUR); |
302 | 302 | } |
303 | 303 | } |
304 | - if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
|
305 | - ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
|
306 | - ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
|
304 | + if (($gi->databaseType == GEOIP_COUNTRY_EDITION) || |
|
305 | + ($gi->databaseType == GEOIP_PROXY_EDITION) || |
|
306 | + ($gi->databaseType == GEOIP_NETSPEED_EDITION)) { |
|
307 | 307 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
308 | 308 | } |
309 | - fseek($gi->filehandle,$filepos,SEEK_SET); |
|
309 | + fseek($gi->filehandle, $filepos, SEEK_SET); |
|
310 | 310 | } |
311 | 311 | return $gi; |
312 | 312 | } |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | function geoip_open($filename, $flags) { |
315 | 315 | $gi = new GeoIP; |
316 | 316 | $gi->flags = $flags; |
317 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
318 | - $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0); |
|
317 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
318 | + $gi->shmid = @shmop_open(GEOIP_SHM_KEY, "a", 0, 0); |
|
319 | 319 | } else { |
320 | - $gi->filehandle = fopen($filename,"rb"); |
|
321 | - if ($gi->flags & GEOIP_MEMORY_CACHE) { |
|
320 | + $gi->filehandle = fopen($filename, "rb"); |
|
321 | + if ($gi->flags&GEOIP_MEMORY_CACHE) { |
|
322 | 322 | $s_array = fstat($gi->filehandle); |
323 | 323 | $gi->memory_buffer = fread($gi->filehandle, $s_array[size]); |
324 | 324 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | function geoip_close($gi) { |
332 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
332 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
333 | 333 | return true; |
334 | 334 | } |
335 | 335 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | } |
346 | 346 | |
347 | 347 | function geoip_country_code_by_name($gi, $name) { |
348 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
348 | + $country_id = geoip_country_id_by_name($gi, $name); |
|
349 | 349 | if ($country_id !== false) { |
350 | 350 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
351 | 351 | } |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | function geoip_country_name_by_name($gi, $name) { |
356 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
356 | + $country_id = geoip_country_id_by_name($gi, $name); |
|
357 | 357 | if ($country_id !== false) { |
358 | 358 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
359 | 359 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | |
368 | 368 | function geoip_country_code_by_addr($gi, $addr) { |
369 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
369 | + $country_id = geoip_country_id_by_addr($gi, $addr); |
|
370 | 370 | if ($country_id !== false) { |
371 | 371 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
372 | 372 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | function geoip_country_name_by_addr($gi, $addr) { |
377 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
377 | + $country_id = geoip_country_id_by_addr($gi, $addr); |
|
378 | 378 | if ($country_id !== false) { |
379 | 379 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
380 | 380 | } |
@@ -384,26 +384,26 @@ discard block |
||
384 | 384 | function _geoip_seek_country($gi, $ipnum) { |
385 | 385 | $offset = 0; |
386 | 386 | for ($depth = 31; $depth >= 0; --$depth) { |
387 | - if ($gi->flags & GEOIP_MEMORY_CACHE) { |
|
387 | + if ($gi->flags&GEOIP_MEMORY_CACHE) { |
|
388 | 388 | $buf = substr($gi->memory_buffer, |
389 | - 2 * $gi->record_length * $offset, |
|
390 | - 2 * $gi->record_length); |
|
391 | - } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
392 | - $buf = @shmop_read ($gi->shmid, |
|
393 | - 2 * $gi->record_length * $offset, |
|
394 | - 2 * $gi->record_length ); |
|
389 | + 2*$gi->record_length*$offset, |
|
390 | + 2*$gi->record_length); |
|
391 | + } elseif ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
392 | + $buf = @shmop_read($gi->shmid, |
|
393 | + 2*$gi->record_length*$offset, |
|
394 | + 2*$gi->record_length); |
|
395 | 395 | } else { |
396 | - fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 |
|
396 | + fseek($gi->filehandle, 2*$gi->record_length*$offset, SEEK_SET) == 0 |
|
397 | 397 | or die("fseek failed"); |
398 | - $buf = fread($gi->filehandle, 2 * $gi->record_length); |
|
398 | + $buf = fread($gi->filehandle, 2*$gi->record_length); |
|
399 | 399 | } |
400 | - $x = array(0,0); |
|
400 | + $x = array(0, 0); |
|
401 | 401 | for ($i = 0; $i < 2; ++$i) { |
402 | 402 | for ($j = 0; $j < $gi->record_length; ++$j) { |
403 | - $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8); |
|
403 | + $x[$i] += ord($buf[$gi->record_length*$i + $j]) << ($j*8); |
|
404 | 404 | } |
405 | 405 | } |
406 | - if ($ipnum & (1 << $depth)) { |
|
406 | + if ($ipnum&(1 << $depth)) { |
|
407 | 407 | if ($x[1] >= $gi->databaseSegments) { |
408 | 408 | return $x[1]; |
409 | 409 | } |
@@ -419,23 +419,23 @@ discard block |
||
419 | 419 | return false; |
420 | 420 | } |
421 | 421 | |
422 | -function _get_org($gi,$ipnum){ |
|
423 | - $seek_org = _geoip_seek_country($gi,$ipnum); |
|
422 | +function _get_org($gi, $ipnum) { |
|
423 | + $seek_org = _geoip_seek_country($gi, $ipnum); |
|
424 | 424 | if ($seek_org == $gi->databaseSegments) { |
425 | 425 | return NULL; |
426 | 426 | } |
427 | - $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
|
428 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
429 | - $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
|
427 | + $record_pointer = $seek_org + (2*$gi->record_length - 1)*$gi->databaseSegments; |
|
428 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
429 | + $org_buf = @shmop_read($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
|
430 | 430 | } else { |
431 | 431 | fseek($gi->filehandle, $record_pointer, SEEK_SET); |
432 | - $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH); |
|
432 | + $org_buf = fread($gi->filehandle, MAX_ORG_RECORD_LENGTH); |
|
433 | 433 | } |
434 | 434 | $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); |
435 | 435 | return $org_buf; |
436 | 436 | } |
437 | 437 | |
438 | -function geoip_org_by_addr ($gi,$addr) { |
|
438 | +function geoip_org_by_addr($gi, $addr) { |
|
439 | 439 | if ($addr == NULL) { |
440 | 440 | return 0; |
441 | 441 | } |
@@ -443,38 +443,38 @@ discard block |
||
443 | 443 | return _get_org($gi, $ipnum); |
444 | 444 | } |
445 | 445 | |
446 | -function _get_region($gi,$ipnum){ |
|
447 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
448 | - $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
|
449 | - if ($seek_region >= 1000){ |
|
446 | +function _get_region($gi, $ipnum) { |
|
447 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
448 | + $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0; |
|
449 | + if ($seek_region >= 1000) { |
|
450 | 450 | $country_code = "US"; |
451 | - $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
|
451 | + $region = chr(($seek_region - 1000)/26 + 65).chr(($seek_region - 1000)%26 + 65); |
|
452 | 452 | } else { |
453 | 453 | $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region]; |
454 | 454 | $region = ""; |
455 | 455 | } |
456 | - return array ($country_code,$region); |
|
457 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
458 | - $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1; |
|
456 | + return array($country_code, $region); |
|
457 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
458 | + $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1; |
|
459 | 459 | //print $seek_region; |
460 | - if ($seek_region < US_OFFSET){ |
|
460 | + if ($seek_region < US_OFFSET) { |
|
461 | 461 | $country_code = ""; |
462 | 462 | $region = ""; |
463 | 463 | } else if ($seek_region < CANADA_OFFSET) { |
464 | 464 | $country_code = "US"; |
465 | - $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65); |
|
465 | + $region = chr(($seek_region - US_OFFSET)/26 + 65).chr(($seek_region - US_OFFSET)%26 + 65); |
|
466 | 466 | } else if ($seek_region < WORLD_OFFSET) { |
467 | 467 | $country_code = "CA"; |
468 | - $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
468 | + $region = chr(($seek_region - CANADA_OFFSET)/26 + 65).chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
469 | 469 | } else { |
470 | - $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE]; |
|
470 | + $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET)/FIPS_RANGE]; |
|
471 | 471 | $region = ""; |
472 | 472 | } |
473 | - return array ($country_code,$region); |
|
473 | + return array($country_code, $region); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | -function geoip_region_by_addr ($gi,$addr) { |
|
477 | +function geoip_region_by_addr($gi, $addr) { |
|
478 | 478 | if ($addr == NULL) { |
479 | 479 | return 0; |
480 | 480 | } |
@@ -482,12 +482,12 @@ discard block |
||
482 | 482 | return _get_region($gi, $ipnum); |
483 | 483 | } |
484 | 484 | |
485 | -function getdnsattributes ($l,$ip){ |
|
485 | +function getdnsattributes($l, $ip) { |
|
486 | 486 | $r = new Net_DNS_Resolver(); |
487 | 487 | $r->nameservers = array("ws1.maxmind.com"); |
488 | - $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
|
489 | - $str = is_object($p->answer[0])?$p->answer[0]->string():''; |
|
490 | - ereg("\"(.*)\"",$str,$regs); |
|
488 | + $p = $r->search($l.".".$ip.".s.maxmind.com", "TXT", "IN"); |
|
489 | + $str = is_object($p->answer[0]) ? $p->answer[0]->string() : ''; |
|
490 | + ereg("\"(.*)\"", $str, $regs); |
|
491 | 491 | $str = $regs[1]; |
492 | 492 | return $str; |
493 | 493 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | shmop_close ($shmid); |
230 | 230 | } |
231 | 231 | |
232 | -function _setup_segments($gi){ |
|
232 | +function _setup_segments($gi) { |
|
233 | 233 | $gi->databaseType = GEOIP_COUNTRY_EDITION; |
234 | 234 | $gi->record_length = STANDARD_RECORD_LENGTH; |
235 | 235 | if ($gi->flags & GEOIP_SHARED_MEMORY) { |
@@ -241,18 +241,18 @@ discard block |
||
241 | 241 | $gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1)); |
242 | 242 | $offset++; |
243 | 243 | |
244 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
244 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
245 | 245 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
246 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
246 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
247 | 247 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
248 | 248 | } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
249 | 249 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) |
250 | 250 | || ($gi->databaseType == GEOIP_ORG_EDITION) |
251 | 251 | || ($gi->databaseType == GEOIP_ISP_EDITION) |
252 | - || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
252 | + || ($gi->databaseType == GEOIP_ASNUM_EDITION)) { |
|
253 | 253 | $gi->databaseSegments = 0; |
254 | 254 | $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
255 | - for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
|
255 | + for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++) { |
|
256 | 256 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
257 | 257 | } |
258 | 258 | if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | } |
268 | 268 | if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
269 | 269 | ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
270 | - ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
|
270 | + ($gi->databaseType == GEOIP_NETSPEED_EDITION)) { |
|
271 | 271 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
272 | 272 | } |
273 | 273 | } else { |
@@ -275,21 +275,20 @@ discard block |
||
275 | 275 | fseek($gi->filehandle, -3, SEEK_END); |
276 | 276 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
277 | 277 | $delim = fread($gi->filehandle,3); |
278 | - if ($delim == (chr(255).chr(255).chr(255))){ |
|
278 | + if ($delim == (chr(255).chr(255).chr(255))) { |
|
279 | 279 | $gi->databaseType = ord(fread($gi->filehandle,1)); |
280 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
280 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
281 | 281 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
282 | - } |
|
283 | - else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
282 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
284 | 283 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
285 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
284 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
286 | 285 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) || |
287 | 286 | ($gi->databaseType == GEOIP_ORG_EDITION) || |
288 | 287 | ($gi->databaseType == GEOIP_ISP_EDITION) || |
289 | - ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
288 | + ($gi->databaseType == GEOIP_ASNUM_EDITION)) { |
|
290 | 289 | $gi->databaseSegments = 0; |
291 | 290 | $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH); |
292 | - for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
|
291 | + for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++) { |
|
293 | 292 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
294 | 293 | } |
295 | 294 | if ($gi->databaseType == GEOIP_ORG_EDITION) { |
@@ -303,7 +302,7 @@ discard block |
||
303 | 302 | } |
304 | 303 | if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
305 | 304 | ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
306 | - ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
|
305 | + ($gi->databaseType == GEOIP_NETSPEED_EDITION)) { |
|
307 | 306 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
308 | 307 | } |
309 | 308 | fseek($gi->filehandle,$filepos,SEEK_SET); |
@@ -419,7 +418,7 @@ discard block |
||
419 | 418 | return false; |
420 | 419 | } |
421 | 420 | |
422 | -function _get_org($gi,$ipnum){ |
|
421 | +function _get_org($gi,$ipnum) { |
|
423 | 422 | $seek_org = _geoip_seek_country($gi,$ipnum); |
424 | 423 | if ($seek_org == $gi->databaseSegments) { |
425 | 424 | return NULL; |
@@ -443,10 +442,10 @@ discard block |
||
443 | 442 | return _get_org($gi, $ipnum); |
444 | 443 | } |
445 | 444 | |
446 | -function _get_region($gi,$ipnum){ |
|
447 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
445 | +function _get_region($gi,$ipnum) { |
|
446 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
448 | 447 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
449 | - if ($seek_region >= 1000){ |
|
448 | + if ($seek_region >= 1000) { |
|
450 | 449 | $country_code = "US"; |
451 | 450 | $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
452 | 451 | } else { |
@@ -454,10 +453,10 @@ discard block |
||
454 | 453 | $region = ""; |
455 | 454 | } |
456 | 455 | return array ($country_code,$region); |
457 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
456 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
458 | 457 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1; |
459 | 458 | //print $seek_region; |
460 | - if ($seek_region < US_OFFSET){ |
|
459 | + if ($seek_region < US_OFFSET) { |
|
461 | 460 | $country_code = ""; |
462 | 461 | $region = ""; |
463 | 462 | } else if ($seek_region < CANADA_OFFSET) { |
@@ -482,7 +481,7 @@ discard block |
||
482 | 481 | return _get_region($gi, $ipnum); |
483 | 482 | } |
484 | 483 | |
485 | -function getdnsattributes ($l,$ip){ |
|
484 | +function getdnsattributes ($l,$ip) { |
|
486 | 485 | $r = new Net_DNS_Resolver(); |
487 | 486 | $r->nameservers = array("ws1.maxmind.com"); |
488 | 487 | $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | function _get_org($gi,$ipnum){ |
423 | 423 | $seek_org = _geoip_seek_country($gi,$ipnum); |
424 | 424 | if ($seek_org == $gi->databaseSegments) { |
425 | - return NULL; |
|
425 | + return null; |
|
426 | 426 | } |
427 | 427 | $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
428 | 428 | if ($gi->flags & GEOIP_SHARED_MEMORY) { |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | } |
437 | 437 | |
438 | 438 | function geoip_org_by_addr ($gi,$addr) { |
439 | - if ($addr == NULL) { |
|
439 | + if ($addr == null) { |
|
440 | 440 | return 0; |
441 | 441 | } |
442 | 442 | $ipnum = ip2long($addr); |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | function geoip_region_by_addr ($gi,$addr) { |
478 | - if ($addr == NULL) { |
|
478 | + if ($addr == null) { |
|
479 | 479 | return 0; |
480 | 480 | } |
481 | 481 | $ipnum = ip2long($addr); |
@@ -324,6 +324,11 @@ discard block |
||
324 | 324 | // so it's OK to show the domain name etc. |
325 | 325 | // If private is false, show the owner's name only if they've given permission |
326 | 326 | // |
327 | +/** |
|
328 | + * @param integer $i |
|
329 | + * @param boolean $show_owner |
|
330 | + * @param boolean $any_product_name |
|
331 | + */ |
|
327 | 332 | function show_host_row($host, $i, $private, $show_owner, $any_product_name) { |
328 | 333 | $anonymous = false; |
329 | 334 | if (!$private) { |
@@ -503,6 +508,9 @@ discard block |
||
503 | 508 | // that their time intervals are disjoint. |
504 | 509 | // So the CPU/OS checks don't have to be very strict. |
505 | 510 | // |
511 | +/** |
|
512 | + * @param boolean $show_detail |
|
513 | + */ |
|
506 | 514 | function hosts_compatible($host1, $host2, $show_detail) { |
507 | 515 | // A host is "new" if it has no credit and no results. |
508 | 516 | // Skip disjoint-time check if one host or other is new |
@@ -642,6 +650,9 @@ discard block |
||
642 | 650 | return "hosts_user.php?sort=$sort&rev=$rev&show_all=$show_all$x"; |
643 | 651 | } |
644 | 652 | |
653 | +/** |
|
654 | + * @param string $sort |
|
655 | + */ |
|
645 | 656 | function link_url_rev($actual_sort, $sort, $rev, $show_all) { |
646 | 657 | if ($actual_sort == $sort) { |
647 | 658 | $rev = 1 - $rev; |
@@ -661,6 +672,9 @@ discard block |
||
661 | 672 | echo "<p>"; |
662 | 673 | } |
663 | 674 | |
675 | +/** |
|
676 | + * @param boolean $any_product_name |
|
677 | + */ |
|
664 | 678 | function user_host_table_start( |
665 | 679 | $private, $sort, $rev, $show_all, $any_product_name |
666 | 680 | ) { |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | |
33 | 33 | function sched_log_name($x) { |
34 | 34 | if ($x == 0) return "NO_SUCH_LOG"; |
35 | - return gmdate('Y-m-d_H/Y-m-d_H:i', $x) . ".txt"; |
|
35 | + return gmdate('Y-m-d_H/Y-m-d_H:i', $x).".txt"; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function sched_log_link($x) { |
39 | 39 | if (file_exists("sched_logs")) { |
40 | - return "<a href=\"../sched_logs/" . sched_log_name($x) . "\">" . time_str($x) . "</a>"; |
|
40 | + return "<a href=\"../sched_logs/".sched_log_name($x)."\">".time_str($x)."</a>"; |
|
41 | 41 | } else { |
42 | 42 | return time_str($x); |
43 | 43 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | function location_form($host) { |
47 | 47 | $none = "selected"; |
48 | - $h=$w=$s=$m=""; |
|
48 | + $h = $w = $s = $m = ""; |
|
49 | 49 | if ($host->venue == "home") $h = "selected"; |
50 | 50 | if ($host->venue == "work") $w = "selected"; |
51 | 51 | if ($host->venue == "school") $s = "selected"; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | row2(tra("Product name"), $host->product_name); |
99 | 99 | } |
100 | 100 | $x = $host->timezone/3600; |
101 | - if ($x >= 0) $x="+$x"; |
|
101 | + if ($x >= 0) $x = "+$x"; |
|
102 | 102 | row2(tra("Local Standard Time"), tra("UTC %1 hours", $x)); |
103 | 103 | } else { |
104 | 104 | $owner = BoincUser::lookup_id($host->userid); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | if ($d[0] == "BOINC") continue; |
257 | 257 | if ($d[0] == "vbox") continue; |
258 | 258 | if ($str) $str .= "<p>"; |
259 | - if ($d[2]!="" && $d[2]!="1") $str .= "[".$d[2]."] "; |
|
259 | + if ($d[2] != "" && $d[2] != "1") $str .= "[".$d[2]."] "; |
|
260 | 260 | if ($d[0] == "CUDA") { |
261 | 261 | $str .= "NVIDIA"; |
262 | 262 | } else if ($d[0] == "CAL") { |
@@ -449,14 +449,14 @@ discard block |
||
449 | 449 | if ($pos1 === false) return $x; |
450 | 450 | $pos2 = strpos($model, ']'); |
451 | 451 | if ($pos2 === false) return $x; |
452 | - $a = substr($model, $pos1+1, $pos2-$pos1-1); |
|
452 | + $a = substr($model, $pos1 + 1, $pos2 - $pos1 - 1); |
|
453 | 453 | $y = explode(" ", $a); |
454 | 454 | if (count($y) == 0) return $x; |
455 | 455 | if ($y[0] == "Family") { |
456 | 456 | $x->info = $a; |
457 | 457 | } else { |
458 | 458 | $x->arch = $y[0]; |
459 | - $x->info = substr($a, strlen($y[0])+1); |
|
459 | + $x->info = substr($a, strlen($y[0]) + 1); |
|
460 | 460 | } |
461 | 461 | return $x; |
462 | 462 | } |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | $avg_time = 0; |
546 | 546 | |
547 | 547 | $results = BoincResult::enum("hostid=$hostid order by received_time"); |
548 | - foreach($results as $result) { |
|
548 | + foreach ($results as $result) { |
|
549 | 549 | if ($result->granted_credit <= 0) continue; |
550 | 550 | $total += $result->granted_credit; |
551 | 551 | |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | |
639 | 639 | function link_url($sort, $rev, $show_all) { |
640 | 640 | global $userid; |
641 | - $x = $userid ? "&userid=$userid":""; |
|
641 | + $x = $userid ? "&userid=$userid" : ""; |
|
642 | 642 | return "hosts_user.php?sort=$sort&rev=$rev&show_all=$show_all$x"; |
643 | 643 | } |
644 | 644 | |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | } |
711 | 711 | |
712 | 712 | function show_user_hosts($userid, $private, $show_all, $sort, $rev) { |
713 | - $desc = false; // whether the sort order's default is decreasing |
|
713 | + $desc = false; // whether the sort order's default is decreasing |
|
714 | 714 | switch ($sort) { |
715 | 715 | case "total_credit": $sort_clause = "total_credit"; $desc = true; break; |
716 | 716 | case "expavg_credit": $sort_clause = "expavg_credit"; $desc = true; break; |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | more_or_less($sort, $rev, $show_all); |
734 | 734 | |
735 | 735 | $now = time(); |
736 | - $old_hosts=0; |
|
736 | + $old_hosts = 0; |
|
737 | 737 | $i = 1; |
738 | 738 | $hosts = BoincHost::enum("userid=$userid order by $sort_clause"); |
739 | 739 | $any_product_name = false; |
@@ -745,9 +745,9 @@ discard block |
||
745 | 745 | } |
746 | 746 | user_host_table_start($private, $sort, $rev, $show_all, $any_product_name); |
747 | 747 | foreach ($hosts as $host) { |
748 | - $is_old=false; |
|
748 | + $is_old = false; |
|
749 | 749 | if (($now - $host->rpc_time) > 30*86400) { |
750 | - $is_old=true; |
|
750 | + $is_old = true; |
|
751 | 751 | $old_hosts++; |
752 | 752 | } |
753 | 753 | if (!$show_all && $is_old) continue; |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | } |
757 | 757 | end_table(); |
758 | 758 | |
759 | - if ($old_hosts>0) { |
|
759 | + if ($old_hosts > 0) { |
|
760 | 760 | more_or_less($sort, $rev, $show_all); |
761 | 761 | } |
762 | 762 | |
@@ -776,6 +776,6 @@ discard block |
||
776 | 776 | } |
777 | 777 | } |
778 | 778 | |
779 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
779 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
780 | 780 | |
781 | 781 | ?> |
@@ -90,7 +90,7 @@ |
||
90 | 90 | if ($host->last_ip_addr != $host->external_ip_addr) { |
91 | 91 | row2(tra("External IP address"), $host->external_ip_addr); |
92 | 92 | } |
93 | - } else { |
|
93 | + } else { |
|
94 | 94 | row2(tra("IP address"), "<a href=show_host_detail.php?hostid=$host->id&ipprivate=1>".tra("Show IP address")."</a>"); |
95 | 95 | } |
96 | 96 | row2(tra("Domain name"), $host->domain_name); |
@@ -65,6 +65,10 @@ |
||
65 | 65 | return $forum->parent_type == 0 && ($forum->title === $forum_name); |
66 | 66 | } |
67 | 67 | |
68 | +/** |
|
69 | + * @param integer $start |
|
70 | + * @param integer $count |
|
71 | + */ |
|
68 | 72 | function show_news($start, $count) { |
69 | 73 | $forum = news_forum(); |
70 | 74 | if (!$forum) { |
@@ -118,5 +118,5 @@ |
||
118 | 118 | "; |
119 | 119 | } |
120 | 120 | |
121 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
121 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
122 | 122 | ?> |
@@ -27,6 +27,10 @@ discard block |
||
27 | 27 | echo "</div>\n"; |
28 | 28 | } |
29 | 29 | |
30 | +/** |
|
31 | + * @param null|integer $teamid |
|
32 | + * @param string $error |
|
33 | + */ |
|
30 | 34 | function pm_team_form($user, $teamid, $error=null) { |
31 | 35 | global $bbcode_html, $bbcode_js; |
32 | 36 | $team = BoincTeam::lookup_id($teamid); |
@@ -78,6 +82,9 @@ discard block |
||
78 | 82 | page_tail(); |
79 | 83 | } |
80 | 84 | |
85 | +/** |
|
86 | + * @param string $error |
|
87 | + */ |
|
81 | 88 | function pm_form($replyto, $userid, $error = null) { |
82 | 89 | global $bbcode_html, $bbcode_js; |
83 | 90 | global $g_logged_in_user; |
@@ -196,6 +203,9 @@ discard block |
||
196 | 203 | return "<a href=pm.php>".tra("Private message%1 from %2, subject:" , "</a>", $from_user->name )." $pm->subject"; |
197 | 204 | } |
198 | 205 | |
206 | +/** |
|
207 | + * @param boolean $send_email |
|
208 | + */ |
|
199 | 209 | function pm_send_msg($from_user, $to_user, $subject, $content, $send_email) { |
200 | 210 | $sql_subject = BoincDb::escape_string(sanitize_tags($subject)); |
201 | 211 | $sql_content = BoincDb::escape_string($content); |
@@ -224,6 +234,9 @@ discard block |
||
224 | 234 | BoincNotify::insert("(userid, create_time, type, opaque) values ($to_user->id, ".time().", ".NOTIFY_PM.", $mid)"); |
225 | 235 | } |
226 | 236 | |
237 | +/** |
|
238 | + * @param integer $duration |
|
239 | + */ |
|
227 | 240 | function pm_count($userid, $duration) { |
228 | 241 | $time = time() - $duration; |
229 | 242 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | echo "</div>\n"; |
28 | 28 | } |
29 | 29 | |
30 | -function pm_team_form($user, $teamid, $error=null) { |
|
30 | +function pm_team_form($user, $teamid, $error = null) { |
|
31 | 31 | global $bbcode_html, $bbcode_js; |
32 | 32 | $team = BoincTeam::lookup_id($teamid); |
33 | 33 | if (!$team) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | error_page("not admin"); |
38 | 38 | } |
39 | 39 | |
40 | - page_head(tra("Send message to team"),'','','', $bbcode_js); |
|
40 | + page_head(tra("Send message to team"), '', '', '', $bbcode_js); |
|
41 | 41 | |
42 | 42 | $subject = post_str("subject", true); |
43 | 43 | $content = post_str("content", true); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | function pm_form($replyto, $userid, $error = null) { |
82 | 82 | global $bbcode_html, $bbcode_js; |
83 | 83 | global $g_logged_in_user; |
84 | - page_head(tra("Send private message"),'','','', $bbcode_js); |
|
84 | + page_head(tra("Send private message"), '', '', '', $bbcode_js); |
|
85 | 85 | |
86 | 86 | if (post_str("preview", true) == tra("Preview")) { |
87 | 87 | $content = post_str("content", true); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | function send_pm_notification_email( |
164 | 164 | $logged_in_user, $to_user, $subject, $content |
165 | 165 | ) { |
166 | - $message = " |
|
166 | + $message = " |
|
167 | 167 | You have received a new private message at ".PROJECT.". |
168 | 168 | |
169 | 169 | From: $logged_in_user->name (ID $logged_in_user->id) |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $pm = BoincPrivateMessage::lookup_id($notify->opaque); |
194 | 194 | $from_user = BoincUser::lookup_id($pm->senderid); |
195 | 195 | if (!$pm || !$from_user) return null; |
196 | - return "<a href=pm.php>".tra("Private message%1 from %2, subject:" , "</a>", $from_user->name )." $pm->subject"; |
|
196 | + return "<a href=pm.php>".tra("Private message%1 from %2, subject:", "</a>", $from_user->name)." $pm->subject"; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | function pm_send_msg($from_user, $to_user, $subject, $content, $send_email) { |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | |
258 | 258 | function pm_email_remind($user) { |
259 | 259 | if (!$user->prefs->pm_notification) { |
260 | - return "<br><small>" . |
|
260 | + return "<br><small>". |
|
261 | 261 | tra( |
262 | 262 | "For email notification, %1edit community prefs%2", |
263 | 263 | '<a href="edit_forum_preferences_form.php">', '</a>' |
264 | - ) . |
|
264 | + ). |
|
265 | 265 | "</small>" |
266 | 266 | ; |
267 | 267 | } |
@@ -287,5 +287,5 @@ discard block |
||
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | -$cvs_version_tracker[]="\$Id: pm.inc 14019 2007-11-01 23:04:39Z davea $"; |
|
290 | +$cvs_version_tracker[] = "\$Id: pm.inc 14019 2007-11-01 23:04:39Z davea $"; |
|
291 | 291 | ?> |