@@ -11,10 +11,10 @@ |
||
| 11 | 11 | |
| 12 | 12 | spl_autoload_register(function ($class) { |
| 13 | 13 | if (substr($class, 0, 10) !== 'ReCaptcha\\') { |
| 14 | - /* If the class does not lie under the "ReCaptcha" namespace, |
|
| 14 | + /* If the class does not lie under the "ReCaptcha" namespace, |
|
| 15 | 15 | * then we can exit immediately. |
| 16 | 16 | */ |
| 17 | - return; |
|
| 17 | + return; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /* All of the classes have names like "ReCaptcha\Foo", so we need |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | * classes. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -spl_autoload_register(function ($class) { |
|
| 12 | +spl_autoload_register(function($class) { |
|
| 13 | 13 | if (substr($class, 0, 10) !== 'ReCaptcha\\') { |
| 14 | 14 | /* If the class does not lie under the "ReCaptcha" namespace, |
| 15 | 15 | * then we can exit immediately. |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | require_once('../inc/sanitize_html.inc'); |
| 21 | 21 | |
| 22 | -function image_as_bb($text){ |
|
| 22 | +function image_as_bb($text) { |
|
| 23 | 23 | // This function depends on sanitized HTML |
| 24 | 24 | |
| 25 | 25 | $pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si'; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | return $text; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -function link_as_bb($text){ |
|
| 36 | +function link_as_bb($text) { |
|
| 37 | 37 | /* This function depends on sanitized HTML */ |
| 38 | 38 | // Build some regex (should be a *lot* faster) |
| 39 | 39 | $pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1... |
@@ -49,35 +49,35 @@ discard block |
||
| 49 | 49 | return $text; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -function formatting_as_bb($text){ |
|
| 52 | +function formatting_as_bb($text) { |
|
| 53 | 53 | /* This function depends on sanitized HTML */ |
| 54 | - $in[]="<b>";$out[]="[b]"; |
|
| 55 | - $in[]="</b>";$out[]="[/b]"; |
|
| 54 | + $in[] = "<b>"; $out[] = "[b]"; |
|
| 55 | + $in[] = "</b>"; $out[] = "[/b]"; |
|
| 56 | 56 | |
| 57 | - $in[]="<i>";$out[]="[i]"; |
|
| 58 | - $in[]="</i>";$out[]="[/i]"; |
|
| 57 | + $in[] = "<i>"; $out[] = "[i]"; |
|
| 58 | + $in[] = "</i>"; $out[] = "[/i]"; |
|
| 59 | 59 | |
| 60 | - $in[]="<u>";$out[]="[u]"; |
|
| 61 | - $in[]="</u>";$out[]="[/u]"; |
|
| 60 | + $in[] = "<u>"; $out[] = "[u]"; |
|
| 61 | + $in[] = "</u>"; $out[] = "[/u]"; |
|
| 62 | 62 | |
| 63 | - $in[]="<b>";$out[]="[b]"; |
|
| 64 | - $in[]="</b>";$out[]="[/b]"; |
|
| 63 | + $in[] = "<b>"; $out[] = "[b]"; |
|
| 64 | + $in[] = "</b>"; $out[] = "[/b]"; |
|
| 65 | 65 | |
| 66 | - $in[]="<ul>";$out[]="[list]"; |
|
| 67 | - $in[]="</ul>";$out[]="[/list]"; |
|
| 66 | + $in[] = "<ul>"; $out[] = "[list]"; |
|
| 67 | + $in[] = "</ul>"; $out[] = "[/list]"; |
|
| 68 | 68 | |
| 69 | - $in[]="<ol>";$out[]="[list=1]"; |
|
| 70 | - $in[]="</ol>";$out[]="[/list]"; |
|
| 69 | + $in[] = "<ol>"; $out[] = "[list=1]"; |
|
| 70 | + $in[] = "</ol>"; $out[] = "[/list]"; |
|
| 71 | 71 | |
| 72 | - $in[]="<pre>";$out[]="[pre]"; |
|
| 73 | - $in[]="</pre>";$out[]="[/pre]"; |
|
| 72 | + $in[] = "<pre>"; $out[] = "[pre]"; |
|
| 73 | + $in[] = "</pre>"; $out[] = "[/pre]"; |
|
| 74 | 74 | |
| 75 | - $in[]="</br>";$out[]="\n"; |
|
| 76 | - $in[]="<br/>";$out[]="\n"; |
|
| 77 | - $in[]="<br>";$out[]="\n"; |
|
| 78 | - $in[]=">";$out[]=">"; |
|
| 79 | - $in[]="<";$out[]="<"; |
|
| 80 | - $in[]="&";$out[]="&"; |
|
| 75 | + $in[] = "</br>"; $out[] = "\n"; |
|
| 76 | + $in[] = "<br/>"; $out[] = "\n"; |
|
| 77 | + $in[] = "<br>"; $out[] = "\n"; |
|
| 78 | + $in[] = ">"; $out[] = ">"; |
|
| 79 | + $in[] = "<"; $out[] = "<"; |
|
| 80 | + $in[] = "&"; $out[] = "&"; |
|
| 81 | 81 | |
| 82 | 82 | return str_replace($in, $out, $text); |
| 83 | 83 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | require_once('../inc/sanitize_html.inc'); |
| 21 | 21 | |
| 22 | -function image_as_bb($text){ |
|
| 22 | +function image_as_bb($text) { |
|
| 23 | 23 | // This function depends on sanitized HTML |
| 24 | 24 | |
| 25 | 25 | $pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si'; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | return $text; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -function link_as_bb($text){ |
|
| 36 | +function link_as_bb($text) { |
|
| 37 | 37 | /* This function depends on sanitized HTML */ |
| 38 | 38 | // Build some regex (should be a *lot* faster) |
| 39 | 39 | $pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1... |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | return $text; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -function formatting_as_bb($text){ |
|
| 52 | +function formatting_as_bb($text) { |
|
| 53 | 53 | /* This function depends on sanitized HTML */ |
| 54 | 54 | $in[]="<b>";$out[]="[b]"; |
| 55 | 55 | $in[]="</b>";$out[]="[/b]"; |
@@ -358,10 +358,10 @@ |
||
| 358 | 358 | $db = BoincDb::get(); |
| 359 | 359 | return $db->enum('result', 'BoincResult', $where_clause); |
| 360 | 360 | } |
| 361 | - static function enum_fields($fields, $where_clause, $order_clause) { |
|
| 361 | + static function enum_fields($fields, $where_clause, $order_clause) { |
|
| 362 | 362 | $db = BoincDb::get(); |
| 363 | - return $db->enum_fields('result', 'BoincResult', $fields, $where_clause, $order_clause); |
|
| 364 | - } |
|
| 363 | + return $db->enum_fields('result', 'BoincResult', $fields, $where_clause, $order_clause); |
|
| 364 | + } |
|
| 365 | 365 | function update($clause) { |
| 366 | 366 | $db = BoincDb::get(); |
| 367 | 367 | return $db->update($this, 'result', $clause); |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | // close() closes the connection. |
| 45 | 45 | |
| 46 | 46 | class BoincDb { |
| 47 | - static $instance; // a DbConn object, or null |
|
| 48 | - static $dbnum; // which replica we're connected to |
|
| 47 | + static $instance; // a DbConn object, or null |
|
| 48 | + static $dbnum; // which replica we're connected to |
|
| 49 | 49 | |
| 50 | 50 | // connect to DB $dbnum (0, 1, ...) |
| 51 | 51 | // If the requested DB doesn't exist or connection fails, connect to DB 0. |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | self::$instance = null; |
| 57 | 57 | $config = get_config(); |
| 58 | 58 | if ($dbnum) { |
| 59 | - $r = $dbnum==1?'':strval($dbnum); |
|
| 59 | + $r = $dbnum == 1 ? '' : strval($dbnum); |
|
| 60 | 60 | $host = parse_config($config, sprintf('<replica%s_db_host>', $r)); |
| 61 | 61 | $name = parse_config($config, sprintf('<replica%s_db_name>', $r)); |
| 62 | 62 | $user = parse_config($config, sprintf('<replica%s_db_user>', $r)); |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | $db = BoincDb::get(); |
| 202 | 202 | return $db->update($this, 'user', $clause); |
| 203 | 203 | } |
| 204 | - static function enum($where_clause, $order_clause=null) { |
|
| 204 | + static function enum($where_clause, $order_clause = null) { |
|
| 205 | 205 | $db = BoincDb::get(); |
| 206 | 206 | return $db->enum('user', 'BoincUser', $where_clause, $order_clause); |
| 207 | 207 | } |
| 208 | - static function enum_fields($fields, $where_clause, $order_clause=null) { |
|
| 208 | + static function enum_fields($fields, $where_clause, $order_clause = null) { |
|
| 209 | 209 | $db = BoincDb::get(); |
| 210 | 210 | return $db->enum_fields( |
| 211 | 211 | 'user', 'BoincUser', $fields, $where_clause, $order_clause |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $db = BoincDb::get(); |
| 256 | 256 | return $db->update($this, 'team', $clause); |
| 257 | 257 | } |
| 258 | - static function enum($where_clause, $order_clause=null) { |
|
| 258 | + static function enum($where_clause, $order_clause = null) { |
|
| 259 | 259 | $db = BoincDb::get(); |
| 260 | 260 | return $db->enum('team', 'BoincTeam', $where_clause, $order_clause); |
| 261 | 261 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $db = BoincDb::get(); |
| 281 | 281 | return $db->max('team', $field); |
| 282 | 282 | } |
| 283 | - static function enum_fields($fields, $where_clause, $order_clause=null) { |
|
| 283 | + static function enum_fields($fields, $where_clause, $order_clause = null) { |
|
| 284 | 284 | $db = BoincDb::get(); |
| 285 | 285 | return $db->enum_fields( |
| 286 | 286 | 'team', 'BoincTeam', $fields, $where_clause, $order_clause |
@@ -318,11 +318,11 @@ discard block |
||
| 318 | 318 | $db = BoincDb::get(); |
| 319 | 319 | return $db->delete($this, 'host'); |
| 320 | 320 | } |
| 321 | - static function enum($where_clause, $order_clause=null) { |
|
| 321 | + static function enum($where_clause, $order_clause = null) { |
|
| 322 | 322 | $db = BoincDb::get(); |
| 323 | 323 | return $db->enum('host', 'BoincHost', $where_clause, $order_clause); |
| 324 | 324 | } |
| 325 | - static function enum_fields($fields, $where_clause, $order_clause=null) { |
|
| 325 | + static function enum_fields($fields, $where_clause, $order_clause = null) { |
|
| 326 | 326 | $db = BoincDb::get(); |
| 327 | 327 | return $db->enum_fields( |
| 328 | 328 | 'host', 'BoincHost', $fields, $where_clause, $order_clause |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | $db = BoincDb::get(); |
| 445 | 445 | return $db->update($this, 'app', $clause); |
| 446 | 446 | } |
| 447 | - static function sum($field, $clause=null) { |
|
| 447 | + static function sum($field, $clause = null) { |
|
| 448 | 448 | $db = BoincDb::get(); |
| 449 | 449 | return $db->sum('app', $field, $clause); |
| 450 | 450 | } |
@@ -502,11 +502,11 @@ discard block |
||
| 502 | 502 | $db = BoincDb::get(); |
| 503 | 503 | return $db->insert('profile', $clause); |
| 504 | 504 | } |
| 505 | - static function enum($where_clause=null, $order_clause=null) { |
|
| 505 | + static function enum($where_clause = null, $order_clause = null) { |
|
| 506 | 506 | $db = BoincDb::get(); |
| 507 | 507 | return $db->enum('profile', 'BoincProfile', $where_clause, $order_clause); |
| 508 | 508 | } |
| 509 | - static function enum_fields($fields, $where_clause=null, $order_clause=null) { |
|
| 509 | + static function enum_fields($fields, $where_clause = null, $order_clause = null) { |
|
| 510 | 510 | $db = BoincDb::get(); |
| 511 | 511 | return $db->enum_fields('profile', 'BoincProfile', $fields, $where_clause, $order_clause); |
| 512 | 512 | } |
@@ -901,12 +901,12 @@ discard block |
||
| 901 | 901 | return $db->enum('consent', 'BoincConsent', $where_clause); |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - static function insert ($clause) { |
|
| 904 | + static function insert($clause) { |
|
| 905 | 905 | $db = BoincDb::get(); |
| 906 | 906 | return $db->insert('consent', $clause); |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | - static function update ($clause) { |
|
| 909 | + static function update($clause) { |
|
| 910 | 910 | $db = BoincDb::get(); |
| 911 | 911 | return $db->update_aux('consent', $clause); |
| 912 | 912 | } |
@@ -931,17 +931,17 @@ discard block |
||
| 931 | 931 | return $db->lookup('consent_type', 'BoincConsentType', $clause); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | - static function enum($where_clause, $order_clause=null) { |
|
| 934 | + static function enum($where_clause, $order_clause = null) { |
|
| 935 | 935 | $db = BoincDb::get(); |
| 936 | 936 | return $db->enum('consent_type', 'BoincConsentType', $where_clause, $order_clause); |
| 937 | 937 | } |
| 938 | 938 | |
| 939 | - static function insert ($clause) { |
|
| 939 | + static function insert($clause) { |
|
| 940 | 940 | $db = BoincDb::get(); |
| 941 | 941 | return $db->insert('consent_type', $clause); |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | - static function update ($clause) { |
|
| 944 | + static function update($clause) { |
|
| 945 | 945 | $db = BoincDb::get(); |
| 946 | 946 | return $db->update_aux('consent_type', $clause); |
| 947 | 947 | } |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | return $db->lookup('latest_consent', 'BoincLatestConsent', $clause); |
| 968 | 968 | } |
| 969 | 969 | |
| 970 | - static function enum($where_clause, $order_clause=null) { |
|
| 970 | + static function enum($where_clause, $order_clause = null) { |
|
| 971 | 971 | $db = BoincDb::get(); |
| 972 | 972 | return $db->enum('latest_consent', 'BoincLatestConsent', $where_clause, $order_clause); |
| 973 | 973 | } |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | // apply this to any user-supplied strings used in queries |
| 979 | 979 | // |
| 980 | 980 | function boinc_real_escape_string($x) { |
| 981 | - if (version_compare(phpversion(),"4.3.0")>=0) { |
|
| 981 | + if (version_compare(phpversion(), "4.3.0") >= 0) { |
|
| 982 | 982 | return BoincDb::escape_string($x); |
| 983 | 983 | } else { |
| 984 | 984 | $x = str_replace("'", "\'", $x); |
@@ -191,7 +191,7 @@ |
||
| 191 | 191 | $min_credit = parse_config(get_config(), "<profile_min_credit>"); |
| 192 | 192 | if (!$logged_in_user && $min_credit && $user->expavg_credit < $min_credit ) { |
| 193 | 193 | error_page( |
| 194 | - tra("To prevent spam, profiles of users with an average credit of less than %1 are displayed only to logged-in users. We apologize for this inconvenience.", $min_credit) |
|
| 194 | + tra("To prevent spam, profiles of users with an average credit of less than %1 are displayed only to logged-in users. We apologize for this inconvenience.", $min_credit) |
|
| 195 | 195 | ); |
| 196 | 196 | } |
| 197 | 197 | if (is_banished($user)) { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | if (!$user->has_profile) return null; |
| 72 | 72 | $profile = BoincProfile::lookup("userid=$user->id"); |
| 73 | 73 | if (!$profile->has_picture) return null; |
| 74 | - if (profile_screening() && $profile->verification!=1) return null; |
|
| 74 | + if (profile_screening() && $profile->verification != 1) return null; |
|
| 75 | 75 | return profile_thumb_url($user->id); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -125,11 +125,11 @@ discard block |
||
| 125 | 125 | return $image; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - ($origWidth > $origHeight)? $scalar = ($origWidth / $targetWidth) : $scalar = ($origHeight / $targetHeight); |
|
| 128 | + ($origWidth > $origHeight) ? $scalar = ($origWidth/$targetWidth) : $scalar = ($origHeight/$targetHeight); |
|
| 129 | 129 | |
| 130 | 130 | if ($scalar != 0) { |
| 131 | - $destWidth = $origWidth / $scalar; |
|
| 132 | - $destHeight = $origHeight / $scalar; |
|
| 131 | + $destWidth = $origWidth/$scalar; |
|
| 132 | + $destHeight = $origHeight/$scalar; |
|
| 133 | 133 | } else { |
| 134 | 134 | $destWidth = $origWidth; |
| 135 | 135 | $destHeight = $origHeight; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $gd_info = gd_info(); |
| 139 | 139 | $v = $gd_info["GD Version"]; |
| 140 | 140 | $v = explode('.', $v); |
| 141 | - $v = (int)$v[0]; // major version |
|
| 141 | + $v = (int)$v[0]; // major version |
|
| 142 | 142 | if ($v >= 2) { |
| 143 | 143 | // If you are using a modern PHP/GD installation that does |
| 144 | 144 | // 'truecolor' images, this is what's needed. |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $options->htmlitems = false; |
| 182 | 182 | $temp = output_transform($profile->response1, $options); |
| 183 | 183 | $temp = sanitize_tags($temp); |
| 184 | - $description = "(\"" . sub_sentence($temp, ' ', MAX_DESC_LENGTH, true) . "\")"; |
|
| 184 | + $description = "(\"".sub_sentence($temp, ' ', MAX_DESC_LENGTH, true)."\")"; |
|
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | function check_whether_to_show_profile($user, $logged_in_user) { |
| 193 | 193 | $min_credit = parse_config(get_config(), "<profile_min_credit>"); |
| 194 | - if (!$logged_in_user && $min_credit && $user->expavg_credit < $min_credit ) { |
|
| 194 | + if (!$logged_in_user && $min_credit && $user->expavg_credit < $min_credit) { |
|
| 195 | 195 | error_page( |
| 196 | 196 | tra("To prevent spam, profiles of users with an average credit of less than %1 are displayed only to logged-in users. We apologize for this inconvenience.", $min_credit) |
| 197 | 197 | ); |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | // |
| 230 | 230 | $show_picture = $profile->has_picture; |
| 231 | 231 | if (profile_screening()) { |
| 232 | - if (!$screen_mode && !$can_edit && $profile->verification!=1) { |
|
| 232 | + if (!$screen_mode && !$can_edit && $profile->verification != 1) { |
|
| 233 | 233 | $show_picture = false; |
| 234 | 234 | } |
| 235 | 235 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | // yet verified. This will tell them if other users can't view it yet, or |
| 246 | 246 | // if there is a problem with it and they need to replace it. |
| 247 | 247 | // |
| 248 | - if (profile_screening() && $profile->has_picture && $can_edit && $profile->verification!=1) { |
|
| 248 | + if (profile_screening() && $profile->has_picture && $can_edit && $profile->verification != 1) { |
|
| 249 | 249 | row1(offensive_profile_warning($profile->verification)); |
| 250 | 250 | } |
| 251 | 251 | |
@@ -86,14 +86,14 @@ |
||
| 86 | 86 | function _mysql_field_attrs($r, $i) { |
| 87 | 87 | $x = mysqli_fetch_field_direct($r, $i); |
| 88 | 88 | switch ($x->type) { |
| 89 | - case 1: $x->type = 'tinyint'; break; |
|
| 90 | - case 2: $x->type = 'smallint'; break; |
|
| 91 | - case 3: $x->type = 'int'; break; |
|
| 92 | - case 5: $x->type = 'double'; break; |
|
| 93 | - case 7: $x->type = 'timestamp'; break; |
|
| 94 | - case 252: $x->type = 'blob'; break; |
|
| 95 | - case 253: $x->type = 'varchar'; break; |
|
| 96 | - case 254: $x->type = 'char'; break; |
|
| 89 | + case 1: $x->type = 'tinyint'; break; |
|
| 90 | + case 2: $x->type = 'smallint'; break; |
|
| 91 | + case 3: $x->type = 'int'; break; |
|
| 92 | + case 5: $x->type = 'double'; break; |
|
| 93 | + case 7: $x->type = 'timestamp'; break; |
|
| 94 | + case 252: $x->type = 'blob'; break; |
|
| 95 | + case 253: $x->type = 'varchar'; break; |
|
| 96 | + case 254: $x->type = 'char'; break; |
|
| 97 | 97 | } |
| 98 | 98 | return $x; |
| 99 | 99 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | function _mysql_connect($host, $user, $pass, $dbname) { |
| 44 | 44 | global $mysqli; |
| 45 | 45 | $x = explode(":", $host); |
| 46 | - if (sizeof($x)>1) { |
|
| 46 | + if (sizeof($x) > 1) { |
|
| 47 | 47 | $host = $x[0]; |
| 48 | 48 | $port = $x[1]; |
| 49 | 49 | } else { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | -function db_init_aux($try_replica=false) { |
|
| 165 | +function db_init_aux($try_replica = false) { |
|
| 166 | 166 | $config = get_config(); |
| 167 | 167 | $user = parse_config($config, "<db_user>"); |
| 168 | 168 | $pass = parse_config($config, "<db_passwd>"); |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | header("Expires: Thu, 01 Jan 1970 00:00:00 GMT"); |
| 24 | 24 | |
| 25 | 25 | echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" |
| 26 | - . "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" " |
|
| 27 | - . "\"http://www.wapforum.org/DTD/wml_1.2.xml\">" |
|
| 28 | - . "<wml><card id=\"cd1\"><p>"; |
|
| 26 | + . "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" " |
|
| 27 | + . "\"http://www.wapforum.org/DTD/wml_1.2.xml\">" |
|
| 28 | + . "<wml><card id=\"cd1\"><p>"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | function wap_end() { |
@@ -33,6 +33,6 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | function wap_timestamp() { |
| 36 | - return gmdate('j M Y G:i:s', time()) . " UTC"; |
|
| 36 | + return gmdate('j M Y G:i:s', time()) . " UTC"; |
|
| 37 | 37 | } |
| 38 | 38 | ?> |
@@ -33,6 +33,6 @@ |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | function wap_timestamp() { |
| 36 | - return gmdate('j M Y G:i:s', time()) . " UTC"; |
|
| 36 | + return gmdate('j M Y G:i:s', time())." UTC"; |
|
| 37 | 37 | } |
| 38 | 38 | ?> |
@@ -23,10 +23,10 @@ discard block |
||
| 23 | 23 | $gd_info = gd_info(); |
| 24 | 24 | // libgd version numbers seem to be always three numbers |
| 25 | 25 | preg_match('/(\d).(\d).(\d)/', $gd_info['GD Version'], $match); |
| 26 | - $newGD = ($match[1]>=2); |
|
| 26 | + $newGD = ($match[1] >= 2); |
|
| 27 | 27 | |
| 28 | 28 | list($ow, $oh, $from_type) = getimagesize($sourcefile); |
| 29 | - switch($from_type) { |
|
| 29 | + switch ($from_type) { |
|
| 30 | 30 | case 1: // GIF |
| 31 | 31 | $srcImage = imageCreateFromGif($sourcefile); |
| 32 | 32 | break; |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | $tempw = $fw; |
| 42 | 42 | $temph = number_format((($oh*$fw)/$ow), 0); |
| 43 | 43 | |
| 44 | - if($temph < $fh) { |
|
| 44 | + if ($temph < $fh) { |
|
| 45 | 45 | $tempw = number_format((($ow*$fh)/$oh), 0); |
| 46 | 46 | $temph = $fh; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ($newGD){ |
|
| 49 | + if ($newGD) { |
|
| 50 | 50 | $tempImage = imageCreateTrueColor($tempw, $temph); |
| 51 | 51 | // Seems not to work: |
| 52 | 52 | // imageAntiAlias($tempImage, true); |
@@ -58,15 +58,15 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | // Calculate offsets |
| 61 | - if($temph < $fh) { |
|
| 62 | - $offsety = number_format(($temph/2)-($fh/2), 0); |
|
| 61 | + if ($temph < $fh) { |
|
| 62 | + $offsety = number_format(($temph/2) - ($fh/2), 0); |
|
| 63 | 63 | $offsetx = 0; |
| 64 | 64 | } else { |
| 65 | 65 | $offsety = 0; |
| 66 | - $offsetx = number_format(($tempw/2)-($fw/2), 0); |
|
| 66 | + $offsetx = number_format(($tempw/2) - ($fw/2), 0); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ($newGD){ |
|
| 69 | + if ($newGD) { |
|
| 70 | 70 | $destImage = imageCreateTrueColor($fw, $fh); |
| 71 | 71 | // Seems not to work: |
| 72 | 72 | // imageAntiAlias($tempImage, true); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $temph = $fh; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ($newGD){ |
|
| 49 | + if ($newGD) { |
|
| 50 | 50 | $tempImage = imageCreateTrueColor($tempw, $temph); |
| 51 | 51 | // Seems not to work: |
| 52 | 52 | // imageAntiAlias($tempImage, true); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $offsetx = number_format(($tempw/2)-($fw/2), 0); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ($newGD){ |
|
| 69 | + if ($newGD) { |
|
| 70 | 70 | $destImage = imageCreateTrueColor($fw, $fh); |
| 71 | 71 | // Seems not to work: |
| 72 | 72 | // imageAntiAlias($tempImage, true); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | function team_type_name($num) { |
| 39 | 39 | global $team_types; |
| 40 | - if ($num>0 && $num<count($team_types)) { |
|
| 40 | + if ($num > 0 && $num < count($team_types)) { |
|
| 41 | 41 | return $team_types[$num]; |
| 42 | 42 | } |
| 43 | 43 | return "None"; |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | function team_type_num($name) { |
| 55 | 55 | global $team_types; |
| 56 | - for ($i=0; $i<sizeof($team_types); $i++) { |
|
| 56 | + for ($i = 0; $i < sizeof($team_types); $i++) { |
|
| 57 | 57 | if ($name == $team_types[$i]) return $i; |
| 58 | 58 | } |
| 59 | 59 | return 0; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | -function team_type_select($selected_type, $allow_none=false){ |
|
| 62 | +function team_type_select($selected_type, $allow_none = false) { |
|
| 63 | 63 | global $team_types; |
| 64 | 64 | |
| 65 | 65 | $types = $team_types; |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | return 0; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | -function team_type_select($selected_type, $allow_none=false){ |
|
| 62 | +function team_type_select($selected_type, $allow_none=false) { |
|
| 63 | 63 | global $team_types; |
| 64 | 64 | |
| 65 | 65 | $types = $team_types; |
@@ -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 | ?> |
@@ -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); |
@@ -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 | 235 | if ($gi->flags & GEOIP_SHARED_MEMORY) { |
| 236 | - $offset = @shmop_size ($gi->shmid) - 3; |
|
| 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 | } |
@@ -315,9 +315,9 @@ discard block |
||
| 315 | 315 | $gi = new GeoIP; |
| 316 | 316 | $gi->flags = $flags; |
| 317 | 317 | if ($gi->flags & GEOIP_SHARED_MEMORY) { |
| 318 | - $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0); |
|
| 318 | + $gi->shmid = @shmop_open(GEOIP_SHM_KEY, "a", 0, 0); |
|
| 319 | 319 | } else { |
| 320 | - $gi->filehandle = fopen($filename,"rb"); |
|
| 320 | + $gi->filehandle = fopen($filename, "rb"); |
|
| 321 | 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]); |
@@ -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 | } |
@@ -386,21 +386,21 @@ discard block |
||
| 386 | 386 | for ($depth = 31; $depth >= 0; --$depth) { |
| 387 | 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); |
|
| 389 | + 2*$gi->record_length*$offset, |
|
| 390 | + 2*$gi->record_length); |
|
| 391 | 391 | } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { |
| 392 | - $buf = @shmop_read ($gi->shmid, |
|
| 393 | - 2 * $gi->record_length * $offset, |
|
| 394 | - 2 * $gi->record_length ); |
|
| 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 | 406 | if ($ipnum & (1 << $depth)) { |
@@ -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; |
|
| 427 | + $record_pointer = $seek_org + (2*$gi->record_length - 1)*$gi->databaseSegments; |
|
| 428 | 428 | if ($gi->flags & GEOIP_SHARED_MEMORY) { |
| 429 | - $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
|
| 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 | } |