This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.php
91 lines (68 loc) · 2.16 KB
/
util.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
<?php
include_once 'conf.php';
$tplMessage = "";
function initLang($languageArray, $language) {
$lang[$language] = $languageArray['default'];
foreach ($languageArray['default'] as $key => $value) {
if(isset($languageArray[$language][$value]) && !empty($languageArray[$language][$value])){
$lang[$value] = $languageArray[$language][$value];
}
}
return $lang;
}
function queryToArray($query) {
$ret = null;
foreach ($query as $id => $value) {
$ret[$id] = array(
'name' => $value['name'],
'time' => $value['time'],
'status' => $value['status']);
}
return $ret;
}
function stDate($time, $format) {
return date($format, $time);
}
function setTplMessage($str){
$GLOBALS['tplMessage'] = $str;
}
function goo_gl($longUrl) {
//http://www.webgalli.com/blog/easily-create-short-urls-with-php-curl-and-goo-gl-or-bit-ly/
//stolen and modified
$config = $GLOBALS['config'];
$googleApiKey = $config['googleApiKey'];
$postData = array();
if (!empty($googleApiKey) && $googleApiKey != '')
$postData['key'] = $googleApiKey;
$postData['longUrl'] = $longUrl;
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
//As the API is on https, set the value for CURLOPT_SSL_VERIFYPEER to false. This will stop cURL from verifying the SSL certificate.
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
$data = json_decode($response);
curl_close($curlObj);
return $data->id;
}
function rotationToInt($value=''){
switch (strtoupper($value)) {
case 'CW':
return '90';
break;
case 'CCW':
return '270';
break;
default:
return '0';
break;
}
}
function isDebug() {
return $GLOBALS["config"]["debug"];
}