public function __construct(PwPost $pwpost, $tid = null, $wikilink = '') { $this->user = $pwpost->user; $this->special = $pwpost->special; $this->tid = $tid ? intval($tid) : null; $this->fid = intval($pwpost->forum->fid); $this->wikilink = $wikilink; $this->action = $this->tid ? 'modify' : 'add'; $this->passkey = PwPasskey::getPassKey($this->user->uid); }
public function downloadAction() { $id = $this->getInput('id'); $passkey = $this->getInput('passkey'); if (!$this->loginUser->uid && empty($passkey)) { $this->showError('必须登录才能进行本操作!'); } elseif (is_string($passkey)) { $user = $this->_getTorrentUserDS()->getTorrentUserByPasskey($passkey); if (empty($user)) { $this->showError('Passkey 错误!'); } else { $uid = $user['uid']; } } else { Wind::import('EXT:torrent.service.srv.helper.PwPasskey'); $uid = $this->loginUser->uid; $passkey = PwPasskey::getPassKey($uid); } $userBan = $this->__getUserBanDS()->getBanInfo($uid); if ($userBan) { $this->showError('用户处于封禁期!'); } $file = WEKIT_PATH . '../torrent/' . $id . '.torrent'; if (!file_exists($file)) { $this->showError('种子文件不存在!'); } $torrent = $this->_getTorrentDS()->getTorrent($id); // Check if torrent was removed $topic = $this->__getThreadDS()->getThread($torrent['tid']); if ($topic['disabled'] > 0 && !(in_array($user['groupid'], array(3, 4, 5)) || $topic['created_userid'] == $user['uid'])) { $this->showError('种子已被删除或得审核!'); } // Change announce to user's private announce $bencode = Wekit::load('EXT:torrent.service.srv.helper.PwBencode'); $dictionary = $bencode->doDecodeFile($file); $dictionary['value']['announce'] = $bencode->doDecode($bencode->doEncodeString(WindUrlHelper::createUrl('/app/torrent/index/announce?passkey=' . $passkey))); // Generate file name $torrentnameprefix = Wekit::C('site', 'app.torrent.torrentnameprefix'); if ($torrentnameprefix == '') { $torrentnameprefix = Wekit::C('site', 'info.name'); } $filename = rawurlencode('[' . $torrentnameprefix . '][' . $torrent['save_as'] . ']'); // Send torrent file to broswer header('Content-Description: File Transfer'); header('Content-type: application/octet-streamn'); header('Content-Disposition: attachment; charset=utf-8; filename="' . $filename . '.torrent"; filename*=UTF-8\'\'' . $filename . '.torrent'); header('Content-Transfer-Encoding: binary'); exit($bencode->doEncode($dictionary)); }