public function query($postdata) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $limit = (int) $postdata["limit"] ?: 25; $index = (int) $postdata["index"] ?: 0; $search = $postdata["search"] ?: ""; $where = ""; if (strlen($search) > 0) { $searchWords = Helper::searchTextToWordParams($search); $where = "WHERE MATCH (adminlog.search_text) AGAINST (" . $this->db->quote($searchWords) . " IN BOOLEAN MODE)"; } $sth = $this->db->query("SELECT COUNT(*) FROM adminlog " . $where); $res = $sth->fetch(); $totalCount = $res[0]; $sth = $this->db->prepare("SELECT adminlog.added, adminlog.id AS aid, adminlog.txt, users.id, users.username FROM adminlog LEFT JOIN users ON adminlog.userid = users.id " . $where . " ORDER BY adminlog.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["aid"]; $r["added"] = $row["added"]; $r["txt"] = str_replace("{{username}}", "[url=/user/" . $row["id"] . "/" . $row["username"] . "][b]" . $row["username"] . "[/b][/url]", $row["txt"]); array_push($result, $r); } return array($result, $totalCount); }
public function create($postdata = null) { if ($this->user->getClass() < User::CLASS_ACTOR) { throw new Exception(L::get("SEED_REQUEST_CLASS_REQUIREMENT"), 401); } $sth = $this->db->prepare('SELECT * FROM reseed_requests WHERE torrentid = ? AND added > DATE_ADD(NOW(),INTERVAL -1 MONTH)'); $sth->bindParam(1, $postdata["torrentid"], PDO::PARAM_INT); $sth->execute(); if ($sth->rowCount() > 0) { throw new Exception(L::get("SEED_REQUEST_ALREADY_REQUESTED"), 412); } if ($this->user->getBonus() < 5) { throw new Exception(L::get("NOT_ENOUGH_BONUS"), 412); } $torrent = $this->torrent->get($postdata["torrentid"]); if ($torrent["seeders"] > 2) { throw new Exception(L::get("SEED_REQUEST_SEEDERS_REQUIREMENT"), 412); } $this->user->bonusLog(-5, L::get("SEED_REQUEST_BONUS_LOG"), $this->user->getId()); $sth = $this->db->query("SELECT snatch.userid, users.language FROM snatch LEFT JOIN users ON users.id = snatch.userid WHERE torrentid = " . $torrent["id"] . " AND lastaction > DATE_ADD(NOW(),INTERVAL -6 MONTH) AND timesCompleted > 0 AND userid != " . $this->user->getId()); while ($res = $sth->fetch(PDO::FETCH_ASSOC)) { $this->mailbox->sendSystemMessage($res["userid"], L::get("SEED_REQUEST_PM_SUBJECT", null, $res["language"]), L::get("SEED_REQUEST_PM_BODY", [$torrent["id"], $torrent["name"], $torrent["name"]], $res["language"])); } $sth = $this->db->prepare("INSERT INTO reseed_requests(torrentid, userid, added) VALUES(?, ?, NOW())"); $sth->bindParam(1, $torrent["id"], PDO::PARAM_INT); $sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT); $sth->execute(); $this->log->log(1, L::get("SEED_REQUEST_SITE_LOG", [$torrent["id"], $torrent["name"], $torrent["name"]], Config::DEFAULT_LANGUAGE), $this->user->getId(), 1); }
public function query($limit = 25, $index = 0) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $sth = $this->db->query("SELECT COUNT(*) FROM nyregg"); $res = $sth->fetch(); $totalCount = $res[0]; $sth = $this->db->prepare("SELECT nyregg.ip, nyregg.userid, nyregg.datum AS added, nyregg.email, nyregg.hostname, nyregg.log_mail, nyregg.log_ip, nyregg.level, users.warned, users.enabled, users.username FROM nyregg LEFT JOIN users ON nyregg.userid = users.id ORDER BY nyregg.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["added"] = $row["added"]; $r["hostname"] = $row["hostname"]; $r["ip"] = $row["ip"]; $r["email"] = $row["email"]; $r["log_ip"] = $row["log_ip"]; $r["level"] = $row["level"]; $r["log_mail"] = $row["log_mail"]; $r["user"] = array("id" => $row["userid"], "username" => $row["username"], "warned" => $row["warned"], "enabled" => $row["enabled"]); array_push($result, $r); } return array($result, $totalCount); }
public function testGetSetWorks() { $lingua = "l"; L::set($lingua); $check_lingua = L::get(); $this->assertEquals($check_lingua, $lingua); }
public function run() { if ($_SERVER['SERVER_ADDR'] != $_SERVER["REMOTE_ADDR"]) { throw new Exception(L::get("MUST_BE_RUN_BY_SERVER_ERROR"), 401); } /* 1. Save all users current seed amount. Run every hour */ $now = time('Y-m-d H'); $user = $this->db->query('SELECT * FROM users WHERE enabled = "yes"'); while ($u = $user->fetch(PDO::FETCH_ASSOC)) { $res = $this->db->query('SELECT torrents.size, peers.to_go FROM peers JOIN torrents ON peers.torrent = torrents.id WHERE userid = ' . $u["id"] . ' GROUP BY userid, torrent'); $seededAmount = 0; while ($r = $res->fetch(PDO::FETCH_ASSOC)) { $seededAmount += $r["size"] - $r["to_go"]; } $gb = round($seededAmount / 1073741824); if ($gb > 0) { $this->db->query('INSERT INTO leechbonus(userid, datum, gbseed) VALUES(' . $u["id"] . ', ' . $now . ', ' . $gb . ')'); } } /* 2. Erase all logs older than 3 days */ $timeSpan = time() - 259200; // 3 days $this->db->query('DELETE FROM leechbonus WHERE datum < ' . $timeSpan); /* 3. Update all leechbonus percent based on the last 3 days */ $user = $this->db->query('SELECT id, UNIX_TIMESTAMP(added) AS added FROM users'); while ($u = $user->fetch(PDO::FETCH_ASSOC)) { $res = $this->db->query('SELECT SUM(gbseed) AS seedsum FROM leechbonus WHERE userid = ' . $u["id"] . ' '); $res2 = $res->fetch(PDO::FETCH_ASSOC); $leechbonus = $this->leechbonus($res2["seedsum"] / 72); // Split into 24*3 hours $this->db->query('UPDATE users SET leechbonus = ' . $leechbonus . ' WHERE id = ' . $u["id"]); } }
/** * Create the category menu with his childrens * @todo test */ public function create() { // get the categories $categories = $this->r->getRootNodes(); $cat_menu = new Collection(); if ($categories) { foreach ($categories as $category) { // get the childrens $childrens = $category->children()->whereLang(L::get())->count() ? $category->children()->whereLang(L::get())->get(["id", "description", "slug_lang"]) : null; // create the menuitems //@todo handle multiple recursive subitems with a better algorithm $cat_menu_item = new MenuItem($category->description, $category->slug_lang, $this->cat_type, null, $this->getActive($category->slug_lang)); if ($childrens) { foreach ($childrens as $children) { $children_item = new MenuItem($children->description, $children->slug_lang, $this->cat_type, null, $this->getActive($children->slug_lang)); // if has sub-subcategories if ($children->children()->whereLang(L::get())->count()) { $childrens_children = $children->children()->whereLang(L::get())->get(["id", "description", "slug_lang"]); foreach ($childrens_children as $children_children) { $children_item->add(new MenuItem($children_children->description, $children_children->slug_lang, $this->cat_type, null, $this->getActive($children_children->slug_lang))); } } $cat_menu_item->add($children_item); } } // append to original menu $cat_menu->push($cat_menu_item); } } return $cat_menu; }
public function delete($id, $postdata = null) { $bookmark = $this->get($id); if ($bookmark["userid"] != $this->user->getId()) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $this->db->query('DELETE FROM torrent_list_bookmarks WHERE id = ' . $bookmark["id"]); }
public function delete($id) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $sth = $this->db->prepare("DELETE FROM rules WHERE id = ?"); $sth->bindParam(1, $id, PDO::PARAM_INT); $sth->execute(); }
public function checkValidity($secret) { $sth = $this->db->prepare('SELECT * FROM invites WHERE secret = ?'); $sth->bindParam(1, $secret, PDO::PARAM_STR); $sth->execute(); if (!$sth->fetch()) { throw new Exception(L::get("INVITE_NOT_FOUND"), 404); } }
/** * Base url translator * @param $type * @param $name * @param null $params * @return string */ protected function base($type, $name, $params) { $base_url = URL::to('/'); $new_url = "{$base_url}/" . L::get(); $desired_url = URL::$type($name, $params); $last_url = substr($desired_url, strlen($base_url)); $new_url .= $last_url; // baseurl/lingua/parte_finale return $new_url; }
public function get($id) { $sth = $this->db->prepare('SELECT * FROM blocks WHERE id = ?'); $sth->bindParam(1, $id, PDO::PARAM_INT); $sth->execute(); $res = $sth->fetch(PDO::FETCH_ASSOC); if (!$res) { throw new Exception(L::get("BLOCK_NOT_EXIST")); } return $res; }
private function get($id) { $sth = $this->db->prepare("SELECT * FROM nonscene WHERE id = ?"); $sth->bindParam(1, $id, PDO::PARAM_INT); $sth->execute(); $res = $sth->fetch(PDO::FETCH_ASSOC); if (!$res) { throw new Exception(L::get("ITEM_NOT_FOUND"), 404); } return $res; }
public function get($id) { $sth = $this->db->prepare('SELECT * FROM friends WHERE id = ?'); $sth->bindParam(1, $id, PDO::PARAM_INT); $sth->execute(); $res = $sth->fetch(PDO::FETCH_ASSOC); if (!$res) { throw new Exception(L::get("USER_FRIEND_NOT_FOUND"), 404); } return $res; }
public function update($id, $postdata) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $sth = $this->db->prepare("UPDATE donated SET status = ?, sum = ? WHERE id = ?"); $sth->bindParam(1, $postdata["status"], PDO::PARAM_INT); $sth->bindParam(2, $postdata["sum"], PDO::PARAM_INT); $sth->bindParam(3, $id, PDO::PARAM_INT); $sth->execute(); }
public function check() { $date = date("Y-m-d H:i:s", time() - 300); $sth = $this->db->prepare('SELECT COUNT(*) FROM inlogg WHERE ip = ? AND tid > ?'); $sth->bindParam(1, $_SERVER["REMOTE_ADDR"], PDO::PARAM_STR, 15); $sth->bindParam(2, $date, PDO::PARAM_STR); $sth->execute(); $arr = $sth->fetch(); if ($arr[0] > $this->maximumLoginAttempts) { throw new Exception(L::get("LOGIN_ATTEMPTS_EXCEEDED"), 401); } }
public function check($ip) { $date = date("Y-m-d H:i:s", time() - 86400); $sth = $this->db->prepare('SELECT COUNT(*) FROM recoverlog WHERE ip = ? AND date > ?'); $sth->bindParam(1, $ip, PDO::PARAM_STR); $sth->bindParam(2, $date, PDO::PARAM_STR); $sth->execute(); $arr = $sth->fetch(); if ($arr[0] > 5) { throw new Exception(L::get("RECOVERY_LIMIT_EXCEEDED"), 401); } }
private function validatePasskey($passkey) { if (!preg_match("/^[a-z0-9]{32}\$/", $passkey)) { throw new Exception(L::get("TORRENTS_FINDER_INVALID_PASSKEY"), 401); } $sth = $this->db->prepare('SELECT id FROM users WHERE passkey = ? AND enabled = "yes"'); $sth->bindParam(1, $passkey, PDO::PARAM_STR, 32); $sth->execute(); $res = $sth->fetch(PDO::FETCH_ASSOC); if (!$res) { throw new Exception(L::get("USER_NOT_FOUND_ERROR"), 401); } return $res; }
public function create($postData) { if (strlen($postData["body"]) < 2) { throw new Exception(L::get("MESSAGE_TOO_SHORT"), 412); } if (strlen($postData["subject"]) < 3) { $postData["subject"] = substr($postData["body"], 0, 30); } $sth = $this->db->prepare("INSERT INTO staffmessages (sender, added, msg, subject, fromprivate) VALUES(?, NOW(), ?, ?, ?)"); $sth->bindParam(1, $postData["sender"], PDO::PARAM_INT); $sth->bindParam(2, $postData["body"], PDO::PARAM_INT); $sth->bindParam(3, $postData["subject"], PDO::PARAM_STR); $sth->bindParam(4, $postData["fromprivate"], PDO::PARAM_STR); $sth->execute(); }
public function query($postdata) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $limit = (int) $postdata["limit"] ?: 25; $index = (int) $postdata["index"] ?: 0; $sth = $this->db->query("SELECT COUNT(*) FROM sqlerror"); $res = $sth->fetch(); $totalCount = $res[0]; $sth = $this->db->prepare("SELECT sqlerror.datum AS added, sqlerror.msg AS txt, users.id, users.username FROM sqlerror LEFT JOIN users ON sqlerror.uid = users.id ORDER BY sqlerror.id DESC LIMIT ?, ?"); $sth->bindParam(1, $index, PDO::PARAM_INT); $sth->bindParam(2, $limit, PDO::PARAM_INT); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_ASSOC); return array($result, $totalCount); }
public function run($params) { if ($_SERVER['SERVER_ADDR'] != $_SERVER["REMOTE_ADDR"]) { throw new Exception(L::get("MUST_BE_RUN_BY_SERVER_ERROR"), 401); } /* Fetch todays guide data */ $res = $this->db->query('SELECT * FROM tv_kanaler WHERE visible = 1'); $days = 86400 * (int) $params["days"]; $dagensdatum = date('Y-m-d', time() + $days); while ($r = $res->fetch(PDO::FETCH_ASSOC)) { $data = json_decode(file_get_contents('http://json.xmltv.se/' . $r["xmlid"] . '_' . $dagensdatum . '.js.gz'), true); if (!$data) { continue; } $data = $data["jsontv"]; foreach ($data["programme"] as $dat) { $titel = $dat["title"]["sv"]; if (strlen($titel) < 2) { $titel = $dat["title"]["en"]; } $titel = trim($titel); $tid = $dat["start"]; $episod = ''; if ($dat["episodeNum"]) { $episod = $dat["episodeNum"]["onscreen"]; } $desc = $dat["desc"]["sv"]; if (strlen($desc) < 2) { $desc = $dat["desc"]["en"]; } $this->db->query('INSERT INTO tv_program (datum, kanalid, program, program_search, episod, info) VALUES(' . $tid . ', ' . $r["id"] . ', ' . $this->db->quote($titel) . ', ' . $this->db->quote(Helper::searchfield($titel)) . ', ' . $this->db->quote($episod) . ', ' . $this->db->quote($desc) . ')'); } } /* Erase old tv-data to clear up space in database */ $dag = 86400 * 7; // Erase 7 days old $time = time() - $dag; $this->db->query('DELETE FROM tv_program WHERE datum < ' . $time); }
public function upload($file, $post) { if (!preg_match("/\\.(srt|zip|rar)\$/", $file["name"], $match)) { throw new Exception(L::get("SUBTITLE_FILE_EXTENSION_REQUIREMENT"), 412); } if (!is_uploaded_file($file["tmp_name"])) { throw new Exception(L::get("SUBTITLE_FILE_UPLOAD_ERROR")); } if (!filesize($file["tmp_name"])) { throw new Exception(L::get("SUBTITLE_FILE_EMPTY_ERROR")); } $sth = $this->db->prepare("SELECT COUNT(*) FROM subs WHERE filnamn = ?"); $sth->bindParam(1, $file["name"], PDO::PARAM_STR); $sth->execute(); $res = $sth->fetch(); if ($res[0] > 0) { throw new Exception(L::get("SUBTITLE_CONFLICT_ERROR"), 409); } $sth = $this->db->prepare("INSERT INTO subs(torrentid, filnamn, datum, quality, userid) VALUES(?, ?, NOW(), ?, ?)"); $sth->bindParam(1, $post["torrentid"], PDO::PARAM_INT); $sth->bindParam(2, $file["name"], PDO::PARAM_STR); $sth->bindValue(3, $post["quality"] ?: '', PDO::PARAM_STR); $sth->bindValue(4, $this->user->getId(), PDO::PARAM_INT); $sth->execute(); move_uploaded_file($file["tmp_name"], $this->subsDir . $file["name"]); $torrent = $this->torrent->get($post["torrentid"]); $this->db->query("UPDATE torrents SET swesub = 1 WHERE id = " . $torrent["id"]); $this->log->log(1, L::get("SUBTITLE_UPLOAD_SITE_LOG", [$torrent["id"], $torrent["name"], $torrent["name"]], Config::DEFAULT_LANGUAGE), $this->user->getId(), true); // Inform users watching for subtitles $sth = $this->db->prepare("SELECT * FROM bevakasubs WHERE torrentid = ? AND userid != ?"); $sth->bindParam(1, $torrent["id"], PDO::PARAM_INT); $sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT); $sth->execute(); $subject = L::get("SUBTITLE_UPLOAD_PM_SUBJECT", [$torrent["name"]]); $message = L::get("SUBTITLE_UPLOAD_PM_BODY", [$file["name"], $torrent["id"], $torrent["name"], $torrent["name"]]); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $this->mailbox->sendSystemMessage($row["userid"], $subject, $message); } return array("status" => "ok"); }
/** * getDefaultHandlers * * @static * @access private * @return void */ private static function getDefaultHandlers() { static $defaultHandlers; if (!empty($defaultHandlers)) { return $defaultHandlers; } $defaultHandlers = array(301 => function ($url) { header('Location: ' . $url, false, 301); }, 302 => function ($url) { header('Location: ' . $url, false, 302); }, 403 => function ($file = '') { header('HTTP/1.1 403 ACCESS DENIED', true, 403); if (empty($file)) { echo '<h1>403</h1>'; } else { require $file; } }, 404 => function ($file = '') { header('HTTP/1.1 404 Not Found', true, 404); if (empty($file)) { echo '<h1>404</h1>'; } else { require $file; } }, 500 => function ($e, $file = '') { header('HTTP/1.1 500 Internal Server Error', true, 500); if (empty($file)) { echo '<h1>' . $e . '</h1>'; } else { require $file; } }, 'back' => function () { $referer = L::getClient('referer'); if (!empty($referer)) { header('Location: ' . $referer, false, 302); } }, 'json' => function ($data) { header('Content-Type: application/json; charset=UTF-8'); header('Cache-Control: no-cache'); echo json_encode($data); }, 'jsonp' => function ($data, $callback = 'callback') { header('Content-Type: text/javascript; charset=UTF-8'); header('Cache-Control: no-cache'); $callback = L::get($callback, 'jsonp'); echo $callback . '(' . json_encode($data) . ')'; }, 'template' => function ($file, $data, $base = '') { global $template; $template = function ($file, array $custom = NULL) use($data, $base) { global $template; if (is_object($data)) { $vars = get_object_vars($data); if (!empty($custom)) { $vars = array_merge($vars, $custom); } extract($vars); unset($vars); } else { if (!empty($custom)) { $data = array_merge($data, $custom); } extract($data); } require (empty($base) ? '' : $base . '/') . $file; }; header('Content-Type: text/html; charset=UTF-8'); $template($file); }); return $defaultHandlers; }
$bookmarks = new TorrentListBookmarks($db, $user); httpResponse($bookmarks->create($postdata)); break; case validateRoute('DELETE', 'torrent-list-bookmarks/\\d+'): $bookmarks = new TorrentListBookmarks($db, $user); httpResponse($bookmarks->delete((int) $params[1])); break; } httpResponseError(404, 'Resource not found'); } catch (Exception $e) { /* Don't expose SQL errors, log them. */ if ($e instanceof PDOException) { $errorString = $e->getMessage() . $e->getFile() . $e->getLine(); $sqlerrors = new SqlErrors($db, $user); $sqlerrors->create($errorString); httpResponseError(500, L::get("SERVER_ERROR")); } else { httpResponseError($e->getCode(), $e->getMessage()); } } /* Route matcher function */ function validateRoute($method, $pattern) { if ($method == $_SERVER['REQUEST_METHOD'] && preg_match('/^' . str_replace('/', '\\/', $pattern) . '$/', $_GET['url'])) { return true; } return false; } function httpResponse($data = null, $totalCount = -1) { header("Access-Control-Expose-Headers: *");
<div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#"><?php echo L::get("sitename"); ?> </a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li class="divider"></li> <li class="dropdown-header">Nav header</li> <li><a href="#">Separated link</a></li> <li><a href="#">One more separated link</a></li> </ul> </li> </ul>
public function update($requestId, $postId, $postData) { if (strlen($postData) < 2) { throw new Exception(L::get("COMMENT_TOO_SHORT"), 412); } $post = $this->get($postId); if ($post["request"] != $requestId) { throw new Exception(L::get("COMMENT_REQUEST_NOT_MATCHING")); } $sth = $this->db->prepare('UPDATE request_comments SET ori_text = text, text = ?, editedby = ?, editedat = NOW() WHERE id = ?'); $sth->bindParam(1, $postData, PDO::PARAM_STR); $sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT); $sth->bindParam(3, $postId, PDO::PARAM_INT); $sth->execute(); }
public function run() { if ($_SERVER['SERVER_ADDR'] != $_SERVER["REMOTE_ADDR"]) { throw new Exception(L::get("MUST_BE_RUN_BY_SERVER_ERROR"), 401); } /* Delete dead peers and correct all seeders, leechers amounts */ $this->db->query("DELETE FROM peers WHERE last_action < FROM_UNIXTIME(" . $this->peer_deadtime . ")"); $torrents = array(); $res = $this->db->query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($row["seeder"] == "yes") { $key = "seeders"; } else { $key = "leechers"; } $torrents[$row["torrent"]][$key] = $row["c"]; } $fields = explode(":", "leechers:seeders"); $res = $this->db->query("SELECT id, seeders, leechers FROM torrents"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $id = $row["id"]; $torr = array(); if ($torrents[$id]) { $torr = $torrents[$id]; } foreach ($fields as $field) { if (!isset($torr[$field])) { $torr[$field] = 0; } } $update = array(); foreach ($fields as $field) { if ($torr[$field] != $row[$field]) { $update[] = "{$field} = " . $torr[$field]; } } if (count($update)) { $this->db->query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = {$id}"); } } /* Disabled inactive user accounts */ $reason = L::get("AUTO_DISABLED_INACTIVITY"); $dt = time() - $this->max_inactive_user_days * 86400; $maxclass = 7; $res = $this->db->query("SELECT id FROM users WHERE class < {$maxclass} AND last_access < FROM_UNIXTIME({$dt}) AND parkerad = 0 AND enabled = 'yes'"); $text = date("Y-m-d") . " - " . ($reason .= "\n"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE users SET modcomment = concat('{$text}', modcomment), secret = '{$reason}' WHERE id = " . $row["id"]); } $this->db->query("UPDATE users SET enabled = 'no' WHERE class < {$maxclass} AND last_access < FROM_UNIXTIME({$dt}) AND parkerad = 0"); /* Remove unused invit codes */ $maxdt = time() - 86400 * $this->invite_code_expiration_days; $res = $this->db->query("SELECT invites.id, invites.userid, users.username, users.language FROM invites LEFT JOIN users ON invites.userid = users.id WHERE skapad < FROM_UNIXTIME({$maxdt})"); while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("DELETE FROM invites WHERE id = " . $arr["id"]); $this->db->query("UPDATE users SET invites = invites + 1 WHERE id = " . $arr["userid"]); $this->mailbox->sendSystemMessage($arr["userid"], L::get("UNCONFIRMED_INVITE_PM_SUBJECT", null, $arr["language"]), L::get("UNCONFIRMED_INVITE_PM_BODY", null, $arr["language"])); } /* Remove free leech from new torrents */ $dt = time() - $self->max_free_leech_days * 86400; $this->db->query("UPDATE torrents SET frileech = 0 WHERE section = 'new' AND added < FROM_UNIXTIME({$dt}) AND size < 16106127360"); /* Bad ratio warning */ $limit = $limit * 1024 * 1024 * 1024; $siteName = Config::NAME; $min_downloaded = $this->ratio_warning_minimum_gb * 1024 * 1024 * 1024; $warned_until = time() + $this->ratio_warning_length * 86400; $res = $this->db->query("SELECT id, username, language FROM users WHERE class = 0 AND enabled = 'yes' AND downloaded > {$min_downloaded} AND uploaded / downloaded < {$this->ratio_warning_minimum_ratio} AND warned = 'no'"); $modcomment = date("Y-m-d") . " - " . L::get("RATIO_WARNING_LOG") . "\n"; while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE users SET warned = 'yes', warneduntil = FROM_UNIXTIME({$warned_until}), modcomment = concat('{$modcomment}', modcomment) WHERE id = " . $arr["id"]); $this->mailbox->sendSystemMessage($arr["id"], L::get("RATIO_WARNING_PM_SUBJECT", null, $arr["language"]), L::get("RATIO_WARNING_PM_BODY", [$this->ratio_warning_length, $siteName], $arr["language"])); $this->adminlog->create(L::get("RATIO_WARNING_ADMIN_LOG", [$arr["id"], $arr["username"], $arr["username"]])); } /* Ban when warning expired and ratio still bad */ $res = $this->db->query("SELECT id, ip, username, modcomment, language FROM users WHERE class = 0 AND warned = 'yes' AND warneduntil < NOW() AND enabled = 'yes' AND downloaded > {$limit} AND uploaded / downloaded < {$this->ratio_warning_minimum_ratio} AND donor = 'no'"); $modcomment = date("Y-m-d") . " - " . L::get("BAD_RATIO_AUTO_DISABLED") . "\n"; while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE users SET enabled = 'no', modcomment = concat('{$modcomment}', modcomment) WHERE id = " . $arr["id"]); $this->adminlog->create(L::get("BAD_RATIO_AUTO_DISABLED_ADMIN_LOG", [$arr["id"], $arr["username"], $arr["username"]])); } /* Remove expired warnings */ $res = $this->db->query("SELECT id, language FROM users WHERE warned = 'yes' AND warneduntil < NOW() AND warneduntil <> '0000-00-00 00:00:00'") or sqlerr(__FILE__, __LINE__); $modcomment = date("Y-m-d") . " - Varning automatiskt borttagen\n"; while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE users SET warned = 'no', warneduntil = '0000-00-00 00:00:00', modcomment = concat('{$modcomment}', modcomment) WHERE id = " . $arr["id"]); $this->mailbox->sendSystemMessage($arr["id"], L::get("WARNING_REMOVED_PM_SUBJECT", null, $arr["language"]), L::get("WARNING_AUTO_REMOVED_PM_BODY", null, $arr["language"])); } /* Move torrents from New to Archive */ $dt = time() - $this->move_to_archive_after_days * 86400; $res = $this->db->query("SELECT id FROM torrents WHERE added < FROM_UNIXTIME({$dt}) AND section = 'new'"); while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE torrents SET section = 'archive' WHERE id = " . $arr["id"]); $this->db->query("UPDATE peers SET section = 'new' WHERE torrent = " . $arr["id"]); } /* Delete inactive torrents */ $dt = time() - $this->delete_inactive_torrents_after_days * 86400; $res = $this->db->query("SELECT id, name, reqid FROM torrents WHERE last_action < FROM_UNIXTIME({$dt}) AND seeders = 0 AND leechers = 0 AND section = 'archive'"); /* Prevent deletion of "all" torrents if site has been offline or similiar */ if ($res->rowCount() < 100) { while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->torrent->delete($arr["id"], L::get("AUTO_DELETE_INACTIVE_TORRENT", [$this->delete_inactive_torrents_after_days])); } } else { $this->adminlog->create(L::get("AUTO_DELETE_INACTIVE_TORRENTS_PREVENTED", [$res->rowCount()])); } /* Delete new unseeded torrents /* $dt = time() - $this->delete_unseeded_torrents_after_minutes * 60; $dtmax = time() - 86400; $res = $this->db->query("SELECT id, name, reqid FROM torrents WHERE added < FROM_UNIXTIME({$dt}) AND added > FROM_UNIXTIME({$dtmax}) AND seeders = 0 AND leechers > 0 AND reqid = 0"); /* Prevent deletion of lots of torrents if site has been offline or similiar if ($res->rowCount() < 10) { while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->torrent->delete($arr["id"], L::get("AUTO_DELETE_UNSEEDED_TORRENTS", [$this->delete_unseeded_torrents_after_minutes]), 1); } } else { $this->adminlog->create(L::get("AUTO_DELETE_INACTIVE_TORRENTS_PREVENTED", [$res->rowCount()])); } */ /* Delete inactive requests */ $dt = time() - $this->delete_inactive_requests_after_days * 86400; $res = $this->db->query("SELECT id FROM requests WHERE added < FROM_UNIXTIME({$dt}) AND filled = 0"); while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->requests->delete($arr["id"], L::get("REQUEST_NOT_FILLED", [$this->delete_inactive_requests_after_days])); } /* Demote inactive Uploaders */ $dt = time() - $this->demote_uploaders_after_days_inactive * 86400; $res = $this->db->query("SELECT users.id, users.username, users.language FROM `users` WHERE class = 6 AND (SELECT added FROM torrents WHERE owner = users.id ORDER BY `added` DESC LIMIT 1) < FROM_UNIXTIME({$dt})"); $modcomment = date("Y-m-d") . " - " . L::get("UPLOADED_AUTO_DOWNGRADED") . ".\n"; while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE users SET class = 1, modcomment = concat('{$modcomment}', modcomment) WHERE id = " . $arr["id"]); $this->adminlog->create(L::get("UPLOADED_AUTO_DOWNGRADED_ADMIN_LOG", [$arr["id"], $arr["username"], $arr["username"]])); $this->mailbox->sendSystemMessage($arr["id"], ucfirst(L::get("STATUS_DOWNGRADED", null, $arr["language"])), L::get("UPLOADED_AUTO_DOWNGRADED_PM_BODY", [$this->demote_uploaders_after_days_inactive], $arr["language"])); } /* Delete old inbox messages */ $dt = time() - $this->delete_messages_after_days * 86400; $this->db->query("DELETE FROM messages WHERE last < FROM_UNIXTIME({$dt}) AND saved = 0 AND unread = 'no';"); /* Delete old logs */ $dt = time() - $this->delete_logs_after_days * 86400; $this->db->query("DELETE FROM sitelog WHERE added < FROM_UNIXTIME({$dt})"); /* Give gold coin icon to users invited users with high leech bonus */ $res = $this->db->query("SELECT invited_by, username FROM users WHERE leechbonus >= 25 AND invited_by > 1"); while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $who = $this->db->query("SELECT id, coin, language FROM users WHERE id = " . $arr["invited_by"]); while ($arr2 = $who->fetch(PDO::FETCH_ASSOC)) { if ($arr2["coin"] == 0) { $this->db->query("UPDATE users SET coin = 1 WHERE id = " . $arr2["id"]); $this->mailbox->sendSystemMessage($arr2["id"], L::get("GOLD_COIN_PM_SUBJECT", null, $arr2["language"]), L::get("GOLD_COIN_PM_BODY", [$arr["username"]], $arr2["language"])); } } } /* Update which suggestions that are "hot" */ $this->db->query('UPDATE suggestions SET hotpoints = 0'); $res = $this->db->query('SELECT id, suggestid FROM `topics` WHERE suggestid > 0'); $dt = time() - 30 * 86400; while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $re = $this->db->query("SELECT COUNT(*) FROM `posts` WHERE topicid = " . $arr["id"] . " AND added > FROM_UNIXTIME({$dt})"); $re = $re->fetch(); $this->db->query('UPDATE suggestions SET hotpoints = ' . $re[0] . ' WHERE id = ' . $arr["suggestid"]); } /* Update forum posts amount on suggestions */ $res = $this->db->query("SELECT id, topicid FROM suggestions"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $t = $this->db->query("SELECT COUNT(*) FROM posts WHERE topicid = " . $row["topicid"]); $r = $t->fetch(); if ($r[0] > 0) { $this->db->query("UPDATE suggestions SET comments = " . ($r[0] - 1) . " WHERe id = " . $row["id"]); } } foreach ($this->userClassPromotions as $class) { $limit = $class["minimumGigabyteUpload"] * 1024 * 1024 * 1024; $dt = time() - 86400 * $class["minimumMemberDays"]; $message = L::get("AUTO_PROMOTED_PM_BODY", [$class["className"]]); if ($class["perks"]) { $message .= "\n\n" . L::get("AUTO_PROMOTED_PM_PERKS", [$class["className"]]) . "\n\n" . $class["perks"]; } $modcomment = date("Y-m-d") . " - " . L::get("AUTO_PROMOTED_LOG", [$class["className"]]) . "\n"; $res = $this->db->query("SELECT id, class, doljuploader, title, language FROM users WHERE class < " . $class["classId"] . " AND uploaded >= " . $limit . " AND uploaded / downloaded >= " . $class["minratio"] . " AND added < FROM_UNIXTIME({$dt})"); while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->mailbox->sendSystemMessage($arr["id"], L::get("AUTO_PROMOTED_PM_SUBJECT", [$class["className"]], $arr["language"]), $message); $this->db->query("UPDATE users SET class = " . $class["classId"] . ", modcomment = concat('{$modcomment}', modcomment) WHERE id = " . $arr["id"]); if ($class["classId"] >= 2) { $this->db->query('DELETE FROM iplog WHERE userid = ' . $arr["id"]); } } } /* Demote users with bad ratio */ $modcomment = date("Y-m-d") . " - " . L::get("AUTO_DEMOTED_TO_CLASS_1") . "\n"; $res = $this->db->query("SELECT id, class, language FROM users WHERE class > 0 AND class < 4 AND uploaded / downloaded < 0.90"); while ($arr = $res->fetch(PDO::FETCH_ASSOC)) { $this->db->query("UPDATE users SET class = 0, modcomment = concat('{$modcomment}', modcomment) WHERE id = " . $arr["id"]); $this->mailbox->sendSystemMessage($arr["id"], L::get("DEMOTED_TO_CLASS_1_PM_SUBJECT", null, $arr["language"]), L::get("DEMOTED_TO_CLASS_1_PM_BODY", null, $arr["language"])); } /* Update peer record */ $peers = $this->db->query("SELECT COUNT(DISTINCT userid, torrent) FROM peers"); $peers = $peers->fetch(); $peersRecord = $this->db->query("SELECT value_i FROM settings WHERE arg = 'peers_rekord'"); $peersRecord = $peersRecord->fetch(); if ($peers[0] > $peersRecord[0]) { $sth = $this->db->prepare("UPDATE settings SET value_i = ? WHERE arg = 'peers_rekord'"); $sth->bindParam(1, $peers[0], PDO::PARAM_INT); $sth->execute(); } }
public function query($postdata) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 401); } $limit = (int) $postdata["limit"] ?: 25; $index = (int) $postdata["index"] ?: 0; $userid = (int) $postdata["userid"] ?: 0; switch ($postdata["sort"]) { case 'rate': $sortColumn = 'cheatlog.rate'; break; case 'time': $sortColumn = 'cheatlog.time'; break; case 'ip': $sortColumn = 'cheatlog.ip'; break; case 'port': $sortColumn = 'cheatlog.port'; break; case 'connectable': $sortColumn = 'cheatlog.connectable'; break; case 'agent': $sortColumn = 'cheatlog.agent'; break; case 'up': $sortColumn = 'cheatlog.uploaded'; break; case 'down': $sortColumn = 'cheatlog.downloaded'; break; default: $sortColumn = 'cheatlog.id'; } if ($postdata["order"] == "asc") { $order = "ASC"; } else { $order = "DESC"; } $where = ""; if ($userid > 0) { $where = "WHERE userid = " . $userid; } $sth = $this->db->query("SELECT COUNT(*) FROM cheatlog {$where}"); $res = $sth->fetch(); $totalCount = $res[0]; $sth = $this->db->prepare("SELECT cheatlog.*, torrents.name, users.id as uid, users.username, users.warned, users.enabled, users.mbitupp FROM cheatlog LEFT JOIN users ON userid = users.id LEFT JOIN torrents ON cheatlog.torrentid = torrents.id {$where} ORDER BY {$sortColumn} {$order} LIMIT ?, ?"); $sth->bindParam(1, $index, PDO::PARAM_INT); $sth->bindParam(2, $limit, PDO::PARAM_INT); $sth->execute(); $result = array(); while ($r = $sth->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row["user"] = array("id" => $r["uid"], "username" => $r["username"], "warned" => $r["warned"], "enabled" => $r["enabled"], "mbitupp" => $r["mbitupp"]); $row["id"] = $r["id"]; $row["name"] = $r["name"]; $row["torrentid"] = $r["torrentid"]; $row["ip"] = $r["ip"]; $row["port"] = $r["port"]; $row["uploaded"] = $r["uploaded"]; $row["downloaded"] = $r["downloaded"]; $row["rate"] = $r["rate"]; $row["seeder"] = $r["seeder"]; $row["connectable"] = $r["connectable"]; $row["agent"] = $r["agent"]; $row["time"] = $r["time"]; $row["added"] = $r["datum"]; $row["agentdiff"] = $r["agentdiff"]; $row["adsl"] = $r["adsl"]; array_push($result, $row); } return array($result, $totalCount); }
public function updateImdbToplist() { if ($_SERVER['SERVER_ADDR'] != $_SERVER["REMOTE_ADDR"]) { throw new Exception(L::get("MUST_BE_RUN_BY_SERVER_ERROR"), 401); } $data = file_get_contents("http://akas.imdb.com/boxoffice/rentals"); preg_match_all("/\\/title\\/(.*?)\\//", $data, $matches); $array = $matches[1]; unset($array[0]); $this->db->query('DELETE FROM imdbtop20'); foreach ($array as $a) { $this->db->query('INSERT INTO imdbtop20(imdbid) VALUES(' . $this->db->quote($a) . ')'); $this->getDataByImdbId($a); } }
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 getSnatchLog($torrentId) { if ($this->user->getClass() < User::CLASS_ADMIN) { throw new Exception(L::get("PERMISSION_DENIED"), 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; }