Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
refactor(Route): Fix Route of Torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Mar 16, 2019
1 parent 3a1780b commit c2282ec
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 70 deletions.
76 changes: 76 additions & 0 deletions apps/controllers/TorrentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 2019/3/16
* Time: 16:53
*/

namespace apps\controllers;

use apps\models\Torrent;
use apps\models\form\TorrentUploadForm;

use Rid\Http\Controller;

class TorrentController extends Controller
{
public function actionDetails()
{
$tid = app()->request->get('id');
$torrent = new Torrent($tid);

return $this->render('torrent/details', ['torrent' => $torrent]);
}

public function actionUpload()
{
// TODO Check user upload pos
if (app()->request->isPost()) {
$torrent = new TorrentUploadForm();
$torrent->setData(app()->request->post());
$torrent->setFileData(app()->request->files());
$success = $torrent->validate();
if (!$success) {
return $this->render('errors/action_fail', ['title' => 'Upload Failed', 'msg' => $torrent->getError()]);
} else {
try {
$torrent->flush();
} catch (\Exception $e) {
return $this->render('errors/action_fail', ['title' => 'Upload Failed', 'msg' => $e->getMessage()]);
}

return app()->response->redirect('/torrent/details?id=' . $torrent->id);
}

} else {
// TODO Check user can upload
return $this->render('torrent/upload');
}

}

public function actionDownload()
{
$tid = app()->request->get('id');

$torrent = new Torrent($tid); // If torrent is not exist or can't visit , a notfound exception will throw out........
$filename = '[' . app()->config->get('base.site_name') . ']' . $torrent->getTorrentName() . '.torrent';

app()->response->setHeader('Content-Type', 'application/x-bittorrent');
if (strpos(app()->request->header('user-agent'), 'IE')) {
app()->response->setHeader('Content-Disposition', 'attachment; filename=' . str_replace('+', '%20', rawurlencode($filename)));
} else {
app()->response->setHeader('Content-Disposition', "attachment; filename=\"$filename\" ; charset=utf-8");
}

return $torrent->getDownloadDict(true);
}

public function actionStructure() {
$tid = app()->request->get('id');

$torrent = new Torrent($tid); // If torrent is not exist or can't visit , a notfound exception will throw out........
return $this->render('torrent/structure',['torrent'=> $torrent]);
}
}
54 changes: 0 additions & 54 deletions apps/controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Rid\Http\Controller;

use apps\models\Torrent;
use apps\models\form\TorrentUploadForm;


class TorrentsController extends Controller
{
Expand All @@ -32,60 +30,8 @@ public function actionIndex()

}

public function actionUpload()
{
// TODO Check user upload pos
if (app()->request->isPost()) {
$torrent = new TorrentUploadForm();
$torrent->setData(app()->request->post());
$torrent->setFileData(app()->request->files());
$success = $torrent->validate();
if (!$success) {
return $this->render('errors/action_fail', ['title' => 'Upload Failed', 'msg' => $torrent->getError()]);
} else {
try {
$torrent->flush();
} catch (\Exception $e) {
return $this->render('errors/action_fail', ['title' => 'Upload Failed', 'msg' => $e->getMessage()]);
}

return app()->response->redirect('/torrents/details?id=' . $torrent->id);
}

} else {
// TODO Check user can upload
return $this->render('torrents/upload');
}

}

public function actionSearch()
{

}

public function actionDetails()
{
$tid = app()->request->get('id');
$torrent = new Torrent($tid);

return $this->render('torrents/details', ['torrent' => $torrent]);
}

public function actionDownload()
{
$tid = app()->request->get('id');

$torrent = new Torrent($tid); // If torrent is not exist or can't visit , a notfound exception will throw out........
$filename = '[' . app()->config->get('base.site_name') . ']' . $torrent->getTorrentName() . '.torrent';

app()->response->setHeader('Content-Type', 'application/x-bittorrent');
if (strpos(app()->request->header('user-agent'), 'IE')) {
app()->response->setHeader('Content-Disposition', 'attachment; filename=' . str_replace('+', '%20', rawurlencode($filename)));
} else {
app()->response->setHeader('Content-Disposition', "attachment; filename=\"$filename\" ; charset=utf-8");
}

return $torrent->getDownloadDict(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @param \apps\models\Torrent $torrent
* @return string
*/

function get_torrent_uploader_id(\apps\models\Torrent $torrent)
{
if ($torrent->getUplver() == 'yes' and app()->user->getClass(true) < app()->config->get('authority.see_anonymous_uploader')) {
Expand All @@ -24,6 +23,10 @@ function get_torrent_uploader_id(\apps\models\Torrent $torrent)
}
}

/**
* @param \apps\models\Torrent $torrent
* @return string
*/
function get_torrent_uploader(\apps\models\Torrent $torrent)
{
$owner_id = get_torrent_uploader_id($torrent);
Expand Down
2 changes: 1 addition & 1 deletion apps/views/layout/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/forums', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/forums"><?= __('nav_forums') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/torrents', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/torrents"><?= __('nav_torrents') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/torrents/request', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/torrents/request"><?= __('nav_requests') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/torrents/upload', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/torrents/upload"><?= __('nav_upload') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/torrent/upload', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/torrents/upload"><?= __('nav_upload') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/subtitles', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/subtitles"><?= __('nav_subtitles') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/site/topten', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/site/topten"><?= __('nav_topten') ?></a></li>
<li class="layui-nav-item<?= /** @noinspection PhpUndefinedMethodInspection */ $this->uri('/site/about', ' layui-this'); ?>"><!--suppress HtmlUnknownTarget --><a href="/site/about"><?= __('nav_faq') ?></a></li>
Expand Down
6 changes: 3 additions & 3 deletions apps/views/rss_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
<?php foreach ($torrents as $torrent): ?>
<item>
<title><![CDATA[<?= $torrent->getTitle() ?>]]></title>
<link><?= $url.'/torrents/details?id=' . $torrent->getId() ?></link>
<link><?= $url.'/torrent/details?id=' . $torrent->getId() ?></link>
<description><?= $torrent->getDescr() ?></description>
<author><?= ($torrent->getUplver() == 'yes' ? 'Anonymous' : $torrent->getOwner()->getUsername()) . '@' . $site_name ?></author>
<category domain="<?= $url . '/torrents?cat='.$torrent->getCategoryId()?>">Movie</category>
<comments><![CDATA[<?= $url. '/torrents/details?id=' . $torrent->getId() . '&cmtpage=0#startcomments' ?>]]></comments>
<enclosure url="<?= $url . '/torrents/download?id=' . $torrent->getId() . ('') ?>" length="<?= $torrent->getTorrentSize() ?>" type="application/x-bittorrent" />
<comments><![CDATA[<?= $url. '/torrent/details?id=' . $torrent->getId() . '&cmtpage=0#startcomments' ?>]]></comments>
<enclosure url="<?= $url . '/torrent/download?id=' . $torrent->getId() . ('') ?>" length="<?= $torrent->getTorrentSize() ?>" type="application/x-bittorrent" />
<guid isPermaLink="false"><?= $torrent->getInfoHash() ?></guid>
<pubDate><?= date('r',strtotime($torrent->getAddedAt())) ?></pubDate>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* @var \apps\models\Torrent $torrent
*/

include 'helper.php';
?>

<?php $this->insert('common/helper') ?>

<?= $this->layout('layout/base') ?>

<?php $this->start('title')?><?= $torrent->getTitle() ?><?php $this->end();?>
Expand Down Expand Up @@ -45,8 +46,8 @@
<div class="layui-card-header"><b>Torrent Action</b></div>
<div class="layui-card-body">
<div class="torrent-action-item"><!--suppress HtmlUnknownTarget -->
<a href="/torrents/download?id=<?= $torrent->getId() ?>"><i class="fa fa-download fa-fw"></i>&nbsp;Download Torrent</a>
</div><!-- Download Torrent -->
<a href="/torrent/download?id=<?= $torrent->getId() ?>"><i class="fa fa-download fa-fw"></i>&nbsp;Download Torrent</a>
</div><!-- Download TorrentController -->
<div class="torrent-action-item">
<a class="torrent-favour" href="javascript:" data-tid="<?= $torrent->getId() ?>"><i class="<?= app()->user->inBookmarkList($torrent->getId()) ? 'fas' : 'far' ?> fa-star fa-fw"></i>&nbsp;Add to Favour</a>
</div><!-- TODO Add to Favour -->
Expand All @@ -55,18 +56,18 @@
</div><!-- TODO Add to RSS Basket -->
<hr>
<div class="torrent-action-item"><!--suppress HtmlUnknownTarget -->
<a class="torrent-edit" href="/torrents/edit?id=<?= $torrent->getId() ?>"><i class="fas fa-edit fa-fw"></i>&nbsp;Edit/Remove this Torrent</a>
</div><!-- TODO Edit/Remove this Torrent -->
<a class="torrent-edit" href="/torrent/edit?id=<?= $torrent->getId() ?>"><i class="fas fa-edit fa-fw"></i>&nbsp;Edit/Remove this Torrent</a>
</div><!-- TODO Edit/Remove this TorrentController -->
<div class="torrent-action-item"><!--suppress HtmlUnknownTarget -->
<a class="torrent-report" href="/report?type=torrent&id=<?= $torrent->getId() ?>"><i class="fa fa-bug fa-fw"></i>&nbsp;Report this Torrent</a>
</div><!-- TODO Report this Torrent -->
</div><!-- TODO Report this TorrentController -->
<hr>
<div class="torrent-action-item"><!--suppress HtmlUnknownTarget -->
<a class="torrent-files" href="javascript:" data-tid="<?= $torrent->getId() ?>"><i class="fas fa-file fa-fw"></i>&nbsp;View Torrent's Files</a>
</div><!-- TODO View Torrent's Files -->
</div><!-- TODO View TorrentController's Files -->
<div class="torrent-action-item"><!--suppress HtmlUnknownTarget -->
<a class="torrent-structure" href="javascript:" data-tid="<?= $torrent->getId() ?>"><i class="fas fa-folder-open fa-fw"></i>&nbsp;View Torrent's Structure</a>
</div><!-- TODO View Torrent's Structure -->
</div><!-- TODO View TorrentController's Structure -->
</div>
</div>
<div class="layui-card" id="torrent-info-card">
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions apps/views/torrents/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
* @var \apps\models\Torrent $torrent
*/

include 'helper.php';
$time_now = time();
?>

<?php $this->insert('common/helper') ?>

<?= $this->layout('layout/base') ?>

<?php $this->start('title')?>Torrents List<?php $this->end();?>
Expand All @@ -40,12 +41,12 @@
<td>
<div class="pull-left">
<!--suppress HtmlUnknownTarget -->
<a href="/torrents/details?id=<?= $torrent->getId() ?>" target="_blank"><?= $torrent->getTitle() ?></a>
<a href="/torrent/details?id=<?= $torrent->getId() ?>" target="_blank"><?= $torrent->getTitle() ?></a>
</div>
<div class="pull-right">
<div class="text-center" style="width: 5px">
<!--suppress HtmlUnknownTarget -->
<a href="/torrents/download?id=<?= $torrent->getId() ?>"><i class="fas fa-download"></i></a>
<a href="/torrent/download?id=<?= $torrent->getId() ?>"><i class="fas fa-download"></i></a>
<a class="torrent-favour" href="javascript:" data-tid="<?= $torrent->getId() ?>"><i class="<?= app()->user->inBookmarkList($torrent->getId()) ? 'fas' : 'far' ?> fa-star"></i></a>
</div>
</div>
Expand Down

0 comments on commit c2282ec

Please sign in to comment.