From 9d3a8e12b53f6fabb5b27c93c8f29f762b806b44 Mon Sep 17 00:00:00 2001 From: 7IN0SAN9 Date: Mon, 2 Nov 2015 18:13:44 +0800 Subject: [PATCH] Check is_array() before foreach() and in_array() --- cron/PwCronDoClearPeers.php | 10 +++ cron/PwCronDoClearTorrents.php | 7 +- extensions/torrent/admin/ManageController.php | 69 ++++++++++------ .../torrent/controller/IndexController.php | 78 +++++++++++-------- .../service/srv/do/PwPostDoTorrent.php | 69 +++++++++++----- .../srv/do/PwSpaceProfileDoTorrent.php | 15 ++-- .../srv/do/PwThreadDisplayDoTorrent.php | 22 ++++-- .../srv/do/PwThreadDisplayDoTorrentSide.php | 15 ++-- .../service/srv/do/PwThreadListDoTorrent.php | 18 +++-- .../srv/do/PwThreadsBatchDeleteDoTorrent.php | 23 ++++-- .../srv/do/PwThreadsDeleteDoTorrent.php | 8 +- .../torrent/service/srv/helper/PwAnnounce.php | 7 ++ .../torrent/template/admin/manage_agent.htm | 2 + .../torrent/template/admin/manage_credit.htm | 2 + .../torrent/template/admin/manage_run.htm | 2 + extensions/torrent/template/index_my.htm | 2 + .../template/read_injector_before_torrent.htm | 2 +- 17 files changed, 239 insertions(+), 112 deletions(-) diff --git a/cron/PwCronDoClearPeers.php b/cron/PwCronDoClearPeers.php index 1529274..fb17ce6 100644 --- a/cron/PwCronDoClearPeers.php +++ b/cron/PwCronDoClearPeers.php @@ -9,8 +9,18 @@ class PwCronDoClearPeers extends AbstractCronBase public function run($cronId) { $torrents = Wekit::load('EXT:torrent.service.PwTorrent')->fetchTorrent(); + + if (!is_array($torrents)) { + return; + } + foreach ($torrents as $torrent) { $peers = Wekit::load('EXT:torrent.service.PwTorrentPeer')->getTorrentPeerByTorrent($torrent['id']); + + if (!is_array($peers)) { + continue; + } + foreach ($peers as $peer) { if (strtotime($peer['last_action']) < strtotime('-' . Wekit::C('site', 'app.torrent.cron.peertimeout') . ' minute')) { Wekit::load('EXT:torrent.service.PwTorrentPeer')->deleteTorrentPeer($peer['id']); diff --git a/cron/PwCronDoClearTorrents.php b/cron/PwCronDoClearTorrents.php index 615365f..2449d79 100644 --- a/cron/PwCronDoClearTorrents.php +++ b/cron/PwCronDoClearTorrents.php @@ -30,16 +30,21 @@ private function deleteThread($topic) public function run($cronId) { $torrentimeout = Wekit::C('site', 'app.torrent.cron.torrentimeout'); + if ($torrentimeout < 1) { return null; } $torrents = Wekit::load('EXT:torrent.service.PwTorrent')->fetchTorrent(); + if (!is_array($torrents)) { + return; + } + foreach ($torrents as $torrent) { $topic = Wekit::load('forum.PwThread')->getThread($torrent['tid']); - if ($topic['disabled'] > 0) { + if (is_array($topic) && $topic['disabled'] > 0) { continue; } diff --git a/extensions/torrent/admin/ManageController.php b/extensions/torrent/admin/ManageController.php index ca08b73..1e351c2 100755 --- a/extensions/torrent/admin/ManageController.php +++ b/extensions/torrent/admin/ManageController.php @@ -51,13 +51,17 @@ public function themeAction() public function dorunAction() { list($showuserinfo, $titlegenifopen, $titlegendouban, $check, $deniedfts, $torrentnameprefix, $peertimeout, $torrentimeout) = $this->getInput(array('showuserinfo', 'titlegenifopen', 'titlegendouban', 'check', 'deniedfts', 'torrentnameprefix', 'peertimeout', 'torrentimeout'), 'post'); - foreach ($deniedfts as $key => $value) { - if (empty($value)) { - continue; - } - $_deniedfts[$key] = $value; + if (is_array($deniedfts)) { + foreach ($deniedfts as $key => $value) { + if (empty($value)) { + continue; + } + + $_deniedfts[$key] = $value; + } } + if (empty($torrentnameprefix)) { $torrentnameprefix = Wekit::C('site', 'info.name'); } @@ -68,29 +72,35 @@ public function dorunAction() $config = new PwConfigSet('site'); $config->set('app.torrent.showuserinfo', $showuserinfo)->set('app.torrent.titlegen.ifopen', $titlegenifopen)->set('app.torrent.titlegen.douban', $titlegendouban)->set('app.torrent.check', $check)->set('app.torrent.torrentnameprefix', $torrentnameprefix)->set('app.torrent.cron.peertimeout', intval($peertimeout))->set('app.torrent.cron.torrentimeout', intval($torrentimeout)); + if (!empty($deniedfts)) { $config->set('app.torrent.deniedfts', $_deniedfts); } $config->flush(); + $this->showMessage('ADMIN:success'); } public function docreditAction() { list($creditifopen, $credits) = $this->getInput(array('creditifopen', 'credits'), 'post'); + $_credits = array(); - !$credits && $credits = array(); - foreach ($credits as $key => $credit) { - if (!$credit['enabled'] || empty($credit['func'])) { - continue; - } - $_credits[$key] = $credit; + if (is_array($credits)) { + foreach ($credits as $key => $credit) { + if (!$credit['enabled'] || empty($credit['func'])) { + continue; + } + + $_credits[$key] = $credit; + } } $config = new PwConfigSet('site'); $config->set('app.torrent.creditifopen', intval($creditifopen))->set('app.torrent.credits', $_credits)->flush(); + $this->showMessage('ADMIN:success'); } @@ -101,26 +111,34 @@ public function doagentAction() $PwTorrentAgentDs->deleteTorrentAgent($this->getInput('id', 'post')); } else { Wind::import('EXT:torrent.service.dm.PwTorrentAgentDm'); + list($allowedClients, $newAllowedClients) = $this->getInput(array('allowedClients', 'newAllowedClients'), 'post'); - foreach ($allowedClients as $key => $allowedClient) { - if (empty($allowedClient['family']) || empty($allowedClient['agent_pattern'])) { - continue; - } - $dm = new PwTorrentAgentDm($key); - $dm->setFamily($allowedClient['family'])->setPeeridPattern($allowedClient['peer_id_pattern'])->setAgentPattern($allowedClient['agent_pattern'])->setAllowHttps($allowedClient['allowhttps']); - $PwTorrentAgentDs->updateTorrentAgent($dm); - } - foreach ($newAllowedClients as $key => $allowedClient) { - if (empty($allowedClient['family']) || empty($allowedClient['agent_pattern'])) { - continue; + if (is_array($allowedClients)) { + foreach ($allowedClients as $key => $allowedClient) { + if (empty($allowedClient['family']) || empty($allowedClient['agent_pattern'])) { + continue; + } + + $dm = new PwTorrentAgentDm($key); + $dm->setFamily($allowedClient['family'])->setPeeridPattern($allowedClient['peer_id_pattern'])->setAgentPattern($allowedClient['agent_pattern'])->setAllowHttps($allowedClient['allowhttps']); + $PwTorrentAgentDs->updateTorrentAgent($dm); } + } + + if (is_array($newAllowedClients)) { + foreach ($newAllowedClients as $key => $allowedClient) { + if (empty($allowedClient['family']) || empty($allowedClient['agent_pattern'])) { + continue; + } - $dm = new PwTorrentAgentDm(); - $dm->setFamily($allowedClient['family'])->setPeeridPattern($allowedClient['peer_id_pattern'])->setAgentPattern($allowedClient['agent_pattern'])->setAllowHttps($allowedClient['allowhttps']); - $PwTorrentAgentDs->addTorrentAgent($dm); + $dm = new PwTorrentAgentDm(); + $dm->setFamily($allowedClient['family'])->setPeeridPattern($allowedClient['peer_id_pattern'])->setAgentPattern($allowedClient['agent_pattern'])->setAllowHttps($allowedClient['allowhttps']); + $PwTorrentAgentDs->addTorrentAgent($dm); + } } } + $this->showMessage('ADMIN:success'); } @@ -131,6 +149,7 @@ public function dothemeAction() $config = new PwConfigSet('site'); $config->set('app.torrent.theme.showpeers', $showpeers); $config->flush(); + $this->showMessage('ADMIN:success'); } diff --git a/extensions/torrent/controller/IndexController.php b/extensions/torrent/controller/IndexController.php index 52db03f..7af54d8 100755 --- a/extensions/torrent/controller/IndexController.php +++ b/extensions/torrent/controller/IndexController.php @@ -63,11 +63,13 @@ public function updateInfoAction() if ($w_type == 12) { // 豆瓣 $url = 'https://api.douban.com/v2/movie/subject/' . $wikilink; + if (!empty(Wekit::C('site', 'app.torrent.titlegen.douban'))) { $url .= '?apikey=' . Wekit::C('site', 'app.torrent.titlegen.douban'); } $result = json_decode(PwUpdateInfo::curl($url)); + $title = '[' . $result->countries[0] . ']'; // 国别 $title .= '[' . $result->year . ']'; // 年份 $title .= '[' . $result->title . ']'; // 影片中文名 @@ -209,18 +211,24 @@ public function announceAction() Wind::import('EXT:torrent.service.srv.helper.PwAnnounce'); // Check if a BitTorrent client + $allowed = false; + $allowedClients = $this->_getTorrentAgentDS()->fetchTorrentAgent(); - foreach ($allowedClients as $allowedClient) { - if (!preg_match($allowedClient['agent_pattern'], $agent)) { - continue; - } - if ($allowedClient['peer_id_pattern'] == '' || preg_match($allowedClient['peer_id_pattern'], $peerId)) { - $allowed = true; - } + if (is_array($allowedClients)) { + foreach ($allowedClients as $allowedClient) { + if (!preg_match($allowedClient['agent_pattern'], $agent)) { + continue; + } + + if ($allowedClient['peer_id_pattern'] == '' || preg_match($allowedClient['peer_id_pattern'], $peerId)) { + $allowed = true; + } - break; + break; + } } + if (!$allowed) { PwAnnounce::showError('This a a bittorrent application and can\'t be loaded into a browser!'); } @@ -343,14 +351,16 @@ public function announceAction() $WindApi = WindidApi::api('user'); $pwUser = Wekit::load('user.PwUser'); $crdtits = $WindApi->getUserCredit($user['uid']); - $_credits = Wekit::C('site', 'app.torrent.credits'); $user_torrents = count($this->_getTorrentDS()->fetchTorrentByUid($user['uid'])); $histories = $this->_getTorrentHistoryDs()->fetchTorrentHistoryByUid($user['uid']); - foreach ($histories as $history) { - $downloaded_total += $history['downloaded']; - $uploaded_total += $history['uploaded']; + if (is_array($histories)) { + foreach ($histories as $history) { + $downloaded_total += $history['downloaded']; + $uploaded_total += $history['uploaded']; + } } + unset($histories); if ($downloaded_total != 0) { @@ -371,15 +381,19 @@ public function announceAction() $m->e('time = ' . intval($timeUsed)); $m->e('torrents = ' . intval($user_torrents)); - foreach ($_credits as $key => $value) { - if ($value['enabled'] != '1') { - continue; - } + $_credits = Wekit::C('site', 'app.torrent.credits'); - $m->e('credit = ' . intval($crdtits['credit' . $key])); + if (is_array($_credits)) { + foreach ($_credits as $key => $value) { + if ($value['enabled'] != '1') { + continue; + } + + $m->e('credit = ' . intval($crdtits['credit' . $key])); - $changes[$key] = intval($m->e($exp)); - $changed++; + $changes[$key] = intval($m->e($exp)); + $changed++; + } } if ($changed) { @@ -569,19 +583,21 @@ public function rssAction() $torrents = $this->_getTorrentSubscribeDs()->getTorrentSubscribeByUid($this->loginUser->uid); - foreach ($torrents as $torrent) { - if ($torrent['disabled'] > 0 && !in_array($user['groupid'], array(3, 4, 5))) { - continue; + if (is_array($torrents)) { + foreach ($torrents as $torrent) { + if ($torrent['disabled'] > 0 && !in_array($user['groupid'], array(3, 4, 5))) { + continue; + } + echo ''; + echo '<![CDATA[' . $torrent['filename'] . ']]>'; + echo ''; + echo '' . date('D, d M Y H:i:s O', $torrent['created_time']) . ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; } - echo ''; - echo '<![CDATA[' . $torrent['filename'] . ']]>'; - echo ''; - echo '' . date('D, d M Y H:i:s O', $torrent['created_time']) . ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; } echo ''; diff --git a/extensions/torrent/service/srv/do/PwPostDoTorrent.php b/extensions/torrent/service/srv/do/PwPostDoTorrent.php index 44243df..13f69b4 100755 --- a/extensions/torrent/service/srv/do/PwPostDoTorrent.php +++ b/extensions/torrent/service/srv/do/PwPostDoTorrent.php @@ -86,49 +86,76 @@ public function check($postDm) if (!count($flist)) { return new PwError('种子不存在任何文件,请检查种子是否正确!'); } + $totalLength = 0; - foreach ($flist as $fn) { - list($ll, $ff) = $bencode->doDictionaryCheck($fn, 'length(integer):path(list)'); - $totalLength += $ll; - $ffa = array(); - foreach ($ff as $ffe) { - if ($ffe['type'] != 'string') { + + if (is_array($flist)) { + foreach ($flist as $fn) { + list($ll, $ff) = $bencode->doDictionaryCheck($fn, 'length(integer):path(list)'); + + $totalLength += $ll; + + $ffa = array(); + + if (is_array($ff)) { + foreach ($ff as $ffe) { + if ($ffe['type'] != 'string') { + return new PwError('种子存在文件名错误,请检查种子是否正确!'); + } + $ffa[] = $ffe['value']; + } + } + + if (!count($ffa)) { return new PwError('种子存在文件名错误,请检查种子是否正确!'); } - $ffa[] = $ffe['value']; - } - if (!count($ffa)) { - return new PwError('种子存在文件名错误,请检查种子是否正确!'); + + $ffe = implode('/', $ffa); + $fileList[] = array($ffe, $ll); } - $ffe = implode('/', $ffa); - $fileList[] = array($ffe, $ll); } $type = 'multi'; } - if (in_array('deniedfts', Wekit::C('site', 'app.torrent.check'))) { - $deniedfts = Wekit::C('site', 'app.torrent.deniedfts'); - foreach ($fileList as $file) { - $ft = substr(strrchr($file[0], '.'), 1); - if (in_array($ft, $deniedfts)) { - return new PwError('种子内存在禁止发布的文件类型!'); + + $torrentcheck = Wekit::C('site', 'app.torrent.check'); + + if (is_array($torrentcheck)) { + if (in_array('deniedfts', $torrentcheck)) { + $deniedfts = Wekit::C('site', 'app.torrent.deniedfts'); + + if (is_array($deniedfts)) { + foreach ($fileList as $file) { + $ft = substr(strrchr($file[0], '.'), 1); + if (in_array($ft, $deniedfts)) { + return new PwError('种子内存在禁止发布的文件类型!'); + } + } } } + + if (in_array('source', $torrentcheck)) { + $dictionary['value']['info']['value']['source'] = $bencode->doDecode($bencode->doEncodeString(Wekit::C('site', 'info.name'))); + } } + $dictionary['value']['announce'] = $bencode->doDecode($bencode->doEncodeString(Wekit::C('site', 'info.url') . '/announce.php')); $dictionary['value']['info']['value']['private'] = $bencode->doDecode('i1e'); - if (in_array('source', Wekit::C('site', 'app.torrent.check'))) { - $dictionary['value']['info']['value']['source'] = $bencode->doDecode($bencode->doEncodeString(Wekit::C('site', 'info.name'))); - } unset($dictionary['value']['announce-list']); unset($dictionary['value']['nodes']); + $dictionary = $bencode->doDecode($bencode->doEncode($dictionary)); + list($announce, $info) = $bencode->doDictionaryCheck($dictionary, 'announce(string):info'); + $infohash = pack('H*', sha1($info['string'])); + $check = $this->_getTorrentDS()->getTorrentByInfoHash($infohash); + if ($check) { return new PwError('不能发布重复种子资源'); } + $this->dictionary = $dictionary; $this->infohash = $infohash; $this->filename = $filename; diff --git a/extensions/torrent/service/srv/do/PwSpaceProfileDoTorrent.php b/extensions/torrent/service/srv/do/PwSpaceProfileDoTorrent.php index edcae40..66e6da5 100755 --- a/extensions/torrent/service/srv/do/PwSpaceProfileDoTorrent.php +++ b/extensions/torrent/service/srv/do/PwSpaceProfileDoTorrent.php @@ -6,9 +6,12 @@ class PwSpaceProfileDoTorrent { public function appDo($space) { - if (!in_array('profile', Wekit::C('site', 'app.torrent.showuserinfo'))) { - return ''; + $showuserinfo = Wekit::C('site', 'app.torrent.showuserinfo'); + + if (is_array($showuserinfo) && !in_array('profile', $showuserinfo)) { + return; } + $user = Wekit::load('EXT:torrent.service.PwTorrentUser')->getTorrentUserByUid($space->{'spaceUid'}); $torrents = Wekit::load('EXT:torrent.service.PwTorrent')->fetchTorrentByUid($space->{'spaceUid'}); $histories = Wekit::load('EXT:torrent.service.PwTorrentHistory')->fetchTorrentHistoryByUid($space->{'spaceUid'}); @@ -17,9 +20,11 @@ public function appDo($space) $posted = count($torrents); - foreach ($histories as $history) { - $downloaded_total += $history['downloaded']; - $uploaded_total += $history['uploaded']; + if (is_array($histories)) { + foreach ($histories as $history) { + $downloaded_total += $history['downloaded']; + $uploaded_total += $history['uploaded']; + } } $downloaded_total = floor($downloaded_total / 1048567); diff --git a/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrent.php b/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrent.php index 8b7516c..1b7435e 100755 --- a/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrent.php +++ b/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrent.php @@ -24,22 +24,30 @@ public function getData() $torrent['size'] = $this->formatSize($torrent['size']); $torrent['info_hash'] = $this->formatHash($torrent['info_hash']); $torrent['list'] = $this->_getTorrentFileService()->getTorrentFileByTorrent($torrent['id']); - if (isset($torrent['list'])) { + + if (is_array($torrent['list'])) { foreach ($torrent['list'] as $key => $value) { $torrent['list'][$key]['size'] = $this->formatSize($value['size']); } } - $peers = $this->_getTorrentPeerService()->getTorrentPeerByTorrent($torrent['id']); + $seeder = $leecher = 0; - foreach ($peers as $peer) { - if ($peer['seeder'] == 'yes') { - $seeder++; - } else { - $leecher++; + + $peers = $this->_getTorrentPeerService()->getTorrentPeerByTorrent($torrent['id']); + + if (is_array($peers)) { + foreach ($peers as $peer) { + if ($peer['seeder'] == 'yes') { + $seeder++; + } else { + $leecher++; + } } } + $torrent['seeder'] = ($seeder == 0) ? '断种' : $seeder; $torrent['leecher'] = $leecher; + $this->torrent = $torrent; } diff --git a/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrentSide.php b/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrentSide.php index 4615f1f..b2f45e5 100755 --- a/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrentSide.php +++ b/extensions/torrent/service/srv/do/PwThreadDisplayDoTorrentSide.php @@ -10,17 +10,22 @@ public function __construct() {} public function createHtmlAfterUserInfo($user, $read) { - if (!in_array('threadside', Wekit::C('site', 'app.torrent.showuserinfo'))) { - return ''; + $showuserinfo = Wekit::C('site', 'app.torrent.showuserinfo'); + + if (is_array($showuserinfo) && !in_array('threadside', $showuserinfo)) { + return; } + $torrents = Wekit::load('EXT:torrent.service.PwTorrent')->fetchTorrentByUid($user['uid']); $histories = Wekit::load('EXT:torrent.service.PwTorrentHistory')->fetchTorrentHistoryByUid($user['uid']); $posted = count($torrents); - foreach ($histories as $history) { - $downloaded_total += $history['downloaded']; - $uploaded_total += $history['uploaded']; + if (is_array($histories)) { + foreach ($histories as $history) { + $downloaded_total += $history['downloaded']; + $uploaded_total += $history['uploaded']; + } } $downloaded_total = floor($downloaded_total / 1048567); diff --git a/extensions/torrent/service/srv/do/PwThreadListDoTorrent.php b/extensions/torrent/service/srv/do/PwThreadListDoTorrent.php index 9764795..21fa8ff 100755 --- a/extensions/torrent/service/srv/do/PwThreadListDoTorrent.php +++ b/extensions/torrent/service/srv/do/PwThreadListDoTorrent.php @@ -12,15 +12,21 @@ public function bulidThread($thread) { if (isset($thread['special']) && $thread['special'] == 'torrent' && Wekit::C('site', 'theme.site.default') == 'pt' && !empty(Wekit::C('site', 'app.torrent.theme.showpeers'))) { $torrent = Wekit::load('EXT:torrent.service.PwTorrent')->getTorrentByTid($thread['tid']); - $peers = Wekit::load('EXT:torrent.service.PwTorrentPeer')->getTorrentPeerByTorrent($torrent['id']); + $seeder = $leecher = 0; - foreach ($peers as $peer) { - if ($peer['seeder'] == 'yes') { - $seeder++; - } else { - $leecher++; + + $peers = Wekit::load('EXT:torrent.service.PwTorrentPeer')->getTorrentPeerByTorrent($torrent['id']); + + if (is_array($peers)) { + foreach ($peers as $peer) { + if ($peer['seeder'] == 'yes') { + $seeder++; + } else { + $leecher++; + } } } + $thread['seeder'] = $seeder; $thread['leecher'] = $leecher; } diff --git a/extensions/torrent/service/srv/do/PwThreadsBatchDeleteDoTorrent.php b/extensions/torrent/service/srv/do/PwThreadsBatchDeleteDoTorrent.php index 1ac391f..631afe0 100755 --- a/extensions/torrent/service/srv/do/PwThreadsBatchDeleteDoTorrent.php +++ b/extensions/torrent/service/srv/do/PwThreadsBatchDeleteDoTorrent.php @@ -8,15 +8,22 @@ public function appDo($ids) { $torrentDs = Wekit::load('EXT:torrent.service.PwTorrent'); $fileDs = Wekit::load('EXT:torrent.service.PwTorrentFile'); - foreach ($ids as $id) { - $torrent = $torrentDs->getTorrentByTid($id); - $files = $fileDs->getTorrentFileByTorrent($torrent['id']); - foreach ($files as $file) { - $fileDs->deleteTorrentFile($file['id']); - } - $torrentDs->deleteTorrent($torrent['id']); - @unlink(WEKIT_PATH . '../torrent/' . $torrent['id'] . '.torrent'); + if (is_array($ids)) { + foreach ($ids as $id) { + $torrent = $torrentDs->getTorrentByTid($id); + $files = $fileDs->getTorrentFileByTorrent($torrent['id']); + + if (is_array($files)) { + foreach ($files as $file) { + $fileDs->deleteTorrentFile($file['id']); + } + } + + $torrentDs->deleteTorrent($torrent['id']); + + @unlink(WEKIT_PATH . '../torrent/' . $torrent['id'] . '.torrent'); + } } } } diff --git a/extensions/torrent/service/srv/do/PwThreadsDeleteDoTorrent.php b/extensions/torrent/service/srv/do/PwThreadsDeleteDoTorrent.php index 5a73d15..3899dee 100755 --- a/extensions/torrent/service/srv/do/PwThreadsDeleteDoTorrent.php +++ b/extensions/torrent/service/srv/do/PwThreadsDeleteDoTorrent.php @@ -11,11 +11,15 @@ public function appDo($id) $torrent = $torrentDs->getTorrentByTid($id); $files = $fileDs->getTorrentFileByTorrent($torrent['id']); - foreach ($files as $file) { - $fileDs->deleteTorrentFile($file['id']); + + if (is_array($files)) { + foreach ($files as $file) { + $fileDs->deleteTorrentFile($file['id']); + } } $torrentDs->deleteTorrent($torrent['id']); + @unlink(WEKIT_PATH . '../torrent/' . $torrent['id'] . '.torrent'); } } diff --git a/extensions/torrent/service/srv/helper/PwAnnounce.php b/extensions/torrent/service/srv/helper/PwAnnounce.php index c37312d..42d5ffc 100755 --- a/extensions/torrent/service/srv/helper/PwAnnounce.php +++ b/extensions/torrent/service/srv/helper/PwAnnounce.php @@ -32,6 +32,7 @@ public static function updatePeerCount($torrent, $peer_list) { $torrent['seeders'] = 0; $torrent['leechers'] = 0; + if (is_array($torrent) && is_array($peer_list)) { foreach ($peer_list as $peer) { if ($peer['seeder'] == 'yes') { @@ -41,6 +42,7 @@ public static function updatePeerCount($torrent, $peer_list) } } } + return $torrent; } @@ -51,8 +53,11 @@ public static function buildPeerList($torrent, $peer_list, $compact, $no_peer_id $string = 'd' . $bencode->doEncodeString('interval') . 'i840e' . $bencode->doEncodeString('min interval') . 'i30e' . $bencode->doEncodeString('complete') . 'i' . $torrent['seeders'] . 'e' . $bencode->doEncodeString('incomplete') . 'i' . $torrent['leechers'] . 'e' . $bencode->doEncodeString('peers'); $peer_string = ''; + if (is_array($peer_list)) { + $count = count($peer_list); + foreach ($peer_list as $peer) { if ($compact) { $peer_string .= str_pad(pack('Nn', ip2long($peer['ip']), $peer['port']), 6); @@ -63,11 +68,13 @@ public static function buildPeerList($torrent, $peer_list, $compact, $no_peer_id } } } + if ($compact) { $string .= $bencode->doEncodeString($peer_string); } else { $string .= 'l' . $peer_string . 'e'; } + return $string . 'e'; } diff --git a/extensions/torrent/template/admin/manage_agent.htm b/extensions/torrent/template/admin/manage_agent.htm index d2de32c..5e1a7fe 100755 --- a/extensions/torrent/template/admin/manage_agent.htm +++ b/extensions/torrent/template/admin/manage_agent.htm @@ -38,6 +38,7 @@ + {$key} @@ -59,6 +60,7 @@ [删除] + diff --git a/extensions/torrent/template/admin/manage_credit.htm b/extensions/torrent/template/admin/manage_credit.htm index 481796a..32c9cb7 100755 --- a/extensions/torrent/template/admin/manage_credit.htm +++ b/extensions/torrent/template/admin/manage_credit.htm @@ -51,6 +51,7 @@ + {$type} @@ -63,6 +64,7 @@ + 可用的变量: downloaded 当前种子下载量, downloaded_total 用户总下载量, uploaded 当前种子上传量, uploaded_total 用户总上传量, rotio 当前种子分享率, rotio_total 用户总分享率, time 当前peer连接时长, credit 当前积分持有量, torrents 用户发布种子数 diff --git a/extensions/torrent/template/admin/manage_run.htm b/extensions/torrent/template/admin/manage_run.htm index 3339c63..d599b55 100755 --- a/extensions/torrent/template/admin/manage_run.htm +++ b/extensions/torrent/template/admin/manage_run.htm @@ -108,12 +108,14 @@
  • 后缀名(小写)
  • +
  • [删除]
  • + 添加文件类型 diff --git a/extensions/torrent/template/index_my.htm b/extensions/torrent/template/index_my.htm index cdec487..12ff4ee 100644 --- a/extensions/torrent/template/index_my.htm +++ b/extensions/torrent/template/index_my.htm @@ -33,12 +33,14 @@

    种子标题
    操作
    +
    {$torrent['subject']}
    取消订阅
    + diff --git a/extensions/torrent/template/read_injector_before_torrent.htm b/extensions/torrent/template/read_injector_before_torrent.htm index f7588b4..93baf0d 100755 --- a/extensions/torrent/template/read_injector_before_torrent.htm +++ b/extensions/torrent/template/read_injector_before_torrent.htm @@ -63,7 +63,7 @@
  • 文件数量:共有{$torrent['numfiles']}个文件文件大小:{$torrent['size']}