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

Commit

Permalink
feat(Gravatar): Add support of gravatar
Browse files Browse the repository at this point in the history
1. Add support of gravatar
2. Fix Behaviour of display username
  • Loading branch information
Rhilip committed Aug 1, 2019
1 parent 134153f commit 4252f8d
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 69 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
- **gitignore:** Add ignore of `/backup` folder

### Feat
- **Category:** Add Categories Support when upload torrent
- **Category:** Add Categories Manage Pane
- **Category:** Add Categories Support when upload torrent
- **Crontab:** Move From Timer to Process
- **Process:** Add custom Process Support
- **Redis:** Add mutiDelete() function for Redis
- **Tracker:** Add `retry in` field when failed
- **Tracker:** Move From Timer to Process
- **Tracker:** Add `retry in` field when failed
- **User:** Add Bonus And Unread Messsage count
- **UserInfo:** Add Cache Lock of user access_{time,ip} update
- **ban:** Add table `ban_usernames` and `ban_emails`
- **csrf:** Add Csrf Support
Expand Down
9 changes: 1 addition & 8 deletions apps/models/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,9 @@ public function getId()
return $this->id;
}

/** FIXME move it to view
* @return mixed
*/
public function getOwnerId()
{
if ($this->getUplver() == 'yes' and !app()->site->getCurUser()->isPrivilege('see_anonymous_uploader')) {
return 0;
} else {
return $this->owner_id;
}
return $this->owner_id;
}

public function getOwner()
Expand Down
27 changes: 23 additions & 4 deletions apps/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,31 @@ public function getClass($raw = false)
}

/** TODO use gravatar
* @param array $opts
* @return mixed
*/
public function getAvatar()
{
if ($this->avatar == '') {
$this->avatar = '/static/avatar/default_avatar.jpg';
public function getAvatar($opts = [])
{
if (config('user.avatar_provider') === 'gravatar') {
/** Get a Gravatar URL for a specified email address.
*
* @param int|string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $d Default imageset to use [ 404 | mp | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
*/
$url = config('gravatar.base_url') . md5(strtolower(trim($this->email)));
$url .= '?' . http_build_query([
's' => $opts['s'] ?? 80,
'd' => $opts['d'] ?? config('gravatar.default_fallback') ?? 'identicon',
'r' => $opts['r'] ?? config('gravatar.maximum_rating') ?? 'g'
]);
return $url;
}/* elseif (config('user.avatar_provider') === 'remote') {
// For example : another Image Hosting
}*/ else { // config('user.avatar_provider') === 'local'
if ($this->avatar == '') {
$this->avatar = '/static/avatar/default_avatar.jpg';
}
}

return $this->avatar;
Expand Down
7 changes: 6 additions & 1 deletion apps/process/CronTabProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ protected function clean_dead_peer()
$this->print_log('Success clean ' . $affect_peer_count . ' peers from our peer list');
}

protected function calculate_seeding_bonus()
{
// TODO
}

protected function clean_expired_session()
{
$timenow = time();
Expand All @@ -123,7 +128,7 @@ protected function clean_expired_session()
}

$clean_record_count = app()->redis->zRemRangeByScore('Site:Sessions:to_expire', 0, $timenow);
if ($clean_record_count) $this->print_log('Success clean expired Sessions: Database(' . count($expired_sessions) . '), Redis(' . $clean_record_count . ').');
if ($clean_record_count > 0) $this->print_log('Success clean expired Sessions: Database(' . count($expired_sessions) . '), Redis(' . $clean_record_count . ').');
}

protected function expired_invitee()
Expand Down
26 changes: 0 additions & 26 deletions apps/views/common/helper.php

This file was deleted.

27 changes: 27 additions & 0 deletions apps/views/helper/username.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 8/1/2019
* Time: 10:57 AM
*
* @var League\Plates\Template\Template $this
* @var \apps\models\User $user
* @var \apps\models\Torrent $torrent
*/

$torrent = $torrent ?? false;
$user_name_hide = $user_name_hide ?? ($torrent && $torrent->getUplver());
$user_badge = $user_badge ?? false;
?>
<?php if ($user_name_hide): ?>
<i>Anonymous</i>
<?php if (app()->site->getCurUser()->isPrivilege('see_anonymous_uploader')): ?>
(<?= $this->insert('helper/username', ['user' => $user, 'user_name_hide' => false, 'user_badge' => $user_badge]) ?>)
<?php endif; ?>
<?php else: ?>
<a href="/user?id=<?= $user->getId() ?>"><?= $user->getUsername() ?></a>
<?php if ($user_badge): ?>
<!-- TODO -->
<?php endif; ?>
<?php endif; ?>
4 changes: 3 additions & 1 deletion apps/views/layout/nav_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* User: Rhilip
* Date: 7/21/2019
* Time: 8:19 AM
*
* @var League\Plates\Template\Template $this
*/

$user = app()->site->getCurUser();
Expand Down Expand Up @@ -40,7 +42,7 @@

<div id="info_block">
<div id="info_block_line_1">
Welcome Back, <a href="/user" data-user-id="<?= $user->getId() ?>"><?= $user->getUsername() ?></a>&nbsp;
Welcome Back, <?= $this->insert('helper/username', ['user' => $user, 'user_name_hide' => false, 'user_badge' => true]) ?>
<span data-item="logout"><!--suppress HtmlUnknownTarget -->[<a href="/auth/logout">Logout</a>]</span>
<?php if ($user->getClass(true) > \apps\models\User::ROLE_FORUM_MODERATOR): ?>
<span><!--suppress HtmlUnknownTarget -->[<a href="/admin">Admin Panel</a>]</span>
Expand Down
2 changes: 1 addition & 1 deletion apps/views/rss_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<title><![CDATA[<?= $torrent->getTitle() ?>]]></title>
<link><?= $url.'/torrent/details?id=' . $torrent->getId() ?></link>
<description><?= $torrent->getDescr() ?></description>
<author><?= ($torrent->getUplver() == 'yes' ? 'Anonymous' : $torrent->getOwner()->getUsername()) . '@' . $site_name ?></author>
<author><?= ($torrent->getUplver() ? 'Anonymous' : $torrent->getOwner()->getUsername()) . '@' . $site_name ?></author>
<category domain="<?= $url . '/torrents?cat='.$torrent->getCategoryId()?>">Movie</category>
<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" />
Expand Down
53 changes: 37 additions & 16 deletions apps/views/torrent/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

?>

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

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

<?php $this->start('title')?><?= $torrent->getTitle() ?><?php $this->end();?>
Expand Down Expand Up @@ -44,11 +42,24 @@
<?php if ($torrent->getComments()): ?>
<section class="comments-list">
<?php foreach ($torrent->getLastCommentsDetails() as $commit): ?>
<?php $user = app()->site->getUser($commit['owner_id']); // TODO FIX if this user is upload and is uplver ?>
<div id="commit_<?= $commit['id'] ?>" class="comment">
<a href="#" class="avatar">
<i class="icon-user icon-2x"></i> <!-- TODO FIX user's avatar -->
</a>
<?php
$commit_user = app()->site->getUser($commit['owner_id']);

// The details of commentator should be hide or not ?
$commentator_hide_flag = false;
if ($torrent->getUplver() && // The torrent is uplver
$commit['owner_id'] == $torrent->getOwnerId() && // Commentator is the uploader for this torrent
!app()->site->getCurUser()->isPrivilege('see_anonymous_uploader') // CurUser can't see uploader detail
) $commentator_hide_flag = true;
?>
<div id="commit_<?= $commit['id'] ?>" class="comment">
<div class="avatar">
<?php if ($commentator_hide_flag): ?>
<i class="icon-user icon-3x"></i>
<?php else: ?>
<img src="<?= $commit_user->getAvatar() ?>" alt="">
<?php endif; ?>
</div>
<div class="content">
<div class="pull-right text-muted">
<a href="#commit_<?= $commit['id'] ?>">#<?= $commit['id'] ?></a> -
Expand All @@ -58,8 +69,10 @@
<span>Created at <?= $commit['create_at'] ?> </span>
<?php endif; ?>
</div>
<div><a href="/user/"><strong><?= $user->getUsername(); ?></strong></a></div>
<div class="text ubbcode-block"><?= $this->batch($commit['text'],'format_ubbcode') ?></div>
<div class="comment-username">
<?= $this->insert('helper/username', ['user' => $commit_user, 'torrent' => $torrent, 'user_badge' => true]) ?>
</div>
<div class="text ubbcode-block"><?= $this->batch($commit['text'], 'format_ubbcode') ?></div>
<div class="actions pull-right"> <!-- TODO -->
<a href="##">Report</a>
<a href="##">Reply</a>
Expand All @@ -73,8 +86,8 @@
<?php endif; ?>
<footer>
<div class="reply-form" id="commentReplyForm1">
<a href="#" class="avatar"><i class="icon-user icon-2x"></i></a>
<form class="form" method="post" action="/torrent/commit?id=<?= $torrent->getId() ?>">
<div class="avatar"><img src="<?= app()->site->getCurUser()->getAvatar() ?>" alt=""></div>
<form class="form" method="post" action="/torrent/commit?id=<?= $torrent->getId() ?>"> <!-- FIXME commit point -->
<div class="form-group">
<textarea class="form-control new-comment-text" rows="3" placeholder="Quick Commit Here" data-autoresize></textarea>
</div>
Expand Down Expand Up @@ -139,13 +152,21 @@
<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->getOwnerId() ?>"><b>Uploader:</b> <?= get_torrent_uploader($torrent) ?></div>
<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(), 'torrent' => $torrent]) ?>
</div>
<div data-field="peers" data-seeders="<?= $torrent->getComplete() ?>" data-leechers="<?= $torrent->getComplete() ?>" data-completed="<?= $torrent->getDownloaded() ?>">
<b>Peers:</b> <span style="color: green;"><i class="fas fa-arrow-up fa-fw"></i> <?= $torrent->getComplete() ?></span> / <span style="color: 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>
<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 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">
Expand Down
4 changes: 1 addition & 3 deletions apps/views/torrents/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
$time_now = time();
?>

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

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

<?php $this->start('title')?>Torrents List<?php $this->end();?>
Expand Down Expand Up @@ -79,7 +77,7 @@
<td class="text-center" data-item="t-seeder" data-seeder="<?= $this->e($torrent->getComplete()) ?>"><?= number_format($torrent->getComplete()) ?></td>
<td class="text-center" data-item="t-leecher" data-leecher="<?= $this->e($torrent->getIncomplete()) ?>"><?= number_format($torrent->getIncomplete()) ?></td>
<td class="text-center" data-item="t-completed" data-completed="<?= $this->e($torrent->getDownloaded()) ?>"><?= number_format($torrent->getDownloaded()) ?></td>
<td class="text-center" data-item="t-uploader" data-uploader="<?= $this->e($torrent->getOwnerId()) ?>"><?= get_torrent_uploader($torrent) ?></td>
<td class="text-center" data-item="t-uploader" data-uploader="<?= $this->e($torrent->getUplver() ? 0 : $torrent->getOwnerId()) ?>"><?= $this->insert('helper/username', ['user' => $torrent->getOwner(), 'torrent' => $torrent]) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Expand Down
20 changes: 13 additions & 7 deletions migration/ridpt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jul 28, 2019 at 04:37 PM
-- Generation Time: Aug 01, 2019 at 10:50 AM
-- Server version: 8.0.16
-- PHP Version: 7.3.7

Expand Down Expand Up @@ -735,6 +735,9 @@ INSERT INTO `site_config` (`name`, `value`) VALUES
('buff.random_percent_30%', '0'),
('buff.random_percent_50%', '5'),
('buff.random_percent_free', '2'),
('gravatar.base_url', 'https://www.gravatar.com/avatar/'),
('gravatar.default_fallback', 'identicon'),
('gravatar.maximum_rating', 'g'),
('invite.force_interval', '1'),
('invite.interval', '7200'),
('invite.recycle_invite_lifetime', '86400'),
Expand Down Expand Up @@ -790,7 +793,8 @@ INSERT INTO `site_config` (`name`, `value`) VALUES
('tracker.user_max_leech', '1'),
('tracker.user_max_seed', '3'),
('upload.max_nfo_file_size', '65535'),
('upload.max_torrent_file_size', '3145728');
('upload.max_torrent_file_size', '3145728'),
('user.avatar_provider', 'gravatar');

-- --------------------------------------------------------

Expand All @@ -803,7 +807,7 @@ CREATE TABLE IF NOT EXISTS `site_crontab` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`job` varchar(64) NOT NULL,
`priority` int(10) UNSIGNED NOT NULL DEFAULT '100' COMMENT '0 - disable this crontab work, else the lower number job have higher priority, by default 100',
`job_interval` int(11) NOT NULL,
`job_interval` int(11) UNSIGNED NOT NULL DEFAULT '600',
`last_run_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`next_run_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
Expand All @@ -824,10 +828,12 @@ TRUNCATE TABLE `site_crontab`;
--

INSERT INTO `site_crontab` (`id`, `job`, `priority`, `job_interval`) VALUES
(1, 'clean_dead_peer', 1, 600),
(2, 'clean_expired_session', 1, 600),
(3, 'expired_temporarily_invites', 1, 600),
(4, 'update_expired_external_link_info', 1, 600);
(1, 'clean_expired_zset_cache', 1, 60),
(2, 'clean_dead_peer', 1, 600),
(3, 'calculate_seeding_bonus', 2, 900),
(4, 'clean_expired_session', 3, 600),
(5, 'expired_invitee', 3, 600),
(6, 'update_expired_external_link_info', 100, 1200);

-- --------------------------------------------------------

Expand Down

0 comments on commit 4252f8d

Please sign in to comment.