-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
64 lines (47 loc) · 1.53 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
<?php
function isMultiArray($multiarray) {
if (is_array($multiarray)) { // confirms array
foreach ($multiarray as $array) { // goes one level deeper
if (is_array($array)) { // is subarray an array
return true; // return will stop function
} // end 2nd check
} // end loop
} // end 1st check
return false; // not a multiarray if this far
}
function sqThm($src,$dest,$size=220){
list($w,$h) = getimagesize($src);
if($w > $h){
exec("convert ".$src." -resize x".$size." -quality 100 ".$dest);
}else{
exec("convert ".$src." -resize ".$size." -quality 100 ".$dest);
}
exec("convert ".$dest." -gravity Center -crop ".$size."x".$size."+0+0 ".$dest);
}
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
function check_bans() {
global $db;
$crit = array('ip' => $_SERVER['REMOTE_ADDR']);
$count = $db->count('ip',$crit);
return($count);
}
?>