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
<?php
function set_upload_service($path){
$config = array();
$config['upload_path'] = $path;
$config['allowed_types'] = '*';
$config['overwrite'] = FALSE;
return $config;
}
function remove_html(&$item, $key){
$item = strip_tags($item);
}
function set_log($class,$method,$postdata,$auth){
$CI = & get_instance();
$url = $class.'/'.$method;
$data = array('url'=>$url,
'parameter'=>$postdata,
'auth'=>$auth,
'time'=>date('Y-m-d h:i:s'));
$CI->db->insert('service_log',$data);
return $CI->db->insert_id();
}
function getSettings(){
$CI = & get_instance();
$settings = $CI->db->get('setting');
return (!empty($settings))?$settings->row_array():'';
}
function pr($val){
echo (is_array($val))?'<pre>':'';
print_r($val);
echo (is_array($val))?'</pre>':'';
exit;
}
function pre($val){
echo (is_array($val))?'<pre>':'';
print_r($val);
echo (is_array($val))?'</pre>':'';
echo '<br>';
}
function encode_param($param = ''){
if(empty($param)){
return;
}
$encode = base64_encode('{*}'.$param.'{*}');
$encode = base64_encode('a%a'.$encode.'a%a');
$encode = base64_encode('b'.$encode.'b');
$encode = base64_encode('Ta7K'.$encode.'eyRq');
return urlencode($encode);
}
function decode_param($param = ''){
if(empty($param)){
return;
}
$decode = urldecode(trim($param));
$decode = trim(base64_decode(urldecode($decode)),'Ta7K');
$decode = trim($decode,'eyRq');
$decode = trim(base64_decode(urldecode($decode)),'b');
$decode = trim(base64_decode(urldecode($decode)),'a%a');
$decode = trim(base64_decode(urldecode($decode)),'{*}');
return $decode;
}
function getLocationLatLng($location = ''){
$settings = getSettings();
if(empty($location) || empty($settings) || !isset($settings['google_api_key']) ||
empty($gKey = $settings['google_api_key'])){
return 0;
}
$thisObj = & get_instance();
$locData = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=".
urlencode($location)."&sensor=false&key=".$gKey);
if(empty($locData))
return 0;
$loc_data = json_decode($locData);
if(empty($loc_data) || !isset($loc_data->status) || $loc_data->status != 'OK')
return 0;
$locArr['lat'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$locArr['lng'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
if(empty($locArr['lat']) || empty($locArr['lng']))
return 0;
return $locArr;
}
function generate_unique() {
$unique = md5(uniqid(time().mt_rand(), true));
return $unique;
}
?>