-
Notifications
You must be signed in to change notification settings - Fork 0
/
elonutils.php
58 lines (50 loc) · 1.54 KB
/
elonutils.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
<?php
include 'passwords.php';
$text = explode(" ", $_POST["text"]);
array_shift($text);
$text = implode(" ", $text);
define("TEXT", $text);
function validateCommandToken() {
if( COMMAND_TOKEN !== $_POST["token"] ) {
returnToSlackChannel("Błąd autoryzacji!");
exit();
}
}
function execQuery($query, $queryArgs = null) {
try {
$db = new PDO('mysql:host='.HOST.';dbname='.DATABASE.';charset=utf8mb4', LOGIN, PASSWORD);
$queryPDO = $db->prepare($query);
$queryPDO->execute($queryArgs);
$queryOut = $queryPDO->fetchAll(PDO::FETCH_ASSOC);
return $queryOut;
} catch (PDOException $e) {
$error = array();
$error["error"] = utf8_encode($e->getMessage());
$error["error_code"] = "0";
echo json_encode($error);
die();
}
}
function returnToSlackChannel($text, $inChannel = false) {
$data = array(
"response_type" => $inChannel ? "in_channel" : "ephemeral",
"channel" => $_POST['channel_id'],
"text" => $text,
"mrkdwn" => true,
);
$json_string = json_encode($data);
header('Content-Type: application/json');
echo $json_string;
}
function execCurl($url, $data = array()) {
$data["token"] = TOKEN;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
return $server_output;
}
?>