-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·74 lines (60 loc) · 2.21 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
<?php
function astrk_json_remote_get($url, $auth) {
return astrk_json_remote_request('GET', $url, $auth, null);
}
function astrk_json_remote_post($url, $auth, $body) {
return astrk_json_remote_request('POST', $url, $auth, $body);
}
function astrk_json_remote_delete($url, $auth, $body) {
return astrk_json_remote_request('DELETE', $url, $auth, $body);
}
function astrk_json_remote_request($method, $url, $auth, $body) {
$headers = array();
if ($method !== 'GET') {
$headers['Content-Type'] = 'application/json';
}
if ($auth && isset($auth['uid']) && isset($auth['token'])) {
$headers['Authorization'] = 'Basic ' . base64_encode($auth['uid'] . ':' . $auth['token']);
}
if ($body) {
$body = wp_json_encode($body);
}
$result = wp_remote_request( $url, array(
'body' => $body,
'data_format' => 'body',
'headers' => $headers,
'method' => $method
)
);
return json_decode($result['body']);
}
function escapeJavaScriptText($string)
{
return str_replace("\n", '\n', str_replace('"', '\"', addcslashes(str_replace("\r", '', (string)$string), "\0..\37'\\")));
}
function astrk_get_login_token($username, $password) {
$auth = array(
"username" => $username,
"password" => $password
);
$r = astrk_json_remote_post("https://api.adservice.com/v2/client/account/logintoken", null, $auth);
if(isset($r->data)) {
return array($r->data->uid, $r->data->login_token);
}
}
function astrk_check_login($options) {
$r = astrk_json_remote_get("https://api.adservice.com/v2/client/account/", $options);
if (isset($r->success) && $r->success) {
return $r;
} else {
return false;
}
}
function astrk_get_campaigns($options) {
$r = astrk_json_remote_get("https://api.adservice.com/v2/client/campaigns/?get_prices=1", $options);
$campaigns = array();
if (isset($r->success) && $r->success) {
return $r;
}
}
?>