/** * Изменение имени файла торрента в соотв. с паттерном CTRev * @param array $row массив данных торрента * @return int ID торрента */ public function get_tfile($row) { $fname = default_filename($row['posted_time'], $row['poster_id']); $path = ROOT . config::o()->v('torrents_folder') . '/'; $nname = $path . bittorrent::torrent_prefix . $fname . ".torrent"; $oname = $path . $row['id'] . ".torrent"; if (!file_exists($nname) && file_exists($oname)) { rename($oname, $nname); } return $row['id']; }
/** * Удаление скриншотов, постера и торрента * @param int $posted_time время создания * @param int $poster_id ID залившего * @param string $screenshots массив скриншотов * @return null */ protected function delete_files($posted_time, $poster_id, $screenshots) { if (!$this->tstate) { return; } $f = default_filename($posted_time, $poster_id); @unlink(ROOT . config::o()->v('torrents_folder') . '/' . bittorrent::torrent_prefix . $f . ".torrent"); $screenshots = unserialize($screenshots); if (!$screenshots) { return; } foreach ($screenshots as $screenshot) { if (is_array($screenshot)) { if ($screenshot[0]) { @unlink(ROOT . config::o()->v('screenshots_folder') . '/' . $screenshot[0]); } if ($screenshot[1]) { @unlink(ROOT . config::o()->v('screenshots_folder') . '/' . $screenshot[1]); } } } }
/** * Скачивание вложения * @param int $id ID вложения * @return null * @throws EngineException */ public function download($id) { if (!$this->state) { return; } users::o()->check_perms('attach', 1, 2); $id = (int) $id; $q = db::o()->p($id)->query("SELECT * FROM attachments WHERE id=? LIMIT 1"); $row = db::o()->fetch_assoc($q); if (!$row) { throw new EngineException('file_not_exists'); } $file = config::o()->v("attachments_folder") . "/" . self::attach_prefix . default_filename($row['time'], $row['user']); try { plugins::o()->pass_data(array("row" => &$row))->run_hook('attachments_download'); } catch (PReturn $e) { return $e->r(); } db::o()->p($id)->update(array("_cb_downloaded" => 'downloaded+1'), "attachments", 'WHERE id = ? LIMIT 1'); /* @var $uploader uploader */ $uploader = n("uploader"); $uploader->download($file, display::o()->html_decode($row["filename"])); }
/** * Предобработка dict перед скачиванием * @param int $id ID торрента * @param int $posted_time время постинга * @param int $poster_id ID автора * @return array словарь торрента */ protected function prepare_dict($id, $posted_time, $poster_id) { $fname = default_filename($posted_time, $poster_id); $dict = $this->bdec(ROOT . config::o()->v('torrents_folder') . '/' . self::torrent_prefix . $fname . ".torrent", true); $dict['comment'] = sprintf(lang::o()->v('content_torrent_from_site'), config::o()->v('site_title'), furl::o()->construct("download", array("id" => $id, 'noencode' => true))); $passkey = users::o()->v('passkey'); $dict['announce'] = config::o()->v('annadress') ? config::o()->v('annadress') : furl::o()->construct('announce', array('passkey' => $passkey, 'noencode' => true), false, true); if (!is_array($dict['announce-list'])) { unset($dict['announce-list']); } $this->dict_pk_replace($dict); $this->dict_addition_announces($dict); if ($dict['announce-list']) { array_unshift($dict['announce-list'], array($dict['announce'])); } return $dict; }