-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.php
executable file
·179 lines (142 loc) · 4.46 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
function isEmail($email)
{
return !empty($email) && preg_match(cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z0-9]+$/ui'), $email);
}
function isPasswd($passwd, $size = 5)
{
return (strlen($passwd) >= $size && strlen($passwd) < 255);
}
function isSACSID($secsid){
return preg_match('/^[a-zA-Z0-9-_]+$/', $secsid) AND is_int(stripos($secsid,'AJKiYc')) AND stripos($secsid,'AJKiYc') ==0;
}
function isRegCode($code){
return preg_match('/^[a-zA-Z0-9]+$/', $code) AND strlen($code)==7;
}
function isPasscode($code){
return preg_match('/^[a-zA-Z0-9]+$/', $code);
}
function isGuid($guid) {
return preg_match('/^[0-9a-f.]+$/', $guid);
}
function cleanNonUnicodeSupport($pattern)
{
if (!defined('PREG_BAD_UTF8_OFFSET'))
return $pattern;
return preg_replace('/\\\[px]\{[a-z]\}{1,2}|(\/[a-z]*)u([a-z]*)$/i', "$1$2", $pattern);
}
function getValue($key, $default_value = false)
{
if (!isset($key) || empty($key) || !is_string($key))
return false;
$ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $default_value));
if (is_string($ret) === true)
$ret = urldecode(preg_replace('/((\%5C0+)|(\%00+))/i', '', urlencode($ret)));
return !is_string($ret)? $ret : stripslashes($ret);
}
function isSubmit($submit)
{
return (
isset($_POST[$submit]) || isset($_POST[$submit.'_x']) || isset($_POST[$submit.'_y'])
|| isset($_GET[$submit]) || isset($_GET[$submit.'_x']) || isset($_GET[$submit.'_y'])
);
}
function showErrors($errors){
echo '
<div class="alert alert-danger col-md-6 col-md-offset-3">';
foreach ($errors as $e){
echo '<p class="text-center">'.$e.'</p>';
}
echo '
</div>';
}
function getLevelColor($level){
switch ($level){
case 1:
return '#fece5a';
case 2:
return '#ffa630';
case 3:
return '#ff7315';
case 4:
return '#e40000';
case 5:
return '#fd2992';
case 6:
return '#eb26cd';
case 7:
return '#c124e0';
case 8:
return '#9627f4';
case 'FLIP_CARD':
return '#FFFFFF';
}
}
function getRarityColor($rarity){
switch ($rarity){
case 'COMMON':
return '#84FBBD';
case 'RARE' :
return '#AD8EFF';
case 'VERY_RARE':
return '#F78AF7';
}
}
function getFactionColor($faction){
switch ($faction){
case 'ALIENS':
return '#00F170';
case 'RESISTANCE':
return '#00C2FF';
default:
return '#FFFFFF';
}
}
//
//.aliens { color: rgb(0,241,112); text-shadow: 0 0 2px rgb(0,241,112);}
//.resistance { color:rgb(0,194,255); text-shadow: 0 0 2px rgb(0,194,255);}
function dump($var){
if(DEV_MODE)
var_dump($var);
}
function friendly_name ($item){
switch ($item){
case 'EMITTER_A' : return 'Resonator';
case 'RES_SHIELD' : return 'Portal Shield';
case 'FORCE_AMP' : return 'Force Amp';
case 'HEATSINK' : return 'Heat Sink';
case 'LINK_AMPLIFIER' : return 'Link Amp';
case 'MULTIHACK' : return 'Multi-hack';
case 'TURRET' : return 'Turret';
case 'EMP_BURSTER' : return 'XMP Burster';
case 'POWER_CUBE' : return 'Power Cube';
case 'FLIP_CARD' : return 'Alignment virus';
case 'ADA' : return 'ADA Refractor';
case 'JARVIS' : return 'Jarvis Virus';
default : return $item;
}
}
function getCoordinates($address){
$address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";
$response = file_get_contents($url);
$json = json_decode($response,TRUE); //generate array object from the response from the web
if($json['status'] =='ZERO_RESULTS') return false;
return array('lat' => $json['results'][0]['geometry']['location']['lat'], 'lng' => $json['results'][0]['geometry']['location']['lng']);
}
function hexdecs($hex)
{
// ignore non hex characters
$hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
// converted decimal value:
$dec = hexdec($hex);
// maximum decimal value based on length of hex + 1:
// number of bits in hex number is 8 bits for each 2 hex -> max = 2^n
// use 'pow(2,n)' since '1 << n' is only for integers and therefore limited to integer size.
$max = pow(2, 4 * (strlen($hex) + (strlen($hex) % 2)));
// complement = maximum - converted hex:
$_dec = $max - $dec;
// if dec value is larger than its complement we have a negative value (first bit is set)
return $dec > $_dec ? -$_dec : $dec;
}
?>