public function query($requestId, $limit = 10, $index = 0) { $request = $this->request->get($requestId); $sth = $this->db->prepare('SELECT COUNT(*) FROM request_comments WHERE request = ?'); $sth->bindParam(1, $requestId, PDO::PARAM_INT); $sth->execute(); $arr = $sth->fetch(); $totalCount = $arr[0]; $sth = $this->db->prepare('SELECT request_comments.id AS pid,request_comments.added AS padded, request_comments.text AS pbody, request_comments.editedat, ' . implode(',', User::getDefaultFields()) . ' FROM request_comments LEFT JOIN users ON users.id = request_comments.user WHERE request = ? ORDER BY request_comments.id ASC LIMIT ?, ?'); $sth->bindParam(1, $requestId, PDO::PARAM_INT); $sth->bindParam(2, $index, PDO::PARAM_INT); $sth->bindParam(3, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($post = $sth->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row["id"] = $post["pid"]; $row["added"] = $post["padded"]; $row["body"] = $post["pbody"]; $row["editedat"] = $post["editedat"]; if ($request["user"]["id"] != $this->user->getId() && $this->user->getClass() < User::CLASS_ADMIN) { $row["user"] = null; } else { $row["user"] = $this->user->generateUserObject($post, true, true); $row["user"]["anonymous"] = true; } $result[] = $row; } return array($result, $totalCount); }
public function query($location, $limit = 10, $index = 0) { $sth = $this->db->prepare('SELECT COUNT(*) FROM messages WHERE var = ? AND receiver = ?'); $sth->bindParam(1, $location, PDO::PARAM_INT); $sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT); $sth->execute(); $arr = $sth->fetch(); $totalCount = $arr[0]; $sth = $this->db->prepare('SELECT messages.svarad, messages.subject, messages.last, messages.saved, messages.unread, messages.sender, messages.receiver, messages.id AS pid, messages.added AS padded, messages.msg AS pbody, ' . implode(',', User::getDefaultFields()) . ' FROM messages LEFT JOIN users ON users.id = messages.sender WHERE receiver = ? AND var = ? ORDER BY messages.id DESC LIMIT ?, ?'); $sth->bindValue(1, $this->user->getId(), PDO::PARAM_INT); $sth->bindParam(2, $location, PDO::PARAM_INT); $sth->bindParam(3, $index, PDO::PARAM_INT); $sth->bindParam(4, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($post = $sth->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row["id"] = $post["pid"]; $row["added"] = $post["padded"]; $row["body"] = $post["pbody"]; $row["svarad"] = $post["svarad"]; $row["unread"] = $post["unread"]; $row["receiver"] = $post["receiver"]; $row["sender"] = $post["sender"]; $row["subject"] = $post["subject"]; $row["saved"] = $post["saved"]; $row["last"] = $post["last"]; $row["user"] = $this->user->generateUserObject($post); $result[] = $row; } return array($result, $totalCount); }
public function get($id, $fast = false) { $sth = $this->db->prepare('SELECT ' . implode(',', User::getDefaultFields()) . ', (SELECT 1 FROM torrent_list_bookmarks WHERE torrent_list_bookmarks.torrent_list = torrent_lists.id AND torrent_list_bookmarks.userid = ?) AS bookmarked, torrent_lists.id AS listId, imdbinfo.title AS imdb_title, imdbinfo.year AS imdb_year, imdbinfo.id AS imdbid, imdbinfo.imdbid AS imdbid2, torrent_lists.name, torrent_lists.slug, torrent_lists.description, torrent_lists.votes, torrent_lists.added, torrent_lists.torrents, torrent_lists.type FROM torrent_lists LEFT JOIN users ON torrent_lists.userid = users.id LEFT JOIN imdbinfo ON torrent_lists.imdbid = imdbinfo.id WHERE torrent_lists.id = ?'); $sth->bindValue(1, $this->user->getId(), PDO::PARAM_INT); $sth->bindParam(2, $id, PDO::PARAM_INT); $sth->execute(); $row = $sth->fetch(PDO::FETCH_ASSOC); if (!$row) { throw new Exception(L::get("TORRENT_LIST_NOT_FOUND"), 404); } $arr = array(); $arr["id"] = $row["listId"]; $arr["added"] = $row["added"]; $arr["name"] = $row["name"]; $arr["bookmarked"] = $row["bookmarked"]; $arr["description"] = $row["description"]; $arr["torrents"] = explode(",", $row["torrents"]); $arr["slug"] = $row["slug"]; $arr["imdbid"] = $row["imdbid"]; $arr["imdbid2"] = $row["imdbid2"]; $arr["imdbInfo"] = $row["imdb_title"] . ($row["imdb_year"] > 1900 ? " (" . $row["imdb_year"] . ")" : ""); $arr["type"] = $row["type"]; $arr["votes"] = $row["votes"]; $arr["user"] = $this->user->generateUserObject($row); if (!$fast) { $arr["torrents_data"] = $this->torrents->getByIdList($row["torrents"]); } return $arr; }
public function query($postdata = null) { $sth = $this->db->query('SELECT blocks.id AS block_id, blocks.blockid, blocks.comment, ' . implode(',', User::getDefaultFields()) . ' FROM blocks LEFT JOIN users ON blocks.blockid = users.id WHERE userid = ' . $this->user->getId()); $result = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $friend["user"] = $this->user->generateUserObject($row); $friend["id"] = $row["block_id"]; $friend["comment"] = $row["comment"]; $friend["user"]["last_access"] = $row["last_access"]; array_push($result, $friend); } return $result; }
public function query($postdata = null) { $sth = $this->db->query('SELECT friends.id AS friends_id, friendid, kom, ' . implode(',', User::getDefaultFields()) . ' FROM friends LEFT JOIN users ON friends.friendid = users.id WHERE friends.userid = ' . $this->user->getId() . ' ORDER BY users.username ASC'); $result = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $friend["user"] = $this->user->generateUserObject($row); $friend["id"] = $row["friends_id"]; $friend["comment"] = $row["kom"]; $friend["user"]["last_access"] = $row["last_access"]; array_push($result, $friend); } return $result; }
public function query($postdata) { $limit = (int) $postdata["limit"] ?: 10; $index = (int) $postdata["index"] ?: 0; $sth = $this->db->query('SELECT ' . implode(',', User::getDefaultFields()) . ', torrent_list_bookmarks.torrent_list AS listId, torrent_list_bookmarks.id AS bookmarkId, imdbinfo.genres, imdbinfo.photo, imdbinfo.rating, imdbinfo.imdbid AS imdbid2, torrent_lists.* FROM torrent_list_bookmarks LEFT JOIN torrent_lists ON torrent_list_bookmarks.torrent_list = torrent_lists.id LEFT JOIN users ON torrent_lists.userid = users.id LEFT JOIN imdbinfo ON torrent_lists.imdbid = imdbinfo.id WHERE torrent_list_bookmarks.userid = ' . $this->user->getId() . ' ORDER BY torrent_lists.id DESC'); $result = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $arr = array(); $arr["id"] = $row["listId"]; $arr["bookmarkId"] = $row["bookmarkId"]; $arr["added"] = $row["added"]; $arr["description"] = $row["description"]; $arr["name"] = $row["name"]; $arr["slug"] = $row["slug"]; $arr["imdbid"] = $row["imdbid"]; $arr["votes"] = $row["votes"]; $arr["imdbid2"] = $row["imdbid2"]; $arr["bookmarked"] = $row["bookmarked"] == 1; $arr["user"] = $this->user->generateUserObject($row); array_push($result, $arr); } return $result; }
public function query($postdata) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $limit = (int) $postdata["limit"] ?: 10; $index = (int) $postdata["index"] ?: 0; $sth = $this->db->prepare('SELECT COUNT(*) FROM staffmessages'); $sth->bindParam(1, $location, PDO::PARAM_INT); $sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT); $sth->execute(); $arr = $sth->fetch(); $totalCount = $arr[0]; $sth = $this->db->prepare('SELECT u2.username AS username2, u2.id AS id2, staffmessages.id AS pid, staffmessages.added AS padded, staffmessages.msg AS pbody, staffmessages.sender, staffmessages.fromprivate, staffmessages.subject, staffmessages.answeredby, staffmessages.answered, staffmessages.answer, staffmessages.svaradwhen, ' . implode(',', User::getDefaultFields()) . ' FROM staffmessages LEFT JOIN users ON users.id = staffmessages.sender LEFT JOIN users AS u2 ON u2.id = staffmessages.answeredby ORDER BY staffmessages.id DESC LIMIT ?, ?'); $sth->bindParam(1, $index, PDO::PARAM_INT); $sth->bindParam(2, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($post = $sth->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row["id"] = $post["pid"]; $row["added"] = $post["padded"]; $row["body"] = $post["pbody"]; $row["receiver"] = $post["receiver"]; $row["sender"] = $post["sender"]; $row["subject"] = $post["subject"]; $row["fromprivate"] = $post["fromprivate"]; $row["answer"] = $post["answer"]; $row["answered"] = $post["answered"]; $row["answeredAt"] = $post["svaradwhen"]; $row["answeredBy"] = array("id" => $post["id2"], "username" => $post["username2"]); $row["user"] = array("id" => $post["id"], "username" => $post["username"], "enabled" => $post["enabled"], "added" => $post["added"], "last_access" => $post["last_access"], "bonuspoang" => $post["bonuspoang"], "class" => $this->user->calculateClass($post["class"], $post["doljuploader"]), "coin" => $post["coin"], "crown" => $post["crown"], "gender" => $post["gender"], "donor" => $post["donor"], "leechbonus" => $post["leechbonus"], "parkerad" => $post["parkerad"], "pokal" => $post["pokal"], "title" => $post["title"], "warned" => $post["warned"], "avatar" => $post["avatar"]); $result[] = $row; } return array($result, $totalCount); }
public function getAllPosts($limit = 10, $index = 0) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $sth = $this->db->prepare('SELECT COUNT(*) FROM posts'); $sth->bindParam(1, $topicId, PDO::PARAM_INT); $sth->execute(); $arr = $sth->fetch(); $totalCount = $arr[0]; $sth = $this->db->prepare('SELECT posts.id AS pid, posts.topicid, posts.added AS padded, posts.body AS pbody, posts.editedat, ' . implode(',', User::getDefaultFields()) . ', topics.subject, topics.slug, topics.forumid FROM posts LEFT JOIN users ON users.id = posts.userid LEFT JOIN topics ON topics.id = posts.topicid ORDER BY posts.id DESC LIMIT ?, ?'); $sth->bindParam(1, $index, PDO::PARAM_INT); $sth->bindParam(2, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($post = $sth->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row["id"] = $post["pid"]; $row["topicid"] = $post["topicid"]; $row["added"] = $post["padded"]; $row["body"] = $post["pbody"]; $row["editedat"] = $post["editedat"]; $row["topic"] = array("id" => $post["topicid"], "forumid" => $post["forumid"], "subject" => $post["subject"], "slug" => $post["slug"]); $row["user"] = $this->user->generateUserObject($post); $result[] = $row; } return array($result, $totalCount); }
public function getAllComments($limit = 10, $index = 0) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception('Du saknar rättigheter', 401); } $sth = $this->db->query('SELECT COUNT(*) FROM comments'); $arr = $sth->fetch(); $totalCount = $arr[0]; $sth = $this->db->prepare('SELECT torrents.name, torrents.id AS torrentid, comments.id AS pid,comments.added AS padded, comments.text AS pbody, comments.editedat, ' . implode(',', User::getDefaultFields()) . ' FROM comments LEFT JOIN users ON users.id = comments.user LEFT JOIN torrents ON torrents.id = comments.torrent ORDER BY comments.id DESC LIMIT ?, ?'); $sth->bindParam(1, $index, PDO::PARAM_INT); $sth->bindParam(2, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($post = $sth->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row["id"] = $post["pid"]; $row["added"] = $post["padded"]; $row["body"] = $post["pbody"]; $row["editedat"] = $post["editedat"]; $row["torrent"] = array("id" => $post["torrentid"], "name" => $post["name"]); $row["user"] = $this->user->generateUserObject($post); $result[] = $row; } return array($result, $totalCount); }
public function getSnatchLog($torrentId) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception('Du saknar rättigheter.', 401); } $sth = $this->db->query('SELECT snatch.*, snatch.uploaded AS s_uploaded, snatch.downloaded AS s_downloaded, snatch.id AS snatchId, ' . implode(',', User::getDefaultFields()) . ' FROM snatch LEFT JOIN users ON snatch.userid = users.id WHERE snatch.torrentid = ' . $torrentId . ' ORDER BY klar DESC'); $result = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $snatch = array(); $snatch["id"] = $row["snatchId"]; $snatch["ip"] = $row["ip"]; $snatch["port"] = $row["port"]; $snatch["uploaded"] = $row["s_uploaded"]; $snatch["downloaded"] = $row["s_downloaded"]; $snatch["agent"] = $row["agent"]; $snatch["connectable"] = $row["connectable"]; $snatch["finishedat"] = $row["klar"]; $snatch["lastaction"] = $row["lastaction"]; $snatch["timesStarted"] = $row["timesStarted"]; $snatch["timesCompleted"] = $row["timesCompleted"]; $snatch["timesStopped"] = $row["timesStopped"]; $snatch["timesUpdated"] = $row["timesUpdated"]; $snatch["seedtime"] = $row["seedtime"]; $snatch["user"] = $this->user->generateUserObject($row); array_push($result, $snatch); } return $result; }
public function query($postdata) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception('Du saknar rättigheter.', 401); } $limit = (int) $postdata["limit"] ?: 25; $index = (int) $postdata["index"] ?: 0; $sth = $this->db->query("SELECT COUNT(*) FROM reports"); $res = $sth->fetch(); $totalCount = $res[0]; $sth = $this->db->prepare("SELECT reports.added AS added2, reports.targetid, reports.type, reports.id AS reportid, reports.reason, reports.handledBy, " . implode(',', User::getDefaultFields()) . " FROM reports LEFT JOIN users ON reports.userid = users.id ORDER BY reports.id DESC LIMIT ?, ?"); $sth->bindParam(1, $index, PDO::PARAM_INT); $sth->bindParam(2, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $r = array(); $r["id"] = $row["reportid"]; $r["added"] = $row["added2"]; $r["type"] = $row["type"]; $r["reason"] = $row["reason"]; $r["handledBy"] = $row["handledBy"] == 0 ? null : $this->user->get($row["handledBy"]); $r["user"] = $this->user->generateUserObject($row); switch ($row["type"]) { case 'torrent': try { $r["torrent"] = $this->torrent->get($row["targetid"], true); if ($r["torrent"]["imdbid"]) { $r["relatedTorrents"] = $this->torrent->getRelated($r["torrent"]["imdbid"], $r["torrent"]["id"]); } else { $r["relatedTorrents"] = []; } } catch (Exception $e) { $r["torrent"] = null; $r["deleted"] = true; } break; case 'post': try { $r["post"] = $this->forum->getPost($row["targetid"]); $topic = $this->forum->getTopic($r["post"]["topicid"]); $r["post"]["forumid"] = $topic["forumid"]; try { $r["post"]["user"] = $this->user->get($r["post"]["userid"]); } catch (Exception $e) { $r["post"]["user"] = null; } } catch (Exception $e) { $r["post"] = null; $r["deleted"] = true; } break; case 'pm': try { $r["pm"] = $this->mailbox->get($row["targetid"]); try { $r["pm"]["user"] = $this->user->get($r["pm"]["sender"]); } catch (Exception $e) { $r["pm"]["user"] = null; } } catch (Exception $e) { $r["pm"] = null; $r["deleted"] = true; } break; case 'request': try { $r["request"] = $this->requests->get($row["targetid"]); } catch (Exception $e) { $r["request"] = null; $r["deleted"] = true; } break; case 'comment': try { $r["comment"] = $this->comments->get($row["targetid"]); try { $r["comment"]["user"] = $this->user->get($r["comment"]["user"]); } catch (Exception $e) { $r["comment"]["user"] = null; } } catch (Exception $e) { $r["comment"] = null; $r["deleted"] = true; } break; case 'subtitle': try { $r["subtitle"] = $this->subtitles->get($row["targetid"]); try { $r["subtitle"]["user"] = $this->user->get($r["subtitle"]["userid"]); } catch (Exception $e) { $r["subtitle"]["user"] = null; } } catch (Exception $e) { $r["subtitle"] = null; $r["deleted"] = true; } break; case 'user': try { $r["reportedUser"] = $this->user->get($row["targetid"]); } catch (Exception $e) { $r["reportedUser"] = null; $r["deleted"] = true; } break; } array_push($result, $r); } return array($result, $totalCount); }
public function getVotes($id) { $sth = $this->db->prepare('SELECT ' . implode(',', User::getDefaultFields()) . ', reqvotes.id AS vid, reqvotes.krydda, reqvotes.reqid FROM reqvotes LEFT JOIN users ON reqvotes.userid = users.id WHERE reqvotes.reqid = ?'); $sth->bindParam(1, $id, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $arr = array(); $arr["id"] = $row["vid"]; $arr["reward"] = $row["krydda"]; $arr["user"] = $this->user->generateUserObject($row); array_push($result, $arr); } return $result; }