mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-18 15:50:50 +08:00
get_username() support in laravel
This commit is contained in:
@@ -77,9 +77,10 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$torrent = \App\Models\Torrent::query()->find(3);
|
||||
$promotionInfo = apply_filter('torrent_promotion', $torrent->toArray());
|
||||
dd($promotionInfo);
|
||||
$end = Carbon::parse('2022-06-06 14:10');
|
||||
$begin = Carbon::parse('2022-06-06 03:10');
|
||||
$r = $end->diffInHours($begin);
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class Torrent extends NexusModel
|
||||
|
||||
public static $commentFields = [
|
||||
'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'pos_state', 'hr', 'picktype', 'picktime',
|
||||
'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover'
|
||||
'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover', 'anonymous',
|
||||
];
|
||||
|
||||
public static $basicRelations = [
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Nexus\Database\NexusDB;
|
||||
@@ -173,7 +174,7 @@ class User extends Authenticatable
|
||||
'id', 'username', 'email', 'class', 'status', 'added', 'avatar',
|
||||
'uploaded', 'downloaded', 'seedbonus', 'seedtime', 'leechtime',
|
||||
'invited_by', 'enabled', 'seed_points', 'last_access', 'invites',
|
||||
'lang', 'attendance_card',
|
||||
'lang', 'attendance_card', 'privacy', 'noad',
|
||||
];
|
||||
|
||||
public static function getDefaultUserAttributes(): array
|
||||
@@ -196,12 +197,28 @@ class User extends Authenticatable
|
||||
];
|
||||
}
|
||||
|
||||
public static function defaultUser()
|
||||
public static function defaultUser(): static
|
||||
{
|
||||
return new static(self::getDefaultUserAttributes());
|
||||
}
|
||||
|
||||
public function checkIsNormal(array $fields = ['status', 'enabled'])
|
||||
public static function getClassName($class, $compact = false, $b_colored = false, $I18N = false)
|
||||
{
|
||||
$class_name = self::$classes[$class]['text'];
|
||||
if ($class >= self::CLASS_VIP && $I18N) {
|
||||
$class_name = nexus_trans("user.class_names.$class");
|
||||
}
|
||||
$class_name_color = self::$classes[$class]['text'];
|
||||
if ($compact) {
|
||||
$class_name = str_replace(" ", "",$class_name);
|
||||
}
|
||||
if ($b_colored) {
|
||||
return "<b class='" . str_replace(" ", "",$class_name_color) . "_Name'>" . $class_name . "</b>";
|
||||
}
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
public function checkIsNormal(array $fields = ['status', 'enabled']): bool
|
||||
{
|
||||
if (in_array('status', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {
|
||||
throw new \InvalidArgumentException(sprintf('User: %s is not confirmed.', $this->id));
|
||||
@@ -416,7 +433,7 @@ class User extends Authenticatable
|
||||
return $this->update($update);
|
||||
}
|
||||
|
||||
public function canAccessAdmin()
|
||||
public function canAccessAdmin(): bool
|
||||
{
|
||||
$targetClass = self::CLASS_SYSOP;
|
||||
if (!$this->class || $this->class < $targetClass) {
|
||||
@@ -426,7 +443,7 @@ class User extends Authenticatable
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isDonating()
|
||||
public function isDonating(): bool
|
||||
{
|
||||
$rawDonorUntil = $this->getRawOriginal('donoruntil');
|
||||
if (
|
||||
@@ -438,4 +455,6 @@ class User extends Authenticatable
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -17,4 +20,20 @@ class BaseRepository
|
||||
return [$field, $type];
|
||||
}
|
||||
|
||||
protected function handleAnonymous($username, User $user, User $authenticator, Torrent $torrent = null)
|
||||
{
|
||||
$canViewAnonymousClass = Setting::get('authority.viewanonymous');
|
||||
if($user->privacy == "strong" || ($torrent && $torrent->anonymous == 'yes' && $user->id == $torrent->owner)) {
|
||||
//用户强私密,或者种子作者匿名而当前项作者刚好为种子作者
|
||||
if($authenticator->class >= $canViewAnonymousClass || $user->id == $authenticator->id) {
|
||||
//但当前用户权限可以查看匿名者,或当前用户查看自己的数据,显示个匿名,后边加真实用户名
|
||||
return sprintf('匿名(%s)', $username);
|
||||
} else {
|
||||
return '匿名';
|
||||
}
|
||||
} else {
|
||||
return $username;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -460,6 +460,9 @@ function get_user_class()
|
||||
|
||||
function get_user_class_name($class, $compact = false, $b_colored = false, $I18N = false)
|
||||
{
|
||||
if (!IN_NEXUS) {
|
||||
return \App\Models\User::getClassName($class, $compact, $b_colored, $I18N);
|
||||
}
|
||||
global $SITENAME;
|
||||
static $en_lang_functions;
|
||||
static $current_user_lang_functions;
|
||||
@@ -1896,20 +1899,29 @@ function get_user_row($id)
|
||||
global $Cache, $CURUSER;
|
||||
static $curuserRowUpdated = false;
|
||||
static $neededColumns = array('id', 'noad', 'class', 'enabled', 'privacy', 'avatar', 'signature', 'uploaded', 'downloaded', 'last_access', 'username', 'donor', 'donoruntil', 'leechwarn', 'warned', 'title');
|
||||
if ($CURUSER && $id == $CURUSER['id']) {
|
||||
$row = array();
|
||||
foreach($neededColumns as $column) {
|
||||
$row[$column] = $CURUSER[$column];
|
||||
}
|
||||
if (!$curuserRowUpdated) {
|
||||
$Cache->cache_value('user_'.$CURUSER['id'].'_content', $row, 900);
|
||||
$curuserRowUpdated = true;
|
||||
}
|
||||
} elseif (!$row = $Cache->get_value('user_'.$id.'_content')){
|
||||
$res = sql_query("SELECT ".implode(',', $neededColumns)." FROM users WHERE id = ".sqlesc($id)) or sqlerr(__FILE__,__LINE__);
|
||||
$row = mysql_fetch_array($res);
|
||||
$Cache->cache_value('user_'.$id.'_content', $row, 900);
|
||||
}
|
||||
$cacheKey = 'user_'.$id.'_content';
|
||||
$row = \Nexus\Database\NexusDB::remember($cacheKey, 900, function () use ($id, $neededColumns) {
|
||||
$user = \App\Models\User::query()->find($id, $neededColumns);
|
||||
if ($user) {
|
||||
return $user->toArray();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// if ($CURUSER && $id == $CURUSER['id']) {
|
||||
// $row = array();
|
||||
// foreach($neededColumns as $column) {
|
||||
// $row[$column] = $CURUSER[$column];
|
||||
// }
|
||||
// if (!$curuserRowUpdated) {
|
||||
// $Cache->cache_value('user_'.$CURUSER['id'].'_content', $row, 900);
|
||||
// $curuserRowUpdated = true;
|
||||
// }
|
||||
// } elseif (!$row = $Cache->get_value('user_'.$id.'_content')){
|
||||
// $res = sql_query("SELECT ".implode(',', $neededColumns)." FROM users WHERE id = ".sqlesc($id)) or sqlerr(__FILE__,__LINE__);
|
||||
// $row = mysql_fetch_array($res);
|
||||
// $Cache->cache_value('user_'.$id.'_content', $row, 900);
|
||||
// }
|
||||
|
||||
if (!$row)
|
||||
return false;
|
||||
@@ -3626,7 +3638,8 @@ function get_username($id, $big = false, $link = true, $bold = true, $target = f
|
||||
|
||||
$username = ($underline == true ? "<u>" . $arr['username'] . "</u>" : $arr['username']);
|
||||
$username = ($bold == true ? "<b>" . $username . "</b>" : $username);
|
||||
$username = ($link == true ? "<a ". $link_ext . " href=\"userdetails.php?id=" . $id . "\"" . ($target == true ? " target=\"_blank\"" : "") . " class='". get_user_class_name($arr['class'],true) . "_Name'>" . $username . "</a>" : $username) . $pics . ($withtitle == true ? " (" . ($arr['title'] == "" ? get_user_class_name($arr['class'],false,true,true) : "<span class='".get_user_class_name($arr['class'],true) . "_Name'><b>".htmlspecialchars($arr['title'])) . "</b></span>)" : "");
|
||||
$href = getSchemeAndHttpHost() . "/userdetails.php?id=$id";
|
||||
$username = ($link == true ? "<a ". $link_ext . " href=\"" . $href . "\"" . ($target == true ? " target=\"_blank\"" : "") . " class='". get_user_class_name($arr['class'],true) . "_Name'>" . $username . "</a>" : $username) . $pics . ($withtitle == true ? " (" . ($arr['title'] == "" ? get_user_class_name($arr['class'],false,true,true) : "<span class='".get_user_class_name($arr['class'],true) . "_Name'><b>".htmlspecialchars($arr['title'])) . "</b></span>)" : "");
|
||||
|
||||
$username = "<span class=\"nowrap\">" . ( $bracket == true ? "(" . $username . ")" : $username) . "</span>";
|
||||
}
|
||||
@@ -5590,6 +5603,11 @@ function get_smile($num)
|
||||
return $all[$num] ?? null;
|
||||
}
|
||||
|
||||
function username_under_torrent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate user seed bonus per hour
|
||||
*
|
||||
|
||||
@@ -16,4 +16,13 @@ return [
|
||||
'invites' => 'Invites',
|
||||
'attendance_card' => 'Attend card',
|
||||
],
|
||||
'class_name' => [
|
||||
\App\Models\User::CLASS_VIP => 'Vip',
|
||||
\App\Models\User::CLASS_RETIREE => 'Retiree',
|
||||
\App\Models\User::CLASS_UPLOADER => 'Uploader',
|
||||
\App\Models\User::CLASS_MODERATOR => 'Moderator',
|
||||
\App\Models\User::CLASS_ADMINISTRATOR => 'Administrator',
|
||||
\App\Models\User::CLASS_SYSOP => 'Sysop',
|
||||
\App\Models\User::CLASS_STAFF_LEADER => 'Staff Leader',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -16,4 +16,13 @@ return [
|
||||
'invites' => '邀请',
|
||||
'attendance_card' => '补签卡',
|
||||
],
|
||||
'class_names' => [
|
||||
\App\Models\User::CLASS_VIP => '贵宾',
|
||||
\App\Models\User::CLASS_RETIREE => '养老族',
|
||||
\App\Models\User::CLASS_UPLOADER => '发布员',
|
||||
\App\Models\User::CLASS_MODERATOR => '总版主',
|
||||
\App\Models\User::CLASS_ADMINISTRATOR => '管理员',
|
||||
\App\Models\User::CLASS_SYSOP => '维护开发员',
|
||||
\App\Models\User::CLASS_STAFF_LEADER => '主管',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -16,4 +16,13 @@ return [
|
||||
'invites' => '邀請',
|
||||
'attendance_card' => '補簽卡',
|
||||
],
|
||||
'class_name' => [
|
||||
\App\Models\User::CLASS_VIP => '貴賓',
|
||||
\App\Models\User::CLASS_RETIREE => '養老族',
|
||||
\App\Models\User::CLASS_UPLOADER => '發布員',
|
||||
\App\Models\User::CLASS_MODERATOR => '總版主',
|
||||
\App\Models\User::CLASS_ADMINISTRATOR => '管理員',
|
||||
\App\Models\User::CLASS_SYSOP => '維護開發員',
|
||||
\App\Models\User::CLASS_STAFF_LEADER => '主管',
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user