-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
63 lines (54 loc) · 1.83 KB
/
function.php
File metadata and controls
63 lines (54 loc) · 1.83 KB
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
<?php
function sendError($txt,$header=["HTTP/1.0 202 Accepted","Content-Type: Application/json"]){
if(is_array($header)){
foreach($header as $head)
header($head);
}else if(!empty($header))
header($header);
header($header);
die(json_encode(['status'=>'failed','message'=>$txt]));
}
function sendResult($data,$header=["HTTP/1.0 200 OK","Content-Type: Application/json"]){
if(is_array($header)){
foreach($header as $head)
header($head);
}else if(!empty($header))
header($header);
die(json_encode(['status'=>'success','data'=>$data]));
}
function showAlert($msg, $type){
?><div class="alert alert-<?=$type?> alert-dismissible fade show" role="alert"><?=$msg?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div><?php
}
function analytics($routeID){
global $_db;
$date = date("Y-m-d");
$hour = date("H")*1;
$where = ['AND'=>['route_id'=>$routeID,'date'=>$date]];
$val = $_db->get('api_stats',"$hour",$where);
if($val=="0"||$val>0){
$_db->update('api_stats',[$hour=>$val+1],$where);
}else{
$_db->insert('api_stats',['route_id'=>$routeID,'date'=>$date,"$hour"=>1]);
}
}
//https://stackoverflow.com/questions/6225351/how-to-minify-php-page-html-output
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'/<!--(.|\s)*?-->/' // Remove HTML comments
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}