Example #1
0
 public function getIndex($type, $id)
 {
     $column = '';
     if ($type == 'track') {
         $column = 'track_id';
     } else {
         if ($type == 'user') {
             $column = 'profile_id';
         } else {
             if ($type == 'album') {
                 $column = 'album_id';
             } else {
                 if ($type == 'playlist') {
                     $column = 'playlist_id';
                 } else {
                     App::abort(500);
                 }
             }
         }
     }
     $query = Comment::where($column, '=', $id)->orderBy('created_at', 'desc')->with('user');
     $comments = [];
     foreach ($query->get() as $comment) {
         $comments[] = Comment::mapPublic($comment);
     }
     return Response::json(['list' => $comments, 'count' => count($comments)]);
 }
 /**
  * @throws \Exception
  * @return CommandResponse
  */
 public function execute()
 {
     $rules = ['content' => 'required', 'track_id' => 'exists:tracks,id', 'albums_id' => 'exists:albums,id', 'playlist_id' => 'exists:playlists,id', 'profile_id' => 'exists:users,id'];
     $validator = Validator::make($this->_input, $rules);
     if ($validator->fails()) {
         return CommandResponse::fail($validator);
     }
     $comment = new Comment();
     $comment->user_id = Auth::user()->id;
     $comment->content = $this->_input['content'];
     if ($this->_type == 'track') {
         $column = 'track_id';
     } else {
         if ($this->_type == 'user') {
             $column = 'profile_id';
         } else {
             if ($this->_type == 'album') {
                 $column = 'album_id';
             } else {
                 if ($this->_type == 'playlist') {
                     $column = 'playlist_id';
                 } else {
                     App::abort(500);
                 }
             }
         }
     }
     $comment->{$column} = $this->_id;
     $comment->save();
     // Recount the track's comments, if this is a track comment
     if ($this->_type === 'track') {
         $entity = Track::find($this->_id);
     } elseif ($this->_type === 'album') {
         $entity = Album::find($this->_id);
     } elseif ($this->_type === 'playlist') {
         $entity = Playlist::find($this->_id);
     } elseif ($this->_type === 'user') {
         $entity = User::find($this->_id);
     } else {
         App::abort(400, 'This comment is being added to an invalid entity!');
     }
     $entity->comment_count = Comment::where($column, $this->_id)->count();
     $entity->save();
     return CommandResponse::succeed(Comment::mapPublic($comment));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get list of affected users
     $usernames = DB::table('users')->select(['username', DB::raw('COUNT(*) as count')])->whereNull('disabled_at')->whereNotNull('username')->groupBy(DB::raw('LOWER(username)'))->having('count', '>=', 2)->lists('username');
     foreach ($usernames as $username) {
         // Find the relevant accounts
         // ==========================
         /** @var Collection $accounts */
         $accounts = User::where('username', $username)->orderBy('created_at', 'ASC')->get();
         $firstAccount = $accounts[0];
         $accounts->forget(0);
         $accountIds = $accounts->pluck('id');
         // Reassign content
         // ================
         // This is done with the less-efficient-than-raw-SQL Eloquent
         // methods to generate appropriate revision logs.
         $this->info('Merging duplicates for: ' . $firstAccount->username);
         DB::transaction(function () use($accounts, $accountIds, $firstAccount) {
             foreach (Album::whereIn('user_id', $accountIds)->get() as $album) {
                 $album->user_id = $firstAccount->id;
                 $album->save();
             }
             foreach (Comment::whereIn('user_id', $accountIds)->get() as $comment) {
                 $comment->user_id = $firstAccount->id;
                 $comment->save();
             }
             foreach (Favourite::whereIn('user_id', $accountIds)->get() as $favourite) {
                 $favourite->user_id = $firstAccount->id;
                 $favourite->save();
             }
             foreach (Follower::whereIn('artist_id', $accountIds)->get() as $follow) {
                 $follow->artist_id = $firstAccount->id;
                 $follow->save();
             }
             foreach (Image::whereIn('uploaded_by', $accountIds)->get() as $image) {
                 $image->uploaded_by = $firstAccount->id;
                 $image->save();
             }
             foreach (Image::whereIn('uploaded_by', $accountIds)->get() as $image) {
                 $image->uploaded_by = $firstAccount->id;
                 $image->save();
             }
             DB::table('oauth2_tokens')->whereIn('user_id', $accountIds)->update(['user_id' => $firstAccount->id]);
             foreach (PinnedPlaylist::whereIn('user_id', $accountIds)->get() as $playlist) {
                 $playlist->user_id = $firstAccount->id;
                 $playlist->save();
             }
             foreach (Playlist::whereIn('user_id', $accountIds)->get() as $playlist) {
                 $playlist->user_id = $firstAccount->id;
                 $playlist->save();
             }
             foreach (ResourceLogItem::whereIn('user_id', $accountIds)->get() as $item) {
                 $item->user_id = $firstAccount->id;
                 $item->save();
             }
             foreach (ResourceUser::whereIn('user_id', $accountIds)->get() as $item) {
                 $item->user_id = $firstAccount->id;
                 $item->save();
             }
             foreach (Track::whereIn('user_id', $accountIds)->get() as $track) {
                 $track->user_id = $firstAccount->id;
                 $track->save();
             }
             foreach ($accounts as $account) {
                 $account->disabled_at = Carbon::now();
                 $account->save();
             }
         });
     }
 }
Example #4
0
 public static function mapPublicPlaylistShow(Playlist $playlist)
 {
     $tracks = [];
     foreach ($playlist->tracks as $track) {
         /** @var $track Track */
         $tracks[] = Track::mapPublicTrackSummary($track);
     }
     $formats = [];
     foreach (Track::$Formats as $name => $format) {
         $formats[] = ['name' => $name, 'extension' => $format['extension'], 'url' => $playlist->getDownloadUrl($name), 'size' => Helpers::formatBytes($playlist->getFilesize($name)), 'isCacheable' => in_array($name, Track::$CacheableFormats) ? true : false];
     }
     $comments = [];
     foreach ($playlist->comments as $comment) {
         $comments[] = Comment::mapPublic($comment);
     }
     $data = self::mapPublicPlaylistSummary($playlist);
     $data['tracks'] = $tracks;
     $data['comments'] = $comments;
     $data['formats'] = $formats;
     $data['share'] = ['url' => action('PlaylistsController@getShortlink', ['id' => $playlist->id]), 'tumblrUrl' => 'http://www.tumblr.com/share/link?url=' . urlencode($playlist->url) . '&name=' . urlencode($playlist->title) . '&description=' . urlencode($playlist->description), 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text=' . $playlist->title . ' by ' . $playlist->user->display_name . ' on Pony.fm'];
     return $data;
 }
Example #5
0
 public static function mapPublicTrackShow(Track $track)
 {
     $returnValue = self::mapPublicTrackSummary($track);
     $returnValue['description'] = $track->description;
     $returnValue['lyrics'] = $track->lyrics;
     $comments = [];
     foreach ($track->comments as $comment) {
         $comments[] = Comment::mapPublic($comment);
     }
     $returnValue['comments'] = $comments;
     if ($track->album_id != null) {
         $returnValue['album'] = ['title' => $track->album->title, 'url' => $track->album->url];
     }
     $formats = [];
     foreach ($track->trackFiles as $trackFile) {
         $formats[] = ['name' => $trackFile->format, 'extension' => $trackFile->extension, 'url' => $trackFile->url, 'size' => $trackFile->size, 'isCacheable' => (bool) $trackFile->is_cacheable];
     }
     $returnValue['share'] = ['url' => action('TracksController@getShortlink', ['id' => $track->id]), 'html' => '<iframe src="' . action('TracksController@getEmbed', ['id' => $track->id]) . '" width="100%" height="150" allowTransparency="true" frameborder="0" seamless allowfullscreen></iframe>', 'bbcode' => '[url=' . $track->url . '][img]' . $track->getCoverUrl() . '[/img][/url]', 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text=' . $track->title . ' by ' . $track->user->display_name . ' on Pony.fm'];
     $returnValue['share']['tumblrUrl'] = 'http://www.tumblr.com/share/video?embed=' . urlencode($returnValue['share']['html']) . '&caption=' . urlencode($track->title);
     $returnValue['formats'] = $formats;
     return $returnValue;
 }
Example #6
0
 public function getShow($slug)
 {
     $user = User::whereSlug($slug)->whereNull('disabled_at')->userDetails()->with(['comments' => function ($query) {
         $query->with('user');
     }])->first();
     if (!$user) {
         App::abort(404);
     }
     $trackQuery = Track::summary()->published()->explicitFilter()->listed()->with('genre', 'cover', 'user')->userDetails()->whereUserId($user->id)->whereNotNull('published_at')->orderBy('created_at', 'desc')->take(20);
     $latestTracks = [];
     foreach ($trackQuery->get() as $track) {
         $latestTracks[] = Track::mapPublicTrackSummary($track);
     }
     $comments = [];
     foreach ($user->comments as $comment) {
         $comments[] = Comment::mapPublic($comment);
     }
     $userData = ['is_following' => false];
     if ($user->users->count()) {
         $userRow = $user->users[0];
         $userData = ['is_following' => (bool) $userRow->is_followed];
     }
     return Response::json(['artist' => ['id' => (int) $user->id, 'name' => $user->display_name, 'slug' => $user->slug, 'is_archived' => (bool) $user->is_archived, 'avatars' => ['small' => $user->getAvatarUrl(Image::SMALL), 'normal' => $user->getAvatarUrl(Image::NORMAL)], 'created_at' => $user->created_at, 'followers' => [], 'following' => [], 'latest_tracks' => $latestTracks, 'comments' => $comments, 'bio' => $user->bio, 'mlpforums_username' => $user->username, 'message_url' => $user->message_url, 'user_data' => $userData]], 200);
 }