diff --git a/app/controllers/TracksController.php b/app/controllers/TracksController.php index acd365dc..771fc7cb 100644 --- a/app/controllers/TracksController.php +++ b/app/controllers/TracksController.php @@ -10,11 +10,41 @@ } public function getEmbed($id) { - $track = Track::find($id); + $track = Track + ::whereId($id) + ->published() + ->userDetails() + ->with( + 'user', + 'user.avatar', + 'genre' + )->first(); + if (!$track || !$track->canView(Auth::user())) App::abort(404); - return View::make('tracks.embed', ['track' => $track]); + $userData = [ + 'stats' => [ + 'views' => 0, + 'plays' => 0, + 'downloads' => 0 + ], + 'is_favourited' => false + ]; + + if ($track->users->count()) { + $userRow = $track->users[0]; + $userData = [ + 'stats' => [ + 'views' => $userRow->view_count, + 'plays' => $userRow->play_count, + 'downloads' => $userRow->download_count, + ], + 'is_favourited' => $userRow->is_favourited + ]; + } + + return View::make('tracks.embed', ['track' => $track, 'user' => $userData]); } public function getTrack($id, $slug) { diff --git a/app/library/Assets.php b/app/library/Assets.php index 2a2b6b24..ee6a3065 100644 --- a/app/library/Assets.php +++ b/app/library/Assets.php @@ -82,6 +82,22 @@ ])); } + return $collection; + } else if ($area == 'embed') { + $collection = new AssetCollection([ + new FileAsset('scripts/base/jquery-2.0.2.js'), + new FileAsset('scripts/base/jquery.viewport.js'), + new FileAsset('scripts/base/underscore.js'), + new FileAsset('scripts/base/moment.js'), + new FileAsset('scripts/base/jquery.timeago.js'), + new FileAsset('scripts/base/soundmanager2-nodebug.js'), + new AssetCollection([ + new GlobAsset('scripts/embed/*.coffee'), + ], [ + new CoffeeScriptFilter(Config::get('app.coffee')) + ]) + ]); + return $collection; } @@ -104,6 +120,12 @@ $css->add(new FileAsset('styles/prettify.css')); } + return $css; + } else if ($area == 'embed') { + $css = new AssetCollection([ + new FileAsset('styles/embed.less'), + ], [new \Assetic\Filter\LessFilter('node')]); + return $css; } diff --git a/app/library/Helpers.php b/app/library/Helpers.php index ec6caaac..771cb787 100644 --- a/app/library/Helpers.php +++ b/app/library/Helpers.php @@ -23,4 +23,20 @@ return round($bytes, $precision) . ' ' . $units[$pow]; } + + /** + * timeago-style timestamp generator macro. + * + * @param string $timestamp A timestamp in SQL DATETIME syntax + * @return string + */ + public static function timestamp( $timestamp ) { + if(gettype($timestamp) !== 'string' && get_class($timestamp) === 'DateTime'){ + $timestamp = $timestamp->format('c'); + } + + $title = date('c', strtotime($timestamp)); + $content = date('F d, o \@ g:i:s a', strtotime($timestamp)); + return ''.$content.''; + } } \ No newline at end of file diff --git a/app/views/tracks/embed.blade.php b/app/views/tracks/embed.blade.php index 6ef69c7b..e27cd640 100644 --- a/app/views/tracks/embed.blade.php +++ b/app/views/tracks/embed.blade.php @@ -2,10 +2,8 @@ - @section('title')Pony.fm - @yield_section + {{$track->title}} by {{$track->user->display_name}} on Pony.fm - {{-- --}} @@ -13,55 +11,46 @@ - {{ HTML::style( 'css/app-embed.css?' . filemtime(path('public').'/css/app.css') ) }} - {{ Asset::styles() }} - - - - + {{ Assets::styleIncludes('embed') }} - -
- @if($track->explicit && !(Auth::check() && Auth::user()->can_see_explicit_content)) -
- Enable explicit content in {{ HTML::link(URL::to_action('account@edit'), 'your account', ['target' => '_blank']) }} to play this track. - + + @if($track->explicit && !(Auth::check() && Auth::user()->can_see_explicit_content)) +
+ Enable explicit content in {{ HTML::link(URL::to('/account/settings'), 'your account', ['target' => '_blank']) }} to play this track.
Hosted by Pony.fm
- @else -
+ @else +
-
- {{ HTML::image($track->get_cover_url('normal')) }} +
+ {{ HTML::image($track->getCoverUrl(\Entities\Image::SMALL)) }}
@if (Auth::check()) - + @endif
-
-
-
-
+
+
{{ HTML::link( $track->url, $track->title, ['target' => '_blank'] ) }} - by: {{ HTML::link($track->user->url, $track->artist, ['target' => '_blank']) }} / {{ HTML::link($track->genre->url, $track->genre->title, ['target' => '_blank']) }} / {{ HTML::timestamp($track->published_at) }} -
+ by: {{ HTML::link($track->user->url, $track->user->display_name, ['target' => '_blank']) }} / {{$track->genre->name}} / {{Helpers::timestamp($track->published_at)}}
- Views: {{ $track->views }} / Plays: {{ $track->plays }} / Downloads: {{ $track->downloads }} / + Views: {{ $track->view_count }} / Plays: {{ $track->play_count }} / Downloads: {{ $track->download_count }} / Hosted by Pony.fm
- @endif -
+ @endif - {{ Asset::scripts() }} + + {{ Assets::scriptIncludes('embed') }} +