kuvia/app/Http/Controllers/PublicController.php

90 lines
3.4 KiB
PHP
Raw Normal View History

2021-01-12 14:49:45 +00:00
<?php
namespace App\Http\Controllers;
2021-01-21 00:37:38 +00:00
2021-01-12 14:49:45 +00:00
use App\Models\Gallery;
use App\Models\Image;
use App\Models\Tenant;
2021-01-21 00:37:38 +00:00
2021-01-12 14:49:45 +00:00
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
2021-01-19 22:32:50 +00:00
use Illuminate\Support\Facades\Auth;
2021-01-21 00:37:38 +00:00
2021-01-12 14:49:45 +00:00
class PublicController extends BaseController
{
2021-01-17 02:20:21 +00:00
public static $size = ["pixel" => 100, "small" => 300, "medium" => 600, "big" => 1200];
2021-01-17 02:04:16 +00:00
2021-01-12 14:49:45 +00:00
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function listGalleriesView($name) {
$tenant = Tenant::query()->where("url", "=", $name)->firstOrFail();
2021-01-19 22:30:21 +00:00
$galleries = Gallery::query()
->where("tenant", "=", $tenant->id)
->where("status", "=", "online")
->where("listed", "=", 1)
->orderByDesc("gallery_create_time")
->orderByDesc("created_at")
->get();
2021-01-17 16:28:53 +00:00
$parser = new \Parsedown();
foreach ($galleries as $gallery) {
$gallery->html = $parser->parse($gallery->description);
}
2021-01-12 22:14:38 +00:00
return view("themes.tenant.kuvia-blog.list", ["galleries" => $galleries, "tenant" => $tenant]);
2021-01-12 14:49:45 +00:00
}
public function listGalleryImagesView($tenant, $gallery) {
$tenant = Tenant::query()->where("url", "=", $tenant)->firstOrFail();
$gallery = Gallery::getByTenantAndUrl($tenant->id, $gallery);
2021-01-19 22:33:41 +00:00
if($gallery->status == "online" || (Auth::check() && $gallery->status == "preview" && Auth::user()->id == $tenant->owner)) {
2021-01-19 23:12:50 +00:00
$images = Image::query()
->where("gallery", "=", $gallery->id)
->whereNull("deleted_at")
->orderBy("rating")
->orderBy("DateTimeOriginal")
->get();
2021-01-19 22:32:50 +00:00
} else {
abort( 404);
}
2021-01-20 00:17:57 +00:00
$parser = new \Parsedown();
2021-01-20 00:17:34 +00:00
$gallery->html = $parser->parse($gallery->description);
2021-01-17 04:12:42 +00:00
return view("themes.gallery.gallery-detail.list", ["gallery" => $gallery, "tenant" => $tenant, "images" => $images]);
2021-01-12 14:49:45 +00:00
}
2021-01-21 00:37:38 +00:00
public function returnWatermakeFile(\App\Helper\Image $imageHelper, \App\Helper\Access $accessHelper) {
2021-01-20 20:43:58 +00:00
$tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail();
2021-01-21 00:40:38 +00:00
$imageModel = Image::query()->where("id", "=", $tenant->watermark)->firstOrFail();
$img = $imageHelper->getRawImage($imageModel);
$accessHelper->add($imageModel, $img, \App\Helper\Access::TYPE_CACHE);
2021-01-21 00:37:38 +00:00
return $img->response();
2021-01-20 20:43:58 +00:00
}
2021-01-21 00:13:41 +00:00
public function returnImageFile($tenant_url, $gallery_url, $image_id, \App\Helper\Image $image, \App\Helper\Access $access, Request $request) {
2021-01-17 02:04:16 +00:00
$sizeName = $request->input("size", "medium");
2021-01-17 02:39:33 +00:00
if(!array_key_exists($sizeName, self::$size)) {
2021-01-17 02:04:16 +00:00
abort(400, "Size not exists");
}
2021-01-17 02:40:00 +00:00
$size = (int)self::$size[$sizeName];
2021-01-12 14:49:45 +00:00
2021-01-21 00:13:41 +00:00
$imageModel = Image::query()->where("id", "=", $image_id)->firstOrFail();
if(!$image->validateGalleryAndTenant($imageModel, $gallery_url, $tenant_url)) {
abort(404);
}
$img = $image->getImage($imageModel, $size);
$typ = \App\Helper\Access::TYPE_S3;
if($img->getDrive() == "cache") {
$typ = \App\Helper\Access::TYPE_CACHE;
}
$access->addById($image_id, $img, $typ);
return $img->response();
2021-01-12 14:49:45 +00:00
}
}