replace method id() by property id, empty by isset/strlen

This commit is contained in:
Spine
2025-10-12 23:58:17 +00:00
parent a8ed74a90e
commit be7fae7c70
23 changed files with 125 additions and 123 deletions

View File

@@ -2,6 +2,8 @@
namespace Gazelle\Search\Torrent; namespace Gazelle\Search\Torrent;
use Gazelle\User;
class Report extends \Gazelle\Base { class Report extends \Gazelle\Base {
protected string $orderBy; protected string $orderBy;
protected string $title; protected string $title;
@@ -95,17 +97,19 @@ class Report extends \Gazelle\Base {
} }
} }
public function setReporterId(int $reporterId): void { public function setReporter(User $reporter): static {
$this->configure(); $this->configure();
$this->cond[] = "r.ReporterID = ?"; $this->cond[] = "r.ReporterID = ?";
$this->args[] = $reporterId; $this->args[] = $reporter->id;
return $this;
} }
public function setOrderBy(string $orderBy): void { public function setOrderBy(string $orderBy): static {
$this->orderBy = "ORDER BY $orderBy"; $this->orderBy = "ORDER BY $orderBy";
return $this;
} }
public function canUnclaim(\Gazelle\User $user): bool { public function canUnclaim(User $user): bool {
return $this->mode === 'staff' && $user->id === (int)$this->id; return $this->mode === 'staff' && $user->id === (int)$this->id;
} }

View File

@@ -32,14 +32,14 @@ class Friend extends \Gazelle\BaseUser {
} }
public function add(\Gazelle\User $friend): int { public function add(\Gazelle\User $friend): int {
if ($this->user->id === $friend->id()) { if ($this->user->id === $friend->id) {
return -1; return -1;
} }
self::$db->prepared_query(" self::$db->prepared_query("
INSERT IGNORE INTO friends INSERT IGNORE INTO friends
(UserID, FriendID) (UserID, FriendID)
VALUES (?, ?) VALUES (?, ?)
", $this->user->id, $friend->id() ", $this->user->id, $friend->id
); );
return self::$db->affected_rows(); return self::$db->affected_rows();
} }
@@ -50,7 +50,7 @@ class Friend extends \Gazelle\BaseUser {
Comment = ? Comment = ?
WHERE UserID = ? WHERE UserID = ?
AND FriendID = ? AND FriendID = ?
", $comment, $this->user->id, $friend->id() ", $comment, $this->user->id, $friend->id
); );
return self::$db->affected_rows(); return self::$db->affected_rows();
} }
@@ -60,7 +60,7 @@ class Friend extends \Gazelle\BaseUser {
DELETE FROM friends DELETE FROM friends
WHERE UserID = ? WHERE UserID = ?
AND FriendID = ? AND FriendID = ?
", $this->user->id, $friend->id() ", $this->user->id, $friend->id
); );
return self::$db->affected_rows(); return self::$db->affected_rows();
} }

View File

@@ -143,7 +143,7 @@ class Session extends \Gazelle\BaseUser {
$info = $this->info(); $info = $this->info();
if (count($info) > 1) { if (count($info) > 1) {
foreach ($info as $id => $session) { foreach ($info as $id => $session) {
if ($id != $sessionKey) { if ($id !== $sessionKey) {
return $session; return $session;
} }
} }

View File

@@ -15,7 +15,7 @@ if (isset($_GET['search'])) {
$_GET['search'] = trim($_GET['search']); $_GET['search'] = trim($_GET['search']);
} }
if (!empty($_GET['search'])) { if (isset($_GET['search'])) {
if (preg_match(IP_REGEXP, $_GET['search'])) { if (preg_match(IP_REGEXP, $_GET['search'])) {
$_GET['ip'] = $_GET['search']; $_GET['ip'] = $_GET['search'];
} elseif (preg_match(EMAIL_REGEXP, $_GET['search'])) { } elseif (preg_match(EMAIL_REGEXP, $_GET['search'])) {
@@ -69,36 +69,35 @@ $orderBy = [
$dir = ['Ascending' => 'ASC', 'Descending' => 'DESC']; $dir = ['Ascending' => 'ASC', 'Descending' => 'DESC'];
// Arrays, regexps, and all that fun stuff we can use for validation, form generation, etc // Arrays, regexps, and all that fun stuff we can use for validation, form generation, etc
$orderByValue = ['inarray' => array_keys($orderBy)]; $orderByValue = ['inarray' => array_keys($orderBy)];
$dirValue = ['inarray' => array_keys($dir)]; $dirValue = ['inarray' => array_keys($dir)];
$dateChoice = ['inarray' => ['on', 'before', 'after', 'between']];
$dateChoice = ['inarray' => ['on', 'before', 'after', 'between']];
$singledateChoice = ['inarray' => ['on', 'before', 'after']]; $singledateChoice = ['inarray' => ['on', 'before', 'after']];
$numberChoice = ['inarray' => ['equal', 'above', 'below', 'between', 'buffer']]; $numberChoice = ['inarray' => ['equal', 'above', 'below', 'between', 'buffer']];
$offNumberChoice = ['inarray' => ['equal', 'above', 'below', 'between', 'buffer', 'off']]; $offNumberChoice = ['inarray' => ['equal', 'above', 'below', 'between', 'buffer', 'off']];
$yesNo = ['inarray' => ['any', 'yes', 'no']]; $yesNo = ['inarray' => ['any', 'yes', 'no']];
$nullable = ['inarray' => ['any', 'isnull', 'isnotnull']]; $nullable = ['inarray' => ['any', 'isnull', 'isnotnull']];
$emailHistoryChecked = false; $emailHistoryChecked = false;
$ipHistoryChecked = false; $ipHistoryChecked = false;
$disabledIpChecked = false; $disabledIpChecked = false;
$trackerLiveSource = true; $trackerLiveSource = true;
$paginator = new Util\Paginator(USERS_PER_PAGE, (int)($_GET['page'] ?? 1)); $paginator = new Util\Paginator(USERS_PER_PAGE, (int)($_GET['page'] ?? 1));
$stylesheet = new \Gazelle\Manager\Stylesheet()->list(); $stylesheet = new Manager\Stylesheet()->list();
$matchMode = ($_GET['matchtype'] ?? 'fuzzy'); $matchMode = $_GET['matchtype'] ?? 'fuzzy';
$searchDisabledInvites = (isset($_GET['disabled_invites']) && $_GET['disabled_invites'] != ''); $searchDisabledInvites = isset($_GET['disabled_invites']) && $_GET['disabled_invites'] != '';
$searchDisabledUploads = (isset($_GET['disabled_uploads']) && $_GET['disabled_uploads'] != ''); $searchDisabledUploads = isset($_GET['disabled_uploads']) && $_GET['disabled_uploads'] != '';
$searchLockedAccount = (($_GET['lockedaccount'] ?? '') == 'locked'); $searchLockedAccount = ($_GET['lockedaccount'] ?? '') === 'locked';
$showInvited = (($_GET['invited'] ?? 'off') !== 'off'); $showInvited = ($_GET['invited'] ?? 'off') !== 'off';
if (empty($_GET)) { if ($_GET === []) {
$result = []; $result = [];
} else { } else {
$emailHistoryChecked = !empty($_GET['email_history']); $emailHistoryChecked = isset($_GET['email_history']);
$disabledIpChecked = !empty($_GET['disabled_ip']); $disabledIpChecked = isset($_GET['disabled_ip']);
$ipHistoryChecked = !empty($_GET['ip_history']); $ipHistoryChecked = isset($_GET['ip_history']);
$trackerLiveSource = ($_GET['tracker-src'] ?? 'live') == 'live'; $trackerLiveSource = ($_GET['tracker-src'] ?? 'live') == 'live';
$dateRegexp = ['regexp' => '/\d{4}-\d{2}-\d{2}/']; $dateRegexp = ['regexp' => '/\d{4}-\d{2}-\d{2}/'];
$userclassList = []; $userclassList = [];
@@ -178,12 +177,12 @@ if (empty($_GET)) {
LEFT JOIN relay.user_last_access AS ula ON (ula.user_id = um1."ID") LEFT JOIN relay.user_last_access AS ula ON (ula.user_id = um1."ID")
'; ';
if (!empty($_GET['username'])) { if (strlen($_GET['username'] ?? '')) {
$where[] = $m->matchField('um1."Username"'); $where[] = $m->matchField('um1."Username"');
$args[] = $_GET['username']; $args[] = $_GET['username'];
} }
if (!empty($_GET['email'])) { if (strlen($_GET['email'] ?? '')) {
if (isset($_GET['email_history'])) { if (isset($_GET['email_history'])) {
$distinct = true; $distinct = true;
$join['he'] = 'INNER JOIN relay.users_history_emails AS he ON (he."UserID" = um1."ID")'; $join['he'] = 'INNER JOIN relay.users_history_emails AS he ON (he."UserID" = um1."ID")';
@@ -194,7 +193,7 @@ if (empty($_GET)) {
$args[] = $_GET['email']; $args[] = $_GET['email'];
} }
if (isset($_GET['email_opt']) && isset($_GET['email_cnt']) && strlen($_GET['email_cnt'])) { if (strlen($_GET['email_opt'] ?? '') && strlen($_GET['email_cnt'] ?? '')) {
$where[] = sprintf('um1."ID" IN (%s)', $where[] = sprintf('um1."ID" IN (%s)',
$m->op(' $m->op('
SELECT "UserID" FROM relay.users_history_emails GROUP BY "UserID" HAVING count(DISTINCT "Email") SELECT "UserID" FROM relay.users_history_emails GROUP BY "UserID" HAVING count(DISTINCT "Email")
@@ -204,7 +203,7 @@ if (empty($_GET)) {
$args[] = (int)$_GET['email_cnt']; $args[] = (int)$_GET['email_cnt'];
} }
if (!empty($_GET['ip'])) { if (strlen($_GET['ip'] ?? '')) {
if ($ipHistoryChecked) { if ($ipHistoryChecked) {
$distinct = true; $distinct = true;
$join['hi'] = 'INNER JOIN relay.users_history_ips AS hi ON (hi."UserID" = um1."ID")'; $join['hi'] = 'INNER JOIN relay.users_history_ips AS hi ON (hi."UserID" = um1."ID")';
@@ -222,12 +221,12 @@ if (empty($_GET)) {
$where[] = 'la."UserID" IS NULL'; $where[] = 'la."UserID" IS NULL';
} }
if (!empty($_GET['cc'])) { if (strlen($_GET['cc'] ?? '')) {
$where[] = $m->op('um1.ipcc', $_GET['cc_op']); $where[] = $m->op('um1.ipcc', $_GET['cc_op']);
$args[] = trim($_GET['cc']); $args[] = trim($_GET['cc']);
} }
if (!empty($_GET['tracker_ip'])) { if (strlen($_GET['tracker_ip'] ?? '')) {
$distinct = true; $distinct = true;
$join['xfu'] = $trackerLiveSource $join['xfu'] = $trackerLiveSource
? 'INNER JOIN relay.xbt_files_users AS xfu ON (um1."ID" = xfu.uid)' ? 'INNER JOIN relay.xbt_files_users AS xfu ON (um1."ID" = xfu.uid)'
@@ -236,27 +235,27 @@ if (empty($_GET)) {
$args[] = trim($_GET['tracker_ip']); $args[] = trim($_GET['tracker_ip']);
} }
if (!empty($_GET['comment'])) { if (strlen($_GET['comment'] ?? '')) {
$distinct = true; $distinct = true;
$join['audit'] = 'inner join user_audit_trail uat on (uat.id_user = um1."ID")'; $join['audit'] = 'inner join user_audit_trail uat on (uat.id_user = um1."ID")';
$where[] = "note_ts @@ plainto_tsquery('simple', ?)"; $where[] = "note_ts @@ plainto_tsquery('simple', ?)";
$args[] = $_GET['comment']; $args[] = $_GET['comment'];
} }
if (!empty($_GET['lastfm'])) { if (strlen($_GET['lastfm'] ?? '')) {
$distinct = true; $distinct = true;
$join['lfm'] = 'INNER JOIN relay.lastfm_users AS lfm ON (lfm."ID" = um1."ID")'; $join['lfm'] = 'INNER JOIN relay.lastfm_users AS lfm ON (lfm."ID" = um1."ID")';
$where[] = $m->matchField('lfm."Username"'); $where[] = $m->matchField('lfm."Username"');
$args[] = $_GET['lastfm']; $args[] = $_GET['lastfm'];
} }
if (isset($_GET['invites']) && !empty($_GET['invites']) && isset($_GET['invites1']) && strlen($_GET['invites1'])) { if (strlen($_GET['invites'] ?? '') && strlen($_GET['invites1'] ?? '')) {
$op = $_GET['invites']; $op = $_GET['invites'];
$where[] = $m->op('um1."Invites"', $op); $where[] = $m->op('um1."Invites"', $op);
$args = array_merge($args, [$_GET['invites1']], ($op === 'between' ? [$_GET['invites2']] : [])); $args = array_merge($args, [$_GET['invites1']], ($op === 'between' ? [$_GET['invites2']] : []));
} }
if ($showInvited && isset($_GET['invited1']) && strlen($_GET['invited1'])) { if ($showInvited && strlen($_GET['invited1'] ?? '')) {
$op = $_GET['invited']; $op = $_GET['invited'];
$where[] = 'um1.ID IN (' $where[] = 'um1.ID IN ('
. $m->op('SELECT umi."ID" . $m->op('SELECT umi."ID"
@@ -290,7 +289,7 @@ if (empty($_GET)) {
$args[] = 'disable-upload'; $args[] = 'disable-upload';
} }
if (isset($_GET['joined']) && !empty($_GET['joined']) && isset($_GET['join1']) && !empty($_GET['join1'])) { if (strlen($_GET['joined'] ?? '') && strlen($_GET['join1'] ?? '')) {
$op = $_GET['joined']; $op = $_GET['joined'];
$where[] = $m->date('um1.created', $op); $where[] = $m->date('um1.created', $op);
$args[] = $_GET['join1']; $args[] = $_GET['join1'];
@@ -301,7 +300,7 @@ if (empty($_GET)) {
} }
} }
if (isset($_GET['lastactive']) && !empty($_GET['lastactive']) && isset($_GET['lastactive1']) && !empty($_GET['lastactive1'])) { if (strlen($_GET['lastactive'] ?? '') && strlen($_GET['lastactive1'] ?? '')) {
$op = $_GET['lastactive']; $op = $_GET['lastactive'];
$where[] = $m->date('ula.last_access', $op); $where[] = $m->date('ula.last_access', $op);
$args[] = $_GET['lastactive1']; $args[] = $_GET['lastactive1'];
@@ -312,7 +311,7 @@ if (empty($_GET)) {
} }
} }
if (isset($_GET['ratio']) && !empty($_GET['ratio']) && isset($_GET['ratio1']) && strlen($_GET['ratio1'])) { if (strlen($_GET['ratio'] ?? '') && strlen($_GET['ratio1'] ?? '')) {
$frac = explode('.', $_GET['ratio1']); $frac = explode('.', $_GET['ratio1']);
$decimals = strlen(end($frac)); $decimals = strlen(end($frac));
if (!$decimals) { if (!$decimals) {
@@ -323,19 +322,19 @@ if (empty($_GET)) {
$args = array_merge($args, [$decimals, $_GET['ratio1']], ($op === 'between' ? [$_GET['ratio2']] : [])); $args = array_merge($args, [$decimals, $_GET['ratio1']], ($op === 'between' ? [$_GET['ratio2']] : []));
} }
if (isset($_GET['bounty']) && !empty($_GET['bounty']) && $_GET['bounty'] !== 'off' && isset($_GET['bounty1']) && strlen($_GET['bounty1'])) { if (strlen($_GET['bounty'] ?? '') && $_GET['bounty'] !== 'off' && strlen($_GET['bounty1'] ?? '')) {
$op = $_GET['bounty']; $op = $_GET['bounty'];
$where[] = $m->op('(SELECT sum("Bounty") FROM relay.requests_votes rv WHERE rv."UserID" = um1."ID")', $op); $where[] = $m->op('(SELECT sum("Bounty") FROM relay.requests_votes rv WHERE rv."UserID" = um1."ID")', $op);
$args = array_merge($args, [$_GET['bounty1'] * 1024 ** 3], ($op === 'between' ? [$_GET['bounty2'] * 1024 ** 3] : [])); $args = array_merge($args, [$_GET['bounty1'] * 1024 ** 3], ($op === 'between' ? [$_GET['bounty2'] * 1024 ** 3] : []));
} }
if (isset($_GET['downloads']) && !empty($_GET['downloads']) && $_GET['downloads'] !== 'off' && isset($_GET['downloads1']) && strlen($_GET['downloads1'])) { if (strlen($_GET['downloads'] ?? '') && $_GET['downloads'] !== 'off' && strlen($_GET['downloads1'] ?? '')) {
$op = $_GET['downloads']; $op = $_GET['downloads'];
$where[] = $m->op('(SELECT count(DISTINCT "TorrentID") FROM relay.users_downloads ud WHERE ud."UserID" = um1."ID")', $op); $where[] = $m->op('(SELECT count(DISTINCT "TorrentID") FROM relay.users_downloads ud WHERE ud."UserID" = um1."ID")', $op);
$args = array_merge($args, [$_GET['downloads1']], ($op === 'between' ? [$_GET['downloads2']] : [])); $args = array_merge($args, [$_GET['downloads1']], ($op === 'between' ? [$_GET['downloads2']] : []));
} }
if (isset($_GET['seeding']) && $_GET['seeding'] !== 'off' && isset($_GET['seeding1'])) { if (strlen($_GET['seeding'] ?? '') && $_GET['seeding'] !== 'off' && strlen($_GET['seeding1'] ?? '')) {
$op = $_GET['seeding']; $op = $_GET['seeding'];
$where[] = $m->op('(SELECT count(DISTINCT fid) $where[] = $m->op('(SELECT count(DISTINCT fid)
FROM relay.xbt_files_users xfu FROM relay.xbt_files_users xfu
@@ -344,13 +343,13 @@ if (empty($_GET)) {
$args = array_merge($args, [$_GET['seeding1']], ($op === 'between' ? [$_GET['seeding2']] : [])); $args = array_merge($args, [$_GET['seeding1']], ($op === 'between' ? [$_GET['seeding2']] : []));
} }
if (isset($_GET['snatched']) && $_GET['snatched'] !== 'off' && isset($_GET['snatched1'])) { if (strlen($_GET['snatched'] ?? '') && $_GET['snatched'] !== 'off' && strlen($_GET['snatched1'] ?? '')) {
$op = $_GET['snatched']; $op = $_GET['snatched'];
$where[] = $m->op('(SELECT count(DISTINCT fid) FROM relay.xbt_snatched AS xs WHERE xs.uid = um1."ID")', $op); $where[] = $m->op('(SELECT count(DISTINCT fid) FROM relay.xbt_snatched AS xs WHERE xs.uid = um1."ID")', $op);
$args = array_merge($args, [$_GET['snatched1']], ($op === 'between' ? [$_GET['snatched2']] : [])); $args = array_merge($args, [$_GET['snatched1']], ($op === 'between' ? [$_GET['snatched2']] : []));
} }
if (isset($_GET['uploaded']) && !empty($_GET['uploaded']) && isset($_GET['uploaded1']) && strlen($_GET['uploaded1'])) { if (strlen($_GET['uploaded'] ?? '') && strlen($_GET['uploaded1'] ?? '')) {
$op = $_GET['uploaded']; $op = $_GET['uploaded'];
if ($op === 'buffer') { if ($op === 'buffer') {
$where[] = 'uls1."Uploaded" - uls1."Downloaded" BETWEEN ? AND ?'; $where[] = 'uls1."Uploaded" - uls1."Downloaded" BETWEEN ? AND ?';
@@ -366,7 +365,7 @@ if (empty($_GET)) {
} }
} }
if (isset($_GET['downloaded']) && !empty($_GET['downloaded']) && isset($_GET['downloaded1']) && strlen($_GET['downloaded1'])) { if (strlen($_GET['downloaded'] ?? '') && strlen($_GET['downloaded1'] ?? '')) {
$op = $_GET['downloaded']; $op = $_GET['downloaded'];
$where[] = $m->op('uls1."Downloaded"', $op); $where[] = $m->op('uls1."Downloaded"', $op);
$args[] = $_GET['downloaded1'] * 1024 ** 3; $args[] = $_GET['downloaded1'] * 1024 ** 3;
@@ -377,7 +376,7 @@ if (empty($_GET)) {
} }
} }
if (isset($_GET['enabled']) && $_GET['enabled'] != '') { if (strlen($_GET['enabled'] ?? '')) {
$where[] = 'um1."Enabled" = ?'; $where[] = 'um1."Enabled" = ?';
$args[] = $_GET['enabled']; $args[] = $_GET['enabled'];
} }
@@ -387,13 +386,13 @@ if (empty($_GET)) {
$args = array_merge($args, $_GET['class']); $args = array_merge($args, $_GET['class']);
} }
if (isset($_GET['secclass']) && $_GET['secclass'] != '') { if (strlen($_GET['secclass'] ?? '')) {
$join['ul'] = 'INNER JOIN relay.users_levels AS ul ON (um1."ID" = ul."UserID")'; $join['ul'] = 'INNER JOIN relay.users_levels AS ul ON (um1."ID" = ul."UserID")';
$where[] = 'ul."PermissionID" = ?'; $where[] = 'ul."PermissionID" = ?';
$args[] = $_GET['secclass']; $args[] = $_GET['secclass'];
} }
if (isset($_GET['warned']) && !empty($_GET['warned'])) { if (isset($_GET['warned'])) {
$where[] = $m->op('ui1."Warned"', $_GET['warned']); $where[] = $m->op('ui1."Warned"', $_GET['warned']);
} }
@@ -409,17 +408,17 @@ if (empty($_GET)) {
} }
} }
if (isset($_GET['passkey']) && !empty($_GET['passkey'])) { if (strlen($_GET['passkey'] ?? '')) {
$where[] = $m->matchField('um1.torrent_pass'); $where[] = $m->matchField('um1.torrent_pass');
$args[] = $_GET['passkey']; $args[] = $_GET['passkey'];
} }
if (isset($_GET['avatar']) && !empty($_GET['avatar'])) { if (strlen($_GET['avatar'] ?? '')) {
$where[] = $m->matchField('um1.avatar'); $where[] = $m->matchField('um1.avatar');
$args[] = $_GET['avatar']; $args[] = $_GET['avatar'];
} }
if (isset($_GET['stylesheet']) && !empty($_GET['stylesheet'])) { if (strlen($_GET['stylesheet'] ?? '')) {
$where[] = $m->matchField('um1.stylesheet_id'); $where[] = $m->matchField('um1.stylesheet_id');
$args[] = $_GET['stylesheet']; $args[] = $_GET['stylesheet'];
} }

View File

@@ -12,7 +12,7 @@ $user = new Manager\Invite()->findUserByKey($inviteKey, new Manager\User());
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
if ($user->id != $Viewer->id()) { if ($user->id !== $Viewer->id) {
Error403::error(); Error403::error();
} }

View File

@@ -8,17 +8,16 @@ namespace Gazelle;
$userMan = new Manager\User(); $userMan = new Manager\User();
$user = $userMan->findById(($_REQUEST['id'] ?? '') === 'me' ? $Viewer->id() : (int)($_REQUEST['id'] ?? 0)); $user = $userMan->findById(($_REQUEST['id'] ?? '') === 'me' ? $Viewer->id : (int)($_REQUEST['id'] ?? 0));
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
$UserID = $user->id; if ($user->id !== $Viewer->id && !$Viewer->permitted('users_edit_profiles')) {
if ($UserID != $Viewer->id() && !$Viewer->permitted('users_edit_profiles')) {
Error403::error(); Error403::error();
} }
$donor = new User\Donor($user); $donor = new User\Donor($user);
$profile = [ $profile = [
'title' => $user->profileTitle(), 'title' => $user->profileTitle(),
'info' => new Util\Textarea('info', $user->profileInfo(), 42, 8), 'info' => new Util\Textarea('info', $user->profileInfo(), 42, 8),
]; ];
@@ -30,17 +29,17 @@ foreach (range(1, 4) as $level) {
]; ];
} }
} }
$navList = new Manager\UserNavigation()->fullList(); $navList = new Manager\UserNavigation()->fullList();
$pushToken = new User\Notification($user)->pushToken(); $notifier = new User\Notification($user);
echo $Twig->render('user/setting.twig', [ echo $Twig->render('user/setting.twig', [
'donor' => $donor, 'donor' => $donor,
'lastfm_username' => new Util\LastFM()->username($user), 'lastfm_username' => new Util\LastFM()->username($user),
'nav_items' => $navList, 'nav_items' => $navList,
'nav_items_user' => $user->navigationList(), 'nav_items_user' => $user->navigationList(),
'notify_config' => new User\Notification($user)->config(), 'notify_config' => $notifier->config(),
'push_topic' => $pushToken,
'profile' => $profile, 'profile' => $profile,
'push_topic' => $notifier->pushToken(),
'release_order' => $user->releaseOrder(new ReleaseType()->extendedList()), 'release_order' => $user->releaseOrder(new ReleaseType()->extendedList()),
'stylesheet' => new User\Stylesheet($user), 'stylesheet' => new User\Stylesheet($user),
'stylesheets' => new Manager\Stylesheet()->list(), 'stylesheets' => new Manager\Stylesheet()->list(),

View File

@@ -21,7 +21,7 @@ if (!isset($_REQUEST['id'])) {
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
$ownProfile = ($user->id === $Viewer->id()); $ownProfile = $user->id === $Viewer->id;
if (!$ownProfile && !$Viewer->permitted('users_edit_profiles')) { if (!$ownProfile && !$Viewer->permitted('users_edit_profiles')) {
$irc::sendMessage(IRC_CHAN_MOD, "User {$Viewer->label()} tried to edit {$user->publicLocation()}"); $irc::sendMessage(IRC_CHAN_MOD, "User {$Viewer->label()} tried to edit {$user->publicLocation()}");
Error403::error(); Error403::error();
@@ -154,7 +154,7 @@ if ($avatar != $user->avatar()) {
} }
$ResetPassword = false; $ResetPassword = false;
if (!empty($_POST['password']) && !empty($_POST['new_pass_1']) && !empty($_POST['new_pass_2'])) { if (isset($_POST['password']) && isset($_POST['new_pass_1']) && isset($_POST['new_pass_2'])) {
if (!$user->validatePassword($_POST['password'])) { if (!$user->validatePassword($_POST['password'])) {
Error400::error('You did not enter the correct password.'); Error400::error('You did not enter the correct password.');
} elseif (!Util\PasswordCheck::checkPasswordStrength($_POST['password'], $user)) { } elseif (!Util\PasswordCheck::checkPasswordStrength($_POST['password'], $user)) {
@@ -180,24 +180,25 @@ if (!empty($_POST['password']) && !empty($_POST['new_pass_1']) && !empty($_POST[
} }
} }
$option['DisableGrouping2'] = (!empty($_POST['disablegrouping']) ? 0 : 1); $option['AutoSubscribe'] = isset($_POST['autosubscribe']) ? 1 : 0;
$option['TorrentGrouping'] = (!empty($_POST['torrentgrouping']) ? 1 : 0); $option['CoverArt'] = isset($_POST['coverart']) ? 1 : 0;
$option['DisableAutoSave'] = isset($_POST['disableautosave']) ? 1 : 0;
$option['DisableAvatars'] = isset($_POST['disableavatars']) ? 1 : 0;
$option['DisableGrouping2'] = isset($_POST['disablegrouping']) ? 1 : 0;
$option['DisablePMAvatars'] = isset($_POST['disablepmavatars']) ? 1 : 0;
$option['DisableSmileys'] = isset($_POST['disablesmileys']) ? 1 : 0;
$option['EnableMatureContent'] = isset($_POST['enablematurecontent']) ? 1 : 0;
$option['ListUnreadPMsFirst'] = isset($_POST['list_unread_pms_first']) ? 1 : 0;
$option['NoVoteLinks'] = isset($_POST['novotelinks']) ? 1 : 0;
$option['ShowExtraCovers'] = isset($_POST['show_extra_covers']) ? 1 : 0;
$option['ShowSnatched'] = isset($_POST['showsnatched']) ? 1 : 0;
$option['ShowTorFilter'] = isset($_POST['showtfilter']) ? 1 : 0;
$option['TorrentGrouping'] = isset($_POST['torrentgrouping']) ? 1 : 0;
$option['UseOpenDyslexic'] = isset($_POST['useopendyslexic']) ? 1 : 0;
$option['PostsPerPage'] = (int)$_POST['postsperpage']; $option['PostsPerPage'] = (int)$_POST['postsperpage'];
$option['CollageCovers'] = (int)$_POST['collagecovers']; $option['CollageCovers'] = (int)$_POST['collagecovers'];
$option['ShowTorFilter'] = (empty($_POST['showtfilter']) ? 0 : 1);
$option['AutoSubscribe'] = (!empty($_POST['autosubscribe']) ? 1 : 0);
$option['DisableSmileys'] = (int)isset($_POST['disablesmileys']);
$option['EnableMatureContent'] = (!empty($_POST['enablematurecontent']) ? 1 : 0);
$option['UseOpenDyslexic'] = (!empty($_POST['useopendyslexic']) ? 1 : 0);
$option['DisableAvatars'] = (int)($_POST['disableavatars'] ?? 0);
$option['Identicons'] = (int)($_POST['identicons'] ?? 0); $option['Identicons'] = (int)($_POST['identicons'] ?? 0);
$option['DisablePMAvatars'] = (!empty($_POST['disablepmavatars']) ? 1 : 0);
$option['ListUnreadPMsFirst'] = (!empty($_POST['list_unread_pms_first']) ? 1 : 0);
$option['ShowSnatched'] = (!empty($_POST['showsnatched']) ? 1 : 0);
$option['DisableAutoSave'] = (!empty($_POST['disableautosave']) ? 1 : 0);
$option['NoVoteLinks'] = (!empty($_POST['novotelinks']) ? 1 : 0);
$option['CoverArt'] = (int)!empty($_POST['coverart']);
$option['ShowExtraCovers'] = (int)!empty($_POST['show_extra_covers']);
$option['AutoComplete'] = $_POST['autocomplete']; $option['AutoComplete'] = $_POST['autocomplete'];
// user options // user options
@@ -206,7 +207,7 @@ foreach (['DefaultSearch', 'DisableFreeTorrentTop10'] as $opt) {
$option[$opt] = $user->option($opt); $option[$opt] = $user->option($opt);
} }
} }
if (empty($_POST['sorthide'])) { if (!isset($_POST['sorthide'])) {
$option['SortHide'] = []; $option['SortHide'] = [];
} else { } else {
$JSON = json_decode($_POST['sorthide']); $JSON = json_decode($_POST['sorthide']);
@@ -216,7 +217,7 @@ if (empty($_POST['sorthide'])) {
} }
} }
if ($Viewer->permitted('site_advanced_search')) { if ($Viewer->permitted('site_advanced_search')) {
$option['SearchType'] = (int)!empty($_POST['search_type_advanced']); $option['SearchType'] = (int)isset($_POST['search_type_advanced']);
} else { } else {
unset($option['SearchType']); unset($option['SearchType']);
} }

View File

@@ -9,7 +9,7 @@ $user = new Manager\User()->findById((int)($_REQUEST['userid'] ?? 0));
if (is_null($user)) { if (is_null($user)) {
Error404::error('No such user'); Error404::error('No such user');
} }
if ($user->id != $Viewer->id && !$Viewer->permitted('users_mod')) { if ($user->id !== $Viewer->id && !$Viewer->permitted('users_mod')) {
Error403::error(); Error403::error();
} }

View File

@@ -53,7 +53,7 @@ $visible = isset($_POST['Visible']) ? '1' : '0';
$unlimitedDownload = isset($_POST['unlimitedDownload']); $unlimitedDownload = isset($_POST['unlimitedDownload']);
$invites = (int)$_POST['Invites']; $invites = (int)$_POST['Invites'];
$slogan = trim($_POST['slogan']); $slogan = trim($_POST['slogan']);
$changePassword = !empty($_POST['ChangePassword']); $changePassword = isset($_POST['ChangePassword']);
$uploaded = 0; $uploaded = 0;
$downloaded = 0; $downloaded = 0;
$bonusPoints = null; $bonusPoints = null;
@@ -88,7 +88,7 @@ $resetPasskey = isset($_POST['ResetPasskey']) ? 1 : 0;
$resetAuthkey = isset($_POST['ResetAuthkey']) ? 1 : 0; $resetAuthkey = isset($_POST['ResetAuthkey']) ? 1 : 0;
$logoutSession = isset($_POST['Logout']) ? 1 : 0; $logoutSession = isset($_POST['Logout']) ? 1 : 0;
$sendHackedMail = isset($_POST['SendHackedMail']) ? 1 : 0; $sendHackedMail = isset($_POST['SendHackedMail']) ? 1 : 0;
if ($sendHackedMail && !empty(trim($_POST['HackedEmail']))) { if ($sendHackedMail && isset($_POST['HackedEmail'])) {
$hackedEmail = trim($_POST['HackedEmail']); $hackedEmail = trim($_POST['HackedEmail']);
} else { } else {
$sendHackedMail = false; $sendHackedMail = false;
@@ -353,11 +353,11 @@ if ($Viewer->permittedAny('users_promote_below', 'users_promote_to')) {
if ($currentClasses != $secondaryClasses) { if ($currentClasses != $secondaryClasses) {
$removedClasses = array_diff($currentClasses, $secondaryClasses); $removedClasses = array_diff($currentClasses, $secondaryClasses);
$addedClasses = array_diff($secondaryClasses, $currentClasses); $addedClasses = array_diff($secondaryClasses, $currentClasses);
if (!empty($removedClasses)) { if ($removedClasses !== []) {
$names = array_map(fn (int $c): string => $userMan->userclassName($c), $removedClasses); $names = array_map(fn (int $c): string => $userMan->userclassName($c), $removedClasses);
$editSummary[] = 'secondary classes dropped: ' . implode(', ', $names); $editSummary[] = 'secondary classes dropped: ' . implode(', ', $names);
} }
if (!empty($addedClasses)) { if ($addedClasses !== []) {
$names = array_map(fn (int $c): string => $userMan->userclassName($c), $addedClasses); $names = array_map(fn (int $c): string => $userMan->userclassName($c), $addedClasses);
$editSummary[] = "secondary classes added: " . implode(', ', $names); $editSummary[] = "secondary classes added: " . implode(', ', $names);
} }

View File

@@ -60,5 +60,5 @@ if ($filterId) {
$filter->create($Viewer); $filter->create($Viewer);
} }
$Cache->delete_multi(["u_notify_" . $Viewer->id(), "notify_artists_" . $Viewer->id()]); $Cache->delete_multi(["u_notify_{$Viewer->id}", "notify_artists_{$Viewer->id}"]);
header('Location: user.php?action=notify'); header('Location: user.php?action=notify');

View File

@@ -9,12 +9,15 @@ $user = new Manager\User()->findById((int)$_GET['userid']);
if (is_null($user)) { if (is_null($user)) {
Error403::error(); Error403::error();
} }
if (!$Viewer->permitted('users_mod') && $user->id != $Viewer->id()) { if ($user->id !== $Viewer->id && !$Viewer->permitted('users_mod')) {
Error403::error(); Error403::error();
} }
authorize(); authorize();
new Manager\Notification()->push([$user->id], new Manager\Notification()->push(
'Push!', 'You have been pushed by ' . $Viewer->username()); [$user->id],
'Push!',
"You have been pushed by {$Viewer->username()}",
);
header('Location: ' . $user->location() . '&action=edit'); header("Location: {$user->location()}&action=edit");

View File

@@ -11,7 +11,7 @@ if (!$Viewer->hasAttr('feature-seedbox') && !$Viewer->permitted('users_view_ips'
} }
if (!isset($_POST['action'])) { if (!isset($_POST['action'])) {
$userId = (int)($_GET['userid'] ?? $Viewer->id()); $userId = (int)($_GET['userid'] ?? $Viewer->id);
} else { } else {
authorize(); authorize();
$userId = (int)$_POST['userid']; $userId = (int)$_POST['userid'];
@@ -20,7 +20,7 @@ $user = new Manager\User()->findById($userId);
if (!$user) { if (!$user) {
Error404::error(); Error404::error();
} }
if ($Viewer->id() != $userId && !$Viewer->permitted('users_view_ips')) { if ($userId !== $Viewer->id && !$Viewer->permitted('users_view_ips')) {
Error403::error(); Error403::error();
} }

View File

@@ -11,7 +11,7 @@ if (!$Viewer->hasAttr('feature-seedbox') && !$Viewer->permitted('users_view_ips'
} }
if (!isset($_POST['action'])) { if (!isset($_POST['action'])) {
$userId = (int)($_GET['userid'] ?? $Viewer->id()); $userId = (int)($_GET['userid'] ?? $Viewer->id);
} else { } else {
authorize(); authorize();
$userId = (int)$_POST['userid']; $userId = (int)$_POST['userid'];
@@ -20,7 +20,7 @@ $user = new Manager\User()->findById($userId);
if (!$user) { if (!$user) {
Error404::error(); Error404::error();
} }
if ($Viewer->id() != $userId && !$Viewer->permitted('users_view_ips')) { if ($userId !== $Viewer->id && !$Viewer->permitted('users_view_ips')) {
Error403::error(); Error403::error();
} }

View File

@@ -10,7 +10,7 @@ if (!isset($_GET['id'])) {
$user = $Viewer; $user = $Viewer;
} else { } else {
$userId = (int)$_GET['id']; $userId = (int)$_GET['id'];
if ($userId !== $Viewer->id() && !$Viewer->permittedAny('users_logout', 'users_view_ips')) { if ($userId !== $Viewer->id && !$Viewer->permittedAny('users_logout', 'users_view_ips')) {
Error403::error(); Error403::error();
} }
$user = new Manager\User()->findById($userId); $user = new Manager\User()->findById($userId);

View File

@@ -6,7 +6,7 @@ declare(strict_types=1);
namespace Gazelle; namespace Gazelle;
$userId = (int)($_GET['user_id'] ?? $Viewer->id()); $userId = (int)($_GET['user_id'] ?? $Viewer->id);
$user = new User($userId); $user = new User($userId);
$tokenId = (int)($_GET['token_id'] ?? 0); $tokenId = (int)($_GET['token_id'] ?? 0);
@@ -16,7 +16,7 @@ $tokenName = '';
$_GET['do'] ??= ''; $_GET['do'] ??= '';
if (!empty($_GET['do']) && $userId !== $Viewer->id() && !$Viewer->permitted('users_mod')) { if (strlen($_GET['do']) && $userId !== $Viewer->id && !$Viewer->permitted('users_mod')) {
Error403::error(); Error403::error();
} }
@@ -25,8 +25,8 @@ if ($_GET['do'] === 'revoke') {
header("Location: {$user->location()}&action=edit"); header("Location: {$user->location()}&action=edit");
exit; exit;
} elseif ($_GET['do'] === 'generate') { } elseif ($_GET['do'] === 'generate') {
$tokenName = $_POST['token_name'] ?? ''; $tokenName = trim($_POST['token_name'] ?? '');
if (empty($tokenName)) { if (!strlen($tokenName)) {
$error = 'You must supply a name for the token.'; $error = 'You must supply a name for the token.';
} elseif ($user->hasApiTokenByName($tokenName)) { } elseif ($user->hasApiTokenByName($tokenName)) {
$error = 'You have already generated a token with that name.'; $error = 'You have already generated a token with that name.';

View File

@@ -296,7 +296,7 @@ if ($Viewer->permitted('users_mod') && $user->onRatioWatch()) {
<?php <?php
foreach (range(1, 4) as $level) { foreach (range(1, 4) as $level) {
$profileInfo = $donor->profileInfo($level); $profileInfo = $donor->profileInfo($level);
if (!empty($profileInfo)) { if (is_string($profileInfo)) {
?> ?>
<div class="box"> <div class="box">
<div class="head"> <div class="head">

View File

@@ -17,7 +17,7 @@ if (!isset($_GET['userid'])) {
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
if ($user->id != $Viewer->id() && !$Viewer->permitted('users_mod')) { if ($user->id !== $Viewer->id && !$Viewer->permitted('users_mod')) {
Error403::error(); Error403::error();
} }
} }

View File

@@ -30,7 +30,7 @@ switch ($_REQUEST['dupeaction'] ?? '') {
$target = $userMan->find($username); $target = $userMan->find($username);
if (is_null($target)) { if (is_null($target)) {
Error400::error("User '" . display_str($username) . "' not found."); Error400::error("User '" . display_str($username) . "' not found.");
} elseif ($source->id() === $target->id()) { } elseif ($source->id === $target->id) {
Error400::error("Cannot link a user to themselves"); Error400::error("Cannot link a user to themselves");
} }
$userLink->dupe($target, $Viewer, $updateNote); $userLink->dupe($target, $Viewer, $updateNote);

View File

@@ -12,7 +12,7 @@ $user = new Manager\User()->findById((int)$_GET['id']);
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
$ownProfile = $user->id === $Viewer->id(); $ownProfile = $user->id === $Viewer->id;
if (!$Viewer->permitted('view-release-votes') && !$ownProfile) { if (!$Viewer->permitted('view-release-votes') && !$ownProfile) {
Error403::error(); Error403::error();
} }

View File

@@ -16,8 +16,8 @@ if (is_null($user)) {
Error404::error(); Error404::error();
} }
$ownProfile = $user->id === $Viewer->id(); $ownProfile = $user->id === $Viewer->id;
$showUnread = $ownProfile && (bool)($_GET['showunread'] ?? false); $showUnread = $ownProfile && (bool)($_GET['showunread'] ?? false);
$showGrouped = $ownProfile && (bool)($_GET['group'] ?? false); $showGrouped = $ownProfile && (bool)($_GET['group'] ?? false);
if ($showGrouped) { if ($showGrouped) {

View File

@@ -10,29 +10,27 @@ $filter = $_GET['filter'] ?? '';
$userMan = new Manager\User(); $userMan = new Manager\User();
if (empty($_GET['userid'])) { if (empty($_GET['userid'])) {
$user = $Viewer; $user = $Viewer;
$ownProfile = true;
} else { } else {
$userId = (int)$_GET['userid']; $userId = (int)$_GET['userid'];
if ($Viewer->id() !== $userId && !$Viewer->permitted('admin_reports')) { if ($userId !== $Viewer->id && !$Viewer->permitted('admin_reports')) {
Error403::error(); Error403::error();
} }
$user = $userMan->findById($userId); $user = $userMan->findById($userId);
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
$ownProfile = ($user->id === $Viewer->id());
} }
$ownProfile = $user->id === $Viewer->id;
if (!empty($filter) && !in_array($filter, ['resolved', 'open'])) { if (!empty($filter) && !in_array($filter, ['resolved', 'open'])) {
Error400::error('Invalid filter specified'); Error400::error('Invalid filter specified');
} }
$search = new Search\Torrent\Report($filter, '', new Manager\Torrent\ReportType(), $userMan); $search = new Search\Torrent\Report($filter, '', new Manager\Torrent\ReportType(), $userMan)
->setReporter($user)
->setOrderBy('r.ReportedTime DESC');
$paginator = new Util\Paginator(50, (int)($_REQUEST['page'] ?? 1)); $paginator = new Util\Paginator(50, (int)($_REQUEST['page'] ?? 1));
$search->setReporterId($user->id());
$search->setOrderBy('r.ReportedTime DESC');
$paginator->setTotal($search->total()); $paginator->setTotal($search->total());
$torManager = new Manager\Torrent(); $torManager = new Manager\Torrent();
@@ -45,5 +43,3 @@ echo $Twig->render('user/report-history.twig', [
'user' => $user, 'user' => $user,
'viewer' => $Viewer, 'viewer' => $Viewer,
]); ]);

View File

@@ -13,7 +13,7 @@ if (!isset($_GET['userid'])) {
if (is_null($user)) { if (is_null($user)) {
Error404::error(); Error404::error();
} }
if ($user->id !== $Viewer->id() && !$Viewer->permitted('admin_fl_history')) { if ($user->id !== $Viewer->id && !$Viewer->permitted('admin_fl_history')) {
Error403::error(); Error403::error();
} }
} }

View File

@@ -15,7 +15,7 @@ if (is_null($user)) {
Error404::error(); Error404::error();
} }
$forumSearch = new Search\Forum($user); $forumSearch = new Search\Forum($user);
if ($Viewer->id() != $user->id) { if ($user->id !== $Viewer->id) {
$forumSearch->setViewer($Viewer); $forumSearch->setViewer($Viewer);
} }