declare strict types and Gazelle namespace

This commit is contained in:
Spine
2025-02-23 05:09:28 +00:00
parent 4fb6ffa8e7
commit 36cda91529
529 changed files with 3509 additions and 1516 deletions

View File

@@ -99,7 +99,7 @@ class ApplicantRole extends BaseObject {
);
(new Manager\Applicant())->flush();
(new Manager\ApplicantRole())->flush();
return new \Gazelle\Applicant(self::$db->inserted_id());
return new Applicant(self::$db->inserted_id());
}
public function modify(): bool {

View File

@@ -317,7 +317,7 @@ class Artist extends BaseObject implements CollageEntry {
* Revert to a prior revision of the artist metadata
* (Which also creates a new revision).
*/
public function revertRevision(int $revisionId, \Gazelle\User $user): int {
public function revertRevision(int $revisionId, User $user): int {
self::$db->prepared_query("
INSERT INTO wiki_artists
(Body, Image, PageID, UserID, Summary)
@@ -726,7 +726,7 @@ class Artist extends BaseObject implements CollageEntry {
// Cache clearing
self::$cache->delete_multi([array_map(fn ($id) => "notify_artists_$id", $bookmarkList)]);
self::$cache->delete_multi([array_map(fn ($id) => sprintf(\Gazelle\Collage::CACHE_KEY, $id), $collageList)]);
self::$cache->delete_multi([array_map(fn ($id) => sprintf(Collage::CACHE_KEY, $id), $collageList)]);
foreach ($artistCollageList as $collageId) {
$collMan->findById($collageId)?->flush();
}
@@ -892,7 +892,7 @@ class Artist extends BaseObject implements CollageEntry {
$id = $this->id;
$name = $this->name();
$this->flush();
$db = new \Gazelle\DB();
$db = new DB();
self::$db->begin_transaction();
$db->relaxConstraints(true);
@@ -903,7 +903,7 @@ class Artist extends BaseObject implements CollageEntry {
self::$db->prepared_query("DELETE FROM wiki_artists WHERE PageID = ?", $id);
$db->relaxConstraints(false);
(new \Gazelle\Manager\Comment())->remove('artist', $id);
(new Manager\Comment())->remove('artist', $id);
$this->logger()->general(
"Artist $id ($name) was deleted by {$user->username()}"
);

View File

@@ -4,7 +4,7 @@ namespace Gazelle;
use Gazelle\Intf\CategoryHasArtist;
abstract class ArtistRole extends \Gazelle\Base {
abstract class ArtistRole extends Base {
protected const RENDER_TEXT = 1;
protected const RENDER_HTML = 2;
@@ -20,7 +20,7 @@ abstract class ArtistRole extends \Gazelle\Base {
public function __construct(
protected readonly CategoryHasArtist $object,
protected readonly \Gazelle\Manager\Artist $manager,
protected readonly Manager\Artist $manager,
) {}
protected function artistList(): array {

View File

@@ -9,5 +9,5 @@ abstract class BaseManager extends Base {
* Gazelle objects. Handy if you want to pass arbitrary
* managers around.
*/
abstract public function findById(int $id): ?\Gazelle\Base;
abstract public function findById(int $id): ?Base;
}

View File

@@ -3,7 +3,7 @@
namespace Gazelle;
abstract class BasePgObject extends BaseObject {
use \Gazelle\Pg;
use Pg;
public function modify(): bool {
if (!$this->dirty()) {

View File

@@ -12,7 +12,7 @@ order to better handle the caching of full pages with bits of dynamic
content that are different for every user.
Also, Memcache::get and Memcache::set have been wrapped by
Gazelle\Cache::get_value and Gazelle\Cache::cache_value. get_value uses
Cache::get_value and Cache::cache_value. get_value uses
the same argument as get, but cache_value only takes the key, the value,
and the duration (no zlib).

View File

@@ -380,13 +380,13 @@ class Collage extends BaseObject {
}
public function setFreeleech(
\Gazelle\Manager\Torrent $torMan,
\Gazelle\Tracker $tracker,
\Gazelle\User $user,
LeechType $leechType,
LeechReason $reason,
int $threshold = 0,
bool $all = false,
Manager\Torrent $torMan,
Tracker $tracker,
User $user,
LeechType $leechType,
LeechReason $reason,
int $threshold = 0,
bool $all = false,
): int {
$regular = [];
$large = [];

View File

@@ -61,8 +61,8 @@ abstract class Collector extends Base {
abstract public function fillZip(\ZipStream\ZipStream $zip): int;
public function __construct(
protected \Gazelle\User $user,
protected \Gazelle\Manager\Torrent $torMan,
protected User $user,
protected Manager\Torrent $torMan,
protected readonly string $title,
protected int $orderBy,
) {

View File

@@ -51,7 +51,7 @@ class Contest extends BaseObject {
}
// upload-flac-no-single => UploadFlacNoSingle
$className = '\\Gazelle\\Contest\\' . implode('', array_map('ucfirst', explode('-', $info['contest_type'])));
$className = 'Contest\\' . implode('', array_map('ucfirst', explode('-', $info['contest_type'])));
$info['type'] = new $className($this->id, $info['date_begin'], $info['date_end']);
if ($info['bonus_pool_id']) {
@@ -104,7 +104,7 @@ class Contest extends BaseObject {
return $this->info()['name'];
}
public function rank(\Gazelle\User $user): ?array {
public function rank(User $user): ?array {
$page = 0;
$userId = $user->id();
while (true) {

View File

@@ -88,7 +88,7 @@ class Debug {
}
$errorList = (string)json_encode(self::$Errors);
$id = (new \Gazelle\Manager\ErrorLog())->create(
$id = (new Manager\ErrorLog())->create(
uri: $uri,
userId: $userId,
duration: $this->duration(),
@@ -113,7 +113,7 @@ class Debug {
'flags' => $this->markList(),
'includes' => $this->includeList(),
'perf' => $this->perfInfo(),
'ocelot' => (new \Gazelle\Tracker())->requestList(),
'ocelot' => (new Tracker())->requestList(),
'searches' => class_exists('Sphinxql') ? \Sphinxql::$Queries : [],
'searches_time' => class_exists('Sphinxql') ? \Sphinxql::$Time : 0.0,
'queries' => $this->db->queryList(),

View File

@@ -18,8 +18,8 @@ class Download extends Base {
protected DownloadStatus $status;
public function __construct(
protected \Gazelle\Torrent $torrent,
protected \Gazelle\User\UserclassRateLimit $limiter,
protected Torrent $torrent,
protected User\UserclassRateLimit $limiter,
protected bool $useToken,
) {}
@@ -101,7 +101,7 @@ class Download extends Base {
self::$db->rollback();
return DownloadStatus::no_tokens;
}
if (!(new \Gazelle\Tracker())->addToken($this->torrent, $user)) {
if (!(new Tracker())->addToken($this->torrent, $user)) {
self::$db->rollback();
return DownloadStatus::tracker;
}

View File

@@ -210,7 +210,7 @@ class ForumPost extends BaseObject {
self::$db->commit();
$this->thread()->forum()->adjust();
(new \Gazelle\Manager\Subscription())->flushPage('forums', $threadId);
(new Manager\Subscription())->flushPage('forums', $threadId);
$thread->flushPostCatalogue($this);
$thread->flush();

View File

@@ -310,7 +310,7 @@ class ForumThread extends BaseObject {
// LastPostID is a chicken and egg situation when removing a thread,
// so foreign key constraints must be suspended temporarily.
$db = new \Gazelle\DB();
$db = new DB();
$db->relaxConstraints(true);
self::$db->prepared_query("
DELETE ft, fp, unq

View File

@@ -2,7 +2,7 @@
namespace Gazelle;
class Invite extends \Gazelle\Base {
class Invite extends Base {
protected array $info;
public function __construct(

View File

@@ -82,7 +82,7 @@ abstract class Json extends Base {
}
$info = [
'debug' => [
'queries' => \Gazelle\DB::DB()->queryList(),
'queries' => DB::DB()->queryList(),
],
];
if (class_exists('Sphinxql')) {

View File

@@ -48,7 +48,7 @@ class Log extends Base {
return $this;
}
public function merge(\Gazelle\TGroup $old, \Gazelle\TGroup $new): int {
public function merge(TGroup $old, TGroup $new): int {
self::$db->prepared_query("
UPDATE group_log SET
GroupID = ?

View File

@@ -261,16 +261,19 @@ class User extends \Gazelle\BaseManager {
* @return array $classes
*/
public function classList(): array {
if (($classList = self::$cache->get_value('user_class')) === false) {
$qid = self::$db->get_query_id();
$classList = self::$cache->get_value('user_class');
if ($classList === false) {
self::$db->prepared_query("
SELECT ID, Name, Level, Secondary, badge
FROM permissions
ORDER BY Level
");
$classList = self::$db->to_array('ID');
self::$db->set_query_id($qid);
self::$cache->cache_value('user_class', $classList, 7200);
$classList = [];
foreach (self::$db->to_array(false, MYSQLI_ASSOC, false) as $row) {
$row['Level'] = (int)$row['Level'];
$classList[$row['ID']] = $row;
}
self::$cache->cache_value('user_class', $classList, 86400);
}
return $classList;
}

View File

@@ -6,16 +6,16 @@ trait Pg {
protected static \Gazelle\DB\Pg $pgro; // R/O access
protected static \Gazelle\DB\Pg $pg; // R/W access
public function pgro(): \Gazelle\DB\Pg {
return self::$pgro ??= new \Gazelle\DB\Pg(PG_RO_DSN);
public function pgro(): DB\Pg {
return self::$pgro ??= new DB\Pg(PG_RO_DSN);
}
public function pg(): \Gazelle\DB\Pg {
public function pg(): DB\Pg {
return self::pgStatic();
}
// disgusting hack required for \View class
public static function pgStatic(): \Gazelle\DB\Pg {
return self::$pg ??= new \Gazelle\DB\Pg(PG_RW_DSN);
public static function pgStatic(): DB\Pg {
return self::$pg ??= new DB\Pg(PG_RW_DSN);
}
}

View File

@@ -9,7 +9,7 @@ class ReportAuto extends BasePgObject {
public function __construct(
protected int $id,
protected $typeMan = new \Gazelle\Manager\ReportAutoType(),
protected $typeMan = new Manager\ReportAutoType(),
) {
parent::__construct($id);
}
@@ -143,7 +143,7 @@ class ReportAuto extends BasePgObject {
/**
* returns comment id on success, null otherwise
*/
public function addComment(\Gazelle\User $user, string $comment): ?int {
public function addComment(User $user, string $comment): ?int {
$commentId = $this->pg()->scalar("
INSERT INTO report_auto_comment
(id_report_auto, id_user, comment)

View File

@@ -915,7 +915,7 @@ class Request extends BaseObject implements CategoryHasArtist {
REPLACE INTO sphinx_requests_delta (ID) VALUES (?)
", $this->id
);
(new \Gazelle\Manager\Comment())->remove('requests', $this->id);
(new Manager\Comment())->remove('requests', $this->id);
self::$db->commit();
foreach ($artisIds as $artistId) {

View File

@@ -61,7 +61,7 @@ class Staff extends BaseUser {
WHERE " . implode(' AND ', $cond), ...$args);
}
public function userStaffPmList(\Gazelle\User $user): array {
public function userStaffPmList(User $user): array {
self::$db->prepared_query("
SELECT spc.ID AS pm_id,
spc.Subject AS subject,

View File

@@ -403,7 +403,7 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
public function releaseTypeName(): ?string {
static $releaseTypes;
if (is_null($releaseTypes)) {
$releaseTypes = (new \Gazelle\ReleaseType())->list();
$releaseTypes = (new ReleaseType())->list();
}
return $this->info()['ReleaseType'] == 0 ? null : $releaseTypes[$this->releaseType()];
}
@@ -440,7 +440,7 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
/**
* Delegate stats methods to the Stats\TGroup class
*/
public function stats(): \Gazelle\Stats\TGroup {
public function stats(): Stats\TGroup {
if (!isset($this->stats)) {
$this->stats = new Stats\TGroup($this->id);
}
@@ -620,7 +620,7 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
$n = count($names);
for ($i = 0; $i < $n; $i++) {
$role = $roles[$i];
$name = \Gazelle\Artist::sanitize($names[$i]);
$name = Artist::sanitize($names[$i]);
if (!$name || !in_array($role, array_keys(ARTIST_TYPE))) {
continue;
}
@@ -807,9 +807,9 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
}
public function setFreeleech(
\Gazelle\Manager\Torrent $torMan,
\Gazelle\Tracker $tracker,
\Gazelle\User $user,
Manager\Torrent $torMan,
Tracker $tracker,
User $user,
LeechType $leechType,
LeechReason $reason,
int $threshold = 0,
@@ -853,11 +853,10 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
$old->flush();
$old->refresh();
} else {
(new \Gazelle\Manager\Bookmark())->merge($old, $this);
(new \Gazelle\Manager\Comment())->merge('torrents', $oldId, $this->id);
(new \Gazelle\Manager\Vote())->merge($old, $this, new Manager\User());
(new Manager\Bookmark())->merge($old, $this);
(new Manager\Comment())->merge('torrents', $oldId, $this->id);
(new Manager\Vote())->merge($old, $this, new Manager\User());
$this->logger()->merge($old, $this);
$old->remove($user);
}
$this->logger()
@@ -927,12 +926,12 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
", $this->id
);
foreach ($CollageIDs as $CollageID) {
self::$cache->delete_value(sprintf(\Gazelle\Collage::CACHE_KEY, $CollageID));
self::$cache->delete_value(sprintf(Collage::CACHE_KEY, $CollageID));
}
self::$cache->delete_value("torrent_collages_" . $this->id);
}
(new \Gazelle\Manager\Comment())->remove('torrents', $this->id);
(new Manager\Comment())->remove('torrents', $this->id);
// Requests
self::$db->prepared_query("
@@ -967,7 +966,7 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
", $this->id
);
$manager = new \Gazelle\DB();
$manager = new DB();
[$ok, $message] = $manager->softDelete(MYSQL_DB, 'torrents_group', [['ID', $this->id]]);
if (!$ok) {
return false;
@@ -983,8 +982,8 @@ class TGroup extends BaseObject implements CategoryHasArtist, CollageEntry {
"torrent_group_{$this->id}",
sprintf(self::CACHE_KEY, $this->id),
sprintf(self::CACHE_TLIST_KEY, $this->id),
sprintf(\Gazelle\Manager\TGroup::ID_KEY, $this->id),
sprintf(\Gazelle\Manager\Torrent::CACHE_KEY_LATEST_UPLOADS, 5),
sprintf(Manager\TGroup::ID_KEY, $this->id),
sprintf(Manager\Torrent::CACHE_KEY_LATEST_UPLOADS, 5),
]);
return true;
}

View File

@@ -107,7 +107,7 @@ class Tag extends BaseObject {
return self::$db->to_array(false, MYSQLI_ASSOC, false);
}
public function addTGroup(\Gazelle\TGroup $tgroup, \Gazelle\User $user, int $weight): int {
public function addTGroup(TGroup $tgroup, User $user, int $weight): int {
self::$db->begin_transaction();
self::$db->prepared_query("
INSERT INTO torrents_tags
@@ -154,7 +154,7 @@ class Tag extends BaseObject {
return self::$db->to_array(false, MYSQLI_ASSOC, false);
}
public function voteTGroup(\Gazelle\TGroup $tgroup, \Gazelle\User $user, string $way): int {
public function voteTGroup(TGroup $tgroup, User $user, string $way): int {
self::$db->begin_transaction();
self::$db->prepared_query("
SELECT TagID
@@ -196,7 +196,7 @@ class Tag extends BaseObject {
return $affected;
}
public function hasVoteTGroup(\Gazelle\TGroup $tgroup, \Gazelle\User $user): bool {
public function hasVoteTGroup(TGroup $tgroup, User $user): bool {
return (bool)self::$db->scalar("
SELECT 1
FROM torrents_tags_votes
@@ -207,7 +207,7 @@ class Tag extends BaseObject {
);
}
public function removeTGroup(\Gazelle\TGroup $tgroup): bool {
public function removeTGroup(TGroup $tgroup): bool {
$tgroupId = $tgroup->id();
self::$db->begin_transaction();
self::$db->prepared_query("

View File

@@ -80,7 +80,7 @@ abstract class Task extends Base {
if (!$this->isDebug && $severity === 'debug') {
return;
}
$this->events[] = new TaskScheduler\Event($severity, $message, $reference, \Gazelle\Util\Time::sqlTime());
$this->events[] = new TaskScheduler\Event($severity, $message, $reference, Util\Time::sqlTime());
}
public function debug(string $message, int $reference = 0): void {

View File

@@ -5,9 +5,9 @@ namespace Gazelle\Top10;
class Torrent extends \Gazelle\Base {
private string $baseQuery = "
SELECT
t.ID,
g.ID,
((t.Size * tls.Snatched) + (t.Size * 0.5 * tls.Leechers)) AS Data
t.ID AS torrent_id,
g.ID AS tgroup_id,
((t.Size * tls.Snatched) + (t.Size * 0.5 * tls.Leechers)) AS score
FROM torrents AS t
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)
INNER JOIN torrents_group AS g ON (g.ID = t.GroupID)
@@ -22,7 +22,7 @@ class Torrent extends \Gazelle\Base {
) {}
public function getTopTorrents($getParameters, $details = 'all', $limit = 10): array {
$cacheKey = "top10_{$details}_{$limit}_"
$cacheKey = "T10_{$details}_{$limit}_"
. trim(signature(implode('', $getParameters), TOP10_SALT), '=');
$topTorrents = self::$cache->get_value($cacheKey);
@@ -81,7 +81,11 @@ class Torrent extends \Gazelle\Base {
);
self::$db->prepared_query($query, ...$parameters);
$topTorrents = self::$db->to_array();
$topTorrents = [];
foreach (self::$db->to_array(false, MYSQLI_ASSOC, false) as $row) {
$row['score'] = (float)$row['score']; // wtf
$topTorrents[] = $row;
}
self::$cache->cache_value($cacheKey, $topTorrents, 3600 * 6);
self::$cache->delete_value("{$cacheKey}_lock");
@@ -99,7 +103,7 @@ class Torrent extends \Gazelle\Base {
return match ($details) {
'snatched' => 'tls.Snatched',
'seeded' => 'tls.Seeders',
'data' => 'Data',
'data' => 'score',
default => '(tls.Seeders + tls.Leechers)',
};
}

View File

@@ -94,7 +94,7 @@ class Torrent extends TorrentAbstract {
* Convert a stored torrent into a binary file that can be loaded in a torrent client
*/
public function torrentBody(string $announceUrl): string {
$filer = new \Gazelle\File\Torrent();
$filer = new File\Torrent();
$contents = $filer->get($this->id);
if ($contents == false) {
return '';
@@ -184,7 +184,7 @@ class Torrent extends TorrentAbstract {
return $affected;
}
public function rescoreLog(int $logId, \Gazelle\Logfile $logfile, string $version): int {
public function rescoreLog(int $logId, Logfile $logfile, string $version): int {
self::$db->prepared_query("
UPDATE torrents_logs SET
Score = ?, `Checksum` = ?, ChecksumState = ?, Ripper = ?, RipperVersion = ?,
@@ -311,7 +311,7 @@ class Torrent extends TorrentAbstract {
self::$db->begin_transaction();
$this->info();
if ($this->id > MAX_PREV_TORRENT_ID && $removePoints) {
(new \Gazelle\User\Bonus($this->uploader()))->removePointsForUpload($this);
(new User\Bonus($this->uploader()))->removePointsForUpload($this);
}
$edition = $this->edition();
@@ -322,13 +322,13 @@ class Torrent extends TorrentAbstract {
$media = $this->media();
$format = $this->format();
$encoding = $this->encoding();
(new \Gazelle\Tracker())->update('delete_torrent', [
(new Tracker())->update('delete_torrent', [
'id' => $this->id,
'info_hash' => $this->infohashEncoded(),
'reason' => $trackerReason,
]);
$manager = new \Gazelle\DB();
$manager = new DB();
$manager->relaxConstraints(true);
[$ok, $message] = $manager->softDelete(MYSQL_DB, 'torrents_leech_stats', [['TorrentID', $this->id]], false);
if (!$ok) {
@@ -439,7 +439,7 @@ class Torrent extends TorrentAbstract {
);
$affected = self::$db->affected_rows();
self::$cache->delete_value("users_tokens_{$user->id()}");
(new \Gazelle\Tracker())->removeToken($this, $user);
(new Tracker())->removeToken($this, $user);
return $affected;
}
@@ -573,7 +573,7 @@ class Torrent extends TorrentAbstract {
*
* @return int number of files regenned
*/
public function regenerateFilelist(\Gazelle\File\Torrent $filer, \OrpheusNET\BencodeTorrent\BencodeTorrent $encoder): int {
public function regenerateFilelist(File\Torrent $filer, \OrpheusNET\BencodeTorrent\BencodeTorrent $encoder): int {
$torrentFile = $filer->get($this->id);
if ($torrentFile === false) {
return 0;

View File

@@ -494,7 +494,7 @@ abstract class TorrentAbstract extends BaseObject {
return $this->info()['LogScore'];
}
public function logfileList(\Gazelle\File\RipLog $ripFiler, \Gazelle\File\RipLogHTML $htmlFiler): array {
public function logfileList(File\RipLog $ripFiler, File\RipLogHTML $htmlFiler): array {
self::$db->prepared_query("
SELECT LogID AS id,
Score,
@@ -567,7 +567,7 @@ abstract class TorrentAbstract extends BaseObject {
/**
* Get the reports associated with this torrent
*
* @return array of ids of \Gazelle\Torrent\Report
* @return array of ids of Torrent\Report
*/
public function reportIdList(User $viewer): array {
if ($this->isDeleted()) {

View File

@@ -4,14 +4,14 @@ namespace Gazelle;
use Gazelle\Util\Textarea;
class Upload extends \Gazelle\Base {
class Upload extends Base {
final public const TORRENT_INPUT_ACCEPT = ['application/x-bittorrent', '.torrent'];
final public const JSON_INPUT_ACCEPT = ['application/json', '.json'];
protected bool $isUploaded;
public function __construct(
protected \Gazelle\User $user,
protected User $user,
protected array|false $Torrent = false,
protected string|false $Error = false,
) {
@@ -66,7 +66,7 @@ class Upload extends \Gazelle\Base {
}
public function foot(bool $showFooter): string {
$torMan = new \Gazelle\Manager\Torrent();
$torMan = new Manager\Torrent();
return self::$twig->render('upload/footer.twig', [
'is_upload' => !$this->isUploaded || isset($this->Torrent['add-format']),
'info' => $this->Torrent,
@@ -129,18 +129,18 @@ class Upload extends \Gazelle\Base {
]);
}
public function music(array $GenreTags, \Gazelle\Manager\TGroup $manager): string {
public function music(array $GenreTags, Manager\TGroup $manager): string {
return self::$twig->render('upload/music.twig', [
'add_format' => $this->isUploaded && is_array($this->Torrent) && isset($this->Torrent['add-format']),
'description_album' => $this->albumDescription(),
'description_release' => $this->releaseDescription(),
'is_uploaded' => $this->isUploaded,
'logchecker_accept' => \OrpheusNET\Logchecker\Logchecker::getAcceptValues(),
'release_type' => (new \Gazelle\ReleaseType())->list(),
'release_type' => (new ReleaseType())->list(),
'tag_list' => $GenreTags,
'tgroup' => $this->isUploaded && is_array($this->Torrent) ? $manager->findById($this->Torrent['GroupID']) : null,
'torrent' => $this->Torrent,
'torrent_flags' => \Gazelle\Enum\TorrentFlag::cases(),
'torrent_flags' => Enum\TorrentFlag::cases(),
'user' => $this->user,
]);
}

View File

@@ -90,7 +90,7 @@ class User extends BaseObject {
return $this->snatch ??= new User\Snatch($this);
}
public function stats(): \Gazelle\Stats\User {
public function stats(): Stats\User {
return $this->stats ??= new Stats\User($this->id);
}
@@ -918,9 +918,9 @@ class User extends BaseObject {
/**
* Warn a user. Returns expiry date.
*/
public function warn(int $duration, string $reason, \Gazelle\User $staff, string $userMessage): string {
public function warn(int $duration, string $reason, User $staff, string $userMessage): string {
$warnTime = Time::offset($duration * 7 * 86_400);
$warning = new \Gazelle\User\Warning($this);
$warning = new User\Warning($this);
$expiry = $warning->warningExpiry();
if ($expiry) {
$subject = 'You have received a new warning';
@@ -943,7 +943,7 @@ class User extends BaseObject {
public function warnPost(
BaseObject $post,
int $weekDuration,
\Gazelle\User $staffer,
User $staffer,
string $staffReason,
string $userMessage
): void {
@@ -1310,7 +1310,7 @@ class User extends BaseObject {
return stripos($info['Artists'], "|$name|") !== false;
}
public function addArtistNotification(\Gazelle\Artist $artist): int {
public function addArtistNotification(Artist $artist): int {
$info = $this->loadArtistNotifications();
$alias = implode('|', $artist->aliasNameList());
if (!$alias) {
@@ -1353,7 +1353,7 @@ class User extends BaseObject {
return !$this->hasAttr('no-pm-delete-download');
}
public function removeArtistNotification(\Gazelle\Artist $artist): int {
public function removeArtistNotification(Artist $artist): int {
$info = $this->loadArtistNotifications();
$aliasList = $artist->aliasNameList();
foreach ($aliasList as $alias) {
@@ -1939,7 +1939,7 @@ class User extends BaseObject {
", $this->id, $name, $token
);
return $token;
} catch (\Gazelle\DB\MysqlDuplicateKeyException) {
} catch (DB\MysqlDuplicateKeyException) {
;
}
}

View File

@@ -11,7 +11,7 @@ namespace Gazelle;
*
* It begins with a RANKING_WEIGHT table in the configuration, which
* specifies the weight a dimension has towards the overall score, and
* a class name X that points to \Gazelle\UserRank\X.
* a class name X that points to UserRank\X.
*
* To explore and test in Boris:
* Consider that there are two users, one who has up/down votes a
@@ -41,7 +41,7 @@ namespace Gazelle;
* This then has to hooked up to sections/user/user.php and
* sections/ajax/user.php
*
* Future directions: pass a \Gazelle\User object to the UserRank
* Future directions: pass a User object to the UserRank
* object, and define the appropriate ethod names in the ranking
* table so that the dimension classes can obtain the metrics
* directly and not need to have them passed in.
@@ -53,7 +53,7 @@ class UserRank extends Base {
final public const PREFIX = 'percentiles_'; // Prefix for memcache keys, to make life easier
public function __construct(protected \Gazelle\UserRank\Configuration $config, protected array $dimension) {
public function __construct(protected UserRank\Configuration $config, protected array $dimension) {
$definition = $this->config->definition();
foreach ($definition as $d) {
$this->rank[$d] = $this->config->instance($d)->rank(

View File

@@ -221,12 +221,7 @@ parameters:
path: ../classes/sphinxqlresult.class.php
-
message: "#^Function payload\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#"
count: 1
path: ../sections/ajax/top10/torrents.php
-
message: "#^Function payload\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Function \\w+\\\\payload\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#"
count: 1
path: ../sections/ajax/top10/torrents.php
@@ -241,37 +236,37 @@ parameters:
path: ../sections/better/better.php
-
message: "#^Function notify invoked with 2 parameters, 3 required\\.$#"
message: "#^Function Gazelle\\\\notify invoked with 2 parameters, 3 required\\.$#"
count: 1
path: ../sections/error/404.php
-
message: "#^Function notify invoked with 2 parameters, 3 required\\.$#"
message: "#^Function Gazelle\\\\notify invoked with 2 parameters, 3 required\\.$#"
count: 1
path: ../sections/error/413.php
-
message: "#^Function notify invoked with 2 parameters, 3 required\\.$#"
message: "#^Function Gazelle\\\\notify invoked with 2 parameters, 3 required\\.$#"
count: 1
path: ../sections/error/504.php
-
message: "#^Function notify\\(\\) has no return type specified\\.$#"
message: "#^Function Gazelle\\\\notify\\(\\) has no return type specified\\.$#"
count: 1
path: ../sections/error/index.php
-
message: "#^Function notify\\(\\) has parameter \\$Channel with no type specified\\.$#"
message: "#^Function Gazelle\\\\notify\\(\\) has parameter \\$Channel with no type specified\\.$#"
count: 1
path: ../sections/error/index.php
-
message: "#^Function notify\\(\\) has parameter \\$Message with no type specified\\.$#"
message: "#^Function Gazelle\\\\notify\\(\\) has parameter \\$Message with no type specified\\.$#"
count: 1
path: ../sections/error/index.php
-
message: "#^Function notify\\(\\) has parameter \\$Viewer with no type specified\\.$#"
message: "#^Function Gazelle\\\\notify\\(\\) has parameter \\$Viewer with no type specified\\.$#"
count: 1
path: ../sections/error/index.php
@@ -291,7 +286,7 @@ parameters:
path: ../sections/recovery/save.php
-
message: "#^Function print_or_return\\(\\) has no return type specified\\.$#"
message: "#^Function Gazelle\\\\print_or_return\\(\\) has no return type specified\\.$#"
count: 1
path: ../sections/requests/fill_handle.php
@@ -300,11 +295,6 @@ parameters:
count: 1
path: ../sections/tools/managers/ajax_take_enable_request.php
-
message: "#^Function type_list\\(\\) has parameter \\$Types with no value type specified in iterable type array\\.$#"
count: 1
path: ../sections/tools/managers/referral_accounts.php
-
message: "#^Parameter \\#1 \\(array\\<int, string\\>\\|string\\) of echo cannot be converted to string\\.$#"
count: 1
@@ -319,8 +309,3 @@ parameters:
message: "#^Variable \\$url might not be defined\\.$#"
count: 2
path: ../sections/tools/development/referral_sandbox.php
-
message: "#^Function diff\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../sections/wiki/compare.php

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$torrent = (new Gazelle\Manager\Torrent())->findById((int)($_GET['id'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$torrent = (new Manager\Torrent())->findById((int)($_GET['id'] ?? 0));
if (is_null($torrent)) {
json_error('bad parameters');
}
@@ -12,11 +16,11 @@ if (empty($_FILES) || empty($_FILES['logfiles'])) {
json_error('no log files uploaded');
}
echo (new Gazelle\Json\AddLog(
echo (new Json\AddLog(
$torrent,
$Viewer,
new Gazelle\Manager\TorrentLog(new Gazelle\File\RipLog(), new Gazelle\File\RipLogHTML()),
new Gazelle\LogfileSummary($_FILES['logfiles']),
new Manager\TorrentLog(new File\RipLog(), new File\RipLogHTML()),
new LogfileSummary($_FILES['logfiles']),
))
->setVersion(1)
->response();

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$newsMan = new Gazelle\Manager\News();
declare(strict_types=1);
namespace Gazelle;
$newsMan = new Manager\News();
$newsReader = new \Gazelle\WitnessTable\UserReadNews();
if ($newsMan->latestId() < $newsReader->lastRead($Viewer)) {
$newsReader->witness($Viewer);
@@ -18,12 +22,12 @@ foreach ($headlines as $item) {
'newsId' => $item['id'],
'title' => $item['title'],
'bbBody' => $item['body'],
'body' => Text::full_format($item['body']),
'body' => \Text::full_format($item['body']),
'newsTime' => $item['created'],
];
}
$headlines = (new Gazelle\Manager\Blog())->headlines();
$headlines = (new Manager\Blog())->headlines();
$blog = [];
foreach ($headlines as $item) {
$blog[] = [
@@ -31,7 +35,7 @@ foreach ($headlines as $item) {
'author' => $item->userId(),
'title' => $item->title(),
'bbBody' => $item->body(),
'body' => Text::full_format($item->body()),
'body' => \Text::full_format($item->body()),
'blogTime' => $item->created(),
'threadId' => $item->threadId(),
];

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$artistMan = new Gazelle\Manager\Artist();
declare(strict_types=1);
namespace Gazelle;
$artistMan = new Manager\Artist();
$revisionId = isset($_GET['revisionid']) ? (int)$_GET['revisionid'] : null;
$artistId = (int)($_GET['id'] ?? 0);
@@ -37,13 +41,13 @@ if ($artistId) {
json_die("failure", "bad parameters");
}
echo (new Gazelle\Json\Artist(
echo (new Json\Artist(
$artist,
$Viewer,
new Gazelle\User\Bookmark($Viewer),
new Gazelle\Manager\Request(),
new Gazelle\Manager\TGroup(),
new Gazelle\Manager\Torrent(),
new User\Bookmark($Viewer),
new Manager\Request(),
new Manager\TGroup(),
new Manager\Torrent(),
))
->setReleasesOnly(!empty($_GET['artistreleases']))
->setVersion(2)

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
match ($_GET['method'] ?? '') {
'transcode' => include_once 'transcode.php',
'single' => include_once 'single.php',

View File

@@ -1,9 +1,13 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
echo (new Gazelle\Json\Better\SingleSeeded(
declare(strict_types=1);
namespace Gazelle;
echo (new Json\Better\SingleSeeded(
$Viewer,
new Gazelle\Better\SingleSeeded($Viewer, 'all', new Gazelle\Manager\Torrent())
new Better\SingleSeeded($Viewer, 'all', new Manager\Torrent())
))
->setVersion(2)
->response();

View File

@@ -1,15 +1,19 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (!in_array((int)($_GET['type'] ?? 0), range(0, 3))) {
json_error('Unknown transcode type');
}
$search = new Gazelle\Search\Transcode($Viewer, (new Gazelle\Manager\Torrent())->setViewer($Viewer));
$search = new Search\Transcode($Viewer, (new Manager\Torrent())->setViewer($Viewer));
if (isset($_GET['search'])) {
$search->setSearch($_GET['search']);
}
echo (new Gazelle\Json\Better\Transcode($Viewer->announceKey(), $search))
echo (new Json\Better\Transcode($Viewer->announceKey(), $search))
->setVersion(2)
->response();

View File

@@ -1,17 +1,21 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (empty($_GET['userid'])) {
$user = $Viewer;
} else {
if (!$Viewer->permitted('users_override_paranoia')) {
json_die('failure');
}
$user = (new Gazelle\Manager\User())->findById((int)$_GET['userid']);
$user = (new Manager\User())->findById((int)$_GET['userid']);
if (is_null($user)) {
json_die('failure');
}
}
echo (new Gazelle\Json\Bookmark\Artist(new Gazelle\User\Bookmark($user)))
echo (new Json\Bookmark\Artist(new User\Bookmark($user)))
->response();

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
switch ($_REQUEST['type'] ?? '') {
case 'artists':
include_once __DIR__ . '/artists.php';

View File

@@ -1,6 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
ini_set('memory_limit', -1);
if (empty($_GET['userid'])) {
@@ -9,16 +13,16 @@ if (empty($_GET['userid'])) {
if (!$Viewer->permitted('users_override_paranoia')) {
json_error('bad parameters');
}
$user = (new Gazelle\Manager\User())->findById((int)($_GET['userid'] ?? 0));
$user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0));
if (is_null($user)) {
json_error('bad parameters');
}
}
echo (new Gazelle\Json\Bookmark\TGroup(
new Gazelle\User\Bookmark($user),
new Gazelle\Manager\TGroup(),
new Gazelle\Manager\Torrent())
echo (new Json\Bookmark\TGroup(
new User\Bookmark($user),
new Manager\TGroup(),
new Manager\Torrent())
)
->setVersion(2)
->response();

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
if (empty($_GET['order_by']) || !isset(Gazelle\Search\Torrent::$SortOrders[$_GET['order_by']])) {
declare(strict_types=1);
namespace Gazelle;
if (empty($_GET['order_by']) || !isset(Search\Torrent::$SortOrders[$_GET['order_by']])) {
$OrderBy = 'time';
} else {
$OrderBy = $_GET['order_by'];
@@ -10,9 +14,9 @@ $OrderWay = ($_GET['order_way'] ?? 'desc');
$GroupResults = ($_GET['group_results'] ?? '1') != '0';
$Page = (int)($_GET['page'] ?? 1);
$Search = new Gazelle\Search\Torrent(
new Gazelle\Manager\TGroup(),
new Gazelle\Manager\Torrent(),
$Search = new Search\Torrent(
new Manager\TGroup(),
new Manager\Torrent(),
$GroupResults,
$OrderBy,
$OrderWay,
@@ -37,12 +41,12 @@ if ($resultTotal == 0) {
}
echo (new Gazelle\Json\TGroupList(
new Gazelle\User\Bookmark($Viewer),
echo (new Json\TGroupList(
new User\Bookmark($Viewer),
$Viewer->snatch(),
new Gazelle\Manager\Artist(),
(new Gazelle\Manager\TGroup())->setViewer($Viewer),
(new Gazelle\Manager\Torrent())->setViewer($Viewer),
new Manager\Artist(),
(new Manager\TGroup())->setViewer($Viewer),
(new Manager\Torrent())->setViewer($Viewer),
$Results,
$GroupResults,
$resultTotal,

View File

@@ -1,6 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
$notifier = 'Gazelle\\User\\Notification\\' . $_POST['type'];
if (!class_exists($notifier)) {
json_die('failure', 'no such notification');

View File

@@ -1,16 +1,20 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$collage = (new Gazelle\Manager\Collage())->findById((int)($_GET['id'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$collage = (new Manager\Collage())->findById((int)($_GET['id'] ?? 0));
if (is_null($collage)) {
json_die('bad parameters');
}
echo (new Gazelle\Json\Collage(
echo (new Json\Collage(
$collage,
(int)($_GET['page'] ?? 1),
$Viewer,
new Gazelle\Manager\TGroup(),
new Gazelle\Manager\Torrent()
new Manager\TGroup(),
new Manager\Torrent()
))
->response();

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$forum = (new Gazelle\Manager\Forum())->findById((int)($_GET['forumid'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$forum = (new Manager\Forum())->findById((int)($_GET['forumid'] ?? 0));
if (is_null($forum)) {
print json_die(['status' => $_GET]);
}
@@ -9,11 +13,11 @@ if (!$Viewer->readAccess($forum)) {
json_die("failure", "insufficient permission");
}
echo (new Gazelle\Json\Forum(
echo (new Json\Forum(
$forum,
$Viewer,
new Gazelle\Manager\ForumThread(),
new Gazelle\Manager\User(),
new Manager\ForumThread(),
new Manager\User(),
isset($_GET['pp']) ? (int)$_GET['pp'] : $Viewer->postsPerPage(),
(int)($_GET['page'] ?? 1),
))

View File

@@ -1,6 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if ($Viewer->disableForums()) {
print json_die('failure');
}

View File

@@ -1,11 +1,15 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$userMan = new Gazelle\Manager\User();
declare(strict_types=1);
namespace Gazelle;
$userMan = new Manager\User();
$user = [$Viewer->id() => $Viewer];
$category = [];
foreach ((new Gazelle\Manager\Forum())->forumList() as $forum) {
foreach ((new Manager\Forum())->forumList() as $forum) {
if (!$Viewer->readAccess($forum)) {
continue;
}

View File

@@ -1,15 +1,19 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (isset($_GET['postid'])) {
$post = (new Gazelle\Manager\ForumPost())->findById((int)$_GET['postid']);
$post = (new Manager\ForumPost())->findById((int)$_GET['postid']);
if (is_null($post)) {
json_error('bad post id');
}
$thread = $post->thread();
} elseif (isset($_GET['threadid']) || isset($_GET['topicid'])) {
$post = false;
$thread = (new Gazelle\Manager\ForumThread())
$thread = (new Manager\ForumThread())
->findById((int)($_GET['threadid'] ?? $_GET['topicid'] ?? 0));
if (is_null($thread)) {
json_error('bad thread id');
@@ -31,15 +35,15 @@ $postNum = match (true) {
default => 1,
};
$perPage = (int)($_GET['pp'] ?? $Viewer->postsPerPage());
$paginator = new Gazelle\Util\Paginator(
$paginator = new Util\Paginator(
$perPage,
(int)($_GET['page'] ?? ceil($postNum / $perPage)),
);
echo (new Gazelle\Json\ForumThread(
echo (new Json\ForumThread(
$thread,
$Viewer,
$paginator,
isset($_GET['updatelastread']),
new Gazelle\Manager\User(),
new Manager\User(),
))->response();

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$alertList = (new Gazelle\User\Notification($Viewer))->alertList();
declare(strict_types=1);
namespace Gazelle;
$alertList = (new User\Notification($Viewer))->alertList();
$payload = [];
foreach ($alertList as $alert) {

View File

@@ -1,12 +1,16 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$json = new Gazelle\Json\Inbox(
declare(strict_types=1);
namespace Gazelle;
$json = new Json\Inbox(
$Viewer,
$_GET['type'] ?? 'inbox',
(int)($_GET['page'] ?? 1),
($_GET['sort'] ?? 'unread') === 'unread',
new Gazelle\Manager\User(),
new Manager\User(),
);
if (!empty($_GET['search'])) {

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
require_once match ($_GET['type'] ?? 'inbox') {
'viewconv' => 'viewconv.php',
default => 'inbox.php',

View File

@@ -1,10 +1,14 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$pm = (new Gazelle\Manager\PM($Viewer))->findById((int)($_GET['id'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$pm = (new Manager\PM($Viewer))->findById((int)($_GET['id'] ?? 0));
if (is_null($pm)) {
json_die('failure');
}
$pm->markRead();
echo (new Gazelle\Json\PM($pm, new Gazelle\Manager\User()))->response();
echo (new Json\PM($pm, new Manager\User()))->response();

View File

@@ -3,6 +3,10 @@
/** @phpstan-var ?\Gazelle\User $Viewer */
/** @phpstan-var \Gazelle\Cache $Cache */
declare(strict_types=1);
namespace Gazelle;
define('AJAX', !isset($_POST['auth']));
/* 'x' requests every 'y' seconds: [5,10] = 5 requests every 10 seconds */
@@ -81,7 +85,7 @@ if (!$Viewer->permitted('site_unlimit_ajax') && isset($LimitedPages[$Action])) {
} else {
$Cache->increment_value('ajax_requests_' . $UserID);
if ($UserRequests > $rate) {
Gazelle\Util\Irc::sendMessage(IRC_CHAN_STATUS, "ajax rate limit hit by {$Viewer->username()} on $Action");
Util\Irc::sendMessage(IRC_CHAN_STATUS, "ajax rate limit hit by {$Viewer->username()} on $Action");
json_error("Rate limit exceeded");
}
}
@@ -196,7 +200,7 @@ switch ($Action) {
include_once 'wiki.php';
break;
case 'get_friends':
echo json_encode((new Gazelle\User\Friend($Viewer))->userList());
echo json_encode((new User\Friend($Viewer))->userList());
break;
case 'news_ajax':
include_once 'news_ajax.php';

View File

@@ -1,6 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
//calculate ratio
//returns 0 for DNE and -1 for infinity, because we don't want strings being returned for a numeric value in our java

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
authorize(true);
print

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
if (isset($_FILES['log']) && is_uploaded_file($_FILES['log']['tmp_name'])) {
$file = $_FILES['log'];
$isPaste = false;

View File

@@ -1,6 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('site_archive_ajax')) {
json_die('failure', 'insufficient permissions to view page');
}
@@ -16,7 +20,7 @@ if ($_GET['type'] === 'active') {
}
$where = implode(' AND ', $where);
$db = Gazelle\DB::DB();
$db = DB::DB();
$db->prepared_query("SELECT t.ID FROM torrents t INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID) WHERE {$where}");
json_print('success', ['IDs' => $db->collect('ID', false)]);

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
$limit = (int)($_GET['count'] ?? 0);
$offset = (int)($_GET['offset'] ?? 0);
@@ -8,4 +12,4 @@ if ($limit <= 0 || $offset < 0 || $limit > 10) {
json_die('failure');
}
echo (new Gazelle\Json\News($limit, $offset))->setVersion(2)->response();
echo (new Json\News($limit, $offset))->setVersion(2)->response();

View File

@@ -1,14 +1,18 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('site_torrents_notify')) {
json_die("failure");
}
echo (new Gazelle\Json\Notification\Torrent(
new Gazelle\User\Notification\Torrent($Viewer),
new Gazelle\Util\Paginator(TORRENTS_PER_PAGE, (int)($_GET['page'] ?? 1)),
new Gazelle\Manager\Torrent(),
echo (new Json\Notification\Torrent(
new User\Notification\Torrent($Viewer),
new Util\Paginator(TORRENTS_PER_PAGE, (int)($_GET['page'] ?? 1)),
new Manager\Torrent(),
))
->setVersion(2)
->response();

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
echo (
\Gazelle\Util\PasswordCheck::checkPasswordStrength($_REQUEST['password'] ?? '', $Viewer, false) ?
Util\PasswordCheck::checkPasswordStrength($_REQUEST['password'] ?? '', $Viewer, false) ?
'true' : 'false'
);

View File

@@ -2,6 +2,10 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('site_admin_forums')) {
error(403);
}
@@ -19,7 +23,7 @@ if ($_GET['depth'] != $depth) {
die("bad depth");
}
$commentMan = new Gazelle\Manager\Comment();
$commentMan = new Manager\Comment();
$history = $commentMan->loadEdits($pageType, $postId);
[$userId, $editTime] = $history[$depth];
@@ -27,7 +31,7 @@ if ($depth != 0) {
$body = $history[$depth - 1][2];
} else {
$body = match ($pageType) {
'forums' => (new Gazelle\Manager\ForumPost())->findById($postId)->body(),
'forums' => (new Manager\ForumPost())->findById($postId)->body(),
default => $commentMan->findById($postId)->body(),
};
}

View File

@@ -1,11 +1,15 @@
<?php
Text::$TOC = true;
declare(strict_types=1);
namespace Gazelle;
\Text::$TOC = true;
if (!empty($_POST['admincomment'])) {
echo Text::full_format($_POST['admincomment']);
echo \Text::full_format($_POST['admincomment']);
} elseif (!empty($_POST['WikiText'])) {
echo Text::full_format($_REQUEST['WikiText']);
echo \Text::full_format($_REQUEST['WikiText']);
} else {
echo Text::full_format($_REQUEST['body']);
echo \Text::full_format($_REQUEST['body']);
}

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$post = (new Gazelle\Manager\ForumPost())->findById((int)($_GET['postid'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$post = (new Manager\ForumPost())->findById((int)($_GET['postid'] ?? 0));
if (is_null($post)) {
json_die("failure", "empty postid");
} elseif (!$Viewer->readAccess($post->thread()->forum())) {

View File

@@ -1,17 +1,21 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$request = (new Gazelle\Manager\Request())->findById((int)($_GET['id'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$request = (new Manager\Request())->findById((int)($_GET['id'] ?? 0));
if (is_null($request)) {
json_die("failure");
}
echo (new Gazelle\Json\Request(
echo (new Json\Request(
$request,
$Viewer,
new Gazelle\User\Bookmark($Viewer),
new Gazelle\Comment\Request($request->id(), (int)($_GET['page'] ?? 1), (int)($_GET['post'] ?? 0)),
new Gazelle\Manager\User(),
new User\Bookmark($Viewer),
new Comment\Request($request->id(), (int)($_GET['page'] ?? 1), (int)($_GET['post'] ?? 0)),
new Manager\User(),
))
->setVersion(2)
->response();

View File

@@ -1,9 +1,13 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$search = new Gazelle\Search\Request(new Gazelle\Manager\Request());
declare(strict_types=1);
$userMan = new Gazelle\Manager\User();
namespace Gazelle;
$search = new Search\Request(new Manager\Request());
$userMan = new Manager\User();
if (!isset($_GET['userid'])) {
$user = null;
} else {
@@ -99,7 +103,7 @@ if (isset($_GET['requestor'])) {
}
}
$paginator = new Gazelle\Util\Paginator(REQUESTS_PER_PAGE, (int)($_GET['page'] ?? 1));
$paginator = new Util\Paginator(REQUESTS_PER_PAGE, (int)($_GET['page'] ?? 1));
if ($type === 'random') {
$search->limit(0, REQUESTS_PER_PAGE, REQUESTS_PER_PAGE);
} else {
@@ -121,6 +125,6 @@ $search->execute(
);
$paginator->setTotal($search->total());
echo (new Gazelle\Json\Requests($search, $paginator->page(), $userMan))
echo (new Json\Requests($search, $paginator->page(), $userMan))
->setVersion(2)
->response();

View File

@@ -1,14 +1,18 @@
<?php
declare(strict_types=1);
namespace Gazelle;
$logId = (int)($_GET['logid'] ?? 0);
if (!$logId) {
json_error('missing logid parameter');
}
$torrent = (new Gazelle\Manager\Torrent())->findById((int)($_GET['id'] ?? 0));
$torrent = (new Manager\Torrent())->findById((int)($_GET['id'] ?? 0));
if (is_null($torrent)) {
json_error('torrent not found');
}
echo (new Gazelle\Json\RipLog($torrent->id(), $logId))
echo (new Json\RipLog($torrent->id(), $logId))
->setVersion(2)
->response();

View File

@@ -1,9 +1,13 @@
<?php
$artist = (new Gazelle\Manager\Artist())->findById((int)($_GET['id'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$artist = (new Manager\Artist())->findById((int)($_GET['id'] ?? 0));
if (is_null($artist)) {
print json_die('missing artist id');
}
$limit = max(50, (int)($_GET['limit'] ?? 10));
echo (new Gazelle\Json\ArtistSimilar($artist, $limit))->response();
echo (new Json\ArtistSimilar($artist, $limit))->response();

View File

@@ -1,9 +1,13 @@
<?php
echo (new Gazelle\Json\Stats\General(
new Gazelle\Stats\Request(),
new Gazelle\Stats\Torrent(),
new Gazelle\Stats\Users(),
declare(strict_types=1);
namespace Gazelle;
echo (new Json\Stats\General(
new Stats\Request(),
new Stats\Torrent(),
new Stats\Users(),
))
->setVersion(2)
->response();

View File

@@ -1,5 +1,9 @@
<?php
echo (new Gazelle\Json\Stats\Torrent(new Gazelle\Stats\Torrent()))
declare(strict_types=1);
namespace Gazelle;
echo (new Json\Stats\Torrent(new Stats\Torrent()))
->setVersion(2)
->response();

View File

@@ -1,9 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
echo (new Gazelle\Json\Stats\User(
new Gazelle\Stats\Users(),
$Viewer,
))
declare(strict_types=1);
namespace Gazelle;
echo (new Json\Stats\User(new Stats\Users(), $Viewer))
->setVersion(2)
->response();

View File

@@ -1,14 +1,18 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if ($Viewer->disableForums()) {
json_die('failure');
}
$showUnread = (bool)($_GET['showunread'] ?? true);
$forMan = new Gazelle\Manager\Forum();
$paginator = new Gazelle\Util\Paginator($Viewer->postsPerPage(), (int)($_GET['page'] ?? 1));
$forMan = new Manager\Forum();
$paginator = new Util\Paginator($Viewer->postsPerPage(), (int)($_GET['page'] ?? 1));
$paginator->setTotal(
$showUnread ? $forMan->unreadSubscribedForumTotal($Viewer) : $forMan->subscribedForumTotal($Viewer)
);

View File

@@ -1,15 +1,19 @@
<?php
declare(strict_types=1);
namespace Gazelle;
$groupId = (int)($_GET['id'] ?? 0);
if (!$groupId) {
json_die("failure");
}
$commentPage = new Gazelle\Comment\Torrent($groupId, (int)($_GET['page'] ?? 1), (int)($_GET['postid'] ?? 0));
$commentPage = new Comment\Torrent($groupId, (int)($_GET['page'] ?? 1), (int)($_GET['postid'] ?? 0));
$thread = $commentPage->load()->thread();
$userCache = [];
$userMan = new Gazelle\Manager\User();
$userMan = new Manager\User();
$JsonComments = [];
foreach ($thread as $Post) {
@@ -22,14 +26,14 @@ foreach ($thread as $Post) {
'postId' => $PostID,
'addedTime' => $AddedTime,
'bbBody' => $Body,
'body' => Text::full_format($Body),
'body' => \Text::full_format($Body),
'editedUserId' => $EditedUserID,
'editedTime' => $EditedTime,
'editedUsername' => $EditedUsername,
'userinfo' => [
'authorId' => $AuthorID,
'authorName' => $author->username(),
'donor' => (new Gazelle\User\Donor($author))->isDonor(),
'donor' => (new User\Donor($author))->isDonor(),
'warned' => $author->isWarned(),
'avatar' => $author->avatar(),
'enabled' => $author->isEnabled(),

View File

@@ -1,6 +1,10 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('site_top10')) {
json_die('failure');
}

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
$details = $_GET['details'] ?? 'all';
if (!in_array($details, ['all', 'ut', 'ur', 'v'])) {
json_die(['status' => 'bad details parameter']);
@@ -10,10 +14,10 @@ if (!in_array($limit, [10, 100, 250])) {
json_die(['status' => 'bad limit parameter']);
}
echo (new Gazelle\Json\Top10\Tag(
echo (new Json\Top10\Tag(
details: $details,
limit: $limit,
manager: new Gazelle\Manager\Tag(),
manager: new Manager\Tag(),
))
->setVersion(2)
->response();

View File

@@ -2,13 +2,17 @@
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
$details = isset($_GET['details']) && in_array($_GET['details'], ['day', 'week', 'overall', 'snatched', 'data', 'seeded', 'month', 'year']) ? $_GET['details'] : 'all';
$limit = (int)($_GET['limit'] ?? 10);
$limit = in_array($limit, [10, 100, 250]) && $details !== 'all' ? $limit : 10;
$top10 = new Gazelle\Top10\Torrent(FORMAT, $Viewer);
$torMan = new Gazelle\Manager\Torrent();
$top10 = new Top10\Torrent(FORMAT, $Viewer);
$torMan = new Manager\Torrent();
$result = [];
// Filter out common parameters that are not needed in getTopTorrents to get more cache hits
@@ -91,7 +95,10 @@ print json_encode([
'response' => $result
]);
function payload(Gazelle\Manager\Torrent $torMan, array $details): array {
/**
* @return array<array<mixed>>
*/
function payload(Manager\Torrent $torMan, array $details): array {
$results = [];
foreach ($details as $detail) {
$torrent = $torMan->findById($detail[0]);

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
$details = $_GET['details'] ?? 'all';
if (!in_array($details, ['all', 'ul', 'dl', 'numul', 'uls', 'dls'])) {
json_die('failure', 'bad details parameter');
@@ -10,11 +14,11 @@ if (!in_array($limit, [10, 100, 250])) {
json_die('failure', 'bad limit parameter');
}
echo (new Gazelle\Json\Top10\User(
echo (new Json\Top10\User(
details: $details,
limit: $limit,
stats: new Gazelle\Stats\Users(),
userMan: new Gazelle\Manager\User(),
stats: new Stats\Users(),
userMan: new Manager\User(),
))
->setVersion(2)
->response();

View File

@@ -1,17 +1,21 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (isset($_GET['id']) && isset($_GET['hash'])) {
json_error('bad parameters');
} elseif (isset($_GET['hash'])) {
$torrent = (new Gazelle\Manager\Torrent())->findByInfohash($_GET['hash'] ?? '');
$torrent = (new Manager\Torrent())->findByInfohash($_GET['hash'] ?? '');
} else {
$torrent = (new Gazelle\Manager\Torrent())->findById((int)$_GET['id']);
$torrent = (new Manager\Torrent())->findById((int)$_GET['id']);
}
if (is_null($torrent)) {
json_error('bad parameters');
}
echo (new Gazelle\Json\Torrent($torrent, $Viewer, new Gazelle\Manager\Torrent()))
echo (new Json\Torrent($torrent, $Viewer, new Manager\Torrent()))
->setVersion(5)
->response();

View File

@@ -1,11 +1,15 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
authorize();
if (!$Viewer->permitted('site_edit_wiki')) {
json_die('failure', 'forbidden');
}
$tgroup = (new Gazelle\Manager\TGroup())->findById((int)$_GET['groupid']);
$tgroup = (new Manager\TGroup())->findById((int)$_GET['groupid']);
$coverId = (int)$_GET['id'];
if (!$coverId || is_null($tgroup)) {
json_die('failure', 'bad parameters');

View File

@@ -2,6 +2,10 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Gazelle\Cache $Cache */
declare(strict_types=1);
namespace Gazelle;
if ($Viewer->disableTagging()) {
json_or_error('tagging disabled for your account', 403);
}
@@ -10,7 +14,7 @@ if (!defined('AJAX') || !AJAX) {
authorize();
}
$tgMan = new Gazelle\Manager\TGroup();
$tgMan = new Manager\TGroup();
$tgroup = $tgMan->findById((int)($_REQUEST['groupid'] ?? 0));
if (is_null($tgroup)) {
json_or_error('invalid groupid', 0);

View File

@@ -2,12 +2,16 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Gazelle\Cache $Cache */
declare(strict_types=1);
namespace Gazelle;
authorize();
if ($Viewer->disableTagging() || !$Viewer->permitted('site_delete_tag')) {
error(403);
}
$tagMan = new Gazelle\Manager\Tag();
$tgMan = new Gazelle\Manager\TGroup();
$tagMan = new Manager\Tag();
$tgMan = new Manager\TGroup();
$tag = $tagMan->findById((int)$_GET['tagid']);
$tgroup = $tgMan->findById((int)$_GET['groupid']);

View File

@@ -1,13 +1,17 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
$groupId = (int)($_GET['id'] ?? 0);
$infohash = $_GET['hash'] ?? null;
if ($groupId && $infohash) {
json_error('bad parameters');
}
$tgMan = new Gazelle\Manager\TGroup();
$tgMan = new Manager\TGroup();
$tgroup = $infohash
? $tgMan->findByTorrentInfohash($infohash)
: $tgMan->findById($groupId);
@@ -16,9 +20,9 @@ if (is_null($tgroup)) {
json_error('bad parameters');
}
echo (new Gazelle\Json\TGroup(
echo (new Json\TGroup(
$tgroup,
$Viewer,
(new \Gazelle\Manager\Torrent())->setViewer($Viewer))
(new Manager\Torrent())->setViewer($Viewer))
)->setVersion(2)
->response();

View File

@@ -1,6 +1,10 @@
<?php
$tgroup = (new Gazelle\Manager\TGroup())->findById((int)$_GET['id']);
declare(strict_types=1);
namespace Gazelle;
$tgroup = (new Manager\TGroup())->findById((int)$_GET['id']);
if (is_null($tgroup)) {
json_die('failure', 'bad id parameter');
}

View File

@@ -1,9 +1,13 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
// echo out the slice of the form needed for the selected upload type ($_GET['section']).
$uploadForm = new Gazelle\Upload($Viewer);
$uploadForm = new Upload($Viewer);
$emitJS = isset($_GET['js']);
switch (CATEGORY[(int)$_GET['categoryid']]) {
@@ -34,7 +38,7 @@ switch (CATEGORY[(int)$_GET['categoryid']]) {
case 'Music':
echo $emitJS
? $uploadForm->albumReleaseJS()
: $uploadForm->music((new Gazelle\Manager\Tag())->genreList(), new Gazelle\Manager\TGroup());
: $uploadForm->music((new Manager\Tag())->genreList(), new Manager\TGroup());
break;
default:

View File

@@ -1,11 +1,15 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$user = (new Gazelle\Manager\User())->findById((int)$_GET['id']);
declare(strict_types=1);
namespace Gazelle;
$user = (new Manager\User())->findById((int)$_GET['id']);
if (is_null($user)) {
json_die("failure", "bad id parameter");
}
echo (new Gazelle\Json\User($user, $Viewer))
echo (new Json\User($user, $Viewer))
->setVersion(2)
->response();

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$user = (new Gazelle\Manager\User())->findById((int)($_GET['userid'] ?? 0));
declare(strict_types=1);
namespace Gazelle;
$user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0));
if (is_null($user)) {
json_error("bad userid");
}
@@ -10,7 +14,7 @@ if ($limit < 1 || $limit > 50) {
json_error("bad limit");
}
echo (new Gazelle\Json\UserRecent($user, $Viewer, new Gazelle\Manager\TGroup()))
echo (new Json\UserRecent($user, $Viewer, new Manager\TGroup()))
->setLimit($limit)
->setVersion(2)
->response();

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
match ($_GET['type'] ?? '') {
'posts' => include_once 'post_history.php',
default => json_error('bad type'),

View File

@@ -1,23 +1,27 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if ($Viewer->disableForums()) {
json_error('You do not have access to the forums!');
}
$user = empty($_GET['userid']) ? $Viewer : (new Gazelle\Manager\User())->findById((int)$_GET['userid']);
$user = empty($_GET['userid']) ? $Viewer : (new Manager\User())->findById((int)$_GET['userid']);
if (is_null($user)) {
json_error('User does not exist!');
}
$ownProfile = ($user->id() === $Viewer->id());
$forumSearch = (new Gazelle\Search\Forum($user))
$forumSearch = (new Search\Forum($user))
->setViewer($Viewer)
->setShowGrouped($ownProfile && (!isset($_GET['group']) || !!$_GET['group']))
->setShowUnread($ownProfile && (!isset($_GET['showunread']) || !!$_GET['showunread']));
echo (new Gazelle\Json\PostHistory(
echo (new Json\PostHistory(
$forumSearch,
new Gazelle\Manager\User(),
new Gazelle\Util\Paginator($Viewer->postsPerPage(), (int)($_GET['page'] ?? 1))
new Manager\User(),
new Util\Paginator($Viewer->postsPerPage(), (int)($_GET['page'] ?? 1))
))->response();

View File

@@ -1,16 +1,20 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
$search = trim($_GET['search'] ?? '');
if (!strlen($search)) {
json_die("failure", "no search terms");
}
echo (new Gazelle\Json\UserSearch(
echo (new Json\UserSearch(
$search,
$Viewer,
new Gazelle\Manager\User(),
new Gazelle\Util\Paginator(AJAX_USERS_PER_PAGE, (int)($_GET['page'] ?? 1)),
new Manager\User(),
new Util\Paginator(AJAX_USERS_PER_PAGE, (int)($_GET['page'] ?? 1)),
))
->setVersion(2)
->response();

View File

@@ -1,16 +1,20 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
authorize();
if (!$Viewer->permitted('site_album_votes')) {
json_error('forbidden');
}
$tgroup = (new Gazelle\Manager\TGroup())->findById((int)$_REQUEST['groupid']);
$tgroup = (new Manager\TGroup())->findById((int)$_REQUEST['groupid']);
if (is_null($tgroup)) {
json_error('no such group');
}
$vote = new Gazelle\User\Vote($Viewer);
$vote = new User\Vote($Viewer);
if ($_REQUEST['do'] != 'vote') {
json_error('bad args');

View File

@@ -1,7 +1,11 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
$wikiMan = new Gazelle\Manager\Wiki();
declare(strict_types=1);
namespace Gazelle;
$wikiMan = new Manager\Wiki();
if (isset($_GET['id'])) {
$wiki = $wikiMan->findById((int)$_GET['id']);
} elseif (isset($_GET['name'])) {
@@ -17,15 +21,15 @@ if ($wiki->minClassRead() > $Viewer->privilege()->effectiveClassLevel()) {
json_error("higher user class required to view article");
}
Text::$TOC = true;
\Text::$TOC = true;
json_print("success", [
'title' => $wiki->title(),
'bbBody' => $wiki->body(),
'body' => Text::full_format($wiki->body(), false),
'body' => \Text::full_format($wiki->body(), false),
'aliases' => $wiki->alias(),
'authorID' => $wiki->authorId(),
'authorName' => (new Gazelle\Manager\User())->findById($wiki->authorId())?->username(),
'authorName' => (new Manager\User())->findById($wiki->authorId())?->username(),
'date' => $wiki->date(),
'revision' => $wiki->revision(),
]);

View File

@@ -1,10 +1,14 @@
<?php
/** @phpstan-var \Gazelle\Debug $Debug */
declare(strict_types=1);
namespace Gazelle;
if (empty($_GET['aid']) || empty($_GET['token'])) {
json_error('invalid parameters');
}
if (!(new Gazelle\API())->validateToken((int)($_GET['aid'] ?? 0), $_GET['token'] ?? '')) {
if (!(new API())->validateToken((int)($_GET['aid'] ?? 0), $_GET['token'] ?? '')) {
json_error('invalid token');
}
$className = "Gazelle\\API\\" . str_replace("_", "", ucwords($_GET['action'], "_"));

View File

@@ -2,7 +2,11 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
$appRoleMan = new Gazelle\Manager\ApplicantRole();
declare(strict_types=1);
namespace Gazelle;
$appRoleMan = new Manager\ApplicantRole();
if ($Viewer->permitted('admin_manage_applicants')) {
$list = $appRoleMan->list(); // everything, including archived roles
} else {
@@ -33,6 +37,6 @@ if (isset($_POST['auth'])) {
echo $Twig->render('applicant/admin.twig', [
'error' => $error,
'list' => $list,
'text' => new Gazelle\Util\Textarea('description', ''),
'text' => new Util\Textarea('description', ''),
'viewer' => $Viewer,
]);

View File

@@ -2,8 +2,12 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
$appMan = new Gazelle\Manager\Applicant();
$roleMan = new Gazelle\Manager\ApplicantRole();
declare(strict_types=1);
namespace Gazelle;
$appMan = new Manager\Applicant();
$roleMan = new Manager\ApplicantRole();
if (isset($_POST['auth'])) {
authorize();
@@ -27,7 +31,7 @@ if (isset($_POST['auth'])) {
}
echo $Twig->render('applicant/apply.twig', [
'body' => new Gazelle\Util\Textarea('body', $body ?? ''),
'body' => new Util\Textarea('body', $body ?? ''),
'error' => $error ?? null,
'list' => $roleMan->publishedList(),
'role' => $role ?? null,

View File

@@ -2,11 +2,15 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('admin_manage_applicants')) {
error(403);
}
$role = (new Gazelle\Manager\ApplicantRole())->findById((int)($_GET['id'] ?? 0));
$role = (new Manager\ApplicantRole())->findById((int)($_GET['id'] ?? 0));
if (is_null($role)) {
error(404);
}
@@ -29,10 +33,10 @@ if (isset($_POST['auth'])) {
}
}
$userMan = new Gazelle\Manager\User();
$userMan = new Manager\User();
echo $Twig->render('applicant/role.twig', [
'text' => new Gazelle\Util\Textarea('description', $role->description()),
'text' => new Util\Textarea('description', $role->description()),
'role' => $role,
'error' => $error ?? null,
'viewer' => $Viewer,

View File

@@ -1,5 +1,9 @@
<?php
declare(strict_types=1);
namespace Gazelle;
require_once match ($_GET['action'] ?? '') {
'admin' => 'admin.php',
'edit' => 'edit.php',

View File

@@ -2,7 +2,11 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
$appMan = new Gazelle\Manager\Applicant();
declare(strict_types=1);
namespace Gazelle;
$appMan = new Manager\Applicant();
if (isset($_REQUEST['id'])) {
$app = $appMan->findById((int)$_GET['id']);
if (is_null($app)) {
@@ -46,6 +50,6 @@ echo $Twig->render('applicant/view.twig', [
$Viewer->permitted('users_mod') => $appMan->openList($Viewer),
default => $appMan->userList($Viewer),
},
'note' => new Gazelle\Util\Textarea('note_reply', ''),
'note' => new Util\Textarea('note_reply', ''),
'viewer' => $Viewer,
]);

View File

@@ -2,18 +2,22 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('torrents_edit')) {
error(403);
}
authorize();
$redirectId = (int)$_POST['redirect'];
$newName = Gazelle\Artist::sanitize($_POST['name']);
$newName = Artist::sanitize($_POST['name']);
if (empty($newName)) {
error('The specified name is empty.');
}
$artMan = new Gazelle\Manager\Artist();
$artMan = new Manager\Artist();
$artist = $artMan->findById((int)$_POST['artistid']);
if (is_null($artist)) {
error(404);

View File

@@ -1,11 +1,15 @@
<?php
/** @phpstan-var \Gazelle\User $Viewer */
declare(strict_types=1);
namespace Gazelle;
if (!defined('AJAX')) {
authorize();
}
$artistMan = new Gazelle\Manager\Artist();
$artistMan = new Manager\Artist();
$artist = $artistMan->findById((int)($_POST['artistid'] ?? 0));
if (is_null($artist)) {
if (defined('AJAX')) {

View File

@@ -4,8 +4,12 @@
// phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
declare(strict_types=1);
namespace Gazelle;
$revisionId = (int)($_GET['revisionid'] ?? 0);
$artistMan = new Gazelle\Manager\Artist();
$artistMan = new Manager\Artist();
$artist = $revisionId
? $artistMan->findByIdAndRevision((int)($_GET['id'] ?? 0), $revisionId)
: $artistMan->findById((int)($_GET['id'] ?? 0));
@@ -15,21 +19,22 @@ if (is_null($artist)) {
$artist->loadArtistRole();
$artistId = $artist->id();
$bookmark = new Gazelle\User\Bookmark($Viewer);
$collageMan = new Gazelle\Manager\Collage();
$tgMan = (new Gazelle\Manager\TGroup())->setViewer($Viewer);
$torMan = (new Gazelle\Manager\Torrent())->setViewer($Viewer);
$stats = new Gazelle\Stats\Artist($artistId);
$userMan = new Gazelle\Manager\User();
$reportMan = new Gazelle\Manager\Report($userMan);
$vote = new Gazelle\User\Vote($Viewer);
$imgProxy = new Gazelle\Util\ImageProxy($Viewer);
$bookmark = new User\Bookmark($Viewer);
$collageMan = new Manager\Collage();
$tgMan = (new Manager\TGroup())->setViewer($Viewer);
$torMan = (new Manager\Torrent())->setViewer($Viewer);
$stats = new Stats\Artist($artistId);
$userMan = new Manager\User();
$reportMan = new Manager\Report($userMan);
$vote = new User\Vote($Viewer);
$imgProxy = new Util\ImageProxy($Viewer);
$isSubscribed = (new User\Subscription($Viewer))->isSubscribedComments('artist', $artistId);
$requestList = $Viewer->disableRequests() ? [] : (new Manager\Request())->findByArtist($artist);
$isSubscribed = (new Gazelle\User\Subscription($Viewer))->isSubscribedComments('artist', $artistId);
$requestList = $Viewer->disableRequests() ? [] : (new Gazelle\Manager\Request())->findByArtist($artist);
if (count($artist->groupIds()) > 1000) {
// prevent OOMs
Gazelle\DB::DB()->disableQueryLog();
DB::DB()->disableQueryLog();
}
echo $Twig->render('artist/header.twig', [
@@ -39,9 +44,7 @@ echo $Twig->render('artist/header.twig', [
'revision_id' => $revisionId,
'viewer' => $Viewer,
]);
?>
<?php
$artistReleaseType = [];
$sections = $artist->sections();
foreach ($sections as $sectionId => $groupList) {
@@ -198,7 +201,7 @@ if ($sections = $artist->sections()) {
</div>
<table class="torrent_table grouped release_table m_table">
<?php
$urlStem = (new Gazelle\User\Stylesheet($Viewer))->imagePath();
$urlStem = (new User\Stylesheet($Viewer))->imagePath();
$groupsClosed = (bool)$Viewer->option('TorrentGrouping');
$snatcher = $Viewer->snatch();
@@ -301,14 +304,14 @@ echo $Twig->render('artist/similar-graph.twig', [
<strong>Artist Information</strong>
<a href="#" class="brackets" onclick="$('#body').gtoggle(); return false;">Toggle</a>
</div>
<div id="body" class="body"><?=Text::full_format($artist->body())?></div>
<div id="body" class="body"><?=\Text::full_format($artist->body())?></div>
</div>
<div id="artistcomments">
<?php
$commentPage = new Gazelle\Comment\Artist($artistId, (int)($_GET['page'] ?? 0), (int)($_GET['postid'] ?? 0));
$commentPage = new Comment\Artist($artistId, (int)($_GET['page'] ?? 0), (int)($_GET['postid'] ?? 0));
$commentPage->load()->handleSubscription($Viewer);
$paginator = new Gazelle\Util\Paginator(TORRENT_COMMENTS_PER_PAGE, $commentPage->pageNum());
$paginator = new Util\Paginator(TORRENT_COMMENTS_PER_PAGE, $commentPage->pageNum());
$paginator->setAnchor('comments')->setTotal($commentPage->total())->removeParam('postid');
echo $Twig->render('comment/thread.twig', [
@@ -318,7 +321,7 @@ echo $Twig->render('comment/thread.twig', [
'comment' => $commentPage,
'paginator' => $paginator,
'subbed' => $isSubscribed,
'textarea' => (new Gazelle\Util\Textarea('quickpost', '', 90, 8))->setPreviewManual(true),
'textarea' => (new Util\Textarea('quickpost', '', 90, 8))->setPreviewManual(true),
'url' => $_SERVER['REQUEST_URI'],
'url_stem' => 'comments.php?page=artist',
'userMan' => $userMan,
@@ -330,4 +333,4 @@ echo $Twig->render('comment/thread.twig', [
</div>
</div>
<?php
View::show_footer();
\View::show_footer();

View File

@@ -1,9 +1,13 @@
<?php
declare(strict_types=1);
namespace Gazelle;
header('Content-Type: application/json; charset=utf-8');
$prefix = trim(urldecode($_GET['query'] ?? ''));
echo json_encode([
'query' => $prefix,
'suggestions' => (new Gazelle\Manager\Artist())->autocompleteList($prefix),
'suggestions' => (new Manager\Artist())->autocompleteList($prefix),
]);

View File

@@ -2,12 +2,16 @@
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
declare(strict_types=1);
namespace Gazelle;
if (!$Viewer->permitted('torrents_edit')) {
error(403);
}
authorize();
$artMan = new Gazelle\Manager\Artist();
$artMan = new Manager\Artist();
$artist = $artMan->findById((int)($_POST['artistid'] ?? 0));
if (is_null($artist)) {
error('Please select a valid artist to change.');

Some files were not shown because too many files have changed in this diff Show More