Esempio n. 1
0
 public function create($text)
 {
     $searchText = Helper::searchfield($text);
     $sth = $this->db->prepare('INSERT INTO adminlog (added, txt, userid, search_text) VALUES (NOW(), ?, ?, ?)');
     $sth->bindParam(1, $text, PDO::PARAM_STR);
     $sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT);
     $sth->bindParam(3, $searchText, PDO::PARAM_STR);
     $sth->execute();
 }
Esempio n. 2
0
 public function log($type, $txt, $userid, $anonym = 0)
 {
     $searchText = Helper::searchfield($txt);
     $sth = $this->db->prepare('INSERT INTO sitelog (typ, added, txt, search_text, userid, anonymous) VALUES (?, NOW(), ?, ?, ?, ?)');
     $sth->bindParam(1, $type, PDO::PARAM_INT);
     $sth->bindParam(2, $txt, PDO::PARAM_STR);
     $sth->bindParam(3, $searchText, PDO::PARAM_STR);
     $sth->bindParam(4, $userid, PDO::PARAM_INT);
     $sth->bindParam(5, $anonym, PDO::PARAM_INT);
     $sth->execute();
 }
Esempio n. 3
0
 public static function searchTextToWordParams($searchText)
 {
     $search = Helper::searchfield($searchText);
     $arr = explode(" ", $search);
     $searchWords = '';
     foreach ($arr as $word) {
         if (strlen($word) > 1) {
             $searchWords .= "+" . $word . "* ";
         } else {
             if (strlen($word) == 1) {
                 $searchWords .= "+" . $word . " ";
             }
         }
     }
     return $searchWords;
 }
Esempio n. 4
0
 public function guessChannelAndProgram($name)
 {
     if (($pos = stripos($name, ".SWE")) > 4) {
         $name = substr($name, 0, $pos);
     }
     $name = Helper::searchfield($name);
     preg_match("/E([0-9]+)/i", $name, $match);
     $releaseEpisodeNumber = $match[1];
     $hits = array();
     $sth = $this->db->prepare("SELECT tv_program.id AS programid, priority, kanalid, episod, FROM_UNIXTIME(datum), MATCH(program_search) AGAINST(?) AS relevance FROM `tv_program` LEFT JOIN tv_kanaler ON tv_program.kanalid = tv_kanaler.id  WHERE MATCH(program_search) AGAINST(?) AND FROM_UNIXTIME(datum) > (NOW() - INTERVAL 4 DAY) ORDER BY relevance DESC, datum DESC, tv_kanaler.priority ASC LIMIT 10");
     $sth->bindParam(1, $name, PDO::PARAM_STR);
     $sth->bindParam(2, $name, PDO::PARAM_STR);
     $sth->execute();
     $relevance = -1;
     while ($r = $sth->fetch(PDO::FETCH_ASSOC)) {
         if ($relevance == -1) {
             $relevance = $r["relevance"];
         }
         if ($relevance !== $r["relevance"]) {
             break;
         }
         preg_match("/Del ([0-9]+) /i", $r["episod"], $match);
         $r["episodeNumber"] = $match[1];
         $hits[] = $r;
     }
     if (count($hits) == 0) {
         return false;
     }
     $hits = array_reverse($hits);
     $chosenEpisode = $hits[0];
     if (is_numeric($releaseEpisodeNumber)) {
         foreach ($hits as $h) {
             if ($h["episodeNumber"] == $releaseEpisodeNumber) {
                 $chosenEpisode = $h;
                 break;
             }
         }
     }
     return array($chosenEpisode["kanalid"], $chosenEpisode["programid"]);
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public function run()
 {
     if ($_SERVER['SERVER_ADDR'] != $_SERVER["REMOTE_ADDR"]) {
         throw new Exception("Must be run by server.", 401);
     }
     /* Spara ner dagens tablåer */
     $res = $this->db->query('SELECT * FROM tv_kanaler WHERE visible = 1');
     $dagensdatum = date('Y-m-d', time());
     // hämta dagens tablåer
     while ($r = $res->fetch(PDO::FETCH_ASSOC)) {
         $data = json_decode(gzdecode(file_get_contents('http://xmltv.tvtab.la/json/' . $r["xmlid"] . '_' . $dagensdatum . '.js.gz')), true);
         $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) . ')');
         }
     }
     /* Radera gamla tv-data så det inte blir för mycket i databasen */
     $dag = 86400 * 7;
     // Radera 7 dagar gamla
     $veckagammal = time() - $dag;
     $this->db->query('DELETE FROM tv_program WHERE datum < ' . $veckagammal);
 }
Esempio n. 7
0
 public function upload($uploaded_file, $post)
 {
     if ($this->user->isUploadBanned()) {
         throw new Exception("Du är bannad ifrån att kunna ladda upp torrents.", 401);
     }
     $max_torrent_size = 10000000;
     ini_set("upload_max_filesize", $max_torrent_size);
     include 'benc.php';
     if ($post["category"] < 1 || $post["category"] > 12) {
         throw new Exception('Ogiltig kategori.');
     }
     if (!preg_match("/^\\d+\$/", $post["reqid"])) {
         throw new Exception('Ogiltig sektion.');
     }
     if (!preg_match("/\\.torrent\$/", $uploaded_file["name"], $match)) {
         throw new Exception('Ingen torrent-fil.');
     }
     if (!is_uploaded_file($uploaded_file["tmp_name"])) {
         throw new Exception('Filen kunde inte laddas upp.');
     }
     if (!filesize($uploaded_file["tmp_name"])) {
         throw new Exception('Filen verkar vara tom.');
     }
     if ($post["category"] == 8 && $post["reqid"] == 0 && ($post["channel"] == 0 || $post["program"] == 0)) {
         throw new Exception('Du måste välja kanal och program för ny Svensk TV.');
     }
     if ($post["reqid"] > 2) {
         $request = $this->requests->get($post["reqid"]);
         if ($this->user->getId() == $request["user"]["id"]) {
             throw new Exception("Du får inte fylla din egna request", 400);
         }
         if ($request["filled"] == 1) {
             throw new Exception("Requesten är redan fylld.", 400);
         }
     }
     $name = preg_replace("/\\.torrent\$/", '', $uploaded_file["name"]);
     $category = $post["category"];
     $reqid = $post["reqid"];
     $anonymousUpload = $post["anonymousUpload"];
     $nfo = $post["nfo"];
     $imdbId = $post["imdbId"];
     $p2p = $post["p2p"];
     $freeleech = 0;
     $stereoscopic = 0;
     $swesub = 0;
     if (in_array($category, array(1, 2, 3, 10, 11))) {
         $swesub = 1;
     }
     if ($post["swesub"] == 1 && in_array($category, array(4, 5, 6, 7))) {
         $swesub = 1;
     }
     /* SWE-TV */
     $tvProgramId = $post["program"] ?: 0;
     $tvChannel = $post["channel"] ?: 0;
     $tvProgram = '';
     $tvEpisode = '';
     $tvInfo = '';
     $tvTime = 0;
     if ($category == 8 && $tvProgramId > 0 && $tvChannel > 0) {
         /* Manual entered program */
         if ($tvProgramId == 1) {
             $tvProgram = $post["programTitle"];
             $tvTime = strtotime($post["programDate"]);
             if (strlen($tvProgram) < 2) {
                 throw new Exception('Programnamnet för kort.');
             }
             $tvProgramId = 2;
         } else {
             $sweTv = $this->sweTv->getProgram($tvProgramId);
             if (!$sweTv) {
                 throw new Exception('Ogiltigt TV-program valt.');
             }
             $tvProgram = $sweTv["program"];
             $tvEpisode = $sweTv["episod"];
             $tvInfo = $sweTv["info"];
             $tvTime = $sweTv["datum"];
         }
     }
     if ($this->user->getClass() < User::CLASS_UPLOADER && $reqid == 0) {
         throw new Exception('Bara uppladdare kan ladda upp på nytt.');
     }
     $sth = $this->db->prepare("SELECT COUNT(*) FROM torrents WHERE name = ?");
     $sth->execute(array($name));
     $arr = $sth->fetch();
     if ($arr[0] == 1) {
         throw new Exception('Dublett. Releasen finns redan på sidan.');
     }
     $sth = $this->db->prepare("SELECT COUNT(*) FROM packfiles WHERE filename = ?");
     $sth->execute(array($name));
     $arr = $sth->fetch();
     if ($arr[0] == 1) {
         throw new Exception('Dublett. Releasen finns redan inuti ett pack.');
     }
     $sth = $this->db->prepare("SELECT comment FROM banned WHERE namn = ?");
     $sth->execute(array($name));
     while ($arr = $sth->fetch(PDO::FETCH_ASSOC)) {
         throw new Exception('Releasen är bannad med anledning: ' . $arr["comment"]);
     }
     $dict = bdec_file($uploaded_file["tmp_name"], $max_torrent_size);
     if (!isset($dict)) {
         throw new Exception('Fel på .torrent-filen.');
     }
     function dict_check($d, $s)
     {
         if ($d["type"] != "dictionary") {
             throw new Exception("Filen är inte en torrent-fil");
         }
         $a = explode(":", $s);
         $dd = $d["value"];
         $ret = array();
         foreach ($a as $k) {
             unset($t);
             if (preg_match('/^(.*)\\((.*)\\)$/', $k, $m)) {
                 $k = $m[1];
                 $t = $m[2];
             }
             if (isset($t)) {
                 if ($dd[$k]["type"] != $t) {
                     throw new Exception("Torrent-filen saknar troligtvis announce/tracker url.");
                 }
                 $ret[] = $dd[$k]["value"];
             } else {
                 $ret[] = $dd[$k];
             }
         }
         return $ret;
     }
     function dict_get($d, $k, $t)
     {
         if ($d["type"] != "dictionary") {
             throw new Exception("Fel på torrent-fil.");
         }
         $dd = $d["value"];
         if (!isset($dd[$k])) {
             return;
         }
         $v = $dd[$k];
         if ($v["type"] != $t) {
             throw new Exception("Fel på torrent-fil.");
         }
         return $v["value"];
     }
     list($ann, $info) = dict_check($dict, "announce(string):info");
     list($dname, $plen, $pieces) = dict_check($info, "name(string):piece length(integer):pieces(string)");
     if (strlen($pieces) % 20 != 0) {
         throw new Exception("Fel på torrent-fil.");
     }
     $filelist = array();
     $totallen = dict_get($info, "length", "integer");
     if (isset($totallen)) {
         $filelist[] = array($dname, $totallen);
         $type = "single";
     } else {
         $flist = dict_get($info, "files", "list");
         if (!isset($flist)) {
             throw new Exception("Saknar både längd och filer.");
         }
         if (!count($flist)) {
             throw new Exception("Torrent saknar filer.");
         }
         $totallen = 0;
         foreach ($flist as $fn) {
             list($ll, $ff) = dict_check($fn, "length(integer):path(list)");
             $totallen += $ll;
             $ffa = array();
             foreach ($ff as $ffe) {
                 if ($ffe["type"] != "string") {
                     throw new Exception("Fel på filnamn.");
                 }
                 $ffa[] = $ffe["value"];
             }
             if (!count($ffa)) {
                 throw new Exception("Fel på filnamn.");
             }
             $ffe = implode("/", $ffa);
             $filelist[] = array($ffe, $ll);
         }
         $type = "multi";
     }
     $foundBanned = array();
     $bannedfiles = array(".DS_Store", "._.DS_Store", "ufxpcrc.log", "Thumbs.db", ".checked", ".message", "desktop.ini", "Default.PLS", ".url", ".html", "imdb.nfo", ".missing", "-missing", ".torrent");
     foreach ($filelist as $file) {
         foreach ($bannedfiles as $bfile) {
             if (preg_match("/" . $bfile . "\$/", $file[0])) {
                 $foundBanned[] = $file[0];
             }
         }
     }
     if (count($foundBanned) > 0) {
         $files = '';
         foreach ($foundBanned as $f) {
             $files .= '\'' . $f . '\', ';
         }
         $this->adminlog->create("[b]" . $this->user->getUsername() . "[/b] försökte ladda upp [i]" . $name . "[/i] innehållandes otllåtna skräpfil(er): [b]" . $files . "[/b].");
         throw new Exception("Din torrent innehåller följande otillåtna skräpfiler: [b]" . $files);
     }
     if (($txt = $this->detectMissingFiles($filelist)) != false) {
         $this->adminlog->create('[b]' . $this->user->getUsername() . '[/b] försökte ladda upp [i]' . $name . '[/i] men: ' . $txt);
         throw new Exception("Fattas filer i torrent: " . $txt);
     }
     $info['value']['source']['type'] = "string";
     $info['value']['source']['value'] = Helper::$siteName;
     $info['value']['source']['strlen'] = strlen($info['value']['source']['value']);
     $info['value']['private']['type'] = "integer";
     $info['value']['private']['value'] = 1;
     $dict['value']['info'] = $info;
     $dict = benc($dict);
     $dict = bdec($dict);
     list($ann, $info) = dict_check($dict, "announce(string):info");
     $infohash = bin2hex(pack("H*", sha1($info["string"])));
     $sth = $this->db->prepare("SELECT COUNT(*) FROM torrents WHERE info_hash = ?");
     $sth->bindParam(1, $infohash, PDO::PARAM_STR);
     $sth->execute();
     $arr = $sth->fetch();
     if ($arr[0] == 1) {
         throw new Exception('Dublett. Releasen finns redan på sidan.');
     }
     $pre = Helper::preCheck($name);
     if (!$pre) {
         $pre = 0;
     } else {
         if ($pre > time()) {
             $pre = time() - 100;
         }
         /* Use pre-time to determine New or Archive section */
         if ($reqid == 1 && $pre > time() - 604800) {
             $reqid = 0;
             $this->adminlog->create("[b]" . $this->user->getUsername() . "[/b] laddade upp [i]'" . $name . "'[/i] på Arkiv men PRE-tid säger under 7 dagar, auto-flyttar till Nytt.");
         } else {
             if ($reqid == 0 && time() - $pre > 604800) {
                 $this->adminlog->create("[b]" . $this->user->getUsername() . "[/b] laddade upp [i]'" . $name . "'[/i] på Nytt men PRE-tid säger över 7 dagar, auto-flyttar till Arkiv.");
                 $reqid = 1;
             }
         }
     }
     if (stripos($name, '.3d.') > -1 || stripos($name, '.hsbs.') > -1 || stripos($name, '-sbs.') > -1) {
         $stereoscopic = 1;
     }
     /* Presume p2p release when not rar archive */
     if (in_array($category, [1, 2, 3, 4, 5, 6, 7]) && count($filelist) < 10) {
         $p2p = 1;
     }
     /* Block or p2p-mark non-scene groups */
     $sth = $this->db->prepare("SELECT * FROM nonscene WHERE groupname = ?");
     $sth->bindParam(1, $this->matchGroupName($name), PDO::PARAM_STR);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     if ($res) {
         if ($res["whitelist"] == 0) {
             throw new Exception("Release-gruppen är bannad med anledningen: " . $res["comment"], 401);
         } else {
             $p2p = 1;
         }
     }
     /* Torrents sized 15GB+ should be free leech */
     if ($totallen > 16106127360) {
         $freeleech = 1;
     }
     /* Detect if torrent is a "pack" with releases inside */
     $packFolders = array();
     foreach ($filelist as $file) {
         preg_match('/^(.*?)\\//', $file[0], $match);
         if (strlen($match[1]) > 6) {
             array_push($packFolders, $match[1]);
         }
     }
     $packFolders = array_unique($packFolders);
     if (count($packFolders) > 1) {
         $pack = 1;
     } else {
         $pack = 0;
     }
     if ($imdbId) {
         $imdbInfo = $this->movieData->getData($imdbId);
         if ($imdbInfo["releaseNameStart"] == "") {
             $this->movieData->updateReleaseNameStart($name, $imdbId);
         }
     } else {
         $imdbInfo = $this->movieData->findImdbInfoByReleaseName($name);
         if ($imdbInfo) {
             $imdbId = $imdbInfo["id"];
         }
     }
     $fname = $name . ".torrent";
     $searchText = Helper::searchfield("{$name} {$imdbInfo['genres']} {$imdbInfo['imdbid']} " . implode(" ", $packFolders));
     $searchText2 = Helper::searchfield("{$imdbInfo['director']} {$imdbInfo['writer']} {$imdbInfo['cast']}");
     $sth = $this->db->prepare("INSERT INTO torrents (name, filename, search_text, search_text2, owner, visible, info_hash, size, numfiles, type, ano_owner, descr, category, added, last_action,  frileech, tv_kanalid, tv_program, tv_episode, tv_info, imdbid, tv_klockslag, tv_programid, reqid, pre, p2p, 3d, pack, swesub) VALUES (:name, :filename, :searchText, :searchText2, :owner, 'no', :infoHash, :size, :numfiles, :type, :anoymous, :descr, :category, NOW(), NOW(), :freeLeech, :tvChannel, :tvProgram, :tvEpisode, :tvInfo, :imdbid, :tvTime, :tvProgramId, :reqid, :pre, :p2p, :3d, :pack, :swesub)");
     $sth->bindParam(":name", $name, PDO::PARAM_STR);
     $sth->bindParam(":filename", $fname, PDO::PARAM_STR);
     $sth->bindParam(":searchText", $searchText, PDO::PARAM_STR);
     $sth->bindParam(":searchText2", $searchText2, PDO::PARAM_STR);
     $sth->bindParam(":owner", $this->user->getId(), PDO::PARAM_INT);
     $sth->bindParam(":infoHash", $infohash, PDO::PARAM_STR);
     $sth->bindParam(":size", $totallen, PDO::PARAM_INT);
     $sth->bindParam(":numfiles", count($filelist), PDO::PARAM_INT);
     $sth->bindParam(":type", $type, PDO::PARAM_STR);
     $sth->bindParam(":anoymous", $anonymousUpload, PDO::PARAM_INT);
     $sth->bindParam(":descr", $nfo, PDO::PARAM_STR);
     $sth->bindParam(":category", $category, PDO::PARAM_INT);
     $sth->bindParam(":freeLeech", $freeleech, PDO::PARAM_INT);
     $sth->bindParam(":tvChannel", $tvChannel, PDO::PARAM_INT);
     $sth->bindParam(":tvProgram", $tvProgram, PDO::PARAM_STR);
     $sth->bindParam(":tvEpisode", $tvEpisode, PDO::PARAM_STR);
     $sth->bindParam(":tvInfo", $tvInfo, PDO::PARAM_STR);
     $sth->bindParam(":tvTime", $tvTime, PDO::PARAM_INT);
     $sth->bindParam(":tvProgramId", $tvProgramId, PDO::PARAM_INT);
     $sth->bindParam(":imdbid", $imdbId, PDO::PARAM_INT);
     $sth->bindParam(":reqid", $reqid, PDO::PARAM_INT);
     $sth->bindParam(":pre", $pre, PDO::PARAM_INT);
     $sth->bindParam(":p2p", $p2p, PDO::PARAM_INT);
     $sth->bindParam(":3d", $stereoscopic, PDO::PARAM_INT);
     $sth->bindParam(":pack", $pack, PDO::PARAM_INT);
     $sth->bindParam(":swesub", $swesub, PDO::PARAM_INT);
     $sth->execute();
     $insertId = $this->db->lastInsertId();
     $sth = $this->db->prepare("INSERT INTO files (torrent, filename, size) VALUES (?, ?, ?)");
     foreach ($filelist as $file) {
         $sth->bindParam(1, $insertId, PDO::PARAM_INT);
         $sth->bindParam(2, $file[0], PDO::PARAM_STR);
         $sth->bindParam(3, $file[1], PDO::PARAM_INT);
         $sth->execute();
     }
     if (count($packFolders) > 1) {
         $sth = $this->db->prepare("INSERT INTO packfiles(torrent, filename) VALUES (?, ?)");
         foreach ($packFolders as $folder) {
             $sth->bindParam(1, $insertId, PDO::PARAM_INT);
             $sth->bindParam(2, $folder, PDO::PARAM_STR);
             $sth->execute();
         }
     }
     move_uploaded_file($uploaded_file["tmp_name"], $this->torrentDir . $insertId . ".torrent");
     $fp = fopen($this->torrentDir . $insertId . ".torrent", "w");
     if ($fp) {
         @fwrite($fp, benc($dict), strlen(benc($dict)));
         fclose($fp);
     }
     $this->user->initTorrentComments();
     if ($reqid > 2) {
         $this->requests->fill($reqid);
         $votes = $this->requests->getVotes($reqid);
         $uploader = "[url=/user/" . $this->user->getId() . "/" . $this->user->getUsername() . "][b]" . $this->user->getUsername() . "[/b][/url]";
         if ($anonymousUpload) {
             $uploader = "[i]Anonym[/i]";
         }
         $message = "Requesten [url=/torrent/" . $insertId . "/" . $name . "][b]" . $name . "[/b][/url] har blivit uppladdad av " . $uploader;
         foreach ($votes as $vote) {
             if ($vote["user"]["id"] !== $this->user->getId()) {
                 $this->mailbox->sendSystemMessage($vote["user"]["id"], "Request uppladdad!", $message);
             }
         }
     }
     $this->log->log(1, "Torrent ([url=/torrent/" . $insertId . "/" . $name . "][b]" . $name . "[/b][/url]) laddades upp utav {{username}}", $this->user->getId(), $anonymousUpload);
     /* Flush memcached */
     if ($memcache) {
         if ($category == 8) {
             $memcache->delete('swetvguide-0');
         }
     }
     /* Give uploaders more free leech when uploading torrent */
     if ($reqid == 0 && $p2p == 0 && $pack == 0) {
         $leechStart = strtotime($this->user->getLeechStart());
         $newLeech = round($totallen / 1024 / 1024 * 0.02);
         if ($leechStart > time()) {
             $newLeech = $leechStart + $newLeech * 100;
         } else {
             $newLeech = time() + $newLeech * 100;
         }
         $this->db->query("UPDATE users SET leechstart = FROM_UNIXTIME(" . $newLeech . ") WHERE id = " . $this->user->getId());
     }
     return array("id" => $insertId, "name" => $name);
 }
Esempio n. 8
0
 public function upload($uploaded_file, $post)
 {
     if ($this->user->isUploadBanned()) {
         throw new Exception(L::get("TORRENT_UPLOAD_BANNED"), 401);
     }
     $max_torrent_size = 10000000;
     ini_set("upload_max_filesize", $max_torrent_size);
     include 'benc.php';
     if ($post["category"] < Config::$categories["DVDR_PAL"]["id"] || $post["category"] > Config::$categories["MOVIE_4K"]["id"]) {
         throw new Exception(L::get("TORRENT_INVALID_CATEGORY"));
     }
     if ($post["section"] !== 'new' && $post["section"] !== 'archive') {
         throw new Exception(L::get("TORRENT_INVALID_SECTION"));
     }
     if (!preg_match("/\\.torrent\$/", $uploaded_file["name"], $match)) {
         throw new Exception(L::get("TORRENT_INVLID_FILE"));
     }
     if (!is_uploaded_file($uploaded_file["tmp_name"])) {
         throw new Exception(L::get("TORRENT_UPLOAD_ERROR"));
     }
     if (!filesize($uploaded_file["tmp_name"])) {
         throw new Exception(L::get("TORRENT_EMPTY_FILE_ERROR"));
     }
     if ($post["category"] == Config::$categories["TV_SWE"]["id"] && $post["section"] == 'new' && ($post["channel"] == 0 || $post["program"] == 0)) {
         throw new Exception(L::get("TORRENT_SWE_TV_DATA_MISSING"), 412);
     }
     if ($post["reqid"] > 0) {
         $request = $this->requests->get($post["reqid"]);
         if ($this->user->getId() == $request["user"]["id"]) {
             throw new Exception(L::get("TORRENT_FILL_OWN_REQUEST_ERROR"), 400);
         }
         if ($request["filled"] == 1) {
             throw new Exception(L::get("TORRENT_REQUEST_ALREADY_FILLED_ERROR"), 400);
         }
     }
     $name = preg_replace("/\\.torrent\$/", '', $uploaded_file["name"]);
     $category = $post["category"];
     $section = $post["section"];
     $reqid = $post["reqid"];
     $anonymousUpload = $post["anonymousUpload"];
     $nfo = $post["nfo"];
     $imdbId = $post["imdbId"];
     $p2p = $post["p2p"];
     $freeleech = 0;
     $sweaudio = $post["sweaudio"] ?: 0;
     $stereoscopic = 0;
     $swesub = 0;
     /* The following categories should always be tagged with "has swesub" */
     if (in_array($category, array(Config::$categories["DVDR_PAL"]["id"], Config::$categories["DVDR_CUSTOM"]["id"], Config::$categories["DVDR_TV"]["id"], Config::$categories["EBOOKS"]["id"], Config::$categories["EPAPERS"]["id"], Config::$categories["BLURAY"]["id"], Config::$categories["SUBPACK"]["id"]))) {
         $swesub = 2;
     }
     /* The following categories should be marked with "has swesub" if release "contains" swesub */
     if ($post["swesub"] == 1 && in_array($category, array(Config::$categories["MOVIE_720P"]["id"], Config::$categories["MOVIE_1080P"]["id"], Config::$categories["TV_720P"]["id"], Config::$categories["TV_1080P"]["id"], Config::$categories["MOVIE_4K"]["id"]))) {
         $swesub = 2;
     }
     /* SWE TV is excepted from swe audio tag */
     if ($post["sweaudio"] && in_array($category, array(Config::$categories["TV_SWE"]["id"], Config::$categories["AUDIOBOOKS"]["id"], Config::$categories["EBOOKS"]["id"], Config::$categories["EPAPERS"]["id"], Config::$categories["MUSIC"]["id"], Config::$categories["SUBPACK"]["id"]))) {
         $sweaudio = 0;
     }
     /* SWE-TV */
     $tvProgramId = $post["program"] ?: 0;
     $tvChannel = $post["channel"] ?: 0;
     $tvProgram = '';
     $tvEpisode = '';
     $tvInfo = '';
     $tvTime = 0;
     if ($category == Config::$categories["TV_SWE"]["id"] && $tvProgramId > 0 && $tvChannel > 0) {
         /* Manual entered program */
         if ($tvProgramId == 1) {
             $tvProgram = $post["programTitle"];
             $tvTime = strtotime($post["programDate"]);
             if (strlen($tvProgram) < 2) {
                 throw new Exception(L::get("TORRENT_TV_NAME_TOO_SHORT"));
             }
             $tvProgramId = 2;
         } else {
             $sweTv = $this->sweTv->getProgram($tvProgramId);
             if (!$sweTv) {
                 throw new Exception(L::get("TORRENT_TV_PROGRAM_INVALID"));
             }
             $tvProgram = $sweTv["program"];
             $tvEpisode = $sweTv["episod"];
             $tvInfo = $sweTv["info"];
             $tvTime = $sweTv["datum"];
         }
     }
     if ($this->user->getClass() < User::CLASS_UPLOADER && $section == 'new') {
         throw new Exception(L::get("TORRENT_UPLOADER_REQUIRED_NEW"));
     }
     $sth = $this->db->prepare("SELECT COUNT(*) FROM torrents WHERE name = ?");
     $sth->execute(array($name));
     $arr = $sth->fetch();
     if ($arr[0] == 1) {
         throw new Exception(L::get("TORRENT_CONFLICT"), 409);
     }
     $sth = $this->db->prepare("SELECT COUNT(*) FROM packfiles WHERE filename = ?");
     $sth->execute(array($name));
     $arr = $sth->fetch();
     if ($arr[0] == 1) {
         throw new Exception(L::get("TORRENT_CONFLICT_IN_PACK"), 409);
     }
     $sth = $this->db->prepare("SELECT comment FROM banned WHERE namn = ?");
     $sth->execute(array($name));
     while ($arr = $sth->fetch(PDO::FETCH_ASSOC)) {
         throw new Exception(L::get("TORRENT_BANNED", [$arr["comment"]]));
     }
     $dict = bdec_file($uploaded_file["tmp_name"], $max_torrent_size);
     if (!isset($dict)) {
         throw new Exception(L::get("TORRENT_FILE_ERROR"));
     }
     function dict_check($d, $s)
     {
         if ($d["type"] != "dictionary") {
             throw new Exception(L::get("TORRENT_INVLID_FILE"));
         }
         $a = explode(":", $s);
         $dd = $d["value"];
         $ret = array();
         foreach ($a as $k) {
             unset($t);
             if (preg_match('/^(.*)\\((.*)\\)$/', $k, $m)) {
                 $k = $m[1];
                 $t = $m[2];
             }
             if (isset($t)) {
                 if ($dd[$k]["type"] != $t) {
                     throw new Exception(L::get("TORRENT_MISSING_ANNOUNCE_URL"));
                 }
                 $ret[] = $dd[$k]["value"];
             } else {
                 $ret[] = $dd[$k];
             }
         }
         return $ret;
     }
     function dict_get($d, $k, $t)
     {
         if ($d["type"] != "dictionary") {
             throw new Exception(L::get("TORRENT_FILE_ERROR"));
         }
         $dd = $d["value"];
         if (!isset($dd[$k])) {
             return;
         }
         $v = $dd[$k];
         if ($v["type"] != $t) {
             throw new Exception(L::get("TORRENT_FILE_ERROR"));
         }
         return $v["value"];
     }
     list($ann, $info) = dict_check($dict, "announce(string):info");
     list($dname, $plen, $pieces) = dict_check($info, "name(string):piece length(integer):pieces(string)");
     if (strlen($pieces) % 20 != 0) {
         throw new Exception(L::get("TORRENT_FILE_ERROR"));
     }
     $filelist = array();
     $totallen = dict_get($info, "length", "integer");
     if (isset($totallen)) {
         $filelist[] = array($dname, $totallen);
         $type = "single";
     } else {
         $flist = dict_get($info, "files", "list");
         if (!isset($flist)) {
             throw new Exception(L::get("TORRENT_MISSSING_FILES_LENGTH"));
         }
         if (!count($flist)) {
             throw new Exception(L::get("TORRENT_MISSING_FILES"));
         }
         $totallen = 0;
         foreach ($flist as $fn) {
             list($ll, $ff) = dict_check($fn, "length(integer):path(list)");
             $totallen += $ll;
             $ffa = array();
             foreach ($ff as $ffe) {
                 if ($ffe["type"] != "string") {
                     throw new Exception(L::get("TORRENT_FILE_NAME_ERROR"));
                 }
                 $ffa[] = $ffe["value"];
             }
             if (!count($ffa)) {
                 throw new Exception(L::get("TORRENT_FILE_NAME_ERROR"));
             }
             $ffe = implode("/", $ffa);
             $filelist[] = array($ffe, $ll);
         }
         $type = "multi";
     }
     $foundBanned = array();
     $bannedfiles = array(".DS_Store", "._.DS_Store", "ufxpcrc.log", "Thumbs.db", ".checked", ".message", "desktop.ini", "Default.PLS", ".url", ".html", "imdb.nfo", ".missing", "-missing", ".torrent");
     foreach ($filelist as $file) {
         foreach ($bannedfiles as $bfile) {
             if (preg_match("/" . $bfile . "\$/", $file[0])) {
                 $foundBanned[] = $file[0];
             }
         }
     }
     if (count($foundBanned) > 0) {
         $files = '';
         foreach ($foundBanned as $f) {
             $files .= '\'' . $f . '\', ';
         }
         $this->adminlog->create(L::get("TORRENT_CONTAINING_BANNED_FILES_LOG", [$this->user->getUsername(), $name, $files], Config::DEFAULT_LANGUAGE));
         throw new Exception(L::get("TORRENT_CONTAINING_BANNED_FILES", [$files]));
     }
     if (($txt = $this->detectMissingFiles($filelist)) != false) {
         $this->adminlog->create(L::get("TORRENT_PREVENTED_BANNED_FILE", [$this->user->getUsername(), $name], Config::DEFAULT_LANGUAGE) . $txt);
         throw new Exception(L::get("TORRENT_MISSING_FOLLOWING_FILES") . $txt);
     }
     $info['value']['source']['type'] = "string";
     $info['value']['source']['value'] = Config::SITE_NAME;
     $info['value']['source']['strlen'] = strlen($info['value']['source']['value']);
     $info['value']['private']['type'] = "integer";
     $info['value']['private']['value'] = 1;
     $dict['value']['info'] = $info;
     $dict = benc($dict);
     $dict = bdec($dict);
     list($ann, $info) = dict_check($dict, "announce(string):info");
     $infohash = bin2hex(pack("H*", sha1($info["string"])));
     $sth = $this->db->prepare("SELECT COUNT(*) FROM torrents WHERE info_hash = ?");
     $sth->bindParam(1, $infohash, PDO::PARAM_STR);
     $sth->execute();
     $arr = $sth->fetch();
     if ($arr[0] == 1) {
         throw new Exception(L::get("TORRENT_CONFLICT"), 409);
     }
     $pre = Helper::preCheck($name);
     if (!$pre) {
         $pre = 0;
     } else {
         if ($pre > time()) {
             $pre = time() - 100;
         }
         /* Use pre-time to determine New or Archive section */
         if ($section == 'archive' && $pre > time() - 604800) {
             $section = 'new';
             $this->adminlog->create(L::get("TORRENT_AUTO_MOVED_NEW", [$this->user->getUsername(), $name], Config::DEFAULT_LANGUAGE));
         } else {
             if ($section == 'new' && time() - $pre > 604800) {
                 $this->adminlog->create(L::get("TORRENT_AUTO_MOVED_ARCHIVE", [$this->user->getUsername(), $name], Config::DEFAULT_LANGUAGE));
                 $section = 'archive';
             }
         }
     }
     if (stripos($name, '.3d.') > -1 || stripos($name, '.hsbs.') > -1 || stripos($name, '-sbs.') > -1) {
         $stereoscopic = 1;
     }
     /* Presume p2p release when not rar archive */
     if (in_array($category, [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"]]) && count($filelist) < 10) {
         $p2p = 1;
     }
     /* Block or p2p-mark non-scene groups */
     $sth = $this->db->prepare("SELECT * FROM nonscene WHERE groupname = ?");
     $sth->bindValue(1, $this->matchGroupName($name), PDO::PARAM_STR);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     if ($res) {
         if ($res["whitelist"] == 0) {
             throw new Exception(L::get("TORRENT_RELEASE_GROUP_BANNED", [$res["comment"]]), 401);
         } else {
             $p2p = 1;
         }
     }
     /* Torrents sized 15GB+ should be free leech */
     if ($totallen > 16106127360 && $category != Config::$categories["BLURAY"]["id"] && $category != Config::$categories["MOVIE_4K"]["id"]) {
         $freeleech = 1;
     }
     /* Detect if torrent is a "pack" with releases inside */
     $packFolders = array();
     foreach ($filelist as $file) {
         preg_match('/^(.*?)\\//', $file[0], $match);
         if (strlen($match[1]) > 6) {
             array_push($packFolders, $match[1]);
         }
     }
     $packFolders = array_unique($packFolders);
     if (count($packFolders) > 1) {
         $pack = 1;
     } else {
         $pack = 0;
     }
     if ($imdbId) {
         $imdbInfo = $this->movieData->getData($imdbId);
         /* Always replace the release name start when empty or tv-show to keep it up to date for auto-matching */
         if ($imdbInfo["releaseNameStart"] == "" || in_array($category, [Config::$categories["TV_720P"]["id"], Config::$categories["TV_1080P"]["id"]])) {
             $this->movieData->updateReleaseNameStart($name, $imdbId);
         }
     }
     $fname = $name . ".torrent";
     $searchText = Helper::searchfield("{$name} {$imdbInfo['genres']} {$imdbInfo['imdbid']} " . implode(" ", $packFolders));
     $searchText2 = Helper::searchfield("{$imdbInfo['director']} {$imdbInfo['writer']} {$imdbInfo['cast']}");
     $sth = $this->db->prepare("INSERT INTO torrents (name, filename, search_text, search_text2, owner, visible, info_hash, size, numfiles, type, ano_owner, descr, category, added, last_action,  frileech, tv_kanalid, tv_program, tv_episode, tv_info, imdbid, tv_klockslag, tv_programid, reqid, section, pre, p2p, 3d, pack, swesub, sweaudio) VALUES (:name, :filename, :searchText, :searchText2, :owner, 'no', :infoHash, :size, :numfiles, :type, :anoymous, :descr, :category, NOW(), NOW(), :freeLeech, :tvChannel, :tvProgram, :tvEpisode, :tvInfo, :imdbid, :tvTime, :tvProgramId, :reqid, :section, :pre, :p2p, :3d, :pack, :swesub, :sweaudio)");
     $sth->bindParam(":name", $name, PDO::PARAM_STR);
     $sth->bindParam(":filename", $fname, PDO::PARAM_STR);
     $sth->bindParam(":searchText", $searchText, PDO::PARAM_STR);
     $sth->bindParam(":searchText2", $searchText2, PDO::PARAM_STR);
     $sth->bindValue(":owner", $this->user->getId(), PDO::PARAM_INT);
     $sth->bindParam(":infoHash", $infohash, PDO::PARAM_STR);
     $sth->bindParam(":size", $totallen, PDO::PARAM_INT);
     $sth->bindValue(":numfiles", count($filelist), PDO::PARAM_INT);
     $sth->bindParam(":type", $type, PDO::PARAM_STR);
     $sth->bindParam(":anoymous", $anonymousUpload, PDO::PARAM_INT);
     $sth->bindParam(":descr", $nfo, PDO::PARAM_STR);
     $sth->bindParam(":category", $category, PDO::PARAM_INT);
     $sth->bindParam(":freeLeech", $freeleech, PDO::PARAM_INT);
     $sth->bindParam(":tvChannel", $tvChannel, PDO::PARAM_INT);
     $sth->bindParam(":tvProgram", $tvProgram, PDO::PARAM_STR);
     $sth->bindParam(":tvEpisode", $tvEpisode, PDO::PARAM_STR);
     $sth->bindParam(":tvInfo", $tvInfo, PDO::PARAM_STR);
     $sth->bindParam(":tvTime", $tvTime, PDO::PARAM_INT);
     $sth->bindParam(":tvProgramId", $tvProgramId, PDO::PARAM_INT);
     $sth->bindParam(":imdbid", $imdbId, PDO::PARAM_INT);
     $sth->bindParam(":reqid", $reqid, PDO::PARAM_INT);
     $sth->bindParam(":section", $section, PDO::PARAM_STR);
     $sth->bindParam(":pre", $pre, PDO::PARAM_INT);
     $sth->bindParam(":p2p", $p2p, PDO::PARAM_INT);
     $sth->bindParam(":3d", $stereoscopic, PDO::PARAM_INT);
     $sth->bindParam(":pack", $pack, PDO::PARAM_INT);
     $sth->bindParam(":swesub", $swesub, PDO::PARAM_INT);
     $sth->bindParam(":sweaudio", $sweaudio, PDO::PARAM_INT);
     $sth->execute();
     $insertId = $this->db->lastInsertId();
     $sth = $this->db->prepare("INSERT INTO files (torrent, filename, size) VALUES (?, ?, ?)");
     foreach ($filelist as $file) {
         $sth->bindParam(1, $insertId, PDO::PARAM_INT);
         $sth->bindParam(2, $file[0], PDO::PARAM_STR);
         $sth->bindParam(3, $file[1], PDO::PARAM_INT);
         $sth->execute();
     }
     if (count($packFolders) > 1) {
         $sth = $this->db->prepare("INSERT INTO packfiles(torrent, filename) VALUES (?, ?)");
         foreach ($packFolders as $folder) {
             $sth->bindParam(1, $insertId, PDO::PARAM_INT);
             $sth->bindParam(2, $folder, PDO::PARAM_STR);
             $sth->execute();
         }
     }
     move_uploaded_file($uploaded_file["tmp_name"], $this->torrentDir . $insertId . ".torrent");
     $fp = fopen($this->torrentDir . $insertId . ".torrent", "w");
     if ($fp) {
         @fwrite($fp, benc($dict), strlen(benc($dict)));
         fclose($fp);
     }
     $this->user->initTorrentComments();
     if ($reqid > 0) {
         $this->requests->fill($reqid);
         $votes = $this->requests->getVotes($reqid);
         $uploader = "[url=/user/" . $this->user->getId() . "/" . $this->user->getUsername() . "][b]" . $this->user->getUsername() . "[/b][/url]";
         foreach ($votes as $vote) {
             if ($anonymousUpload) {
                 $uploader = "[i]" . L::get("TORRENT_ANONYMOUS", null, $vote["user"]["language"]) . "[/i]";
             }
             $message = L::get("TORRENT_REQUEST_FILLED_PM_BODY", [$insertId, $name, $name, $uploader], $vote["user"]["language"]);
             if ($vote["user"]["id"] !== $this->user->getId()) {
                 $this->mailbox->sendSystemMessage($vote["user"]["id"], L::get("TORRENT_REQUEST_FILLED_PM_TOPIC", null, $vote["user"]["language"]), $message);
             }
         }
     }
     $this->log->log(1, L::get("TORRENT_UPLOADED_LOG", [$insertId, $name, $name], Config::DEFAULT_LANGUAGE), $this->user->getId(), $anonymousUpload);
     /* Flush memcached */
     if ($memcached && $category == 8) {
         $memcached->delete('swetvguide-0');
         $memcached->delete('swetvguide-1');
         $memcached->delete('swetvguide-2');
     }
     /* Give uploaders more free leech when uploading torrent */
     if ($section == 'new' && $p2p == 0 && $pack == 0) {
         $leechStart = strtotime($this->user->getLeechStart());
         $newLeech = round($totallen / 1024 / 1024 * 0.02);
         if ($leechStart > time()) {
             $newLeech = $leechStart + $newLeech * 100;
         } else {
             $newLeech = time() + $newLeech * 100;
         }
         $this->db->query("UPDATE users SET leechstart = FROM_UNIXTIME(" . $newLeech . ") WHERE id = " . $this->user->getId());
     }
     return array("id" => $insertId, "name" => $name);
 }
Esempio n. 9
0
 public function createOrUpdate($postData, $reqId = null)
 {
     if ($this->user->getClass() < User::CLASS_ACTOR) {
         throw new Exception(L::get("PERMISSION_DENIED"), 401);
     }
     if ($reqId) {
         $request = $this->get($reqId);
         if ($request["user"]["id"] != $this->user->getId() && $this->user->getClass() < User::CLASS_ADMIN) {
             throw new Exception(L::get("PERMISSION_DENIED"));
         }
     } else {
         if ($this->user->getRequestSlots() <= count($this->myRequests())) {
             throw new Exception(L::get("REQUEST_SLOTS_EXCEEDED"), 401);
         }
     }
     if ($postData["category"] < Config::$categories["DVDR_PAL"]["id"] || $postData["category"] > Config::$categories["SUBPACK"]["id"]) {
         throw new Exception(L::get("REQUEST_INVALID_CATEGORY"));
     }
     if (in_array($postData["category"], array(1, 2, 3, 4, 5, 6, 7)) && strlen($postData["imdbInfo"]) < 2) {
         throw new Exception(L::get("REQUEST_NO_IMDB_URL"));
     }
     if (in_array($postData["category"], array(8, 9, 10, 11, 12)) && strlen($postData["customName"]) < 2) {
         throw new Exception(L::get("REQUEST_NAME_TOO_SHORT"));
     }
     $requestName = $postData["imdbInfo"];
     if (in_array($postData["category"], array(8, 9, 10, 11, 12))) {
         $requestName = $postData["customName"];
     }
     $slug = Helper::slugify($requestName);
     $searchText = Helper::searchfield($requestName);
     $userid = $this->user->getId();
     if ($reqId) {
         $sth = $this->db->prepare("UPDATE requests SET userid = ?, request = ?, comment = ?, search_text = ?, season = ?, imdbid = ?, typ = ?, slug = ? WHERE id = " . $request["id"]);
         $userid = $request["user"]["id"];
     } else {
         $sth = $this->db->prepare("INSERT INTO requests(userid, request, added, comment, search_text, season, imdbid, typ, slug) VALUES(?, ?, NOW(), ?, ?, ?, ?, ?, ?)");
     }
     $sth->bindParam(1, $userid, PDO::PARAM_INT);
     $sth->bindParam(2, $requestName, PDO::PARAM_STR);
     $sth->bindParam(3, $postData["comment"], PDO::PARAM_STR);
     $sth->bindParam(4, $searchText, PDO::PARAM_STR);
     $sth->bindParam(5, $postData["season"], PDO::PARAM_INT);
     $sth->bindParam(6, $postData["imdbId"], PDO::PARAM_INT);
     $sth->bindParam(7, $postData["category"], PDO::PARAM_INT);
     $sth->bindParam(8, $slug, PDO::PARAM_STR);
     $sth->execute();
     if ($reqId) {
         return array("id" => $request["id"], "slug" => $slug);
     } else {
         $insertId = $this->db->lastInsertId();
         $this->log->log(1, L::get("REQUEST_SITE_LOG", [$insertId, $slug, $requestName], Config::DEFAULT_LANGUAGE), $this->user->getId(), false);
         $this->vote($insertId, 0);
         return array("id" => $insertId, "name" => $requestName);
     }
 }
Esempio n. 10
0
 public function createOrUpdate($postData, $reqId = null)
 {
     if ($this->user->getClass() < User::CLASS_SKADIS) {
         throw new Exception('Du har inte rättigheter.', 401);
     }
     if ($reqId) {
         $request = $this->get($reqId);
         if ($request["user"]["id"] != $this->user->getId() && $this->user->getClass() < User::CLASS_ADMIN) {
             throw new Exception('Du saknar rättigheter att redigera denna request.');
         }
     } else {
         if ($this->user->getRequestSlots() <= count($this->myRequests())) {
             throw new Exception('Du har utnyttjat alla dina maximalt antal aktiva requests.');
         }
     }
     if ($postData["category"] < 1 || $postData["category"] > 12) {
         throw new Exception('Ogiltig kategori.');
     }
     if (in_array($postData["category"], array(1, 2, 3, 4, 5, 6, 7)) && strlen($postData["imdbInfo"]) < 2) {
         throw new Exception('Ingen IMDB-länk vald.');
     }
     if (in_array($postData["category"], array(8, 9, 10, 11, 12)) && strlen($postData["customName"]) < 2) {
         throw new Exception('Namnet är för kort.');
     }
     if ($postData["receiver"] == $this->user->getId()) {
         throw new Exception('Skicka inte meddelande till dig själv.');
     }
     $requestName = $postData["imdbInfo"];
     if (in_array($postData["category"], array(8, 9, 10, 11, 12))) {
         $requestName = $postData["customName"];
     }
     $searchText = Helper::searchfield($requestName);
     $userid = $this->user->getId();
     if ($reqId) {
         $sth = $this->db->prepare("UPDATE requests SET userid = ?, request = ?, comment = ?, search_text = ?, season = ?, imdbid = ?, typ = ? WHERE id = " . $request["id"]);
         $userid = $request["user"]["id"];
     } else {
         $sth = $this->db->prepare("INSERT INTO requests(userid, request, added, comment, search_text, season, imdbid, typ) VALUES(?, ?, NOW(), ?, ?, ?, ?, ?)");
     }
     $sth->bindParam(1, $userid, PDO::PARAM_INT);
     $sth->bindParam(2, $requestName, PDO::PARAM_STR);
     $sth->bindParam(3, $postData["comment"], PDO::PARAM_STR);
     $sth->bindParam(4, $searchText, PDO::PARAM_STR);
     $sth->bindParam(5, $postData["season"], PDO::PARAM_INT);
     $sth->bindParam(6, $postData["imdbId"], PDO::PARAM_INT);
     $sth->bindParam(7, $postData["category"], PDO::PARAM_INT);
     $sth->execute();
     if ($reqId) {
         return array("id" => $request["id"], "name" => $requestName);
     } else {
         $insertId = $this->db->lastInsertId();
         $this->log->log(1, "Request ([url=/archive/request/" . $insertId . "/][b]" . $requestName . "[/b][/url]) inlagd utav {{username}}", $this->user->getId(), false);
         $this->vote($insertId, 0);
         return array("id" => $insertId, "name" => $requestName);
     }
 }