-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.php
78 lines (70 loc) · 2 KB
/
router.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
<?php
/**
* auto_reply
*
* @author Jang Joonho <jhjang1005@naver.com>
* @copyright 2016 Jang Joonho
* @license GPLv3
*/
include_once 'lib.php';
include_once 'class/Keyboard.php';
include_once 'class/Message.php';
$uri = isset($_GET['id']) ? $_GET['id'] : '';
$uri = explode('/', $uri);
$method = $_SERVER['REQUEST_METHOD'];
use kakao\Keyboard;
use kakao\Msg;
use kakao\Msg\Message;
if ($uri[0] == '') {
header("Location: ".BASE_URL."login.php");
return;
}
if (!ip_check())
show_error(403, "Not allowed ip!!");
switch ($uri[0]) {
case "keyboard":
if ($method !== "GET")
exit("INVALID METHOD");
header("Content-Type: application/json; charset=utf-8");
echo new Keyboard($DEFAULT_KEYBOARD);
break;
case "message":
if ($method !== "POST")
exit("INVALID METHOD");
header("Content-Type: application/json; charset=utf-8");
$raw_post_data = file_get_contents("php://input");
$post_data = json_decode($raw_post_data);
$content = $post_data->content;
$type = $post_data->type;
pre_message_receive($post_data);
if ($type === "text") {
$file_path = get_message_file($content);
if (file_exists($file_path))
include_once $file_path;
else
undefined_msg_operation($content);
} else {
msg_media_upload();
}
post_message_receive($post_data);
break;
case "friend":
if ($method === "POST") {
$post_data = json_decode(file_get_contents("php://input"));
add_friend($post_data->user_key);
} else if ($method === "DELETE") {
delete_friend($uri[1]);
} else {
exit("INVALID METHOD");
}
break;
case "chat_room":
if ($method === "DELETE") {
delete_chat_room($uri[1]);
} else {
exit("INVALID METHOD");
}
break;
default:
exit("UNKNOWN REQUEST");
}