Updated URL generation to use Laravel 5's helpers.

This commit is contained in:
Peter Deltchev 2015-12-20 07:07:36 -08:00
parent fe1133e99e
commit e6c31a1500
12 changed files with 19 additions and 94 deletions

View file

@ -28,7 +28,6 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use Auth; use Auth;
use Cache; use Cache;
use Poniverse\Ponyfm\Traits\TrackCollection; use Poniverse\Ponyfm\Traits\TrackCollection;
use URL;
use Poniverse\Ponyfm\Traits\SlugTrait; use Poniverse\Ponyfm\Traits\SlugTrait;
use Venturecraft\Revisionable\RevisionableTrait; use Venturecraft\Revisionable\RevisionableTrait;
@ -131,7 +130,7 @@ class Album extends Model
$data['description'] = $album->description; $data['description'] = $album->description;
$data['is_downloadable'] = $is_downloadable; $data['is_downloadable'] = $is_downloadable;
$data['share'] = [ $data['share'] = [
'url' => URL::to('/a' . $album->id), 'url' => action('AlbumsController@getShortlink', ['id' => $album->id]),
'tumblrUrl' => 'http://www.tumblr.com/share/link?url=' . urlencode($album->url) . '&name=' . urlencode($album->title) . '&description=' . urlencode($album->description), 'tumblrUrl' => 'http://www.tumblr.com/share/link?url=' . urlencode($album->url) . '&name=' . urlencode($album->title) . '&description=' . urlencode($album->description),
'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text=' . $album->title . ' by ' . $album->user->display_name . ' on Pony.fm' 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text=' . $album->title . ' by ' . $album->user->display_name . ' on Pony.fm'
]; ];
@ -198,12 +197,12 @@ class Album extends Model
public function getUrlAttribute() public function getUrlAttribute()
{ {
return URL::to('albums/' . $this->id . '-' . $this->slug); return action('AlbumsController@getShow', ['id' => $this->id, 'slug' => $this->slug]);
} }
public function getDownloadUrl($format) public function getDownloadUrl($format)
{ {
return URL::to('a' . $this->id . '/dl.' . Track::$Formats[$format]['extension']); return action('AlbumsController@getDownload', ['id' => $this->id, 'extension' => Track::$Formats[$format]['extension']]);
} }
public function getFilesize($format) public function getFilesize($format)

View file

@ -25,7 +25,6 @@ use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Poniverse\Ponyfm\Traits\SlugTrait; use Poniverse\Ponyfm\Traits\SlugTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use URL;
use Venturecraft\Revisionable\RevisionableTrait; use Venturecraft\Revisionable\RevisionableTrait;
class Genre extends Model class Genre extends Model
@ -75,6 +74,6 @@ class Genre extends Model
* @return string relative, Angular-friendly URL to this genre * @return string relative, Angular-friendly URL to this genre
*/ */
public function getUrlAttribute() { public function getUrlAttribute() {
return URL::route('tracks.discover', ['filter' => "genres-{$this->id}"], false); return route('tracks.discover', ['filter' => "genres-{$this->id}"], false);
} }
} }

View file

@ -27,7 +27,6 @@ use DB;
use Input; use Input;
use Poniverse; use Poniverse;
use Redirect; use Redirect;
use URL;
class AuthController extends Controller class AuthController extends Controller
{ {
@ -36,7 +35,7 @@ class AuthController extends Controller
public function __construct() public function __construct()
{ {
$this->poniverse = new Poniverse(Config::get('poniverse.client_id'), Config::get('poniverse.secret')); $this->poniverse = new Poniverse(Config::get('poniverse.client_id'), Config::get('poniverse.secret'));
$this->poniverse->setRedirectUri(URL::to('/auth/oauth')); $this->poniverse->setRedirectUri(action('AuthController@getOAuth'));
} }
public function getLogin() public function getLogin()
@ -62,7 +61,7 @@ class AuthController extends Controller
'authorization_code', 'authorization_code',
[ [
'code' => Input::query('code'), 'code' => Input::query('code'),
'redirect_uri' => URL::to('/auth/oauth') 'redirect_uri' => action('AuthController@getOAuth')
]); ]);
if ($code['code'] != 200) { if ($code['code'] != 200) {

View file

@ -25,7 +25,6 @@ use Config;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Response; use Response;
use URL;
class ImagesController extends Controller class ImagesController extends Controller
{ {
@ -46,7 +45,7 @@ class ImagesController extends Controller
$filename = $image->getFile($coverType['id']); $filename = $image->getFile($coverType['id']);
if (!is_file($filename)) { if (!is_file($filename)) {
$redirect = URL::to('/images/icons/profile_' . Image::$ImageTypes[$coverType['id']]['name'] . '.png'); $redirect = url('/images/icons/profile_' . Image::$ImageTypes[$coverType['id']]['name'] . '.png');
return Redirect::to($redirect); return Redirect::to($redirect);
} }

View file

@ -1,44 +0,0 @@
<?php
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Peter Deltchev
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Poniverse\Ponyfm\Http\Controllers;
use Poniverse\Ponyfm\User;
use File;
use Illuminate\Support\Facades\App;
class UsersController extends Controller
{
public function getAvatar($id, $type)
{
$coverType = Cover::getCoverFromName($type);
if ($coverType == null) {
App::abort(404);
}
$user = User::find($id);
if (!$user) {
App::abort(404);
}
return File::inline($user->getAvatarFile($coverType['id']), 'image/png', 'cover.png');
}
}

View file

@ -62,8 +62,6 @@ Route::get('/mlpforums-advertising-program', function() { return View::make('pag
Route::get('i{id}/{type}.png', 'ImagesController@getImage')->where('id', '\d+'); Route::get('i{id}/{type}.png', 'ImagesController@getImage')->where('id', '\d+');
Route::get('u{id}/avatar_{type}.png', 'UsersController@getAvatar')->where('id', '\d+');
Route::get('playlist/{id}-{slug}', 'PlaylistsController@getPlaylist'); Route::get('playlist/{id}-{slug}', 'PlaylistsController@getPlaylist');
Route::get('p{id}', 'PlaylistsController@getShortlink')->where('id', '\d+'); Route::get('p{id}', 'PlaylistsController@getShortlink')->where('id', '\d+');
Route::get('p{id}/dl.{extension}', 'PlaylistsController@getDownload' ); Route::get('p{id}/dl.{extension}', 'PlaylistsController@getDownload' );

View file

@ -22,8 +22,7 @@ namespace Poniverse\Ponyfm;
use External; use External;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config; use Config;
use Illuminate\Support\Facades\URL;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
class Image extends Model class Image extends Model
@ -101,7 +100,7 @@ class Image extends Model
{ {
$type = self::$ImageTypes[$type]; $type = self::$ImageTypes[$type];
return URL::to('i' . $this->id . '/' . $type['name'] . '.png'); return action('ImagesController@getImage', ['id' => $this->id, 'type' => $type['name']]);
} }
public function getFile($type = self::NORMAL) public function getFile($type = self::NORMAL)

View file

@ -27,7 +27,6 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use Auth; use Auth;
use Cache; use Cache;
use Poniverse\Ponyfm\Traits\TrackCollection; use Poniverse\Ponyfm\Traits\TrackCollection;
use URL;
use Poniverse\Ponyfm\Traits\SlugTrait; use Poniverse\Ponyfm\Traits\SlugTrait;
use Venturecraft\Revisionable\RevisionableTrait; use Venturecraft\Revisionable\RevisionableTrait;
@ -88,7 +87,7 @@ class Playlist extends Model
$data['comments'] = $comments; $data['comments'] = $comments;
$data['formats'] = $formats; $data['formats'] = $formats;
$data['share'] = [ $data['share'] = [
'url' => URL::to('/p' . $playlist->id), '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), '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' 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text=' . $playlist->title . ' by ' . $playlist->user->display_name . ' on Pony.fm'
]; ];
@ -202,12 +201,12 @@ class Playlist extends Model
public function getUrlAttribute() public function getUrlAttribute()
{ {
return URL::to('/playlist/' . $this->id . '-' . $this->slug); return action('PlaylistsController@getPlaylist', ['id' => $this->id, 'slug' => $this->slug]);
} }
public function getDownloadUrl($format) public function getDownloadUrl($format)
{ {
return URL::to('p' . $this->id . '/dl.' . Track::$Formats[$format]['extension']); return action('PlaylistsController@getDownload', ['id' => $this->id]);
} }
public function getFilesize($format) public function getFilesize($format)

View file

@ -20,11 +20,7 @@
namespace Poniverse\Ponyfm\Providers; namespace Poniverse\Ponyfm\Providers;
use App;
use Auth;
use Illuminate\Auth\Guard;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
// use PFMAuth;
use PfmValidator; use PfmValidator;
use Validator; use Validator;
@ -37,12 +33,6 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
/*
Auth::extend('pfm', function() {
return new Guard(new PFMAuth(), App::make('session.store'));
});
*/
Validator::resolver(function($translator, $data, $rules, $messages) Validator::resolver(function($translator, $data, $rules, $messages)
{ {
return new PfmValidator($translator, $data, $rules, $messages); return new PfmValidator($translator, $data, $rules, $messages);

View file

@ -33,7 +33,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Log; use Log;
use URL;
use Venturecraft\Revisionable\RevisionableTrait; use Venturecraft\Revisionable\RevisionableTrait;
class Track extends Model class Track extends Model
@ -257,8 +256,8 @@ class Track extends Model
} }
$returnValue['share'] = [ $returnValue['share'] = [
'url' => URL::to('/t' . $track->id), 'url' => action('TracksController@getShortlink', ['id' => $track->id]),
'html' => '<iframe src="' . URL::to('t' . $track->id . '/embed') . '" 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>',
'bbcode' => '[url=' . $track->url . '][img]' . $track->getCoverUrl() . '[/img][/url]', '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' 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text=' . $track->title . ' by ' . $track->user->display_name . ' on Pony.fm'
]; ];
@ -477,7 +476,7 @@ class Track extends Model
public function getUrlAttribute() public function getUrlAttribute()
{ {
return URL::to('/tracks/' . $this->id . '-' . $this->slug); return action('TracksController@getTrack', ['id' => $this->id, 'slug' => $this->slug]);
} }
public function getDownloadDirectoryAttribute() public function getDownloadDirectoryAttribute()
@ -537,7 +536,7 @@ class Track extends Model
public function getStreamUrl($format = 'MP3') public function getStreamUrl($format = 'MP3')
{ {
return URL::to('/t' . $this->id . '/stream.' . self::$Formats[$format]['extension']); return action('TracksController@getStream', ['id' => $this->id, 'extension' => self::$Formats[$format]['extension']]);
} }
public function getDirectory() public function getDirectory()
@ -605,7 +604,7 @@ class Track extends Model
$format = self::$Formats[$format]; $format = self::$Formats[$format];
return URL::to('/t' . $this->id . '/dl.' . $format['extension']); return action('TracksController@getDownload', ['id' => $this->id, 'extension' => $format['extension']]);
} }

View file

@ -25,7 +25,6 @@ use Helpers;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App; use App;
use File; use File;
use URL;
class TrackFile extends Model class TrackFile extends Model
{ {
@ -88,7 +87,7 @@ class TrackFile extends Model
public function getUrlAttribute() public function getUrlAttribute()
{ {
return URL::to('/t' . $this->track_id . '/dl.' . $this->extension); return action('TracksController@getDownload', ['id' => $this->track_id, 'extension' => $this->extension]);
} }
public function getSizeAttribute() public function getSizeAttribute()

View file

@ -85,7 +85,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
public function getUrlAttribute() public function getUrlAttribute()
{ {
return URL::to('/' . $this->slug); return action('ArtistsController@getProfile', $this->slug);
} }
public function getMessageUrlAttribute() public function getMessageUrlAttribute()
@ -133,17 +133,6 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']); return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']);
} }
public function getAvatarFile($type = Image::NORMAL)
{
if ($this->uses_gravatar) {
throw new Exception('Cannot get avatar file if this user is configured to use Gravatar!');
}
$imageType = Image::$ImageTypes[$type];
return URL::to('t' . $this->id . '/cover_' . $imageType['name'] . '.png?' . $this->cover_id);
}
/** /**
* Get the token value for the "remember me" session. * Get the token value for the "remember me" session.
* *