jonnybarnes.uk/app/Http/Controllers/ShortURLsController.php

53 lines
1.2 KiB
PHP
Raw Normal View History

2016-05-19 15:01:28 +01:00
<?php
declare(strict_types=1);
2016-05-19 15:01:28 +01:00
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
2016-05-19 15:01:28 +01:00
class ShortURLsController extends Controller
{
/*
|--------------------------------------------------------------------------
| Short URL Controller
|--------------------------------------------------------------------------
|
| This redirects the short urls to long ones
|
*/
/**
* Redirect from '/' to the long url.
*/
public function baseURL(): RedirectResponse
2016-05-19 15:01:28 +01:00
{
return redirect(config('app.url'));
}
/**
* Redirect from '/@' to a twitter profile.
*/
public function twitter(): RedirectResponse
2016-05-19 15:01:28 +01:00
{
return redirect('https://twitter.com/jonnybarnes');
}
/**
* Redirect a short url of this site out to a long one based on post type.
*
2023-02-18 09:34:57 +00:00
* Further redirects may happen.
2016-05-19 15:01:28 +01:00
*/
public function expandType(string $type, string $postId): RedirectResponse
2016-05-19 15:01:28 +01:00
{
2023-02-18 09:34:57 +00:00
if ($type === 't') {
2016-05-19 15:01:28 +01:00
$type = 'notes';
}
2023-02-18 09:34:57 +00:00
if ($type === 'b') {
2016-05-19 15:01:28 +01:00
$type = 'blog/s';
}
return redirect(config('app.url') . '/' . $type . '/' . $postId);
}
}