Beispiel #1
0
     $polls->create($postdata);
     httpResponse();
     break;
 case validateRoute('PATCH', 'polls/\\d+'):
     $polls = new Polls($db, $user);
     $polls->update($params[1], $postdata);
     httpResponse();
     break;
 case validateRoute('DELETE', 'polls/\\d+'):
     $polls = new Polls($db, $user);
     $polls->delete($params[1], $postdata);
     httpResponse();
     break;
 case validateRoute('GET', 'torrents'):
     $torrent = new Torrent($db, $user);
     list($torrents, $total) = $torrent->search($_GET);
     if ($_GET["page"]) {
         $user->updateLastTorrentViewAccess($_GET["page"]);
     }
     httpResponse($torrents, $total);
     break;
 case validateRoute('GET', 'torrents/\\d+'):
     $torrent = new Torrent($db);
     $myTorrent = $torrent->get($params[1]);
     httpResponse($myTorrent);
     break;
 case validateRoute('DELETE', 'torrents/\\d+'):
     $log = new Logs($db);
     $mailbox = new Mailbox($db, $user);
     $requests = new Requests($db, $user, $log, $mailbox);
     $torrent = new Torrent($db, $user, $log, null, null, $requests, $mailbox);
Beispiel #2
0
     $polls->create($postdata);
     httpResponse();
     break;
 case validateRoute('PATCH', 'polls/\\d+'):
     $polls = new Polls($db, $user);
     $polls->update($params[1], $postdata);
     httpResponse();
     break;
 case validateRoute('DELETE', 'polls/\\d+'):
     $polls = new Polls($db, $user);
     $polls->delete($params[1], $postdata);
     httpResponse();
     break;
 case validateRoute('GET', 'torrents'):
     $torrent = new Torrent($db, $user);
     list($torrents, $total) = $torrent->search($_GET["categories"], $_GET['section'], $_GET["index"], $_GET["limit"], $_GET["sort"], $_GET["order"], $_GET["searchText"], $_GET["hideOld"], $_GET["p2p"], $_GET["extendedSearch"], $_GET["watchview"]);
     if ($_GET["page"]) {
         $user->updateLastTorrentViewAccess($_GET["page"]);
     }
     httpResponse($torrents, $total);
     break;
 case validateRoute('GET', 'torrents/\\d+'):
     $torrent = new Torrent($db);
     $myTorrent = $torrent->get($params[1]);
     httpResponse($myTorrent);
     break;
 case validateRoute('DELETE', 'torrents/\\d+'):
     $log = new Logs($db);
     $mailbox = new Mailbox($db, $user);
     $requests = new Requests($db, $user, $log, $mailbox);
     $torrent = new Torrent($db, $user, $log, null, null, $requests, $mailbox);
$categories = [Config::$categories["DVDR_PAL"]["id"], Config::$categories["DVDR_CUSTOM"]["id"], Config::$categories["DVDR_TV"]["id"], Config::$categories["MOVIE_720P"]["id"], Config::$categories["MOVIE_1080P"]["id"], Config::$categories["TV_720P"]["id"], Config::$categories["TV_1080P"]["id"], Config::$categories["BLURAY"]["id"], Config::$categories["MOVIE_4K"]["id"]];
if (!preg_match("/^[a-z0-9]{32}\$/", $passkey) || empty($imdbid) && empty($search)) {
    error("Incorrect parameters.");
}
/* Just search for imdbid */
if (empty($search)) {
    $search = $imdbid;
}
$sth = $db->prepare("SELECT id FROM users WHERE passkey = ? AND enabled = 'yes'");
$sth->bindParam(1, $passkey);
$sth->execute();
if (!$sth->fetch()) {
    error("Permission denied.");
}
$torrents = new Torrent($db);
list($result, $total) = $torrents->search(array("searchText" => $search, "categories" => $categories));
$torr = array();
foreach ($result as &$res) {
    $torrent = array("release_name" => $res["name"], "torrent_id" => $res["id"], "details_url" => Config::SITE_URL . "/torrent/" . $res["id"] . "/" . $res["name"], "download_url" => Config::SITE_URL . "/api/v1/torrents/download/" . $res["id"] . "/ " . $passkey, "imdb_id" => $res["imdbid2"], "freeleech" => (bool) $res["frileech"], "type" => typeByCategory($res["category"]), "size" => bitsToMb($res["size"]), "leechers" => $res["leechers"], "seeders" => $res["seeders"]);
    array_push($torr, $torrent);
}
$response = array("results" => $torr, "total_results" => $total);
echo json_encode($response, JSON_NUMERIC_CHECK);
function bitsToMb($bits)
{
    return round($bits / 1024 / 1024);
}
function typeByCategory($category)
{
    switch ($category) {
        case Config::$categories["DVDR_PAL"]["id"]: