From 07a0c485bc5709c0ac254e227642808edbe58b67 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Fri, 21 Aug 2020 23:23:43 +0200 Subject: [PATCH] init --- .gitignore | 2 ++ acapi.php | 68 +++++++++++++++++++++++++++++++++++++ acapi/discord.php | 39 +++++++++++++++++++++ acapi/mcuuid.php | 14 ++++++++ mpt.php | 9 +++++ twitch.php | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 218 insertions(+) create mode 100644 .gitignore create mode 100644 acapi.php create mode 100644 acapi/discord.php create mode 100644 acapi/mcuuid.php create mode 100644 mpt.php create mode 100644 twitch.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc67892 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vars.php +.idea \ No newline at end of file diff --git a/acapi.php b/acapi.php new file mode 100644 index 0000000..e304861 --- /dev/null +++ b/acapi.php @@ -0,0 +1,68 @@ +status = 404; + +if($path[1] == "users") { + $users = array(); + $query = "SELECT * FROM users"; + + if ($_GET["hasmc"] == "true") { + $query = addCondition("mcuuid IS NOT NULL", $query); + } elseif ($_GET["hasmc"] == "false") { + $query = addCondition("mcuuid IS NULL", $query); + } + + $res_users = mysqli_query($accon, $query); + checksql($res_users); + while ($row = mysqli_fetch_array( $res_users, MYSQLI_ASSOC)) { + $user = new stdClass(); + $user->id = $row["discord"]; + if (isset($row["mcuuid"])) { + $minecraft = new stdClass(); + $minecraft->uuid = $row["mcuuid"]; + $user->minecraft = $minecraft; + } + $user->roles = explode(",", $row["roles"]); + if (isset($row["twchannel"])) { + $user->twitchlink = $row["twchannel"]; + } + if (isset($row["ytchannel"])) { + $user->youtubelink = $row["ytchannel"]; + } + array_push($users, $user); + } + mysqli_free_result($res_users); + $obj->users = $users; + $obj->status = 200; + + +} +else { + +} +header('Content-Type: application/json'); +echo json_encode($obj, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); + + + +function addCondition($cond, $query) { + if (strpos($query, "WHERE")) { + $query = $query . " AND " . $cond; + } else { + $query = $query . " WHERE " . $cond; + } + return $query; +} + +function checksql($res) { + global $accon; + global $obj; + if (!$res) { + $obj->status = 500; + $obj->error = mysqli_error($accon); + } +} diff --git a/acapi/discord.php b/acapi/discord.php new file mode 100644 index 0000000..694afc0 --- /dev/null +++ b/acapi/discord.php @@ -0,0 +1,39 @@ +{'user'} != null) { + $obj->status = 200; + $obj->username = $json->{'user'}->{'username'} . "#" . $json->{'user'}->{'discriminator'}; + $obj->accounts = $json->{'connected_accounts'}; + if (is_array($json->{'connected_accounts'})) { + foreach ($json->{'connected_accounts'} as $acc) { + if ($acc->{'type'} == "youtube") { + $obj->ytchannel = "https://www.youtube.com/channel/" . $acc->{'id'}; + } + elseif ($acc->{'type'} == "twitch") { + $obj->twchannel = "https://www.twitch.tv/". $acc->{'name'}; + } + } + } + } else { + $obj->status = 404; + } + echo stripslashes(json_encode($obj)); + diff --git a/acapi/mcuuid.php b/acapi/mcuuid.php new file mode 100644 index 0000000..2c93b4b --- /dev/null +++ b/acapi/mcuuid.php @@ -0,0 +1,14 @@ +{'status'} == "OK") { + $obj->status = 200; + $obj->uuid = $json->{'id'}; + $obj->name = $json->{'name'}; + } else { + $obj->status = 404; + } + echo json_encode($obj); + diff --git a/mpt.php b/mpt.php new file mode 100644 index 0000000..3b016d7 --- /dev/null +++ b/mpt.php @@ -0,0 +1,9 @@ +{'client_id'}; + + $curl_h = curl_init('https://api.twitch.tv/helix/users?login=' . $_GET["user"]); + curl_setopt($curl_h, CURLOPT_HTTPHEADER, + array( + 'Authorization: Bearer ' . $twtoken, + 'Client-ID: ' . $client_id, + ) + ); + curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true); + $json = json_decode(curl_exec($curl_h)); + $userid = $json->{'data'}[0]->{'id'}; + $username = $json->{'data'}[0]->{'display_name'}; + if ($userid != null) { + if ($_SERVER['PATH_INFO'] == "/werfolgt") { + echo "

" . $username . " wird gefolgt von:

"; + getFollows("from"); + } + else if ($_SERVER['PATH_INFO'] == "/wemfolgt") { + echo "

" . $username . " folgt:

"; + getFollows("to"); + } + } else { + echo "Der Nutzer " . $_GET["user"] . " existiert nicht."; + } + } else { + echo "Nutzernamen angeben: ?user=(twitch username) an den Link anhängen"; + } +} else { + echo "Wer folgt...
Wem folgt...
"; +} + + + +function getFollows($dir) { + + $cursor = null; + do { + $json = req($cursor, $dir); + $cursor = $json->{'pagination'}->{'cursor'}; + foreach ($json->{'data'} as $fol) { + echo "" . $fol->{$dir . '_name'} . "
"; + } + + } while($cursor != null); + +} + +function req($cursor, $dir) { + global $client_id; + global $userid; + global $dctoken; + $side = "from"; + if ($dir == "from") + $side = "to"; + + if ($cursor == null) { + $curl_h = curl_init('https://api.twitch.tv/helix/users/follows?' . $side . '_id='. $userid . '&first=100'); + } + else { + $curl_h = curl_init('https://api.twitch.tv/helix/users/follows?' . $side . '_id=' . $userid .'&first=100&after=' . $cursor); + } + curl_setopt($curl_h, CURLOPT_HTTPHEADER, + array( + 'Authorization: Bearer ' . $dctoken, + 'Client-ID: ' . $client_id, + ) + ); + curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true); + return json_decode(curl_exec($curl_h)); +}