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

Commit

Permalink
feat(Torrent): Show team, quality information in torrent/details page
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Aug 18, 2019
1 parent 66998d3 commit 44314e3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 41 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
- **template:** Add git commit hash in `CHANGELOG.md` (76bc527)

### Feat
- **Auth:** Sep Auth part from Site to new components (f36884e)
- **Auth:** Add Auth By passkey support for special route (aff1f87)
- **Auth:** Use JWT to set cookies content (bf897c6)
- **Auth:** Add Auth By passkey support for special route (aff1f87)
- **Auth:** Sep Auth part from Site to new components (f36884e)
- **Auth/Login:** Add full Advanced Options support (6009dc8)
- **Secret:** Check session and user_id match or not in jwt payload (358ba5d)
- **Secret:** Protect jwt key for env('APP_SECRET_KEY') (dfa67da)
- **Sessions:** record user access information at Auth->onRequestAfter() (e2a22a7)
- **Sessions/List:** Use SessionsListForm to show user sessions (9ecfb97)
- **Site:** Add page Site/{Logs,Rules} (65cea9e)
- **Torrent/Download:** Add user download pos check (db6d5ff)
- **Torrent/Search:** Use MySQL fulltext search. (354c07b)
- **ban_ips:** Store banned ip in components/Site (01084c9)
Expand Down Expand Up @@ -163,7 +164,7 @@
- **View:** Rename folder `error` to `action` (f5344af)
- **action_success:** Simple The Action Template (9facda1)
- **array/function:** move setDefault to \Rid class (b49d529)
- **auth/error:** merge `auth/error` page to `action/success` (9f02aae)
- **auth/error:** merge `auth/error` page to `action/action_success` (9f02aae)
- **class/cache:** Use trait to simple class value cache (9913873)
- **site/torrent_upload_rule:** Move rule loader to \library\Site::class (ed01663)
- **torrent/download:** Separate Torrent::getDownloadDict to torrent\DownloadForm (4b617ca)
Expand Down
10 changes: 7 additions & 3 deletions apps/components/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ public function ruleQuality($quality): array
{
if (!in_array($quality, array_keys($this->getQualityTableList()))) throw new \RuntimeException('Unregister quality : ' . $quality);
if (false === $data = config('runtime.enabled_quality_' . $quality)) {
$data = [];

/** @noinspection SqlResolve */
$data = app()->pdo->createCommand("SELECT * FROM `quality_$quality` WHERE `id` > 0 AND `enabled` = 1 ORDER BY `sort_index`,`id`")->queryAll();
$data_raws = app()->pdo->createCommand("SELECT * FROM `quality_$quality` WHERE `id` > 0 AND `enabled` = 1 ORDER BY `sort_index`,`id`")->queryAll();
foreach ($data_raws as $data_raw) $data[$data_raw['id']] = $data_raw;
app()->config->set('runtime.enabled_quality_' . $quality, $data, 'json');
}
return $data ?: [];
Expand All @@ -166,8 +169,9 @@ public function ruleQuality($quality): array
public function ruleTeam(): array
{
if (false === $data = config('runtime.enabled_teams')) {
/** @noinspection SqlResolve */
$data = app()->pdo->createCommand('SELECT * FROM `teams` WHERE `id` > 0 AND `enabled` = 1 ORDER BY `sort_index`,`id`')->queryAll();
$data = [];
$data_raws = app()->pdo->createCommand('SELECT * FROM `teams` WHERE `id` > 0 AND `enabled` = 1 ORDER BY `sort_index`,`id`')->queryAll();
foreach ($data_raws as $data_raw) $data[$data_raw['id']] = $data_raw;
app()->config->set('runtime.enabled_teams', $data, 'json');
}

Expand Down
28 changes: 19 additions & 9 deletions apps/models/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class Torrent
private $torrent_size;
private $torrent_structure;

protected $comment_perpage = 10;
private $team;

protected $comment_perpage = 10; // FIXME

const TORRENT_TYPE_SINGLE = 'single';
const TORRENT_TYPE_MULTI = 'multi';
Expand Down Expand Up @@ -170,6 +172,22 @@ public function getTorrentStructure(): array
return json_decode($this->torrent_structure, true);
}

public function getTeam(){
if ($this->team == 0) return false;
return app()->site->ruleTeam()[$this->team];
}

public function getQuality($quality)
{
if ($this->{'quality_' . $quality} == 0) return false;
return app()->site->ruleQuality($quality)[$this->{'quality_' . $quality}];
}

public function getDescr(): string
{
return $this->descr;
}

/**
* @return array like [<tag1>, <tag2>, <tag3>]
*/
Expand All @@ -193,14 +211,6 @@ public function getPinnedTags(): array
return $pinned_tags;
}

/**
* @return mixed
*/
public function getDescr()
{
return $this->descr;
}

public function getUplver(): bool
{
return (boolean)$this->uplver;
Expand Down
79 changes: 53 additions & 26 deletions apps/views/torrent/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,34 @@
<div class="row torrent-details-block">
<div class="col-md-8">
<div class="panel" id="torrent_descr_panel">
<div class="panel-body">
<div class="ubbcode-block" id="torrent_descr">
<article class="panel-body article">
<header>
<dl class="dl-inline">
<!-- Team -->
<?php if ($torrent->getTeam()): ?>
<dt>Team:</dt>
<dd><?= $torrent->getTeam()['name']; ?></dd>
<?php endif; ?>

<!-- Quality -->
<?php foreach (app()->site->getQualityTableList() as $quality => $title): ?>
<?php if (config('torrent_upload.enable_quality_' . $quality) && $torrent->getQuality($quality)) : ?>
<dt><?= $title ?>:</dt>
<dd><?= $torrent->getQuality($quality)['name'] ?></dd>
<?php endif; ?>
<?php endforeach; ?>

<dt></dt>
<dd class="pull-right">
<span class="label label-success">豆瓣</span>
<span class="label label-warning">Imdb</span>
</dd>
</dl>
</header>
<section class="content ubbcode-block" id="torrent_descr">
<?= $this->batch($torrent->getDescr() ?? '[h4]No description.[/h4]','format_ubbcode') ?>
</div>
</div>
</section>
</article>
</div> <!-- END //*[@id="torrent_descr"] -->
<div class="panel" id="torrent_commit_panel">
<div class="panel-heading">
Expand All @@ -44,6 +67,29 @@
</div>
</div>
<div class="col-md-4" id="torrent_extend_info_panel_group">
<div class="panel" id="torrent_info_panel">
<div class="panel-heading"><b>Torrent Information</b></div>
<div class="panel-body" id="torrent_information">
<div data-field="category"><b>Type:</b> <?= $torrent->getCategory()['name'] ?></div>
<div data-field="added_date"><b>Uploaded Date:</b> <?= $torrent->getAddedAt() ?></div>
<div data-field="size"><b>File size:</b> <?= $this->e($torrent->getTorrentSize(), 'format_bytes') ?></div>
<div data-field="uploader"><b>Uploader:</b> <?= $this->insert('helper/username', ['user' => $torrent->getOwner(), 'hide' => $torrent->getUplver()]) ?></div>
<div data-field="peers">
<b>Peers:</b>
<span class="green"><i class="fas fa-arrow-up fa-fw"></i> <?= $torrent->getComplete() ?></span> /
<span class="red"><i class="fas fa-arrow-down fa-fw"></i> <?= $torrent->getIncomplete() ?></span> /
<span><i class="fas fa-check fa-fw"></i> <?= $torrent->getDownloaded() ?></span>
</div>
<div data-field="info_hash"><b>Info Hash:</b><kbd><?= $torrent->getInfoHash() ?></kbd></div>
<hr>
<div data-field="quality">



</div>

</div>
</div>
<div class="panel" id="torrent_action_panel">
<div class="panel-heading"><b>Torrent Action</b></div>
<div class="panel-body" id="torrent_action">
Expand All @@ -70,7 +116,7 @@
<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><!-- View Torrent's Files -->
<?php if($torrent->hasNfo()): // TODO add global config key of NFO ?>
<?php if ($torrent->hasNfo()): // TODO add global config key of NFO ?>
<div class="torrent-action-item">
<a class="torrent-nfo" href="javascript:" data-tid="<?= $torrent->getId() ?>"><i class="fas fa-info fa-fw"></i>&nbsp;View Torrent's Nfo file</a>
</div><!-- View Torrent's Nfo -->
Expand All @@ -87,33 +133,14 @@
</div><!-- View Torrent's Structure -->
</div>
</div>
<div class="panel" id="torrent_info_panel">
<div class="panel-heading"><b>Torrent Information</b></div>
<div class="panel-body" id="torrent_information">
<div data-field="added_date" data-timestamp="<?= strtotime($torrent->getAddedAt()) ?>">
<b>Uploaded Date:</b> <?= $torrent->getAddedAt() ?></div>
<div data-field="size" data-filesize="<?= $torrent->getTorrentSize() ?>">
<b>File size:</b> <?= $this->e($torrent->getTorrentSize(), 'format_bytes') ?></div>
<div data-field="uploader" data-owner-id="<?= $torrent->getUplver() ? 0 : $torrent->getOwnerId(); ?>">
<b>Uploader:</b> <?= $this->insert('helper/username', ['user' => $torrent->getOwner(), 'hide' => $torrent->getUplver()]) ?>
</div>
<div data-field="peers" data-seeders="<?= $torrent->getComplete() ?>" data-leechers="<?= $torrent->getComplete() ?>" data-completed="<?= $torrent->getDownloaded() ?>">
<b>Peers:</b>
<span class="green"><i class="fas fa-arrow-up fa-fw"></i> <?= $torrent->getComplete() ?></span> /
<span class="red"><i class="fas fa-arrow-down fa-fw"></i> <?= $torrent->getIncomplete() ?></span> /
<span><i class="fas fa-check fa-fw"></i> <?= $torrent->getDownloaded() ?></span>
</div>
<div data-field="info_hash" data-infohash="<?= $torrent->getInfoHash() ?>"><b>Info Hash:</b>
<kbd><?= $torrent->getInfoHash() ?></kbd></div>
</div>
</div>
<div class="panel" id="torrent_tags_panel">
<div class="panel-heading"><b>Torrent Tags</b></div>
<div class="panel-body" id="torrent_tags">
<?php $tags = $torrent->getTags(); ?>
<?php if (count($tags) > 0) : ?>
<?php $pinned_tags = $torrent->getPinnedTags(); ?>
<?php foreach ($tags as $tag): ?>
<a href="/torrents/tags?tag=<?= $tag ?>" class="label label-outline"><?= $tag ?></a>
<a href="/torrents/search?tags=<?= $tag ?>" class="label label-outline <?= array_key_exists($tag,$pinned_tags) ? $pinned_tags[$tag] : '' ?>"><?= $tag ?></a>
<?php endforeach; ?>
<?php else: ?>
<span class="text-muted">No tags for this torrent</span>
Expand Down

0 comments on commit 44314e3

Please sign in to comment.