예제 #1
0
/**
 * @param $data
 */
function json_response($data)
{
    if (isset($_GET['callback'])) {
        json_p($data);
    }
    exit(json_encode($data));
}
예제 #2
0
<?php

/*
 * Endpoint: /room/image.php
 * Arguments:
 * 		GET action: remove|check_upload|start_upload	Whether the permission is being added or removed to the target.
 * 		GET scope: string	The id of the room in question.
 * 		GET url: (optional)	string	The url of the background to remove.
 * 		GET type:	background|icon
 * 		GET ext:	string	The file extension that's being uploaded.
 * 		GET authkey: (optional)	string	The last known identifying string representing the user uploading the image.
 */
require_once '../autoload.php';
if (!$_GET['action']) {
    json_p(['success' => false, 'reason' => "Expected parameter action (check_upload|start_upload)"]);
}
$action = $_GET['action'];
$dbManager = new DatabaseManager();
switch ($action) {
    case "check_upload":
        json_p($dbManager->checkUpload($_GET['authkey'], "profile"));
        break;
    case "start_upload":
        echo $dbManager->userUploadImage($dbManager->authkeytoid($_GET['authkey']), $_GET['ext']);
        break;
}
예제 #3
0
<?php

require_once '../autoload.php';
$user = Auth::user();
$dbManager = new DatabaseManager();
if ($dbManager->isOwner($user, $_GET['scope'])) {
    $dbManager->deleteRoom($_GET['scope']);
    json_p(["success" => true]);
} else {
    json_p(["success" => false, "reason" => "You are not the owner of this room."]);
}
예제 #4
0
$user = Auth::user();
if (!$user) {
    json_p(['success' => false, 'reason' => 'needs_login']);
}
$playlists = [];
try {
    $gClient = Client::fromUserSession($user)->client();
    $google_youtube = new Google_Service_YouTube($gClient);
    $channel = $google_youtube->channels->listChannels('contentDetails', ['mine' => true]);
    /** @var Google_Service_YouTube_ChannelListResponse $channel */
    $mychannel = $channel->getItems()[0];
    /** @var Google_Service_YouTube_Channel $mychannel */
    $mychanneldetails = $mychannel->getContentDetails();
    /** @var Google_Service_YouTube_ChannelContentDetails $mychanneldetails */
    $relatedplaylists = $mychanneldetails->getRelatedPlaylists();
    /** @var Google_Service_YouTube_ChannelContentDetailsRelatedPlaylists $relatedplaylists */
    $playlists["Liked Videos"] = $relatedplaylists->getLikes();
    $playlists["Favorites"] = $relatedplaylists->getFavorites();
    foreach ($google_youtube->playlists->listPlaylists('snippet', ['mine' => true, 'maxResults' => 50])->getItems() as $item) {
        /** @var Google_Service_YouTube_PlaylistItem $item */
        $snippet = $item->getSnippet();
        $title = $snippet->title;
        $playlists[$title] = $item->id;
    }
    json_p(['success' => true, 'data' => $playlists]);
} catch (Google_Service_Exception $e) {
    $errors = $e->getErrors();
    json_p(['success' => false, 'reason' => isset($errors[0]['reason']) ? $errors[0]['reason'] : 'Unknown', 'message' => isset($errors[0]['message']) ? $errors[0]['message'] : 'Unknown']);
} catch (Exception $e) {
    json_p(['success' => false, 'reason' => 'no_account']);
}
예제 #5
0
<?php

require_once '../autoload.php';
$user = Auth::user();
if (!$user) {
    json_p(['success' => false]);
}
if (!$_GET['subject'] or !(strlen($_GET['subject']) > 0)) {
    json_p(['success' => false]);
}
if (!$_GET['text'] or !(strlen($_GET['text']) > 0)) {
    json_p(['success' => false]);
}
try {
    $mandrill = new Mandrill('{mandrill key}');
    $message = array('text' => $_GET['text'], 'subject' => $_GET['subject'], 'from_email' => '{from email}', 'from_name' => $user->displayName(), 'to' => array(array('email' => '{reply email}', 'name' => '{reply name}', 'type' => 'to')), 'headers' => array('Reply-To' => $user->email()), 'important' => false, 'tags' => array('totem-contact'));
    $async = false;
    $ip_pool = 'Main Pool';
    $result = $mandrill->messages->send($message, $async, $ip_pool);
    json_p(['success' => true]);
} catch (Mandrill_Error $e) {
    json_p(['success' => false]);
}
예제 #6
0
if (!$user) {
    json_p(["success" => false, "This endpoint requires authentication."]);
}
$dbManager = new DatabaseManager();
if (!$dbManager->validateScope($scope)) {
    json_p("Invalid room name.");
}
switch ($level) {
    case "admin":
        if (!$dbManager->isOwner($user, $scope)) {
            json_p(['success' => false, 'reason' => "Only the room owner can appoint or demote admins."]);
        }
        json_p($dbManager->changePermission($type, $username, $scope, DatabaseManager::PERMISSION_LEVEL_ROOM_ADMIN));
        break;
    case "host":
    case "ban":
        if (!$dbManager->isOwnerOrAdmin($user, $scope)) {
            json_p(['success' => false, 'reason' => "You don't have permission to do this."]);
        }
        json_p($dbManager->changePermission($type, $username, $scope, $level === "host" ? DatabaseManager::PERMISSION_LEVEL_ROOM_HOST : DatabaseManager::PERMISSION_LEVEL_ROOM_BANNED));
        break;
    case "queue_ban":
    case "mute":
        if (!$dbManager->isHostOrAbove($user, $scope)) {
            json_p(['success' => false, 'reason' => "You don't have permission to do this."]);
        }
        json_p($dbManager->changePermission($type, $username, $scope, $level === "queue_ban" ? DatabaseManager::PERMISSION_LEVEL_ROOM_QUEUE_BANNED : DatabaseManager::PERMISSION_LEVEL_ROOM_MUTED));
        break;
    default:
        json_p($INVALID);
}
예제 #7
0
 */
require_once '../autoload.php';
$user = Auth::user();
if (!$_GET['scope'] || !$_GET['action']) {
    json_p(['success' => false, 'reason' => "Expected parameter scope (room id), action (remove|check_upload|start_upload)"]);
}
$scope = $_GET['scope'];
$action = $_GET['action'];
if ($action === 'remove' && !$_GET['url']) {
    json_p(['success' => false, 'reason' => "The remove action requires a target url."]);
}
if ($action === 'check_upload' && !($_GET['type'] === 'background' || $_GET['type'] === 'icon')) {
    json_p(['success' => false]);
}
if (!$user && $action === "remove" && !$_GET['server_override']) {
    json_p(["success" => false, "This endpoint requires authentication."]);
}
$dbManager = new DatabaseManager();
if (!$dbManager->validateScope($scope)) {
    json_p(['success' => false, 'reason' => "Invalid room name."]);
}
switch ($action) {
    case "check_upload":
        json_p($dbManager->checkUpload($_GET['authkey'], $scope, $_GET['type']));
        break;
    case "start_upload":
        echo $dbManager->roomUploadImage($scope, $_GET['ext'], $_GET['type']);
        break;
    case "remove":
        json_p($dbManager->removeImage($scope, $_GET['url'], $_GET['type']));
}
예제 #8
0
<?php

require_once '../autoload.php';
$dbManager = new DatabaseManager();
$user = Auth::user();
if (!$user) {
    json_p(['success' => false]);
}
json_p($dbManager->setUserSettings($user, $_GET));
예제 #9
0
<?php

require_once '../autoload.php';
$dbManager = new DatabaseManager();
json_p($dbManager->suggest($_GET['q']));
예제 #10
0
        }
        json_p($dbManager->setRoomPassword($scope, $_GET['password']));
        break;
    case "remove_password":
        if (!$dbManager->isOwner($user, $scope)) {
            json_p(['success' => false, 'reason' => "You must be the room owner to make changes to the room password."]);
        }
        json_p($dbManager->removeRoomPassword($scope));
        break;
    case "transfer_ownership":
        if (!$dbManager->isOwner($user, $scope)) {
            json_p(['success' => false, 'reason' => "You must be the room owner to transfer room ownership."]);
        }
        if ($dbManager->checkUser($target)) {
            $target_obj = $dbManager->getUserByDisplayName($target);
            if ($target_obj) {
                json_p($dbManager->setOwner($target_obj->id(), $scope));
            } else {
                json_p(['success' => false, 'reason' => 'The user you want to transfer to does not exist.']);
            }
        } else {
            json_p(['success' => false, 'reason' => 'Invalid transfer target.']);
        }
        break;
    case "delete":
        if (!$dbManager->isOwner($user, $scope)) {
            json_p(['success' => false, 'reason' => "You must be the room owner to delete the room."]);
        }
        json_p($dbManager->deleteRoom($scope));
        break;
}
예제 #11
0
<?php

require_once '../autoload.php';
$dbManager = new DatabaseManager();
$rooms = $dbManager->getRooms();
json_p($rooms);
<?php

require_once '../autoload.php';
$user = Auth::user();
if (!$user) {
    json_p(["success" => false, "This endpoint requires authentication."]);
}
$dbManager = new DatabaseManager();
json_p(["data" => $dbManager->getRemainingUsernameChanges($user)]);
예제 #13
0
<?php

require_once '../autoload.php';
$dbManager = new DatabaseManager();
$user = Auth::user();
if (!$user) {
    json_p($dbManager->getDefaultSettings());
}
json_p($dbManager->getUserSettings($user));
예제 #14
0
$dbManager = new DatabaseManager();
if (!$dbManager->validateScope($scope)) {
    json_p(['success' => false, 'reason' => "Invalid room name."]);
}
switch ($q) {
    case "blacklist":
    case "whitelist":
        $room = $dbManager->getRoom($scope);
        json_p(['success' => true, 'data' => $room->{$q}]);
        break;
    case "host":
        json_p($dbManager->getUsersMatchingPermissionLevel($scope, DatabaseManager::PERMISSION_LEVEL_ROOM_HOST));
        break;
    case "admin":
        json_p($dbManager->getUsersMatchingPermissionLevel($scope, DatabaseManager::PERMISSION_LEVEL_ROOM_ADMIN));
        break;
    case "mute":
        json_p($dbManager->getUsersMatchingPermissionLevel($scope, DatabaseManager::PERMISSION_LEVEL_ROOM_MUTED));
        break;
    case "ban":
        json_p($dbManager->getUsersMatchingPermissionLevel($scope, DatabaseManager::PERMISSION_LEVEL_ROOM_BANNED));
        break;
    case "queue_ban":
        json_p($dbManager->getUsersMatchingPermissionLevel($scope, DatabaseManager::PERMISSION_LEVEL_ROOM_QUEUE_BANNED));
        break;
    case "backgrounds":
        json_p($dbManager->getRoomBackgrounds($scope));
        break;
    default:
        json_p($ERR_INVALID);
}