Adopt Laravel coding style

Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started.

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
This commit is contained in:
Laravel Shift 2021-02-14 02:39:15 +00:00
parent a1522f3cd7
commit 263ea48c5b
390 changed files with 43866 additions and 44115 deletions

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -45,8 +45,8 @@ class AlbumDownloader
public function download()
{
// Check whether the format is lossless yet not all master files are lossless
$isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats)
&& !$this->_album->hasLosslessTracksOnly()
$isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats)
&& ! $this->_album->hasLosslessTracksOnly()
&& $this->_album->hasLosslessTracks();
$zip = new ZipStream($this->_album->user->display_name.' - '.$this->_album->title.'.zip');
@ -71,7 +71,7 @@ class AlbumDownloader
"\r\n";
foreach ($this->_album->tracks as $track) {
if (!$track->is_downloadable) {
if (! $track->is_downloadable) {
continue;
}
@ -79,12 +79,12 @@ class AlbumDownloader
$masterFormatName = $track->getMasterFormatName();
$zip->addLargeFile(
$track->getFileFor($masterFormatName),
$directory . $track->getDownloadFilenameFor($masterFormatName)
$directory.$track->getDownloadFilenameFor($masterFormatName)
);
} else {
$zip->addLargeFile(
$track->getFileFor($this->_format),
$directory . $track->getDownloadFilenameFor($this->_format)
$directory.$track->getDownloadFilenameFor($this->_format)
);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -59,20 +59,19 @@ class AddTrackToPlaylistCommand extends CommandBase
// check if this track is already in the playlist
$validator = Validator::make(
['track_id' => $this->_track->id],
['track_id' => "unique:playlist_track,track_id,null,id,playlist_id,{$this->_playlist->id}", ]
['track_id' => "unique:playlist_track,track_id,null,id,playlist_id,{$this->_playlist->id}"]
);
if ($validator->fails()) {
return CommandResponse::fail($validator);
}
$songIndex = $this->_playlist->trackCount() + 1;
$this->_playlist->tracks()->attach($this->_track, ['position' => $songIndex]);
$this->_playlist->touch();
Playlist::where('id', $this->_playlist->id)->update([
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')')
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')'),
]);
return CommandResponse::succeed(['message' => 'Track added!']);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -37,7 +37,7 @@ class CommandResponse
public static function fail($validatorOrMessages, int $statusCode = 400)
{
$response = new CommandResponse();
$response = new self();
$response->_didFail = true;
$response->_statusCode = $statusCode;
@ -53,7 +53,7 @@ class CommandResponse
public static function succeed($response = null, int $statusCode = 200)
{
$cmdResponse = new CommandResponse();
$cmdResponse = new self();
$cmdResponse->_didFail = false;
$cmdResponse->_response = $response;
$cmdResponse->_statusCode = $statusCode;

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,11 +20,11 @@
namespace App\Commands;
use Gate;
use App\Models\Album;
use App\Models\Image;
use Auth;
use App\Models\User;
use Auth;
use Gate;
use Validator;
class CreateAlbumCommand extends CommandBase
@ -60,7 +60,7 @@ class CreateAlbumCommand extends CommandBase
'cover' => 'image|mimes:png|min_width:350|min_height:350',
'cover_id' => 'exists:images,id',
'track_ids' => 'exists:tracks,id',
'user_id' => 'exists:users,id'
'user_id' => 'exists:users,id',
];
$validator = Validator::make($this->_input, $rules);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,8 +20,8 @@
namespace App\Commands;
use Gate;
use App\Models\Announcement;
use Gate;
use Validator;
class CreateAnnouncementCommand extends CommandBase
@ -48,7 +48,6 @@ class CreateAnnouncementCommand extends CommandBase
*/
public function execute()
{
$rules = [
'name' => 'required|max:50',
];

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,13 +20,13 @@
namespace App\Commands;
use Notification;
use App\Models\Album;
use App\Models\Comment;
use App\Models\Playlist;
use App\Models\Track;
use App\Models\User;
use Auth;
use Notification;
use Validator;
class CreateCommentCommand extends CommandBase
@ -112,7 +112,7 @@ class CreateCommentCommand extends CommandBase
$entity->comment_count = Comment::where($column, $this->_id)->count();
$entity->save();
Notification::newComment($comment);
return CommandResponse::succeed(Comment::mapPublic($comment));

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Commands;
use App\Models\Genre;
use Gate;
use Illuminate\Support\Str;
use App\Models\Genre;
use Validator;
class CreateGenreCommand extends CommandBase
@ -53,12 +53,12 @@ class CreateGenreCommand extends CommandBase
$rules = [
'name' => 'required|unique:genres,name,NULL,id,deleted_at,NULL|max:50',
'slug' => 'required|unique:genres,slug,NULL,id,deleted_at,NULL'
'slug' => 'required|unique:genres,slug,NULL,id,deleted_at,NULL',
];
$validator = Validator::make([
'name' => $this->_genreName,
'slug' => $slug
'slug' => $slug,
], $rules);
if ($validator->fails()) {
@ -67,7 +67,7 @@ class CreateGenreCommand extends CommandBase
Genre::create([
'name' => $this->_genreName,
'slug' => $slug
'slug' => $slug,
]);
return CommandResponse::succeed(['message' => 'Genre created!']);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Commands;
use Notification;
use App\Models\Playlist;
use Auth;
use Notification;
use Validator;
class CreatePlaylistCommand extends CommandBase
@ -53,7 +53,7 @@ class CreatePlaylistCommand extends CommandBase
$rules = [
'title' => 'required|min:3|max:50',
'is_public' => 'required',
'is_pinned' => 'required'
'is_pinned' => 'required',
];
$validator = Validator::make($this->_input, $rules);
@ -69,7 +69,7 @@ class CreatePlaylistCommand extends CommandBase
$playlist->is_public = $this->_input['is_public'] == 'true';
$playlist->save();
Notification::publishedNewPlaylist($playlist);
if ($this->_input['is_pinned'] == 'true') {
@ -84,7 +84,7 @@ class CreatePlaylistCommand extends CommandBase
'description' => $playlist->description,
'url' => $playlist->url,
'is_pinned' => $this->_input['is_pinned'] == 'true',
'is_public' => $this->_input['is_public'] == 'true'
'is_public' => $this->_input['is_public'] == 'true',
]);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Commands;
use App\Models\ShowSong;
use Gate;
use Illuminate\Support\Str;
use App\Models\ShowSong;
use Validator;
class CreateShowSongCommand extends CommandBase
@ -53,12 +53,12 @@ class CreateShowSongCommand extends CommandBase
$rules = [
'title' => 'required|unique:show_songs,title,NULL,id,deleted_at,NULL|max:250',
'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL'
'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL',
];
$validator = Validator::make([
'title' => $this->_songName,
'slug' => $slug
'slug' => $slug,
], $rules);
if ($validator->fails()) {
@ -68,7 +68,7 @@ class CreateShowSongCommand extends CommandBase
ShowSong::create([
'title' => $this->_songName,
'slug' => $slug,
'lyrics' => ''
'lyrics' => '',
]);
return CommandResponse::succeed(['message' => 'Song created!']);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,8 +20,8 @@
namespace App\Commands;
use Gate;
use App\Models\User;
use Gate;
use Validator;
class CreateUserCommand extends CommandBase
@ -30,7 +30,7 @@ class CreateUserCommand extends CommandBase
private $displayName;
private $email;
private $createArchivedUser;
public function __construct(
string $username,
string $displayName,
@ -72,7 +72,7 @@ class CreateUserCommand extends CommandBase
if ($validator->fails()) {
return CommandResponse::fail([
'message' => $validator->getMessageBag()->first(),
'user' => null
'user' => null,
]);
}
@ -81,12 +81,12 @@ class CreateUserCommand extends CommandBase
if ($user->wasRecentlyCreated) {
return CommandResponse::succeed([
'message' => 'New user successfully created!',
'user' => User::mapPublicUserSummary($user)
'user' => User::mapPublicUserSummary($user),
], 201);
} else {
return CommandResponse::fail([
'message' => 'A user with that username already exists.',
'user' => User::mapPublicUserSummary($user)
'user' => User::mapPublicUserSummary($user),
], 409);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Commands;
use Gate;
use App\Models\Album;
use Auth;
use Gate;
class DeleteAlbumCommand extends CommandBase
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,17 +20,16 @@
namespace App\Commands;
use App\Jobs\DeleteGenre;
use App\Models\Genre;
use Gate;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Models\Genre;
use App\Jobs\DeleteGenre;
use Validator;
class DeleteGenreCommand extends CommandBase
{
use DispatchesJobs;
/** @var Genre */
private $_genreToDelete;
private $_destinationGenre;
@ -67,7 +66,6 @@ class DeleteGenreCommand extends CommandBase
'destination_genre' => $this->_destinationGenre,
], $rules);
if ($validator->fails()) {
return CommandResponse::fail($validator);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,17 +20,16 @@
namespace App\Commands;
use App\Jobs\DeleteShowSong;
use App\Models\ShowSong;
use Gate;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Models\ShowSong;
use App\Jobs\DeleteShowSong;
use Validator;
class DeleteShowSongCommand extends CommandBase
{
use DispatchesJobs;
/** @var ShowSong */
private $_songToDelete;
private $_destinationSong;
@ -67,7 +66,6 @@ class DeleteShowSongCommand extends CommandBase
'destination_song' => $this->_destinationSong,
], $rules);
if ($validator->fails()) {
return CommandResponse::fail($validator);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,12 +20,12 @@
namespace App\Commands;
use Gate;
use App\Models\Track;
use Gate;
class DeleteTrackCommand extends CommandBase
{
/** @var int */
/** @var int */
private $_trackId;
/** @var Track */

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -24,8 +24,8 @@ use App\Models\Album;
use App\Models\Image;
use App\Models\User;
use Auth;
use Gate;
use DB;
use Gate;
use Validator;
class EditAlbumCommand extends CommandBase
@ -63,7 +63,7 @@ class EditAlbumCommand extends CommandBase
'title' => 'required|min:3|max:50',
'cover' => 'image|mimes:png|min_width:350|min_height:350',
'cover_id' => 'exists:images,id',
'username' => 'exists:users,username'
'username' => 'exists:users,username',
];
$validator = Validator::make($this->_input, $rules);
@ -77,7 +77,7 @@ class EditAlbumCommand extends CommandBase
$trackDbCount = DB::table('tracks')->whereIn('id', $trackIds)->count();
if ($trackDbCount != $trackIdsCount) {
return CommandResponse::fail("Track IDs invalid");
return CommandResponse::fail('Track IDs invalid');
}
$this->_album->title = $this->_input['title'];

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -57,7 +57,7 @@ class EditPlaylistCommand extends CommandBase
$rules = [
'title' => 'required|min:3|max:50',
'is_public' => 'required',
'is_pinned' => 'required'
'is_pinned' => 'required',
];
$validator = Validator::make($this->_input, $rules);
@ -76,7 +76,7 @@ class EditPlaylistCommand extends CommandBase
if ($pin && $this->_input['is_pinned'] != 'true') {
$pin->delete();
} else {
if (!$pin && $this->_input['is_pinned'] == 'true') {
if (! $pin && $this->_input['is_pinned'] == 'true') {
$this->_playlist->pin(Auth::user()->id);
}
}
@ -89,7 +89,7 @@ class EditPlaylistCommand extends CommandBase
'description' => $this->_playlist->description,
'url' => $this->_playlist->url,
'is_pinned' => $this->_input['is_pinned'] == 'true',
'is_public' => $this->_input['is_public'] == 'true'
'is_public' => $this->_input['is_public'] == 'true',
]);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,15 +20,15 @@
namespace App\Commands;
use Gate;
use Notification;
use App\Models\Album;
use App\Models\Image;
use App\Models\Playlist;
use App\Models\Track;
use App\Models\TrackType;
use App\Models\User;
use App\Models\Playlist;
use DB;
use Gate;
use Notification;
class EditTrackCommand extends CommandBase
{
@ -65,9 +65,9 @@ class EditTrackCommand extends CommandBase
$rules = [
'title' => 'required|min:3|max:80',
'released_at' => 'before:' .
(date('Y-m-d', time() + (86400 * 2))) . (
isset($this->_input['released_at']) && $this->_input['released_at'] != ""
'released_at' => 'before:'.
(date('Y-m-d', time() + (86400 * 2))).(
isset($this->_input['released_at']) && $this->_input['released_at'] != ''
? '|date'
: ''),
'license_id' => 'required|exists:licenses,id',
@ -76,7 +76,7 @@ class EditTrackCommand extends CommandBase
'track_type_id' => 'required|exists:track_types,id|not_in:'.TrackType::UNCLASSIFIED_TRACK,
'cover_id' => 'exists:images,id',
'album_id' => 'exists:albums,id',
'username' => 'exists:users,username'
'username' => 'exists:users,username',
];
if (isset($this->_input['track_type_id']) && $this->_input['track_type_id'] == TrackType::OFFICIAL_TRACK_REMIX) {
@ -92,7 +92,7 @@ class EditTrackCommand extends CommandBase
$track = $this->_track;
$track->title = $this->_input['title'];
$track->released_at = isset($this->_input['released_at']) && $this->_input['released_at'] != "" ? strtotime($this->_input['released_at']) : null;
$track->released_at = isset($this->_input['released_at']) && $this->_input['released_at'] != '' ? strtotime($this->_input['released_at']) : null;
$track->description = isset($this->_input['description']) ? $this->_input['description'] : '';
$track->lyrics = isset($this->_input['lyrics']) ? $this->_input['lyrics'] : '';
$track->license_id = $this->_input['license_id'];
@ -163,26 +163,26 @@ class EditTrackCommand extends CommandBase
$track->save();
User::whereId($this->_track->user_id)->update([
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $this->_track->user_id . ')')
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = '.$this->_track->user_id.')'),
]);
if ($oldid != null) {
User::whereId($oldid)->update([
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $oldid . ')')
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = '.$oldid.')'),
]);
}
if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime("2016-12-20 23:59:59")) {
if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime('2016-12-20 23:59:59')) {
$playlist = Playlist::where('user_id', 22549)->first();
if ($this->_input['hwc_submit'] == 'true') {
if (!$playlist->tracks()->get()->contains($track)) {
if (! $playlist->tracks()->get()->contains($track)) {
$songIndex = $playlist->trackCount() + 1;
$playlist->tracks()->attach($track, ['position' => $songIndex]);
$playlist->touch();
Playlist::where('id', $playlist->id)->update([
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')')
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')'),
]);
}
} else {
@ -190,11 +190,12 @@ class EditTrackCommand extends CommandBase
$playlist->tracks()->detach($track);
Playlist::whereId($playlist->id)->update([
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')')
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')'),
]);
}
}
}
return CommandResponse::succeed(['real_cover_url' => $track->getCoverUrl(Image::NORMAL)]);
}
@ -215,7 +216,7 @@ class EditTrackCommand extends CommandBase
}
Album::whereId($album->id)->update([
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count()
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count(),
]);
}
@ -230,7 +231,7 @@ class EditTrackCommand extends CommandBase
$track->save();
$album->update([
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count()
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count(),
]);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,23 +20,21 @@
namespace App\Commands;
use App\Exceptions\InvalidEncodeOptionsException;
use App\Jobs\EncodeTrackFile;
use App\Models\Track;
use App\Models\TrackFile;
use AudioCache;
use FFmpegMovie;
use File;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Str;
use App\Exceptions\InvalidEncodeOptionsException;
use App\Jobs\EncodeTrackFile;
use App\Models\Track;
use App\Models\TrackFile;
use SplFileInfo;
/**
* This command is the "second phase" of the upload process - once metadata has
* been parsed and the track object is created, this generates the track's
* corresponding TrackFile objects and ensures that all of them have been encoded.
*
* @package App\Commands
*/
class GenerateTrackFilesCommand extends CommandBase
{
@ -53,7 +51,7 @@ class GenerateTrackFilesCommand extends CommandBase
'flac',
'pcm',
'adpcm',
'alac'
'alac',
];
public function __construct(Track $track, SplFileInfo $sourceFile, bool $autoPublish = false, bool $isForUpload = false, bool $isReplacingTrack = false, int $version = 1)
@ -78,25 +76,26 @@ class GenerateTrackFilesCommand extends CommandBase
// Lossy uploads need to be identified and set as the master file
// without being re-encoded.
$audioObject = AudioCache::get($source);
$isLossyUpload = !$this->isLosslessFile($audioObject);
$isLossyUpload = ! $this->isLosslessFile($audioObject);
$codecString = $audioObject->getAudioCodec();
if ($isLossyUpload) {
if ($codecString === 'mp3') {
$masterFormat = 'MP3';
} else if (Str::startsWith($codecString, 'aac')) {
} elseif (Str::startsWith($codecString, 'aac')) {
$masterFormat = 'AAC';
} else if ($codecString === 'vorbis') {
} elseif ($codecString === 'vorbis') {
$masterFormat = 'OGG Vorbis';
} else {
$this->track->delete();
return CommandResponse::fail(['track' => "The track does not contain audio in a known lossy format. The format read from the file is: {$codecString}"]);
}
// Sanity check: skip creating this TrackFile if it already exists.
$trackFile = $this->trackFileExists($masterFormat);
if (!$trackFile) {
if (! $trackFile) {
$trackFile = new TrackFile();
$trackFile->is_master = true;
$trackFile->format = $masterFormat;
@ -109,7 +108,6 @@ class GenerateTrackFilesCommand extends CommandBase
File::copy($source, $trackFile->getFile());
}
$trackFiles = [];
foreach (Track::$Formats as $name => $format) {
@ -132,7 +130,7 @@ class GenerateTrackFilesCommand extends CommandBase
$trackFile->status = TrackFile::STATUS_PROCESSING_PENDING;
$trackFile->version = $this->version;
if (in_array($name, Track::$CacheableFormats) && !$trackFile->is_master) {
if (in_array($name, Track::$CacheableFormats) && ! $trackFile->is_master) {
$trackFile->is_cacheable = true;
} else {
$trackFile->is_cacheable = false;
@ -148,7 +146,7 @@ class GenerateTrackFilesCommand extends CommandBase
try {
foreach ($trackFiles as $trackFile) {
// Don't re-encode master files when replacing tracks with an already-uploaded version
if ($trackFile->is_master && !$this->isForUpload && $this->isReplacingTrack) {
if ($trackFile->is_master && ! $this->isForUpload && $this->isReplacingTrack) {
continue;
}
$this->dispatch(new EncodeTrackFile($trackFile, false, false, $this->isForUpload, $this->isReplacingTrack));
@ -161,6 +159,7 @@ class GenerateTrackFilesCommand extends CommandBase
} else {
$this->track->delete();
}
return CommandResponse::fail(['track' => [$e->getMessage()]]);
}
} catch (\Exception $e) {
@ -176,6 +175,7 @@ class GenerateTrackFilesCommand extends CommandBase
// This ensures that any updates to the track record, like from parsed
// tags, are reflected in the command's response.
$this->track = $this->track->fresh();
return CommandResponse::succeed([
'id' => $this->track->id,
'name' => $this->track->name,

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,8 +20,6 @@
namespace App\Commands;
use Carbon\Carbon;
use DB;
use App\Models\Album;
use App\Models\Comment;
use App\Models\EmailSubscription;
@ -35,6 +33,8 @@ use App\Models\ResourceLogItem;
use App\Models\ResourceUser;
use App\Models\Track;
use App\Models\User;
use Carbon\Carbon;
use DB;
class MergeAccountsCommand extends CommandBase
{
@ -117,7 +117,7 @@ class MergeAccountsCommand extends CommandBase
}
/** @var EmailSubscription $emailSubscription */
foreach($this->sourceAccount->emailSubscriptions()->withTrashed()->get() as $emailSubscription) {
foreach ($this->sourceAccount->emailSubscriptions()->withTrashed()->get() as $emailSubscription) {
// This keeps emails from being sent to disabled accounts.
$emailSubscription->delete();
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,18 +20,18 @@
namespace App\Commands;
use Carbon\Carbon;
use Config;
use getID3;
use App\Models\Album;
use App\Models\Genre;
use App\Models\Image;
use App\Models\Track;
use AudioCache;
use File;
use Illuminate\Support\Str;
use App\Models\TrackType;
use App\Models\User;
use AudioCache;
use Carbon\Carbon;
use Config;
use File;
use getID3;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@ -58,15 +58,14 @@ class ParseTrackTagsCommand extends CommandBase
list($parsedTags, $rawTags) = $this->parseOriginalTags($this->fileToParse, $this->track->user, $audio->getAudioCodec());
$this->track->original_tags = ['parsed_tags' => $parsedTags, 'raw_tags' => $rawTags];
if ($this->input['cover'] !== null) {
$this->track->cover_id = Image::upload($this->input['cover'], $this->track->user_id)->id;
} else {
$this->track->cover_id = $parsedTags['cover_id'];
}
$this->track->title = $this->input['title'] ?? $parsedTags['title'] ?? $this->track->title;
$this->track->track_type_id = $this->input['track_type_id'] ?? TrackType::UNCLASSIFIED_TRACK;
$this->track->title = $this->input['title'] ?? $parsedTags['title'] ?? $this->track->title;
$this->track->track_type_id = $this->input['track_type_id'] ?? TrackType::UNCLASSIFIED_TRACK;
$this->track->genre_id = isset($this->input['genre'])
? $this->getGenreId($this->input['genre'])
@ -89,26 +88,27 @@ class ParseTrackTagsCommand extends CommandBase
? Carbon::createFromFormat(Carbon::ISO8601, $this->input['released_at'])
: $parsedTags['release_date'];
$this->track->description = $this->input['description'] ?? $parsedTags['comments'];
$this->track->lyrics = $this->input['lyrics'] ?? $parsedTags['lyrics'];
$this->track->description = $this->input['description'] ?? $parsedTags['comments'];
$this->track->lyrics = $this->input['lyrics'] ?? $parsedTags['lyrics'];
$this->track->is_vocal = $this->input['is_vocal'] ?? $parsedTags['is_vocal'];
$this->track->is_explicit = $this->input['is_explicit'] ?? false;
$this->track->is_vocal = $this->input['is_vocal'] ?? $parsedTags['is_vocal'];
$this->track->is_explicit = $this->input['is_explicit'] ?? false;
$this->track->is_downloadable = $this->input['is_downloadable'] ?? true;
$this->track->is_listed = $this->input['is_listed'] ?? true;
$this->track->is_listed = $this->input['is_listed'] ?? true;
$this->track = $this->unsetNullVariables($this->track);
$this->track->save();
return CommandResponse::succeed();
}
/**
* If a value is null, remove it! Helps prevent weird SQL errors
* If a value is null, remove it! Helps prevent weird SQL errors.
*
* @param Track
* @return Track
*/
*/
private function unsetNullVariables($track)
{
$vars = $track->getAttributes();
@ -138,7 +138,7 @@ class ParseTrackTagsCommand extends CommandBase
return Genre::create([
'name' => $genreName,
'slug' => Str::slug($genreName)
'slug' => Str::slug($genreName),
])->id;
} else {
// Exists in db, has it been deleted?
@ -150,6 +150,7 @@ class ParseTrackTagsCommand extends CommandBase
// instead of creating a new one
$existingGenre->restore();
return $existingGenre->id;
} else {
// It's fine, just return the ID
@ -166,7 +167,7 @@ class ParseTrackTagsCommand extends CommandBase
*
* @param int $artistId
* @param string|null $albumName
* @param integer|null $coverId
* @param int|null $coverId
* @return int|null
*/
protected function getAlbumId(int $artistId, $albumName, $coverId = null)
@ -174,7 +175,7 @@ class ParseTrackTagsCommand extends CommandBase
if (null !== $albumName) {
$album = Album::firstOrNew([
'user_id' => $artistId,
'title' => $albumName
'title' => $albumName,
]);
if (null === $album->id) {
@ -249,7 +250,6 @@ class ParseTrackTagsCommand extends CommandBase
//==========================================================================================================
$parsedTags['is_vocal'] = $parsedTags['lyrics'] !== null;
//==========================================================================================================
// Determine the genre.
//==========================================================================================================
@ -294,7 +294,6 @@ class ParseTrackTagsCommand extends CommandBase
$parsedTags['cover_id'] = $coverId;
//==========================================================================================================
// Is this part of an album?
//==========================================================================================================
@ -307,11 +306,9 @@ class ParseTrackTagsCommand extends CommandBase
$parsedTags['album_id'] = $albumId;
return [$parsedTags, $rawTags];
}
/**
* @param array $rawTags
* @return array
@ -326,7 +323,6 @@ class ParseTrackTagsCommand extends CommandBase
$tags = [];
}
$comment = null;
if (isset($tags['comment'])) {
@ -361,7 +357,7 @@ class ParseTrackTagsCommand extends CommandBase
'comments' => $comment,
'lyrics' => isset($tags['unsynchronised_lyric']) ? $tags['unsynchronised_lyric'][0] : null,
],
$tags
$tags,
];
}
@ -405,7 +401,7 @@ class ParseTrackTagsCommand extends CommandBase
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
],
$tags
$tags,
];
}
@ -441,7 +437,7 @@ class ParseTrackTagsCommand extends CommandBase
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
],
$tags
$tags,
];
}
@ -474,7 +470,7 @@ class ParseTrackTagsCommand extends CommandBase
// YYYY-MM
case 7:
try {
return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString))
return Carbon::createFromFormat('Y m', str_replace('-', ' ', $dateString))
->day(1);
} catch (\InvalidArgumentException $e) {
return null;
@ -483,7 +479,7 @@ class ParseTrackTagsCommand extends CommandBase
// YYYY-MM-DD
case 10:
try {
return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString));
return Carbon::createFromFormat('Y m d', str_replace('-', ' ', $dateString));
} catch (\InvalidArgumentException $e) {
return null;
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -54,7 +54,7 @@ class RemoveTrackFromPlaylistCommand extends CommandBase
{
$this->_playlist->tracks()->detach($this->_track);
Playlist::whereId($this->_playlist->id)->update([
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')')
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')'),
]);
return CommandResponse::succeed(['message' => 'Track removed!']);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,11 +20,11 @@
namespace App\Commands;
use App\Jobs\UpdateTagsForRenamedGenre;
use App\Models\Genre;
use Gate;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Str;
use App\Jobs\UpdateTagsForRenamedGenre;
use App\Models\Genre;
use Validator;
class RenameGenreCommand extends CommandBase
@ -59,15 +59,14 @@ class RenameGenreCommand extends CommandBase
$rules = [
'name' => 'required|unique:genres,name,'.$this->_genre->id.',id,deleted_at,NULL|max:50',
'slug' => 'required|unique:genres,slug,'.$this->_genre->id.',id,deleted_at,NULL'
'slug' => 'required|unique:genres,slug,'.$this->_genre->id.',id,deleted_at,NULL',
];
$validator = Validator::make([
'name' => $this->_newName,
'slug' => $slug
'slug' => $slug,
], $rules);
if ($validator->fails()) {
return CommandResponse::fail($validator);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,11 +20,11 @@
namespace App\Commands;
use App\Jobs\UpdateTagsForRenamedShowSong;
use App\Models\ShowSong;
use Gate;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Str;
use App\Jobs\UpdateTagsForRenamedShowSong;
use App\Models\ShowSong;
use Validator;
class RenameShowSongCommand extends CommandBase
@ -59,15 +59,14 @@ class RenameShowSongCommand extends CommandBase
$rules = [
'title' => 'required|unique:show_songs,title,'.$this->_song->id.',id|max:250',
'slug' => 'required|unique:show_songs,slug,'.$this->_song->id.',id'
'slug' => 'required|unique:show_songs,slug,'.$this->_song->id.',id',
];
$validator = Validator::make([
'title' => $this->_newName,
'slug' => $slug
'slug' => $slug,
], $rules);
if ($validator->fails()) {
return CommandResponse::fail($validator);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Commands;
use DB;
use App\Models\Image;
use App\Models\User;
use DB;
use Gate;
use Validator;
@ -63,7 +63,7 @@ class SaveAccountSettingsCommand extends CommandBase
'unique:users,slug,'.$this->_user->id,
'min:'.config('ponyfm.user_slug_minimum_length'),
'regex:/^[a-z\d-]+$/',
'is_not_reserved_slug'
'is_not_reserved_slug',
],
'notifications.*.activity_type' => 'required|exists:activity_types,activity_type',
'notifications.*.receive_emails' => 'present|boolean',
@ -77,21 +77,20 @@ class SaveAccountSettingsCommand extends CommandBase
}
$validator = Validator::make($this->_input, $rules, [
'slug.regex' => 'Slugs can only contain numbers, lowercase letters, and dashes.'
'slug.regex' => 'Slugs can only contain numbers, lowercase letters, and dashes.',
]);
if ($validator->fails()) {
return CommandResponse::fail($validator);
}
$this->_user->bio = $this->_input['bio'];
$this->_user->display_name = $this->_input['display_name'];
$this->_user->slug = $this->_input['slug'];
$this->_user->can_see_explicit_content = $this->_input['can_see_explicit_content'] == 'true';
$this->_user->uses_gravatar = $this->_input['uses_gravatar'] == 'true';
if ($this->_user->uses_gravatar && !empty($this->_input['gravatar'])) {
if ($this->_user->uses_gravatar && ! empty($this->_input['gravatar'])) {
$this->_user->avatar_id = null;
$this->_user->gravatar = $this->_input['gravatar'];
} else {
@ -106,21 +105,19 @@ class SaveAccountSettingsCommand extends CommandBase
}
}
DB::transaction(function() {
DB::transaction(function () {
$this->_user->save();
// Sync email subscriptions
$emailSubscriptions = $this->_user->emailSubscriptions->keyBy('activity_type');
foreach ($this->_input['notifications'] as $notificationSetting) {
if (
$notificationSetting['receive_emails'] &&
!$emailSubscriptions->offsetExists($notificationSetting['activity_type'])
! $emailSubscriptions->offsetExists($notificationSetting['activity_type'])
) {
$this->_user->emailSubscriptions()->create(['activity_type' => $notificationSetting['activity_type']]);
} elseif (
!$notificationSetting['receive_emails'] &&
! $notificationSetting['receive_emails'] &&
$emailSubscriptions->offsetExists($notificationSetting['activity_type'])
) {
$emailSubscriptions->get($notificationSetting['activity_type'])->delete();

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,15 +20,15 @@
namespace App\Commands;
use Notification;
use App\Contracts\Favouritable;
use App\Models\Favourite;
use App\Models\Track;
use App\Models\Album;
use App\Models\Favourite;
use App\Models\Playlist;
use App\Models\ResourceUser;
use App\Models\Track;
use Auth;
use DB;
use Notification;
class ToggleFavouriteCommand extends CommandBase
{
@ -98,14 +98,13 @@ class ToggleFavouriteCommand extends CommandBase
// for the same resource at the same time, the cached values will still be correct with this method.
DB::table($resourceTable)->whereId($this->_resourceId)->update([
'favourite_count' =>
DB::raw('(
'favourite_count' => DB::raw('(
SELECT
COUNT(id)
FROM
favourites
WHERE ' .
$typeId.' = '.$this->_resourceId.')')
WHERE '.
$typeId.' = '.$this->_resourceId.')'),
]);
return CommandResponse::succeed(['is_favourited' => $isFavourited]);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -52,7 +52,7 @@ class ToggleFollowingCommand extends CommandBase
*/
public function execute()
{
$typeId = $this->_resourceType . '_id';
$typeId = $this->_resourceType.'_id';
$existing = Follower::where($typeId, '=', $this->_resourceId)->whereUserId(Auth::user()->id)->first();
$isFollowed = false;

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,14 +20,14 @@
namespace App\Commands;
use App\Models\Track;
use App\Models\User;
use Auth;
use Carbon\Carbon;
use Config;
use Gate;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Request;
use App\Models\Track;
use App\Models\User;
use Validator;
class UploadTrackCommand extends CommandBase
@ -106,7 +106,7 @@ class UploadTrackCommand extends CommandBase
$trackFile = Request::file('track', null);
}
if (!$this->_isReplacingTrack) {
if (! $this->_isReplacingTrack) {
$coverFile = Request::file('cover', null);
}
@ -115,12 +115,13 @@ class UploadTrackCommand extends CommandBase
$this->_track->version_upload_status = Track::STATUS_ERROR;
$this->_track->update();
}
return CommandResponse::fail(['track' => ['You must upload an audio file!']]);
}
$audio = \AudioCache::get($trackFile->getPathname());
if (!$this->_isReplacingTrack) {
if (! $this->_isReplacingTrack) {
$this->_track = new Track();
$this->_track->user_id = $this->_artist->id;
// The title set here is a placeholder; it'll be replaced by ParseTrackTagsCommand
@ -133,34 +134,33 @@ class UploadTrackCommand extends CommandBase
}
$this->_track->ensureDirectoryExists();
if (!is_dir(Config::get('ponyfm.files_directory').'/tmp')) {
if (! is_dir(Config::get('ponyfm.files_directory').'/tmp')) {
mkdir(Config::get('ponyfm.files_directory').'/tmp', 0755, true);
}
if (!is_dir(Config::get('ponyfm.files_directory').'/queued-tracks')) {
if (! is_dir(Config::get('ponyfm.files_directory').'/queued-tracks')) {
mkdir(Config::get('ponyfm.files_directory').'/queued-tracks', 0755, true);
}
$trackFile = $trackFile->move(Config::get('ponyfm.files_directory') . '/queued-tracks', $this->_track->id . 'v' . $this->_version);
$trackFile = $trackFile->move(Config::get('ponyfm.files_directory').'/queued-tracks', $this->_track->id.'v'.$this->_version);
$input = Request::all();
$input['track'] = $trackFile;
// Prevent the setting of the cover index for validation
if (!$this->_isReplacingTrack && isset($coverFile)) {
if (! $this->_isReplacingTrack && isset($coverFile)) {
$input['cover'] = $coverFile;
}
$rules = [
'track' =>
'required|'
. ($this->_allowLossy
'track' => 'required|'
.($this->_allowLossy
? 'audio_format:flac,alac,pcm,adpcm,aac,mp3,vorbis|'
: 'audio_format:flac,alac,pcm,adpcm|')
. ($this->_allowShortTrack ? '' : 'min_duration:30|')
. 'audio_channels:1,2',
.($this->_allowShortTrack ? '' : 'min_duration:30|')
.'audio_channels:1,2',
];
if (!$this->_isReplacingTrack) {
if (! $this->_isReplacingTrack) {
array_merge($rules, [
'cover' => 'image|mimes:png,jpeg|min_width:350|min_height:350',
'auto_publish' => 'boolean',
@ -176,7 +176,7 @@ class UploadTrackCommand extends CommandBase
'is_explicit' => 'boolean',
'is_downloadable' => 'boolean',
'is_listed' => 'boolean',
'metadata' => 'json'
'metadata' => 'json',
]);
}
$validator = \Validator::make($input, $rules);
@ -188,15 +188,16 @@ class UploadTrackCommand extends CommandBase
} else {
$this->_track->delete();
}
return CommandResponse::fail($validator);
}
if (!$this->_isReplacingTrack) {
if (! $this->_isReplacingTrack) {
// If json_decode() isn't called here, Laravel will surround the JSON
// string with quotes when storing it in the database, which breaks things.
$this->_track->metadata = json_decode(Request::get('metadata', null));
}
$autoPublish = (bool)($input['auto_publish'] ?? $this->_autoPublishByDefault);
$autoPublish = (bool) ($input['auto_publish'] ?? $this->_autoPublishByDefault);
$this->_track->source = $this->_customTrackSource ?? $source;
$this->_track->save();
@ -206,7 +207,7 @@ class UploadTrackCommand extends CommandBase
$input['cover'] = null;
}
if (!$this->_isReplacingTrack) {
if (! $this->_isReplacingTrack) {
// Parse any tags in the uploaded files.
$parseTagsCommand = new ParseTrackTagsCommand($this->_track, $trackFile, $input);
$result = $parseTagsCommand->execute();
@ -215,11 +216,13 @@ class UploadTrackCommand extends CommandBase
$this->_track->version_upload_status = Track::STATUS_ERROR;
$this->_track->update();
}
return $result;
}
}
$generateTrackFiles = new GenerateTrackFilesCommand($this->_track, $trackFile, $autoPublish, true, $this->_isReplacingTrack, $this->_version);
return $generateTrackFiles->execute();
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -40,7 +40,6 @@ class BootstrapLocalEnvironment extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -53,7 +53,6 @@ class ClassifyMLPMA extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -74,7 +73,7 @@ class ClassifyMLPMA extends Command
$this->comment('Importing tracks...');
$totalTracks = sizeof($tracks);
$totalTracks = count($tracks);
$fileToStartAt = (int) $this->option('startAt') - 1;
$this->comment("Skipping $fileToStartAt files...".PHP_EOL);
@ -88,7 +87,6 @@ class ClassifyMLPMA extends Command
$parsedTags = json_decode($track->parsed_tags, true);
//==========================================================================================================
// Original, show song remix, fan song remix, show audio remix, or ponified song?
//==========================================================================================================
@ -103,7 +101,6 @@ class ClassifyMLPMA extends Command
")
->get();
// If it has "Ingram" in the name, it's definitely an official song remix.
if (Str::contains(Str::lower($track->filename), 'ingram')) {
$this->info('This is an official song remix!');
@ -115,8 +112,7 @@ class ClassifyMLPMA extends Command
$parsedTags
);
// If it has "remix" in the name, it's definitely a remix.
// If it has "remix" in the name, it's definitely a remix.
} else {
if (Str::contains(Str::lower($sanitizedTrackTitle), 'remix')) {
$this->info('This is some kind of remix!');
@ -128,7 +124,7 @@ class ClassifyMLPMA extends Command
$parsedTags
);
// No idea what this is. Have the pony at the terminal figure it out!
// No idea what this is. Have the pony at the terminal figure it out!
} else {
list($trackType, $linkedSongIds) = $this->classifyTrack(
$track->filename,
@ -139,7 +135,6 @@ class ClassifyMLPMA extends Command
}
}
//==========================================================================================================
// Attach the data and publish the track!
//==========================================================================================================
@ -150,7 +145,7 @@ class ClassifyMLPMA extends Command
$track->published_at = $parsedTags['released_at'];
$track->save();
if (sizeof($linkedSongIds) > 0) {
if (count($linkedSongIds) > 0) {
$track->showSongs()->sync($linkedSongIds);
}
@ -167,24 +162,22 @@ class ClassifyMLPMA extends Command
* @param bool|false $isRemixOfOfficialTrack
* @return array
*/
protected function classifyTrack($filename, $officialSongs, $isRemixOfOfficialTrack = false, $tags)
protected function classifyTrack($filename, $officialSongs, $isRemixOfOfficialTrack, $tags)
{
$trackTypeId = null;
$linkedSongIds = [];
foreach ($officialSongs as $song) {
$this->comment('=> Matched official song: ['.$song->id.'] '.$song->title);
}
if ($isRemixOfOfficialTrack && sizeof($officialSongs) === 1) {
if ($isRemixOfOfficialTrack && count($officialSongs) === 1) {
$linkedSongIds = [$officialSongs[0]->id];
} else {
if ($isRemixOfOfficialTrack && sizeof($officialSongs) > 1) {
if ($isRemixOfOfficialTrack && count($officialSongs) > 1) {
$this->question('Multiple official songs matched! Please enter the ID of the correct one.');
} else {
if (sizeof($officialSongs) > 0) {
if (count($officialSongs) > 0) {
$this->question('This looks like a remix of an official song!');
$this->question('Press "r" if the match above is right!');
} else {

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Kelvin Zhang
* Copyright (C) 2015 Kelvin Zhang.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,10 @@
namespace App\Console\Commands;
use App\Models\TrackFile;
use Carbon\Carbon;
use File;
use Illuminate\Console\Command;
use App\Models\TrackFile;
class ClearTrackCache extends Command
{
@ -45,7 +45,6 @@ class ClearTrackCache extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -76,7 +75,7 @@ class ClearTrackCache extends Command
if (count($trackFiles) === 0) {
$this->info('No tracks found. Exiting.');
} else {
if ($this->option('force') || $this->confirm(count($trackFiles) . ' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) {
if ($this->option('force') || $this->confirm(count($trackFiles).' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) {
$count = 0;
foreach ($trackFiles as $trackFile) {
@ -89,10 +88,10 @@ class ClearTrackCache extends Command
$count++;
File::delete($trackFile->getFile());
$this->info('Deleted ' . $trackFile->getFile());
$this->info('Deleted '.$trackFile->getFile());
}
}
$this->info($count . ' files deleted. Deletion complete. Exiting.');
$this->info($count.' files deleted. Deletion complete. Exiting.');
} else {
$this->info('Deletion cancelled. Exiting.');
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,12 +20,12 @@
namespace App\Console\Commands;
use App\Models\Image;
use Config;
use DB;
use File;
use getID3;
use Illuminate\Console\Command;
use App\Models\Image;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class FixMLPMAImages extends Command
@ -47,7 +47,6 @@ class FixMLPMAImages extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -56,7 +55,6 @@ class FixMLPMAImages extends Command
protected $currentFile;
/**
* File extensions to ignore when importing the archive.
*
@ -69,7 +67,7 @@ class FixMLPMAImages extends Command
'txt',
'rtf',
'wma',
'wmv'
'wmv',
];
/**
@ -84,17 +82,16 @@ class FixMLPMAImages extends Command
$this->comment('Enumerating MLP Music Archive source files...');
$files = File::allFiles($mlpmaPath);
$this->info(sizeof($files).' files found!');
$this->info(count($files).' files found!');
$this->comment('Importing tracks...');
$totalFiles = sizeof($files);
$totalFiles = count($files);
$fileToStartAt = (int) $this->option('startAt') - 1;
$this->comment("Skipping $fileToStartAt files...".PHP_EOL);
$files = array_slice($files, $fileToStartAt);
$this->currentFile = $fileToStartAt;
foreach ($files as $file) {
$this->currentFile++;
@ -110,7 +107,6 @@ class FixMLPMAImages extends Command
->first();
$artistId = $importedTrack->user_id;
//==========================================================================================================
// Extract the original tags.
//==========================================================================================================
@ -119,7 +115,6 @@ class FixMLPMAImages extends Command
// all tags read by getID3, including the cover art
$allTags = $getId3->analyze($file->getPathname());
//==========================================================================================================
// Extract the cover art, if any exists.
//==========================================================================================================

View file

@ -2,21 +2,21 @@
namespace App\Console\Commands;
use App\Commands\UploadTrackCommand;
use App\Models\Album;
use App\Models\Genre;
use App\Models\Image;
use App\Models\Track;
use App\Models\User;
use Auth;
use Carbon\Carbon;
use Config;
use DB;
use File;
use Input;
use getID3;
use App\Models\Image;
use App\Models\Track;
use App\Models\User;
use App\Models\Genre;
use App\Models\Album;
use App\Commands\UploadTrackCommand;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Input;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class ImportEQBeats extends Command
@ -69,7 +69,7 @@ class ImportEQBeats extends Command
public function handleInterrupt($signo)
{
$this->error('Import aborted!');
$this->error('Resume it from here using: --startAt=' . $this->currentFile);
$this->error('Resume it from here using: --startAt='.$this->currentFile);
$this->isInterrupted = true;
}
@ -88,13 +88,13 @@ class ImportEQBeats extends Command
$archivePath = $this->argument('archiveFolder');
$tmpPath = Config::get('ponyfm.files_directory').'/tmp';
if (!File::exists($tmpPath)) {
if (! File::exists($tmpPath)) {
File::makeDirectory($tmpPath);
}
$UNKNOWN_GENRE = Genre::firstOrCreate([
'name' => 'Unknown',
'slug' => 'unknown'
'slug' => 'unknown',
]);
//==========================================================================================================
@ -102,18 +102,18 @@ class ImportEQBeats extends Command
//==========================================================================================================
$this->comment('Enumerating files...');
$files = File::allFiles($archivePath);
$this->info(sizeof($files) . ' files found!');
$this->info(count($files).' files found!');
$this->comment('Enumerating artists...');
$artists = File::directories($archivePath);
$this->info(sizeof($artists) . ' artists found!');
$this->info(count($artists).' artists found!');
$this->comment('Importing tracks...');
$totalFiles = sizeof($files);
$totalFiles = count($files);
$fileToStartAt = (int)$this->option('startAt') - 1;
$this->comment("Skipping $fileToStartAt files..." . PHP_EOL);
$fileToStartAt = (int) $this->option('startAt') - 1;
$this->comment("Skipping $fileToStartAt files...".PHP_EOL);
$files = array_slice($files, $fileToStartAt);
$this->currentFile = $fileToStartAt;
@ -127,20 +127,20 @@ class ImportEQBeats extends Command
break;
}
$this->comment('[' . $this->currentFile . '/' . $totalFiles . '] Importing track [' . $file->getFilename() . ']...');
$this->comment('['.$this->currentFile.'/'.$totalFiles.'] Importing track ['.$file->getFilename().']...');
if (!in_array($file->getExtension(), $this->allowedExtensions)) {
$this->comment('This is not an audio file! Skipping...' . PHP_EOL);
if (! in_array($file->getExtension(), $this->allowedExtensions)) {
$this->comment('This is not an audio file! Skipping...'.PHP_EOL);
continue;
}
$this->info('Path to file: ' . $file->getRelativePath());
$this->info('Path to file: '.$file->getRelativePath());
$path_components = explode(DIRECTORY_SEPARATOR, $file->getRelativePath());
$artist_name = $path_components[0];
$album_name = array_key_exists(1, $path_components) ? $path_components[1] : null;
$this->info('Artist: ' . $artist_name);
$this->info('Album: ' . $album_name);
$this->info('Artist: '.$artist_name);
$this->info('Album: '.$album_name);
//==========================================================================================================
// Analyse the track so we can find the MIME type and album art
@ -170,7 +170,7 @@ class ImportEQBeats extends Command
$parsedTags['title'] = substr($fileName, strpos($fileName, $hyphen) + strlen($hyphen));
}
$this->info('Title: ' . $parsedTags['title']);
$this->info('Title: '.$parsedTags['title']);
//==========================================================================================================
// Determine the release date.
@ -183,11 +183,9 @@ class ImportEQBeats extends Command
if ($taggedYear !== null && $modifiedDate->year === $taggedYear) {
$releasedAt = $modifiedDate;
} else if ($taggedYear !== null && $modifiedDate->year !== $taggedYear) {
} elseif ($taggedYear !== null && $modifiedDate->year !== $taggedYear) {
$this->warn('Release years don\'t match! Using the tagged year...');
$releasedAt = Carbon::create($taggedYear);
} else {
// $taggedYear is null
$this->warn('This track isn\'t tagged with its release year! Using the track\'s last modified date...');
@ -215,7 +213,6 @@ class ImportEQBeats extends Command
$genre->restore();
}
$genreId = $genre->id;
} else {
$genre = new Genre();
$genre->name = $genreName;
@ -224,10 +221,9 @@ class ImportEQBeats extends Command
$genreId = $genre->id;
$this->comment('Created a new genre!');
}
} else {
$genreId = $UNKNOWN_GENRE->id; // "Unknown" genre ID
}
}
//==========================================================================================================
// Check to see if we have this track already, if so, compare hashes of the two files
@ -236,7 +232,7 @@ class ImportEQBeats extends Command
$artist = User::where('display_name', '=', $artist_name)->first();
$artistId = null;
$this->comment("Checking for duplicates");
$this->comment('Checking for duplicates');
if ($artist) {
$artistId = $artist->id;
@ -254,7 +250,7 @@ class ImportEQBeats extends Command
$importFormat = $this->getFormat($file->getExtension());
if ($importFormat == null) {
// No idea what this is, skip file
$this->comment(sprintf("Not an audio file (%s), skipping...", $importFormat));
$this->comment(sprintf('Not an audio file (%s), skipping...', $importFormat));
continue;
}
@ -273,7 +269,7 @@ class ImportEQBeats extends Command
// Source is lossless, is the existing track lossy?
if ($existingFile->isMasterLossy()) {
// Cool! Let's replace it
$this->comment('Replacing (' . $existingTrack->id . ') ' . $existingTrack->title);
$this->comment('Replacing ('.$existingTrack->id.') '.$existingTrack->title);
$this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']);
@ -282,16 +278,15 @@ class ImportEQBeats extends Command
}
continue;
} else {
$this->comment("Found existing file");
$this->comment('Found existing file');
// Found a matching format, are they the same?
// Before we check it, see if it came from MLPMA
// We're only replacing tracks with the same format if they're archived
$mlpmaTrack = DB::table('mlpma_tracks')->where('track_id', '=', $existingTrack->id)->first();
if (!is_null($mlpmaTrack)) {
if (! is_null($mlpmaTrack)) {
$getId3_source = new getID3;
$getId3_source->option_md5_data = true;
@ -307,8 +302,8 @@ class ImportEQBeats extends Command
$importHash = array_key_exists('md5_data_source', $sourceWithMd5) ? $sourceWithMd5['md5_data_source'] : $sourceWithMd5['md5_data'];
$targetHash = array_key_exists('md5_data_source', $existingFileTags) ? $existingFileTags['md5_data_source'] : $existingFileTags['md5_data'];
$this->info("Archive hash: " . $importHash);
$this->info("Pony.fm hash: " . $targetHash);
$this->info('Archive hash: '.$importHash);
$this->info('Pony.fm hash: '.$targetHash);
if ($importHash == $targetHash) {
// Audio is identical, no need to reupload
@ -319,28 +314,30 @@ class ImportEQBeats extends Command
if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) {
$existingTrack->description = $parsedTags['comments'];
$changedMetadata = true;
$this->comment("Updated description");
$this->comment('Updated description');
}
if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) {
$existingTrack->lyrics = $parsedTags['lyrics'];
$changedMetadata = true;
$this->comment("Updated lyrics");
$this->comment('Updated lyrics');
}
if ($changedMetadata) $existingTrack->save();
if ($changedMetadata) {
$existingTrack->save();
}
continue;
} else {
// Audio is different, let's replace it
$this->comment('Replacing (' . $existingTrack->id . ') ' . $existingTrack->title);
$this->comment('Replacing ('.$existingTrack->id.') '.$existingTrack->title);
$this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']);
continue;
}
} else {
$this->comment("Not replacing, user uploaded");
$this->comment('Not replacing, user uploaded');
// We can update the metadata though
$changedMetadata = false;
@ -348,28 +345,30 @@ class ImportEQBeats extends Command
if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) {
$existingTrack->description = $parsedTags['comments'];
$changedMetadata = true;
$this->comment("Updated description");
$this->comment('Updated description');
}
if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) {
$existingTrack->lyrics = $parsedTags['lyrics'];
$changedMetadata = true;
$this->comment("Updated lyrics");
$this->comment('Updated lyrics');
}
if ($changedMetadata) $existingTrack->save();
if ($changedMetadata) {
$existingTrack->save();
}
continue;
}
}
} else {
$this->comment("No duplicates");
$this->comment('No duplicates');
}
//==========================================================================================================
// Create new user for the artist if one doesn't exist
//==========================================================================================================
if (!$artist) {
if (! $artist) {
$artist = new User;
$artist->display_name = $artist_name;
$artist->email = null;
@ -379,8 +378,8 @@ class ImportEQBeats extends Command
$slugExists = User::where('slug', '=', $artist->slug)->first();
if ($slugExists) {
$this->error('Horsefeathers! The slug ' . $artist->slug . ' is already taken!');
$artist->slug = $artist->slug . '-' . Str::random(4);
$this->error('Horsefeathers! The slug '.$artist->slug.' is already taken!');
$artist->slug = $artist->slug.'-'.Str::random(4);
}
$artist->save();
@ -396,7 +395,7 @@ class ImportEQBeats extends Command
if (array_key_exists('comments', $allTags) && array_key_exists('picture', $allTags['comments'])) {
$image = $allTags['comments']['picture'][0];
} else if (array_key_exists('id3v2', $allTags) && array_key_exists('APIC', $allTags['id3v2'])) {
} elseif (array_key_exists('id3v2', $allTags) && array_key_exists('APIC', $allTags['id3v2'])) {
$image = $allTags['id3v2']['APIC'][0];
}
@ -415,8 +414,8 @@ class ImportEQBeats extends Command
}
}
// write temporary image file
$imageFilename = $file->getFilename() . ".cover.$extension";
$imageFilePath = "$tmpPath/" . $imageFilename;
$imageFilename = $file->getFilename().".cover.$extension";
$imageFilePath = "$tmpPath/".$imageFilename;
File::put($imageFilePath, $image['data']);
$imageFile = new UploadedFile($imageFilePath, $imageFilename, $image['image_mime'], null, null, true);
@ -437,13 +436,13 @@ class ImportEQBeats extends Command
->where('title', '=', $albumName)
->first();
if (!$album) {
if (! $album) {
$album = new Album;
$album->title = $albumName;
$album->user_id = $artist->id;
$album->cover_id = $coverId;
$album->description = "";
$album->description = '';
$album->save();
}
@ -460,8 +459,8 @@ class ImportEQBeats extends Command
$mime = $allTags['mime_type'];
File::copy($file->getPathname(), "$tmpPath/" . $file->getFilename());
$trackFile = new UploadedFile("$tmpPath/" . $file->getFilename(), $file->getFilename(), $mime, null, null, true);
File::copy($file->getPathname(), "$tmpPath/".$file->getFilename());
$trackFile = new UploadedFile("$tmpPath/".$file->getFilename(), $file->getFilename(), $mime, null, null, true);
$upload = new UploadTrackCommand(true);
$upload->_file = $trackFile;
@ -479,18 +478,18 @@ class ImportEQBeats extends Command
$track->is_downloadable = true;
$track->is_vocal = $isVocal;
$track->license_id = 2;
$track->description = "";
$track->lyrics = "";
$track->description = '';
$track->lyrics = '';
if (!is_null($parsedTags['comments'])) {
if (! is_null($parsedTags['comments'])) {
$track->description = $parsedTags['comments'];
}
if (!is_null($parsedTags['lyrics'])) {
if (! is_null($parsedTags['lyrics'])) {
$track->lyrics = $parsedTags['lyrics'];
}
if (!is_null($parsedTags['title'])) {
if (! is_null($parsedTags['title'])) {
$track->title = $parsedTags['title'];
}
@ -501,7 +500,7 @@ class ImportEQBeats extends Command
->insert([
'track_id' => $result->getResponse()['id'],
'path' => $file->getRelativePath(),
'filename' => iconv("UTF-8", "ISO-8859-1//TRANSLIT", $file->getFilename()),
'filename' => iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $file->getFilename()),
'extension' => $file->getExtension(),
'imported_at' => Carbon::now(),
'parsed_tags' => json_encode($parsedTags),
@ -509,18 +508,21 @@ class ImportEQBeats extends Command
]);
}
echo PHP_EOL . PHP_EOL;
echo PHP_EOL.PHP_EOL;
}
}
protected function hashAudio($filepath) {
protected function hashAudio($filepath)
{
$hash = hash_file('crc32b', $filepath);
$array = unpack('N', pack('H*', $hash));
return $array[1];
}
protected function getFormat($extension) {
foreach(Track::$Formats as $name => $format) {
protected function getFormat($extension)
{
foreach (Track::$Formats as $name => $format) {
if ($format['extension'] == $extension) {
return $name;
}
@ -565,7 +567,6 @@ class ImportEQBeats extends Command
$rawTags = [];
}
return [$parsedTags, $rawTags];
}
@ -623,7 +624,7 @@ class ImportEQBeats extends Command
'comments' => $comment,
'lyrics' => isset($tags['unsynchronised_lyric']) ? $tags['unsynchronised_lyric'][0] : null,
],
$tags
$tags,
];
}
@ -667,7 +668,7 @@ class ImportEQBeats extends Command
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
],
$tags
$tags,
];
}
@ -703,7 +704,7 @@ class ImportEQBeats extends Command
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
],
$tags
$tags,
];
}
@ -736,7 +737,7 @@ class ImportEQBeats extends Command
// YYYY-MM
case 7:
try {
return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString))
return Carbon::createFromFormat('Y m', str_replace('-', ' ', $dateString))
->day(1);
} catch (\InvalidArgumentException $e) {
return null;
@ -745,7 +746,7 @@ class ImportEQBeats extends Command
// YYYY-MM-DD
case 10:
try {
return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString));
return Carbon::createFromFormat('Y m d', str_replace('-', ' ', $dateString));
} catch (\InvalidArgumentException $e) {
return null;
}
@ -762,7 +763,8 @@ class ImportEQBeats extends Command
}
}
protected function replaceTrack($toBeUploaded, $targetTrack, $artist, $mime) {
protected function replaceTrack($toBeUploaded, $targetTrack, $artist, $mime)
{
Auth::loginUsingId($artist->id);
$trackFile = new UploadedFile($toBeUploaded->getPathname(), $toBeUploaded->getFilename(), $mime, null, null, true);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,6 @@
namespace App\Console\Commands;
use Carbon\Carbon;
use DB;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use App\Commands\MergeAccountsCommand;
use App\Models\Album;
use App\Models\Comment;
@ -36,6 +32,10 @@ use App\Models\ResourceLogItem;
use App\Models\ResourceUser;
use App\Models\Track;
use App\Models\User;
use Carbon\Carbon;
use DB;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
class MergeAccounts extends Command
{
@ -57,7 +57,6 @@ class MergeAccounts extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -81,9 +80,10 @@ class MergeAccounts extends Command
if (null !== $sourceAccount->getAccessToken()) {
$this->warn("WARNING: The source account (ID {$sourceAccountId}) is linked to a Poniverse account! Normally, the destination account should be the one that's linked to a Poniverse account as that's the one that the artist will be logging into.");
$this->line('');
$this->warn("If you continue with this merge, the Poniverse account linked to the source Pony.fm account will no longer be able to log into Pony.fm.");
if (!$this->confirm('Continue merging this set of source and destination accounts?')){
$this->warn('If you continue with this merge, the Poniverse account linked to the source Pony.fm account will no longer be able to log into Pony.fm.');
if (! $this->confirm('Continue merging this set of source and destination accounts?')) {
$this->error('Merge aborted.');
return 1;
}
}
@ -91,8 +91,9 @@ class MergeAccounts extends Command
if (null === $destinationAccount->getAccessToken()) {
$this->warn("WARNING: The destination account (ID {$destinationAccountId}) is not linked to a Poniverse account!");
$this->warn("This is normal if you're merging two archived profiles but not if you're helping an artist claim their profile.");
if (!$this->confirm('Continue merging this set of source and destination accounts?')){
if (! $this->confirm('Continue merging this set of source and destination accounts?')) {
$this->error('Merge aborted.');
return 1;
}
}
@ -101,6 +102,7 @@ class MergeAccounts extends Command
$command = new MergeAccountsCommand($sourceAccount, $destinationAccount);
$command->execute();
return 0;
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -45,7 +45,6 @@ class MigrateOldData extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -69,15 +68,15 @@ class MigrateOldData extends Command
$this->info('Syncing Users');
foreach ($oldUsers as $user) {
$displayName = $user->display_name;
if (!$displayName) {
if (! $displayName) {
$displayName = $user->username;
}
if (!$displayName) {
if (! $displayName) {
$displayName = $user->username;
}
if (!$displayName) {
if (! $displayName) {
continue;
}
@ -94,11 +93,11 @@ class MigrateOldData extends Command
'username' => $user->username,
'uses_gravatar' => $user->uses_gravatar,
'gravatar' => $user->gravatar,
'avatar_id' => null
'avatar_id' => null,
]);
$coverId = null;
if (!$user->uses_gravatar) {
if (! $user->uses_gravatar) {
try {
$coverFile = $this->getIdDirectory('users', $user->id).'/'.$user->id.'_.png';
$coverId = Image::upload(new UploadedFile(
@ -119,7 +118,7 @@ class MigrateOldData extends Command
DB::table('genres')->insert([
'id' => $genre->id,
'name' => $genre->title,
'slug' => $genre->slug
'slug' => $genre->slug,
]);
}
@ -139,7 +138,7 @@ class MigrateOldData extends Command
'id' => $playlist->id,
'user_id' => $playlist->user_id,
'view_count' => 0,
'download_count' => 0
'download_count' => 0,
]);
foreach ($logViews as $logItem) {
@ -164,7 +163,7 @@ class MigrateOldData extends Command
'album_id' => $logItem->album_id,
'created_at' => $logItem->created_at,
'ip_address' => $logItem->ip_address,
'track_format_id' => $logItem->track_file_format_id - 1
'track_format_id' => $logItem->track_file_format_id - 1,
]);
} catch (\Exception $e) {
$this->error('Could insert log item for album '.$playlist->id.' because '.$e->getMessage());
@ -219,7 +218,7 @@ class MigrateOldData extends Command
'duration' => $track->duration,
'view_count' => 0,
'play_count' => 0,
'download_count' => 0
'download_count' => 0,
]);
foreach ($trackLogViews as $logItem) {
@ -229,7 +228,7 @@ class MigrateOldData extends Command
'log_type' => ResourceLogItem::VIEW,
'track_id' => $logItem->track_id,
'created_at' => $logItem->created_at,
'ip_address' => $logItem->ip_address
'ip_address' => $logItem->ip_address,
]);
} catch (\Exception $e) {
$this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage());
@ -243,7 +242,7 @@ class MigrateOldData extends Command
'log_type' => ResourceLogItem::PLAY,
'track_id' => $logItem->track_id,
'created_at' => $logItem->created_at,
'ip_address' => $logItem->ip_address
'ip_address' => $logItem->ip_address,
]);
} catch (\Exception $e) {
$this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage());
@ -258,7 +257,7 @@ class MigrateOldData extends Command
'track_id' => $logItem->track_id,
'created_at' => $logItem->created_at,
'ip_address' => $logItem->ip_address,
'track_format_id' => $logItem->track_file_format_id - 1
'track_format_id' => $logItem->track_file_format_id - 1,
]);
} catch (\Exception $e) {
$this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage());
@ -272,7 +271,7 @@ class MigrateOldData extends Command
DB::table('show_song_track')->insert([
'id' => $song->id,
'show_song_id' => $song->song_id,
'track_id' => $song->track_id
'track_id' => $song->track_id,
]);
} catch (\Exception $e) {
$this->error('Could insert show track item for '.$song->track_id.' because '.$e->getMessage());
@ -321,7 +320,7 @@ class MigrateOldData extends Command
'playlist_id' => $logItem->playlist_id,
'created_at' => $logItem->created_at,
'ip_address' => $logItem->ip_address,
'track_format_id' => $logItem->track_file_format_id - 1
'track_format_id' => $logItem->track_file_format_id - 1,
]);
} catch (\Exception $e) {
$this->error('Could insert log item for playlist '.$playlist->id.' because '.$e->getMessage());
@ -338,7 +337,7 @@ class MigrateOldData extends Command
'updated_at' => $playlistTrack->updated_at,
'position' => $playlistTrack->position,
'playlist_id' => $playlistTrack->playlist_id,
'track_id' => $playlistTrack->track_id
'track_id' => $playlistTrack->track_id,
]);
}
@ -356,7 +355,7 @@ class MigrateOldData extends Command
'track_id' => $comment->track_id,
'album_id' => $comment->album_id,
'playlist_id' => $comment->playlist_id,
'profile_id' => $comment->profile_id
'profile_id' => $comment->profile_id,
]);
} catch (Exception $e) {
$this->error('Could not sync comment '.$comment->id.' because '.$e->getMessage());

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Console\Commands;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Console\Command;
use GuzzleHttp\Client;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class PoniverseApiSetup extends Command
@ -43,7 +43,6 @@ class PoniverseApiSetup extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -74,7 +73,7 @@ class PoniverseApiSetup extends Command
$response = $client->post('api-credentials', [
'headers' => ['accept' => 'application/json'],
'auth' => [$username, $password],
'query' => ['app' => 'Pony.fm']
'query' => ['app' => 'Pony.fm'],
]);
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() === 401) {
@ -97,7 +96,6 @@ class PoniverseApiSetup extends Command
$this->info('Client ID and secret set!');
}
protected function setEnvironmentVariable($key, $oldValue, $newValue)
{
$path = base_path('.env');

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,8 +20,8 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
use Illuminate\Console\Command;
class RebuildArtists extends Command
{
@ -41,7 +41,6 @@ class RebuildArtists extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Kelvin Zhang
* Copyright (C) 2015 Kelvin Zhang.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Console\Commands;
use App\Models\TrackFile;
use File;
use Illuminate\Console\Command;
use App\Models\TrackFile;
class RebuildFilesizes extends Command
{
@ -43,7 +43,6 @@ class RebuildFilesizes extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -65,12 +64,10 @@ class RebuildFilesizes extends Command
)
) {
TrackFile::chunk(200, function ($trackFiles) {
$this->info('========== Start Chunk ==========');
foreach ($trackFiles as $trackFile) {
/** @var TrackFile $trackFile */
if (File::exists($trackFile->getFile())) {
$size = $trackFile->updateFilesize();
$this->info('ID '.$trackFile->id.' processed - '.$size.' bytes');

View file

@ -1,7 +1,7 @@
<?php
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2017 Isaac Avram
* Copyright (C) 2017 Isaac Avram.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -19,8 +19,8 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Image;
use Illuminate\Console\Command;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\File;
@ -57,10 +57,10 @@ class RebuildImages extends Command
*/
public function handle()
{
$this->info("Regenerating Images");
$this->info('Regenerating Images');
$progressBar = $this->output->createProgressBar(Image::count());
Image::chunk(1000, function($images) use ($progressBar) {
Image::chunk(1000, function ($images) use ($progressBar) {
foreach ($images as $image) {
try {
$image->buildCovers();

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,12 +20,12 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
use App\Models\Album;
use App\Models\Playlist;
use App\Models\Track;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
class RebuildSearchIndex extends Command
{
@ -45,7 +45,6 @@ class RebuildSearchIndex extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -65,7 +64,7 @@ class RebuildSearchIndex extends Command
$totalUsers = User::count();
$trackProgress = $this->output->createProgressBar($totalTracks);
$this->info("Processing tracks...");
$this->info('Processing tracks...');
Track::withTrashed()->chunk(200, function (Collection $tracks) use ($trackProgress) {
foreach ($tracks as $track) {
/** @var Track $track */
@ -76,9 +75,8 @@ class RebuildSearchIndex extends Command
$trackProgress->finish();
$this->line('');
$albumProgress = $this->output->createProgressBar($totalAlbums);
$this->info("Processing albums...");
$this->info('Processing albums...');
Album::withTrashed()->chunk(200, function (Collection $albums) use ($albumProgress) {
foreach ($albums as $album) {
/** @var Album $album */
@ -89,9 +87,8 @@ class RebuildSearchIndex extends Command
$albumProgress->finish();
$this->line('');
$playlistProgress = $this->output->createProgressBar($totalPlaylists);
$this->info("Processing playlists...");
$this->info('Processing playlists...');
Playlist::withTrashed()->chunk(200, function (Collection $playlists) use ($playlistProgress) {
foreach ($playlists as $playlist) {
/** @var Playlist $playlist */
@ -102,9 +99,8 @@ class RebuildSearchIndex extends Command
$playlistProgress->finish();
$this->line('');
$userProgress = $this->output->createProgressBar($totalUsers);
$this->info("Processing users...");
$this->info('Processing users...');
User::chunk(200, function (Collection $users) use ($userProgress) {
foreach ($users as $user) {
/** @var User $user */

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -42,7 +42,6 @@ class RebuildTags extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -63,7 +62,7 @@ class RebuildTags extends Command
$tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id', 'asc')->get();
}
$numberOfTracks = sizeof($tracks);
$numberOfTracks = count($tracks);
$this->info("Updating tags for ${numberOfTracks} tracks...");
$bar = $this->output->createProgressBar($numberOfTracks);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,11 +20,11 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Commands\GenerateTrackFilesCommand;
use App\Jobs\EncodeTrackFile;
use App\Models\Track;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
class RebuildTrack extends Command
{
@ -48,7 +48,6 @@ class RebuildTrack extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -78,14 +77,14 @@ class RebuildTrack extends Command
// The GenerateTrackFiles command will re-encode all TrackFiles.
if ($result->didFail()) {
$this->error("Something went wrong!");
$this->error('Something went wrong!');
print_r($result->getMessages());
}
} else {
$this->info("Re-encoding this track's files - there should be a line of output for each format!");
foreach ($track->trackFiles as $trackFile) {
if (!$trackFile->is_master) {
if (! $trackFile->is_master) {
$this->info("Re-encoding this track's {$trackFile->format} file...");
$this->dispatch(new EncodeTrackFile($trackFile, true));
}
@ -95,7 +94,7 @@ class RebuildTrack extends Command
private function printTrackInfo(Track $track)
{
$this->comment("Track info:");
$this->comment('Track info:');
$this->comment(" Title: {$track->title}");
$this->comment(" Uploaded at: {$track->created_at}");
$this->comment(" Artist: {$track->user->display_name} [User ID: {$track->user_id}]");

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Kelvin Zhang
* Copyright (C) 2015 Kelvin Zhang.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,16 +20,15 @@
namespace App\Console\Commands;
use File;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Jobs\EncodeTrackFile;
use App\Models\Track;
use App\Models\TrackFile;
use File;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
class RebuildTrackCache extends Command
{
use DispatchesJobs;
/**
@ -49,7 +48,6 @@ class RebuildTrackCache extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -172,7 +170,6 @@ class RebuildTrackCache extends Command
$this->output->newLine(1);
});
$this->info('Format(s) set from cacheable to non-cacheable: '.implode(' ', array_unique($formats)));
$this->info($trackFileCount.' cacheable track files set to non-cacheable.');
@ -209,7 +206,6 @@ class RebuildTrackCache extends Command
$this->output->newLine(1);
});
$this->info(sprintf('%d track files deleted out of %d track files. Continuing.', $count, $trackFileCount));
//==========================================================================================================
@ -228,17 +224,17 @@ class RebuildTrackCache extends Command
$this->output->newLine(1);
$this->info('---------- Start Chunk ----------');
// Record the track files which do not exist (i.e., have not been encoded yet)
// Record the track files which do not exist (i.e., have not been encoded yet)
$emptyTrackFiles = [];
foreach ($trackFiles as $trackFile) {
if (!File::exists($trackFile->getFile())) {
if (! File::exists($trackFile->getFile())) {
$count++;
$emptyTrackFiles[] = $trackFile;
}
}
// Encode recorded track files
// Encode recorded track files
foreach ($emptyTrackFiles as $emptyTrackFile) {
$this->info("Started encoding track file ID {$emptyTrackFile->id}");
$this->dispatch(new EncodeTrackFile($emptyTrackFile, false));
@ -248,7 +244,6 @@ class RebuildTrackCache extends Command
$this->output->newLine(1);
});
$this->info($count.' track files encoded.');
$this->output->newLine(1);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -42,7 +42,6 @@ class RefreshCache extends Command
/**
* Create a new command instance.
*
*/
public function __construct()
{
@ -62,17 +61,17 @@ class RefreshCache extends Command
DB::table('albums')->update([
'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.album_id = albums.id AND deleted_at IS NULL)'),
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)')
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)'),
]);
DB::table('playlists')->update([
'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.playlist_id = playlists.id AND deleted_at IS NULL)'),
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)')
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)'),
]);
DB::table('users')->update([
'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.profile_id = users.id AND deleted_at IS NULL)'),
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)')
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)'),
]);
$users = DB::table('users')->get();
@ -80,7 +79,7 @@ class RefreshCache extends Command
$resources = [
'album' => [],
'playlist' => [],
'track' => []
'track' => [],
];
foreach ($users as $user) {
@ -206,7 +205,7 @@ class RefreshCache extends Command
private function getCacheItem(&$resources, $type, $id)
{
if (!isset($resources[$type][$id])) {
if (! isset($resources[$type][$id])) {
$item = [
'view_count' => 0,
'download_count' => 0,
@ -227,7 +226,7 @@ class RefreshCache extends Command
private function getUserCacheItem(&$items, $userId, $type, $id)
{
if (!isset($items[$userId][$type][$id])) {
if (! isset($items[$userId][$type][$id])) {
$item = [
'is_followed' => false,
'is_favourited' => false,
@ -235,7 +234,7 @@ class RefreshCache extends Command
'view_count' => 0,
'play_count' => 0,
'download_count' => 0,
'user_id' => $userId
'user_id' => $userId,
];
$item[$type.'_id'] = $id;

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,10 @@
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use League\OAuth2\Client\Token\AccessToken;
use Poniverse\Lib\Client;
use App\Models\User;
class SyncPoniverseAccounts extends Command
{
@ -72,24 +72,24 @@ class SyncPoniverseAccounts extends Command
$usersToUpdate
->orderBy('id', 'ASC')
->chunk(100, function($users) use ($progress) {
/** @var User $user */
foreach ($users as $user) {
$progress->setMessage("Updating user ID {$user->id}...");
$progress->advance();
->chunk(100, function ($users) use ($progress) {
/** @var User $user */
foreach ($users as $user) {
$progress->setMessage("Updating user ID {$user->id}...");
$progress->advance();
$this->poniverse->poniverse()->meta()
$this->poniverse->poniverse()->meta()
->syncAccount(
$user->getAccessToken()->getResourceOwnerId(),
function(AccessToken $accessTokenInfo) use ($user) {
function (AccessToken $accessTokenInfo) use ($user) {
$user->setAccessToken($accessTokenInfo);
},
function(string $newEmailAddress) use ($user) {
function (string $newEmailAddress) use ($user) {
$user->email = $newEmailAddress;
$user->save();
});
}
});
}
});
$progress->finish();
$this->line('');

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Kelvin Zhang
* Copyright (C) 2016 Kelvin Zhang.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Console\Commands;
use App\Models\TrackFile;
use File;
use Illuminate\Console\Command;
use App\Models\TrackFile;
class VersionFiles extends Command
{
@ -62,23 +62,22 @@ class VersionFiles extends Command
if ($this->option('force') || $this->confirm('Are you sure you want to rename all unversioned track files? [y|N]', false)) {
TrackFile::chunk(200, function ($trackFiles) {
$this->info('========== Start Chunk ==========');
foreach ($trackFiles as $trackFile) {
/** @var TrackFile $trackFile */
// Check whether the unversioned file exists
if (!File::exists($trackFile->getUnversionedFile())) {
$this->info('ID ' . $trackFile->id . ' skipped - file not found');
if (! File::exists($trackFile->getUnversionedFile())) {
$this->info('ID '.$trackFile->id.' skipped - file not found');
continue;
}
// Version the file and check the outcome
if (File::move($trackFile->getUnversionedFile(), $trackFile->getFile())) {
$this->info('ID ' . $trackFile->id . ' processed');
$this->info('ID '.$trackFile->id.' processed');
} else {
$this->error('ID ' . $trackFile->id . ' was unable to be renamed');
$this->error('ID '.$trackFile->id.' was unable to be renamed');
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -25,8 +25,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* This interface is used for type safety when referring to entities that
* are capable of accepting comments.
*
* @package App\Contracts
*/
interface Commentable extends GeneratesNotifications
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -25,8 +25,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* This interface is used for type safety when referring to entities that
* are capable of being favourited.
*
* @package App\Contracts
*/
interface Favouritable extends GeneratesNotifications
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,14 +20,12 @@
namespace App\Contracts;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\MorphMany;
/**
* This interface is used for type safety when referring to entities that can be
* the "target resource" of a notification (ie. what the notification is about).
*
* @package App\Contracts
*/
interface GeneratesNotifications
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -26,12 +26,7 @@ use App\Models\Track;
use App\Models\User;
/**
* Interface NotificationHandler
* @package App\Contracts
*
* Each method in this interface represents a type of notification. To add a new
* type of notification, add a method for it to this interface and every class
* that implements it. Your IDE should be able to help with this.
* Interface NotificationHandler.
*/
interface NotificationHandler
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -36,5 +36,6 @@ interface Searchable
public function shouldBeIndexed():bool;
public function updateElasticsearchEntry();
public function updateElasticsearchEntrySynchronously();
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -21,8 +21,8 @@
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
use GrahamCampbell\Exceptions\ExceptionHandler;
use Illuminate\Auth\AuthenticationException;
class Handler extends ExceptionHandler
{
@ -45,7 +45,6 @@ class Handler extends ExceptionHandler
'password_confirmation',
];
/**
* Report or log an exception.
*

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -23,7 +23,7 @@ namespace App\Exceptions;
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
* Class TrackFileNotFoundException
* Class TrackFileNotFoundException.
*
* This exception is used to indicate that the requested `TrackFile` object
* does not exist. This is useful when dealing with albums or playlists that

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,8 +20,8 @@
namespace App\Http\Controllers;
use App\AlbumDownloader;
use App;
use App\AlbumDownloader;
use App\Models\Album;
use App\Models\ResourceLogItem;
use App\Models\Track;
@ -38,7 +38,7 @@ class AlbumsController extends Controller
public function getShow($id, $slug)
{
$album = Album::find($id);
if (!$album) {
if (! $album) {
App::abort(404);
}
@ -52,7 +52,7 @@ class AlbumsController extends Controller
public function getShortlink($id)
{
$album = Album::find($id);
if (!$album) {
if (! $album) {
App::abort(404);
}
@ -62,7 +62,7 @@ class AlbumsController extends Controller
public function getDownload($id, $extension)
{
$album = Album::with('tracks', 'tracks.trackFiles', 'user')->find($id);
if (!$album) {
if (! $album) {
App::abort(404);
}
@ -81,7 +81,7 @@ class AlbumsController extends Controller
App::abort(404);
}
if (!$album->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
if (! $album->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
App::abort(404);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -41,7 +41,7 @@ class TracksController extends Controller
$json = [
'total_tracks' => $tracks->count(),
'tracks' => $tracks->toArray()
'tracks' => $tracks->toArray(),
];
return Response::json($json, 200);
@ -53,7 +53,7 @@ class TracksController extends Controller
$json = [
'total_tracks' => $tracks->count(),
'tracks' => $tracks->toArray()
'tracks' => $tracks->toArray(),
];
return Response::json($json, 200);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015-2017 Feld0
* Copyright (C) 2015-2017 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -44,16 +44,16 @@ class TracksController extends ApiControllerBase
'status_url' => action('Api\V1\TracksController@getUploadStatus', ['id' => $commandData['id']]),
'track_url' => action('TracksController@getTrack', ['id' => $commandData['id'], 'slug' => $commandData['slug']]),
'message' => $commandData['autoPublish']
? "This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url."
? 'This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url.'
: "This track has been accepted for processing! Poll the status_url to know when it's ready to publish. It will be published at the track_url.",
];
$response->setData($data);
$response->setStatusCode(202);
return $response;
}
public function getUploadStatus($trackId)
{
$track = Track::findOrFail($trackId);
@ -67,7 +67,7 @@ class TracksController extends ApiControllerBase
? 'Processing complete! The track is live at the track_url. The artist can edit the track by visiting its edit_url.'
: 'Processing complete! The artist must publish the track by visiting its edit_url.',
'edit_url' => action('ContentController@getTracks', ['id' => $trackId]),
'track_url' => $track->url
'track_url' => $track->url,
], 201);
} else {
// something went wrong
@ -83,14 +83,15 @@ class TracksController extends ApiControllerBase
* @param int $id track ID
* @return \Illuminate\Http\JsonResponse
*/
public function getTrackDetails($id) {
public function getTrackDetails($id)
{
/** @var Track|null $track */
$track = Track
::with('user', 'album', 'user.avatar', 'cover', 'genre')
->published()
->where('id', $id)->first();
if (!$track) {
if (! $track) {
return Response::json(['message' => 'Track not found.'], 404);
}
@ -112,7 +113,7 @@ class TracksController extends ApiControllerBase
->published()
->where('hash', $hash)->first();
if (!$track) {
if (! $track) {
return Response::json(['message' => 'Track not found.'], 403);
}
@ -126,7 +127,8 @@ class TracksController extends ApiControllerBase
* @param bool $includeComments if true, includes the track's comments in the serialization
* @return array serialized track
*/
private static function trackToJson(Track $track, bool $includeComments, bool $includeStreamUrl) {
private static function trackToJson(Track $track, bool $includeComments, bool $includeStreamUrl)
{
$trackResponse = [
'id' => $track->id,
'title' => $track->title,
@ -139,41 +141,41 @@ class TracksController extends ApiControllerBase
'avatars' => [
'thumbnail' => $track->user->getAvatarUrl(Image::THUMBNAIL),
'small' => $track->user->getAvatarUrl(Image::SMALL),
'normal' => $track->user->getAvatarUrl(Image::NORMAL)
]
'normal' => $track->user->getAvatarUrl(Image::NORMAL),
],
],
'stats' => [
'views' => $track->view_count,
'plays' => $track->play_count,
'downloads' => $track->download_count,
'comments' => $track->comment_count,
'favourites' => $track->favourite_count
'favourites' => $track->favourite_count,
],
'url' => $track->url,
'is_vocal' => !!$track->is_vocal,
'is_explicit' => !!$track->is_explicit,
'is_downloadable' => !!$track->is_downloadable,
'is_vocal' => (bool) $track->is_vocal,
'is_explicit' => (bool) $track->is_explicit,
'is_downloadable' => (bool) $track->is_downloadable,
'published_at' => $track->published_at,
'duration' => $track->duration,
'genre' => $track->genre != null
?
[
'id' => $track->genre->id,
'name' => $track->genre->name
'name' => $track->genre->name,
] : null,
'type' => [
'id' => $track->trackType->id,
'name' => $track->trackType->title
'name' => $track->trackType->title,
],
'covers' => [
'thumbnail' => $track->getCoverUrl(Image::THUMBNAIL),
'small' => $track->getCoverUrl(Image::SMALL),
'normal' => $track->getCoverUrl(Image::NORMAL)
'normal' => $track->getCoverUrl(Image::NORMAL),
],
// As of 2017-10-28, this should be expected to produce
// "direct_upload", "mlpma", "ponify", or "eqbeats" for all tracks.
'source' => $track->source
'source' => $track->source,
];
if ($includeComments) {
@ -191,8 +193,8 @@ class TracksController extends ApiControllerBase
'normal' => $comment->user->getAvatarUrl(Image::NORMAL),
'thumbnail' => $comment->user->getAvatarUrl(Image::THUMBNAIL),
'small' => $comment->user->getAvatarUrl(Image::SMALL),
]
]
],
],
];
}
@ -204,7 +206,7 @@ class TracksController extends ApiControllerBase
'mp3' => [
'url' => $track->getStreamUrl('MP3', session('api_client_id')),
'mime_type' => Track::$Formats['MP3']['mime_type'],
]
],
];
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,12 +20,12 @@
namespace App\Http\Controllers\Api\Web;
use App\Http\Controllers\ApiControllerBase;
use App\Commands\SaveAccountSettingsCommand;
use App\Models\User;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Image;
use Gate;
use App\Models\User;
use Auth;
use Gate;
use Request;
use Response;
@ -36,11 +36,12 @@ class AccountController extends ApiControllerBase
$this->authorize('edit', $user);
return Response::json([
'user' => $user->toArray()
'user' => $user->toArray(),
]);
}
public function getCurrentUser() {
public function getCurrentUser()
{
$current_user = Auth::user();
if ($current_user != null) {
@ -58,9 +59,9 @@ class AccountController extends ApiControllerBase
'is_archived' => $user->is_archived,
'avatars' => [
'small' => $user->getAvatarUrl(Image::SMALL),
'normal' => $user->getAvatarUrl(Image::NORMAL)
'normal' => $user->getAvatarUrl(Image::NORMAL),
],
'created_at' => $user->created_at
'created_at' => $user->created_at,
], 200);
} else {
return Response::json(['error' => 'You are not logged in'], 404);
@ -88,7 +89,6 @@ class AccountController extends ApiControllerBase
}
}
return Response::json([
'id' => $user->id,
'bio' => $user->bio,
@ -97,10 +97,10 @@ class AccountController extends ApiControllerBase
'slug' => $user->slug,
'username' => $user->username,
'gravatar' => $user->gravatar ? $user->gravatar : $user->email,
'avatar_url' => !$user->uses_gravatar ? $user->getAvatarUrl() : null,
'avatar_url' => ! $user->uses_gravatar ? $user->getAvatarUrl() : null,
'uses_gravatar' => $user->uses_gravatar == 1,
'notification_email' => $user->email,
'notifications' => $user->getNotificationSettings()
'notifications' => $user->getNotificationSettings(),
], 200);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,20 +20,20 @@
namespace App\Http\Controllers\Api\Web;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Models\Album;
use App\Commands\CreateAlbumCommand;
use App\Commands\DeleteAlbumCommand;
use App\Commands\EditAlbumCommand;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Album;
use App\Models\Image;
use App\Models\ResourceLogItem;
use App\Models\Track;
use App\Models\User;
use Auth;
use Gate;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Request;
use App\Models\User;
use Response;
use App\Models\Track;
class AlbumsController extends ApiControllerBase
{
@ -66,12 +66,12 @@ class AlbumsController extends ApiControllerBase
'user',
'user.avatar',
'comments',
'comments.user'
'comments.user',
])
->userDetails()
->find($id);
if (!$album) {
if (! $album) {
App::abort(404);
}
@ -86,7 +86,7 @@ class AlbumsController extends ApiControllerBase
}
return Response::json([
'album' => $returned_album
'album' => $returned_album,
], 200);
}
@ -100,7 +100,7 @@ class AlbumsController extends ApiControllerBase
return $this->notFound('Album not found!');
}
if (!in_array($format, Track::$CacheableFormats)) {
if (! in_array($format, Track::$CacheableFormats)) {
return $this->notFound('Format not found!');
}
@ -144,7 +144,7 @@ class AlbumsController extends ApiControllerBase
}
return Response::json(
["albums" => $albums, "current_page" => $page, "total_pages" => ceil($count / $perPage)],
['albums' => $albums, 'current_page' => $page, 'total_pages' => ceil($count / $perPage)],
200
);
}
@ -167,8 +167,8 @@ class AlbumsController extends ApiControllerBase
'created_at' => $album->created_at->format('c'),
'covers' => [
'small' => $album->getCoverUrl(Image::SMALL),
'normal' => $album->getCoverUrl(Image::NORMAL)
]
'normal' => $album->getCoverUrl(Image::NORMAL),
],
];
}
@ -178,7 +178,7 @@ class AlbumsController extends ApiControllerBase
public function getEdit($id)
{
$album = Album::with('tracks')->find($id);
if (!$album) {
if (! $album) {
return $this->notFound('Album '.$id.' not found!');
}
@ -190,7 +190,7 @@ class AlbumsController extends ApiControllerBase
foreach ($album->tracks as $track) {
$tracks[] = [
'id' => $track->id,
'title' => $track->title
'title' => $track->title,
];
}
@ -205,7 +205,7 @@ class AlbumsController extends ApiControllerBase
'description' => $album->description,
'cover_url' => $album->hasCover() ? $album->getCoverUrl(Image::NORMAL) : null,
'real_cover_url' => $album->getCoverUrl(Image::NORMAL),
'tracks' => $tracks
'tracks' => $tracks,
], 200);
}
}

View file

@ -2,12 +2,12 @@
namespace App\Http\Controllers\Api\Web;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Session\Store;
use App\Http\Controllers\Controller;
use App\Models\AlexaSession;
use App\Models\Track;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Session\Store;
use Psr\Log\LoggerInterface;
class AlexaController extends Controller
@ -27,7 +27,7 @@ class AlexaController extends Controller
if ($sessId) {
$this->session = AlexaSession::find($sessId);
if (!$this->session) {
if (! $this->session) {
$this->session = new AlexaSession();
$this->session->id = $sessId;
}
@ -35,11 +35,11 @@ class AlexaController extends Controller
$logger->debug('Incoming Alexa Request', [
'type' => $type,
'intent' => $intent
'intent' => $intent,
]);
$logger->debug('Incoming Alexa Full Request', [
'json' => json_encode($request->json()->all(), JSON_PRETTY_PRINT)
'json' => json_encode($request->json()->all(), JSON_PRETTY_PRINT),
]);
/** @var JsonResponse $response */
@ -63,7 +63,7 @@ class AlexaController extends Controller
switch ($type) {
case 'LaunchRequest':
return $this->launch();
case 'PlayAudio';
case 'PlayAudio':
return $this->play();
case 'AudioPlayer.PlaybackNearlyFinished':
return $this->queueNextTrack();
@ -99,11 +99,11 @@ class AlexaController extends Controller
{
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
"outputSpeech" => [
"type" => "SSML",
"ssml" => "<speak>If you want to play music, say 'Alexa, ask pony fm to play'</speak>"
'outputSpeech' => [
'type' => 'SSML',
'ssml' => "<speak>If you want to play music, say 'Alexa, ask pony fm to play'</speak>",
],
'shouldEndSession' => true,
],
@ -114,11 +114,11 @@ class AlexaController extends Controller
{
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
"outputSpeech" => [
"type" => "SSML",
"ssml" => "<speak>Sorry, I don't recognise that command.</speak>"
'outputSpeech' => [
'type' => 'SSML',
'ssml' => "<speak>Sorry, I don't recognise that command.</speak>",
],
'shouldEndSession' => true,
],
@ -129,15 +129,15 @@ class AlexaController extends Controller
{
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
"outputSpeech" => [
"type" => "SSML",
"ssml" => "
'outputSpeech' => [
'type' => 'SSML',
'ssml' => '
<speak>
Pony.fm was built by Pixel Wavelength for Viola to keep all her music in one place.
</speak>
"
',
],
'shouldEndSession' => true,
],
@ -153,7 +153,7 @@ class AlexaController extends Controller
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
'directives' => [
[
@ -197,18 +197,18 @@ class AlexaController extends Controller
if (count($playlist) === 0) {
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
"outputSpeech" => [
"type" => "SSML",
"ssml" => "
'outputSpeech' => [
'type' => 'SSML',
'ssml' => "
<speak>
You've reached the end of the popular tracks today. To start from the beginning say 'Alexa, ask pony fm to play'
</speak>
"],
", ],
'directives' => [
[
'type' => 'AudioPlayer.Stop'
'type' => 'AudioPlayer.Stop',
],
],
'shouldEndSession' => true,
@ -216,7 +216,7 @@ class AlexaController extends Controller
];
}
$track = $playlist[$position-1];
$track = $playlist[$position - 1];
$trackHistory[] = $trackId;
@ -231,13 +231,13 @@ class AlexaController extends Controller
'offsetInMilliseconds' => 0,
];
if (!$replace) {
if (! $replace) {
$stream['expectedPreviousToken'] = $trackId;
}
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
'directives' => [
[
@ -247,7 +247,7 @@ class AlexaController extends Controller
'stream' => $stream,
],
],
]
],
],
];
}
@ -259,7 +259,7 @@ class AlexaController extends Controller
$trackHistory = $this->session->get('track_history', []);
$playlist = $this->session->get('playlist', []);
$track = $playlist[$position-2];
$track = $playlist[$position - 2];
$trackHistory[] = $trackId;
@ -275,7 +275,7 @@ class AlexaController extends Controller
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
'directives' => [
[
@ -285,7 +285,7 @@ class AlexaController extends Controller
'stream' => $stream,
],
],
]
],
],
];
}
@ -294,11 +294,11 @@ class AlexaController extends Controller
{
return [
'version' => '1.0',
'sessionAttributes' => (object)[],
'sessionAttributes' => (object) [],
'response' => [
'directives' => [
[
'type' => 'AudioPlayer.Stop'
'type' => 'AudioPlayer.Stop',
],
],
'shouldEndSession' => true,

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,15 +20,17 @@
namespace App\Http\Controllers\Api\Web;
use Carbon\Carbon;
use App\Commands\CreateAnnouncementCommand;
use App\Http\Controllers\Controller;
use App\Models\Announcement;
use Carbon\Carbon;
use Request;
use Response;
class AnnouncementsController extends Controller {
public function getIndex() {
class AnnouncementsController extends Controller
{
public function getIndex()
{
$currentDate = Carbon::now();
$query = Announcement::whereNotNull('start_time')
@ -40,23 +42,25 @@ class AnnouncementsController extends Controller {
$announcement = $query->first();
return Response::json(
["announcement" => $announcement],
['announcement' => $announcement],
200
);
}
public function getAdminIndex() {
public function getAdminIndex()
{
$this->authorize('access-admin-area');
$announcements = Announcement::orderBy('start_time', 'desc')
->get();
return Response::json([
'announcements' => $announcements->toArray()
'announcements' => $announcements->toArray(),
], 200);
}
public function getItemById($genreId) {
public function getItemById($genreId)
{
$this->authorize('access-admin-area');
$query = Announcement::where('id', '=', $genreId)
@ -65,13 +69,15 @@ class AnnouncementsController extends Controller {
$announcement = $query->first();
return Response::json(
["announcement" => $announcement],
['announcement' => $announcement],
200
);
}
public function postCreate() {
public function postCreate()
{
$command = new CreateAnnouncementCommand(Request::get('name'));
return $this->execute($command);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,28 +20,28 @@
namespace App\Http\Controllers\Api\Web;
use Gate;
use App;
use App\Commands\CreateUserCommand;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Album;
use App\Models\Comment;
use App\Models\Favourite;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Follower;
use App\Models\Image;
use App\Models\Track;
use App\Models\User;
use App\Models\Follower;
use App;
use ColorThief\ColorThief;
use Gate;
use Helpers;
use Illuminate\Support\Facades\Request;
use Response;
use ColorThief\ColorThief;
use Helpers;
class ArtistsController extends ApiControllerBase
{
public function getFavourites($slug)
{
$user = User::where('slug', $slug)->whereNull('disabled_at')->first();
if (!$user) {
if (! $user) {
App::abort(404);
}
@ -62,7 +62,7 @@ class ArtistsController extends ApiControllerBase
},
'album' => function ($query) {
$query->userDetails();
}
},
])->get();
$tracks = [];
@ -80,14 +80,14 @@ class ArtistsController extends ApiControllerBase
return Response::json([
'tracks' => $tracks,
'albums' => $albums
'albums' => $albums,
], 200);
}
public function getContent($slug)
{
$user = User::where('slug', $slug)->whereNull('disabled_at')->first();
if (!$user) {
if (! $user) {
App::abort(404);
}
@ -133,10 +133,10 @@ class ArtistsController extends ApiControllerBase
->with([
'comments' => function ($query) {
$query->with(['user', 'user.avatar']);
}
},
])
->first();
if (!$user) {
if (! $user) {
App::abort(404);
}
@ -162,18 +162,18 @@ class ArtistsController extends ApiControllerBase
}
$userData = [
'is_following' => false
'is_following' => false,
];
if ($user->users->count()) {
$userRow = $user->users[0];
$userData = [
'is_following' => (bool) $userRow->is_followed
'is_following' => (bool) $userRow->is_followed,
];
}
$palette = ColorThief::getPalette($user->getAvatarUrlLocal(Image::SMALL), 2);
$formatted_palette = array_map("Helpers::rgb2hex", $palette);
$formatted_palette = array_map('Helpers::rgb2hex', $palette);
$followers = Follower::where('artist_id', $user->id)
->count();
@ -186,7 +186,7 @@ class ArtistsController extends ApiControllerBase
'is_archived' => (bool) $user->is_archived,
'avatars' => [
'small' => $user->getAvatarUrl(Image::SMALL),
'normal' => $user->getAvatarUrl(Image::NORMAL)
'normal' => $user->getAvatarUrl(Image::NORMAL),
],
'avatar_colors' => $formatted_palette,
'created_at' => $user->created_at,
@ -199,10 +199,10 @@ class ArtistsController extends ApiControllerBase
'message_url' => $user->message_url,
'user_data' => $userData,
'permissions' => [
'edit' => Gate::allows('edit', $user)
'edit' => Gate::allows('edit', $user),
],
'isAdmin' => $user->hasRole('admin')
]
'isAdmin' => $user->hasRole('admin'),
],
], 200);
}
@ -228,7 +228,7 @@ class ArtistsController extends ApiControllerBase
}
return Response::json(
["artists" => $users, "current_page" => $page, "total_pages" => ceil($count / $perPage)],
['artists' => $users, 'current_page' => $page, 'total_pages' => ceil($count / $perPage)],
200
);
}
@ -236,6 +236,7 @@ class ArtistsController extends ApiControllerBase
public function postIndex()
{
$name = Request::json('username');
return $this->execute(new CreateUserCommand($name, $name, null, true));
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -22,8 +22,8 @@ namespace App\Http\Controllers\Api\Web;
use App;
use App\Commands\CreateCommentCommand;
use App\Models\Comment;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Comment;
use Illuminate\Support\Facades\Request;
use Response;

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -51,7 +51,7 @@ class DashboardController extends ApiControllerBase
return Response::json([
'recent_tracks' => $recentTracks,
'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content)
'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content),
], 200);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,10 @@
namespace App\Http\Controllers\Api\Web;
use App\Models\Album;
use App\Commands\ToggleFavouriteCommand;
use App\Models\Favourite;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Album;
use App\Models\Favourite;
use App\Models\Playlist;
use App\Models\Track;
use Auth;
@ -52,7 +52,7 @@ class FavouritesController extends ApiControllerBase
'track.genre',
'track.cover',
'track.album',
'track.album.user'
'track.album.user',
]);
$tracks = [];
@ -65,7 +65,7 @@ class FavouritesController extends ApiControllerBase
$tracks[] = Track::mapPublicTrackSummary($fav->track);
}
return Response::json(["tracks" => $tracks], 200);
return Response::json(['tracks' => $tracks], 200);
}
public function getAlbums()
@ -79,7 +79,7 @@ class FavouritesController extends ApiControllerBase
},
'album.user',
'album.user.avatar',
'album.cover'
'album.cover',
]);
$albums = [];
@ -92,7 +92,7 @@ class FavouritesController extends ApiControllerBase
$albums[] = Album::mapPublicAlbumSummary($fav->album);
}
return Response::json(["albums" => $albums], 200);
return Response::json(['albums' => $albums], 200);
}
public function getPlaylist()
@ -107,7 +107,7 @@ class FavouritesController extends ApiControllerBase
'playlist.user',
'playlist.user.avatar',
'playlist.tracks',
'playlist.tracks.cover'
'playlist.tracks.cover',
]);
$playlists = [];
@ -120,6 +120,6 @@ class FavouritesController extends ApiControllerBase
$playlists[] = Playlist::mapPublicPlaylistSummary($fav->playlist);
}
return Response::json(["playlists" => $playlists], 200);
return Response::json(['playlists' => $playlists], 200);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,12 +20,12 @@
namespace App\Http\Controllers\Api\Web;
use Illuminate\Support\Facades\Request;
use App\Commands\CreateGenreCommand;
use App\Commands\DeleteGenreCommand;
use App\Commands\RenameGenreCommand;
use App\Models\Genre;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Genre;
use Illuminate\Support\Facades\Request;
use Response;
class GenresController extends ApiControllerBase
@ -41,26 +41,28 @@ class GenresController extends ApiControllerBase
->get();
return Response::json([
'genres' => $genres->toArray()
'genres' => $genres->toArray(),
], 200);
}
public function postCreate()
{
$command = new CreateGenreCommand(Request::get('name'));
return $this->execute($command);
}
public function putRename($genreId)
{
$command = new RenameGenreCommand($genreId, Request::get('name'));
return $this->execute($command);
}
public function deleteGenre($genreId)
{
$command = new DeleteGenreCommand($genreId, Request::get('destination_genre_id'));
return $this->execute($command);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,10 @@
namespace App\Http\Controllers\Api\Web;
use Auth;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Image;
use App\Models\User;
use Auth;
use Response;
class ImagesController extends ApiControllerBase
@ -42,9 +42,9 @@ class ImagesController extends ApiControllerBase
'small' => $image->getUrl(Image::SMALL),
'normal' => $image->getUrl(Image::NORMAL),
'thumbnail' => $image->getUrl(Image::THUMBNAIL),
'original' => $image->getUrl(Image::ORIGINAL)
'original' => $image->getUrl(Image::ORIGINAL),
],
'filename' => $image->filename
'filename' => $image->filename,
];
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,13 +20,13 @@
namespace App\Http\Controllers\Api\Web;
use Auth;
use Illuminate\Support\Facades\Request;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Notification;
use App\Models\Subscription;
use App\Models\Track;
use App\Models\User;
use Auth;
use Illuminate\Support\Facades\Request;
use Minishlink\WebPush\WebPush;
class NotificationsController extends ApiControllerBase
@ -85,7 +85,7 @@ class NotificationsController extends ApiControllerBase
'user_id' => Auth::user()->id,
'endpoint' => $input->endpoint,
'p256dh' => $input->keys->p256dh,
'auth' => $input->keys->auth
'auth' => $input->keys->auth,
]);
return ['id' => $subscription->id];
@ -98,7 +98,7 @@ class NotificationsController extends ApiControllerBase
}
/**
* Removes a user's notification subscription
* Removes a user's notification subscription.
*
* @return string
*/

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,7 +20,6 @@
namespace App\Http\Controllers\Api\Web;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Commands\AddTrackToPlaylistCommand;
use App\Commands\CreatePlaylistCommand;
use App\Commands\DeletePlaylistCommand;
@ -30,11 +29,12 @@ use App\Http\Controllers\ApiControllerBase;
use App\Models\Image;
use App\Models\Playlist;
use App\Models\ResourceLogItem;
use Auth;
use Illuminate\Support\Facades\Request;
use App\Models\User;
use Response;
use App\Models\Track;
use App\Models\User;
use Auth;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Request;
use Response;
class PlaylistsController extends ApiControllerBase
{
@ -95,9 +95,9 @@ class PlaylistsController extends ApiControllerBase
}
return Response::json([
"playlists" => $playlists,
"current_page" => $page,
"total_pages" => ceil($count / $perPage)
'playlists' => $playlists,
'current_page' => $page,
'total_pages' => ceil($count / $perPage),
], 200);
}
@ -113,9 +113,9 @@ class PlaylistsController extends ApiControllerBase
},
'tracks.trackFiles',
'comments',
'comments.user'
'comments.user',
])->userDetails()->find($id);
if (!$playlist || !$playlist->canView(Auth::user())) {
if (! $playlist || ! $playlist->canView(Auth::user())) {
App::abort('404');
}
@ -137,11 +137,11 @@ class PlaylistsController extends ApiControllerBase
return $this->notFound('Playlist not found!');
}
if ((!$playlist->is_public && !Auth::check()) || (!$playlist->is_public && ($playlist->user_id !== Auth::user()->id))) {
if ((! $playlist->is_public && ! Auth::check()) || (! $playlist->is_public && ($playlist->user_id !== Auth::user()->id))) {
return $this->notFound('Playlist not found!');
}
if (!in_array($format, Track::$CacheableFormats)) {
if (! in_array($format, Track::$CacheableFormats)) {
return $this->notFound('Format not found!');
}
@ -201,18 +201,17 @@ class PlaylistsController extends ApiControllerBase
'url' => $playlist->url,
'covers' => [
'small' => $playlist->getCoverUrl(Image::SMALL),
'normal' => $playlist->getCoverUrl(Image::NORMAL)
'normal' => $playlist->getCoverUrl(Image::NORMAL),
],
'is_pinned' => $playlist->hasPinFor(Auth::user()->id),
'is_public' => $playlist->is_public == 1,
'track_ids' => $playlist->tracks->pluck('id')
'track_ids' => $playlist->tracks->pluck('id'),
];
}
return Response::json($playlists, 200);
}
/**
* This function should not deal with anything other than applying order,
* which is done after the query's total possible results are counted due

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,10 @@
namespace App\Http\Controllers\Api\Web;
use Elasticsearch;
use App\Http\Controllers\ApiControllerBase;
use Illuminate\Support\Facades\Request;
use App\Library\Search;
use Elasticsearch;
use Illuminate\Support\Facades\Request;
use Response;
class SearchController extends ApiControllerBase

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,12 +20,12 @@
namespace App\Http\Controllers\Api\Web;
use Illuminate\Support\Facades\Request;
use App\Commands\CreateShowSongCommand;
use App\Commands\DeleteShowSongCommand;
use App\Commands\RenameShowSongCommand;
use App\Models\ShowSong;
use App\Http\Controllers\ApiControllerBase;
use App\Models\ShowSong;
use Illuminate\Support\Facades\Request;
use Response;
class ShowSongsController extends ApiControllerBase
@ -42,26 +42,28 @@ class ShowSongsController extends ApiControllerBase
->get();
return Response::json([
'showsongs' => $songs->toArray()
'showsongs' => $songs->toArray(),
], 200);
}
public function postCreate()
{
$command = new CreateShowSongCommand(Request::get('title'));
return $this->execute($command);
}
public function putRename($songId)
{
$command = new RenameShowSongCommand($songId, Request::get('title'));
return $this->execute($command);
}
public function deleteSong($songId)
{
$command = new DeleteShowSongCommand($songId, Request::get('destination_song_id'));
return $this->execute($command);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,15 +20,15 @@
namespace App\Http\Controllers\Api\Web;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Http\Controllers\ApiControllerBase;
use App\Models\ResourceLogItem;
use App\Models\Track;
use Auth;
use Cache;
use DB;
use Response;
use Carbon\Carbon;
use DB;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Response;
class StatsController extends ApiControllerBase
{
@ -88,12 +88,12 @@ class StatsController extends ApiControllerBase
if ($hourly) {
$set = [
'hours' => $timeOffet.' '.str_plural('hour', $timeOffet),
'plays' => $plays
'plays' => $plays,
];
} else {
$set = [
'days' => $timeOffet.' '.str_plural('day', $timeOffet),
'plays' => $plays
'plays' => $plays,
];
}
array_push($output, $set);
@ -116,7 +116,7 @@ class StatsController extends ApiControllerBase
}
// Do we have permission to view this track?
if (!$track->canView(Auth::user())) {
if (! $track->canView(Auth::user())) {
return $this->notFound('Track not found!');
}
@ -134,6 +134,7 @@ class StatsController extends ApiControllerBase
$statsData = $this->getStatsData($id, $hourly);
$output = $this->sortTrackStatsArray($statsData, $hourly);
return $output;
});

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,8 +20,8 @@
namespace App\Http\Controllers\Api\Web;
use App\Models\Genre;
use App\Http\Controllers\ApiControllerBase;
use App\Models\Genre;
use App\Models\License;
use App\Models\ShowSong;
use App\Models\TrackType;
@ -48,7 +48,7 @@ class TaxonomiesController extends ApiControllerBase
'id',
'slug',
DB::raw('(SELECT COUNT(tracks.id) FROM show_song_track INNER JOIN tracks ON tracks.id = show_song_track.track_id WHERE show_song_track.show_song_id = show_songs.id AND tracks.published_at IS NOT NULL) AS track_count')
)->orderBy('title')->get()->toArray()
)->orderBy('title')->get()->toArray(),
], 200);
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,10 +20,6 @@
namespace App\Http\Controllers\Api\Web;
use Auth;
use File;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Request;
use App\Commands\DeleteTrackCommand;
use App\Commands\EditTrackCommand;
use App\Commands\GenerateTrackFilesCommand;
@ -33,9 +29,13 @@ use App\Jobs\EncodeTrackFile;
use App\Models\Genre;
use App\Models\ResourceLogItem;
use App\Models\Track;
use App\Models\TrackType;
use App\Models\TrackFile;
use App\Models\TrackType;
use App\Models\User;
use Auth;
use File;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Request;
use Response;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -78,13 +78,14 @@ class TracksController extends ApiControllerBase
session_write_close();
$track = Track::find($trackId);
if (!$track) {
if (! $track) {
return $this->notFound('Track not found!');
}
$this->authorize('edit', $track);
$track->version_upload_status = Track::STATUS_PROCESSING;
$track->update();
return $this->execute(new UploadTrackCommand(true, false, null, false, $track->getNextVersion(), $track));
}
@ -113,8 +114,8 @@ class TracksController extends ApiControllerBase
foreach ($trackFiles as $trackFile) {
$versions[] = [
'version' => $trackFile->version,
'url' => '/tracks/' . $track->id . '/version-change/' . $trackFile->version,
'created_at' => $trackFile->created_at->timestamp
'url' => '/tracks/'.$track->id.'/version-change/'.$trackFile->version,
'created_at' => $trackFile->created_at->timestamp,
];
}
@ -124,26 +125,27 @@ class TracksController extends ApiControllerBase
public function getChangeVersion($trackId, $newVersion)
{
$track = Track::find($trackId);
if (!$track) {
if (! $track) {
return $this->notFound('Track not found!');
}
$this->authorize('edit', $track);
$masterTrackFile = $track->trackFilesForVersion($newVersion)->where('is_master', true)->first();
if (!$masterTrackFile) {
if (! $masterTrackFile) {
return $this->notFound('Version not found!');
}
$track->version_upload_status = Track::STATUS_PROCESSING;
$track->update();
$sourceFile = new UploadedFile($masterTrackFile->getFile(), $masterTrackFile->getFilename());
return $this->execute(new GenerateTrackFilesCommand($track, $sourceFile, false, false, true, $newVersion));
}
public function getShow($id)
{
$track = Track::userDetails()->withComments()->find($id);
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
return $this->notFound('Track not found!');
}
@ -169,15 +171,15 @@ class TracksController extends ApiControllerBase
return $this->notFound('Track not found!');
}
if (!$track->canView(Auth::user())) {
return $this->notFound('Track not found!');
if (! $track->canView(Auth::user())) {
return $this->notFound('Track not found!');
}
if ($track->is_downloadable == false) {
return $this->notFound('Track not found!');
return $this->notFound('Track not found!');
}
if (!in_array($format, Track::$CacheableFormats)) {
if (! in_array($format, Track::$CacheableFormats)) {
return $this->notFound('Format not found!');
}
@ -239,21 +241,23 @@ class TracksController extends ApiControllerBase
}
return Response::json([
"tracks" => $tracks,
"current_page" => $page,
"total_pages" => ceil($totalCount / $perPage)
'tracks' => $tracks,
'current_page' => $page,
'total_pages' => ceil($totalCount / $perPage),
], 200);
}
public function getAllTracks()
{
$this->authorize('access-admin-area');
return $this->getIndex(true);
}
public function getClassifierQueue()
{
$this->authorize('access-admin-area');
return $this->getIndex(true, true);
}
@ -272,7 +276,7 @@ class TracksController extends ApiControllerBase
public function getEdit($id)
{
$track = Track::with('showSongs')->find($id);
if (!$track) {
if (! $track) {
return $this->notFound('Track '.$id.' not found!');
}
@ -329,7 +333,7 @@ class TracksController extends ApiControllerBase
$query->whereIn('genre_id', Request::get('genres'));
}
if (Request::has('types') && !$unknown) {
if (Request::has('types') && ! $unknown) {
$query->whereIn('track_type_id', Request::get('types'));
}
@ -355,8 +359,9 @@ class TracksController extends ApiControllerBase
$archives = ['mlpma', 'ponify', 'eqbeats'];
$akey = array_search($archive, $archives);
if (!$akey)
$query->join($archive . '_tracks', 'tracks.id', '=', $archive . 'tracks.track_id');
if (! $akey) {
$query->join($archive.'_tracks', 'tracks.id', '=', $archive.'tracks.track_id');
}
}
if (Request::has('songs')) {

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -34,7 +34,7 @@ abstract class ApiControllerBase extends Controller
*/
protected function execute(CommandBase $command)
{
if (!$command->authorize()) {
if (! $command->authorize()) {
return $this->notAuthorized();
}
@ -42,7 +42,7 @@ abstract class ApiControllerBase extends Controller
if ($result->didFail()) {
return Response::json([
'message' => 'Validation failed',
'errors' => $result->getMessages()
'errors' => $result->getMessages(),
], $result->getStatusCode());
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -22,8 +22,8 @@ namespace App\Http\Controllers;
use App;
use App\Models\User;
use View;
use Redirect;
use View;
class ArtistsController extends Controller
{
@ -68,7 +68,7 @@ class ArtistsController extends Controller
public function getShortlink($id)
{
$user = User::find($id);
if (!$user || $user->disabled_at !== null) {
if (! $user || $user->disabled_at !== null) {
App::abort('404');
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,18 +20,18 @@
namespace App\Http\Controllers;
use App\Models\Activity;
use App\Models\User;
use Auth;
use Carbon\Carbon;
use DB;
use Illuminate\Support\Facades\Input;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessToken;
use Log;
use Poniverse\Lib\Client;
use App\Models\Activity;
use App\Models\User;
use Auth;
use DB;
use Request;
use Redirect;
use Request;
class AuthController extends Controller
{
@ -57,6 +57,7 @@ class AuthController extends Controller
public function postLogout()
{
Auth::logout();
return Redirect::to('/');
}
@ -67,7 +68,7 @@ class AuthController extends Controller
try {
$accessToken = $oauthProvider->getAccessToken('authorization_code', [
'code' => Request::query('code'),
'redirect_uri' => action('AuthController@getOAuth')
'redirect_uri' => action('AuthController@getOAuth'),
]);
$this->poniverse->setAccessToken($accessToken);
$resourceOwner = $oauthProvider->getResourceOwner($accessToken);
@ -94,13 +95,14 @@ class AuthController extends Controller
'type' => 'Bearer',
];
if (!empty($accessToken->getRefreshToken())) {
if (! empty($accessToken->getRefreshToken())) {
$setData['refresh_token'] = $accessToken->getRefreshToken();
}
if ($token) {
//User already exists, update access token and refresh token if provided.
DB::table('oauth2_tokens')->where('id', '=', $token->id)->update($setData);
return $this->loginRedirect(User::find($token->user_id));
}
@ -120,7 +122,6 @@ class AuthController extends Controller
}
}
return $this->loginRedirect($user);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -22,8 +22,8 @@ namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,9 +20,9 @@
namespace App\Http\Controllers;
use App;
use App\Models\Image;
use Config;
use App;
use Redirect;
use Response;
@ -37,14 +37,14 @@ class ImagesController extends Controller
}
$image = Image::find($id);
if (!$image) {
if (! $image) {
App::abort(404);
}
$response = Response::make('', 200);
$filename = $image->getFile($coverType['id']);
if (!is_file($filename)) {
if (! is_file($filename)) {
$redirect = url('/images/icons/profile_'.Image::$ImageTypes[$coverType['id']]['name'].'.png');
return Redirect::to($redirect);

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Feld0
* Copyright (C) 2016 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -21,23 +21,24 @@
namespace App\Http\Controllers;
use App;
use Auth;
use DB;
use App\Models\Email;
use App\Models\EmailSubscription;
use Auth;
use DB;
use View;
class NotificationsController extends Controller {
class NotificationsController extends Controller
{
/**
* @param $emailKey
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function getEmailClick($emailKey) {
public function getEmailClick($emailKey)
{
/** @var Email $email */
$email = Email::findOrFail($emailKey);
DB::transaction(function() use ($email) {
DB::transaction(function () use ($email) {
$email->emailClicks()->create(['ip_address' => \Request::ip()]);
$email->notification->is_read = true;
$email->notification->save();
@ -46,7 +47,8 @@ class NotificationsController extends Controller {
return redirect($email->getActivity()->url);
}
public function getEmailUnsubscribe($subscriptionKey) {
public function getEmailUnsubscribe($subscriptionKey)
{
/** @var EmailSubscription $subscription */
$subscription = EmailSubscription::findOrFail($subscriptionKey);
$subscription->delete();
@ -54,17 +56,18 @@ class NotificationsController extends Controller {
if (Auth::check() && $subscription->user->id === Auth::user()->id) {
return redirect(route('account:settings', [
'slug' => $subscription->user->slug,
'unsubscribedMessageKey' => $subscription->activity_type
'unsubscribedMessageKey' => $subscription->activity_type,
]), 303);
} else {
return redirect(route('email:confirm-unsubscribed', [
'unsubscribedUser' => $subscription->user->display_name,
'unsubscribedMessageKey' => $subscription->activity_type
'unsubscribedMessageKey' => $subscription->activity_type,
]), 303);
}
}
public function getEmailUnsubscribePage() {
public function getEmailUnsubscribePage()
{
return View::make('shared.null');
}
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -39,7 +39,7 @@ class PlaylistsController extends Controller
public function getPlaylist($id, $slug)
{
$playlist = Playlist::find($id);
if (!$playlist || !$playlist->canView(Auth::user())) {
if (! $playlist || ! $playlist->canView(Auth::user())) {
App::abort(404);
}
@ -53,7 +53,7 @@ class PlaylistsController extends Controller
public function getShortlink($id)
{
$playlist = Playlist::find($id);
if (!$playlist || !$playlist->canView(Auth::user())) {
if (! $playlist || ! $playlist->canView(Auth::user())) {
App::abort(404);
}
@ -63,7 +63,7 @@ class PlaylistsController extends Controller
public function getDownload($id, $extension)
{
$playlist = Playlist::with('tracks', 'tracks.trackFiles', 'user', 'tracks.album')->find($id);
if (!$playlist || !$playlist->canView(Auth::user())) {
if (! $playlist || ! $playlist->canView(Auth::user())) {
App::abort(404);
}
@ -82,7 +82,7 @@ class PlaylistsController extends Controller
App::abort(404);
}
if (!$playlist->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
if (! $playlist->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
App::abort(404);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2016 Logic
* Copyright (C) 2016 Logic.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,13 +20,13 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App;
use App\Models\ResourceLogItem;
use App\Models\Track;
use App\Models\TrackFile;
use Auth;
use Config;
use App;
use Illuminate\Http\Request;
use Redirect;
use Response;
use View;
@ -50,7 +50,7 @@ class TracksController extends Controller
'genre'
)->first();
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
App::abort(404);
}
@ -58,9 +58,9 @@ class TracksController extends Controller
'stats' => [
'views' => 0,
'plays' => 0,
'downloads' => 0
'downloads' => 0,
],
'is_favourited' => false
'is_favourited' => false,
];
if ($track->users->count()) {
@ -71,7 +71,7 @@ class TracksController extends Controller
'plays' => $userRow->play_count,
'downloads' => $userRow->download_count,
],
'is_favourited' => $userRow->is_favourited
'is_favourited' => $userRow->is_favourited,
];
}
@ -80,7 +80,7 @@ class TracksController extends Controller
public function getOembed(Request $request)
{
if (!$request->filled('url')) {
if (! $request->filled('url')) {
App::abort(404);
}
@ -93,7 +93,7 @@ class TracksController extends Controller
->userDetails()
->first();
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
App::abort(404);
}
@ -107,7 +107,7 @@ class TracksController extends Controller
'title' => $track->title,
'author_name' => $track->user->display_name,
'author_url' => $track->user->url,
'html' => '<iframe src="'.action('TracksController@getEmbed', ['id' => $track->id]).'" width="100%" height="150" allowTransparency="true" frameborder="0" seamless allowfullscreen></iframe>'
'html' => '<iframe src="'.action('TracksController@getEmbed', ['id' => $track->id]).'" width="100%" height="150" allowTransparency="true" frameborder="0" seamless allowfullscreen></iframe>',
];
return Response::json($output);
@ -116,7 +116,7 @@ class TracksController extends Controller
public function getTrack($id, $slug)
{
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
App::abort(404);
}
@ -135,7 +135,7 @@ class TracksController extends Controller
public function getShortlink($id)
{
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
App::abort(404);
}
@ -145,7 +145,7 @@ class TracksController extends Controller
public function getStream($id, $extension)
{
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
App::abort(404);
}
@ -154,7 +154,7 @@ class TracksController extends Controller
$response = Response::make('', 200);
$filename = $trackFile->getFile();
if (!file_exists($filename)) {
if (! file_exists($filename)) {
App::abort(418);
}
@ -182,7 +182,7 @@ class TracksController extends Controller
public function getDownload($id, $extension)
{
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user())) {
if (! $track || ! $track->canView(Auth::user())) {
App::abort(404);
}

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -42,7 +42,7 @@ class Kernel extends HttpKernel
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\App\Http\Middleware\DisabledAccountCheck::class,
]
],
];
/**

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -20,6 +20,7 @@
namespace App\Http\Middleware;
use App\Models\User;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
@ -27,7 +28,6 @@ use Illuminate\Session\Store;
use League\OAuth2\Client\Token\AccessToken;
use Poniverse;
use Poniverse\Lib\Client;
use App\Models\User;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthenticateOAuth
@ -71,11 +71,11 @@ class AuthenticateOAuth
// check that access token is valid at Poniverse.net
$accessTokenInfo = $this->poniverse->poniverse()->meta()->introspect($accessToken);
if (!$accessTokenInfo->getIsActive()) {
if (! $accessTokenInfo->getIsActive()) {
throw new AccessDeniedHttpException('This access token is expired or invalid!');
}
if (!in_array($requiredScope, $accessTokenInfo->getScopes())) {
if (! in_array($requiredScope, $accessTokenInfo->getScopes())) {
throw new AccessDeniedHttpException("This access token lacks the '${requiredScope}' scope!");
}
@ -92,7 +92,6 @@ class AuthenticateOAuth
return $next($request);
}
private function determineAccessToken(Request $request, $headerOnly = true)
{
$header = $request->header('Authorization');

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -43,8 +43,6 @@ class DisabledAccountCheck
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
@ -59,7 +57,7 @@ class DisabledAccountCheck
// something other than merged accounts.
if ($this->auth->check()
&& $this->auth->user()->disabled_at !== null
&& !($request->getMethod() === 'POST' && $request->getRequestUri() == '/auth/logout')
&& ! ($request->getMethod() === 'POST' && $request->getRequestUri() == '/auth/logout')
) {
Log::info("A login was attempted to a disabled account, user ID #{$this->auth->user()->id}.");
$this->auth->logout();

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by

View file

@ -2,7 +2,7 @@
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -24,11 +24,7 @@ use Closure;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
* Class JsonExceptions
* @package App\Http\Middleware
*
* This middleware turns any HTTP exceptions thrown during the request
* into a JSON response. To be used when implementing the API!
* Class JsonExceptions.
*/
class JsonExceptions
{
@ -45,7 +41,7 @@ class JsonExceptions
$response = $next($request);
} catch (HttpException $e) {
return \Response::json([
'message' => $e->getMessage()
'message' => $e->getMessage(),
], $e->getStatusCode());
}

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