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 @@
-