2016-09-03 22:13:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Gallery;
|
|
|
|
|
|
|
|
use App\Album;
|
2016-09-05 14:27:20 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-09 17:08:35 +01:00
|
|
|
use App\Helpers\DbHelper;
|
2016-09-03 22:13:05 +01:00
|
|
|
use app\Http\Controllers\Admin\AlbumController;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Photo;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
class PhotoController extends Controller
|
|
|
|
{
|
2016-09-04 21:59:32 +01:00
|
|
|
public function download(Request $request, $albumUrlAlias, $photoFilename)
|
2016-09-03 22:13:05 +01:00
|
|
|
{
|
2016-09-09 17:08:35 +01:00
|
|
|
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
|
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$this->authorize('album.view', $album);
|
|
|
|
|
2016-09-03 22:13:05 +01:00
|
|
|
$albumSource = $album->getAlbumSource();
|
|
|
|
|
2016-09-09 17:08:35 +01:00
|
|
|
$thumbnail = $request->get('t');
|
2016-09-03 22:13:05 +01:00
|
|
|
$photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename);
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
return response()->file($albumSource->getPathToPhoto($photo, $thumbnail));
|
2016-09-03 22:13:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-05 14:27:20 +01:00
|
|
|
public function show($albumUrlAlias, $photoFilename)
|
|
|
|
{
|
2016-09-09 17:08:35 +01:00
|
|
|
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
|
2016-09-03 22:13:05 +01:00
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-09-09 17:08:35 +01:00
|
|
|
$this->authorize('album.view', $album);
|
|
|
|
|
|
|
|
$photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename);
|
|
|
|
|
|
|
|
return Theme::render('gallery.photo', [
|
|
|
|
'album' => $album,
|
|
|
|
'photo' => $photo
|
|
|
|
]);
|
2016-09-03 22:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Photo
|
|
|
|
*/
|
|
|
|
public static function loadPhotoByAlbumAndFilename(Album $album, $filename)
|
|
|
|
{
|
|
|
|
$photo = Photo::where([
|
|
|
|
['album_id', $album->id],
|
2016-09-06 19:47:25 +01:00
|
|
|
['storage_file_name', $filename]
|
2016-09-03 22:13:05 +01:00
|
|
|
])->first();
|
|
|
|
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $photo;
|
|
|
|
}
|
|
|
|
}
|